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/compiler/TopLevel/main/compile.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/TopLevel/main/compile.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 879 - (view) (download)

1 : monnier 16 (* COPYRIGHT (c) 1996 Bell Laboratories *)
2 :     (* compile.sml *)
3 :    
4 :     functor CompileF(structure M : CODEGENERATOR
5 :     structure CC : CCONFIG) : COMPILE0 =
6 :     struct
7 :    
8 : blume 879 fun mkCompInfo { source, transform } =
9 :     CompInfo.mkCompInfo { source = source,
10 :     transform = transform,
11 :     mkMkStamp = CC.mkMkStamp }
12 : monnier 16
13 : blume 879 type pickle = CC.pickle (* pickled format *)
14 :     type hash = CC.hash (* environment hash id *)
15 : monnier 16
16 : blume 879 (*************************************************************************
17 :     * ELABORATION *
18 :     *************************************************************************)
19 : monnier 16
20 : blume 879 (** several preprocessing phases done after parsing or
21 :     ** after elaborations *)
22 :     (*
23 :     val fixityparse =
24 :     (* Stats.doPhase (Stats.makePhase "Compiler 005 fixityparse") *)
25 :     FixityParse.fixityparse
26 :     val lazycomp =
27 :     (* Stats.doPhase (Stats.makePhase "Compiler 006 lazycomp") *)
28 :     LazyComp.lazycomp
29 :     *)
30 :     val pickUnpick =
31 :     Stats.doPhase (Stats.makePhase "Compiler 036 pickunpick") CC.pickUnpick
32 : monnier 16
33 : blume 879 (** take ast, do semantic checks,
34 :     ** and output the new env, absyn and pickles *)
35 :     fun elaborate {ast=ast, statenv=senv, compInfo=cinfo} = let
36 : monnier 16
37 : blume 879 val (absyn, nenv) = ElabTop.elabTop(ast, senv, cinfo)
38 :     val (absyn, nenv) =
39 :     if CompInfo.anyErrors cinfo then
40 :     (Absyn.SEQdec nil, StaticEnv.empty)
41 :     else (absyn, nenv)
42 :     val { hash, pickle, exportLvars, exportPid, newenv } =
43 :     pickUnpick { context = senv, env = nenv }
44 :     in {absyn=absyn, newstatenv=newenv, exportPid=exportPid,
45 :     exportLvars=exportLvars, staticPid = hash, pickle=pickle }
46 :     end (* function elaborate *)
47 : monnier 16
48 : blume 879 val elaborate =
49 :     Stats.doPhase(Stats.makePhase "Compiler 030 elaborate") elaborate
50 : monnier 16
51 : blume 879 (*************************************************************************
52 :     * ABSYN INSTRUMENTATION *
53 :     *************************************************************************)
54 : monnier 16
55 : blume 879 (** instrumenting the abstract syntax to do time- and space-profiling *)
56 :     fun instrument {source, senv, compInfo} =
57 :     SProf.instrumDec (senv, compInfo) source
58 :     o TProf.instrumDec (senv, compInfo)
59 :     o BTrace.instrument (senv, compInfo)
60 : monnier 16
61 : blume 879 val instrument =
62 :     Stats.doPhase (Stats.makePhase "Compiler 039 instrument") instrument
63 : monnier 16
64 : blume 879 (*************************************************************************
65 :     * TRANSLATION INTO FLINT *
66 :     *************************************************************************)
67 : monnier 16
68 : blume 879 (** take the abstract syntax tree, generate the flint intermediate code *)
69 :     fun translate{absyn, exportLvars, newstatenv, oldstatenv, compInfo} =
70 :     (*** statenv used for printing Absyn in messages ***)
71 :     let val statenv = StaticEnv.atop (newstatenv, oldstatenv)
72 :     in
73 : monnier 16 Translate.transDec(absyn, exportLvars, statenv, compInfo)
74 : blume 879 end
75 : monnier 16
76 : blume 879 val translate =
77 :     Stats.doPhase (Stats.makePhase "Compiler 040 translate") translate
78 : monnier 16
79 :    
80 : blume 879 (*************************************************************************
81 :     * CODE GENERATION *
82 :     *************************************************************************)
83 : monnier 16
84 : blume 879 (** take the flint code and generate the machine binary code *)
85 :     local
86 :     val inline = LSplitInline.inline
87 :     val addCode = Stats.addStat (Stats.makeStat "Code Size")
88 :     in
89 :     fun codegen { flint, imports, symenv, splitting, compInfo } = let
90 :     (* hooks for cross-module inlining and specialization *)
91 :     val (flint, revisedImports) = inline (flint, imports, symenv)
92 : monnier 113
93 : blume 879 (* from optimized FLINT code, generate the machine code. *)
94 :     val (csegs,inlineExp) = M.flintcomp(flint, compInfo, splitting)
95 :     (* Obey the nosplit directive used during bootstrapping. *)
96 :     (* val inlineExp = if isSome splitting then inlineExp else NONE *)
97 :     val codeSz =
98 :     List.foldl
99 :     (fn (co, n) => n + CodeObj.size co)
100 :     (CodeObj.size(#c0 csegs) + Word8Vector.length(#data csegs))
101 : monnier 251 (#cn csegs)
102 : blume 879 in
103 :     addCode codeSz;
104 :     { csegments=csegs, inlineExp=inlineExp, imports = revisedImports }
105 :     end
106 :     end (* local codegen *)
107 : monnier 16
108 : blume 587 (*
109 : blume 879 val codegen =
110 :     Stats.doPhase (Stats.makePhase "Compiler 140 CodeGen") codegen
111 : blume 587 *)
112 : monnier 16
113 : blume 879 (*************************************************************************
114 :     * COMPILATION *
115 :     * = ELABORATION + TRANSLATION TO FLINT + CODE GENERATION *
116 :     * used by interact/evalloop.sml, cm/compile/compile.sml only *
117 :     *************************************************************************)
118 :     (** compiling the ast into the binary code = elab + translate + codegen *)
119 :     fun compile {source=source, ast=ast, statenv, symenv=symenv,
120 :     compInfo=cinfo, checkErr=check, splitting=splitting} =
121 :     let val {absyn, newstatenv, exportLvars, exportPid, staticPid, pickle } =
122 :     elaborate {ast=ast, statenv=statenv, compInfo=cinfo }
123 :     before (check "elaborate")
124 : monnier 16
125 : blume 879 val absyn = instrument {source=source, senv = statenv,
126 :     compInfo=cinfo} absyn
127 :     before (check "instrument")
128 : monnier 16
129 : blume 879 val {flint, imports} =
130 :     translate {absyn=absyn, exportLvars=exportLvars,
131 :     newstatenv=newstatenv, oldstatenv=statenv,
132 :     compInfo=cinfo}
133 :     before check "translate"
134 : monnier 16
135 : blume 879 val { csegments, inlineExp, imports = revisedImports } =
136 :     codegen { flint = flint, imports = imports, symenv = symenv,
137 :     splitting = splitting, compInfo = cinfo }
138 :     before (check "codegen")
139 :     (*
140 :     * interp mode was currently turned off.
141 :     *
142 :     * if !Control.interp then Interp.interp flint
143 :     * else codegen {flint=flint, splitting=splitting, compInfo=cinfo})
144 :     *)
145 :     in
146 :     { csegments = csegments,
147 :     newstatenv = newstatenv,
148 :     absyn = absyn,
149 :     exportPid = exportPid,
150 :     exportLvars = exportLvars,
151 :     staticPid = staticPid,
152 :     pickle = pickle,
153 :     inlineExp = inlineExp,
154 :     imports = revisedImports }
155 :     end (* function compile *)
156 : monnier 16 end (* functor CompileF *)

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