OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [src/] [c.h] - Blame information for rev 26

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
/* $Id: c.h,v 1.1 2002/08/28 23:12:41 drh Exp $ */
2
#include <assert.h>
3
#include <stdarg.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <limits.h>
7
#include <string.h>
8
 
9
#define NEW(p,a) ((p) = allocate(sizeof *(p), (a)))
10
#define NEW0(p,a) memset(NEW((p),(a)), 0, sizeof *(p))
11
#define isaddrop(op) (specific(op)==ADDRG+P || specific(op)==ADDRL+P \
12
        || specific(op)==ADDRF+P)
13
 
14
#define MAXLINE  512
15
#define BUFSIZE 4096
16
 
17
#define istypename(t,tsym) (kind[t] == CHAR \
18
        || t == ID && tsym && tsym->sclass == TYPEDEF)
19
#define sizeop(n) ((n)<<10)
20
#define generic(op)  ((op)&0x3F0)
21
#define specific(op) ((op)&0x3FF)
22
#define opindex(op) (((op)>>4)&0x3F)
23
#define opkind(op)  ((op)&~0x3F0)
24
#define opsize(op)  ((op)>>10)
25
#define optype(op)  ((op)&0xF)
26
#ifdef __LCC__
27
#ifndef __STDC__
28
#define __STDC__
29
#endif
30
#endif
31
#define NELEMS(a) ((int)(sizeof (a)/sizeof ((a)[0])))
32
#undef roundup
33
#define roundup(x,n) (((x)+((n)-1))&(~((n)-1)))
34
#define mkop(op,ty) (specific((op) + ttob(ty)))
35
 
36
#define extend(x,ty) ((x)&(1<<(8*(ty)->size-1)) ? (x)|((~0UL)<<(8*(ty)->size-1)) : (x)&ones(8*(ty)->size))
37
#define ones(n) ((n)>=8*sizeof (unsigned long) ? ~0UL : ~((~0UL)<<(n)))
38
 
39
#define isqual(t)     ((t)->op >= CONST)
40
#define unqual(t)     (isqual(t) ? (t)->type : (t))
41
 
42
#define isvolatile(t) ((t)->op == VOLATILE \
43
                    || (t)->op == CONST+VOLATILE)
44
#define isconst(t)    ((t)->op == CONST \
45
                    || (t)->op == CONST+VOLATILE)
46
#define isarray(t)    (unqual(t)->op == ARRAY)
47
#define isstruct(t)   (unqual(t)->op == STRUCT \
48
                    || unqual(t)->op == UNION)
49
#define isunion(t)    (unqual(t)->op == UNION)
50
#define isfunc(t)     (unqual(t)->op == FUNCTION)
51
#define isptr(t)      (unqual(t)->op == POINTER)
52
#define ischar(t)     ((t)->size == 1 && isint(t))
53
#define isint(t)      (unqual(t)->op == INT \
54
                    || unqual(t)->op == UNSIGNED)
55
#define isfloat(t)    (unqual(t)->op == FLOAT)
56
#define isarith(t)    (unqual(t)->op <= UNSIGNED)
57
#define isunsigned(t) (unqual(t)->op == UNSIGNED)
58
#define isscalar(t)   (unqual(t)->op <= POINTER \
59
                    || unqual(t)->op == ENUM)
60
#define isenum(t)     (unqual(t)->op == ENUM)
61
#define fieldsize(p)  (p)->bitsize
62
#define fieldright(p) ((p)->lsb - 1)
63
#define fieldleft(p)  (8*(p)->type->size - \
64
                        fieldsize(p) - fieldright(p))
65
#define fieldmask(p)  (~(fieldsize(p) < 8*unsignedtype->size ? ~0u<<fieldsize(p) : 0u))
66
typedef struct node *Node;
67
 
68
typedef struct list *List;
69
 
70
typedef struct code *Code;
71
 
72
typedef struct swtch *Swtch;
73
 
74
typedef struct symbol *Symbol;
75
 
76
typedef struct coord {
77
        char *file;
78
        unsigned x, y;
79
} Coordinate;
80
typedef struct table *Table;
81
 
