diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-06-29 06:56:11 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-15 23:01:27 -0400 |
commit | 762330d6fa626e57a0b350cd89680d59b3158ba6 (patch) | |
tree | b22418242490d80fd291da7ea83fbdd35355f52f /lisc/lisc.h | |
parent | bab23d801eb12767f12ae8a04c24fdb29ece5aa8 (diff) | |
download | roux-762330d6fa626e57a0b350cd89680d59b3158ba6.tar.gz |
try writing a parser, painful
Diffstat (limited to 'lisc/lisc.h')
-rw-r--r-- | lisc/lisc.h | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h index dbe4d63..d73cc63 100644 --- a/lisc/lisc.h +++ b/lisc/lisc.h @@ -1,33 +1,42 @@ +#include <assert.h> #include <stdio.h> #include <stdlib.h> +/* + References have to be able to encode: + - Results of other operations (temporaries). + - Machine registers (for lowering). + - Spill locations. + - Constants/pointers to program data. +*/ + enum { - R = -1, /* Invalid reference. */ - Temp0 = 32, /* First temporary, below are machine registers. */ - MaxPreds = 16, /* Maximum number of predecessors for a block. */ + R = 0, /* Invalid reference. */ + Temp0 = 33, /* First temporary ref. */ + Const0 = 20000, /* First constant ref. */ + MaxIdnt = 32, + MaxPreds = 16, MaxBlks = 128, MaxInss = 128, MaxPhis = 128, }; -typedef int Ref; +typedef unsigned Ref; typedef struct Ins Ins; typedef struct Phi Phi; typedef struct Blk Blk; +typedef struct Fn Fn; typedef enum Op Op; typedef enum Jmp Jmp; enum Op { - ONop, - OAdd, + OAdd = 1, OSub, - OSDiv, + ODiv, OMod, - OParam, - OCall, - /* x86 instructions (reserved) */ - XDiv, + /* Reserved instructions. */ + X86Div, }; enum Jmp { @@ -49,14 +58,51 @@ struct Phi { }; struct Blk { - int np; - int ni; Phi *ps; Ins *is; + int np; + int ni; struct { Jmp ty; Ref arg; } jmp; int suc0, suc1; - int dpth; + int lvl; +}; + +struct Sym { + enum { + SUndef, + SReg, + SNum, + STemp, + } ty; + union { + char sreg[MaxIdnt]; + long long snum; + struct { + char id[MaxIdnt]; + int blk; + enum { + TPhi, + TIns, + } ty; + int loc; + } stemp; + } u; +}; + +#define sreg u.sreg +#define snum u.snum +#define stemp u.stemp + +struct Fn { + Sym *sym; + Blk *blk; + int nblk; + Ref nref; }; + + +/* parse.c */ +Fn *parsefn(FILE *); |