xref: /illumos-gate/usr/src/tools/ctf/stabs/common/fth_enum.c (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Used to dump enums in forth mode.
29  *
30  * Enums are simple - there is no member-specific mode for them.  We get
31  * the header op at the start, and we save the type id for dumping later.
32  * If we get the members op, we've been invoked in member-specific mode,
33  * which is a syntax error for an enum.  When we ge the trailer op, we
34  * dump all of the members and the trailer thus concluding the enum.
35  */
36 
37 #include "forth.h"
38 
39 static ctf_id_t	fth_enum_curtid;
40 static int	fth_enum_curnmems;
41 
42 static int
43 fth_enum_header(ctf_id_t tid)
44 {
45 	fth_enum_curtid = tid;
46 
47 	(void) fprintf(out, "\n");
48 
49 	return (0);
50 }
51 
52 /*ARGSUSED*/
53 static int
54 fth_enum_members(char *memfilter, char *format)
55 {
56 	return (parse_warn("Member-specific mode cannot be used for "
57 	    " enums"));
58 }
59 
60 /*ARGSUSED2*/
61 static int
62 fth_enum_cb(const char *name, int value, void *arg)
63 {
64 	(void) fprintf(out, "here ,\" %s\" %x\n", name, value);
65 	fth_enum_curnmems++;
66 
67 	return (0);
68 }
69 
70 static int
71 fth_enum_trailer(void)
72 {
73 	if (ctf_enum_iter(ctf, fth_enum_curtid, fth_enum_cb, NULL) != 0)
74 		return (-1);
75 
76 	(void) fprintf(out, "%x c-enum .%s\n", fth_enum_curnmems, fth_curtype);
77 
78 	fth_enum_curnmems = 0;
79 
80 	return (0);
81 }
82 
83 fth_type_ops_t fth_enum_ops = {
84 	fth_enum_header,
85 	fth_enum_members,
86 	fth_enum_trailer
87 };
88