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 344 - (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 329 fun compile { binroot, pcmodespec, initgspec, maingspec } = let
44 : blume 327
45 : blume 329 val keep_going = EnvConfig.getSet StdConfig.keep_going NONE
46 :    
47 :     val ctxt = AbsPath.cwdContext ()
48 :    
49 :     val initgspec = AbsPath.native { context = ctxt, spec = initgspec }
50 :     val maingspec = AbsPath.native { context = ctxt, spec = maingspec }
51 :     val pcmodespec = AbsPath.native { context = ctxt, spec = pcmodespec }
52 :     val binroot = AbsPath.native { context = ctxt, spec = binroot }
53 :    
54 : blume 344 val pcmode = let
55 : blume 329 val s = AbsPath.openTextIn pcmodespec
56 :     fun loop l = let
57 :     val line = TextIO.inputLine s
58 :     in
59 :     if line = "" then PathConfig.hardwire l
60 :     else case String.tokens Char.isSpace line of
61 :     [a, s] => loop ((a, s) :: l)
62 :     | _ => (Say.say [AbsPath.name pcmodespec,
63 :     ": malformed line (ignored)\n"];
64 :     loop l)
65 :     end
66 :     in
67 :     loop [] before TextIO.closeIn s
68 :     end
69 :    
70 :     val fnpolicy =
71 :     FilenamePolicy.separate { root = binroot,
72 :     parentArc = "DOTDOT",
73 :     absArc = "ABSOLUTE" }
74 :     { arch = MachDepVC.architecture, os = os }
75 :    
76 : blume 327 val emptydyn = E.dynamicPart E.emptyEnv
77 :    
78 :     (* first, build an initial GeneralParam.info, so we can
79 :     * deal with the pervasive env and friends... *)
80 :     local
81 :     (* We could actually go and calculate the actual pid of primEnv.
82 :     * But in reality it's pretty pointless to do so... *)
83 :     val bogusPid = PS.fromBytes (Byte.stringToBytes "0123456789abcdef")
84 :     val pspec = { name = "primitive",
85 :     env = E.mkenv { static = E.primEnv,
86 :     symbolic = E.symbolicPart E.emptyEnv,
87 :     dynamic = emptydyn },
88 :     pidInfo = { statpid = bogusPid,
89 :     sympid = bogusPid,
90 :     ctxt = SE.empty } }
91 :     in
92 :     val primconf = Primitive.configuration [pspec]
93 :     end
94 :    
95 : blume 329 val param_nocore = { primconf = primconf,
96 :     fnpolicy = fnpolicy,
97 :     pcmode = pcmode,
98 : blume 336 symenv = SSV.env,
99 : blume 329 keep_going = keep_going,
100 :     pervasive = E.emptyEnv,
101 :     corenv = BE.staticPart BE.emptyEnv,
102 :     pervcorepids = PidSet.empty }
103 : blume 327
104 :     val groupreg = GroupReg.new ()
105 :     val errcons = EM.defaultConsumer ()
106 : blume 329 val ginfo_nocore = { param = param_nocore, groupreg = groupreg,
107 :     errcons = errcons }
108 : blume 327
109 :     fun main_compile arg = let
110 : blume 335 val { rts, core, pervasive, primitives, binpaths } = arg
111 : blume 327
112 : blume 329 val ovldR = GenericVC.Control.overloadKW
113 :     val savedOvld = !ovldR
114 :     val _ = ovldR := true
115 :    
116 : blume 327 (* here we build a new gp -- the one that uses the freshly
117 :     * brewed pervasive env, core env, and primitives *)
118 : blume 329 val core = valOf (RT.snode ginfo_nocore core)
119 :     val corenv = CoerceEnv.es2bs (#1 (#stat core))
120 : blume 330 (* even though we have a pid for the core, we can't use it
121 :     * (otherwise we would invalidate earlier compilation results) *)
122 :     val pervcorepids = PidSet.empty
123 : blume 329
124 :     (* The following is a bit of a hack (but corenv is a hack anyway):
125 :     * As soon as we have core available, we have to patch the
126 :     * ginfo to include the correct corenv (because virtually
127 :     * everybody else needs access to corenv). *)
128 :     val param_justcore = { primconf = primconf,
129 :     fnpolicy = fnpolicy,
130 :     pcmode = pcmode,
131 : blume 336 symenv = SSV.env,
132 : blume 329 keep_going = keep_going,
133 :     pervasive = E.emptyEnv,
134 :     corenv = corenv,
135 :     pervcorepids = pervcorepids }
136 :     val ginfo_justcore = { param = param_justcore, groupreg = groupreg,
137 :     errcons = errcons }
138 :    
139 :     fun rt n = valOf (RT.snode ginfo_justcore n)
140 : blume 327 val rts = rt rts
141 :     val pervasive = rt pervasive
142 :    
143 :     fun sn2pspec (name, n) = let
144 :     val { stat = (s, sp), sym = (sy, syp), ctxt } = rt n
145 :     val env =
146 :     E.mkenv { static = s, symbolic = sy, dynamic = emptydyn }
147 :     val pidInfo = { statpid = sp, sympid = syp, ctxt = ctxt }
148 :     in
149 :     { name = name, env = env, pidInfo = pidInfo }
150 :     end
151 :    
152 :     val pspecs = map sn2pspec primitives
153 :    
154 : blume 329 val _ = ovldR := savedOvld
155 :    
156 : blume 327 val param = { primconf = Primitive.configuration pspecs,
157 :     fnpolicy = fnpolicy,
158 :     pcmode = pcmode,
159 : blume 336 symenv = SSV.env,
160 : blume 327 keep_going = keep_going,
161 :     pervasive = E.mkenv { static = #1 (#stat pervasive),
162 :     symbolic = #1 (#sym pervasive),
163 :     dynamic = emptydyn },
164 :     corenv = CoerceEnv.es2bs (#1 (#stat core)),
165 :     pervcorepids =
166 :     PidSet.addList (PidSet.empty,
167 :     [#2 (#stat pervasive),
168 :     #2 (#sym pervasive),
169 :     #2 (#stat core)]) }
170 :     in
171 : blume 331 case Parse.parse param NONE maingspec of
172 : blume 329 NONE => NONE
173 :     | SOME (g, gp) =>
174 :     if recomp gp g then
175 :     SOME { rtspid = PS.toHex (#2 (#stat rts)),
176 :     bootfiles =
177 : blume 335 map (fn x => (x, NONE)) binpaths @
178 : blume 329 MkBootList.group g }
179 :     else NONE
180 : blume 330 end handle Option => (RT.clearFailures (); NONE)
181 :     (* to catch valOf failures in "rt" *)
182 : blume 327 in
183 : blume 329 case BuildInitDG.build ginfo_nocore initgspec of
184 : blume 327 SOME x => main_compile x
185 : blume 329 | NONE => NONE
186 : blume 327 end
187 :     end

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