18 |
| T_Vec of int |
| T_Vec of int |
19 |
| T_IVec of int |
| T_IVec of int |
20 |
| T_Image of int (* n-dimensional image data *) |
| T_Image of int (* n-dimensional image data *) |
21 |
| T_Data (* pointer to image data *) |
| T_Data of CL.ty (* pointer to image data *) |
22 |
|
|
23 |
type strand = unit (* FIXME *) |
type strand = unit (* FIXME *) |
24 |
|
|
35 |
strands : strand list ref |
strands : strand list ref |
36 |
} |
} |
37 |
|
|
|
fun newProgram () = Prog{ |
|
|
globals = ref [], |
|
|
strands = ref [] |
|
|
} |
|
|
|
|
38 |
(* globals that specify the target characteristics. These should be initialized |
(* globals that specify the target characteristics. These should be initialized |
39 |
* when the program object is created. |
* when the program object is created. |
40 |
*) |
*) |
70 |
else T_IVec n |
else T_IVec n |
71 |
fun imageTy dim = T_Image dim |
fun imageTy dim = T_Image dim |
72 |
|
|
73 |
|
(* convert target types to CLang types *) |
74 |
|
fun cvtTy T_Bool = CLang.T_Named "bool" |
75 |
|
| cvtTy T_Int = !gIntTy |
76 |
|
| cvtTy T_Real = !gRealTy |
77 |
|
| cvtTy (T_Vec n) = CLang.T_Named(concat["Diderot_vec", Int.toString n, "D_t"]) |
78 |
|
| cvtTy (T_IVec n) = raise Fail "FIXME: T_IVec" |
79 |
|
| cvtTy (T_Image n) = CLang.T_Named(concat["Diderot_image", Int.toString n, "D_t"]) |
80 |
|
| cvtTy (T_Data ty) = ty |
81 |
|
|
82 |
(* helper functions for checking the types of arguments *) |
(* helper functions for checking the types of arguments *) |
83 |
fun scalarTy T_Int = true |
fun scalarTy T_Int = true |
84 |
| scalarTy T_Real = true |
| scalarTy T_Real = true |
85 |
| scalarTy _ = false |
| scalarTy _ = false |
86 |
fun numTy T_Bool = false |
fun numTy T_Bool = false |
87 |
| numTy (T_Image _) = false |
| numTy (T_Image _) = false |
88 |
| numTy T_Data = false |
| numTy (T_Data _) = false |
89 |
| numTy _ = true |
| numTy _ = true |
90 |
|
|
91 |
|
fun newProgram () = ( |
92 |
|
initGlobals(); |
93 |
|
Prog{ |
94 |
|
globals = ref [], |
95 |
|
strands = ref [] |
96 |
|
}) |
97 |
|
|
98 |
fun defineStrand (p, strandId) = raise Fail "FIXME: unimplemented" |
fun defineStrand (p, strandId) = raise Fail "FIXME: unimplemented" |
99 |
|
|
100 |
structure Var = |
structure Var = |
101 |
struct |
struct |
102 |
fun global (p, ty, name) = raise Fail "FIXME: Var.global" |
fun global (Prog{globals, ...}, ty, name) = ( |
103 |
|
globals := CL.D_Var([], cvtTy ty, name) :: !globals; |
104 |
|
(ty, name)) |
105 |
fun state (strand, ty, name) = raise Fail "FIXME: Var.state" |
fun state (strand, ty, name) = raise Fail "FIXME: Var.state" |
106 |
fun tmp ty = raise Fail "FIXME: Var.tmp" |
fun tmp ty = raise Fail "FIXME: Var.tmp" |
107 |
end |
end |
118 |
(* literals *) |
(* literals *) |
119 |
fun intLit n = (CL.mkInt(n, !gIntTy), intTy) |
fun intLit n = (CL.mkInt(n, !gIntTy), intTy) |
120 |
fun floatLit f = (CL.mkFlt(f, !gRealTy), realTy) |
fun floatLit f = (CL.mkFlt(f, !gRealTy), realTy) |
121 |
fun stringLit s = raise Fail "FIXME: Expr.stringLit" |
fun stringLit s = (CL.mkStr s, T_Data CL.charPtr) |
122 |
fun boolLit b = (CL.mkBool b, boolTy) |
fun boolLit b = (CL.mkBool b, boolTy) |
123 |
|
|
124 |
(* vector construction *) |
(* vector construction *) |
246 |
| floorToInt _ = raise Fail "invalid argument for floorToInt" |
| floorToInt _ = raise Fail "invalid argument for floorToInt" |
247 |
|
|
248 |
(* runtime system hooks *) |
(* runtime system hooks *) |
249 |
fun imageAddr (e, T_Image d) = |
fun imageAddr (e, T_Image d) = let |
250 |
(CL.mkCast(CL.T_Ptr(!gRealTy), CL.mkIndirect(e, "data")), T_Data) |
val cTy = CL.T_Ptr(!gRealTy) |
251 |
|
in |
252 |
|
(CL.mkCast(cTy, CL.mkIndirect(e, "data")), T_Data cTy) |
253 |
|
end |
254 |
| imageAddr _ = raise Fail "invalid argument to imageAddr" |
| imageAddr _ = raise Fail "invalid argument to imageAddr" |
255 |
end |
end |
256 |
|
|
260 |
val comment = CL.S_Comment |
val comment = CL.S_Comment |
261 |
fun assignState (x, (e, _)) = CL.mkAssign(#1(Expr.getState x), e) |
fun assignState (x, (e, _)) = CL.mkAssign(#1(Expr.getState x), e) |
262 |
fun assign ((_, x), (e, _)) = CL.mkAssign(CL.mkVar x, e) |
fun assign ((_, x), (e, _)) = CL.mkAssign(CL.mkVar x, e) |
263 |
|
fun decl ((ty, x), SOME(e, _)) = CL.mkDecl(cvtTy ty, x, SOME e) |
264 |
|
| decl ((ty, x), NONE) = CL.mkDecl(cvtTy ty, x, NONE) |
265 |
val block = CL.mkBlock |
val block = CL.mkBlock |
266 |
fun ifthenelse ((e, T_Bool), s1, s2) = CL.mkIfThenElse(e, s1, s2) |
fun ifthenelse ((e, T_Bool), s1, s2) = CL.mkIfThenElse(e, s1, s2) |
267 |
fun die () = raise Fail "FIXME: Stmt.die" |
fun die () = comment ["**** die ****"] (* FIXME *) |
268 |
fun stabilize () = raise Fail "FIXME: Stmt.die" |
fun stabilize () = comment ["**** stabilize ****"] (* FIXME *) |
269 |
end |
end |
270 |
|
|
271 |
fun generate (baseName, Prog{globals, strands}) = let |
fun generate (baseName, Prog{globals, strands}) = let |
273 |
val outS = TextIO.openOut fileName |
val outS = TextIO.openOut fileName |
274 |
val ppStrm = PrintAsC.new outS |
val ppStrm = PrintAsC.new outS |
275 |
in |
in |
276 |
List.app (fn dcl => PrintAsC.output(ppStrm, dcl)) (!globals); |
List.app (fn dcl => PrintAsC.output(ppStrm, dcl)) (List.rev (!globals)); |
277 |
(* what about the strands, etc? *) |
(* what about the strands, etc? *) |
278 |
PrintAsC.close ppStrm; |
PrintAsC.close ppStrm; |
279 |
TextIO.closeOut outS |
TextIO.closeOut outS |