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 358 - (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 327
12 : blume 357 val compile :
13 :     { dirbase: string,
14 :     pcmodespec: string,
15 :     initgspec: string,
16 : blume 358 maingspec: string }
17 : blume 357 -> bool
18 :    
19 :     end = struct
20 :    
21 : blume 327 structure EM = GenericVC.ErrorMsg
22 :     structure E = GenericVC.Environment
23 :     structure SE = GenericVC.CMStaticEnv
24 :     structure BE = GenericVC.BareEnvironment
25 :     structure PS = GenericVC.PersStamps
26 :     structure CoerceEnv = GenericVC.CoerceEnv
27 : blume 336 structure SSV = SpecificSymValFn (structure MachDepVC = MachDepVC
28 :     val os = os)
29 : blume 327
30 :     (* Since the bootstrap compiler never executes any of the code
31 :     * it produces, we don't need any dynamic values. Therefore,
32 :     * we create RecompPersstate (but not FullPersstate!) and
33 :     * instantiate Recomp as well as RecompTraversal.
34 :     * Since RecompPersstate is not part of any surrounding FullPersstate,
35 :     * function "discard_value" simply does nothing. *)
36 :     structure RecompPersstate =
37 :     RecompPersstateFn (structure MachDepVC = MachDepVC
38 :     val discard_code = true
39 :     fun discard_value (i: SmlInfo.info) = ())
40 :     structure Recomp = RecompFn (structure PS = RecompPersstate)
41 :     structure RT = CompileGenericFn (structure CT = Recomp)
42 :    
43 :     fun recomp gp g = isSome (RT.group gp g)
44 :    
45 :     (* instantiate Stabilize... *)
46 : blume 329 structure Stabilize =
47 :     StabilizeFn (fun bn2statenv gp i = #1 (#stat (valOf (RT.bnode gp i)))
48 : blume 357 val getPid = RecompPersstate.pid_fetch_sml
49 :     fun warmup (i, p) = ()
50 : blume 329 val recomp = recomp)
51 : blume 327 (* ... and Parse *)
52 :     structure Parse = ParseFn (structure Stabilize = Stabilize)
53 :    
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 358 fun compile { dirbase, pcmodespec, initgspec, maingspec } = let
69 :    
70 : blume 357 val arch = MachDepVC.architecture
71 :     val osname = FilenamePolicy.kind2name os
72 :     val bindir = concat [dirbase, ".bin.", arch, "-", osname]
73 :     val bootdir = concat [dirbase, ".boot.", arch, "-", osname]
74 :    
75 : blume 329 val keep_going = EnvConfig.getSet StdConfig.keep_going NONE
76 :    
77 : blume 354 val ctxt = SrcPath.cwdContext ()
78 : blume 329
79 : blume 357 val pidfile = OS.Path.joinDirFile { dir = bootdir, file = "RTPID" }
80 :     val listfile = OS.Path.joinDirFile { dir = bootdir, file = "BINLIST" }
81 : blume 329
82 : blume 344 val pcmode = let
83 : blume 345 fun work s = let
84 :     fun loop l = let
85 :     val line = TextIO.inputLine s
86 :     in
87 :     if line = "" then PathConfig.hardwire l
88 :     else case String.tokens Char.isSpace line of
89 :     [a, s] => loop ((a, s) :: l)
90 : blume 354 | _ => (Say.say [pcmodespec,
91 : blume 345 ": malformed line (ignored)\n"];
92 :     loop l)
93 :     end
94 : blume 329 in
95 : blume 345 loop []
96 : blume 329 end
97 :     in
98 : blume 354 SafeIO.perform { openIt = fn () => TextIO.openIn pcmodespec,
99 : blume 345 closeIt = TextIO.closeIn,
100 :     work = work,
101 :     cleanup = fn () => () }
102 : blume 329 end
103 :    
104 : blume 354 fun stdpath s = SrcPath.standard pcmode { context = ctxt, spec = s }
105 : blume 352
106 :     val initgspec = stdpath initgspec
107 :     val maingspec = stdpath maingspec
108 :    
109 : blume 357 val initfnpolicy =
110 :     FilenamePolicy.separate { bindir = bootdir, bootdir = bootdir }
111 :     { arch = arch, os = os }
112 : blume 329
113 : blume 357 val mainfnpolicy =
114 :     FilenamePolicy.separate { bindir = bindir, bootdir = bootdir }
115 :     { arch = arch, os = os }
116 :    
117 :     fun mkParam { primconf, pervasive, pervcorepids, fnpolicy }
118 :     { corenv } =
119 : blume 349 { primconf = primconf,
120 :     fnpolicy = fnpolicy,
121 :     pcmode = pcmode,
122 :     symenv = SSV.env,
123 :     keep_going = keep_going,
124 :     pervasive = pervasive,
125 :     corenv = corenv,
126 :     pervcorepids = pervcorepids }
127 :    
128 : blume 327 val emptydyn = E.dynamicPart E.emptyEnv
129 :    
130 :     (* first, build an initial GeneralParam.info, so we can
131 :     * deal with the pervasive env and friends... *)
132 :     local
133 :     (* We could actually go and calculate the actual pid of primEnv.
134 :     * But in reality it's pretty pointless to do so... *)
135 :     val bogusPid = PS.fromBytes (Byte.stringToBytes "0123456789abcdef")
136 :     val pspec = { name = "primitive",
137 :     env = E.mkenv { static = E.primEnv,
138 :     symbolic = E.symbolicPart E.emptyEnv,
139 :     dynamic = emptydyn },
140 :     pidInfo = { statpid = bogusPid,
141 :     sympid = bogusPid,
142 :     ctxt = SE.empty } }
143 :     in
144 :     val primconf = Primitive.configuration [pspec]
145 :     end
146 :    
147 : blume 349 val mkInitParam = mkParam { primconf = primconf,
148 :     pervasive = E.emptyEnv,
149 : blume 357 pervcorepids = PidSet.empty,
150 :     fnpolicy = initfnpolicy }
151 : blume 327
152 : blume 349 val param_nocore = mkInitParam { corenv = BE.staticPart BE.emptyEnv }
153 :    
154 : blume 327 val groupreg = GroupReg.new ()
155 :     val errcons = EM.defaultConsumer ()
156 : blume 329 val ginfo_nocore = { param = param_nocore, groupreg = groupreg,
157 :     errcons = errcons }
158 : blume 327
159 :     fun main_compile arg = let
160 : blume 335 val { rts, core, pervasive, primitives, binpaths } = arg
161 : blume 327
162 : blume 329 val ovldR = GenericVC.Control.overloadKW
163 :     val savedOvld = !ovldR
164 :     val _ = ovldR := true
165 :    
166 : blume 327 (* here we build a new gp -- the one that uses the freshly
167 :     * brewed pervasive env, core env, and primitives *)
168 : blume 358 val core = valOf (RT.sbnode ginfo_nocore core)
169 : blume 329 val corenv = CoerceEnv.es2bs (#1 (#stat core))
170 : blume 356 val core_sym = #1 (#sym core)
171 : blume 329
172 :     (* The following is a bit of a hack (but corenv is a hack anyway):
173 :     * As soon as we have core available, we have to patch the
174 :     * ginfo to include the correct corenv (because virtually
175 :     * everybody else needs access to corenv). *)
176 : blume 349 val param_justcore = mkInitParam { corenv = corenv }
177 : blume 329 val ginfo_justcore = { param = param_justcore, groupreg = groupreg,
178 :     errcons = errcons }
179 :    
180 : blume 358 fun rt n = valOf (RT.sbnode ginfo_justcore n)
181 : blume 327 val rts = rt rts
182 :     val pervasive = rt pervasive
183 :    
184 :     fun sn2pspec (name, n) = let
185 :     val { stat = (s, sp), sym = (sy, syp), ctxt } = rt n
186 :     val env =
187 :     E.mkenv { static = s, symbolic = sy, dynamic = emptydyn }
188 :     val pidInfo = { statpid = sp, sympid = syp, ctxt = ctxt }
189 :     in
190 :     { name = name, env = env, pidInfo = pidInfo }
191 :     end
192 :    
193 :     val pspecs = map sn2pspec primitives
194 :    
195 : blume 329 val _ = ovldR := savedOvld
196 :    
197 : blume 356 (* This is a hack but must be done for both the symbolic
198 :     * and later the dynamic part of the core environment:
199 :     * we must include these parts in the pervasive env. *)
200 :     val perv_sym = E.layerSymbolic (#1 (#sym pervasive), core_sym)
201 :    
202 : blume 349 val param =
203 :     mkParam { primconf = Primitive.configuration pspecs,
204 : blume 327 pervasive = E.mkenv { static = #1 (#stat pervasive),
205 : blume 356 symbolic = perv_sym,
206 : blume 327 dynamic = emptydyn },
207 :     pervcorepids =
208 :     PidSet.addList (PidSet.empty,
209 :     [#2 (#stat pervasive),
210 :     #2 (#sym pervasive),
211 : blume 357 #2 (#stat core)]),
212 :     fnpolicy = mainfnpolicy }
213 : blume 349 { corenv = corenv }
214 : blume 327 in
215 : blume 358 case Parse.parse NONE param (SOME true) maingspec of
216 : blume 349 NONE => false
217 : blume 329 | SOME (g, gp) =>
218 : blume 349 if recomp gp g then let
219 :     val rtspid = PS.toHex (#2 (#stat rts))
220 :     val bootfiles =
221 :     map (fn x => (x, NONE)) binpaths @
222 :     MkBootList.group g
223 :     fun writeList s = let
224 :     fun offset NONE = ["\n"]
225 :     | offset (SOME i) = ["@", Int.toString i, "\n"]
226 :     fun showBootFile (p, off) =
227 : blume 358 TextIO.output (s, concat (listName p ::
228 :     offset off))
229 : blume 349 in
230 :     app showBootFile bootfiles
231 :     end
232 :     in
233 :     Say.say ["Runtime System PID is: ", rtspid, "\n"];
234 :     SafeIO.perform { openIt = fn () =>
235 : blume 354 AutoDir.openTextOut pidfile,
236 : blume 349 closeIt = TextIO.closeOut,
237 :     work = fn s =>
238 :     TextIO.output (s, rtspid ^ "\n"),
239 :     cleanup = fn () =>
240 : blume 354 OS.FileSys.remove pidfile
241 :     handle _ => () };
242 : blume 349 SafeIO.perform { openIt = fn () =>
243 : blume 354 AutoDir.openTextOut listfile,
244 : blume 349 closeIt = TextIO.closeOut,
245 :     work = writeList,
246 :     cleanup = fn () =>
247 : blume 354 OS.FileSys.remove listfile
248 :     handle _ => () };
249 : blume 349 true
250 :     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 :     end

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