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 3916, Sat May 28 12:01:02 2016 UTC revision 3917, Sat May 28 16:41:39 2016 UTC
# Line 62  Line 62 
62      fun verbFrag (spec, parFrag, seqFrag, subs) =      fun verbFrag (spec, parFrag, seqFrag, subs) =
63            CL.verbatimDcl [if (TargetSpec.isParallel spec) then parFrag else seqFrag] subs            CL.verbatimDcl [if (TargetSpec.isParallel spec) then parFrag else seqFrag] subs
64    
65      fun runFrag (false, spec, subs) =    (* generate declarations for the types and operations that are used in the program *)
66            verbFrag (spec, Fragments.parallelRun, Fragments.sequentialRun, subs)      fun genTypesAndOperations (outS, spec : TargetSpec.t, info) = let
67        | runFrag (true, spec, subs) =            fun doType (ty, isPrint) = ()
68            verbFrag (spec, Fragments.parallelRunNoBSP, Fragments.sequentialRunNoBSP, subs)            in
69                CollectInfo.applyToTypes doType info
70              end
71    
72      (* generate the struct declaration for the global variables *)
73        fun genGlobalStruct (spec : TargetSpec.t, globals) =
74              if #hasGlobals spec
75                then let
76                  val fields = [] (* FIXME *)
77                  in
78                    [CL.D_StructDef(SOME "globals", fields, NONE)]
79                  end
80                else []
81    
82      (* generate the struct declaration for the world representation *)
83        fun genWorldStruct (spec : TargetSpec.t, strandName) = let
84              fun memberVar (ty, name) = CL.D_Var([], ty, name, NONE)
85              val members = []
86              val statePtrTy = CL.T_Ptr(CL.T_Ptr(CL.T_Named(Atom.toString strandName ^ "_strand")))
87              val members = if TargetSpec.dualState spec
88                    then memberVar(statePtrTy, "_inState") ::
89                      memberVar(statePtrTy, "_inState") :: members
90                    else memberVar(statePtrTy, "_state") :: members
91              val members = memberVar(CL.T_Ptr CL.uint8, "_status") :: members
92              val members = if #hasGlobals spec
93                    then memberVar(RN.globalPtrTy, "_globals") :: members
94                    else members
95              val members = if #exec spec orelse not(#hasInputs spec)
96                    then members
97                    else memberVar(CL.T_Named "inputs", "_definedInp") :: members
98              val members = if TargetSpec.isParallel spec
99                    then memberVar(CL.T_Ptr(CL.T_Named "sched_info"), "_sched") :: members
100                    else memberVar(CL.T_Named "uint32_t", "_nactive") ::
101                      memberVar(CL.T_Named "uint32_t", "_nstable") :: members
102            (* add world method decls *)
103              fun memberFun (ty, name, params) = CL.D_Proto([], ty, name, params)
104              val members =
105                    memberFun (CL.voidTy, "swap_state", []) ::
106                    memberFun (CL.uint32, "run", [CL.PARAM([], CL.uint32, "max_nsteps")]) ::
107                    memberFun (CL.voidTy, "initially", []) ::
108                    CL.D_Destr([], NONE, "world", NONE) ::
109                    CL.D_Constr([], NONE, "world", [], [], NONE) ::
110                    members
111              in
112                CL.D_ClassDef{
113                    name = "world",
114                    from = SOME "public diderot::world_base",
115                    public = List.rev members,
116                    protected = [],
117                    private = []
118                  }
119              end
120    
121        fun runFrag (spec, subs) = if TargetSpec.noBSP spec
122                then verbFrag (spec, Fragments.parallelRunNoBSP, Fragments.sequentialRunNoBSP, subs)
123                else verbFrag (spec, Fragments.parallelRun, Fragments.sequentialRun, subs)
124    
125      fun compile (spec : TargetSpec.t, basename) = let      fun compile (spec : TargetSpec.t, basename) = let
126          (* generate the C compiler flags *)          (* generate the C compiler flags *)
# Line 89  Line 144 
144              end              end
145            else [TargetSpec.runtimeLibName spec]            else [TargetSpec.runtimeLibName spec]
146    
   
