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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/codegen/codegen-util.sml
ViewVC logotype

View of /branches/vis15/src/compiler/codegen/codegen-util.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3897 - (download) (annotate)
Sun May 22 20:39:23 2016 UTC (3 years ago) by jhr
File size: 1306 byte(s)
working on merge: code generation
(* codegen-util.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2016 The University of Chicago
 * All rights reserved.
 *)

structure CodeGenUtil : sig

  (* is an expression "simple" (i.e., a variable or literal)? *)
    val isSimple : TreeIR.exp -> bool

  (* translate an API type to a C type suitable for external use *)
    val trAPIType : CodeGenEnv.t * APITypes.t -> CLang.ty

  end = struct

    structure IR = TreeIR
    structure CL = CLang
    structure Env = CodeGenEnv

    fun isSimple e = (case e
	   of IR.E_Global _ => true
	    | IR.E_State(NONE, _) => true
	    | IR.E_State(SOME e, _) => isSimple e
	    | IR.E_Var _ => true
	    | IR.E_Lit _ => true
	    | _ => false
	  (* end case *))

    fun trAPIType (env, ty) = (case ty
	   of APITypes.IntTy => Env.intTy env
	    | APITypes.BoolTy => Env.boolTy env
	    | APITypes.TensorTy[] => Env.realTy env
	    | APITypes.TensorTy dd => CL.T_Array(Env.realTy env, SOME(List.foldl Int.* 1 dd))
	    | APITypes.StringTy => CL.charPtr (* const?? *)
	    | APITypes.ImageTy(dim, _) => CL.T_Ptr(CL.T_Named "nrrd")
	    | APITypes.SeqTy(ty, NONE) => CL.T_Ptr(CL.T_Named "nrrd")
	    | APITypes.SeqTy(ty, SOME n) => CL.T_Array(trAPIType(env, ty), SOME n)
	  (* end case *))

  end

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