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

SCM Repository

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

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

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

revision 1639, Wed Nov 16 01:48:07 2011 UTC revision 1640, Wed Nov 16 02:19:51 2011 UTC
# Line 72  Line 72 
72      and exp      and exp
73        = E_Grp of exp                    (* "(" e ")" *)        = E_Grp of exp                    (* "(" e ")" *)
74        | E_AssignOp of exp * assignop * exp (* lvalue op= e *)        | E_AssignOp of exp * assignop * exp (* lvalue op= e *)
75          | E_Cond of exp * exp * exp       (* e "?" e ":" e *)
76        | E_BinOp of exp * binop * exp    (* e op e *)        | E_BinOp of exp * binop * exp    (* e op e *)
77        | E_UnOp of unop * exp            (* op e *)        | E_UnOp of unop * exp            (* op e *)
78        | E_PostOp of exp * postfix       (* e op *)        | E_PostOp of exp * postfix       (* e op *)
# Line 145  Line 146 
146              (* end case *))              (* end case *))
147        fun prec (E_Grp _) = atomP        fun prec (E_Grp _) = atomP
148          | prec (E_AssignOp _) = assignP          | prec (E_AssignOp _) = assignP
149            | prec (E_Cond _) = condP
150          | prec (E_BinOp(_, rator, _)) = precOfBinop rator          | prec (E_BinOp(_, rator, _)) = precOfBinop rator
151          | prec (E_UnOp _) = preP          | prec (E_UnOp _) = preP
152          | prec (E_PostOp _) = postP          | prec (E_PostOp _) = postP
# Line 167  Line 169 
169            in            in
170              E_AssignOp(e1', rator, e2')              E_AssignOp(e1', rator, e2')
171            end            end
172      (* note that we over-parenthesize here, but it makes nested conditionals easeier to read *)
173        fun mkCond (e1, e2, e3) = E_Cond(
174              if prec e1 <= condP then E_Grp e1 else e1,
175              if prec e2 <= condP then E_Grp e2 else e2,
176              if prec e3 < condP then E_Grp e3 else e3)
177    (* Note that all C binary operators are left associative. *)    (* Note that all C binary operators are left associative. *)
178      fun mkBinOp (e1, #-, e2 as E_UnOp(%-, _)) = let      fun mkBinOp (e1, #-, e2 as E_UnOp(%-, _)) = let
179            val e1' = if prec e1 < addP then E_Grp e1 else e1            val e1' = if prec e1 < addP then E_Grp e1 else e1
# Line 292  Line 299 
299              | ^-- => "--"              | ^-- => "--"
300            (* end case *))            (* end case *))
301    
302      (* generate verbatim text from a template string by substituting for placeholders
303       * Placeholders have the syntax @<id>@ and are replaced with the string associated
304       * with <id> in the list of substitutions.  If <id> is empty, then no substitution
305       * is applied, instead the "@@" is replaced by "@".
306       *)
307        local
308          structure SS = Substring
309        in
310        fun verbatim sl subs = let
311              fun scan (start, ss, n, frags) = (case SS.getc ss
312                     of SOME(#"@", rest) => let
313                          val frags = SS.slice(start, 0, SOME n) :: frags
314                          val (expansion, rest) = scanPlaceholder rest
315                          in
316                            scan (rest, rest, 0, expansion::frags)
317                          end
318                      | SOME(_, rest) => scan (start, rest, n+1, frags)
319                      | NONE => SS.concat(List.rev(start::frags))
320                    (* end case *))
321              and scanPlaceholder start = let
322                    fun scan (ss, n) = (case SS.getc ss
323                           of NONE => raise Fail "incomplete placeholder"
324                            | SOME(#"@", rest) => (SS.string(SS.slice(start, 0, SOME n)), rest)
325                            | SOME(_, rest) => scan (rest, n+1)
326                          (* end case *))
327                    val (placeholder, rest) = scan (start, 0)
328                    in
329                      if (placeholder = "")
330                        then (SS.full "@", rest)
331                        else (case List.find (fn (s, _) => (s = placeholder)) subs
332                           of SOME(_, expansion) => (SS.full expansion, rest)
333                            | NONE => raise Fail(concat["unknown placeholder @", placeholder, "@"])
334                          (* end case *))
335                    end
336              fun expand s = let
337                    val ss = SS.full s
338                    in
339                      scan (ss, ss, 0, [])
340                    end
341              in
342                D_Verbatim(List.map expand sl)
343              end
344        end (* local *)
345    
346    (* for debugging (not syntactically correct!) *)    (* for debugging (not syntactically correct!) *)
347      fun expToString e = let      fun expToString e = let
348            fun e2s (e, l) = (case e            fun e2s (e, l) = (case e

Legend:
Removed from v.1639  
changed lines
  Added in v.1640

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