From 9483f7df5e022587aa682fb6a2eea386eee0fd53 Mon Sep 17 00:00:00 2001 From: Arnaud DABY-SEESARAM Date: Mon, 19 Dec 2022 14:22:19 +0100 Subject: [PATCH] [c pass] merge neighbour conditionals (improved) --- src/ctranslation.ml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ctranslation.ml b/src/ctranslation.ml index 41a3f55..2470737 100644 --- a/src/ctranslation.ml +++ b/src/ctranslation.ml @@ -96,8 +96,15 @@ let rec merge_neighbour_ifs = function | [] -> [] | [stmt] -> [stmt] | CIf (c, e1, e2) :: CIf (c', e'1, e'2) :: b -> - if c = c' - then merge_neighbour_ifs (CIf (c, e1 @ e'1, e2 @ e'2) :: b) - else (CIf (c, e1, e2)) :: merge_neighbour_ifs (CIf (c', e'1, e'2) :: b) + begin + if c = c' then + merge_neighbour_ifs (CIf (c, e1 @ e'1, e2 @ e'2) :: b) + else if c = CMonOp (MOp_not, c') then + merge_neighbour_ifs (CIf (c, e1 @ e'2, e2 @ e'1) :: b) + else if c' = CMonOp (MOp_not, c) then + merge_neighbour_ifs (CIf (c, e1 @ e'2, e2 @ e'1) :: b) + else CIf (c, e1, e2) :: merge_neighbour_ifs (CIf (c', e'1, e'2) :: b) + end | stmt :: stmt' :: b -> stmt :: merge_neighbour_ifs (stmt' :: b) +