26 |
val lcontract = phase "Compiler 052 lcontract" LContract.lcontract |
val lcontract = phase "Compiler 052 lcontract" LContract.lcontract |
27 |
val fcollect = phase "Compiler 052a fcollect" Collect.collect |
val fcollect = phase "Compiler 052a fcollect" Collect.collect |
28 |
val fcontract = phase "Compiler 052b fcontract" FContract.contract |
val fcontract = phase "Compiler 052b fcontract" FContract.contract |
29 |
val fcontract = fcontract o fcollect |
val fcontract = fn f => (lcontract f; fcontract(fcollect f, Stats.newCounter[])) |
30 |
|
|
31 |
val specialize= phase "Compiler 053 specialize" Specialize.specialize |
val specialize= phase "Compiler 053 specialize" Specialize.specialize |
32 |
val wrapping = phase "Compiler 054 wrapping" Wrapping.wrapping |
val wrapping = phase "Compiler 054 wrapping" Wrapping.wrapping |
76 |
done () |
done () |
77 |
end (* function dumpTerm *) |
end (* function dumpTerm *) |
78 |
|
|
79 |
|
val fcs : (FLINT.prog -> FLINT.prog) list ref = ref [] |
80 |
|
|
81 |
(** compiling FLINT code into the binary machine code *) |
(** compiling FLINT code into the binary machine code *) |
82 |
fun flintcomp(flint, compInfo as {error, sourceName=src, ...}: CB.compInfo) = |
fun flintcomp(flint, compInfo as {error, sourceName=src, ...}: CB.compInfo) = |
83 |
let fun err severity s = |
let fun err severity s = |
93 |
check (ChkFlint.checkTop, PPFlint.printFundec, |
check (ChkFlint.checkTop, PPFlint.printFundec, |
94 |
"FLINT") (CTRL.check, b, s) |
"FLINT") (CTRL.check, b, s) |
95 |
|
|
96 |
|
val fcing = ref (!fcs) |
97 |
|
|
98 |
|
(* fun fcontract f = |
99 |
|
case !fcing |
100 |
|
of fcontract::fcs => (fcing := fcs; fcontract f) |
101 |
|
| [] => let val fcc = Stats.newCounter[] |
102 |
|
val fcname = "FContract-"^(Int.toString(length(!fcs))) |
103 |
|
val coname = "FCollect-"^(Int.toString(length(!fcs))) |
104 |
|
val lcname = "LContract-"^(Int.toString(length(!fcs))) |
105 |
|
val fcstat = Stats.newStat(fcname, [fcc]) |
106 |
|
val fcphase = phase ("Compiler 052b "^fcname) |
107 |
|
FContract.contract |
108 |
|
val cophase = phase ("Compiler 052a "^coname) |
109 |
|
Collect.collect |
110 |
|
val lcphase = phase ("Compiler 052 "^lcname) |
111 |
|
LContract.lcontract |
112 |
|
fun g c = (lcphase c; fcphase(cophase c,fcc)) |
113 |
|
in |
114 |
|
Stats.registerStat fcstat; |
115 |
|
fcs := (!fcs) @ [g]; |
116 |
|
g f |
117 |
|
end *) |
118 |
|
|
119 |
(* f:FLINT.prog flint codee |
(* f:FLINT.prog flint codee |
120 |
* r:boot whether it has gone through reify yet |
* r:boot whether it has gone through reify yet |
121 |
* l:string last phase through which it went *) |
* l:string last phase through which it went *) |
145 |
fun check (f,r,l) = (chkF (r, l) f; (f, r, l)) |
fun check (f,r,l) = (chkF (r, l) f; (f, r, l)) |
146 |
|
|
147 |
fun runphase' (arg as (p,{1=f,...})) = |
fun runphase' (arg as (p,{1=f,...})) = |
148 |
((* say("Phase "^p^"..."); *) |
(if !CTRL.printPhases then say("Phase "^p^"...") else (); |
149 |
(runphase arg) (* before *) |
((check o print o runphase) arg) before |
150 |
(* say("..."^p^" Done.\n") *)) |
(if !CTRL.printPhases then say("..."^p^" Done.\n") else ())) |
151 |
handle x => (say ("\nwhile in "^p^" phase"); |
handle x => (say ("\nwhile in "^p^" phase\n"); |
152 |
dumpTerm(PPFlint.printFundec,"FLINT.core", f); |
dumpTerm(PPFlint.printFundec,"FLINT.core", f); |
153 |
raise x) |
raise x) |
154 |
|
|
155 |
(* the "id" phases is just added to do the print/check at the entrance *) |
(* the "id" phases is just added to do the print/check at the entrance *) |
156 |
val (flint,r,_) = foldl (check o print o runphase') |
val (flint,r,_) = foldl runphase' |
157 |
(flint,false,"flintnm") |
(flint,false,"flintnm") |
158 |
((* "id" :: *) !CTRL.phases) |
((* "id" :: *) !CTRL.phases) |
159 |
val flint = if r then flint else (say "\n!!Forgot reify!!\n"; reify flint) |
val flint = if r then flint else (say "\n!!Forgot reify!!\n"; reify flint) |