aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Transform.ml
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2015-04-28 11:21:59 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2015-04-28 11:21:59 +0200
commitb04bb783badb9051c62b26fb1858f916d0e4ccd0 (patch)
treec102a6ccdcfad8b4b3a76cffc2019742232a7cb3 /cparser/Transform.ml
parent3c6f5343e0e64b273658b6b3508a8dd6c29b8cef (diff)
downloadcompcert-kvx-b04bb783badb9051c62b26fb1858f916d0e4ccd0.tar.gz
compcert-kvx-b04bb783badb9051c62b26fb1858f916d0e4ccd0.zip
Extended inline asm: handle missing cases.
Bitfields: better translation of initializers and compound literals; run this pass before unblocking. Transform.stmt: extend with ability to treat unblocked code. test/regression: more bitfield tests.
Diffstat (limited to 'cparser/Transform.ml')
-rw-r--r--cparser/Transform.ml33
1 files changed, 21 insertions, 12 deletions
diff --git a/cparser/Transform.ml b/cparser/Transform.ml
index 3b6f10f6..6cdd8a6b 100644
--- a/cparser/Transform.ml
+++ b/cparser/Transform.ml
@@ -138,37 +138,46 @@ let expand_postincrdecr ~read ~write env ctx op l =
ecomma (eassign tmp (read l)) (ecomma (write l newval) tmp))
(* Generic transformation of a statement, transforming expressions within
- and preserving the statement structure. Applies only to unblocked code. *)
+ and preserving the statement structure.
+ If [decl] is not given, it applies only to unblocked code. *)
-let stmt trexpr env s =
+let stmt ~expr ?(decl = fun env decl -> assert false) env s =
let rec stm s =
match s.sdesc with
| Sskip -> s
| Sdo e ->
- {s with sdesc = Sdo(trexpr s.sloc env Effects e)}
+ {s with sdesc = Sdo(expr s.sloc env Effects e)}
| Sseq(s1, s2) ->
{s with sdesc = Sseq(stm s1, stm s2)}
| Sif(e, s1, s2) ->
- {s with sdesc = Sif(trexpr s.sloc env Val e, stm s1, stm s2)}
+ {s with sdesc = Sif(expr s.sloc env Val e, stm s1, stm s2)}
| Swhile(e, s1) ->
- {s with sdesc = Swhile(trexpr s.sloc env Val e, stm s1)}
+ {s with sdesc = Swhile(expr s.sloc env Val e, stm s1)}
| Sdowhile(s1, e) ->
- {s with sdesc = Sdowhile(stm s1, trexpr s.sloc env Val e)}
+ {s with sdesc = Sdowhile(stm s1, expr s.sloc env Val e)}
| Sfor(s1, e, s2, s3) ->
- {s with sdesc = Sfor(stm s1, trexpr s.sloc env Val e, stm s2, stm s3)}
+ {s with sdesc = Sfor(stm s1, expr s.sloc env Val e, stm s2, stm s3)}
| Sbreak -> s
| Scontinue -> s
| Sswitch(e, s1) ->
- {s with sdesc = Sswitch(trexpr s.sloc env Val e, stm s1)}
+ {s with sdesc = Sswitch(expr s.sloc env Val e, stm s1)}
| Slabeled(lbl, s) ->
{s with sdesc = Slabeled(lbl, stm s)}
| Sgoto lbl -> s
| Sreturn None -> s
| Sreturn (Some e) ->
- {s with sdesc = Sreturn(Some(trexpr s.sloc env Val e))}
- | Sasm _ -> s
- | Sblock _ | Sdecl _ ->
- assert false (* should not occur in unblocked code *)
+ {s with sdesc = Sreturn(Some(expr s.sloc env Val e))}
+ | Sasm(attr, template, outputs, inputs, clob) ->
+ let asm_operand (lbl, cstr, e) =
+ (lbl, cstr, expr s.sloc env Val e) in
+ {s with sdesc = Sasm(attr, template,
+ List.map asm_operand outputs,
+ List.map asm_operand inputs, clob)}
+ | Sblock sl ->
+ {s with sdesc = Sblock (List.map stm sl)}
+ | Sdecl d ->
+ {s with sdesc = Sdecl (decl env d)}
+
in stm s
(* Generic transformation of a function definition *)