82
typedef union value {
83
        long i;
84
        unsigned long u;
85
        long double d;
86
        void *p;
87
        void (*g)(void);
88
} Value;
89
typedef struct tree *Tree;
90
 
91
typedef struct type *Type;
92
 
93
typedef struct field *Field;
94
 
95
typedef struct {
96
        unsigned printed:1;
97
        unsigned marked;
98
        unsigned short typeno;
99
        void *xt;
100
} Xtype;
101
 
102
#include "config.h"
103
typedef struct metrics {
104
        unsigned char size, align, outofline;
105
} Metrics;
106
typedef struct interface {
107
        Metrics charmetric;
108
        Metrics shortmetric;
109
        Metrics intmetric;
110
        Metrics longmetric;
111
        Metrics longlongmetric;
112
        Metrics floatmetric;
113
        Metrics doublemetric;
114
        Metrics longdoublemetric;
115
        Metrics ptrmetric;
116
        Metrics structmetric;
117
        unsigned little_endian:1;
118
        unsigned mulops_calls:1;
119
        unsigned wants_callb:1;
120
        unsigned wants_argb:1;
121
        unsigned left_to_right:1;
122
        unsigned wants_dag:1;
123
        unsigned unsigned_char:1;
124
void (*address)(Symbol p, Symbol q, long n);
125
void (*blockbeg)(Env *);
126
void (*blockend)(Env *);
127
void (*defaddress)(Symbol);
128
void (*defconst)  (int suffix, int size, Value v);
129
void (*defstring)(int n, char *s);
130
void (*defsymbol)(Symbol);
131
void (*emit)    (Node);
132
void (*export)(Symbol);
133
void (*function)(Symbol, Symbol[], Symbol[], int);
134
Node (*gen)     (Node);
135
void (*global)(Symbol);
136
void (*import)(Symbol);
137
void (*local)(Symbol);
138
void (*progbeg)(int argc, char *argv[]);
139
void (*progend)(void);
140
void (*segment)(int);
141
void (*space)(int);
142
void (*stabblock)(int, int, Symbol*);
143
void (*stabend)  (Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *);
144
void (*stabfend) (Symbol, int);
145
void (*stabinit) (char *, int, char *[]);
146
void (*stabline) (Coordinate *);
147
void (*stabsym)  (Symbol);
148
void (*stabtype) (Symbol);
149
        Xinterface x;
150
} Interface;
151
typedef struct binding {
152
        char *name;
153
        Interface *ir;
154
} Binding;
155
 
156
extern Binding bindings[];
157
extern Interface *IR;
158
typedef struct {
159
        List blockentry;
160
        List blockexit;
161
        List entry;
162
        List exit;
163
        List returns;
164
        List points;
165
        List calls;
166
        List end;
167
} Events;
168
 
169
enum {
170
#define xx(a,b,c,d,e,f,g) a=b,
171
#define yy(a,b,c,d,e,f,g)
172
#include "token.h"
173
        LAST
174
};
175
struct node {
176
        short op;
177
        short count;
178
        Symbol syms[3];
179
        Node kids[2];
180
        Node link;
181
        Xnode x;
182
};
183
enum {
184
        F=FLOAT,
185
        I=INT,
186
        U=UNSIGNED,
187
        P=POINTER,
188
        V=VOID,
189
        B=STRUCT
190
};
191
#define gop(name,value) name=value<<4,
192
#define op(name,type,sizes)
193
 
194
enum {
195
#include "ops.h"
196
        LASTOP
197
};
198
 
199
#undef gop
200
#undef op
201
enum { CODE=1, BSS, DATA, LIT };
202
enum { PERM=0, FUNC, STMT };
203
struct list {
204
        void *x;
205
        List link;
206
};
207
 
