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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/c-target/c-target.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/c-target/c-target.sml

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

revision 560, Tue Feb 22 22:14:12 2011 UTC revision 561, Wed Feb 23 00:31:32 2011 UTC
# Line 61  Line 61 
61        | cvtTy T_String = CL.charPtr        | cvtTy T_String = CL.charPtr
62        | cvtTy T_Int = !RN.gIntTy        | cvtTy T_Int = !RN.gIntTy
63        | cvtTy T_Real = !RN.gRealTy        | cvtTy T_Real = !RN.gRealTy
64        | cvtTy (T_Vec n) = CLang.T_Named(RN.vecTy n)        | cvtTy (T_Vec n) = CL.T_Named(RN.vecTy n)
65        | cvtTy (T_IVec n) = CLang.T_Named(RN.ivecTy n)        | cvtTy (T_IVec n) = CL.T_Named(RN.ivecTy n)
66        | cvtTy (T_Image(n, _)) = CLang.T_Named(RN.imageTy n)        | cvtTy (T_Image(n, _)) = CL.T_Ptr(CL.T_Named(RN.imageTy n))
67        | cvtTy (T_Ptr ty) = CL.T_Ptr(CL.T_Num ty)        | cvtTy (T_Ptr ty) = CL.T_Ptr(CL.T_Num ty)
68    
69    (* report invalid arguments *)    (* report invalid arguments *)
# Line 147  Line 147 
147          fun stringLit s = (CL.mkStr s, stringTy)          fun stringLit s = (CL.mkStr s, stringTy)
148          fun boolLit b = (CL.mkBool b, boolTy)          fun boolLit b = (CL.mkBool b, boolTy)
149    
150        (* select from a vector *)        (* select from a vector.  We have to cast to the corresponding union type and then
151          fun select (i, (e, T_Vec n)) =         * select from the array field.
152                if (i < 0) orelse (n <= i)         *)
153                  then raise Subscript          local
154                  else (CL.mkSubscript(e, CL.mkInt(IntInf.fromInt i, CL.int32)), T_Real)            fun sel (tyCode, field, ty) (i, e, n) =
           | select (i, (e, T_IVec n)) =  
155                if (i < 0) orelse (n <= i)                if (i < 0) orelse (n <= i)
156                  then raise Subscript                  then raise Subscript
157                  else (CL.mkSubscript(e, CL.mkInt(IntInf.fromInt i, CL.int32)), T_Int)                    else let
158                        val unionTy = CL.T_Named(concat["union", Int.toString n, !tyCode, "_t"])
159                        val e1 = CL.mkCast(unionTy, e)
160                        val e2 = CL.mkSelect(e1, field)
161                        in
162                          (CL.mkSubscript(e2, CL.mkInt(IntInf.fromInt i, CL.int32)), ty)
163                        end
164            val selF = sel (RN.gRealSuffix, "r", T_Real)
165            val selI = sel (RN.gIntSuffix, "i", T_Int)
166            in
167            fun select (i, (e, T_Vec n)) = selF (i, e, n)
168              | select (i, (e, T_IVec n)) = selI (i, e, n)
169            | select (_, x) = invalid("select", [x])            | select (_, x) = invalid("select", [x])
170            end (* local *)
171    
172        (* vector (and scalar) arithmetic *)        (* vector (and scalar) arithmetic *)
173          local          local
# Line 233  Line 244 
244            fun checkTys (ty1, ty2) = (ty1 = ty2) andalso scalarTy ty1            fun checkTys (ty1, ty2) = (ty1 = ty2) andalso scalarTy ty1
245            fun binFn f ((e1, ty1), (e2, ty2)) =            fun binFn f ((e1, ty1), (e2, ty2)) =
246                  if checkTys (ty1, ty2)                  if checkTys (ty1, ty2)
247                    then (CL.mkApply(f, [e1, e2]), ty1)                    then (CL.mkApply(f ty1, [e1, e2]), ty1)
248                    else raise Fail "invalid arguments to binary function"                    else raise Fail "invalid arguments to binary function"
249          in          in
250        (* misc functions *)        (* misc functions *)
251          val min = binFn "Diderot_min"          val min = binFn RN.min
252          val max = binFn "Diderot_max"          val max = binFn RN.max
253          end (* local *)          end (* local *)
254    
255        (* math functions *)        (* math functions *)
# Line 281  Line 292 
292    
293        (* runtime system hooks *)        (* runtime system hooks *)
294          fun imageAddr (e, T_Image(_, rTy)) = let          fun imageAddr (e, T_Image(_, rTy)) = let
295                val cTy = CL.T_Ptr(!RN.gRealTy)                val cTy = CL.T_Ptr(CL.T_Num rTy)
296                in                in
297                  (CL.mkCast(cTy, CL.mkIndirect(e, "data")), T_Ptr rTy)                  (CL.mkCast(cTy, CL.mkIndirect(e, "data")), T_Ptr rTy)
298                end                end
# Line 329  Line 340 
340            | cons _ = raise Fail "bogus cons"            | cons _ = raise Fail "bogus cons"
341          fun getImgData ((T_Vec n, x), (e, T_Ptr rTy)) = let          fun getImgData ((T_Vec n, x), (e, T_Ptr rTy)) = let
342                val addr = Var.fresh "vp"                val addr = Var.fresh "vp"
343                fun mkLoad i = CL.mkSubscript(CL.mkVar addr, CL.mkInt(IntInf.fromInt i, CL.int32))                val needsCast = (CL.T_Num rTy <> !RN.gRealTy)
344                  fun mkLoad i = let
345                        val e = CL.mkSubscript(CL.mkVar addr, CL.mkInt(IntInf.fromInt i, CL.int32))
346                        in
347                          if needsCast then CL.mkCast(!RN.gRealTy, e) else e
348                        end
349                in [                in [
350                  CL.mkAssign(CL.mkVar addr, e),                  CL.mkDecl(CL.T_Ptr(CL.T_Num rTy), addr, SOME e),
351                  CL.mkAssign(CL.mkVar x, CL.mkApply(RN.mkVec n, List.tabulate (n, mkLoad)))                  CL.mkAssign(CL.mkVar x,
352                      CL.mkApply(RN.mkVec n, List.tabulate (n, mkLoad)))
353                ] end                ] end
354            | getImgData _ = raise Fail "bogus getImgData"            | getImgData _ = raise Fail "bogus getImgData"
355          local          local

Legend:
Removed from v.560  
changed lines
  Added in v.561

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