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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/codegen/clang.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/codegen/clang.sml

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

revision 3768, Mon Apr 18 22:20:53 2016 UTC revision 3769, Mon Apr 25 12:52:40 2016 UTC
# Line 5  Line 5 
5   * COPYRIGHT (c) 2015 The University of Chicago   * COPYRIGHT (c) 2015 The University of Chicago
6   * All rights reserved.   * All rights reserved.
7   *   *
8   * An tree representation of programs in a C-like language (e.g., C, CUDA,   * An tree representation of programs in a C-like language (e.g., C, C++, CUDA,
9   * or OpenCL).  The purpose of this code is to commonality between the various   * or OpenCL).
  * backends, which are all generating C-like code.  
10   *)   *)
11    
12  structure CLang =  structure CLang =
# Line 19  Line 18 
18      datatype ty      datatype ty
19        = T_Num of RawTypes.ty        = T_Num of RawTypes.ty
20        | T_Ptr of ty        | T_Ptr of ty
21          | T_RestrictPtr of ty     (* pointer type with "restrict" annotation *)
22        | T_Array of ty * int option        | T_Array of ty * int option
23        | T_Named of string        | T_Named of string
24          | T_Template of string * ty list
25        | T_Qual of attr * ty     (* qualified type *)        | T_Qual of attr * ty     (* qualified type *)
26    
27      datatype typed_var = V of ty * var      datatype typed_var = V of ty * var
# Line 61  Line 62 
62        | I_Exps of initializer list        | I_Exps of initializer list
63        | I_Struct of (string * initializer) list (* C99 labeled struct initializer *)        | I_Struct of (string * initializer) list (* C99 labeled struct initializer *)
64        | I_Array of (int * initializer) list     (* C99 labeled array initializer *)        | I_Array of (int * initializer) list     (* C99 labeled array initializer *)
65          | I_Cons of ty * exp list
66    
67      and param = PARAM of attr list * ty * var      and param = PARAM of attr list * ty * var
68    
# Line 76  Line 78 
78        | S_DoWhile of stm * exp          (* 'do' stm 'while' exp *)        | S_DoWhile of stm * exp          (* 'do' stm 'while' exp *)
79        | S_For of (ty * var * exp) list * exp * exp list * stm        | S_For of (ty * var * exp) list * exp * exp list * stm
80                                          (* 'for' '(' inits ';' exp ';' incrs ')' stm *)                                          (* 'for' '(' inits ';' exp ';' incrs ')' stm *)
81          | S_KernCall of string * exp list * exp list
82                                            (* f "<<<" ... ">>>" "(" ... ")" [CUDA] *)
83        | S_Return of exp option          (* 'return' [ exp ] ';' *)        | S_Return of exp option          (* 'return' [ exp ] ';' *)
84        | S_Break                         (* 'break' ';' *)        | S_Break                         (* 'break' ';' *)
85        | S_Continue                      (* 'continue' ';' *)        | S_Continue                      (* 'continue' ';' *)
# Line 88  Line 92 
92        | E_UnOp of unop * exp            (* op e *)        | E_UnOp of unop * exp            (* op e *)
93        | E_PostOp of exp * postfix       (* e op *)        | E_PostOp of exp * postfix       (* e op *)
94        | E_Apply of exp * exp list       (* f "(" ... ")" *)        | E_Apply of exp * exp list       (* f "(" ... ")" *)
95          | E_Cons of ty * exp list         (* ty "(" ... ")" [C++,CUDA]*)
96          | E_New of ty * exp list          (* "new" ty "(" ... ")" [C++,CUDA]*)
97        | E_Subscript of exp * exp        (* e "[" e "]" *)        | E_Subscript of exp * exp        (* e "[" e "]" *)
98        | E_Select of exp * string        (* e "." f *)        | E_Select of exp * string        (* e "." f *)
99        | E_Indirect of exp * string      (* e "->" f *)        | E_Indirect of exp * string      (* e "->" f *)
100        | E_Cast of ty * exp              (* "(" ty ")" e *)        | E_Cast of ty * exp              (* "(" ty ")" e *)
101        | E_Vec of ty * exp list          (* vector construction; syntax depends on target *)        | E_Vec of ty * exp list          (* vector-expression; syntax depends on target [C,OpenCL] *)
102        | E_Var of var        | E_Var of var
103        | E_Int of IntegerLit.integer * ty        | E_Int of IntLit.t * ty
104        | E_Flt of FloatLit.float * ty        | E_Flt of RealLit.t * ty
105        | E_Bool of bool        | E_Bool of bool
106        | E_Str of string        | E_Str of string
107        | E_Char of char        | E_Char of char
# Line 164  Line 170 
170          | prec (E_UnOp _) = preP          | prec (E_UnOp _) = preP
171          | prec (E_PostOp _) = postP          | prec (E_PostOp _) = postP
172          | prec (E_Apply _) = callP          | prec (E_Apply _) = callP
173            | prec (E_Cons _) = callP (* check this *)
174            | prec (E_New _) = callP (* check this *)
175          | prec (E_Subscript _) = postP          | prec (E_Subscript _) = postP
176          | prec (E_Select _) = postP          | prec (E_Select _) = postP
177          | prec (E_Indirect _) = postP          | prec (E_Indirect _) = postP
# Line 216  Line 224 
224            then E_PostOp(E_Grp e, rator)            then E_PostOp(E_Grp e, rator)
225            else E_PostOp(e, rator)            else E_PostOp(e, rator)
226      fun mkApply (f, args) = E_Apply(E_Var f, args)      fun mkApply (f, args) = E_Apply(E_Var f, args)
227    (* FIXME: check precedence *)
228      fun mkApplyExp (e, args) = E_Apply(e, args)      fun mkApplyExp (e, args) = E_Apply(e, args)
229        val mkCons = E_Cons
230        val mkNew = E_New
231      fun mkSubscript(e1, e2) = if prec e1 < postP      fun mkSubscript(e1, e2) = if prec e1 < postP
232            then E_Subscript(E_Grp e1, e2)            then E_Subscript(E_Grp e1, e2)
233            else E_Subscript(e1, e2)            else E_Subscript(e1, e2)
# Line 233  Line 244 
244      val mkVar = E_Var      val mkVar = E_Var
245      fun mkIntTy (n, ty) = if n < 0 then E_UnOp(%-, E_Int(~n, ty)) else E_Int(n, ty)      fun mkIntTy (n, ty) = if n < 0 then E_UnOp(%-, E_Int(~n, ty)) else E_Int(n, ty)
246      fun mkInt n = mkIntTy(n, intTy)      fun mkInt n = mkIntTy(n, intTy)
247      fun mkFlt (f, ty) = if FloatLit.isNeg f      fun mkFlt (f, ty) = if RealLit.isNeg f
248            then E_UnOp(%-, E_Flt(FloatLit.negate f, ty))            then E_UnOp(%-, E_Flt(RealLit.negate f, ty))
249            else E_Flt(f, ty)            else E_Flt(f, ty)
250      val mkBool = E_Bool      val mkBool = E_Bool
251      val mkStr = E_Str      val mkStr = E_Str
# Line 270  Line 281 
281      fun mkDoWhile (b, e) = S_DoWhile(b, paren e)      fun mkDoWhile (b, e) = S_DoWhile(b, paren e)
282      fun mkCall (f, args) = S_Exp(mkApply(f, args))      fun mkCall (f, args) = S_Exp(mkApply(f, args))
283      fun mkCallExp (f, args) = S_Exp(mkApplyExp(f, args))      fun mkCallExp (f, args) = S_Exp(mkApplyExp(f, args))
284        val mkKernCall = S_KernCall
285      val mkReturn = S_Return      val mkReturn = S_Return
286      val mkBreak = S_Break      val mkBreak = S_Break
287      val mkContinue = S_Continue      val mkContinue = S_Continue
# Line 384  Line 396 
396                  | E_UnOp(rator, e) => unopToString rator :: e2s(e, l)                  | E_UnOp(rator, e) => unopToString rator :: e2s(e, l)
397                  | E_PostOp(e, rator) => e2s(e, postopToString rator :: l)                  | E_PostOp(e, rator) => e2s(e, postopToString rator :: l)
398                  | E_Apply(e, es) => e2s(e, "(" :: args2s(es, ")"::l))                  | E_Apply(e, es) => e2s(e, "(" :: args2s(es, ")"::l))
399                    | E_Cons(ty, es) => e2s(e, "ty(" :: args2s(es, ")"::l))
400                    | E_New(ty, es) => e2s(e, "new ty (" :: args2s(es, ")"::l))
401                  | E_Subscript(e1, e2) => e2s(e1, "[" :: e2s(e2, "]"::l))                  | E_Subscript(e1, e2) => e2s(e1, "[" :: e2s(e2, "]"::l))
402                  | E_Select(e, f) => e2s(e, "." :: f :: l)                  | E_Select(e, f) => e2s(e, "." :: f :: l)
403                  | E_Indirect(e, f) => e2s(e, "->" :: f :: l)                  | E_Indirect(e, f) => e2s(e, "->" :: f :: l)
404                  | E_Cast(ty, e) => "(ty)" :: e2s(e, l)  (* FIXME: need tyToString *)                  | E_Cast(ty, e) => "(ty)" :: e2s(e, l)  (* FIXME: need tyToString *)
405                  | E_Vec(ty, args) => "(vec)(" :: args2s(args, ")"::l)  (* FIXME: need tyToString *)                  | E_Vec(ty, args) => "(vec)(" :: args2s(args, ")"::l)  (* FIXME: need tyToString *)
406                  | E_Var x => x::l                  | E_Var x => x::l
407                  | E_Int(n, _) => IntegerLit.toString n :: l                  | E_Int(n, _) => IntLit.toString n :: l
408                  | E_Flt(f, _) => FloatLit.toString f :: l                  | E_Flt(f, _) => RealLit.toString f :: l
409                  | E_Bool b => Bool.toString b :: l                  | E_Bool b => Bool.toString b :: l
410                  | E_Str s => "\"" :: String.toCString s :: "\"" :: l                  | E_Str s => "\"" :: String.toCString s :: "\"" :: l
411                  | E_Char c => "'" :: Char.toCString c :: "'" :: l                  | E_Char c => "'" :: Char.toCString c :: "'" :: l

Legend:
Removed from v.3768  
changed lines
  Added in v.3769

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