scc

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

as.h (2952B)


      1 /*
      2  * First 3 bits of flags in segments and symbols are for the
      3  * type of segment
      4  */
      5 enum symflags {
      6 	FREG    = 1 << 0,
      7 	FSECT   = 1 << 1,
      8 	FSYM    = 1 << 2,
      9 	FCOMMON = 1 << 3,
     10 	FEXTERN = 1 << 4,
     11 	FDEF    = 1 << 5,
     12 	FGLOBAL = 1 << 6,
     13 	FABS    = 1 << 7,
     14 };
     15 
     16 /*
     17  * some systems polute the namespace defining BIG_ENDIAN and
     18  * LITTLE_ENDIAN
     19  */
     20 #undef BIG_ENDIAN
     21 #undef LITTLE_ENDIAN
     22 
     23 enum endianess {
     24 	BIG_ENDIAN    = -1,
     25 	LITTLE_ENDIAN = 1
     26 };
     27 
     28 enum common_args {
     29 	AIMM = 1,
     30 	ASTR,
     31 	AREG,
     32 	ANUMBER,
     33 	AIMM2,
     34 	AIMM3,
     35 	AIMM5,
     36 	AIMM8,
     37 	AIMM16,
     38 	AIMM32,
     39 	AIMM64,
     40 	AINDIR,
     41 	AINDEX,
     42 	ADIRECT,
     43 	AREG_OFF,
     44 	ASYM,
     45 	AOPT,
     46 	AREP,
     47 	AMAX,
     48 };
     49 
     50 enum tokens {
     51 	EOS = -1,
     52 	IDEN = 1,
     53 	NUMBER,
     54 	REG,
     55 	STRING,
     56 	MINUS,
     57 	SHL,
     58 	SHR,
     59 	GE,
     60 	LE,
     61 };
     62 
     63 #define MAXSYM 63
     64 
     65 typedef struct reloc Reloc;
     66 typedef struct ins Ins;
     67 typedef struct op Op;
     68 typedef struct node Node;
     69 typedef void Format(Op *, Node **);
     70 
     71 struct line {
     72 	char *label;
     73 	char *op;
     74 	char *args;
     75 };
     76 
     77 struct ins {
     78 	int begin, end;
     79 	char *str;
     80 };
     81 
     82 struct reloc {
     83 	size_t offset;
     84 	Symbol *sym;
     85 	unsigned char flags;
     86 	unsigned char size;
     87 	unsigned char nbits;
     88 	unsigned char shift;
     89 };
     90 
     91 struct op {
     92 	unsigned char flags;
     93 	unsigned char size;
     94 	void (*format)(Op *, Node **);
     95 	unsigned char *bytes;
     96 	unsigned char *args;
     97 };
     98 
     99 struct node {
    100 	unsigned char op;
    101 	unsigned char addr;
    102 	struct symbol *sym;
    103 	struct node *left;
    104 	struct node *right;
    105 };
    106 
    107 union yylval {
    108 	TUINT val;
    109 	Symbol *sym;
    110 };
    111 
    112 /* symbol.c */
    113 extern void cleansecs(void);
    114 extern void ibinfmt(void);
    115 extern void emit(char *, int);
    116 extern Section *defsec(char *, char *);
    117 extern Symbol *tmpsym(TUINT);
    118 extern void killtmp(void);
    119 extern int toobig(Node *, int);
    120 extern void dumpstab(char *);
    121 extern Symbol *lookup(char *);
    122 extern Symbol *deflabel(char *);
    123 extern unsigned long long getpc(void);
    124 
    125 /* parser.c */
    126 extern Node **getargs(char *);
    127 extern void error(char *, ...);
    128 /* Avoid errors in files where stdio is not included */
    129 #ifdef stdin
    130 extern int nextline(struct line *);
    131 #endif
    132 extern void unexpected(void);
    133 extern void expect(int);
    134 int next(void);
    135 #define accept(t) (yytoken == (t) ? next() : 0)
    136 extern void regctx(int mode);
    137 extern Node *getreg(void);
    138 extern Node *operand(char **);
    139 extern void addinput(char *);
    140 extern int delinput(void);
    141 extern int ahead(void);
    142 
    143 /* expr.c */
    144 extern Node *expr(void);
    145 extern void deltree(Node *);
    146 extern Node *node(int, Node *, Node *);
    147 
    148 /* proc.c */
    149 extern void iarch(void);
    150 extern int match(Op *, Node **);
    151 extern Node *moperand(void);
    152 
    153 /* ins.c */
    154 extern char *tobytes(TUINT, int, int);
    155 
    156 /* binfmt.c */
    157 extern void writeout(char *);
    158 
    159 /*
    160  * Definition of global variables
    161  */
    162 extern unsigned long M, S, K;
    163 extern short hashmap[];
    164 extern Section *cursec;
    165 extern Ins instab[];
    166 extern Op optab[];
    167 extern int pass;
    168 extern TUINT maxaddr;
    169 extern int endian;
    170 extern Symbol *linesym;
    171 extern char *infile, *outfile;
    172 extern int endpass;
    173 extern int yytoken;
    174 extern size_t yylen;
    175 extern union yylval yylval;
    176 extern char yytext[];