Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/cm/bootstrap/btcompile.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/bootstrap/btcompile.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 363 - (view) (download)

1 : blume 327 (*
2 :     * The bootstrap compiler.
3 :     * (Formerly known as "batch" compiler.)
4 :     *
5 :     * (C) 1999 Lucent Technologies, Bell Laboratories
6 :     *
7 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
8 :     *)
9 : blume 329 functor BootstrapCompileFn (structure MachDepVC: MACHDEP_VC
10 : blume 357 val os: SMLofNJ.SysInfo.os_kind) :> sig
11 : blume 362 val recomp' : string option -> bool
12 :     val recomp : unit -> bool
13 :     val deliver' : string option -> bool
14 :     val deliver : unit -> bool
15 :     val reset : unit -> unit
16 : blume 357 end = struct
17 :    
18 : blume 327 structure EM = GenericVC.ErrorMsg
19 :     structure E = GenericVC.Environment
20 :     structure SE = GenericVC.CMStaticEnv
21 :     structure BE = GenericVC.BareEnvironment
22 :     structure PS = GenericVC.PersStamps
23 :     structure CoerceEnv = GenericVC.CoerceEnv
24 : blume 336 structure SSV = SpecificSymValFn (structure MachDepVC = MachDepVC
25 :     val os = os)
26 : blume 327
27 :     (* Since the bootstrap compiler never executes any of the code
28 :     * it produces, we don't need any dynamic values. Therefore,
29 :     * we create RecompPersstate (but not FullPersstate!) and
30 :     * instantiate Recomp as well as RecompTraversal.
31 :     * Since RecompPersstate is not part of any surrounding FullPersstate,
32 :     * function "discard_value" simply does nothing. *)
33 :     structure RecompPersstate =
34 :     RecompPersstateFn (structure MachDepVC = MachDepVC
35 :     val discard_code = true
36 : blume 362 fun stable_value_present i = false
37 :     fun new_smlinfo i = ())
38 : blume 360
39 : blume 327 structure Recomp = RecompFn (structure PS = RecompPersstate)
40 :     structure RT = CompileGenericFn (structure CT = Recomp)
41 :    
42 :     fun recomp gp g = isSome (RT.group gp g)
43 :    
44 :     (* instantiate Stabilize... *)
45 : blume 329 structure Stabilize =
46 :     StabilizeFn (fun bn2statenv gp i = #1 (#stat (valOf (RT.bnode gp i)))
47 : blume 357 val getPid = RecompPersstate.pid_fetch_sml
48 :     fun warmup (i, p) = ()
49 : blume 363 val recomp = recomp
50 :     val transfer_state = RecompPersstate.transfer_state)
51 : blume 327 (* ... and Parse *)
52 : blume 362 structure Parse = ParseFn (structure Stabilize = Stabilize
53 :     val pending = AutoLoad.getPending)
54 : blume 327
55 : blume 358 fun listName p =
56 :     case OS.Path.fromString p of
57 :     { vol = "", isAbs = false, arcs = _ :: arc1 :: arcn } => let
58 :     fun win32name () =
59 :     concat (arc1 ::
60 :     foldr (fn (a, r) => "\\" :: a :: r) [] arcn)
61 :     in
62 :     case os of
63 :     SMLofNJ.SysInfo.WIN32 => win32name ()
64 :     | _ => OS.Path.toString { isAbs = false, vol = "",
65 :     arcs = arc1 :: arcn }
66 :     end
67 :     | _ => raise Fail "BootstrapCompile:listName: bad name"
68 : blume 327
69 : blume 362 fun compile deliver dbopt = let
70 : blume 358
71 : blume 360 val dirbase = getOpt (dbopt, BtNames.dirbaseDefault)
72 :     val pcmodespec = BtNames.pcmodespec
73 :     val initgspec = BtNames.initgspec
74 :     val maingspec = BtNames.maingspec
75 :    
76 : blume 357 val arch = MachDepVC.architecture
77 :     val osname = FilenamePolicy.kind2name os
78 :     val bindir = concat [dirbase, ".bin.", arch, "-", osname]
79 :     val bootdir = concat [dirbase, ".boot.", arch, "-", osname]
80 :    
81 : blume 329 val keep_going = EnvConfig.getSet StdConfig.keep_going NONE
82 :    
83 : blume 354 val ctxt = SrcPath.cwdContext ()
84 : blume 329
85 : blume 357 val pidfile = OS.Path.joinDirFile { dir = bootdir, file = "RTPID" }
86 : blume 362 val listfile = OS.Path.joinDirFile { dir = bootdir, file = "BOOTLIST" }
87 : blume 329
88 : blume 361 val pcmode = PathConfig.new ()
89 :     val _ = PathConfig.processSpecFile (pcmode, pcmodespec)
90 : blume 329
91 : blume 354 fun stdpath s = SrcPath.standard pcmode { context = ctxt, spec = s }
92 : blume 352
93 :     val initgspec = stdpath initgspec
94 :     val maingspec = stdpath maingspec
95 :    
96 : blume 360 val cmifile = valOf (SrcPath.reAnchoredName (initgspec, bootdir))
97 :     handle Option => raise Fail "BootstrapCompile: cmifile"
98 :    
99 : blume 357 val initfnpolicy =
100 :     FilenamePolicy.separate { bindir = bootdir, bootdir = bootdir }
101 :     { arch = arch, os = os }
102 : blume 329
103 : blume 357 val mainfnpolicy =
104 :     FilenamePolicy.separate { bindir = bindir, bootdir = bootdir }
105 :     { arch = arch, os = os }
106 :    
107 :     fun mkParam { primconf, pervasive, pervcorepids, fnpolicy }
108 :     { corenv } =
109 : blume 349 { primconf = primconf,
110 :     fnpolicy = fnpolicy,
111 :     pcmode = pcmode,
112 :     symenv = SSV.env,
113 :     keep_going = keep_going,
114 :     pervasive = pervasive,
115 :     corenv = corenv,
116 :     pervcorepids = pervcorepids }
117 :    
118 : blume 327 val emptydyn = E.dynamicPart E.emptyEnv
119 :    
120 :     (* first, build an initial GeneralParam.info, so we can
121 :     * deal with the pervasive env and friends... *)
122 :    
123 : blume 360 val primconf = Primitive.primEnvConf
124 : blume 349 val mkInitParam = mkParam { primconf = primconf,
125 :     pervasive = E.emptyEnv,
126 : blume 357 pervcorepids = PidSet.empty,
127 :     fnpolicy = initfnpolicy }
128 : blume 327
129 : blume 349 val param_nocore = mkInitParam { corenv = BE.staticPart BE.emptyEnv }
130 :    
131 : blume 327 val groupreg = GroupReg.new ()
132 :     val errcons = EM.defaultConsumer ()
133 : blume 329 val ginfo_nocore = { param = param_nocore, groupreg = groupreg,
134 :     errcons = errcons }
135 : blume 327
136 :     fun main_compile arg = let
137 : blume 335 val { rts, core, pervasive, primitives, binpaths } = arg
138 : blume 327
139 : blume 329 val ovldR = GenericVC.Control.overloadKW
140 :     val savedOvld = !ovldR
141 :     val _ = ovldR := true
142 :    
143 : blume 327 (* here we build a new gp -- the one that uses the freshly
144 :     * brewed pervasive env, core env, and primitives *)
145 : blume 358 val core = valOf (RT.sbnode ginfo_nocore core)
146 : blume 329 val corenv = CoerceEnv.es2bs (#1 (#stat core))
147 : blume 356 val core_sym = #1 (#sym core)
148 : blume 329
149 :     (* The following is a bit of a hack (but corenv is a hack anyway):
150 :     * As soon as we have core available, we have to patch the
151 :     * ginfo to include the correct corenv (because virtually
152 :     * everybody else needs access to corenv). *)
153 : blume 349 val param_justcore = mkInitParam { corenv = corenv }
154 : blume 329 val ginfo_justcore = { param = param_justcore, groupreg = groupreg,
155 :     errcons = errcons }
156 :    
157 : blume 358 fun rt n = valOf (RT.sbnode ginfo_justcore n)
158 : blume 327 val rts = rt rts
159 :     val pervasive = rt pervasive
160 :    
161 :     fun sn2pspec (name, n) = let
162 :     val { stat = (s, sp), sym = (sy, syp), ctxt } = rt n
163 :     val env =
164 :     E.mkenv { static = s, symbolic = sy, dynamic = emptydyn }
165 :     val pidInfo = { statpid = sp, sympid = syp, ctxt = ctxt }
166 :     in
167 :     { name = name, env = env, pidInfo = pidInfo }
168 :     end
169 :    
170 :     val pspecs = map sn2pspec primitives
171 :    
172 : blume 329 val _ = ovldR := savedOvld
173 :    
174 : blume 356 (* This is a hack but must be done for both the symbolic
175 :     * and later the dynamic part of the core environment:
176 :     * we must include these parts in the pervasive env. *)
177 :     val perv_sym = E.layerSymbolic (#1 (#sym pervasive), core_sym)
178 :    
179 : blume 349 val param =
180 :     mkParam { primconf = Primitive.configuration pspecs,
181 : blume 327 pervasive = E.mkenv { static = #1 (#stat pervasive),
182 : blume 356 symbolic = perv_sym,
183 : blume 327 dynamic = emptydyn },
184 :     pervcorepids =
185 :     PidSet.addList (PidSet.empty,
186 :     [#2 (#stat pervasive),
187 :     #2 (#sym pervasive),
188 : blume 357 #2 (#stat core)]),
189 :     fnpolicy = mainfnpolicy }
190 : blume 349 { corenv = corenv }
191 : blume 362 val stab =
192 :     if deliver then SOME true else NONE
193 : blume 327 in
194 : blume 362 case Parse.parse NONE param stab maingspec of
195 : blume 349 NONE => false
196 : blume 329 | SOME (g, gp) =>
197 : blume 349 if recomp gp g then let
198 :     val rtspid = PS.toHex (#2 (#stat rts))
199 :     val bootfiles =
200 :     map (fn x => (x, NONE)) binpaths @
201 :     MkBootList.group g
202 :     fun writeList s = let
203 :     fun offset NONE = ["\n"]
204 :     | offset (SOME i) = ["@", Int.toString i, "\n"]
205 :     fun showBootFile (p, off) =
206 : blume 358 TextIO.output (s, concat (listName p ::
207 :     offset off))
208 : blume 349 in
209 :     app showBootFile bootfiles
210 :     end
211 : blume 360 fun cpCMI (ins, outs) = let
212 :     val N = 4096
213 :     fun cp () =
214 :     if TextIO.endOfStream ins then ()
215 :     else (TextIO.output (outs,
216 :     TextIO.inputN (ins, N));
217 :     cp ())
218 :     in
219 :     cp ()
220 :     end
221 : blume 349 in
222 : blume 362 Say.say ["Runtime System PID is: ", rtspid, "\n"];
223 :     if deliver then
224 :     (SafeIO.perform { openIt = fn () =>
225 : blume 354 AutoDir.openTextOut pidfile,
226 : blume 349 closeIt = TextIO.closeOut,
227 :     work = fn s =>
228 :     TextIO.output (s, rtspid ^ "\n"),
229 :     cleanup = fn () =>
230 : blume 354 OS.FileSys.remove pidfile
231 :     handle _ => () };
232 : blume 349 SafeIO.perform { openIt = fn () =>
233 : blume 354 AutoDir.openTextOut listfile,
234 : blume 349 closeIt = TextIO.closeOut,
235 :     work = writeList,
236 :     cleanup = fn () =>
237 : blume 354 OS.FileSys.remove listfile
238 :     handle _ => () };
239 : blume 360 SafeIO.perform { openIt = fn () =>
240 :     (SrcPath.openTextIn initgspec,
241 :     AutoDir.openTextOut cmifile),
242 :     closeIt = fn (ins, outs) =>
243 :     (TextIO.closeIn ins;
244 :     TextIO.closeOut outs),
245 :     work = cpCMI,
246 :     cleanup = fn () =>
247 :     OS.FileSys.remove cmifile
248 : blume 362 handle _ => () })
249 :     else ();
250 :     true
251 : blume 349 end
252 :     else false
253 : blume 351 end handle Option => (RT.reset (); false)
254 : blume 330 (* to catch valOf failures in "rt" *)
255 : blume 327 in
256 : blume 329 case BuildInitDG.build ginfo_nocore initgspec of
257 : blume 327 SOME x => main_compile x
258 : blume 349 | NONE => false
259 : blume 327 end
260 : blume 362
261 :     val recomp' = compile false
262 :     fun recomp () = recomp' NONE
263 :     val deliver' = compile true
264 :     fun deliver () = deliver' NONE
265 :     fun reset () =
266 :     (RecompPersstate.reset ();
267 :     RT.resetAll ();
268 :     Recomp.reset ())
269 : blume 327 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0