2 * $Id: unit.h,v 1.3 2007/07/22 13:35:20 khansen Exp $
4 * Revision 1.3 2007/07/22 13:35:20 khansen
5 * convert tabs to whitespaces
7 * Revision 1.2 2004/12/16 13:21:07 kenth
8 * added unit parent pointer to some structs
10 * Revision 1.1 2004/06/30 07:56:49 kenth
16 * (C) 2004 Kent Hansen
18 * The XORcyst is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * The XORcyst is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with The XORcyst; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 /*---------------------------------------------------------------------------*/
37 /* Data structures. */
39 enum tag_xasm_constant_type
{
40 XASM_INTEGER_CONSTANT
=0,
44 typedef enum tag_xasm_constant_type xasm_constant_type
;
47 * Describes a constant exported from unit.
49 struct tag_xasm_constant
{
50 xasm_constant_type type
; /* *_CONSTANT */
53 long integer
; /* type == INTEGER_CONSTANT */
54 char *string
; /* type == STRING_CONSTANT */
56 struct tag_xasm_unit
*unit
; /* Owner unit */
59 typedef struct tag_xasm_constant xasm_constant
;
62 * Describes a symbol located in another unit that this unit references.
64 struct tag_xasm_external
66 unsigned char unit
; /* Unit to import from (0=any unit) (currently not used) */
68 struct tag_xasm_unit
*from
; /* Unit exported from */
71 typedef struct tag_xasm_external xasm_external
;
73 /* The possible kinds of expression */
74 enum tag_xasm_expr_type
76 XASM_OPERATOR_EXPRESSION
=0,
77 XASM_INTEGER_EXPRESSION
,
78 XASM_STRING_EXPRESSION
,
79 XASM_LOCAL_EXPRESSION
,
80 XASM_EXTERNAL_EXPRESSION
,
84 typedef enum tag_xasm_expr_type xasm_expr_type
;
86 /* Attributes of operator expression */
87 struct tag_xasm_operator_expr
89 int operator; /* See bytecode header for valid values */
90 struct tag_xasm_expression
*lhs
;
91 struct tag_xasm_expression
*rhs
;
94 typedef struct tag_xasm_operator_expr xasm_operator_expr
;
96 /** Describes an expression. */
97 struct tag_xasm_expression
101 xasm_operator_expr op_expr
; /* type == OPERATOR_EXPRESSION */
102 unsigned long integer
; /* type == INTEGER_EXPRESSION */
103 char *string
; /* type == STRING_EXPRESSION */
104 int local_id
; /* type == LOCAL_EXPRESSION */
105 int extrn_id
; /* type == EXTERNAL_EXPRESSION */
107 struct tag_xasm_unit
*unit
; /* Owner unit */
110 typedef struct tag_xasm_expression xasm_expression
;
112 /** The possible kinds of segment. */
113 enum tag_xasm_segment_type
{
118 typedef enum tag_xasm_segment_type xasm_segment_type
;
121 * A segment of a unit.
123 struct tag_xasm_segment
{
124 int size
; /* Size in bytes */
125 unsigned char *bytes
;
128 typedef struct tag_xasm_segment xasm_segment
;
133 struct tag_xasm_unit
{
134 const char *name
; /* Name of unit */
135 xasm_constant
*constants
; /* Array of exported constants */
136 int const_count
; /* Number of exported constants */
137 xasm_external
*externals
; /* Array of imported symbols */
138 int ext_count
; /* Number of imported symbols */
139 xasm_expression
**expressions
; /* Array of expressions */
140 int expr_count
; /* Number of expressions */
141 xasm_segment dataseg
; /* The data segment */
142 xasm_segment codeseg
; /* The code segment */
145 typedef struct tag_xasm_unit xasm_unit
;
147 /** Signature for procedure to process a bytecode */
148 typedef void (*xasm_bytecodeproc
)(const unsigned char *, void *);
150 /*---------------------------------------------------------------------------*/
151 /* Function prototypes. */
153 int xasm_unit_read(const char *, xasm_unit
*);
154 void xasm_unit_finalize(xasm_unit
*);
155 const char *xasm_operator_to_string(int op
);