Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/codegen/codegen-fn.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/codegen/codegen-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2645, Thu May 29 15:38:33 2014 UTC revision 2646, Thu May 29 15:52:23 2014 UTC
# Line 22  Line 22 
22    end = struct    end = struct
23    
24      structure IL = TreeIL      structure IL = TreeIL
25        structure gT=getTypes
26        structure CTypes=CTypes
27    
28      val targetSupportsPrinting = ref T.supportsPrinting      val targetSupportsPrinting = ref T.supportsPrinting
29    
# Line 61  Line 63 
63              List.app (trMethod (strand, state, env)) methods              List.app (trMethod (strand, state, env)) methods
64            end            end
65    
66      fun trInitially (env, prog, {isArray, iterPrefix, iters, createPrefix, strand, args}) = let  
67    
68        fun trInitially (env, prog, {isArray, iterPrefix, iters, createPrefix, strand, args}) =( let
69            val env = T.Env.scopeInitially env            val env = T.Env.scopeInitially env
70            val (env, iterPrefix) = T.Tr.fragment (env, iterPrefix)            val (env, iterPrefix) = T.Tr.fragment (env, iterPrefix)
71            fun trIter ((param, lo, hi), (env, iters)) = let            fun trIter ((param, lo, hi), (env, iters)) = let
# Line 83  Line 87 
87                  strand = strand,                  strand = strand,
88                  args = List.map (fn e => T.Tr.exp(env, e)) args                  args = List.map (fn e => T.Tr.exp(env, e)) args
89                }                }
90            end            end)
91    
92    
93    
94      fun generate {basename, double, parallel, debug, prog=srcProg} = let          val line="--------------"
95            fun generate {basename, double, parallel, debug, prog=srcProg} = (let
96            val _ = if parallel then targetSupportsPrinting := false else ()            val _ = if parallel then targetSupportsPrinting := false else ()
97            val treeProg as TreeIL.Program{props, types , oprations,globals, inputInit, globalInit, strands, initially} =            val treeProg as TreeIL.Program{props, types , oprations,globals, inputInit, globalInit, strands, initially} =
98                  PhaseTimer.withTimer Timers.timeLowToTree LowToTree.translate srcProg                  PhaseTimer.withTimer Timers.timeLowToTree LowToTree.translate srcProg
99    
100                val _=print(gT.prnTyFinal(types,oprations,"\t"^line^"CodeGen"^line))
101                val _ =CTypes.treeToCtypes types
102                val _= T.Tr.allTypes types
103                val _= T.Tr.allOpr oprations
104  val _ = (  val _ = (
105  TextIO.output(Log.logFile(), "********** After translation to TreeIL **********\n");  TextIO.output(Log.logFile(), "********** After translation to TreeIL **********\n");
106  TreeILPP.program (Log.logFile(), treeProg))  TreeILPP.program (Log.logFile(), treeProg))
# Line 100  Line 112 
112                  }                  }
113            val env = T.Env.new prog            val env = T.Env.new prog
114          (* define the globals and initialize the environment *)          (* define the globals and initialize the environment *)
115            val env = let              val env = (let
116                (* produce a list of target variables for the globals, such that each global                (* produce a list of target variables for the globals, such that each global
117                 * has a unique name.                 * has a unique name.*)
118                 *)                  fun genName (x, (cnt, globs)) =(let
                 fun genName (x, (cnt, globs)) = let  
119                        val name = IL.Var.name x                        val name = IL.Var.name x
120                        fun uniqueName (name, cnt) =                      fun uniqueName (name, cnt) =(
121                              if List.exists (fn (_, y) => (name = T.Var.name y)) globs                              if List.exists (fn (_, y) => (name = T.Var.name y)) globs
122                                then uniqueName(name ^ Int.toString cnt, cnt+1)                                then uniqueName(name ^ Int.toString cnt, cnt+1)
123                                else (name, cnt)                              else (name, cnt))
124                        val (name, cnt) = uniqueName (IL.Var.name x, cnt)                        val (name, cnt) = uniqueName (IL.Var.name x, cnt)
125                        in                        in
126                          (cnt, (x, T.Var.global(prog, name, IL.Var.ty x))::globs)                          (cnt, (x, T.Var.global(prog, name, IL.Var.ty x))::globs)
127                        end                  end)
128                  val (_, globs) = List.foldl genName (0, []) globals                  val (_, globs) = List.foldl genName (0, []) globals
129                  fun gvar ((x, x'), env) = T.Env.bind(env, x, x')                  fun gvar ((x, x'), env) = T.Env.bind(env, x, x')
130                  in                  in
131                    List.foldl gvar (T.Env.scopeGlobal env) globs                    List.foldl gvar (T.Env.scopeGlobal env) globs
132                  end                  end)
133            in            in
134              T.Program.inputs (prog, T.Tr.block (T.Env.scopeGlobal env, inputInit));              T.Program.inputs (prog, T.Tr.block (T.Env.scopeGlobal env, inputInit));
135            (* global initialization *)            (* global initialization *)
# Line 129  Line 140 
140              trInitially (env, prog, initially);              trInitially (env, prog, initially);
141            (* output the program *)            (* output the program *)
142              T.Program.generate (basename, prog)              T.Program.generate (basename, prog)
143            end            end)
144    
145    end    end

Legend:
Removed from v.2645  
changed lines
  Added in v.2646

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