From a4c60603f61dd1a9f0ce420be9067965586dd694 Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Mon, 4 Aug 2025 22:13:17 +0200 Subject: Object assembly --- parser.sig | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 2 deletions(-) (limited to 'parser.sig') diff --git a/parser.sig b/parser.sig index 72def5f..3b93825 100644 --- a/parser.sig +++ b/parser.sig @@ -1,11 +1,167 @@ signature PARSER = sig structure P: PPC + structure D: DYNARRAY type ctx - type def + + type nid = int + + datatype ctype = + unknown_t | + void_t | + char_t | + uchar_t | + short_t | + ushort_t | + int_t | + uint_t | + long_t | + ulong_t | + longlong_t | + ulonglong_t | + + pointer_t of int * ctype | + function_t of ctype * ctype list | + array_t of Word64.word * ctype | + struct_t of + { name: nid, size: word, alignment: word, + fields: (nid * word * ctype) list } | + union_t of + { name: nid, size: word, alignment: word, + fields: (nid * word * ctype) list } | + + enum_t of nid * bool | (* is complete? *) + remote_t of int + + datatype unop = + UnopPreInc | + UnopPreDec | + UnopAddr | + UnopDeref | + UnopPos | + UnopNeg | + UnopComp | + UnopLogNeg | + UnopSizeof | + UnopCast | + + UnopPostInc | + UnopPostDec + + and binopReg = + BrSubscript | + + BrMul | + BrDiv | + BrMod | + BrSum | + BrSub | + BrShiftLeft | + BrShiftRight | + BrGreater | + BrLess | + BrLessEqual | + BrGreaterEqual | + BrEqual | + BrNotEqual | + BrBitAnd | + BrBitXor | + BrBitOr | + BrLogAnd | + BrLogOr | + + BrAssign | + BrMulAssign | + BrDivAssign | + BrModAssign | + BrSumAssign | + BrSubAssign | + BrLeftShiftAssign | + BrRightShiftAssign | + BrBitAndAssign | + BrBitXorAssign | + BrBitOrAssign | + + BrComma + + and cnum = + Ninteger of Word64.word + | Nfloat of Real32.real + | Ndouble of Real64.real + + and id = Lid of int | Gid of int + + and expr = + Eid of int * id option | + Econst of int * cnum | + Estrlit of int | + EmemberByV of exprAug * int | + EmemberByP of exprAug * int | + EfuncCall of exprAug * exprAug list | + Eternary of exprAug * exprAug * exprAug | + EsizeofType of ctype | + Eunop of unop * exprAug | + Ebinop of binop * exprAug * exprAug + + and exprAug = EA of expr * P.tkPos * bool * ctype + + and binop = BR of binopReg | BinopTernaryIncomplete of exprAug + + datatype linkage = LinkInternal | LinkExternal + + val iniLayouts: + (bool * word * { offset: word, t: ctype, value: word } list) D.t + + datatype cini = CiniExpr of exprAug | CiniConst of word | + CiniLayout of int + + type objDef = int * P.tkPos * ctype * cini * linkage + + datatype stmt = + StmtExpr of exprAug | + StmtCompound of (int * cini option) list * stmt list | + StmtIf of exprAug * stmt * stmt option | + StmtFor of exprAug option * exprAug option * exprAug option * stmt | + StmtWhile of exprAug * stmt | + StmtDoWhile of stmt * exprAug | + StmtReturn of exprAug option | + StmtBreak | + StmtContinue + + type funcInfo = { + name: int, + pos: P.tkPos, + t: ctype, + paramNum: int, + localVars: { name: nid, pos: P.tkPos, onStack: bool, t: ctype } vector, + stmt: stmt + } + + datatype declClass = DeclRegular | DeclTentative | DeclDefined + + type decl = P.tkPos * declClass * ctype * linkage + + (* Objects are in reverse order *) + datatype def = Objects of objDef list | Definition of funcInfo val createCtx: string -> string list -> ctx - val parseDef: ctx -> (def * ctx) option + val parseDef: ctx -> bool * ctx val printDef: def -> unit + + val alignOfType: ctype -> word + val sizeOfType: ctype -> word + + val finalize: ctx -> ctx + + type progInfo = { + ext: nid list, + glob: nid list, + objsZI: objDef list, + objs: objDef list, + funcs: funcInfo list, + strlits: int list + } + + val explode: ctx -> progInfo end -- cgit v1.2.3