208
struct code {
209
        enum { Blockbeg, Blockend, Local, Address, Defpoint,
210
               Label,    Start,    Gen,   Jump,    Switch
211
        } kind;
212
        Code prev, next;
213
        union {
214
                struct {
215
                        int level;
216
                        Symbol *locals;
217
                        Table identifiers, types;
218
                        Env x;
219
                } block;
220
                Code begin;
221
                Symbol var;
222
 
223
                struct {
224
                        Symbol sym;
225
                        Symbol base;
226
                        long offset;
227
                } addr;
228
                struct {
229
                        Coordinate src;
230
                        int point;
231
                } point;
232
                Node forest;
233
                struct {
234
                        Symbol sym;
235
                        Symbol table;
236
                        Symbol deflab;
237
                        int size;
238
                        long *values;
239
                        Symbol *labels;
240
                } swtch;
241
 
242
        } u;
243
};
244
struct swtch {
245
        Symbol sym;
246
        int lab;
247
        Symbol deflab;
248
        int ncases;
249
        int size;
250
        long *values;
251
        Symbol *labels;
252
};
253
struct symbol {
254
        char *name;
255
        int scope;
256
        Coordinate src;
257
        Symbol up;
258
        List uses;
259
        int sclass;
260
        unsigned structarg:1;
261
 
262
        unsigned addressed:1;
263
        unsigned computed:1;
264
        unsigned temporary:1;
265
        unsigned generated:1;
266
        unsigned defined:1;
267
        Type type;
268
        float ref;
269
        union {
270
                struct {
271
                        int label;
272
                        Symbol equatedto;
273
                } l;
274
                struct {
275
                        unsigned cfields:1;
276
                        unsigned vfields:1;
277
                        Table ftab;             /* omit */
278
                        Field flist;
279
                } s;
280
                int value;
281
                Symbol *idlist;
282
                struct {
283
                        Value min, max;
284
                } limits;
285
                struct {
286
                        Value v;
287
                        Symbol loc;
288
                } c;
289
                struct {
290
                        Coordinate pt;
291
                        int label;
292
                        int ncalls;
293
                        Symbol *callee;
294
                } f;
295
                int seg;
296
                Symbol alias;
297
                struct {
298
                        Node cse;
299
                        int replace;
300
                        Symbol next;
301
                } t;
302
        } u;
303
        Xsymbol x;
304
};
305
enum { CONSTANTS=1, LABELS, GLOBAL, PARAM, LOCAL };
306
struct tree {
307
        int op;
308
        Type type;
309
        Tree kids[2];
310
        Node node;
311
        union {
312
                Value v;
313
                Symbol sym;
314
 
315
                Field field;
316
        } u;
317
};
318
enum {
319
        AND=38<<4,
320
        NOT=39<<4,
321
        OR=40<<4,
322
        COND=41<<4,
323
        RIGHT=42<<4,
324
        FIELD=43<<4
325
};
326
struct type {
327
        int op;
328
        Type type;
329
        int align;
330
        int size;
331
        union {
332
                Symbol sym;
333
                struct {
334
                        unsigned oldstyle:1;
335
                        Type *proto;
336
                } f;
337
        } u;
338
        Xtype x;
339
};
340
struct field {
341
        char *name;
342
        Type type;
343
        int offset;
344
        short bitsize;
345
        short lsb;
346
        Field link;
347
};
348
extern int assignargs;
349
extern int prunetemps;
350
extern int nodecount;
351
extern Symbol cfunc;
352
extern Symbol retv;
353
extern Tree (*optree[])(int, Tree, Tree);
354
 
355
extern char kind[];
356
extern int errcnt;
357
extern int errlimit;
358
extern int wflag;
359
extern Events events;
360
extern float refinc;
361
 
362
extern unsigned char *cp;
363
extern unsigned char *limit;
364
extern char *firstfile;
365
extern char *file;
366
extern char *line;
367
extern int lineno;
368
extern int t;
369
extern char *token;
370
extern Symbol tsym;
371
extern Coordinate src;
372
extern int Aflag;
373
extern int Pflag;
374
extern Symbol YYnull;
375
extern Symbol YYcheck;
376
extern int glevel;
377
extern int xref;
378
 
379
extern int ncalled;
380
extern int npoints;
381
 
