summaryrefslogtreecommitdiff
path: root/cparser
diff options
context:
space:
mode:
Diffstat (limited to 'cparser')
-rw-r--r--cparser/Bitfields.ml24
-rw-r--r--cparser/StructAssign.ml19
-rw-r--r--cparser/Transform.ml18
3 files changed, 20 insertions, 41 deletions
diff --git a/cparser/Bitfields.ml b/cparser/Bitfields.ml
index 5ab4eb4..ff4c0c6 100644
--- a/cparser/Bitfields.ml
+++ b/cparser/Bitfields.ml
@@ -15,8 +15,8 @@
(* Elimination of bit fields in structs *)
-(* Assumes: unblocked, simplified code.
- Preserves: unblocked, simplified code. *)
+(* Assumes: unblocked code.
+ Preserves: unblocked code. *)
open Printf
open Machine
@@ -201,26 +201,6 @@ let bitfield_assign bf carrier newval =
{edesc = EBinop(Oor, oldval_masked, newval_masked, TInt(IUInt,[]));
etyp = TInt(IUInt,[])}
-(* Detect invariant l-values *)
-
-let rec invariant_lvalue e =
- match e.edesc with
- | EVar _ -> true
- | EUnop(Oderef, {edesc = EVar _}) -> true (* to check *)
- | EUnop(Odot _, e1) -> invariant_lvalue e1
- | _ -> false
-
-(* Bind a l-value to a temporary variable if it is not invariant. *)
-
-let bind_lvalue e fn =
- if invariant_lvalue e then
- fn e
- else begin
- let tmp = new_temp (TPtr(e.etyp, [])) in
- ecomma (eassign tmp (eaddrof e))
- (fn {edesc = EUnop(Oderef, tmp); etyp = e.etyp})
- end
-
(* Transformation of operators *)
let op_for_incr_decr = function
diff --git a/cparser/StructAssign.ml b/cparser/StructAssign.ml
index a9c5091..5c989a3 100644
--- a/cparser/StructAssign.ml
+++ b/cparser/StructAssign.ml
@@ -93,25 +93,6 @@ let transf_assign env lhs rhs =
else [e_lhs; e_rhs; e_size] in
{edesc = ECall(memcpy, args); etyp = TVoid[]}
-(* Detect invariant l-values *)
-
-let rec invariant_lvalue env e =
- match e.edesc with
- | EVar _ -> true
- | EUnop(Odot _, e1) -> invariant_lvalue env e1
- | _ -> false
-
-(* Bind a l-value to a temporary variable if it is not invariant. *)
-
-let bind_lvalue env e fn =
- if invariant_lvalue env e then
- fn e
- else begin
- let tmp = new_temp (TPtr(e.etyp, [])) in
- ecomma (eassign tmp (addrof e))
- (fn {edesc = EUnop(Oderef, tmp); etyp = e.etyp})
- end
-
(* Transformation of expressions. *)
type context = Val | Effects
diff --git a/cparser/Transform.ml b/cparser/Transform.ml
index 4fd83ae..1cafaba 100644
--- a/cparser/Transform.ml
+++ b/cparser/Transform.ml
@@ -40,6 +40,24 @@ let get_temps () =
temporaries := [];
List.rev temps
+(* Bind a l-value to a temporary variable if it is not invariant. *)
+
+let rec invariant_lvalue env e =
+ match e.edesc with
+ | EVar _ -> true
+ | EUnop(Odot _, e1) -> invariant_lvalue env e1
+ | _ -> false
+
+let bind_lvalue env e fn =
+ if invariant_lvalue env e then
+ fn e
+ else begin
+ let tmp = new_temp (TPtr(e.etyp, [])) in
+ ecomma (eassign tmp (addrof e))
+ (fn {edesc = EUnop(Oderef, tmp); etyp = e.etyp})
+ end
+
+
(* Generic transformation *)
let program