1(* Abstract syntax for C--, nicked from Fermin Reig and heavily modified. *) 2(* Ken Friis Larsen <ken@friislarsen.net> *) 3structure CmmAST = 4struct 5 6datatype toplevel = Imports of typ * (name option * name) list 7 | Exports of typ option * (name * name option) list 8 | Typedef of name * name 9 | Data of sectionname * pseudoop list 10 | Target of memsize option * byteorder 11 | Function of { conv : conv 12 , name : name 13 , formals : formal list 14 , stmts : stmts 15 } 16 17and byteorder = Little | Big 18 19and typ = Bits8 | Bits16 | Bits32 | Bits64 20 21and stmt = DeclReg of formal 22 | DeclStackData of StackDatum list 23 | Assign of lvalue * expr 24 | If of expr * stmts * stmts option 25 | Switch of expr * range option * swt list 26 | Label of label 27 | Goto of label 28 | ComputedGoto of expr * label list 29 | Jump of conv * expr * actual list * target list 30 | Call of reg list * conv * expr * actual list * 31 target list * flow list 32 | Return of conv * actual list 33 | Continuation of name * reg list 34 | Cut of expr * actual list * flow list 35 | Comment of string 36 | Block of stmt list (* For easier assembly *) 37 | SafePoint 38 | MarkStmt of stmt * srcpos 39 40and lvalue = Var of name 41 | Mem of typ * expr * align option 42 43and expr = LitInt of literalInt 44 | LitFloat of literalFloat 45 | LitChar of literalChar 46 | Fetch of lvalue 47 | Prim of name * actual list 48 | EComment of expr * string 49 50 51and flow = Aborts 52 | Cuts of name list 53 | Unwinds of name list 54 | Returns of name list 55 56and pseudoop = DataLabel of label 57 | DataExports of name list 58(* | DataWord of typesize * int * const_expr list 59 (* repeat, constant exprs *) 60 | DataFloat of typesize * int * literalFloat list 61 *) (* repeat *) 62 | DataString of string 63 | DataAlign of align (* # of Bytes *) 64 | DataComm of name * const_expr * align option 65 (* size, align *) 66 | DataLcomm of name * const_expr * align option 67 (* size, align *) 68 69and StackDatum = StackLabel of label 70(* | StackSpace of typesize * int (* size, repeat *) 71*) | StackAlign of align 72 73and swt = Swt of (int list) * stmts 74 | SwtDefault of stmts 75 76(* Compile-time expressions. Addr, but never a Reg, StackL, etc *) 77and const_expr = ConstExpr of expr 78 79(* Calling Convention *) 80and conv = Cmm | Ccall 81 82withtype 83 program = toplevel list 84and filename = string 85and memsize = int 86and sectionname = string 87and name = string 88and label = string 89and target = string 90and reg = string 91and align = int (* in bytes; a power of two *) 92and range = int * int 93and actual = expr 94and formal = typ * string (*reg*) 95and literalInt = string 96and literalFloat = string 97and literalChar = string 98and srcpos = int * int 99and stmts = stmt list 100and exprs = expr list 101 102(* An empty statement *) 103val NOP = Block [] 104 105end 106 107 108 109