Better styling for miniImp
This commit is contained in:
@ -17,7 +17,10 @@ let rewrite_instructions (prg: Types.p_exp) : Types.p_exp =
|
||||
| _, Some a -> Some a
|
||||
)
|
||||
| If (b, c1, c2) -> (
|
||||
match contains_rewrite_b b, contains_rewrite c1, contains_rewrite c2 with
|
||||
match contains_rewrite_b b,
|
||||
contains_rewrite c1,
|
||||
contains_rewrite c2
|
||||
with
|
||||
| None, None, None -> None
|
||||
| Some a, _, _
|
||||
| _, Some a, _
|
||||
@ -30,7 +33,11 @@ let rewrite_instructions (prg: Types.p_exp) : Types.p_exp =
|
||||
| _, Some a -> Some a
|
||||
)
|
||||
| For (c1, b, c2, c3) -> (
|
||||
match contains_rewrite c1, contains_rewrite_b b, contains_rewrite c2, contains_rewrite c3 with
|
||||
match contains_rewrite c1,
|
||||
contains_rewrite_b b,
|
||||
contains_rewrite c2,
|
||||
contains_rewrite c3
|
||||
with
|
||||
| None, None, None, None -> None
|
||||
| Some a, _, _, _
|
||||
| _, Some a, _, _
|
||||
@ -105,7 +112,11 @@ let rewrite_instructions (prg: Types.p_exp) : Types.p_exp =
|
||||
in
|
||||
|
||||
(* functions that replace a pattern in a subexpression *)
|
||||
let rec replace_occurrence_a (pattern: Types.a_exp) (replace: Types.a_exp) (a: Types.a_exp) : Types.a_exp =
|
||||
let rec replace_occurrence_a
|
||||
(pattern: Types.a_exp)
|
||||
(replace: Types.a_exp)
|
||||
(a: Types.a_exp)
|
||||
: Types.a_exp =
|
||||
if a = pattern then
|
||||
replace
|
||||
else (
|
||||
@ -122,7 +133,11 @@ let rewrite_instructions (prg: Types.p_exp) : Types.p_exp =
|
||||
| PowerMod (a1, a2, a3) -> PowerMod (r_o_a a1, r_o_a a2, r_o_a a3)
|
||||
| Rand (a) -> Rand (r_o_a a)
|
||||
)
|
||||
and replace_occurrence_b (pattern: Types.a_exp) (replace: Types.a_exp) (b: Types.b_exp) : Types.b_exp =
|
||||
and replace_occurrence_b
|
||||
(pattern: Types.a_exp)
|
||||
(replace: Types.a_exp)
|
||||
(b: Types.b_exp)
|
||||
: Types.b_exp =
|
||||
let r_o_b = replace_occurrence_b pattern replace in
|
||||
let r_o_a = replace_occurrence_a pattern replace in
|
||||
match b with
|
||||
@ -197,7 +212,10 @@ let rewrite_instructions (prg: Types.p_exp) : Types.p_exp =
|
||||
let freshres = new_fresh_var "res" in
|
||||
Sequence (
|
||||
partial freshres a1 a2 a3,
|
||||
For (fora1, replace_occurrence_b pwm (Variable freshres) b, fora2, fora3)
|
||||
For ( fora1,
|
||||
replace_occurrence_b pwm (Variable freshres) b,
|
||||
fora2,
|
||||
fora3 )
|
||||
)
|
||||
| _ -> failwith "PowerMod is not present"
|
||||
in
|
||||
|
||||
Reference in New Issue
Block a user