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

SCM Repository

[diderot] Diff of /branches/staging/src/compiler/c-util/c-ty-translate.sml
ViewVC logotype

Diff of /branches/staging/src/compiler/c-util/c-ty-translate.sml

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

revision 2634, Mon May 26 13:48:02 2014 UTC revision 2635, Mon May 26 14:06:39 2014 UTC
# Line 10  Line 10 
10  signature TY_TRANSLATE =  signature TY_TRANSLATE =
11    sig    sig
12    
13    (* translate a type to its internal Diderot represenation *)    (* translate a type to its internal Diderot representation *)
14      val toType : TreeIL.Ty.ty -> CLang.ty      val toType : TreeIL.Ty.ty -> CLang.ty
15    
16    (* translate a TreeIL type to the C types used to represent it in the external API *)    (* translate a TreeIL type to the C types used to represent it in the external API *)
# Line 29  Line 29 
29     *)     *)
30      val copyFromC : {ty : TreeIL.Ty.ty, dst : CLang.exp, src : CLang.exp} -> CLang.stm list      val copyFromC : {ty : TreeIL.Ty.ty, dst : CLang.exp, src : CLang.exp} -> CLang.stm list
31    
32      (* return a CLang expression that represents the size of the given Diderot type *)
33        val sizeOfType : TreeIL.Ty.ty -> CLang.exp
34    
35    end    end
36    
37  structure CTyTranslate : TY_TRANSLATE =  structure CTyTranslate : TY_TRANSLATE =
# Line 179  Line 182 
182              | _ => raise Fail(concat["CTyTranslate.copyToC(", Ty.toString ty, ")"])              | _ => raise Fail(concat["CTyTranslate.copyToC(", Ty.toString ty, ")"])
183            (* end case *))            (* end case *))
184    
185      (* return a CLang expression that represents the size of the given Diderot type *)
186        fun sizeOfType ty = let
187              fun tensorSz n = CL.mkBinOp(CL.mkInt(IntInf.fromInt n), CL.#*, CL.E_Var "SIZEOF_DIDEROT_REAL")
188              in
189                case ty
190                 of Ty.BoolTy => CL.mkSizeof CL.boolTy
191                  | Ty.StringTy => CL.mkSizeof(CL.T_Named "Diderot_string_t")
192                  | Ty.IntTy => CL.E_Var "SIZEOF_DIDEROT_INT"
193                  | Ty.TensorTy[] => CL.E_Var "SIZEOF_DIDEROT_REAL"
194                  | Ty.TensorTy[n] => tensorSz n
195                  | Ty.TensorTy[n, m] => tensorSz (n*m)
196                  | Ty.TensorTy[n, m, l] => tensorSz (n*m*l)
197                  | Ty.SeqTy(Ty.IntTy, n) => CL.mkSizeof(CL.T_Named(N.ivecTy n))
198                  | Ty.SeqTy(ty, n) => CL.mkSizeof(CL.T_Array(toType ty, SOME n))
199      (* do we make the following types externally visible? *)
200                  | Ty.AddrTy info => CL.mkSizeof CL.voidTy
201                  | Ty.ImageTy info => CL.mkSizeof CL.voidTy
202                  | _ => raise Fail(concat["CTyTranslate.sizeOfType(", Ty.toString ty, ")"])
203                (* end case *)
204              end
205    
206    end    end

Legend:
Removed from v.2634  
changed lines
  Added in v.2635

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