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

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