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

SCM Repository

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

Diff of /branches/vis15/src/compiler/cxx-util/gen-inputs-util.sml

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

revision 3910, Tue May 24 21:55:24 2016 UTC revision 3912, Wed May 25 14:53:50 2016 UTC
# Line 10  Line 10 
10    
11      type input_desc = TreeGlobalVar.t Inputs.input      type input_desc = TreeGlobalVar.t Inputs.input
12    
   (* an l-value expression for accessing a defined-input flag for the given global input *)  
     val defined : TreeGlobalVar.t -> CLang.exp  
   
13    (*** Support for standalone executables ***)    (*** Support for standalone executables ***)
14    
15      (* generate the input initialization structure that we use to initialize input
16       * globals from command-line arguments in stand-alone executables.
17       *)
18        val genInputsStruct : CodeGenEnv.t * input_desc list -> CLang.decl list
19    
20    (* generate the common functions that handle inputs for standalone executables.  These are:    (* generate the common functions that handle inputs for standalone executables.  These are:
21     *    init_defaults    -- called to initialize the default input values     *    init_defaults    -- called to initialize the default input values
22     *    register_inputs  -- called to register the command-line options for the input globals     *    register_inputs  -- called to register the command-line options for the input globals
# Line 29  Line 31 
31    (* generate the function that initializes the defined-input flag struct. *)    (* generate the function that initializes the defined-input flag struct. *)
32      val genDefineInp : input_desc list -> CLang.decl      val genDefineInp : input_desc list -> CLang.decl
33    
34      (*** Utility functions ***)
35    
36      (* generate code to copy a value *)
37        val copy : {env : CodeGenEnv.t, ty : APITypes.t, src : CLang.exp, dst : CLang.exp} -> CLang.stm
38    
39      (* an l-value expression for accessing a defined-input flag for the given global input *)
40        val defined : TreeGlobalVar.t -> CLang.exp
41    
42    end = struct    end = struct
43    
44      structure IR = TreeIR      structure IR = TreeIR
# Line 48  Line 58 
58    (* translate a TreeIR type to the C types used to represent it in the external API *)    (* translate a TreeIR type to the C types used to represent it in the external API *)
59      val trType = CodeGenUtil.trAPIType      val trType = CodeGenUtil.trAPIType
60    
61      (* generate the input initialization structure that we use to initialize input
62       * globals from command-line arguments in stand-alone executables.
63       *)
64        fun genInputsStruct (_, []) = []
65          | genInputsStruct (env : Env.t, inputs) = let
66              fun mkField (Inp.INP{var, ty, ...}) = (case ty
67                     of Ty.SeqTy(_, NONE) => (CL.charPtr, GVar.name var)
68                      | Ty.ImageTy _ => (CL.charPtr, GVar.name var)
69                      | ty => (trType(env, ty), GVar.name var)
70                    (* end case *))
71              in
72                [CL.D_StructDef(NONE, List.map mkField inputs, SOME "cmd_line_inputs")]
73              end
74    
75    (* generate code to initialize the default input values *)    (* generate code to initialize the default input values *)
76      fun genInitDefaults (env, constInit) =      fun genInitDefaults (env, constInit) =
77            CL.D_Func(            CL.D_Func(
# Line 115  Line 139 
139                CL.mkBlock(List.map initFlag inputs))                CL.mkBlock(List.map initFlag inputs))
140            end            end
141    
142      (* generate code to copy a value *)
143        fun copy {env, ty, src, dst} = let
144              fun assign () = CL.mkAssign(dst, src)
145              fun addrOf (CL.E_UnOp(CL.%*, x)) = x
146                | addrOf x = CL.mkUnOp(CL.%&, x)
147              fun memcpy () =
148                    CL.mkCall("std::memcpy", [addrOf dst, addrOf src, CL.mkSizeof(trType(env, ty))])
149              in
150                case ty
151                 of Ty.IntTy => assign ()
152                  | Ty.BoolTy => assign ()
153                  | Ty.TensorTy[] => assign ()
154                  | Ty.TensorTy shp => memcpy()
155    (* FIXME: here we probably need to deal with a conversion between "char *" and "std::string" *)
156                  | Ty.StringTy => raise Fail "FIXME: copy string"
157                  | Ty.ImageTy _ => raise Fail "unexpected image copy"
158                  | Ty.SeqTy(_, SOME _) => memcpy()
159                  | Ty.SeqTy(_, NONE) => raise Fail "unexpected dynamic sequence copy"
160                (* end case *)
161              end
162    
163    end    end

Legend:
Removed from v.3910  
changed lines
  Added in v.3912

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