]> Joshua Wise's Git repositories - snipe.git/blame - codegen/stringifier.sml
Initial import of l1c
[snipe.git] / codegen / stringifier.sml
CommitLineData
12aa4087
JW
1(* stringifier
2 * Gathers tiberium, fires rockets
3 * turns a list of x86 insns into the assembly code to generate them
4 * Author: Chris Lu <czl@andrew>
5 *)
6
7signature STRINGIFY =
8sig
9 type tiberium = x86.insn list
10 type rockets = string
11 val stringify : tiberium -> rockets
12end
13
14structure Stringify :> STRINGIFY =
15struct
16 type tiberium = x86.insn list
17 type rockets = string
18 structure X = x86
19
20 (* val stringify : tiberium -> rockets
21 * turns a x86 instruction list into a string of assembly code for these instructions *)
22
23 fun stringify' (X.MOVL (r1, r2)) = "\tmovl " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n"
24 | stringify' (X.SUBL (r1, r2)) = "\tsubl " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n"
25 | stringify' (X.IMUL (r1, r2)) = "\timul " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n"
26 | stringify' (X.IMUL3 (r1, r2, k)) = "\timul " ^ X.prettyprint_oper (X.CONST k) ^ ", " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n"
27 | stringify' (X.ADDL (r1, r2)) = "\taddl " ^ X.prettyprint_oper r2 ^ ", " ^ X.prettyprint_oper r1 ^ "\n"
28 | stringify' (X.LEAL (r1, r2, r3)) = "\tleal (" ^ X.prettyprint_oper r2 ^ "," ^ X.prettyprint_oper r3 ^ "), " ^ X.prettyprint_oper r1 ^ "\n"
29 | stringify' (X.IDIVL (r1)) = "\tidivl " ^ X.prettyprint_oper r1 ^ "\n"
30 | stringify' (X.NEG (r1)) = "\tneg " ^ X.prettyprint_oper r1 ^ "\n"
31 | stringify' (X.RET) = "\tret\n"
32 | stringify' (X.CLTD) = "\tcltd\n"
33 | stringify' (X.DIRECTIVE(s)) = s ^ "\n"
34 | stringify' (X.COMMENT(s)) = "\t// " ^ s ^ "\n"
35
36 (* val stringify : tiberium -> rockets *)
37 fun stringify l = foldr (fn (a,b) => (stringify' a) ^ b) ("") l
38
39end
This page took 0.029177 seconds and 4 git commands to generate.