scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

as.h (3017B)


      1 /*
      2  * First 3 bits of flags in segments and symbols are for the
      3  * type of segment
      4  */
      5 enum symtype {
      6 	TUNDEF  = 0,
      7 	TABS    = 1,
      8 	TTEXT   = 2,
      9 	TBSS    = 3,
     10 	TDATA   = 4,
     11 	TREG    = 5,
     12 	TMASK   = 7,
     13 };
     14 
     15 enum secflags {
     16 	SRELOC  = 1 << 4,
     17 	SREAD   = 1 << 5,
     18 	SWRITE  = 1 << 6,
     19 	SFILE   = 1 << 7,
     20 };
     21 
     22 enum symflags {
     23 	FCOMMON = 1 << 4,
     24 	FLOCAL  = 1 << 5,
     25 	FEXTERN = 1 << 6,
     26 	FUNDEF  = 1 << 7,
     27 };
     28 
     29 enum endianess {
     30 	BIG_ENDIAN    = -1,
     31 	LITTLE_ENDIAN = 1
     32 };
     33 
     34 enum common_args {
     35 	AIMM = 1,
     36 	ASTR,
     37 	AREG,
     38 	AIMM8,
     39 	AIMM16,
     40 	AIMM32,
     41 	AIMM64,
     42 	AINDIR,
     43 	AINDEX,
     44 	ADIRECT,
     45 	AREG_OFF,
     46 	AMAX,
     47 	AREP = 128
     48 };
     49 
     50 #define MAXSYM 63
     51 
     52 typedef struct reloc Reloc;
     53 typedef struct ins Ins;
     54 typedef struct op Op;
     55 typedef struct section Section;
     56 typedef struct symbol Symbol;
     57 typedef struct node Node;
     58 typedef struct string String;
     59 typedef void Format(Op *, Node **);
     60 
     61 struct string {
     62 	char *buf;
     63 	size_t offset;
     64 };
     65 
     66 struct line {
     67 	char *label;
     68 	char *op;
     69 	char *args;
     70 };
     71 
     72 struct ins {
     73 	int begin, end;
     74 	char *str;
     75 };
     76 
     77 struct reloc {
     78 	size_t offset;
     79 	Symbol *sym;
     80 	unsigned char flags;
     81 	unsigned char size;
     82 	unsigned char nbits;
     83 	unsigned char shift;
     84 };
     85 
     86 struct op {
     87 	unsigned char flags;
     88 	char size;
     89 	void (*format)(Op *, Node **);
     90 	unsigned char *bytes;
     91 	unsigned char *args;
     92 };
     93 
     94 struct section {
     95 	String name;
     96 	char *mem;
     97 	unsigned char flags;
     98 	unsigned char fill;
     99 	unsigned char aligment;
    100 	TUINT base;
    101 	TUINT max;
    102 	TUINT curpc;
    103 	TUINT pc;
    104 	struct section *next;
    105 };
    106 
    107 struct symbol {
    108 	String name;
    109 	unsigned char flags;
    110 	unsigned char pass;
    111 	unsigned char argtype;
    112 	TUINT value;
    113 	struct symbol *next;
    114 	struct symbol *hash;
    115 };
    116 
    117 struct node {
    118 	unsigned char op;
    119 	unsigned char addr;
    120 	struct symbol *sym;
    121 	struct node *left;
    122 	struct node *right;
    123 };
    124 
    125 /* symbol.c */
    126 extern void isections(void);
    127 extern void emit(Section *sec, char *bytes, int nbytes);
    128 extern Section *section(char *name);
    129 extern Symbol *tmpsym(TUINT val);
    130 extern void killtmp(void);
    131 extern int toobig(Node *np, int type);
    132 extern void dumpstab(char *msg);
    133 extern String newstring(char *s);
    134 
    135 /* main.c */
    136 extern Symbol *lookup(char *name, int type);
    137 extern Symbol *deflabel(char *name);
    138 
    139 /* parser.c */
    140 extern Node **getargs(char *s);
    141 extern void error(char *msg, ...);
    142 /* Avoid errors in files where stdio is not included */
    143 #ifdef stdin
    144 extern int nextline(FILE *fp, struct line *linep);
    145 #endif
    146 
    147 /* expr.c */
    148 extern Node *expr(char **s);
    149 extern void deltree(Node *np);
    150 
    151 /* proc.c */
    152 extern void iarch(void);
    153 extern int match(Op *op, Node **args);
    154 
    155 /* ins.c */
    156 extern char *tobytes(TUINT v, int n, int inc);
    157 
    158 /* format.c */
    159 extern void writeout(char *name);
    160 extern void reloc(Symbol *sym,
    161                   unsigned flags,
    162                   unsigned size,
    163                   unsigned nbits,
    164                   unsigned shift);
    165 
    166 
    167 /*
    168  * Definition of global variables
    169  */
    170 extern Section *cursec, *seclist;
    171 extern int nr_ins;
    172 extern Ins instab[];
    173 extern Op optab[];
    174 extern int pass;
    175 extern TUINT maxaddr;
    176 extern int endian;
    177 extern Symbol *linesym, *symlist;
    178 extern char *filename;