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