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 3905, Mon May 23 20:36:28 2016 UTC revision 3906, Mon May 23 22:09:41 2016 UTC
# Line 18  Line 18 
18      structure CL = CLang      structure CL = CLang
19      structure Env = CodeGenEnv      structure Env = CodeGenEnv
20      structure Out = CodeOutput      structure Out = CodeOutput
21        structure RN = CxxNames
22    
23      val openCxxOut = Out.openOut {ext = "cxx", ppDecl = PrintAsCxx.output}      val openCxxOut = Out.openOut {ext = "cxx", ppDecl = PrintAsCxx.output}
24    
# Line 42  Line 43 
43      fun condCons (true, x, xs) = x::xs      fun condCons (true, x, xs) = x::xs
44        | condCons (false, _, xs) = xs        | condCons (false, _, xs) = xs
45    
46      fun verbFrag (spec : TargetSpec.t, parFrag, seqFrag, subs) =      fun verbFrag (spec, parFrag, seqFrag, subs) =
47            CL.verbatimDcl [if (#parallel spec) then parFrag else seqFrag] subs            CL.verbatimDcl [if (TargetSpec.isParallel spec) then parFrag else seqFrag] subs
48    
49      fun runFrag (false, spec, subs) =      fun runFrag (false, spec, subs) =
50            verbFrag (spec, ParRunFrag.text, SeqRunFrag.text, subs)            verbFrag (spec, ParRunFrag.text, SeqRunFrag.text, subs)
# Line 53  Line 54 
54      fun compile (spec : TargetSpec.t, basename) = let      fun compile (spec : TargetSpec.t, basename) = let
55          (* generate the C compiler flags *)          (* generate the C compiler flags *)
56            val cflags = ["-I" ^ Paths.diderotInclude(), "-I" ^ Paths.teemInclude()]            val cflags = ["-I" ^ Paths.diderotInclude(), "-I" ^ Paths.teemInclude()]
57            val cflags = condCons (#parallel spec, #pthread Paths.cflags, cflags)            val cflags = condCons (TargetSpec.isParallel spec, #pthread Paths.cflags, cflags)
58            val cflags = if #debug props            val cflags = if #debug spec
59                  then #debug Paths.cflags :: cflags                  then #debug Paths.cflags :: cflags
60                  else #ndebug Paths.cflags :: cflags                  else #ndebug Paths.cflags :: cflags
61            val cflags = #base Paths.cflags :: cflags            val cflags = #base Paths.cflags :: cflags
# Line 62  Line 63 
63              RunCC.compile (basename, cflags)              RunCC.compile (basename, cflags)
64            end            end
65    
66      fun ldFlags (spec : TargetSpec.t) = if #exec props      fun ldFlags (spec : TargetSpec.t) = if #exec spec
67            then let            then let
68              val extraLibs = condCons (#parallel spec, #pthread Paths.extraLibs, [])              val extraLibs = condCons (TargetSpec.isParallel spec, #pthread Paths.extraLibs, [])
69              val extraLibs = Paths.teemLinkFlags() @ #base Paths.extraLibs :: extraLibs              val extraLibs = Paths.teemLinkFlags() @ #base Paths.extraLibs :: extraLibs
70              val rtLib = Properties.runtimeName spec              val rtLib = TargetSpec.runtimeLibName spec
71              in              in
72                condCons (#parallel spec, #pthread Paths.cflags, rtLib :: extraLibs)                condCons (TargetSpec.isParallel spec, #pthread Paths.cflags, rtLib :: extraLibs)
73              end              end
74            else [Properties.runtimeName props]            else [TargetSpec.runtimeLibName spec]
75    
76  (********************  (********************
77        (* generate source code that is common to both libraries and standalone executables *)        (* generate source code that is common to both libraries and standalone executables *)
# Line 82  Line 83 
83                val outputs = GenOutput.gen (props, !nAxes) output                val outputs = GenOutput.gen (props, !nAxes) output
84                fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)                fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)
85                in                in
86                  if (#parallel props)                  if (TargetSpec.isParallel spec)
87                    then ppDecl (CL.verbatimDcl [CHeadParExtraFrag.text] substitutions)                    then ppDecl (CL.verbatimDcl [CHeadParExtraFrag.text] substitutions)
88                    else ();                    else ();
89                  if Properties.dualState props                  if Properties.dualState props
# Line 124  Line 125 
125                end                end
126    
127          fun generateLib (prog as Prog{props, inputs, strands, ...}) = let          fun generateLib (prog as Prog{props, inputs, strands, ...}) = let
128                val {outDir, outBase, exec, double, parallel, debug, ...} = props                val {outDir, outBase, exec, double, debug, ...} = props
129                val basename = OS.Path.joinDirFile{dir=outDir, file=outBase}                val basename = OS.Path.joinDirFile{dir=outDir, file=outBase}
130                val [Strand{state, output, ...}] = AtomTable.listItems strands                val [Strand{state, output, ...}] = AtomTable.listItems strands
131                in                in
132                (* generate the library .h file *)                (* generate the library .h file *)
133                  GenLibraryInterface.gen {                  GenLibraryInterface.gen {
134                      props = props,                      props = props,
135                      rt = if #parallel props                      rt = if TargetSpec.isParallel spec
136                        then SOME LibInterfaceParFrag.text                        then SOME LibInterfaceParFrag.text
137                        else NONE,                        else NONE,
138                      inputs = !inputs,                      inputs = !inputs,
# Line 150  Line 151 
151                    props, target, consts, inputs, constInit,                    props, target, consts, inputs, constInit,
152                    globals, globalInit, strand, create, update                    globals, globalInit, strand, create, update
153                  } = prog                  } = prog
154            val {outDir, outBase, exec, double, parallel, debug, ...} = spec            val {outDir, outBase, exec, double, debug, ...} = spec
155            val env = Env.new spec            val env = Env.new {
156                      global = RN.globalsVar,
157                      selfIn = RN.selfInVar,
158                      selfOut = if TargetSpec.dualState spec then RN.selfOutVar else RN.selfInVar,
159                      spec = spec
160                    }
161            val baseName = OS.Path.joinDirFile{dir = #outDir spec, file = #outBase spec}            val baseName = OS.Path.joinDirFile{dir = #outDir spec, file = #outBase spec}
162            val substitutions = mkSubs (props, strand)            val substitutions = mkSubs (spec, strand)
163          (* output to C++ file *)          (* output to C++ file *)
164            val outS = openCxxOut baseName            val outS = openCxxOut baseName
165            val ppDecl = Out.decl outS            val ppDecl = Out.decl outS
# Line 161  Line 167 
167            in            in
168              ppDecl (CL.verbatimDcl [ExecHdrFrag.text] substitutions);              ppDecl (CL.verbatimDcl [ExecHdrFrag.text] substitutions);
169              ppDecl (CL.verbatimDcl [NrrdSaveHelperFrag.text] substitutions);              ppDecl (CL.verbatimDcl [NrrdSaveHelperFrag.text] substitutions);
170              outputSrc (out, prog, strand, substitutions,              outputSrc (outS, prog, strand, substitutions,
171                fn () => (                fn () => (
172                  GenInputs.genInputsStruct (env, !inputs) @                  GenInputs.genInputsStruct (env, inputs) @
173                  GenInputs.genExecInputFuns (env, !inputs) @                  GenInputs.genExecInputFuns (env, inputs) @
174                  OutputUtil.genRegisterOutputOpts output));                  OutputUtil.genRegisterOutputOpts output));
175              ppDecl (verbFrag (props, ParMainFrag.text, SeqMainFrag.text, substitutions));              ppDecl (verbFrag (spec, ParMainFrag.text, SeqMainFrag.text, substitutions));
176              closeOut out;              Out.closeOut outS;
177              compile (props, basename);              compile (spec, baseName);
178              RunCC.linkExec (basename, ldFlags props)              RunCC.linkExec (baseName, ldFlags spec)
179            end            end
180    
181      fun library (spec : TargetSpec.t, prog) = let      fun library (spec : TargetSpec.t, prog) = let
# Line 177  Line 183 
183                    props, target, consts, inputs, constInit,                    props, target, consts, inputs, constInit,
184                    globals, globalInit, strand, create, update                    globals, globalInit, strand, create, update
185                  } = prog                  } = prog
186            val {outDir, outBase, exec, double, parallel, debug, ...} = spec            val {outDir, outBase, exec, double, debug, ...} = spec
187            in            in
188              raise Fail "FIXME"              raise Fail "FIXME"
189            end            end

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

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