17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc.
247c478bdstevel@tonic-gate * All rights reserved.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate#ifndef	_ITMCOMP_H
297c478bdstevel@tonic-gate#define	_ITMCOMP_H
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bdstevel@tonic-gate
337c478bdstevel@tonic-gate#ifdef	__cplusplus
347c478bdstevel@tonic-gateextern "C" {
357c478bdstevel@tonic-gate#endif
367c478bdstevel@tonic-gate
377c478bdstevel@tonic-gate#include <stdlib.h>
387c478bdstevel@tonic-gate#include "iconv_tm.h"
397c478bdstevel@tonic-gate
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gate#define	ITMC_STATUS_SUCCESS	(0)
427c478bdstevel@tonic-gate#define	ITMC_STATUS_CMD		(1)
437c478bdstevel@tonic-gate#define	ITMC_STATUS_CMD2	(2)
447c478bdstevel@tonic-gate#define	ITMC_STATUS_BT		(3)
457c478bdstevel@tonic-gate#define	ITMC_STATUS_BT2		(4)
467c478bdstevel@tonic-gate#define	ITMC_STATUS_SYS		(5)
477c478bdstevel@tonic-gate#define	ITMC_STATUS_SYS2	(6)
487c478bdstevel@tonic-gate
497c478bdstevel@tonic-gate#define	MAXOPNEST 16
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gate/*
527c478bdstevel@tonic-gate * exit status:
537c478bdstevel@tonic-gate * ITMC_STATUS_SUCCESS
547c478bdstevel@tonic-gate * ITMC_STATUS_CMD	specified options are wrong
557c478bdstevel@tonic-gate * ITMC_STATUS_CMD2	cannot access specified file
567c478bdstevel@tonic-gate * ITMC_STATUS_BT	Binary Table format error
577c478bdstevel@tonic-gate * ITMC_STATUS_BT2	Binary Table against limitation
587c478bdstevel@tonic-gate * ITMC_STATUS_SYS	resource shortage (e.g.: malloc )
597c478bdstevel@tonic-gate * ITMC_STATUS_SYS2	internal error: never happen
607c478bdstevel@tonic-gate */
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gate/*
637c478bdstevel@tonic-gate * used later
647c478bdstevel@tonic-gate */
657c478bdstevel@tonic-gate
667c478bdstevel@tonic-gatestruct _itmc_ref;
677c478bdstevel@tonic-gate
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate/*
707c478bdstevel@tonic-gate * command line option
717c478bdstevel@tonic-gate */
727c478bdstevel@tonic-gate
737c478bdstevel@tonic-gatetypedef	enum {
747c478bdstevel@tonic-gate	ITMC_MAP_UNKNOWN = 0,
757c478bdstevel@tonic-gate	ITMC_MAP_AUTOMATIC,
767c478bdstevel@tonic-gate	ITMC_MAP_SIMPLE_INDEX,
777c478bdstevel@tonic-gate	ITMC_MAP_SIMPLE_HASH,
787c478bdstevel@tonic-gate	ITMC_MAP_BINARY_SEARCH,
797c478bdstevel@tonic-gate	ITMC_MAP_DENSE_ENCODING
807c478bdstevel@tonic-gate} itmc_map_type_t;
817c478bdstevel@tonic-gate
827c478bdstevel@tonic-gate
837c478bdstevel@tonic-gate
847c478bdstevel@tonic-gatetypedef struct _itmc_map_name_type {
857c478bdstevel@tonic-gate	char	*name;
867c478bdstevel@tonic-gate	itmc_map_type_t			type;
877c478bdstevel@tonic-gate	int				hash_factor;
887c478bdstevel@tonic-gate	struct _itmc_map_name_type	*next;
897c478bdstevel@tonic-gate}	itmc_map_name_type_t;
907c478bdstevel@tonic-gate
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gatetypedef struct {
937c478bdstevel@tonic-gate	char		*my_name;
947c478bdstevel@tonic-gate	char		**input_file;
957c478bdstevel@tonic-gate	int		input_file_num;
967c478bdstevel@tonic-gate	char		*output_file;
977c478bdstevel@tonic-gate	char		*interpreter;
987c478bdstevel@tonic-gate	char		**cpp_opt;
997c478bdstevel@tonic-gate	int		cpp_opt_num;
1007c478bdstevel@tonic-gate	int		cpp_opt_reserved;
1017c478bdstevel@tonic-gate	char		*preprocess_default;
1027c478bdstevel@tonic-gate	char		*preprocess_specified;
1037c478bdstevel@tonic-gate	char		*preprocess;
1047c478bdstevel@tonic-gate	char		*disassemble;
1057c478bdstevel@tonic-gate	int		binary_search;
1067c478bdstevel@tonic-gate	itmc_map_name_type_t *
1077c478bdstevel@tonic-gate			map_name_type;
1087c478bdstevel@tonic-gate	int		large_table;
1097c478bdstevel@tonic-gate	int		force_overwrite;
1107c478bdstevel@tonic-gate	int		strip;
1117c478bdstevel@tonic-gate	int		quiet;
1127c478bdstevel@tonic-gate	int		no_output;
1137c478bdstevel@tonic-gate	char		*trace;
1147c478bdstevel@tonic-gate} cmd_opt_t;
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gate
1177c478bdstevel@tonic-gate/*
1187c478bdstevel@tonic-gate * data list
1197c478bdstevel@tonic-gate */
1207c478bdstevel@tonic-gate
1217c478bdstevel@tonic-gatetypedef struct {
1227c478bdstevel@tonic-gate	void		*obj;
1237c478bdstevel@tonic-gate	itm_num_t	num;
1247c478bdstevel@tonic-gate} obj_array_t;
1257c478bdstevel@tonic-gate
1267c478bdstevel@tonic-gatetypedef struct _itmc_obj {
1277c478bdstevel@tonic-gate	itm_type_t		type;
1287c478bdstevel@tonic-gate	itm_data_t		*name;
1297c478bdstevel@tonic-gate	void			*obj;
1307c478bdstevel@tonic-gate	struct _itmc_ref	*ref[3];
1317c478bdstevel@tonic-gate	struct _itmc_obj	*next;
1327c478bdstevel@tonic-gate	struct _itmc_obj	*last;
1337c478bdstevel@tonic-gate} itmc_obj_t;
1347c478bdstevel@tonic-gate
1357c478bdstevel@tonic-gate
1367c478bdstevel@tonic-gate/*
1377c478bdstevel@tonic-gate * data pair: used for map and range
1387c478bdstevel@tonic-gate */
1397c478bdstevel@tonic-gate
1407c478bdstevel@tonic-gatetypedef itm_data_t itmc_map_range_t;
1417c478bdstevel@tonic-gatetypedef struct {
1427c478bdstevel@tonic-gate	itm_data_t	data0;
1437c478bdstevel@tonic-gate	itm_data_t	data1;
1447c478bdstevel@tonic-gate	itmc_map_range_t	range;
1457c478bdstevel@tonic-gate} itmc_data_pair_t;
1467c478bdstevel@tonic-gate
1477c478bdstevel@tonic-gate
1487c478bdstevel@tonic-gate/*
1497c478bdstevel@tonic-gate * map pair list
1507c478bdstevel@tonic-gate */
1517c478bdstevel@tonic-gatetypedef struct _itmc_map {
1527c478bdstevel@tonic-gate	itmc_data_pair_t	data_pair;
1537c478bdstevel@tonic-gate	struct _itmc_map	*next;
1547c478bdstevel@tonic-gate	struct _itmc_map	*last;
1557c478bdstevel@tonic-gate} itmc_map_t;
1567c478bdstevel@tonic-gate
1577c478bdstevel@tonic-gate
1587c478bdstevel@tonic-gate/*
1597c478bdstevel@tonic-gate * cross reference: used for relocation
1607c478bdstevel@tonic-gate */
1617c478bdstevel@tonic-gate
1627c478bdstevel@tonic-gatetypedef struct _itmc_ref_link {
1637c478bdstevel@tonic-gate	struct _itmc_ref	*ref;
1647c478bdstevel@tonic-gate	struct _itmc_ref_link	*next;
1657c478bdstevel@tonic-gate} itmc_ref_link_t;
1667c478bdstevel@tonic-gate
1677c478bdstevel@tonic-gatetypedef struct _itmc_name {
1687c478bdstevel@tonic-gate	itm_num_t		id;
1697c478bdstevel@tonic-gate	itm_num_t		reg_id;
1707c478bdstevel@tonic-gate	itm_data_t		name;
1717c478bdstevel@tonic-gate	itm_type_t		type;
1727c478bdstevel@tonic-gate	struct _itmc_ref	*object;
1737c478bdstevel@tonic-gate	itm_place_t		reloc;
1747c478bdstevel@tonic-gate	itmc_ref_link_t		*ref_first;
1757c478bdstevel@tonic-gate	itmc_ref_link_t		*ref_last;
1767c478bdstevel@tonic-gate	struct _itmc_name	*next;
1777c478bdstevel@tonic-gate} itmc_name_t;
1787c478bdstevel@tonic-gate
1797c478bdstevel@tonic-gatetypedef struct _itmc_ref {
1807c478bdstevel@tonic-gate	itmc_name_t		*name;
1817c478bdstevel@tonic-gate	void			*referencee;
1827c478bdstevel@tonic-gate	itm_place_t		reloc;
1837c478bdstevel@tonic-gate	itm_size_t		size;
1847c478bdstevel@tonic-gate	itm_place_t		*referencer;
1857c478bdstevel@tonic-gate	struct _itmc_ref	*next;
1867c478bdstevel@tonic-gate	int			vertex_index;
1877c478bdstevel@tonic-gate} itmc_ref_t;
1887c478bdstevel@tonic-gate
1897c478bdstevel@tonic-gate
1907c478bdstevel@tonic-gate/*
1917c478bdstevel@tonic-gate * action
1927c478bdstevel@tonic-gate */
1937c478bdstevel@tonic-gatetypedef struct {
1947c478bdstevel@tonic-gate	itm_type_t	type;
1957c478bdstevel@tonic-gate	itm_tbl_hdr_t	*tbl_hdr;
1967c478bdstevel@tonic-gate} itmc_action_t;
1977c478bdstevel@tonic-gate
1987c478bdstevel@tonic-gate/*
1997c478bdstevel@tonic-gate * map attribute
2007c478bdstevel@tonic-gate */
2017c478bdstevel@tonic-gatetypedef struct {
2027c478bdstevel@tonic-gate	itm_size_t	resultlen;
2037c478bdstevel@tonic-gate	itm_data_t	*type;
2047c478bdstevel@tonic-gate	int		hash_factor;
2057c478bdstevel@tonic-gate} itmc_map_attr_t;
2067c478bdstevel@tonic-gate
2077c478bdstevel@tonic-gate
2087c478bdstevel@tonic-gate/*
2097c478bdstevel@tonic-gate *	operation hierarchy
2107c478bdstevel@tonic-gate */
2117c478bdstevel@tonic-gatetypedef struct itm_opt_outer {
2127c478bdstevel@tonic-gate	struct itm_opt_outer	*link;
2137c478bdstevel@tonic-gate	struct itm_opt_inner	*in;
2147c478bdstevel@tonic-gate	itm_tbl_hdr_t		*optbl; /* operation object address */
2157c478bdstevel@tonic-gate	itmc_ref_t		*ref; /* corresponding object's ref */
2167c478bdstevel@tonic-gate} itm_op_outer_t;
2177c478bdstevel@tonic-gatetypedef struct itm_opt_inner {
2187c478bdstevel@tonic-gate	struct itm_opt_inner	*in;
2197c478bdstevel@tonic-gate	itmc_ref_t		*ref; /* corresponding object's ref */
2207c478bdstevel@tonic-gate} itm_op_inner_t;
2217c478bdstevel@tonic-gate
2227c478bdstevel@tonic-gate
2237c478bdstevel@tonic-gate/*
2247c478bdstevel@tonic-gate * itm compiler object type
2257c478bdstevel@tonic-gate */
2267c478bdstevel@tonic-gate
2277c478bdstevel@tonic-gate#define	ITMC_OBJ_NONE		(0)
2287c478bdstevel@tonic-gate#define	ITMC_OBJ_FIRST		(1)
2297c478bdstevel@tonic-gate#define	ITMC_OBJ_ITM		(1)
2307c478bdstevel@tonic-gate#define	ITMC_OBJ_STRING		(2)
2317c478bdstevel@tonic-gate#define	ITMC_OBJ_DIREC		(3)
2327c478bdstevel@tonic-gate#define	ITMC_OBJ_COND		(4)
2337c478bdstevel@tonic-gate#define	ITMC_OBJ_MAP		(5)
2347c478bdstevel@tonic-gate#define	ITMC_OBJ_OP		(6)
2357c478bdstevel@tonic-gate#define	ITMC_OBJ_EXPR		(7)
2367c478bdstevel@tonic-gate#define	ITMC_OBJ_DATA		(8)
2377c478bdstevel@tonic-gate#define	ITMC_OBJ_ACTION		(9)
2387c478bdstevel@tonic-gate#define	ITMC_OBJ_RANGE		(10)
2397c478bdstevel@tonic-gate#define	ITMC_OBJ_REGISTER	(11)
2407c478bdstevel@tonic-gate#define	ITMC_OBJ_ESCAPESEQ	(12)
2417c478bdstevel@tonic-gate#define	ITMC_OBJ_LAST		(12)
2427c478bdstevel@tonic-gate
2437c478bdstevel@tonic-gate
2447c478bdstevel@tonic-gate/*
2457c478bdstevel@tonic-gate * global variable
2467c478bdstevel@tonic-gate */
2477c478bdstevel@tonic-gate
2487c478bdstevel@tonic-gateextern itmc_ref_t	*ref_first[ITMC_OBJ_LAST + 1];
2497c478bdstevel@tonic-gateextern itmc_ref_t	*ref_last[ITMC_OBJ_LAST + 1];
2507c478bdstevel@tonic-gate
2517c478bdstevel@tonic-gateextern itmc_name_t	*name_first;
2527c478bdstevel@tonic-gateextern itmc_name_t	*name_last;
2537c478bdstevel@tonic-gate
2547c478bdstevel@tonic-gateextern itm_num_t	name_id;
2557c478bdstevel@tonic-gateextern itm_num_t	reg_id;
2567c478bdstevel@tonic-gate
2577c478bdstevel@tonic-gateextern itmc_name_t	name_lookup_error;
2587c478bdstevel@tonic-gateextern int		error_deferred;
2597c478bdstevel@tonic-gate
2607c478bdstevel@tonic-gateextern cmd_opt_t	cmd_opt;
2617c478bdstevel@tonic-gateextern char		*itm_input_file;
2627c478bdstevel@tonic-gateextern char		*itm_output_file;
2637c478bdstevel@tonic-gate
2647c478bdstevel@tonic-gateextern struct itm_opt_outer *itm_op_outer;
2657c478bdstevel@tonic-gate/*
2667c478bdstevel@tonic-gate * macro definition
2677c478bdstevel@tonic-gate */
2687c478bdstevel@tonic-gate
2697c478bdstevel@tonic-gate#define	NSPTR(n)	(((n)->size <= (sizeof ((n)->place))) ?	\
2707c478bdstevel@tonic-gate				((void *)(&((n)->place.itm_64d))) : \
2717c478bdstevel@tonic-gate				((void *)((n)->place.itm_ptr)))
2727c478bdstevel@tonic-gate#if !defined(ROUNDUP)
2737c478bdstevel@tonic-gate#define	 ROUNDUP(a, n)	 (((a) + ((n) - 1)) & ~((n) - 1))
2747c478bdstevel@tonic-gate#endif
2757c478bdstevel@tonic-gate#define	ITMROUNDUP(i)	ROUNDUP(i, sizeof (uint64_t))
2767c478bdstevel@tonic-gate
2777c478bdstevel@tonic-gate
2787c478bdstevel@tonic-gate/*
2797c478bdstevel@tonic-gate * trace
2807c478bdstevel@tonic-gate */
2817c478bdstevel@tonic-gate
2827c478bdstevel@tonic-gate#if defined(ENABLE_TRACE)
2837c478bdstevel@tonic-gate#define	TRACE(c)	((cmd_opt.trace != 0) && \
2847c478bdstevel@tonic-gate			(0 != *(cmd_opt.trace + (c & 0x007f))))
2857c478bdstevel@tonic-gate#define	TRACE_MESSAGE(c, args)	((TRACE(c))? trace_message args: (void)0)
2867c478bdstevel@tonic-gate#else
2877c478bdstevel@tonic-gate#define	TRACE(c)
2887c478bdstevel@tonic-gate#define	TRACE_MESSAGE(c, args)
2897c478bdstevel@tonic-gate#endif
2907c478bdstevel@tonic-gate
2917c478bdstevel@tonic-gate/*
2927c478bdstevel@tonic-gate * error
2937c478bdstevel@tonic-gate */
2947c478bdstevel@tonic-gate#define	PERROR(s)	if (cmd_opt.quiet == 0) perror(s)
2957c478bdstevel@tonic-gate
2967c478bdstevel@tonic-gate/*
2977c478bdstevel@tonic-gate * function prototype
2987c478bdstevel@tonic-gate */
2997c478bdstevel@tonic-gate
3007c478bdstevel@tonic-gateextern int	assemble(itm_hdr_t *);
3017c478bdstevel@tonic-gateextern void	disassemble(char *);
3027c478bdstevel@tonic-gate
3037c478bdstevel@tonic-gateextern void	*malloc_vital(size_t);
3047c478bdstevel@tonic-gate
3057c478bdstevel@tonic-gateextern char	*name_to_str(itm_data_t *);
3067c478bdstevel@tonic-gateextern char	*data_to_hexadecimal(itm_data_t *);
3077c478bdstevel@tonic-gateextern itm_data_t	*str_to_data(int, char *);
3087c478bdstevel@tonic-gate
3097c478bdstevel@tonic-gate#if defined(ENABLE_TRACE)
3107c478bdstevel@tonic-gateextern void	dump_itm_header(itm_hdr_t *, itm_info_hdr_t *);
3117c478bdstevel@tonic-gate
3127c478bdstevel@tonic-gateextern void	trace_message(char *, ...);
3137c478bdstevel@tonic-gate#endif
3147c478bdstevel@tonic-gate
3157c478bdstevel@tonic-gateextern char	*itm_name_type_name[];
3167c478bdstevel@tonic-gateextern void	itm_error(char *format, ...);
3177c478bdstevel@tonic-gate#ifdef	__cplusplus
3187c478bdstevel@tonic-gate}
3197c478bdstevel@tonic-gate#endif
3207c478bdstevel@tonic-gate
3217c478bdstevel@tonic-gate#endif /* !_ITMCOMP_H */
322