382
extern int needconst;
383
extern int explicitCast;
384
extern struct code codehead;
385
extern Code codelist;
386
extern Table stmtlabs;
387
extern float density;
388
extern Table constants;
389
extern Table externals;
390
extern Table globals;
391
extern Table identifiers;
392
extern Table labels;
393
extern Table types;
394
extern int level;
395
 
396
extern List loci, symbols;
397
 
398
extern List symbols;
399
 
400
extern int where;
401
extern Type chartype;
402
extern Type doubletype;
403
extern Type floattype;
404
extern Type inttype;
405
extern Type longdouble;
406
extern Type longtype;
407
extern Type longlong;
408
extern Type shorttype;
409
extern Type signedchar;
410
extern Type unsignedchar;
411
extern Type unsignedlonglong;
412
extern Type unsignedlong;
413
extern Type unsignedshort;
414
extern Type unsignedtype;
415
extern Type charptype;
416
extern Type funcptype;
417
extern Type voidptype;
418
extern Type voidtype;
419
extern Type unsignedptr;
420
extern Type signedptr;
421
extern Type widechar;
422
extern void  *allocate(unsigned long n, unsigned a);
423
extern void deallocate(unsigned a);
424
extern void *newarray(unsigned long m, unsigned long n, unsigned a);
425
extern void walk(Tree e, int tlab, int flab);
426
extern Node listnodes(Tree e, int tlab, int flab);
427
extern Node newnode(int op, Node left, Node right, Symbol p);
428
extern Tree cvtconst(Tree);
429
extern void printdag(Node, int);
430
extern void compound(int, Swtch, int);
431
extern void defglobal(Symbol, int);
432
extern void finalize(void);
433
extern void program(void);
434
 
435
extern Tree vcall(Symbol func, Type ty, ...);
436
extern Tree addrof(Tree);
437
extern Tree asgn(Symbol, Tree);
438
extern Tree asgntree(int, Tree, Tree);
439
extern Type assign(Type, Tree);
440
extern Tree bittree(int, Tree, Tree);
441
extern Tree call(Tree, Type, Coordinate);
442
extern Tree calltree(Tree, Type, Tree, Symbol);
443
extern Tree condtree(Tree, Tree, Tree);
444
extern Tree cnsttree(Type, ...);
445
extern Tree consttree(unsigned int, Type);
446
extern Tree eqtree(int, Tree, Tree);
447
extern int iscallb(Tree);
448
extern Tree shtree(int, Tree, Tree);
449
extern void typeerror(int, Tree, Tree);
450
 
451
extern void test(int tok, char set[]);
452
extern void expect(int tok);
453
extern void skipto(int tok, char set[]);
454
extern void error(const char *, ...);
455
extern int fatal(const char *, const char *, int);
456
extern void warning(const char *, ...);
457
 
458
typedef void (*Apply)(void *, void *, void *);
459
extern void attach(Apply, void *, List *);
460
extern void apply(List event, void *arg1, void *arg2);
461
extern Tree retype(Tree p, Type ty);
462
extern Tree rightkid(Tree p);
463
extern int hascall(Tree p);
464
extern Type binary(Type, Type);
465
extern Tree cast(Tree, Type);
466
extern Tree cond(Tree);
467
extern Tree expr0(int);
468
extern Tree expr(int);
469
extern Tree expr1(int);
470
extern Tree field(Tree, const char *);
471
extern char *funcname(Tree);
472
extern Tree idtree(Symbol);
473
extern Tree incr(int, Tree, Tree);
474
extern Tree lvalue(Tree);
475
extern Tree nullcall(Type, Symbol, Tree, Tree);
476
extern Tree pointer(Tree);
477
extern Tree rvalue(Tree);
478
extern Tree value(Tree);
479
 
480
extern void defpointer(Symbol);
481
extern Type initializer(Type, int);
482
extern void swtoseg(int);
483
 
484
extern void input_init(int, char *[]);
485
extern void fillbuf(void);
486
extern void nextline(void);
487
 
488
extern int getchr(void);
489
extern int gettok(void);
490
 
