-(* stringifier
- * Gathers tiberium, fires rockets
+(* L3 compiler
+ * stringifier
* turns a list of x86 insns into the assembly code to generate them
- * Author: Chris Lu <czl@andrew>
+ * Author: Chris Lu <czl@andrew.cmu.edu>
*)
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.INSN (pred, X.MOVSYM (r, n))) = X.print (X.INSN (pred, X.MOVSYM (r, (Symbol.symbol (rn (Symbol.name 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