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

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