ref: 7b65afc1ad13f3859eca6eadaa2c45d864320304
dir: /dat.h/
#define BC_EXT "aplbc" #define OC_EXT "aploc" enum { Onop, Oexit, Ocall, Oreturn, Omov, Olocals, Oscalnum, Odisplay, O_max, O_maxargs = 2, }; enum { OAinvalid, OAlabel, /* 8 byte unsigned offset */ OAreg, /* 1 byte unsigned register number */ OAlocal1, /* 1 byte unsigned local number */ OAlocal2, /* 2 byte unsigned local number */ OAlocal4, /* 4 byte unsigned local number */ OAlocal8, /* 8 byte unsigned local number */ OAnum1, /* 1 signed byte */ OAnum2, /* 2 signed byte */ OAnum4, /* 4 signed byte */ OAnum8, /* 8 signed byte */ OA_maxbytes = 8, }; enum { ObjHeader, ObjConsts, ObjCode, Obj_max }; enum { RegIp, /* instruction pointer */ RegMod, /* current module */ RegFunc, /* current function (so we know the names of variables) */ RegSp, /* top of stack */ RegFp, /* start of current stack frame */ RegX, /* left argument */ RegY, /* right argument */ RegF, /* left operand function */ RegG, /* right operand function */ RegR, /* result value */ RegT, /* bool result of test (cmp* instruction) */ Reg_max, Reg_save = RegX /* all regs below are pushed */ }; char *regnames[Reg_max]; typedef struct Label Label; typedef struct Module Module; typedef struct ObjpartSpec ObjpartSpec; typedef struct OpArg OpArg; typedef struct OpcodeSpec OpcodeSpec; typedef struct ParsedInstr ParsedInstr; typedef struct VM VM; typedef union Word Word; union Word { /* Add cases as they are needed */ void *vp; char *cp; u64int u64; s64int s64; s16int s16v[4]; s8int s8v[8]; }; struct Label { char *name; uvlong ioffset; uvlong coffset; uvlong nameoffset; }; struct Module { uvlong codesize; u8int *code; uvlong constsize; u8int *consts; /* stuff used for parsing */ uvlong nlabels; uvlong ninstrs; Label *labels; ParsedInstr *instrs; }; struct ObjpartSpec { char *name; void (*read)(Module *, Biobuf *, int); void (*write)(Module *, Biobuf *, int); }; extern ObjpartSpec objparts[Obj_max]; struct OpArg { int tag; Word; }; struct OpcodeSpec { char *name; int args; }; extern OpcodeSpec optab[O_max]; struct ParsedInstr { int opcode; OpArg args[O_maxargs]; uvlong len; u8int buf[1 + 1 + (O_maxargs * OA_maxbytes)]; }; struct VM { Word regs[Reg_max]; uvlong nmods; Module **mods; Word stack[1024]; /* FIXME: grow stack as needed */ };