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

SCM Repository

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

Diff of /branches/pure-cfg/src/compiler/codegen/clang.sml

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

revision 524, Sat Feb 12 21:11:01 2011 UTC revision 525, Sat Feb 12 22:59:18 2011 UTC
# Line 20  Line 20 
20        | T_Array of ty * int        | T_Array of ty * int
21        | T_Named of string        | T_Named of string
22    
23        val int32 = T_Num(RawTypes.RT_Int32)
24        val int64 = T_Num(RawTypes.RT_Int64)
25        val float = T_Num(RawTypes.RT_Float)
26        val double = T_Num(RawTypes.RT_Double)
27    
28      datatype decl      datatype decl
29        = D_Var of attr list * ty * var        = D_Comment of string list
30        | D_Func of attr list * ty * string * param list * block        | D_Var of attr list * ty * var
31          | D_Func of attr list * ty * string * param list * stm
32    
33      and param = PARAM of attr * ty * var      and param = PARAM of attr * ty * var
34    
     and block = BLK of stm list  
   
35      and stm      and stm
36        = S_Decl of ty * var * exp option (* ty var [ '=' exp ]';' *)        = S_Block of stm list             (* "{" stms "}" *)
37        | S_Assign of exp * exp           (* var '=' exp ';' *)        | S_Comment of string list
38        | S_If of exp * block * block     (* 'if' exp block 'else' block *)        | S_Decl of ty * var * exp option (* ty var [ '=' exp ]';' *)
39        | S_While of exp * block          (* 'while' exp block *)        | S_Assign of exp * exp           (* lvalue '=' exp ';' *)
40          | S_If of exp * stm * stm         (* 'if' exp stm 'else' stm *)
41          | S_While of exp * stm            (* 'while' exp stm *)
42        | S_Call of string * exp list        | S_Call of string * exp list
43          | S_Return of exp option          (* 'return' [ exp ] ';' *)
44    
45      and exp      and exp
46        = E_Grp of exp                    (* "(" e ")" *)        = E_Grp of exp                    (* "(" e ")" *)
# Line 42  Line 49 
49        | E_Apply of string * exp list    (* f "(" ... ")" *)        | E_Apply of string * exp list    (* f "(" ... ")" *)
50        | E_Subscript of exp * exp        (* e "[" e "]" *)        | E_Subscript of exp * exp        (* e "[" e "]" *)
51        | E_Select of exp * string        (* e "." f *)        | E_Select of exp * string        (* e "." f *)
52          | E_Indirect of exp * string      (* e "->" f *)
53        | E_Cast of ty * exp              (* "(" ty ")" e *)        | E_Cast of ty * exp              (* "(" ty ")" e *)
54        | E_Var of var        | E_Var of var
55          | E_Int of IntegerLit.integer * ty
56          | E_Flt of FloatLit.float * ty
57          | E_Bool of bool
58    
59    (* binary operators in increasing order of precedence *)    (* binary operators in increasing order of precedence *)
60      and binop      and binop
# Line 91  Line 102 
102          | prec (E_Apply _) = callP          | prec (E_Apply _) = callP
103          | prec (E_Subscript _) = postP          | prec (E_Subscript _) = postP
104          | prec (E_Select _) = postP          | prec (E_Select _) = postP
105            | prec (E_Indirect _) = postP
106          | prec (E_Cast _) = unaryP          | prec (E_Cast _) = unaryP
107          | prec (E_Var _) = atomP          | prec (E_Var _) = atomP
108            | prec (E_Int _) = atomP
109            | prec (E_Flt _) = atomP
110            | prec (E_Bool _) = atomP
111      in      in
112      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
113    (* Note that all C binary operators are left associative. *)    (* Note that all C binary operators are left associative. *)
# Line 113  Line 128 
128      fun mkSelect (e, f) = if prec e < postP      fun mkSelect (e, f) = if prec e < postP
129            then E_Select(E_Grp e, f)            then E_Select(E_Grp e, f)
130            else E_Select(e, f)            else E_Select(e, f)
131        fun mkIndirect (e, f) = if prec e < postP
132              then E_Indirect(E_Grp e, f)
133              else E_Indirect(e, f)
134      fun mkCast (ty, e) = E_Cast(ty, e)      fun mkCast (ty, e) = E_Cast(ty, e)
135      val mkVar = E_Var      val mkVar = E_Var
136        val mkInt = E_Int
137        val mkFlt = E_Flt
138        val mkBool = E_Bool
139      end (* local *)      end (* local *)
140    
141      val skip = BLK[]      val skip = S_Block[]
142    
143      local      local
144        fun paren (e as E_Grp _) = e        fun paren (e as E_Grp _) = e
145          | paren e = E_Grp e          | paren e = E_Grp e
146      in      in
147        fun mkBlock [stm] = stm
148          | mkBlock stms = S_Block stms
149        val mkAssign = S_Assign
150      fun mkIfThenElse (e, b1, b2) = S_If(paren e, b1, b2)      fun mkIfThenElse (e, b1, b2) = S_If(paren e, b1, b2)
151      fun mkIfThen (e, b) = mkIfThenElse (e, b, skip)      fun mkIfThen (e, b) = mkIfThenElse (e, b, skip)
152      fun mkWhile (e, b) = S_While(paren e, b)      fun mkWhile (e, b) = S_While(paren e, b)
153      end (* local *)      end (* local *)
154    
155      (* utility functions *)
156    
157        fun varToString x = x
158    
159        fun binopToString rator = (case rator
160               of #|| => "||"
161                | #&& => "&&"
162                | #== => "=="
163                | #!= => "!="
164                | #< => "<"
165                | #<= => "<="
166                | #>= => ">="
167                | #> => ">"
168                | #+ => "+"
169                | #- => "-"
170                | #* => "*"
171                | #/ => "/"
172                | #% => "%"
173              (* end case *))
174    
175        fun unopToString rator = (case rator
176               of %- => "-"
177                | %! => "!"
178                | %& => "&"
179                | %* => "*"
180                | %~ => "~"
181              (* end case *))
182    
183    end    end

Legend:
Removed from v.524  
changed lines
  Added in v.525

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