xref: /titanic_44/usr/src/tools/ctf/stabs/common/fth_enum.c (revision 95efa359b507db290a2484b8f615822b1e06096f)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Used to dump enums in forth mode.
31  *
32  * Enums are simple - there is no member-specific mode for them.  We get
33  * the header op at the start, and we save the type id for dumping later.
34  * If we get the members op, we've been invoked in member-specific mode,
35  * which is a syntax error for an enum.  When we ge the trailer op, we
36  * dump all of the members and the trailer thus concluding the enum.
37  */
38 
39 #include "forth.h"
40 
41 static ctf_id_t	fth_enum_curtid;
42 static int	fth_enum_curnmems;
43 
44 static int
45 fth_enum_header(ctf_id_t tid)
46 {
47 	fth_enum_curtid = tid;
48 
49 	(void) fprintf(out, "\n");
50 
51 	return (0);
52 }
53 
54 /*ARGSUSED*/
55 static int
56 fth_enum_members(char *memfilter, char *format)
57 {
58 	return (parse_warn("Member-specific mode cannot be used for "
59 	    " enums"));
60 }
61 
62 /*ARGSUSED2*/
63 static int
64 fth_enum_cb(const char *name, int value, void *arg)
65 {
66 	(void) fprintf(out, "here ,\" %s\" %x\n", name, value);
67 	fth_enum_curnmems++;
68 
69 	return (0);
70 }
71 
72 static int
73 fth_enum_trailer(void)
74 {
75 	if (ctf_enum_iter(ctf, fth_enum_curtid, fth_enum_cb, NULL) != 0)
76 		return (-1);
77 
78 	(void) fprintf(out, "%x c-enum .%s\n", fth_enum_curnmems, fth_curtype);
79 
80 	fth_enum_curnmems = 0;
81 
82 	return (0);
83 }
84 
85 fth_type_ops_t fth_enum_ops = {
86 	fth_enum_header,
87 	fth_enum_members,
88 	fth_enum_trailer
89 };
90