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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/target-cpu/gen.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/target-cpu/gen.sml

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

revision 4130, Fri Jul 1 12:11:34 2016 UTC revision 4131, Fri Jul 1 12:59:23 2016 UTC
# Line 91  Line 91 
91                end                end
92              else []              else []
93    
94      fun genInitGlobals (env, IR.Block{locals, body}) = let    (* generate code for a block, where we optionally add a local variable that points
95            val env = Env.setExitHandler (env, fn _ => [CL.mkReturn(SOME(CL.mkVar "false"))])     * to the globals struct.
96       *)
97        fun genBodyWithGlobPtr (env, IR.Block{locals, body}) = let
98            fun mkBody env = let            fun mkBody env = let
99                  val stms = #2(TreeToCxx.trStms(env, body))                  val stms = #2(TreeToCxx.trStms(env, body))
               (* note that a program can have globalInit block even if it soes not have global  
                * variables!  
                *)  
100                  val stms = if #hasGlobals(Env.target env)                  val stms = if #hasGlobals(Env.target env)
101                        then CL.mkDeclInit(                        then CL.mkDeclInit(
102                            RN.globalPtrTy, RN.globalsVar,                            RN.globalPtrTy, RN.globalsVar,
103                            CL.mkIndirect(CL.mkVar RN.worldVar, "_globals")                            CL.mkIndirect(CL.mkVar(Env.world env), "_globals")
104                          ) :: stms                          ) :: stms
105                        else stms                        else stms
106                  in                  in
107                    stms                    stms
108                  end                  end
109            in            in
110                TreeToCxx.trWithLocals (env, !locals, mkBody)
111              end
112    
113    (* QUESTION: should init_globals be a member of the world struct? *)
114        fun genInitGlobals (env, body) = let
115              val env = Env.setExitHandler (env, fn _ => [CL.mkReturn(SOME(CL.mkVar "false"))])
116              in
117              CL.D_Func(["static"], CL.boolTy, [], "init_globals",              CL.D_Func(["static"], CL.boolTy, [], "init_globals",
118                [RN.worldParam],                [RN.worldParam],
119                TreeToCxx.trWithLocals (env, !locals, mkBody))                genBodyWithGlobPtr (env, body))
120              end
121    
122      (* generate the global initially code, which runs after the initial strands have been
123       * created, but before the first super-step.
124       *)
125        fun genGlobalInitially (env, body) = let
126              val env = Env.insert(env, PseudoVars.world, "this")
127              in
128                CL.D_Func([], CL.voidTy, [], "world::global_initially",
129                  [],
130                  genBodyWithGlobPtr (env, body))
131              end
132    
133      (* generate the global-update code *)
134        fun genGlobalUpdate (env, body) =let
135              val env = Env.insert(env, PseudoVars.world, "this")
136              in
137                CL.D_Func([], CL.voidTy, [], "world::global_update",
138                  [],
139                  genBodyWithGlobPtr (env, body))
140            end            end
141    
142      fun runFrag (spec, subs) = if TargetSpec.noBSP spec      fun runFrag (spec, subs) = if TargetSpec.noBSP spec
# Line 174  Line 200 
200              List.app ppDecl (GenOutputs.gen (env, dim, outputs));              List.app ppDecl (GenOutputs.gen (env, dim, outputs));
201              ppDecl (CL.verbatimDcl [CPUFragments.worldMethods] substitutions);              ppDecl (CL.verbatimDcl [CPUFragments.worldMethods] substitutions);
202              ppDecl (GenWorld.genInitiallyFun (env, globInit, strand, create));              ppDecl (GenWorld.genInitiallyFun (env, globInit, strand, create));
203              ppDecl (runFrag (spec, substitutions))              ppDecl (runFrag (spec, substitutions));
204  (* FIXME: what about the global initially and update code? *)              Option.app (fn blk => ppDecl (genGlobalInitially (env, blk))) init;
205                Option.app (fn blk => ppDecl (genGlobalUpdate (env, blk))) update
206            end            end
207    
208      fun exec (spec : TargetSpec.t, prog) = let      fun exec (spec : TargetSpec.t, prog) = let

Legend:
Removed from v.4130  
changed lines
  Added in v.4131

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