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

SCM Repository

[diderot] Diff of /branches/vis12-cl/src/compiler/codegen/clang.sml
ViewVC logotype

Diff of /branches/vis12-cl/src/compiler/codegen/clang.sml

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

revision 2693, Wed Sep 10 01:37:55 2014 UTC revision 2694, Wed Sep 10 22:55:58 2014 UTC
# Line 1  Line 1 
1  (* clang.sml  (* clang.sml
2   *   *
3   * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2014 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * 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, CUDA,
# Line 56  Line 56 
56    
57      and initializer      and initializer
58        = I_Exp of exp        = I_Exp of exp
59        | I_Struct of (string * initializer) list        | I_Exps of initializer list
60        | I_Array of (int * initializer) list        | I_Struct of (string * initializer) list (* C99 labeled struct initializer *)
61          | I_Array of (int * initializer) list     (* C99 labeled array initializer *)
62    
63      and param = PARAM of attr list * ty * var      and param = PARAM of attr list * ty * var
64    
# Line 73  Line 74 
74        | S_DoWhile of stm * exp          (* 'do' stm 'while' exp *)        | S_DoWhile of stm * exp          (* 'do' stm 'while' exp *)
75        | S_For of (ty * var * exp) list * exp * exp list * stm        | S_For of (ty * var * exp) list * exp * exp list * stm
76                                          (* 'for' '(' inits ';' exp ';' incrs ')' stm *)                                          (* 'for' '(' inits ';' exp ';' incrs ')' stm *)
       | S_Call of string * exp list     (* func '(' args ')' *)  
77        | S_Return of exp option          (* 'return' [ exp ] ';' *)        | S_Return of exp option          (* 'return' [ exp ] ';' *)
78        | S_Break                         (* 'break' ';' *)        | S_Break                         (* 'break' ';' *)
79        | S_Continue                      (* 'continue' ';' *)        | S_Continue                      (* 'continue' ';' *)
# Line 85  Line 85 
85        | E_BinOp of exp * binop * exp    (* e op e *)        | E_BinOp of exp * binop * exp    (* e op e *)
86        | E_UnOp of unop * exp            (* op e *)        | E_UnOp of unop * exp            (* op e *)
87        | E_PostOp of exp * postfix       (* e op *)        | E_PostOp of exp * postfix       (* e op *)
88        | E_Apply of string * exp list    (* f "(" ... ")" *)        | E_Apply of exp * exp list       (* f "(" ... ")" *)
89        | E_Subscript of exp * exp        (* e "[" e "]" *)        | E_Subscript of exp * exp        (* e "[" e "]" *)
90        | E_Select of exp * string        (* e "." f *)        | E_Select of exp * string        (* e "." f *)
91        | E_Indirect of exp * string      (* e "->" f *)        | E_Indirect of exp * string      (* e "->" f *)
# Line 95  Line 95 
95        | E_Flt of FloatLit.float * ty        | E_Flt of FloatLit.float * ty
96        | E_Bool of bool        | E_Bool of bool
97        | E_Str of string        | E_Str of string
98          | E_Char of char
99        | E_Sizeof of ty                  (* "sizeof(" ty ")" *)        | E_Sizeof of ty                  (* "sizeof(" ty ")" *)
100    
101    (* assignment operators *)    (* assignment operators *)
# Line 169  Line 170 
170          | prec (E_Flt _) = atomP          | prec (E_Flt _) = atomP
171          | prec (E_Bool _) = atomP          | prec (E_Bool _) = atomP
172          | prec (E_Str _) = atomP          | prec (E_Str _) = atomP
173            | prec (E_Char _) = atomP
174          | prec (E_Sizeof _) = callP          | prec (E_Sizeof _) = callP
175      in      in
176      fun mkGrp e = if (prec e < atomP) then E_Grp e else e      fun mkGrp e = if (prec e < atomP) then E_Grp e else e
# Line 209  Line 211 
211      fun mkPostOp (e, rator) = if prec e < postP      fun mkPostOp (e, rator) = if prec e < postP
212            then E_PostOp(E_Grp e, rator)            then E_PostOp(E_Grp e, rator)
213            else E_PostOp(e, rator)            else E_PostOp(e, rator)
214      fun mkApply (f, args) = E_Apply(f, args)      fun mkApply (f, args) = E_Apply(E_Var f, args)
215        fun mkApplyExp (e, args) = E_Apply(e, args)
216      fun mkSubscript(e1, e2) = if prec e1 < postP      fun mkSubscript(e1, e2) = if prec e1 < postP
217            then E_Subscript(E_Grp e1, e2)            then E_Subscript(E_Grp e1, e2)
218            else E_Subscript(e1, e2)            else E_Subscript(e1, e2)
# Line 230  Line 233 
233            else E_Flt(f, ty)            else E_Flt(f, ty)
234      val mkBool = E_Bool      val mkBool = E_Bool
235      val mkStr = E_Str      val mkStr = E_Str
236        val mkChar = E_Char
237      val mkSizeof = E_Sizeof      val mkSizeof = E_Sizeof
238        fun mkAddrOf x = mkUnOp(%&, x)
239      end (* local *)      end (* local *)
240    
241      val skip = S_Block[]      val skip = S_Block[]
# Line 246  Line 251 
251        | unBlock stm = [stm]        | unBlock stm = [stm]
252      fun prependStm (stm, blk) = mkBlock(stm :: unBlock blk)      fun prependStm (stm, blk) = mkBlock(stm :: unBlock blk)
253      fun appendStm (blk, stm) = mkBlock(unBlock blk @ [stm])      fun appendStm (blk, stm) = mkBlock(unBlock blk @ [stm])
254        fun concatBlocks blocks = mkBlock(List.concat(List.map unBlock blocks))
255      fun mkDecl (ty, x, init) = S_Decl([], ty, x, init)      fun mkDecl (ty, x, init) = S_Decl([], ty, x, init)
256      fun mkDeclInit (ty, x, init) = S_Decl([], ty, x, SOME(I_Exp init))      fun mkDeclInit (ty, x, init) = S_Decl([], ty, x, SOME(I_Exp init))
257      val mkAttrDecl = S_Decl      val mkAttrDecl = S_Decl
258      val mkExpStm = S_Exp      val mkExpStm = S_Exp
259      fun mkAssign (e1, e2) = S_Exp(mkAssignOp(e1, $=, e2))      fun mkAssign (e1, e2) = S_Exp(mkAssignOp(e1, $=, e2))
260        fun mkAssign' (e1, rator, e2) = S_Exp(mkAssignOp(e1, rator, e2))
261      fun mkIfThenElse (e, b1, b2) = S_If(paren e, b1, b2)      fun mkIfThenElse (e, b1, b2) = S_If(paren e, b1, b2)
262      fun mkIfThen (e, b) = mkIfThenElse (e, b, skip)      fun mkIfThen (e, b) = mkIfThenElse (e, b, skip)
263      val mkFor = S_For      val mkFor = S_For
264      fun mkWhile (e, b) = S_While(paren e, b)      fun mkWhile (e, b) = S_While(paren e, b)
265      fun mkDoWhile (b, e) = S_DoWhile(b, paren e)      fun mkDoWhile (b, e) = S_DoWhile(b, paren e)
266      val mkCall = S_Call      fun mkCall (f, args) = S_Exp(mkApply(f, args))
267        fun mkCallExp (f, args) = S_Exp(mkApplyExp(f, args))
268      val mkReturn = S_Return      val mkReturn = S_Return
269      val mkBreak = S_Break      val mkBreak = S_Break
270      val mkContinue = S_Continue      val mkContinue = S_Continue
# Line 370  Line 378 
378                  | E_BinOp(e1, rator, e2) => e2s(e1, binopToString rator :: e2s(e2, l))                  | E_BinOp(e1, rator, e2) => e2s(e1, binopToString rator :: e2s(e2, l))
379                  | E_UnOp(rator, e) => unopToString rator :: e2s(e, l)                  | E_UnOp(rator, e) => unopToString rator :: e2s(e, l)
380                  | E_PostOp(e, rator) => e2s(e, postopToString rator :: l)                  | E_PostOp(e, rator) => e2s(e, postopToString rator :: l)
381                  | E_Apply(f, es) => let                  | E_Apply(e, es) => let
382                      fun args2s ([], l) = l                      fun args2s ([], l) = l
383                        | args2s ([e], l) = e2s(e, l)                        | args2s ([e], l) = e2s(e, l)
384                        | args2s (e::es, l) = e2s(e, ","::args2s(es, l))                        | args2s (e::es, l) = e2s(e, ","::args2s(es, l))
385                      in                      in
386                        f :: "(" :: args2s(es, ")"::l)                        e2s(e, "(" :: args2s(es, ")"::l))
387                      end                      end
388                  | E_Subscript(e1, e2) => e2s(e1, "[" :: e2s(e2, "]"::l))                  | E_Subscript(e1, e2) => e2s(e1, "[" :: e2s(e2, "]"::l))
389                  | E_Select(e, f) => e2s(e, "." :: f :: l)                  | E_Select(e, f) => e2s(e, "." :: f :: l)
# Line 385  Line 393 
393                  | E_Int(n, _) => IntegerLit.toString n :: l                  | E_Int(n, _) => IntegerLit.toString n :: l
394                  | E_Flt(f, _) => FloatLit.toString f :: l                  | E_Flt(f, _) => FloatLit.toString f :: l
395                  | E_Bool b => Bool.toString b :: l                  | E_Bool b => Bool.toString b :: l
396                  | E_Str s => concat["\"", String.toCString s, "\""] :: l                  | E_Str s => "\"" :: String.toCString s :: "\"" :: l
397                    | E_Char c => "'" :: Char.toCString c :: "'" :: l
398                  | E_Sizeof ty => "sizeof(ty)" :: l                  | E_Sizeof ty => "sizeof(ty)" :: l
399                (* end case *))                (* end case *))
400            in            in

Legend:
Removed from v.2693  
changed lines
  Added in v.2694

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