X-Git-Url: http://git.joshuawise.com/snipe.git/blobdiff_plain/6c5506c5b97dabd72ba38c1f033dc4fded52cbfd..a644da892dbd55a7be1aed029dafebe28d26d27e:/codegen/blarg.sml?ds=inline diff --git a/codegen/blarg.sml b/codegen/blarg.sml index 797ab3e..4df4d48 100644 --- a/codegen/blarg.sml +++ b/codegen/blarg.sml @@ -8,17 +8,18 @@ signature BLARG = sig (* register type *) datatype reg = - R0 | R1 | R2 | R3 | FR | SP | PC + R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 | R11 | R12 | FR | SP | PC (* operands to instructions *) datatype oper = REG of reg | TEMP of Temp.temp | STACKARG of int - datatype pred = NV | NE | EQ | LT | GT | AL + datatype pred = NV | NE | EQ | LT | GT | LE | GE | AL (* instructions *) datatype opc = MOVLIT of oper * word | MOVSYM of oper * Symbol.symbol | MOVLBL of oper * Label.label | + MOVSTR of oper * Stringref.stringref | LDR of oper * oper | STO of oper * oper | MOV of oper * oper | @@ -65,17 +66,18 @@ struct (* register type *) datatype reg = - R0 | R1 | R2 | R3 | FR | SP | PC + R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 | R11 | R12 | FR | SP | PC (* operands to instructions *) datatype oper = REG of reg | TEMP of Temp.temp | STACKARG of int - datatype pred = NV | NE | EQ | LT | GT | AL + datatype pred = NV | NE | EQ | LT | GT | LE | GE | AL (* instructions *) datatype opc = MOVLIT of oper * word | MOVSYM of oper * Symbol.symbol | MOVLBL of oper * Label.label | + MOVSTR of oper * Stringref.stringref | LDR of oper * oper | STO of oper * oper | MOV of oper * oper | @@ -109,6 +111,15 @@ struct (R1, "r1"), (R2, "r2"), (R3, "r3"), + (R4, "r4"), + (R5, "r5"), + (R6, "r6"), + (R7, "r7"), + (R8, "r8"), + (R9, "r9"), + (R10, "r10"), + (R11, "r11"), + (R12, "r12"), (FR, "fr"), (SP, "sp"), (PC, "pc") ]; @@ -125,6 +136,8 @@ struct | predname EQ = "eq" | predname LT = "lt" | predname GT = "gt" + | predname GE = "ge" + | predname LE = "le" | predname AL = "" (* gives number (color) associated with reg *) @@ -132,13 +145,33 @@ struct | regtonum R1 = 1 | regtonum R2 = 2 | regtonum R3 = 3 - | regtonum _ = raise ErrorMsg.InternalError ("regtonum: Invalid register") + | regtonum R4 = 4 + | regtonum R5 = 5 + | regtonum R6 = 6 + | regtonum R7 = 7 + | regtonum R8 = 8 + | regtonum R9 = 9 + | regtonum R10 = 10 + | regtonum R11 = 11 + | regtonum R12 = 12 + | regtonum FR = 13 + | regtonum SP = 14 + | regtonum PC = 15 (* gives reg associated with number (color) *) fun numtoreg 0 = R0 | numtoreg 1 = R1 | numtoreg 2 = R2 | numtoreg 3 = R3 + | numtoreg 4 = R4 + | numtoreg 5 = R5 + | numtoreg 6 = R6 + | numtoreg 7 = R7 + | numtoreg 8 = R8 + | numtoreg 9 = R9 + | numtoreg 10 = R10 + | numtoreg 11 = R11 + | numtoreg 12 = R12 | numtoreg n = raise ErrorMsg.InternalError ("numtoreg: Invalid register "^(Int.toString n)) (* register compare *) @@ -167,13 +200,14 @@ struct val compare = Int.compare end) - fun pp_oper (REG r) = "%" ^ (regname r) + fun pp_oper (REG r) = (regname r) | pp_oper (TEMP t) = (Temp.name t) | pp_oper (STACKARG i) = "arg#"^Int.toString i - fun pp_insn pr (MOVLIT (d, w)) = "\tmov"^pr^" "^(pp_oper d)^", #"^(Word.toString w)^"\n" + fun pp_insn pr (MOVLIT (d, w)) = "\tmov"^pr^" "^(pp_oper d)^", #0x"^(Word.toString w)^"\n" | pp_insn pr (MOVSYM (d, s)) = "\tmov"^pr^" "^(pp_oper d)^", #"^(Symbol.name s)^"\n" | pp_insn pr (MOVLBL (d, l)) = "\tmov"^pr^" "^(pp_oper d)^", #"^(Label.name l)^"\n" + | pp_insn pr (MOVSTR (d, s)) = "\tmov"^pr^" "^(pp_oper d)^", #"^(Stringref.name s)^"\n" | pp_insn pr (LDR (d, s)) = "\tldr"^pr^" "^(pp_oper d)^", ["^(pp_oper s)^"]\n" | pp_insn pr (STO (d, s)) = "\tsto"^pr^" ["^(pp_oper d)^"], "^(pp_oper s)^"\n" | pp_insn pr (MOV (d, s)) = "\tmov"^pr^" "^(pp_oper d)^", "^(pp_oper s)^"\n" @@ -188,13 +222,13 @@ struct | pp_insn pr (NOTS (d, s)) = "\tnots"^pr^" "^(pp_oper d)^", "^(pp_oper s)^"\n" | pp_insn pr (PUSH (d, s)) = "\tpush"^pr^" "^(pp_oper d)^", "^(pp_oper s)^"\n" | pp_insn pr (POP (d, s)) = "\tpop"^pr^" "^(pp_oper d)^", "^(pp_oper s)^"\n" - | pp_insn pr (CALL (d, s, n)) = "\tcall"^pr^" "^(pp_oper d)^", "^(pp_oper s)^" # ("^(Int.toString n)^" args)\n" + | pp_insn pr (CALL (d, s, n)) = "\tcall"^pr^" "^(pp_oper d)^", "^(pp_oper s)^" @ ("^(Int.toString n)^" args)\n" | pp_insn pr (SHR (d, s)) = "\tshr"^pr^" "^(pp_oper d)^", "^(pp_oper s)^"\n" | pp_insn pr (SHL (d, s)) = "\tshl"^pr^" "^(pp_oper d)^", "^(pp_oper s)^"\n" (* pretty prints the asm *) fun print (DIRECTIVE(str)) = str ^ "\n" - | print (COMMENT(str)) = "// " ^ str ^ "\n" + | print (COMMENT(str)) = "@ " ^ str ^ "\n" | print (LABEL(l)) = Label.name l ^ ":\n" | print (INSN (pred, insn)) = pp_insn (predname pred) insn | print (LIVEIGN i) = print i