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 *) |
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 = |
184 |
| _ => raise Fail(concat["CTyTranslate.copyToC(", Ty.toString ty, ")"]) |
| _ => raise Fail(concat["CTyTranslate.copyToC(", Ty.toString ty, ")"]) |
185 |
(* end case *)) |
(* end case *)) |
186 |
|
|
187 |
|
(* return a CLang expression that represents the size of the given Diderot type *) |
188 |
|
fun sizeOfType ty = let |
189 |
|
fun tensorSz n = CL.mkBinOp(CL.mkInt(IntInf.fromInt n), CL.#*, CL.E_Var "SIZEOF_DIDEROT_REAL") |
190 |
|
in |
191 |
|
case ty |
192 |
|
of Ty.BoolTy => CL.mkSizeof CL.boolTy |
193 |
|
| Ty.StringTy => CL.mkSizeof(CL.T_Named "Diderot_string_t") |
194 |
|
| Ty.IntTy => CL.E_Var "SIZEOF_DIDEROT_INT" |
195 |
|
| Ty.TensorTy[] => CL.E_Var "SIZEOF_DIDEROT_REAL" |
196 |
|
| Ty.TensorTy[n] => tensorSz n |
197 |
|
| Ty.TensorTy[n, m] => tensorSz (n*m) |
198 |
|
| Ty.TensorTy[n, m, l] => tensorSz (n*m*l) |
199 |
|
| Ty.SeqTy(Ty.IntTy, n) => CL.mkSizeof(CL.T_Named(N.ivecTy n)) |
200 |
|
| Ty.SeqTy(ty, n) => CL.mkSizeof(CL.T_Array(toType ty, SOME n)) |
201 |
|
(* do we make the following types externally visible? *) |
202 |
|
| Ty.DynSeqTy _ => CL.mkSizeof CL.voidTy |
203 |
|
| Ty.AddrTy info => CL.mkSizeof CL.voidTy |
204 |
|
| Ty.ImageTy info => CL.mkSizeof CL.voidTy |
205 |
|
| _ => raise Fail(concat["CTyTranslate.sizeOfType(", Ty.toString ty, ")"]) |
206 |
|
(* end case *) |
207 |
|
end |
208 |
|
|
209 |
end |
end |