update configure stuff
[xorcyst.git] / unit.h
blob54c8e898b8653647f18c535c400b6d7b3431efc1
1 /*
2 * $Id: unit.h,v 1.3 2007/07/22 13:35:20 khansen Exp $
3 * $Log: unit.h,v $
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
11 * Initial revision
15 /**
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
33 #ifndef UNIT_H
34 #define UNIT_H
36 /*---------------------------------------------------------------------------*/
37 /* Data structures. */
39 enum tag_constant_type {
40 INTEGER_CONSTANT=0,
41 STRING_CONSTANT
44 typedef enum tag_constant_type constant_type;
46 /**
47 * Describes a constant exported from unit.
49 struct tag_constant {
50 constant_type type; /* *_CONSTANT */
51 char *name;
52 union {
53 long integer; /* type == INTEGER_CONSTANT */
54 char *string; /* type == STRING_CONSTANT */
56 struct tag_unit *unit; /* Owner unit */
59 typedef struct tag_constant constant;
61 /**
62 * Describes a symbol located in another unit that this unit references.
64 struct tag_external
66 unsigned char unit;
67 char *name;
68 struct tag_unit *from; /* Unit exported from */
71 typedef struct tag_external external;
73 /* The possible kinds of expression */
74 enum tag_expr_type
76 OPERATOR_EXPRESSION=0,
77 INTEGER_EXPRESSION,
78 STRING_EXPRESSION,
79 LOCAL_EXPRESSION,
80 EXTERNAL_EXPRESSION,
81 PC_EXPRESSION
84 typedef enum tag_expr_type expr_type;
86 /* Attributes of operator expression */
87 struct tag_operator_expr
89 int operator; /* See bytecode header for valid values */
90 struct tag_expression *lhs;
91 struct tag_expression *rhs;
94 typedef struct tag_operator_expr operator_expr;
96 /** Describes an expression. */
97 struct tag_expression
99 expr_type type;
100 union {
101 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_unit *unit; /* Owner unit */
110 typedef struct tag_expression expression;
112 /** The possible kinds of segment. */
113 enum tag_segment_type {
114 DATA_SEGMENT=0,
115 CODE_SEGMENT
118 typedef enum tag_segment_type segment_type;
121 * A segment of a unit.
123 struct tag_segment {
124 int size; /* Size in bytes */
125 unsigned char *bytes;
128 typedef struct tag_segment segment;
131 * Describes a unit.
133 struct tag_unit {
134 char *name; /* Name of unit */
135 constant *constants; /* Array of exported constants */
136 int const_count; /* Number of exported constants */
137 external *externals; /* Array of imported symbols */
138 int ext_count; /* Number of imported symbols */
139 expression **expressions; /* Array of expressions */
140 int expr_count; /* Number of expressions */
141 segment dataseg; /* The data segment */
142 segment codeseg; /* The code segment */
145 typedef struct tag_unit unit;
147 /*---------------------------------------------------------------------------*/
148 /* Function prototypes. */
150 int unit_read(char *, unit *);
151 void unit_finalize(unit *);
153 #endif /* !UNIT_H */