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 3903, Mon May 23 18:41:05 2016 UTC revision 3905, Mon May 23 20:36:28 2016 UTC
# Line 16  Line 16 
16    
17      structure IR = TreeIR      structure IR = TreeIR
18      structure CL = CLang      structure CL = CLang
19        structure Env = CodeGenEnv
20        structure Out = CodeOutput
21    
22        val openCxxOut = Out.openOut {ext = "cxx", ppDecl = PrintAsCxx.output}
23    
24      (* create the target-specific substitution list *)
25        fun mkSubs (spec, IR.Strand{name, ...}) = [
26                ("CFILE",                   OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "c"}),
27                ("CXXFILE",                 OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "cxx"}),
28                ("HDRFILE",                 OS.Path.joinBaseExt{base= #outBase spec, ext= SOME "h"}),
29                ("PREFIX",                  #namespace spec),
30                ("SRCFILE",                 #srcFile spec),
31                ("PROG_NAME",               #outBase spec),
32                ("STRAND",                  Atom.toString name),
33                ("STRANDTY",                Atom.toString name ^ "_strand"),
34                ("DIDEROTC_CMD",            #diderotc spec),
35                ("DIDEROTC_ARGV",           String.concatWith " " (#argv spec)),
36                ("DIDEROTC_VERSION",        #version spec),
37                ("DIDEROT_FLOAT_PRECISION", TargetSpec.floatPrecisionDef spec),
38                ("DIDEROT_INT_PRECISION",   TargetSpec.intPrecisionDef spec),
39                ("DIDEROT_TARGET",          TargetSpec.targetDef spec)
40              ]
41    
42        fun condCons (true, x, xs) = x::xs
43          | condCons (false, _, xs) = xs
44    
45        fun verbFrag (spec : TargetSpec.t, parFrag, seqFrag, subs) =
46              CL.verbatimDcl [if (#parallel spec) then parFrag else seqFrag] subs
47    
48        fun runFrag (false, spec, subs) =
49              verbFrag (spec, ParRunFrag.text, SeqRunFrag.text, subs)
50          | runFrag (true, spec, subs) =
51              verbFrag (spec, ParRunNoBSPFrag.text, SeqRunNoBSPFrag.text, subs)
52    
53        fun compile (spec : TargetSpec.t, basename) = let
54            (* generate the C compiler flags *)
55              val cflags = ["-I" ^ Paths.diderotInclude(), "-I" ^ Paths.teemInclude()]
56              val cflags = condCons (#parallel spec, #pthread Paths.cflags, cflags)
57              val cflags = if #debug props
58                    then #debug Paths.cflags :: cflags
59                    else #ndebug Paths.cflags :: cflags
60              val cflags = #base Paths.cflags :: cflags
61              in
62                RunCC.compile (basename, cflags)
63              end
64    
65        fun ldFlags (spec : TargetSpec.t) = if #exec props
66              then let
67                val extraLibs = condCons (#parallel spec, #pthread Paths.extraLibs, [])
68                val extraLibs = Paths.teemLinkFlags() @ #base Paths.extraLibs :: extraLibs
69                val rtLib = Properties.runtimeName spec
70                in
71                  condCons (#parallel spec, #pthread Paths.cflags, rtLib :: extraLibs)
72                end
73              else [Properties.runtimeName props]
74    
75    (********************
76        (* generate source code that is common to both libraries and standalone executables *)        (* generate source code that is common to both libraries and standalone executables *)
77          fun outputSrc (out, prog, strand, substitutions, genInputCode) = let          fun outputSrc (out, prog, strand, substitutions, genInputCode) = let
78                val Prog{props, globals, topDecls, nAxes, initially, ...} = prog                val Prog{props, globals, topDecls, nAxes, initially, ...} = prog
# Line 87  Line 143 
143                  compile (props, basename);                  compile (props, basename);
144                  RunCC.linkLib (basename, ldFlags props)                  RunCC.linkLib (basename, ldFlags props)
145                end                end
146    ********************)
147    
148      fun exec (spec : TargetSpec.t, prog) = let      fun exec (spec : TargetSpec.t, prog) = let
149            val IR.Program{            val IR.Program{
# Line 94  Line 151 
151                    globals, globalInit, strand, create, update                    globals, globalInit, strand, create, update
152                  } = prog                  } = prog
153            val {outDir, outBase, exec, double, parallel, debug, ...} = spec            val {outDir, outBase, exec, double, parallel, debug, ...} = spec
154            val baseName = OS.Path.joinDirFile{dir=outDir, file=outBase}            val env = Env.new spec
155              val baseName = OS.Path.joinDirFile{dir = #outDir spec, file = #outBase spec}
156            val substitutions = mkSubs (props, strand)            val substitutions = mkSubs (props, strand)
157          (* output to C++ file *)          (* output to C++ file *)
158            val out = openOut baseName            val outS = openCxxOut baseName
159            fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)            val ppDecl = Out.decl outS
160              val fragment = Out.fragment substitutions outS
161            in            in
162              ppDecl (CL.verbatimDcl [ExecHdrFrag.text] substitutions);              ppDecl (CL.verbatimDcl [ExecHdrFrag.text] substitutions);
163              ppDecl (CL.verbatimDcl [NrrdSaveHelperFrag.text] substitutions);              ppDecl (CL.verbatimDcl [NrrdSaveHelperFrag.text] substitutions);
164              outputSrc (out, prog, strand, substitutions,              outputSrc (out, prog, strand, substitutions,
165                fn () => (                fn () => (
166                  GenInputs.genInputsStruct (props, !inputs) @                  GenInputs.genInputsStruct (env, !inputs) @
167                  GenInputs.genExecInputFuns (props, !inputs) @                  GenInputs.genExecInputFuns (env, !inputs) @
168                  OutputUtil.genRegisterOutputOpts output));                  OutputUtil.genRegisterOutputOpts output));
169              ppDecl (verbFrag (props, ParMainFrag.text, SeqMainFrag.text, substitutions));              ppDecl (verbFrag (props, ParMainFrag.text, SeqMainFrag.text, substitutions));
170              closeOut out;              closeOut out;

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

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