xref: /illumos-gate/usr/src/tools/ndrgen/ndrgen.h (revision 2c65701281156d8db8fa6f6f9c5faa6ca021c621)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright 2020 Tintri by DDN, Inc. All rights reserved.
29  */
30 
31 #ifndef _NDRGEN_H
32 #define	_NDRGEN_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <assert.h>
42 
43 typedef struct node {
44 	int		label;
45 	int		line_number;
46 	struct symbol	*file_name;
47 	struct node	*n_next;		/* handy for lists */
48 
49 	union {
50 		struct symbol		*nu_sym;
51 		unsigned long		nu_int;
52 		char			*nu_str;
53 		void			*nu_ptr;
54 		struct node		*nu_node[4];	/* descendents */
55 		void			*nu_arg[4];	/* utility */
56 	}	n_u;
57 #define	n_ptr n_u.nu_ptr
58 #define	n_sym n_u.nu_sym
59 #define	n_str n_u.nu_str
60 #define	n_int n_u.nu_int
61 #define	n_arg n_u.nu_arg
62 #define	n_node n_u.nu_node
63 
64 #define	n_c_advice	n_node[0]
65 #define	n_c_typename	n_node[1]
66 #define	n_c_members	n_node[2]
67 
68 #define	n_m_advice	n_node[0]
69 #define	n_m_type	n_node[1]
70 #define	n_m_decl	n_node[2]
71 #define	n_m_name	n_node[3]
72 
73 #define	n_a_arg		n_node[0]
74 #define	n_a_arg1	n_node[1]
75 #define	n_a_arg2	n_node[2]
76 
77 #define	n_d_descend	n_node[0]
78 #define	n_d_dim		n_node[1]
79 } ndr_node_t;
80 
81 typedef struct keyword {
82 	char		*name;
83 	int		token;
84 	long		value;
85 } ndr_keyword_t;
86 
87 typedef struct symbol {
88 	struct symbol	*next;
89 	char		*name;
90 	ndr_keyword_t	*kw;
91 	struct node	*typedefn;
92 	struct node	s_node;
93 } ndr_symbol_t;
94 
95 typedef struct integer {
96 	struct integer	*next;
97 	long		value;
98 	struct node	s_node;
99 } ndr_integer_t;
100 
101 #define	NDLBUFSZ	100
102 
103 /* This makes certain things much easier */
104 #define	N_ADVICE	19
105 
106 typedef struct advice {
107 	struct node		*a_nodes[N_ADVICE];
108 
109 /* alias for basic types */
110 #define	a_transmit_as	a_nodes[0]
111 
112 /* arg used for size, union or generic purpose */
113 #define	a_arg_is	a_nodes[1]
114 
115 /* operation parameter in/out stuff */
116 #define	a_operation	a_nodes[2]
117 #define	a_in		a_nodes[3]
118 #define	a_out		a_nodes[4]
119 
120 /* size stuff */
121 #define	a_string	a_nodes[5]
122 #define	a_size_is	a_nodes[6]
123 #define	a_length_is	a_nodes[7]
124 
125 /* union stuff */
126 #define	a_case		a_nodes[8]
127 #define	a_default	a_nodes[9]
128 #define	a_switch_is	a_nodes[10]
129 
130 /* interface stuff */
131 #define	a_interface	a_nodes[11]
132 #define	a_uuid		a_nodes[12]
133 #define	a_no_reorder	a_nodes[13]
134 #define	a_extern	a_nodes[14]
135 #define	a_reference	a_nodes[15]
136 #define	a_align		a_nodes[16]
137 #define	a_fake		a_nodes[17]
138 } ndr_advice_t;
139 
140 typedef struct typeinfo {
141 	struct typeinfo		*next;
142 
143 	unsigned int		alignment	: 3;	/* mask */
144 	unsigned int		is_conformant	: 1;
145 	unsigned int		is_varying	: 1;
146 	unsigned int		is_string	: 1;
147 	unsigned int		max_given	: 1;
148 	unsigned int		min_given	: 1;
149 	unsigned int		complete	: 1;
150 	unsigned int		has_pointers	: 1;
151 	unsigned int		is_referenced	: 1;
152 	unsigned int		is_extern	: 1;
153 
154 	unsigned short		type_op;	/* STAR LB */
155 						/* STRUCT BASIC_TYPE */
156 	struct node		*type_dim;	/* for LB */
157 	struct typeinfo		*type_down;	/* for STAR LB */
158 	struct node		*definition;
159 	struct node		*type_name;	/* symbol */
160 	ndr_advice_t		advice;
161 	unsigned int		size_fixed_part;
162 	unsigned int		size_variable_part;
163 
164 	/* size_is(n_members) */
165 	struct member		*member;		/* array */
166 	int			n_member;
167 } ndr_typeinfo_t;
168 
169 typedef struct member {
170 	char			*name;
171 	struct typeinfo		*type;
172 	int			is_conformant;
173 	struct node		*definition;
174 	ndr_advice_t		advice;
175 	unsigned int		pdu_offset;
176 } ndr_member_t;
177 
178 extern ndr_typeinfo_t	*typeinfo_list;
179 extern struct node	*construct_list;
180 
181 /* ndr_anal.c */
182 extern void	analyze(void);
183 extern void	show_typeinfo_list(void);
184 extern void	type_extern_suffix(ndr_typeinfo_t *, char *, size_t);
185 extern void	type_null_decl(ndr_typeinfo_t *, char *, size_t);
186 extern void	type_name_decl(ndr_typeinfo_t *, char *, size_t, char *);
187 extern void	show_advice(ndr_advice_t *, int);
188 extern void	member_fixup(ndr_node_t *);
189 extern void	construct_fixup(ndr_node_t *);
190 
191 /* ndr_gen.c */
192 extern void	generate(void);
193 
194 /* ndr_lex.c */
195 extern ndr_symbol_t	*symbol_list;
196 extern int		line_number;
197 extern int		n_compile_error;
198 extern struct node	*yylval;
199 extern void		set_lex_input(FILE *, char *);
200 extern int		yylex(void);
201 extern void *		ndr_alloc(size_t nelem, size_t elsize);
202 extern void		compile_error(const char *, ...);
203 extern void		fatal_error(const char *, ...);
204 extern struct node	*n_cons(int, ...);
205 extern void		n_splice(struct node *, struct node *);
206 
207 /* ndr_print.c */
208 extern void	tdata_dump(void);
209 extern void	print_node(ndr_node_t *);
210 extern void	print_field_attr(ndr_node_t *);
211 
212 /* ndr_parse.y */
213 extern int	yyparse(void);
214 
215 /* ndr_main.c */
216 extern int	yyerror(char *);
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif /* _NDRGEN_H */
223