scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

cc2.h (4564B)


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