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

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/c-util/gen-inputs.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/c-util/gen-inputs.sml

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

revision 2040, Wed Oct 17 19:34:53 2012 UTC revision 2041, Thu Oct 18 13:16:15 2012 UTC
# Line 11  Line 11 
11    
12      val gatherInputs : TreeIL.block -> input_desc list      val gatherInputs : TreeIL.block -> input_desc list
13    
14      (* generate the input initialization structure that we use to initialize input
15       * globals from command-line arguments in stand-alone executables.
16       *)
17        val genInputsStruct : TargetUtil.target_desc * input_desc list -> CLang.decl
18    
19      (* generate a function to register command-line options for setting the input variables *)
20      val genRegisterInputs : TargetUtil.target_desc * input_desc list -> CLang.decl      val genRegisterInputs : TargetUtil.target_desc * input_desc list -> CLang.decl
21    
22      (* generate a function to initialize the global input variables from the command-line inputs *)
23        val genInitInputs : TargetUtil.target_desc * input_desc list -> CLang.decl
24    
25      (* generated the functions to initialize inputs for the library API *)
26      val genInputFuns : TargetUtil.target_desc * input_desc list -> CLang.decl list      val genInputFuns : TargetUtil.target_desc * input_desc list -> CLang.decl list
27    
28    end = struct    end = struct
# Line 47  Line 57 
57              List.mapPartial gather body              List.mapPartial gather body
58            end            end
59    
60      (* generate the input initialization structure that we use to initialize input
61       * globals from command-line arguments in stand-alone executables.
62       *)
63        fun genInputsStruct (tgt : target_desc, inputs) = let
64              fun mkField (Ty.DynSeqTy _, name, _, _) = (CL.charPtr, name)
65                | mkField (Ty.ImageTy _, name, _, _) = (CL.charPtr, name)
66                | mkField (ty, name, _, _) = (trType ty, name)
67              in
68                CL.D_StructDef(NONE, List.map mkField inputs, SOME(N.inputsTy tgt))
69              end
70    
71    (* generate code to register command-line options for setting the input variables *)    (* generate code to register command-line options for setting the input variables *)
72      fun genRegisterInputs (tgt, inputs) = let      fun genRegisterInputs (tgt, inputs) = let
73            (* the inputs pointer type *)
74              val inputPtrTy = CL.T_Ptr(CL.T_Named(N.inputsTy tgt))
75            (* some common variables *)
76              val inpV = CL.mkVar "inp"
77              val optsV = CL.mkVar "opts"
78            (* register a given input *)
79              fun registerInput (ty, name, desc, hasDflt) = CL.mkCall(N.input ty, [
80                      optsV, CL.mkStr name, CL.mkStr(Option.getOpt(desc, "")),
81                      CL.mkUnOp(CL.%&, CL.mkIndirect(inpV, name)),
82                      CL.mkBool hasDflt
83                    ])
84              in
85                CL.D_Func(
86                  ["static"], CL.voidTy, N.registerOpts,
87                  [CL.PARAM([], inputPtrTy, "inp"), CL.PARAM([], CL.T_Ptr(CL.T_Named N.optionsTy), "opts")],
88                  CL.mkBlock(List.map registerInput inputs))
89              end
90    
91      (* generate code to initialize the global input variables from the command-line inputs *)
92        fun genInitInputs (tgt, inputs) = let
93          (* the world pointer type *)          (* the world pointer type *)
94            val worldPtrTy = CL.T_Ptr(CL.T_Named(N.worldTy tgt))            val worldPtrTy = CL.T_Ptr(CL.T_Named(N.worldTy tgt))
95          (* the global state pointer type *)          (* the global state pointer type *)
96            val globPtrTy = CL.T_Ptr(CL.T_Named(N.globalTy tgt))            val globPtrTy = CL.T_Ptr(CL.T_Named(N.globalTy tgt))
97            (* the inputs pointer type *)
98              val inputPtrTy = CL.T_Ptr(CL.T_Named(N.inputsTy tgt))
99          (* some common variables *)          (* some common variables *)
100              val inpV = CL.mkVar "inp"
101            val globV = CL.mkVar "glob"            val globV = CL.mkVar "glob"
102            val optsV = CL.mkVar "opts"            val optsV = CL.mkVar "opts"
103          (* register a given input *)          (* initialize a given input global; for sequences and images, this requires
104            fun registerInput (Ty.DynSeqTy elemTy, name, desc, hasDflt) = CL.mkCall("dummy", [           * loading the value from the specified nrrd file, while for other types
105             * we just copy the values.
106             *)
107              fun initInput (Ty.DynSeqTy elemTy, name, desc, hasDflt) = CL.mkCall("dummy", [
108                    optsV, CL.mkStr name, CL.mkStr(Option.getOpt(desc, "")),                    optsV, CL.mkStr name, CL.mkStr(Option.getOpt(desc, "")),
109                    CL.mkUnOp(CL.%&, CL.mkIndirect(globV, name)),                    CL.mkUnOp(CL.%&, CL.mkIndirect(globV, name)),
110                    CL.mkBool hasDflt                    CL.mkBool hasDflt
111                  ])                  ])
112              | registerInput (Ty.ImageTy info, name, desc, hasDflt) = CL.mkCall("dummy", [              | initInput (Ty.ImageTy info, name, desc, hasDflt) = CL.mkCall("dummy", [
                   optsV, CL.mkStr name, CL.mkStr(Option.getOpt(desc, "")),  
                   CL.mkUnOp(CL.%&, CL.mkIndirect(globV, name)),  
                   CL.mkBool hasDflt  
                 ])  
             | registerInput (ty, name, desc, hasDflt) = CL.mkCall(N.input ty, [  
113                    optsV, CL.mkStr name, CL.mkStr(Option.getOpt(desc, "")),                    optsV, CL.mkStr name, CL.mkStr(Option.getOpt(desc, "")),
114                    CL.mkUnOp(CL.%&, CL.mkIndirect(globV, name)),                    CL.mkUnOp(CL.%&, CL.mkIndirect(globV, name)),
115                    CL.mkBool hasDflt                    CL.mkBool hasDflt
116                  ])                  ])
117                | initInput (ty, name, _, _) =
118                    CL.mkAssign(CL.mkIndirect(globV, name), CL.mkIndirect(inpV, name))
119            in            in
120              CL.D_Func(              CL.D_Func(
121                ["static"], CL.voidTy, N.registerOpts,                ["static"], CL.voidTy, N.initInputs,
122                [CL.PARAM([], worldPtrTy, "wrld"), CL.PARAM([], CL.T_Ptr(CL.T_Named N.optionsTy), "opts")],                [CL.PARAM([], worldPtrTy, "wrld"), CL.PARAM([], inputPtrTy, "inp")],
123                CL.mkBlock(                CL.mkBlock(
124                  CL.mkDeclInit(globPtrTy, "glob", CL.mkIndirect(CL.mkVar "wrld", "globals")) ::                  CL.mkDeclInit(globPtrTy, "glob", CL.mkIndirect(CL.mkVar "wrld", "globals")) ::
125                  List.map registerInput inputs))                  List.map initInput inputs))
126            end            end
127    
128    (* for each input variable we generate two or three top-level declaraions *)    (* for each input variable we generate two or three top-level declarations in the
129       * exported API.
130       *)
131      fun genInputFuns (tgt, inputs) = let      fun genInputFuns (tgt, inputs) = let
132          (* the world pointer type *)          (* the world pointer type *)
133            val worldPtrTy = CL.T_Ptr(CL.T_Named(N.worldTy tgt))            val worldPtrTy = CL.T_Ptr(CL.T_Named(N.worldTy tgt))

Legend:
Removed from v.2040  
changed lines
  Added in v.2041

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