xref: /illumos-gate/usr/src/cmd/geniconvtbl/itmcomp.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 
28 #ifndef	_ITMCOMP_H
29 #define	_ITMCOMP_H
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <stdlib.h>
36 #include "iconv_tm.h"
37 
38 
39 #define	ITMC_STATUS_SUCCESS	(0)
40 #define	ITMC_STATUS_CMD		(1)
41 #define	ITMC_STATUS_CMD2	(2)
42 #define	ITMC_STATUS_BT		(3)
43 #define	ITMC_STATUS_BT2		(4)
44 #define	ITMC_STATUS_SYS		(5)
45 #define	ITMC_STATUS_SYS2	(6)
46 
47 #define	MAXOPNEST 16
48 
49 /*
50  * exit status:
51  * ITMC_STATUS_SUCCESS
52  * ITMC_STATUS_CMD	specified options are wrong
53  * ITMC_STATUS_CMD2	cannot access specified file
54  * ITMC_STATUS_BT	Binary Table format error
55  * ITMC_STATUS_BT2	Binary Table against limitation
56  * ITMC_STATUS_SYS	resource shortage (e.g.: malloc )
57  * ITMC_STATUS_SYS2	internal error: never happen
58  */
59 
60 /*
61  * used later
62  */
63 
64 struct _itmc_ref;
65 
66 
67 /*
68  * command line option
69  */
70 
71 typedef	enum {
72 	ITMC_MAP_UNKNOWN = 0,
73 	ITMC_MAP_AUTOMATIC,
74 	ITMC_MAP_SIMPLE_INDEX,
75 	ITMC_MAP_SIMPLE_HASH,
76 	ITMC_MAP_BINARY_SEARCH,
77 	ITMC_MAP_DENSE_ENCODING
78 } itmc_map_type_t;
79 
80 
81 
82 typedef struct _itmc_map_name_type {
83 	char	*name;
84 	itmc_map_type_t			type;
85 	int				hash_factor;
86 	struct _itmc_map_name_type	*next;
87 }	itmc_map_name_type_t;
88 
89 
90 typedef struct {
91 	char		*my_name;
92 	char		**input_file;
93 	int		input_file_num;
94 	char		*output_file;
95 	char		*interpreter;
96 	char		**cpp_opt;
97 	int		cpp_opt_num;
98 	int		cpp_opt_reserved;
99 	char		*preprocess_default;
100 	char		*preprocess_specified;
101 	char		*preprocess;
102 	char		*disassemble;
103 	int		binary_search;
104 	itmc_map_name_type_t *
105 			map_name_type;
106 	int		large_table;
107 	int		force_overwrite;
108 	int		strip;
109 	int		quiet;
110 	int		no_output;
111 	char		*trace;
112 } cmd_opt_t;
113 
114 
115 /*
116  * data list
117  */
118 
119 typedef struct {
120 	void		*obj;
121 	itm_num_t	num;
122 } obj_array_t;
123 
124 typedef struct _itmc_obj {
125 	itm_type_t		type;
126 	itm_data_t		*name;
127 	void			*obj;
128 	struct _itmc_ref	*ref[3];
129 	struct _itmc_obj	*next;
130 	struct _itmc_obj	*last;
131 } itmc_obj_t;
132 
133 
134 /*
135  * data pair: used for map and range
136  */
137 
138 typedef itm_data_t itmc_map_range_t;
139 typedef struct {
140 	itm_data_t	data0;
141 	itm_data_t	data1;
142 	itmc_map_range_t	range;
143 } itmc_data_pair_t;
144 
145 
146 /*
147  * map pair list
148  */
149 typedef struct _itmc_map {
150 	itmc_data_pair_t	data_pair;
151 	struct _itmc_map	*next;
152 	struct _itmc_map	*last;
153 } itmc_map_t;
154 
155 
156 /*
157  * cross reference: used for relocation
158  */
159 
160 typedef struct _itmc_ref_link {
161 	struct _itmc_ref	*ref;
162 	struct _itmc_ref_link	*next;
163 } itmc_ref_link_t;
164 
165 typedef struct _itmc_name {
166 	itm_num_t		id;
167 	itm_num_t		reg_id;
168 	itm_data_t		name;
169 	itm_type_t		type;
170 	struct _itmc_ref	*object;
171 	itm_place_t		reloc;
172 	itmc_ref_link_t		*ref_first;
173 	itmc_ref_link_t		*ref_last;
174 	struct _itmc_name	*next;
175 } itmc_name_t;
176 
177 typedef struct _itmc_ref {
178 	itmc_name_t		*name;
179 	void			*referencee;
180 	itm_place_t		reloc;
181 	itm_size_t		size;
182 	itm_place_t		*referencer;
183 	struct _itmc_ref	*next;
184 	int			vertex_index;
185 } itmc_ref_t;
186 
187 
188 /*
189  * action
190  */
191 typedef struct {
192 	itm_type_t	type;
193 	itm_tbl_hdr_t	*tbl_hdr;
194 } itmc_action_t;
195 
196 /*
197  * map attribute
198  */
199 typedef struct {
200 	itm_size_t	resultlen;
201 	itm_data_t	*type;
202 	int		hash_factor;
203 } itmc_map_attr_t;
204 
205 
206 /*
207  *	operation hierarchy
208  */
209 typedef struct itm_opt_outer {
210 	struct itm_opt_outer	*link;
211 	struct itm_opt_inner	*in;
212 	itm_tbl_hdr_t		*optbl; /* operation object address */
213 	itmc_ref_t		*ref; /* corresponding object's ref */
214 } itm_op_outer_t;
215 typedef struct itm_opt_inner {
216 	struct itm_opt_inner	*in;
217 	itmc_ref_t		*ref; /* corresponding object's ref */
218 } itm_op_inner_t;
219 
220 
221 /*
222  * itm compiler object type
223  */
224 
225 #define	ITMC_OBJ_NONE		(0)
226 #define	ITMC_OBJ_FIRST		(1)
227 #define	ITMC_OBJ_ITM		(1)
228 #define	ITMC_OBJ_STRING		(2)
229 #define	ITMC_OBJ_DIREC		(3)
230 #define	ITMC_OBJ_COND		(4)
231 #define	ITMC_OBJ_MAP		(5)
232 #define	ITMC_OBJ_OP		(6)
233 #define	ITMC_OBJ_EXPR		(7)
234 #define	ITMC_OBJ_DATA		(8)
235 #define	ITMC_OBJ_ACTION		(9)
236 #define	ITMC_OBJ_RANGE		(10)
237 #define	ITMC_OBJ_REGISTER	(11)
238 #define	ITMC_OBJ_ESCAPESEQ	(12)
239 #define	ITMC_OBJ_LAST		(12)
240 
241 
242 /*
243  * global variable
244  */
245 
246 extern itmc_ref_t	*ref_first[ITMC_OBJ_LAST + 1];
247 extern itmc_ref_t	*ref_last[ITMC_OBJ_LAST + 1];
248 
249 extern itmc_name_t	*name_first;
250 extern itmc_name_t	*name_last;
251 
252 extern itm_num_t	name_id;
253 extern itm_num_t	reg_id;
254 
255 extern itmc_name_t	name_lookup_error;
256 extern int		error_deferred;
257 
258 extern cmd_opt_t	cmd_opt;
259 extern char		*itm_input_file;
260 extern char		*itm_output_file;
261 
262 extern struct itm_opt_outer *itm_op_outer;
263 /*
264  * macro definition
265  */
266 
267 #define	NSPTR(n)	(((n)->size <= (sizeof ((n)->place))) ?	\
268 				((void *)(&((n)->place.itm_64d))) : \
269 				((void *)((n)->place.itm_ptr)))
270 #if !defined(ROUNDUP)
271 #define	 ROUNDUP(a, n)	 (((a) + ((n) - 1)) & ~((n) - 1))
272 #endif
273 #define	ITMROUNDUP(i)	ROUNDUP(i, sizeof (uint64_t))
274 
275 
276 /*
277  * trace
278  */
279 
280 #if defined(ENABLE_TRACE)
281 #define	TRACE(c)	((cmd_opt.trace != 0) && \
282 			(0 != *(cmd_opt.trace + (c & 0x007f))))
283 #define	TRACE_MESSAGE(c, args)	((TRACE(c))? trace_message args: (void)0)
284 #else
285 #define	TRACE(c)
286 #define	TRACE_MESSAGE(c, args)
287 #endif
288 
289 /*
290  * error
291  */
292 #define	PERROR(s)	if (cmd_opt.quiet == 0) perror(s)
293 
294 /*
295  * function prototype
296  */
297 
298 extern int	assemble(itm_hdr_t *);
299 extern void	disassemble(char *);
300 
301 extern void	*malloc_vital(size_t);
302 
303 extern char	*name_to_str(itm_data_t *);
304 extern char	*data_to_hexadecimal(itm_data_t *);
305 extern itm_data_t	*str_to_data(int, char *);
306 
307 #if defined(ENABLE_TRACE)
308 extern void	dump_itm_header(itm_hdr_t *, itm_info_hdr_t *);
309 
310 extern void	trace_message(char *, ...);
311 #endif
312 
313 extern char	*itm_name_type_name[];
314 extern void	itm_error(char *format, ...);
315 #ifdef	__cplusplus
316 }
317 #endif
318 
319 #endif /* !_ITMCOMP_H */
320