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/tree-to-cxx.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/cxx-util/tree-to-cxx.sml

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

revision 3900, Mon May 23 15:20:24 2016 UTC revision 3922, Wed Jun 1 17:02:34 2016 UTC
# Line 27  Line 27 
27    (* generate code to register an error message (require that a world pointer "wrld" is in scope) *)    (* generate code to register an error message (require that a world pointer "wrld" is in scope) *)
28      val errorMsgAdd : CLang.exp -> CLang.stm      val errorMsgAdd : CLang.exp -> CLang.stm
29    
30        val trParam : CodeGenEnv.t -> TreeIR.var -> CLang.param
31    
32    end = struct    end = struct
33    
34      structure CL = CLang      structure CL = CLang
# Line 35  Line 37 
37      structure Ty = TreeTypes      structure Ty = TreeTypes
38      structure V = TreeVar      structure V = TreeVar
39      structure Env = CodeGenEnv      structure Env = CodeGenEnv
40        structure RN = CxxNames
41    
42      fun trType (env, ty) = (case ty      fun trType (env, ty) = (case ty
43             of Ty.BoolTy => CL.boolTy             of Ty.BoolTy => CL.boolTy
# Line 131  Line 134 
134              | (Op.VScale d, [a, b]) => CL.mkApply("vscale", [a, b])              | (Op.VScale d, [a, b]) => CL.mkApply("vscale", [a, b])
135              | (Op.VMul d, [a, b]) => CL.mkBinOp(a, CL.#*, b)              | (Op.VMul d, [a, b]) => CL.mkBinOp(a, CL.#*, b)
136              | (Op.VNeg d, [a]) => CL.mkUnOp(CL.%-, a)              | (Op.VNeg d, [a]) => CL.mkUnOp(CL.%-, a)
137              | (Op.VSum d, [a]) => CL.mkApply("vsum", [a])              | (Op.VSum(w, _), [a]) => CL.mkApply(RN.vsum w, [a])
138              | (Op.VIndex(w, p, i), [a]) => CL.mkSubscript(a, intExp i)              | (Op.VIndex(w, p, i), [a]) => CL.mkSubscript(a, intExp i)
139              | (Op.VClamp d, [a, b, c]) => CL.mkApply("vclamp", [a, b, c])              | (Op.VClamp(w, _), [a, b, c]) => CL.mkApply("vclamp", [a, b, c])
140              | (Op.VMapClamp d, [a, b, c]) => CL.mkApply("vclamp", [a, b, c])              | (Op.VMapClamp(w, _), [a, b, c]) => CL.mkApply("vclamp", [a, b, c])
141              | (Op.VLerp d, [a, b, c]) => CL.mkApply("vlerp", [a, b, c])              | (Op.VLerp(w, _), [a, b, c]) => CL.mkApply("vlerp", [a, b, c])
142              | (Op.VCeiling d, [a]) => CL.mkApply("vceiling", [a])              | (Op.VCeiling d, [a]) => CL.mkApply("vceiling", [a])
143              | (Op.VFloor d, [a]) => CL.mkApply("vfloor", [a])              | (Op.VFloor d, [a]) => CL.mkApply("vfloor", [a])
144              | (Op.VRound d, [a]) => CL.mkApply("vround", [a])              | (Op.VRound d, [a]) => CL.mkApply("vround", [a])
# Line 208  Line 211 
211              | IR.E_Lit(Literal.Real f) => CL.mkFlt(f, Env.realTy env)              | IR.E_Lit(Literal.Real f) => CL.mkFlt(f, Env.realTy env)
212              | IR.E_Lit(Literal.String s) => CL.mkStr s              | IR.E_Lit(Literal.String s) => CL.mkStr s
213              | IR.E_Op(rator, args) => trOp (env, rator, trExps(env, args))              | IR.E_Op(rator, args) => trOp (env, rator, trExps(env, args))
214              | IR.E_Vec(w, pw, args) => let              | IR.E_Vec(w, pw, args) => CL.mkApply(RN.vcons w, trExps (env, args))
                 val args = trExps (env, args)  
                 val args = if (w < pw) then args @ List.tabulate(pw-w, fn _ => zero) else args  
                 in  
                   CL.mkVec(CL.T_Named("vec" ^ Int.toString pw), args)  
                 end  
215              | IR.E_Cons(args, Ty.TensorTy shape) => raise Fail "unexpected E_Cons"              | IR.E_Cons(args, Ty.TensorTy shape) => raise Fail "unexpected E_Cons"
216              | IR.E_Seq(args, ty) => raise Fail "unexpected E_Seq"              | IR.E_Seq(args, ty) => raise Fail "unexpected E_Seq"
217              | IR.E_Pack(layout, args) => raise Fail "unexpected E_Pack"              | IR.E_Pack(layout, args) => raise Fail "unexpected E_Pack"
218  (* FIXME: check if e is aligned and use "vload_aligned" in that case *)  (* FIXME: check if e is aligned and use "vload_aligned" in that case *)
219              | IR.E_VLoad(layout, e, i) =>              | IR.E_VLoad(layout, e, i) =>
220                  CL.mkTemplateApply("vload",                  CL.mkApply(RN.vload(Ty.nthWidth(layout, i)),
                   [trType(env, Ty.nthVec(layout, i))],  
221                    [CL.mkBinOp(trExp(env, e), CL.#+, intExp(Ty.offsetOf(layout, i)))])                    [CL.mkBinOp(trExp(env, e), CL.#+, intExp(Ty.offsetOf(layout, i)))])
222              | _ => raise Fail "trExp"              | _ => raise Fail "trExp"
223            (* end case *))            (* end case *))
# Line 268  Line 265 
265            (* end case *))            (* end case *))
266        | trMultiAssign (env, lhs, rhs) = raise Fail "bogus multi-assignment"        | trMultiAssign (env, lhs, rhs) = raise Fail "bogus multi-assignment"
267    
268        fun trPrintStm (outS, tys, args) = let
269              fun mkExp (lhs, [], []) = CL.mkBinOp(lhs, CL.#<<, CL.mkVar "std::end")
270                | mkExp (lhs, ty::tys, e::es) = let
271                  (* if necessary, wrap the argument so that the correct "<<" instance is used *)
272                    val e = (case ty
273                           of Ty.TensorTy shape => CL.mkApply(RN.tensorStruct shape, [e])
274                            | _ => e
275                          (* end case *))
276                    in
277                      mkExp (CL.mkBinOp(lhs, CL.#<<, e), tys, es)
278                    end
279                | mkExp _ = raise Fail "trPrintStm: arity mismatch"
280              in
281                CL.mkExpStm (mkExp (outS, tys, args))
282              end
283    
284      fun trStms (env, stms : TreeIR.stm list) = let      fun trStms (env, stms : TreeIR.stm list) = let
285            fun trStm (stm, (env, stms : CL.stm list)) = (case stm            fun trStm (stm, (env, stms : CL.stm list)) = (case stm
286                   of IR.S_Comment text => (env, CL.mkComment text :: stms)                   of IR.S_Comment text => (env, CL.mkComment text :: stms)
# Line 316  Line 329 
329                        end                        end
330                    | IR.S_Foreach(x, e, blk) => raise Fail "Foreach"                    | IR.S_Foreach(x, e, blk) => raise Fail "Foreach"
331                    | IR.S_New(strand, args) => raise Fail "New"                    | IR.S_New(strand, args) => raise Fail "New"
332                    | IR.S_Save(x, exp) => (env, trAssign (env, lvalueStateVar(env, x), exp))                    | IR.S_Save(x, exp) => (env, trAssign (env, lvalueStateVar(env, x), exp) @ stms)
333                    | IR.S_LoadNrrd(lhs, ty, nrrd) => let                    | IR.S_LoadNrrd(lhs, ty, nrrd) => let
334                        val stm = (case ty                        val stm = (case ty
335                               of APITypes.SeqTy(ty, NONE) =>                               of APITypes.SeqTy(ty, NONE) =>
# Line 337  Line 350 
350                    | IR.S_Exit => (env, stms)                    | IR.S_Exit => (env, stms)
351                    | IR.S_Print(tys, args) => let                    | IR.S_Print(tys, args) => let
352                        val args = List.map (fn e => trExp(env, e)) args                        val args = List.map (fn e => trExp(env, e)) args
353                        val stm = GenPrint.genPrintStm (                        val stm = trPrintStm (
354                              CL.mkIndirect(CL.mkVar "wrld", "_output"),                              CL.mkIndirect(CL.mkVar "wrld", "_output"),
355                              tys, args)                              tys, args)
356                        in                        in
# Line 366  Line 379 
379      fun errorMsgAdd msg =      fun errorMsgAdd msg =
380            CL.mkCall("biffMsgAdd", [CL.mkIndirect(CL.mkVar "wrld", "_errors"), msg])            CL.mkCall("biffMsgAdd", [CL.mkIndirect(CL.mkVar "wrld", "_errors"), msg])
381    
382        fun trParam env x = let
383              val x' = V.name x
384              in
385                Env.insert (env, x, x');
386                CL.PARAM([], trType(env, V.ty x), x')
387              end
388    
389    end    end

Legend:
Removed from v.3900  
changed lines
  Added in v.3922

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