Merge branch 'cleanups'
[unleashed.git] / usr / src / cmd / geniconvtbl / itmcomp.h
blobf4df9d17d27c0281a742278134676af4f351ff93
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
28 #ifndef _ITMCOMP_H
29 #define _ITMCOMP_H
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
37 #include <stdlib.h>
38 #include "iconv_tm.h"
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)
49 #define MAXOPNEST 16
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
63 * used later
66 struct _itmc_ref;
70 * command line option
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;
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;
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;
118 * data list
121 typedef struct {
122 void *obj;
123 itm_num_t num;
124 } obj_array_t;
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;
137 * data pair: used for map and range
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;
149 * map pair list
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;
159 * cross reference: used for relocation
162 typedef struct _itmc_ref_link {
163 struct _itmc_ref *ref;
164 struct _itmc_ref_link *next;
165 } itmc_ref_link_t;
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;
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;
191 * action
193 typedef struct {
194 itm_type_t type;
195 itm_tbl_hdr_t *tbl_hdr;
196 } itmc_action_t;
199 * map attribute
201 typedef struct {
202 itm_size_t resultlen;
203 itm_data_t *type;
204 int hash_factor;
205 } itmc_map_attr_t;
209 * operation hierarchy
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;
224 * itm compiler object type
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)
245 * global variable
248 extern itmc_ref_t *ref_first[ITMC_OBJ_LAST + 1];
249 extern itmc_ref_t *ref_last[ITMC_OBJ_LAST + 1];
251 extern itmc_name_t *name_first;
252 extern itmc_name_t *name_last;
254 extern itm_num_t name_id;
255 extern itm_num_t reg_id;
257 extern itmc_name_t name_lookup_error;
258 extern int error_deferred;
260 extern cmd_opt_t cmd_opt;
261 extern char *itm_input_file;
262 extern char *itm_output_file;
264 extern struct itm_opt_outer *itm_op_outer;
266 * macro definition
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))
279 * trace
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
292 * error
294 #define PERROR(s) if (cmd_opt.quiet == 0) perror(s)
297 * function prototype
300 extern int assemble(itm_hdr_t *);
301 extern void disassemble(char *);
303 extern void *malloc_vital(size_t);
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 *);
309 #if defined(ENABLE_TRACE)
310 extern void dump_itm_header(itm_hdr_t *, itm_info_hdr_t *);
312 extern void trace_message(char *, ...);
313 #endif
315 extern char *itm_name_type_name[];
316 extern void itm_error(char *format, ...);
317 #ifdef __cplusplus
319 #endif
321 #endif /* !_ITMCOMP_H */