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 3918, Mon May 30 06:31:35 2016 UTC revision 3924, Fri Jun 3 17:30:27 2016 UTC
# Line 15  Line 15 
15    end = struct    end = struct
16    
17      structure IR = TreeIR      structure IR = TreeIR
18        structure GV = TreeGlobalVar
19      structure CL = CLang      structure CL = CLang
20      structure Env = CodeGenEnv      structure Env = CodeGenEnv
21      structure Out = CodeOutput      structure Out = CodeOutput
# Line 37  Line 38 
38              }              }
39    
40    (* create the target-specific substitution list *)    (* create the target-specific substitution list *)
41      fun mkSubs (spec, IR.Strand{name, ...}) = [      fun mkSubs (spec, IR.Strand{name, ...}, IR.Create{dim, ...}) = [
42              ("CFILE",                   OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "c"}),              ("CFILE",                   OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "c"}),
43              ("CXXFILE",                 OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "cxx"}),              ("CXXFILE",                 OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "cxx"}),
44              ("HDRFILE",                 OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "h"}),              ("HDRFILE",                 OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "h"}),
# Line 46  Line 47 
47              ("PROG_NAME",               #outBase spec),              ("PROG_NAME",               #outBase spec),
48              ("STRAND",                  Atom.toString name),              ("STRAND",                  Atom.toString name),
49              ("STRANDTY",                Atom.toString name ^ "_strand"),              ("STRANDTY",                Atom.toString name ^ "_strand"),
50                ("IS_ARRAY",                Bool.toString(#isArray spec)),
51                ("NUM_AXES",                Int.toString(Option.getOpt(dim, 1))),
52              ("DIDEROTC_CMD",            #diderotc spec),              ("DIDEROTC_CMD",            #diderotc spec),
53              ("DIDEROTC_ARGV",           String.concatWith " " (#argv spec)),              ("DIDEROTC_ARGV",           String.concatWith " " (#argv spec)),
54              ("DIDEROTC_VERSION",        #version spec),              ("DIDEROTC_VERSION",        #version spec),
# Line 67  Line 70 
70      fun genGlobalStruct (env, consts, inputs, globals) =      fun genGlobalStruct (env, consts, inputs, globals) =
71            if #hasGlobals(Env.target env)            if #hasGlobals(Env.target env)
72              then let              then let
73                fun mkField gv = (TreeToCxx.trType(env, TreeGlobalVar.ty gv), TreeGlobalVar.name gv)                fun mkField gv = (TreeToCxx.trType(env, GV.ty gv), GV.qname gv)
74                val fields = List.map (mkField o Inputs.varOf) inputs                val fields = List.map (mkField o Inputs.varOf) inputs
75                val fields = fields @ List.map mkField globals                val fields = fields @ List.map mkField globals
76                in                in
# Line 75  Line 78 
78                end                end
79              else []              else []
80    
   (* generate the struct declaration for the world representation *)  
     fun genWorldStruct (spec : TargetSpec.t, strandName) = let  
           fun memberVar (ty, name) = CL.D_Var([], ty, name, NONE)  
           val members = []  
           val statePtrTy = CL.T_Ptr(CL.T_Ptr(CL.T_Named(Atom.toString strandName ^ "_strand")))  
           val members = if TargetSpec.dualState spec  
                 then memberVar(statePtrTy, "_inState") ::  
                   memberVar(statePtrTy, "_inState") :: members  
                 else memberVar(statePtrTy, "_state") :: members  
           val members = memberVar(CL.T_Ptr CL.uint8, "_status") :: members  
           val members = if #hasGlobals spec  
                 then memberVar(RN.globalPtrTy, "_globals") :: members  
                 else members  
           val members = if #exec spec orelse not(#hasInputs spec)  
                 then members  
                 else memberVar(CL.T_Named "inputs", "_definedInp") :: members  
           val members = if TargetSpec.isParallel spec  
                 then memberVar(CL.T_Ptr(CL.T_Named "sched_info"), "_sched") :: members  
                 else memberVar(CL.T_Named "uint32_t", "_nactive") ::  
                   memberVar(CL.T_Named "uint32_t", "_nstable") :: members  
         (* add world method decls *)  
           fun memberFun (ty, name, params) = CL.D_Proto([], ty, name, params)  
           val members =  
                 memberFun (CL.voidTy, "swap_state", []) ::  
                 memberFun (CL.uint32, "run", [CL.PARAM([], CL.uint32, "max_nsteps")]) ::  
                 memberFun (CL.voidTy, "initially", []) ::  
                 CL.D_Destr([], NONE, "world", NONE) ::  
                 CL.D_Constr([], NONE, "world", [], [], NONE) ::  
                 members  
           in  
             CL.D_ClassDef{  
                 name = "world",  
                 from = SOME "public diderot::world_base",  
                 public = List.rev members,  
                 protected = [],  
                 private = []  
               }  
           end  
   
81      fun runFrag (spec, subs) = if TargetSpec.noBSP spec      fun runFrag (spec, subs) = if TargetSpec.noBSP spec
82              then verbFrag (spec, Fragments.parallelRunNoBSP, Fragments.sequentialRunNoBSP, subs)              then verbFrag (spec, Fragments.parallelRunNoBSP, Fragments.sequentialRunNoBSP, subs)
83              else verbFrag (spec, Fragments.parallelRun, Fragments.sequentialRun, subs)              else verbFrag (spec, Fragments.parallelRun, Fragments.sequentialRun, subs)
# Line 142  Line 106 
106    
107    (* generate source code that is common to both libraries and standalone executables *)    (* generate source code that is common to both libraries and standalone executables *)
108      fun outputSrc (outS, env, spec, prog, strand, substitutions, genInputCode) = let      fun outputSrc (outS, env, spec, prog, strand, substitutions, genInputCode) = let
109            val IR.Program{consts, inputs, globals, create=IR.Create{dim, ...}, ...} = prog            val IR.Program{consts, inputs, globals, create as IR.Create{dim, ...}, ...} = prog
110            val IR.Strand{name=strandName, ...} = strand            val IR.Strand{name=strandName, ...} = strand
111            val ppDecl = Out.decl outS            val ppDecl = Out.decl outS
112            val {structDef, methods} = GenStrand.gen (env, strand)            val {structDef, methods} = GenStrand.gen (env, strand)
# Line 162  Line 126 
126                else ();                else ();
127              List.app ppDecl (genGlobalStruct (env, consts, inputs, globals));              List.app ppDecl (genGlobalStruct (env, consts, inputs, globals));
128              ppDecl structDef;              ppDecl structDef;
129              ppDecl (genWorldStruct(spec, strandName));              ppDecl (GenWorld.genStruct(spec, strandName, Option.getOpt(dim, 1)));
130              List.app ppDecl (genInputCode());              List.app ppDecl (genInputCode());
131  (* FIXME: need to gather/generate topDecls  (* FIXME: need to gather/generate topDecls
132              List.app ppDecl (!topDecls);              List.app ppDecl (!topDecls);
# Line 170  Line 134 
134              List.app ppDecl methods;              List.app ppDecl methods;
135              List.app ppDecl (GenOutputs.gen (env, dim, outputs));              List.app ppDecl (GenOutputs.gen (env, dim, outputs));
136              ppDecl (CL.verbatimDcl [Fragments.worldMethods] substitutions);              ppDecl (CL.verbatimDcl [Fragments.worldMethods] substitutions);
137  (* TODO              ppDecl (GenWorld.genInitiallyFun (env, strandName, create));
             ppDecl (CL.verbatimDcl [InitFrag.text] substitutions);  
             ppDecl (CL.verbatimDcl [AllocFrag.text] substitutions);  
             ppDecl (!initially);  
 *)  
138              ppDecl (runFrag (spec, substitutions))              ppDecl (runFrag (spec, substitutions))
139            end            end
140    
# Line 217  Line 177 
177  ********************)  ********************)
178    
179      fun exec (spec : TargetSpec.t, prog) = let      fun exec (spec : TargetSpec.t, prog) = let
180            val IR.Program{inputs, strand, ...} = prog            val IR.Program{inputs, strand, create, ...} = prog
181            val env = mkEnv spec            val env = mkEnv spec
182            val baseName = OS.Path.joinDirFile{dir = #outDir spec, file = #outBase spec}            val baseName = OS.Path.joinDirFile{dir = #outDir spec, file = #outBase spec}
183            val substitutions = mkSubs (spec, strand)            val substitutions = mkSubs (spec, strand, create)
184          (* output to C++ file *)          (* output to C++ file *)
185            val outS = openCxxOut baseName            val outS = openCxxOut baseName
186            val ppDecl = Out.decl outS            val ppDecl = Out.decl outS
# Line 233  Line 193 
193                  GenInputs.genInputsStruct (env, inputs) @                  GenInputs.genInputsStruct (env, inputs) @
194                  GenInputs.genExecInputFuns (env, prog) @                  GenInputs.genExecInputFuns (env, prog) @
195                  OutputUtil.genRegisterOutputOpts (env, OutputUtil.gatherOutputs prog)));                  OutputUtil.genRegisterOutputOpts (env, OutputUtil.gatherOutputs prog)));
             ppDecl (verbFrag (spec, Fragments.parallelMain, Fragments.sequentialMain, substitutions));  
196              GenExecUtil.execFoot (outS, substitutions);              GenExecUtil.execFoot (outS, substitutions);
197              (* generate main function after closing off the namespace *)
198                ppDecl (verbFrag (spec, Fragments.parallelMain, Fragments.sequentialMain, substitutions));
199              Out.closeOut outS;              Out.closeOut outS;
200              compile (spec, baseName);              compile (spec, baseName);
201              RunCC.linkExec (baseName, ldFlags spec)              RunCC.linkExec (baseName, ldFlags spec)

Legend:
Removed from v.3918  
changed lines
  Added in v.3924

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