-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.sml
63 lines (62 loc) · 2.77 KB
/
template.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
CM.make "sources.cm";
SMLofNJ.Internals.TDP.mode := true;
structure G = Flow.Graph;
structure Frame = MipsFrame;
let val program = "$1"
val absyn_tree = Parse.parse program
val frag_list = Semant.transProg absyn_tree
fun printFrag (Frame.PROC {body, frame}) =
( print (Symbol.name (Frame.name frame) );
print (":\n");
Printtree.printtree (TextIO.stdOut, body);
print ("Linearized:\n");
let
val stms = Canon.linearize body
val stms' = Canon.traceSchedule(Canon.basicBlocks stms)
in
app (fn s => Printtree.printtree(TextIO.stdOut,s)) stms';
print ("Graph:\n");
let
val instrs = List.concat(map (MipsGen.codegen frame) stms')
val instrs' = Frame.procEntryExit2 (frame, instrs)
val {prolog, body, epilog} = Frame.procEntryExit3 (frame, instrs')
val format0 = Assem.format(Frame.register_name)
in
let
val fgraph = MakeGraph.instrs2graph body
val igraph = Liveness.interferenceGraph fgraph
fun strTL templist =
foldl (fn (t, s) => s ^ " " ^ (Temp.makestring t)) "" templist
fun nodeToString (nid, Flow.INS{def, use, ismove}) =
(Int.toString nid) ^ ", def:" ^ (strTL def) ^ ", use:" ^ (strTL use) ^ ", move: " ^ (Bool.toString ismove)
(* val () = G.printGraph nodeToString fgraph *)
in
Liveness.show igraph
end;
print ("Assembly:\n");
TextIO.output(TextIO.stdOut, prolog);
app (fn i => (TextIO.output(TextIO.stdOut, format0 i); print("\n"))) body;
TextIO.output(TextIO.stdOut, epilog);
let
val (body', allocation) = RegAlloc.alloc (body, frame)
fun tempName temp =
"$" ^ (Option.valOf (Temp.Map.find (allocation, temp)))
val format1 = Assem.format(tempName)
in
print("colored:\n");
TextIO.output(TextIO.stdOut, prolog);
app (fn i => (TextIO.output(TextIO.stdOut, format1 i); print("\n"))) body';
TextIO.output(TextIO.stdOut, epilog)
end
end;
print("\n\n")
end)
| printFrag (Frame.STRING (label, str)) = (
print (Symbol.name label);
print (": " ^ str ^ "\n")
)
in
PrintAbsyn.print (TextIO.stdOut , absyn_tree);
map printFrag frag_list;
if !ErrorMsg.anyErrors then print "ERROR FOUND\n" else ()
end