147    (* generate source code that is common to both libraries and standalone executables *)    (* generate source code that is common to both libraries and standalone executables *)
148      fun outputSrc (outS, spec, prog, strand, substitutions, genInputCode) = ()      fun outputSrc (outS, env, spec, prog, strand, substitutions, genInputCode) = let
149  (*            val IR.Program{globals, create=IR.Create{dim, ...}, ...} = prog
150      fun outputSrc (outS, spec, prog, strand, substitutions, genInputCode) = let            val IR.Strand{name=strandName, ...} = strand
151            val IR.Program{globals, create, ...} = prog            val ppDecl = Out.decl outS
152          (* does the program require barrier synchronization to implement BSP semantics? *)            val outputs = OutputUtil.gatherOutputs prog
           val noBSP = TargetSpec.noBSP spec  
           val Strand{output, ...} = strand  
           val outputs = GenOutput.gen (props, !nAxes) output  
           fun ppDecl dcl = Out.decl outS  
153            in            in
154              if (TargetSpec.isParallel spec)              if (TargetSpec.isParallel spec)
155                then ppDecl (CL.verbatimDcl [CHeadParExtraFrag.text] substitutions)                then ppDecl (CL.verbatimDcl [Fragments.parallelExtras] substitutions)
156                else ();                else ();
157              if TargetSpec.dualState spec              if TargetSpec.dualState spec
158                then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])                then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])
# Line 113  Line 163 
163              if not(#hasInputs spec)              if not(#hasInputs spec)
164                then ppDecl (CL.D_Verbatim ["#define DIDEROT_NO_INPUTS\n"])                then ppDecl (CL.D_Verbatim ["#define DIDEROT_NO_INPUTS\n"])
165                else ();                else ();
166              List.app ppDecl (genGlobalStruct (props, !globals));  (* FIXME: what about constants and inputs? *)
167              ppDecl (genWorldStruct(prog, strand));              List.app ppDecl (genGlobalStruct (spec, globals));
168                ppDecl (genWorldStruct(spec, strandName));
169              List.app ppDecl (genInputCode());              List.app ppDecl (genInputCode());
170    (* FIXME: need to gather/generate topDecls
171              List.app ppDecl (!topDecls);              List.app ppDecl (!topDecls);
172              List.app ppDecl (genStrand strand);  *)
173              List.app ppDecl outputs;              List.app ppDecl (GenStrand.gen (env, strand));
174              ppStrandTable (out, [strand]);              List.app ppDecl (GenOutputs.gen (env, dim, outputs));
175                ppDecl (CL.verbatimDcl [Fragments.worldMethods] substitutions);
176    (* TODO
177              ppDecl (CL.verbatimDcl [InitFrag.text] substitutions);              ppDecl (CL.verbatimDcl [InitFrag.text] substitutions);
178              ppDecl (CL.verbatimDcl [AllocFrag.text] substitutions);              ppDecl (CL.verbatimDcl [AllocFrag.text] substitutions);
179              ppDecl (!initially);              ppDecl (!initially);
             ppDecl (runFrag (noBSP, props, substitutions));  
             ppDecl (CL.verbatimDcl [ShutdownFrag.text] substitutions)  
           end  
180  *)  *)
181                ppDecl (runFrag (spec, substitutions))
182              end
183    
184  (********************  (********************
185          fun outputLibSrc (baseName, prog as Prog{props, inputs, strands, ...}) = let          fun outputLibSrc (baseName, prog as Prog{props, inputs, strands, ...}) = let
# Line 177  Line 230 
230            val fragment = Out.fragment substitutions outS            val fragment = Out.fragment substitutions outS
231            in            in
232              GenExecUtil.execHead (outS, substitutions);              GenExecUtil.execHead (outS, substitutions);
233              outputSrc (outS, spec, prog, strand, substitutions,              genTypesAndOperations (outS, spec, CollectInfo.collect prog);
234                outputSrc (outS, env, spec, prog, strand, substitutions,
235                fn () => (                fn () => (
236                  GenInputs.genInputsStruct (env, inputs) @                  GenInputs.genInputsStruct (env, inputs) @
237                  GenInputs.genExecInputFuns (env, prog) @                  GenInputs.genExecInputFuns (env, prog) @

Legend:
Removed from v.3916  
changed lines
  Added in v.3917

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