scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

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