Add the tiger source code bundle from the book site
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
915660c8a7
commit
33d8bac511
87 changed files with 3252 additions and 0 deletions
39
tiger/chap9/main.sml
Normal file
39
tiger/chap9/main.sml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
structure Main = struct
|
||||
|
||||
structure Tr = Translate
|
||||
structure F = Frame
|
||||
structure R = RegAlloc
|
||||
|
||||
fun getsome (SOME x) = x
|
||||
|
||||
fun emitproc out (F.PROC{body,frame}) =
|
||||
let val _ = print ("emit " ^ Frame.name frame ^ "\n")
|
||||
(* val _ = Printtree.printtree(out,body); *)
|
||||
val stms = Canon.linearize body
|
||||
(* val _ = app (fn s => Printtree.printtree(out,s)) stms; *)
|
||||
val stms' = Canon.traceSchedule(Canon.basicBlocks stms)
|
||||
val instrs = List.concat(map (Mips.codegen frame) stms')
|
||||
val format0 = Assem.format(Temp.makestring)
|
||||
in app (fn i => TextIO.output(out,format0 i)) instrs;
|
||||
end
|
||||
end
|
||||
| emitproc out (F.STRING(lab,s)) = TextIO.output(out,F.string(lab,s))
|
||||
|
||||
fun withOpenFile fname f =
|
||||
let val out = TextIO.openOut fname
|
||||
in (f out before TextIO.closeOut out)
|
||||
handle e => (TextIO.closeOut out; raise e)
|
||||
end
|
||||
|
||||
fun compile filename =
|
||||
let val absyn = Parse.parse filename
|
||||
val frags = (FindEscape.prog absyn; Semant.transProg absyn)
|
||||
in
|
||||
withOpenFile (filename ^ ".s")
|
||||
(fn out => (app (emitproc out) frags))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue