X-Git-Url: http://git.joshuawise.com/snipe.git/blobdiff_plain/12aa4087bee3e70f170d7457794921de4e385227..5e46186e8e7b8f4d9a28cb95954d8a75b6b34f81:/codegen/stringifier.sml?ds=sidebyside diff --git a/codegen/stringifier.sml b/codegen/stringifier.sml index 1f21bab..6124a55 100644 --- a/codegen/stringifier.sml +++ b/codegen/stringifier.sml @@ -1,39 +1,27 @@ -(* stringifier - * Gathers tiberium, fires rockets +(* L3 compiler + * stringifier * turns a list of x86 insns into the assembly code to generate them - * Author: Chris Lu + * Author: Chris Lu *) signature STRINGIFY = sig - type tiberium = x86.insn list - type rockets = string - val stringify : tiberium -> rockets + type asm = Blarg.insn list + val stringify : (string -> string) -> asm -> string end structure Stringify :> STRINGIFY = struct - type tiberium = x86.insn list - type rockets = string - structure X = x86 + type asm = Blarg.insn list + structure X = Blarg - (* val stringify : tiberium -> rockets + (* val stringify : asm -> string * turns a x86 instruction list into a string of assembly code for these instructions *) - fun stringify' (X.MOVL (r1, r2)) = "\tmovl " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n" - | stringify' (X.SUBL (r1, r2)) = "\tsubl " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n" - | stringify' (X.IMUL (r1, r2)) = "\timul " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n" - | stringify' (X.IMUL3 (r1, r2, k)) = "\timul " ^ X.prettyprint_oper (X.CONST k) ^ ", " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n" - | stringify' (X.ADDL (r1, r2)) = "\taddl " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n" - | stringify' (X.LEAL (r1, r2, r3)) = "\tleal (" ^ X.prettyprint_oper r2 ^ "," ^ X.prettyprint_oper r3 ^ "), " ^ X.prettyprint_oper r1 ^ "\n" - | stringify' (X.IDIVL (r1)) = "\tidivl " ^ X.prettyprint_oper r1 ^ "\n" - | stringify' (X.NEG (r1)) = "\tneg " ^ X.prettyprint_oper r1 ^ "\n" - | stringify' (X.RET) = "\tret\n" - | stringify' (X.CLTD) = "\tcltd\n" - | stringify' (X.DIRECTIVE(s)) = s ^ "\n" - | stringify' (X.COMMENT(s)) = "\t// " ^ s ^ "\n" + fun (*stringify' rn (X.CALL (l, n)) = X.print (X.CALL ((Symbol.symbol (rn (Symbol.name l))), n)) + | *)stringify' rn x = X.print x - (* val stringify : tiberium -> rockets *) - fun stringify l = foldr (fn (a,b) => (stringify' a) ^ b) ("") l + (* val stringify : asm -> string *) + fun stringify realname l = String.concat (List.map (stringify' realname) l) end