scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

cc2.h (5625B)


      1 enum iflags {
      2 	BBENTRY =    1,        /* basic block entry */
      3 };
      4 
      5 enum tflags {
      6 	SIGNF   =     1 << 0,  /* Signed type */
      7 	INTF    =     1 << 1,  /* integer type */
      8 	FLOATF  =     1 << 2,  /* float type */
      9 	STRF    =     1 << 3,  /* string */
     10 	AGGRF   =     1 << 4,  /* aggregate */
     11 	FUNF    =     1 << 5,  /* function */
     12 	PARF    =     1 << 6,  /* parameter */
     13 	INITF   =     1 << 7,  /* initializer flag */
     14 	ELLIPS  =     1 << 8,  /* vararg function */
     15 	ARRF    =     1 << 9,  /* array flag */
     16 	PTRF    =     1 << 10, /* pointer flag */
     17 };
     18 
     19 enum sclass {
     20 	SAUTO     = 'A',
     21 	SREG      = 'R',
     22 	SLABEL    = 'L',
     23 	SINDEX    = 'I',
     24 	STMP      = 'N',
     25 	SGLOB     = 'G',
     26 	SEXTRN    = 'X',
     27 	SPRIV     = 'Y',
     28 	SLOCAL    = 'T',
     29 	SMEMB     = 'M',
     30 	SCONST    = '#',
     31 	STRING    = '"',
     32 	SNONE     = 0 /* cc2 relies on SNONE being 0 in nextpc() */
     33 };
     34 
     35 enum types {
     36 	ELLIPSIS = 'E',
     37 	INT8     = 'C',
     38 	INT16    = 'I',
     39 	INT32    = 'W',
     40 	INT64    = 'Q',
     41 	UINT8    = 'K',
     42 	UINT16   = 'N',
     43 	UINT32   = 'Z',
     44 	UINT64   = 'O',
     45 	POINTER  = 'P',
     46 	FUNCTION = 'F',
     47 	VECTOR   = 'V',
     48 	UNION    = 'U',
     49 	STRUCT   = 'S',
     50 	BOOL     = 'B',
     51 	FLOAT    = 'J',
     52 	DOUBLE   = 'D',
     53 	LDOUBLE  = 'H',
     54 	VOID     = '0'
     55 };
     56 
     57 enum op {
     58 	/* kind of operand */
     59 	/* operands */
     60 	OMEM     = 'M',
     61 	OTMP     = 'N',
     62 	OAUTO    = 'A',
     63 	OREG     = 'R',
     64 	OMREG    = 'G',
     65 	OCONST   = '#',
     66 	OSTRING  = '"',
     67 	OLOAD    = 'D',
     68 	OLABEL   = 'L',
     69 	OADD     = '+',
     70 	OSUB     = '-',
     71 	OMUL     = '*',
     72 	OMOD     = '%',
     73 	ODIV     = '/',
     74 	OSHL     = 'l',
     75 	OSHR     = 'r',
     76 	OLT      = '<',
     77 	OGT      = '>',
     78 	OLE      = '[',
     79 	OGE      = ']',
     80 	OEQ      = '=',
     81 	ONE      = '!',
     82 	OBAND    = '&',
     83 	OBOR     = '|',
     84 	OBXOR    = '^',
     85 	OCPL     = '~',
     86 	OASSIG   = ':',
     87 	OSNEG    = '_',
     88 	OCALL    = 'c',
     89 	OCALLE   = 'z',
     90 	OPAR     = 'p',
     91 	OFIELD   = '.',
     92 	OCOMMA   = ',',
     93 	OASK     = '?',
     94 	OCOLON   = ' ',
     95 	OADDR    = '\'',
     96 	OAND     = 'a',
     97 	OOR      = 'o',
     98 	ONEG     = 'n',
     99 	OPTR     = '@',
    100 	OCAST    = 'g',
    101 	OINC     = 'i',
    102 	ODEC     = 'd',
    103 	OBUILTIN = 'm',
    104 	/*statements */
    105 	ONOP     = 'q',
    106 	OJMP     = 'j',
    107 	OBRANCH  = 'y',
    108 	ORET     = 'h',
    109 	OBLOOP   = 'b',
    110 	OELOOP   = 'e',
    111 	OCASE    = 'v',
    112 	ODEFAULT = 'f',
    113 	OBSWITCH = 's',
    114 	OESWITCH = 't',
    115 	OBFUN    = 'x',
    116 	OEFUN    = 'k',
    117 };
    118 
    119 enum builtins {
    120 	BVA_START = 's',
    121 	BVA_END   = 'e',
    122 	BVA_ARG   = 'a',
    123 	BVA_COPY  = 'c',
    124 };
    125 
    126 enum nerrors {
    127 	EEOFFUN,       /* EOF while parsing function */
    128 	ENLABEL,       /* label without statement */
    129 	EIDOVER,       /* identifier overflow */
    130 	EOUTPAR,       /* out pf params */
    131 	ESYNTAX,       /* syntax error */
    132 	ESTACKA,       /* stack unaligned */
    133 	ESTACKO,       /* stack overflow */
    134 	ESTACKU,       /* stack underflow */
    135 	ELNLINE,       /* line too long */
    136 	ELNBLNE,       /* line without new line */
    137 	EFERROR,       /* error reading from file:%s */
    138 	EBADID,        /* incorrect symbol id */
    139 	EWTACKO,       /* switch stack overflow */
    140 	EWTACKU,       /* switch stack underflow */
    141 	ENOSWTC,       /* Out of switch statement */
    142 	EBBUILT,       /* Unknown builtin */
    143 	EOVERFL,       /* Numerical overflow */
    144 	ENUMERR
    145 };
    146 
    147 typedef struct node Node;
    148 typedef struct type Type;
    149 typedef struct symbol Symbol;
    150 typedef struct addr Addr;
    151 typedef struct inst Inst;
    152 
    153 struct type {
    154 	unsigned long size;
    155 	unsigned long align;
    156 	unsigned short id;
    157 	short flags;
    158 };
    159 
    160 struct symbol {
    161 	Type type;
    162 	Type rtype;
    163 	unsigned short id;
    164 	unsigned short numid;
    165 	char *name;
    166 	char kind;
    167 	union {
    168 		unsigned long off;
    169 		Node *stmt;
    170 		Inst *inst;
    171 	} u;
    172 	Symbol *next, *prev;
    173 	Symbol *h_next;
    174 };
    175 
    176 struct node {
    177 	char op;
    178 	Type type;
    179 	char complex;
    180 	char address;
    181 	unsigned char flags;
    182 	union {
    183 		TUINT i;
    184 		TFLOAT f;
    185 		char reg;
    186 		char *s;
    187 		Symbol *sym;
    188 		char subop;
    189 	} u;
    190 	Symbol *label;
    191 	Node *left, *right;
    192 	Node *next, *prev;
    193 };
    194 
    195 struct addr {
    196         char kind;
    197         union {
    198                 char reg;
    199                 TUINT i;
    200                 Symbol *sym;
    201         } u;
    202 };
    203 
    204 struct inst {
    205 	unsigned char op;
    206 	unsigned char flags;
    207 	Symbol *label;
    208 	Inst *next, *prev;
    209 	Addr from1, from2, to;
    210 };
    211 
    212 /* main.c */
    213 extern void error(unsigned nerror, ...);
    214 
    215 /* parse.c */
    216 extern void parse(void);
    217 
    218 /* optm.c */
    219 extern Node *optm_dep(Node *np), *optm_ind(Node *np);
    220 
    221 /* cgen.c */
    222 extern Node *sethi(Node *np);
    223 extern Node *cgen(Node *np);
    224 
    225 /* peep.c */
    226 extern void peephole(void);
    227 
    228 /* code.c */
    229 extern void data(Node *np);
    230 extern void writeout(void), endinit(void), newfun(void);
    231 extern void code(int op, Node *to, Node *from1, Node *from2);
    232 extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
    233 extern void setlabel(Symbol *sym), getbblocks(void);
    234 extern Node *label2node(Node *np, Symbol *sym);
    235 extern Node *constnode(Node *np, TUINT n, Type *tp);
    236 extern Node *tmpnode(Type *);
    237 extern Symbol *newlabel(void);
    238 extern void pprint(char *s);
    239 extern void deftype(Type *);
    240 
    241 /* node.c */
    242 #define SETCUR  1
    243 #define KEEPCUR 0
    244 extern void apply(Node *(*fun)(Node *));
    245 extern void cleannodes(void);
    246 extern void delnode(Node *np);
    247 extern void deltree(Node *np);
    248 extern void prtree(Node *np), prforest(char *msg);
    249 extern Node *node(int op);
    250 extern Node *addstmt(Node *np, int flags);
    251 extern Node *delstmt(void);
    252 extern Node *nextstmt(void);
    253 
    254 /* symbol.c */
    255 #define TMPSYM  0
    256 extern Symbol *getsym(unsigned id);
    257 extern void popctx(void);
    258 extern void pushctx(void);
    259 extern void freesym(Symbol *sym);
    260 
    261 /* globals */
    262 extern Symbol *curfun;
    263 extern Symbol *locals;
    264 extern Inst *pc, *prog;
    265 
    266 /* target */
    267 extern Type int8type, int16type, int32type, int64type,
    268             uint8type, uint16type, uint32type, uint64type,
    269             float32type, float64type, float80type,
    270             booltype,
    271             ptrtype,
    272             voidtype,
    273             arg_type;