+
+ fun processir externs (Tree.FUNCTION (id, ir)) =
+ let
+ val name = "_l5_" ^ (Symbol.name id)
+
+ fun realname s = if (List.exists (fn n => s = n) externs)
+ then s
+ else "_l5_" ^ s
+
+ val _ = Flag.guard Flags.verbose say ("Processing function: " ^ name)
+
+ val _ = Flag.guard Flags.verbose say " Generating proto-blargCPU code..."
+ val assem = Codegen.codegen ir
+ val _ = Flag.guard Flags.assem
+ (fn () => List.app (TextIO.print o (Blarg.print)) assem) ()
+
+ val _ = Flag.guard Flags.verbose say " Optimizing pre-liveness..."
+ val assem = Optimizer.optimize_preliveness (!enabledopts) assem
+
+ val _ = Flag.guard Flags.verbose say " Analyzing liveness..."
+ val (preds, liveness) = Liveness.liveness assem;
+ val _ = Flag.guard Flags.liveness
+ (fn () => List.app
+ (fn (asm, liv) =>
+ TextIO.print (
+ let
+ val xpp = Blarg.print asm
+ val xpp = String.extract (xpp, 0, SOME (size xpp - 1))
+ val spaces = implode (List.tabulate (40 - size xpp, fn _ => #" ")) handle size => ""
+ val lpp = Liveness.prettyprint liv
+ val lpp = String.extract (lpp, 0, SOME (size lpp - 1))
+ val spaces2 = implode (List.tabulate (40 - size lpp, fn _ => #" ")) handle size => ""
+ in
+ xpp ^ spaces ^ lpp ^ spaces2 ^ "\n"
+ end))
+ (ListPair.zip (assem, Liveness.listify liveness))) ()
+
+ val _ = Flag.guard Flags.verbose say " Graphing..."
+ val (igraph,temps) = Igraph.gengraph (preds, liveness)
+
+ val _ = Flag.guard Flags.verbose say " Ordering..."
+ val order = ColorOrder.colororder (igraph,temps)
+
+ val _ = Flag.guard Flags.verbose say " Coloring..."
+ val colors = Colorizer.colorize order igraph
+ val _ = Flag.guard Flags.color
+ (fn () => List.app (TextIO.print o
+ (fn (t, i) =>
+ (Temp.name t) ^ " => " ^ (
+ if (i <= 10)
+ then (Blarg.pp_oper (Blarg.REG (Blarg.numtoreg i)))
+ else
+ "spill[" ^ Int.toString (i - 11) ^ "]")
+ ^ "--"^ Int.toString i ^ "\n"))
+ colors) ()
+
+ val _ = Flag.guard Flags.verbose say " Solidifying blargCPU code..."
+ val x86 = Solidify.solidify colors assem
+
+ val _ = Flag.guard Flags.verbose say " Optimizing final assembly..."
+ val x86p = Optimizer.optimize_final (!enabledopts) x86
+
+ val _ = Flag.guard Flags.verbose say " Stringifying..."
+ val x86d = [Blarg.DIRECTIVE(".globl " ^ name),
+ Blarg.DIRECTIVE(name ^ ":")]
+ @ x86p
+ val code = Stringify.stringify realname x86d
+ in
+ code
+ end