forked from lamproae/ncc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglobal.h
356 lines (312 loc) · 7.07 KB
/
global.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#include "config.h"
#include "norm.h"
#include "mem_pool.h"
#define MSPEC 20
#define BITFIELD_Q 64
#define COLS "\033[01;37m"
#define COLE "\033[0m"
#define PRINTF(...) fprintf (report_stream, __VA_ARGS__)
extern FILE *report_stream;
//
// the types we'll be using
//
typedef int NormPtr;
typedef int RegionPtr, ObjPtr, typeID, ArglPtr, Symbol, *Vspec;
typedef int exprID;
//
// preprocessing
//
extern void preproc (int, char**);
extern void ncc_keys ();
//
// program options
//
extern bool usage_only, include_values, include_strings, multiple, abs_paths,
report_structs, halt_on_error, pseudo_code, no_error;
extern char *sourcefile, *preprocfile, *cwd;
//
// inform
//
extern char* StrDup (char*);
extern void debug (const char*, NormPtr, int);
extern void prcode (NormPtr, int);
extern void prcode (NormPtr, int, Symbol[]);
extern void prcode (NormPtr, int, Symbol);
extern void printtype (int, int*);
extern void printtype (typeID);
extern int syntax_error (NormPtr, char* = NULL);
extern int syntax_error (char*, char*);
extern int syntax_error (NormPtr, char*, char*);
extern void half_error (char*, char* = NULL);
extern void warning (char*, char = 0);
extern char *expand (int);
extern int cline_of (NormPtr);
extern int cfile_of (NormPtr);
extern char *in_file (NormPtr);
extern void report_error ();
class EXPR_ERROR {public: EXPR_ERROR () {}};
//
// lex & normalized C source
//
struct token
{
int at_line;
unsigned int type;
char *p;
int len;
};
extern token CTok;
struct cfile_i
{
int indx;
char *file;
};
struct clines_i
{
int ftok, line;
};
extern int* CODE;
extern int C_Ntok;
extern char** C_Syms;
extern int C_Nsyms;
extern char** C_Strings;
extern int C_Nstrings;
extern cfile_i* C_Files;
extern int C_Nfiles;
extern clines_i* C_Lines;
extern int C_Nlines;
extern double* C_Floats;
extern signed char* C_Chars;
extern short int* C_Shortints;
extern long int* C_Ints;
extern unsigned long* C_Unsigned;
extern struct __builtins__ {
int bt__builtin_alloca;
int bt__builtin_return_address;
int bt__FUNCTION__;
int bt__func__;
int bt__PRETTY_FUNCTION__;
} ccbuiltins;
extern void enter_token ();
extern void enter_file_indicator (char*);
extern void prepare ();
extern void make_norm ();
extern int getint (int);
extern void yynorm (char*, int);
extern Symbol intern_sym;
//
// utilities
//
extern void intcpycat (int*, const int*, const int*);
extern int* intdup (int*);
extern int intcmp (int*, int*);
extern void intncpy (int*, int*, int);
extern inline void intcpy (int *d, const int *s)
{ while ((*d++ = *s++) != -1); }
extern inline int intlen (const int *i)
{ int l=0; while (*i++ != -1) l++; return l; }
class load_file
{
int fd;
public:
load_file (char*);
int success;
char *data;
int len;
~load_file ();
};
#define ZC_OK 0
#define ZC_NA 1
#define ZC_AC 2
#define ZC_FF 3
//
// the compilation
//
extern void parse_C ();
//
// CDB interface
//
enum VARSPC {
EXTERN, STATIC, DEFAULT
};
typedef bool Ok;
extern typeID VoidType, SIntType;
enum BASETYPE {
S_CHAR = -20, U_CHAR, S_SINT, U_SINT, S_INT, U_INT,
S_LINT, U_LINT, S_LONG, U_LONG, FLOAT, DOUBLE, VOID,
_BTLIMIT
};
#define INTEGRAL(x) (x >= S_CHAR && x <= U_LONG)
#define TYPEDEF_BASE 50000
struct type {
int base;
Vspec spec;
};
#define ISFUNCTION(t) ((t).spec [0] == '(')
#define T_BASETYPE(t) ((t).base < _BTLIMIT)
#define T_BASESTRUCT(t) (t > 0 && t < TYPEDEF_BASE)
#define ARGLIST_OPEN -2
#define SPECIAL_ELLIPSIS -3
#define INCODE (!INGLOBAL && !INSTRUCT)
extern bool INGLOBAL, INSTRUCT, infuncs;
extern ArglPtr NoArgSpec;
extern void init_cdb ();
extern typeID gettype (type&);
extern typeID gettype (int, int*);
extern ArglPtr make_arglist (typeID*);
extern typeID* ret_arglist (ArglPtr);
extern void opentype (typeID, type&);
extern int base_of (typeID);
extern int* spec_of (typeID);
extern int esizeof_objptr (ObjPtr);
extern int sizeof_typeID (typeID);
extern int sizeof_type (int, Vspec);
extern int ptr_increment (int, Vspec);
extern Ok introduce_obj (Symbol, typeID, VARSPC);
extern Ok introduce_tdef (Symbol, typeID);
extern ObjPtr lookup_typedef (Symbol);
extern Ok is_typedef (Symbol);
extern Ok introduce_enumconst (Symbol, int);
extern Ok introduce_enumtag (Symbol, bool=false);
extern Ok valid_enumtag (Symbol);
extern RegionPtr introduce_anon_struct (bool);
extern RegionPtr introduce_named_struct (Symbol, bool);
extern RegionPtr use_struct_tag (Symbol, bool);
extern RegionPtr fwd_struct_tag (Symbol, bool);
extern Ok function_definition (Symbol, NormPtr, NormPtr, NormPtr, NormPtr);
extern Ok function_no (int, NormPtr*, NormPtr*);
extern void open_compound ();
extern void close_region ();
extern Symbol struct_by_name (RegionPtr);
extern void functions_of_file ();
extern bool have_function (Symbol);
extern bool rename_struct (typeID, Symbol);
extern void struct_location (typeID, NormPtr, NormPtr);
extern void structs_of_file ();
extern void spill_anonymous (RegionPtr);
//
// CDB lookups
//
struct lookup_object {
bool enumconst;
int ec;
ObjPtr base;
RegionPtr FRAME;
int displacement;
int spec [50];
lookup_object (Symbol, bool=true);
};
struct lookup_function {
bool fptr;
ObjPtr base;
RegionPtr FRAME;
bool ARGFUNC;
int displacement;
int spec [50];
bool found;
lookup_function (Symbol, bool=true);
};
struct lookup_member {
ObjPtr base;
int spec [50];
int displacement;
lookup_member (Symbol, RegionPtr);
};
//
// cc-expressions
//
enum COPS {
VALUE, FVALUE, SVALUE, UVALUE, AVALUE,
SYMBOL,
FCALL, ARRAY, MEMB,
PPPOST, MMPOST,
PPPRE, MMPRE, LNEG, OCPL, PTRIND, ADDROF, UPLUS, UMINUS, CAST, SIZEOF,
MUL, DIV, REM, ADD, SUB, SHL, SHR,
BEQ, BNEQ, CGR, CGRE, CLE, CLEE,
BAND, BOR, BXOR,
IAND, IOR,
GCOND, COND, // assignments taken from norm.h defines
COMMA, ARGCOMMA,
COMPOUND_RESULT
};
struct subexpr
{
int action;
union {
int using_result;
long int value;
unsigned long int uvalue;
double fvalue;
Symbol symbol;
exprID e;
} voici;
exprID e;
union {
typeID cast;
Symbol member;
exprID eelse;
typeID result_type;
} voila;
};
struct exprtree
{
subexpr *ee;
int ne;
exprID first;
};
extern exprtree CExpr;
extern int last_result;
extern subexpr *ⅇ
extern int &NeTop;
extern NormPtr ExpressionPtr;
extern typeID typeof_expression ();
extern int cc_int_expression ();
extern struct lrt {
int base;
int spec [MSPEC];
} last_result_type;
//
// expand initializer
//
class dcle
{
struct {
int p;
bool marked;
int c, max;
int s;
} nests [30];
int ni;
Symbol *dclstr;
NormPtr p;
void openarray ();
void openstruct ();
NormPtr skipbracket (NormPtr);
bool opennest ();
bool closenest ();
Symbol pexpr [30];
public:
dcle (Symbol);
bool open_bracket ();
bool tofield ();
bool comma ();
bool tostruct (RegionPtr);
bool designator (Symbol[]);
bool close_bracket ();
Symbol* mk_current ();
void printexpr ();
~dcle ();
};
//
// different behaviour of the compiler
//
extern class ncci
{
public:
virtual void cc_expression () = 0;
virtual void new_function (Symbol) = 0;
virtual void inline_assembly (NormPtr, int) = 0;
virtual void finir () { }
} *ncc;
extern void set_compilation ();
extern void set_usage_report ();