structure Main = struct structure Tr = Translate structure Frame = MipsFrame (* Structure R = RegAlloc *) fun getsome (SOME x) = x fun emitproc out (Frame.PROC{body,frame}) = let val _ = print ("emit " ^ (Temp.labelname (Frame.name frame)) ^ "\n") val _ = Printtree.printtree(TextIO.stdErr,body) val stms = Canon.linearize body val _ = TextIO.print "after linearization\n" val _ = (app (fn s => Printtree.printtree(TextIO.stdErr,s)) stms) val stms' = Canon.traceSchedule(Canon.basicBlocks stms) val instrs = List.concat(map (Mips.codegen frame) stms') val format0 = Assem.format(Frame.string_of_temp) in TextIO.output(out, ".text\n"); app (fn i => TextIO.output(out,format0 i)) instrs end | emitproc out (Frame.STRING(lab,s)) = TextIO.output(out,Frame.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.transverseProg absyn; Semant.transProg absyn) in withOpenFile (filename ^ ".s") (fn out => (app (emitproc out) frags)) end end