Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /trunk/src/compiler/c-target/c-target.sml
ViewVC logotype

Diff of /trunk/src/compiler/c-target/c-target.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1231, Mon May 16 13:49:17 2011 UTC revision 1232, Mon May 16 23:37:52 2011 UTC
# Line 27  Line 27 
27        }        }
28    
29      datatype program = Prog of {      datatype program = Prog of {
30            double : bool,                  (* true for double-precision support *)
31            parallel : bool,                (* true for multithreaded (or multi-GPU) target *)
32            debug : bool,                   (* true for debug support in executable *)
33          globals : CL.decl list ref,          globals : CL.decl list ref,
34          topDecls : CL.decl list ref,          topDecls : CL.decl list ref,
35          strands : strand AtomTable.hash_table,          strands : strand AtomTable.hash_table,
# Line 54  Line 57 
57     * the supported sizes are powers of two, but float2 is broken.     * the supported sizes are powers of two, but float2 is broken.
58     * NOTE: we should also consider the AVX vector hardware, which has 256-bit registers.     * NOTE: we should also consider the AVX vector hardware, which has 256-bit registers.
59     *)     *)
60      fun vectorWidths () = if !Controls.doublePrecision      fun vectorWidths () = if !RuntimeNames.doublePrecision
61            then [2, 4, 8]            then [2, 4, 8]
62            else [4, 8]            else [4, 8]
63    
# Line 65  Line 68 
68    (* TreeIL to target translations *)    (* TreeIL to target translations *)
69      structure Tr =      structure Tr =
70        struct        struct
71            fun fragment (ENV{info, vMap, scope}, blk) = let
72                  val (vMap, stms) = ToC.trFragment (vMap, blk)
73                  in
74                    (ENV{info=info, vMap=vMap, scope=scope}, stms)
75                  end
76          fun saveState cxt stateVars (env, args, stm) = (          fun saveState cxt stateVars (env, args, stm) = (
77                ListPair.foldrEq                ListPair.foldrEq
78                  (fn (x, e, stms) => ToC.trAssign(env, x, e)@stms)                  (fn (x, e, stms) => ToC.trAssign(env, x, e)@stms)
79                    [stm]                    [stm]
80                      (stateVars, args)                      (stateVars, args)
81                ) handle ListPair.UnequalLengths =>                ) handle ListPair.UnequalLengths => (
82                  raise Fail(concat["saveState ", cxt, ": length mismatch"])                  print(concat["saveState ", cxt, ": length mismatch; ", Int.toString(List.length args), " args\n"]);
83                    raise Fail(concat["saveState ", cxt, ": length mismatch"]))
84          fun block (ENV{vMap, scope, ...}, blk) = (case scope          fun block (ENV{vMap, scope, ...}, blk) = (case scope
85                 of StrandScope stateVars => ToC.trBlock (vMap, saveState "StrandScope" stateVars, blk)                 of StrandScope stateVars => ToC.trBlock (vMap, saveState "StrandScope" stateVars, blk)
86                  | MethodScope stateVars => ToC.trBlock (vMap, saveState "MethodScope" stateVars, blk)                  | MethodScope stateVars => ToC.trBlock (vMap, saveState "MethodScope" stateVars, blk)
# Line 126  Line 135 
135    (* programs *)    (* programs *)
136      structure Program =      structure Program =
137        struct        struct
138          fun new () = (          fun new {double, parallel, debug} = (
139                RN.initTargetSpec();                RN.initTargetSpec double;
140                Prog{                Prog{
141                      double = double, parallel = parallel, debug = debug,
142                    globals = ref [                    globals = ref [
143                      CL.D_Verbatim[                      CL.D_Verbatim[
144                          if !Controls.doublePrecision                          if double
145                            then "#define DIDEROT_DOUBLE_PRECISION"                            then "#define DIDEROT_DOUBLE_PRECISION"
146                            else "#define DIDEROT_SINGLE_PRECISION",                            else "#define DIDEROT_SINGLE_PRECISION",
147                          "#include \"Diderot/diderot.h\""                          "#include \"Diderot/diderot.h\""
# Line 142  Line 152 
152                  })                  })
153        (* register the global initialization part of a program *)        (* register the global initialization part of a program *)
154          fun init (Prog{topDecls, ...}, init) = let          fun init (Prog{topDecls, ...}, init) = let
155                val initFn = CL.D_Func([], CL.voidTy, RN.initGlobals, [], init)                val initFn = CL.D_Func(
156                        [], CL.voidTy, RN.initGlobals, [
157                            CL.PARAM([], CL.intTy, "argc"),
158                            CL.PARAM(["const"], CL.T_Ptr(CL.charPtr), "argv")
159                          ],
160                        init)
161                  val shutdownFn = CL.D_Func(
162                        [], CL.voidTy, RN.shutdown,
163                        [CL.PARAM([], CL.T_Ptr(CL.T_Named RN.worldTy), "wrld")],
164                        CL.S_Block[])
165                in                in
166                  topDecls := initFn :: !topDecls                  topDecls := shutdownFn :: initFn :: !topDecls
167                end                end
168        (* create and register the initially function for a program *)        (* create and register the initially function for a program *)
169          fun initially {          fun initially {
170                prog = Prog{strands, initially, ...},                prog = Prog{strands, initially, ...},
171                isArray : bool,                isArray : bool,
172                iterPrefix : stm,                iterPrefix : stm list,
173                iters : (var * exp * exp) list,                iters : (var * exp * exp) list,
174                createPrefix : stm,                createPrefix : stm list,
175                strand : Atom.atom,                strand : Atom.atom,
176                args : exp list                args : exp list
177              } = let              } = let
               val iterPrefix = (case iterPrefix  
                      of CL.S_Block stms => stms  
                       | stm => [stm]  
                     (* end case *))  
               val createPrefix = (case createPrefix  
                      of CL.S_Block stms => stms  
                       | stm => [stm]  
                     (* end case *))  
178                val name = Atom.toString strand                val name = Atom.toString strand
179                val nDims = List.length iters                val nDims = List.length iters
180                val worldTy = CL.T_Ptr(CL.T_Named RN.worldTy)                val worldTy = CL.T_Ptr(CL.T_Named RN.worldTy)
# Line 294  Line 305 
305                    SOME(CL.I_Array(genInits (0, strands)))))                    SOME(CL.I_Array(genInits (0, strands)))))
306                end                end
307    
308          fun genSrc (baseName, Prog{globals, topDecls, strands, initially}) = let          fun genSrc (baseName, Prog{globals, topDecls, strands, initially, ...}) = let
309                val fileName = OS.Path.joinBaseExt{base=baseName, ext=SOME "c"}                val fileName = OS.Path.joinBaseExt{base=baseName, ext=SOME "c"}
310                val outS = TextIO.openOut fileName                val outS = TextIO.openOut fileName
311                val ppStrm = PrintAsC.new outS                val ppStrm = PrintAsC.new outS
# Line 313  Line 324 
324        (* output the code to a file.  The string is the basename of the file, the extension        (* output the code to a file.  The string is the basename of the file, the extension
325         * is provided by the target.         * is provided by the target.
326         *)         *)
327          fun generate (baseName, prog) = (          fun generate (basename, prog as Prog{double, parallel, debug, ...}) = let
328                genSrc (baseName, prog);                fun condCons (true, x, xs) = x::xs
329                RunCC.compile baseName;                  | condCons (false, _, xs) = xs
330                RunCC.link baseName)              (* generate the C compiler flags *)
331                  val cflags = ["-I" ^ Paths.diderotInclude, "-I" ^ Paths.teemInclude]
332                  val cflags = condCons (parallel, #pthread Paths.cflags, cflags)
333                  val cflags = if debug
334                        then #debug Paths.cflags :: cflags
335                        else #ndebug Paths.cflags :: cflags
336                  val cflags = #base Paths.cflags :: cflags
337                (* generate the loader flags *)
338                  val extraLibs = condCons (parallel, #pthread Paths.extraLibs, [])
339                  val extraLibs = Paths.teemLinkFlags @ #base Paths.extraLibs :: extraLibs
340                  val rtLib = TargetUtil.runtimeName {
341                          target = TargetUtil.TARGET_C,
342                          parallel = parallel, double = double, debug = debug
343                        }
344                  val ldOpts = rtLib :: extraLibs
345                  in
346                    genSrc (basename, prog);
347                    RunCC.compile (basename, cflags);
348                    RunCC.link (basename, ldOpts)
349                  end
350    
351        end        end
352    

Legend:
Removed from v.1231  
changed lines
  Added in v.1232

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