cArithmetic_trans: simplification

Reviewed By: ngorogiannis

Differential Revision: D8026689

fbshipit-source-id: 3cbec03
master
Mehdi Bouaziz 7 years ago committed by Facebook Github Bot
parent 575fd04a6e
commit 6c58614f40

@ -17,44 +17,34 @@ module L = Logging
(* "instructions" is not empty when the binary operator is actually a statement like an *) (* "instructions" is not empty when the binary operator is actually a statement like an *)
(* assignment. *) (* assignment. *)
let compound_assignment_binary_operation_instruction boi_kind (e1, t1) typ e2 loc = let compound_assignment_binary_operation_instruction boi_kind (e1, t1) typ e2 loc =
let id = Ident.create_fresh Ident.knormal in let instrs =
let instr1 = Sil.Load (id, e1, typ, loc) in let bop =
let e_res, instr_op =
match boi_kind with match boi_kind with
| `AddAssign -> | `AddAssign ->
let bop = if Typ.is_pointer t1 then Binop.PlusPI else Binop.PlusA in if Typ.is_pointer t1 then Binop.PlusPI else Binop.PlusA
let e1_plus_e2 = Exp.BinOp (bop, Exp.Var id, e2) in
(e1, [Sil.Store (e1, typ, e1_plus_e2, loc)])
| `SubAssign -> | `SubAssign ->
let bop = if Typ.is_pointer t1 then Binop.MinusPI else Binop.MinusA in if Typ.is_pointer t1 then Binop.MinusPI else Binop.MinusA
let e1_sub_e2 = Exp.BinOp (bop, Exp.Var id, e2) in
(e1, [Sil.Store (e1, typ, e1_sub_e2, loc)])
| `MulAssign -> | `MulAssign ->
let e1_mul_e2 = Exp.BinOp (Binop.Mult, Exp.Var id, e2) in Binop.Mult
(e1, [Sil.Store (e1, typ, e1_mul_e2, loc)])
| `DivAssign -> | `DivAssign ->
let e1_div_e2 = Exp.BinOp (Binop.Div, Exp.Var id, e2) in Binop.Div
(e1, [Sil.Store (e1, typ, e1_div_e2, loc)])
| `ShlAssign -> | `ShlAssign ->
let e1_shl_e2 = Exp.BinOp (Binop.Shiftlt, Exp.Var id, e2) in Binop.Shiftlt
(e1, [Sil.Store (e1, typ, e1_shl_e2, loc)])
| `ShrAssign -> | `ShrAssign ->
let e1_shr_e2 = Exp.BinOp (Binop.Shiftrt, Exp.Var id, e2) in Binop.Shiftrt
(e1, [Sil.Store (e1, typ, e1_shr_e2, loc)])
| `RemAssign -> | `RemAssign ->
let e1_mod_e2 = Exp.BinOp (Binop.Mod, Exp.Var id, e2) in Binop.Mod
(e1, [Sil.Store (e1, typ, e1_mod_e2, loc)])
| `AndAssign -> | `AndAssign ->
let e1_and_e2 = Exp.BinOp (Binop.BAnd, Exp.Var id, e2) in Binop.BAnd
(e1, [Sil.Store (e1, typ, e1_and_e2, loc)])
| `OrAssign -> | `OrAssign ->
let e1_or_e2 = Exp.BinOp (Binop.BOr, Exp.Var id, e2) in Binop.BOr
(e1, [Sil.Store (e1, typ, e1_or_e2, loc)])
| `XorAssign -> | `XorAssign ->
let e1_xor_e2 = Exp.BinOp (Binop.BXor, Exp.Var id, e2) in Binop.BXor
(e1, [Sil.Store (e1, typ, e1_xor_e2, loc)]) in
let id = Ident.create_fresh Ident.knormal in
[Sil.Load (id, e1, typ, loc); Sil.Store (e1, typ, Exp.BinOp (bop, Exp.Var id, e2), loc)]
in in
(e_res, instr1 :: instr_op) (e1, instrs)
(** Returns a pair ([binary_expression], instructions). "binary_expression" is returned when we are (** Returns a pair ([binary_expression], instructions). "binary_expression" is returned when we are

Loading…
Cancel
Save