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 -> if Typ.is_pointer t1 then Binop.PlusPI else Binop.PlusA
let bop = if Typ.is_pointer t1 then Binop.PlusPI else Binop.PlusA in | `SubAssign ->
let e1_plus_e2 = Exp.BinOp (bop, Exp.Var id, e2) in if Typ.is_pointer t1 then Binop.MinusPI else Binop.MinusA
(e1, [Sil.Store (e1, typ, e1_plus_e2, loc)]) | `MulAssign ->
| `SubAssign -> Binop.Mult
let bop = if Typ.is_pointer t1 then Binop.MinusPI else Binop.MinusA in | `DivAssign ->
let e1_sub_e2 = Exp.BinOp (bop, Exp.Var id, e2) in Binop.Div
(e1, [Sil.Store (e1, typ, e1_sub_e2, loc)]) | `ShlAssign ->
| `MulAssign -> Binop.Shiftlt
let e1_mul_e2 = Exp.BinOp (Binop.Mult, Exp.Var id, e2) in | `ShrAssign ->
(e1, [Sil.Store (e1, typ, e1_mul_e2, loc)]) Binop.Shiftrt
| `DivAssign -> | `RemAssign ->
let e1_div_e2 = Exp.BinOp (Binop.Div, Exp.Var id, e2) in Binop.Mod
(e1, [Sil.Store (e1, typ, e1_div_e2, loc)]) | `AndAssign ->
| `ShlAssign -> Binop.BAnd
let e1_shl_e2 = Exp.BinOp (Binop.Shiftlt, Exp.Var id, e2) in | `OrAssign ->
(e1, [Sil.Store (e1, typ, e1_shl_e2, loc)]) Binop.BOr
| `ShrAssign -> | `XorAssign ->
let e1_shr_e2 = Exp.BinOp (Binop.Shiftrt, Exp.Var id, e2) in Binop.BXor
(e1, [Sil.Store (e1, typ, e1_shr_e2, loc)]) in
| `RemAssign -> let id = Ident.create_fresh Ident.knormal in
let e1_mod_e2 = Exp.BinOp (Binop.Mod, Exp.Var id, e2) in [Sil.Load (id, e1, typ, loc); Sil.Store (e1, typ, Exp.BinOp (bop, Exp.Var id, e2), loc)]
(e1, [Sil.Store (e1, typ, e1_mod_e2, loc)])
| `AndAssign ->
let e1_and_e2 = Exp.BinOp (Binop.BAnd, Exp.Var id, e2) in
(e1, [Sil.Store (e1, typ, e1_and_e2, loc)])
| `OrAssign ->
let e1_or_e2 = Exp.BinOp (Binop.BOr, Exp.Var id, e2) in
(e1, [Sil.Store (e1, typ, e1_or_e2, loc)])
| `XorAssign ->
let e1_xor_e2 = Exp.BinOp (Binop.BXor, Exp.Var id, e2) in
(e1, [Sil.Store (e1, typ, e1_xor_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