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

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