491
extern void emitcode(void);
492
extern void gencode (Symbol[], Symbol[]);
493
extern void fprint(FILE *f, const char *fmt, ...);
494
extern char *stringf(const char *, ...);
495
extern void check(Node);
496
extern void print(const char *, ...);
497
 
498
extern List append(void *x, List list);
499
extern int  length(List list);
500
extern void *ltov (List *list, unsigned a);
501
extern void init(int, char *[]);
502
 
503
extern Type typename(void);
504
extern void checklab(Symbol p, void *cl);
505
extern Type enumdcl(void);
506
extern void main_init(int, char *[]);
507
extern int main(int, char *[]);
508
 
509
extern void vfprint(FILE *, char *, const char *, va_list);
510
 
511
void profInit(char *);
512
extern int process(char *);
513
extern int findfunc(char *, char *);
514
extern int findcount(char *, int, int);
515
 
516
extern Tree constexpr(int);
517
extern int intexpr(int, int);
518
extern Tree simplify(int, Type, Tree, Tree);
519
extern int ispow2(unsigned long u);
520
 
521
extern int reachable(int);
522
 
523
extern void addlocal(Symbol);
524
extern void branch(int);
525
extern Code code(int);
526
extern void definelab(int);
527
extern void definept(Coordinate *);
528
extern void equatelab(Symbol, Symbol);
529
extern Node jump(int);
530
extern void retcode(Tree);
531
extern void statement(int, Swtch, int);
532
extern void swcode(Swtch, int *, int, int);
533
extern void swgen(Swtch);
534
 
535
extern char * string(const char *str);
536
extern char *stringn(const char *str, int len);
537
extern char *stringd(long n);
538
extern Symbol relocate(const char *name, Table src, Table dst);
539
extern void use(Symbol p, Coordinate src);
540
extern void locus(Table tp, Coordinate *cp);
541
extern Symbol allsymbols(Table);
542
 
543
extern Symbol constant(Type, Value);
544
extern void enterscope(void);
545
extern void exitscope(void);
546
extern Symbol findlabel(int);
547
extern Symbol findtype(Type);
548
extern void foreach(Table, int, void (*)(Symbol, void *), void *);
549
extern Symbol genident(int, Type, int);
550
extern int genlabel(int);
551
extern Symbol install(const char *, Table *, int, int);
552
extern Symbol intconst(int);
553
extern Symbol lookup(const char *, Table);
554
extern Symbol mkstr(char *);
555
extern Symbol mksymbol(int, const char *, Type);
556
extern Symbol newtemp(int, int, int);
557
extern Table newtable(int);
558
extern Table table(Table, int);
559
extern Symbol temporary(int, Type);
560
extern char *vtoa(Type, Value);
561
 
562
extern void traceInit(char *);
563
extern int nodeid(Tree);
564
extern char *opname(int);
565
extern int *printed(int);
566
extern void printtree(Tree, int);
567
extern Tree root(Tree);
568
extern Tree texpr(Tree (*)(int), int, int);
569
extern Tree tree(int, Type, Tree, Tree);
570
 
571
extern void type_init(int, char *[]);
572
 
573
extern Type signedint(Type);
574
 
575
extern int hasproto(Type);
576
extern void outtype(Type, FILE *);
577
extern void printdecl (Symbol p, Type ty);
578
extern void printproto(Symbol p, Symbol args[]);
579
extern char *typestring(Type ty, char *id);
580
extern Field fieldref(const char *name, Type ty);
581
extern Type array(Type, int, int);
582
extern Type atop(Type);
583
extern Type btot(int, int);
584
extern Type compose(Type, Type);
585
extern Type deref(Type);
586
extern int eqtype(Type, Type, int);
587
extern Field fieldlist(Type);
588
extern Type freturn(Type);
589
extern Type ftype(Type, ...);
590
extern Type func(Type, Type *, int);
591
extern Field newfield(char *, Type, Type);
592
extern Type newstruct(int, char *);
593
extern void printtype(Type, int);
594
extern Type promote(Type);
595
extern Type ptr(Type);
596
extern Type qual(int, Type);
597
extern void rmtypes(int);
598
extern int ttob(Type);
599
extern int variadic(Type);
600
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.