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 3902, Mon May 23 18:16:41 2016 UTC revision 3903, Mon May 23 18:41:05 2016 UTC
# Line 17  Line 17 
17      structure IR = TreeIR      structure IR = TreeIR
18      structure CL = CLang      structure CL = CLang
19    
20          (* generate source code that is common to both libraries and standalone executables *)
21            fun outputSrc (out, prog, strand, substitutions, genInputCode) = let
22                  val Prog{props, globals, topDecls, nAxes, initially, ...} = prog
23                (* does the program require barrier synchronization to implement BSP semantics? *)
24                  val noBSP = Properties.noBSP props
25                  val Strand{output, ...} = strand
26                  val outputs = GenOutput.gen (props, !nAxes) output
27                  fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)
28                  in
29                    if (#parallel props)
30                      then ppDecl (CL.verbatimDcl [CHeadParExtraFrag.text] substitutions)
31                      else ();
32                    if Properties.dualState props
33                      then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])
34                      else ();
35                    if not(#hasGlobals props)
36                      then ppDecl (CL.D_Verbatim ["#define DIDEROT_NO_GLOBALS\n"])
37                      else ();
38                    if not(#hasInputs props)
39                      then ppDecl (CL.D_Verbatim ["#define DIDEROT_NO_INPUTS\n"])
40                      else ();
41                    List.app ppDecl (genGlobalStruct (props, !globals));
42                    ppDecl (genWorldStruct(prog, strand));
43                    List.app ppDecl (genInputCode());
44                    List.app ppDecl (!topDecls);
45                    List.app ppDecl (genStrand strand);
46                    List.app ppDecl outputs;
47                    ppStrandTable (out, [strand]);
48                    ppDecl (CL.verbatimDcl [InitFrag.text] substitutions);
49                    ppDecl (CL.verbatimDcl [AllocFrag.text] substitutions);
50                    ppDecl (!initially);
51                    ppDecl (runFrag (noBSP, props, substitutions));
52                    ppDecl (CL.verbatimDcl [ShutdownFrag.text] substitutions)
53                  end
54    
55            fun outputLibSrc (baseName, prog as Prog{props, inputs, strands, ...}) = let
56                  val [strand] = AtomTable.listItems strands
57                  val substitutions = mkSubs (props, strand)
58                (* output to C file *)
59                  val out = openOut baseName
60                  fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)
61                  in
62                    ppDecl (CL.verbatimDcl [LibHdrFrag.text] substitutions);
63                    List.app ppDecl (GenInputs.genDefinedInpStruct (props, !inputs));
64                    outputSrc (out, prog, strand, substitutions,
65                      fn () => GenInputs.genInputFuns(props, !inputs));
66                    ppDecl (CL.verbatimDcl [CBodyFrag.text] substitutions);
67                    closeOut out
68                  end
69    
70            fun generateLib (prog as Prog{props, inputs, strands, ...}) = let
71                  val {outDir, outBase, exec, double, parallel, debug, ...} = props
72                  val basename = OS.Path.joinDirFile{dir=outDir, file=outBase}
73                  val [Strand{state, output, ...}] = AtomTable.listItems strands
74                  in
75                  (* generate the library .h file *)
76                    GenLibraryInterface.gen {
77                        props = props,
78                        rt = if #parallel props
79                          then SOME LibInterfaceParFrag.text
80                          else NONE,
81                        inputs = !inputs,
82                        outputs = output
83                      };
84                  (* *)
85                    outputLibSrc (basename, prog);
86                  (* compile and link *)
87                    compile (props, basename);
88                    RunCC.linkLib (basename, ldFlags props)
89                  end
90    
91      fun exec (spec : TargetSpec.t, prog) = let      fun exec (spec : TargetSpec.t, prog) = let
92            val IR.Program{            val IR.Program{
93                    props, target, consts, inputs, constInit,                    props, target, consts, inputs, constInit,
94                    globals, globalInit, strand, create, update                    globals, globalInit, strand, create, update
95                  } = prog                  } = prog
96              val {outDir, outBase, exec, double, parallel, debug, ...} = spec
97              val baseName = OS.Path.joinDirFile{dir=outDir, file=outBase}
98              val substitutions = mkSubs (props, strand)
99            (* output to C++ file *)
100              val out = openOut baseName
101              fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)
102            in            in
103              raise Fail "FIXME"              ppDecl (CL.verbatimDcl [ExecHdrFrag.text] substitutions);
104                ppDecl (CL.verbatimDcl [NrrdSaveHelperFrag.text] substitutions);
105                outputSrc (out, prog, strand, substitutions,
106                  fn () => (
107                    GenInputs.genInputsStruct (props, !inputs) @
108                    GenInputs.genExecInputFuns (props, !inputs) @
109                    OutputUtil.genRegisterOutputOpts output));
110                ppDecl (verbFrag (props, ParMainFrag.text, SeqMainFrag.text, substitutions));
111                closeOut out;
112                compile (props, basename);
113                RunCC.linkExec (basename, ldFlags props)
114            end            end
115    
116      fun library (spec : TargetSpec.t, prog) = let      fun library (spec : TargetSpec.t, prog) = let
# Line 31  Line 118 
118                    props, target, consts, inputs, constInit,                    props, target, consts, inputs, constInit,
119                    globals, globalInit, strand, create, update                    globals, globalInit, strand, create, update
120                  } = prog                  } = prog
121              val {outDir, outBase, exec, double, parallel, debug, ...} = spec
122            in            in
123              raise Fail "FIXME"              raise Fail "FIXME"
124            end            end

Legend:
Removed from v.3902  
changed lines
  Added in v.3903

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