Skip to content

Commit c888091

Browse files
committed
Update tests
2 parents d563e32 + 820f9e7 commit c888091

35 files changed

+149
-139
lines changed

lib/flow.sail

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,26 @@ therefore be included in just about every Sail specification.
5555
5656
*/
5757

58-
val eq_unit = pure { lean : "BEq.beq", _ : "eq_unit" } : (unit, unit) -> bool(true)
58+
val eq_unit = pure { lean : "_lean_beq", _ : "eq_unit" } : (unit, unit) -> bool(true)
5959
function eq_unit(_, _) = true
6060

61-
val eq_bit = pure { lem : "eq", lean : "BEq.beq", _ : "eq_bit" } : (bit, bit) -> bool
61+
val eq_bit = pure { lem : "eq", lean : "_lean_beq", _ : "eq_bit" } : (bit, bit) -> bool
6262

63-
val not_bool = pure {coq: "negb", lean: "Bool.not", _: "not"} : forall ('p : Bool). bool('p) -> bool(not('p))
63+
val not_bool = pure {coq: "negb", lean: "_lean_not", _: "not"} : forall ('p : Bool). bool('p) -> bool(not('p))
6464
/* NB: There are special cases in Sail for effectful uses of and_bool and
6565
or_bool that are not shown here. */
6666

67-
val and_bool = pure {coq: "andb", lean: "Bool.and", _: "and_bool"} : forall ('p : Bool) ('q : Bool). (bool('p), bool('q)) -> bool('p & 'q)
67+
val and_bool = pure {coq: "andb", lean: "_lean_and", _: "and_bool"} : forall ('p : Bool) ('q : Bool). (bool('p), bool('q)) -> bool('p & 'q)
6868

69-
val and_bool_no_flow = pure {coq: "andb", lean: "Bool.and", _: "and_bool"} : (bool, bool) -> bool
69+
val and_bool_no_flow = pure {coq: "andb", lean: "_lean_and", _: "and_bool"} : (bool, bool) -> bool
7070

71-
val or_bool = pure {coq: "orb", lean: "Bool.or", _: "or_bool"} : forall ('p : Bool) ('q : Bool). (bool('p), bool('q)) -> bool('p | 'q)
71+
val or_bool = pure {coq: "orb", lean: "_lean_or", _: "or_bool"} : forall ('p : Bool) ('q : Bool). (bool('p), bool('q)) -> bool('p | 'q)
7272

73-
val eq_int = pure {ocaml: "eq_int", interpreter: "eq_int", lem: "eq", coq: "Z.eqb", lean: "BEq.beq", _: "eq_int"} : forall 'n 'm. (int('n), int('m)) -> bool('n == 'm)
73+
val eq_int = pure {ocaml: "eq_int", interpreter: "eq_int", lem: "eq", coq: "Z.eqb", lean: "_lean_beq", _: "eq_int"} : forall 'n 'm. (int('n), int('m)) -> bool('n == 'm)
7474

75-
val eq_bool = pure {ocaml: "eq_bool", interpreter: "eq_bool", lem: "eq", coq: "Bool.eqb", lean: "BEq.beq", _: "eq_bool"} : (bool, bool) -> bool
75+
val eq_bool = pure {ocaml: "eq_bool", interpreter: "eq_bool", lem: "eq", coq: "Bool.eqb", lean: "_lean_beq", _: "eq_bool"} : (bool, bool) -> bool
7676

77-
val neq_int = pure {lem: "neq", lean: "bne"} : forall 'n 'm. (int('n), int('m)) -> bool('n != 'm)
77+
val neq_int = pure {lem: "neq", lean: "_lean_bne"} : forall 'n 'm. (int('n), int('m)) -> bool('n != 'm)
7878
function neq_int (x, y) = not_bool(eq_int(x, y))
7979

8080
val neq_bool : (bool, bool) -> bool

lib/generic_equality.sail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $define _GENERIC_EQUALITY
4949

5050
$include <flow.sail>
5151

52-
val eq_anything = pure {ocaml: "(fun (x, y) -> x = y)", lem: "eq", coq: "generic_eq", lean: "BEq.beq", _: "eq_anything"} : forall ('a : Type). ('a, 'a) -> bool
52+
val eq_anything = pure {ocaml: "(fun (x, y) -> x = y)", lem: "eq", coq: "generic_eq", lean: "_lean_beq", _: "eq_anything"} : forall ('a : Type). ('a, 'a) -> bool
5353

5454
overload operator == = {eq_anything}
5555

lib/string.sail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $include <arith.sail>
5252
val eq_string = pure {
5353
lem: "eq",
5454
coq: "generic_eq",
55-
lean: "BEq.beq",
55+
lean: "_lean_beq",
5656
_: "eq_string"} : (string, string) -> bool
5757

5858
overload operator == = {eq_string}

lib/vector.sail

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ val eq_bits = pure {
6060
interpreter: "eq_list",
6161
lem: "eq_vec",
6262
coq: "eq_vec",
63-
lean: "BEq.beq",
63+
lean: "_lean_beq",
6464
_: "eq_bits"
6565
} : forall 'n. (bits('n), bits('n)) -> bool
6666

@@ -70,7 +70,7 @@ val neq_bits = pure {
7070
lem: "neq_vec",
7171
coq: "neq_vec",
7272
c: "neq_bits",
73-
lean: "bne"
73+
lean: "_lean_bne"
7474
} : forall 'n. (bits('n), bits('n)) -> bool
7575

7676
function neq_bits(x, y) = not_bool(eq_bits(x, y))

src/sail_lean_backend/Sail/Sail.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ def sail_tlbi [Arch] (_ : Arch.tlb_op) : PreSailM RegisterType c ue Unit := pure
507507
def sail_translation_start [Arch] (_ : Arch.trans_start) : PreSailM RegisterType c ue Unit := pure ()
508508
def sail_translation_end [Arch] (_ : Arch.trans_end) : PreSailM RegisterType c ue Unit := pure ()
509509
def sail_take_exception [Arch] (_ : Arch.fault) : PreSailM RegisterType c ue Unit := pure ()
510+
def sail_return_exception [Arch] (_ : Arch.pa) : PreSailM RegisterType c ue Unit := pure ()
510511

511512
def cycle_count (_ : Unit) : PreSailM RegisterType c ue Unit :=
512513
modify fun s => { s with cycleCount := s.cycleCount + 1 }

src/sail_lean_backend/Sail/Specialization.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ abbrev sail_tlbi [Arch] (op : Arch.tlb_op) : SailM Unit := PreSail.sail_tlbi op
5959
abbrev sail_translation_start [Arch] (ts : Arch.trans_start) : SailM Unit := PreSail.sail_translation_start ts
6060
abbrev sail_translation_end [Arch] (te : Arch.trans_end) : SailM Unit := PreSail.sail_translation_end te
6161
abbrev sail_take_exception [Arch] (f : Arch.fault) : SailM Unit := PreSail.sail_take_exception f
62+
abbrev sail_return_exception [Arch] (a : Arch.pa) : SailM Unit := PreSail.sail_return_exception a
6263

6364
abbrev cycle_count (a : Unit) : SailM Unit := PreSail.cycle_count a
6465

src/sail_lean_backend/pretty_print_lean.ml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ open Pretty_print_common
1212
(* Command line options *)
1313
let opt_extern_types : string list ref = ref []
1414

15+
let opt_line_width : int ref = ref 100
16+
1517
type global_context = {
1618
effect_info : Effects.side_effect_info;
1719
fun_args : string list Bindings.t;
@@ -86,7 +88,7 @@ let rec fix_id name =
8688
match name with
8789
(* Lean keywords to avoid, to expand as needed *)
8890
| "_lean_wildcard" -> "_"
89-
| "rec" | "def" | "at" -> name ^ "'"
91+
| "rec" | "def" | "at" | "alias" | "break" -> name ^ "'"
9092
| "main" ->
9193
the_main_function_has_been_seen := true;
9294
"sail_main"
@@ -592,6 +594,11 @@ let rec doc_implicit_args ?(docs = []) ns ims d_args =
592594

593595
let op_of_id id =
594596
match id with
597+
| Some "_lean_and" -> `Binop "&&"
598+
| Some "_lean_or" -> `Binop "||"
599+
| Some "_lean_beq" -> `Binop "=="
600+
| Some "_lean_bne" -> `Binop "!="
601+
| Some "_lean_not" -> `Unop "!"
595602
| Some "_lean_add" -> `Binop "+"
596603
| Some "_lean_addi" -> `Binop "+i"
597604
| Some "_lean_sub" -> `Binop "-"
@@ -609,8 +616,8 @@ let op_of_id id =
609616
| Some "_lean_ge" -> `Binop "≥b"
610617
| Some "_lean_le" -> `Binop "≤b"
611618
| Some "_lean_gt" -> `Binop ">b"
612-
| Some "_lean_pow2" -> `Unnop "2 ^"
613-
| Some "_lean_pow2i" -> `Unnop "2 ^i"
619+
| Some "_lean_pow2" -> `Unop "2 ^"
620+
| Some "_lean_pow2i" -> `Unop "2 ^i"
614621
| _ -> `NotOp
615622

616623
let unnop_of_id id = match id with Some "_lean_pow2" -> Some "2 ^ " | _ -> None
@@ -863,7 +870,7 @@ and doc_exp (as_monadic : bool) ctx (E_aux (e, (l, annot)) as full_exp) =
863870
let e2 = List.nth d_args 1 in
864871
let res = e1 ^^ space ^^ string op ^^ space ^^ e2 in
865872
wrap_with_pure as_monadic (parens res) |> nest 2
866-
| `Unnop op ->
873+
| `Unop op ->
867874
let e = List.nth d_args 0 in
868875
let res = string op ^^ space ^^ e in
869876
wrap_with_pure as_monadic (parens res) |> nest 2
@@ -1472,5 +1479,5 @@ let pp_ast_lean (env : Type_check.env) effect_info ({ defs; _ } as ast : Libsail
14721479
(fun file defs -> print file (separate hardline (remove_empties [opens; defs])))
14731480
imp_funcs_files imp_fundefss
14741481
in
1475-
print funcs_file (separate hardline (remove_empties ([opens; main_fundefs] @ main_function)));
1482+
print ~len:!opt_line_width funcs_file (separate hardline (remove_empties ([opens; main_fundefs] @ main_function)));
14761483
!the_main_function_has_been_seen

src/sail_lean_backend/sail_plugin_lean.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ let lean_options =
110110
),
111111
"use matchbv in the Lean output"
112112
);
113+
( Flag.create ~prefix:["lean"] "line_width",
114+
Arg.Int (fun n -> Pretty_print_lean.opt_line_width := n),
115+
"maximum line length of the generated Lean code"
116+
);
113117
( Flag.create ~prefix:["lean"] "noncomputable",
114118
Arg.Unit (fun () -> opt_lean_noncomputable := true),
115119
"add a 'noncomputable section' at the beginning of the output"

test/lean/SailTinyArm.expected.lean

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ open AccessType
510510

511511
/-- Type quantifiers: k_ex5891# : Bool, k_ex5890# : Bool -/
512512
def neq_bool (x : Bool) (y : Bool) : Bool :=
513-
(Bool.not (BEq.beq x y))
513+
(! (x == y))
514514

515515
/-- Type quantifiers: x : Int -/
516516
def __id (x : Int) : Int :=
@@ -548,10 +548,10 @@ def _shr_int_general (m : Int) (n : Int) : Int :=
548548

549549
/-- Type quantifiers: m : Int, n : Int -/
550550
def fdiv_int (n : Int) (m : Int) : Int :=
551-
bif (Bool.and (n <b 0) (m >b 0))
551+
bif ((n <b 0) && (m >b 0))
552552
then ((Int.tdiv (n +i 1) m) -i 1)
553553
else
554-
(bif (Bool.and (n >b 0) (m <b 0))
554+
(bif ((n >b 0) && (m <b 0))
555555
then ((Int.tdiv (n -i 1) m) -i 1)
556556
else (Int.tdiv n m))
557557

@@ -1792,13 +1792,13 @@ def GPRs : (Vector (RegisterRef (BitVec 64)) 31) :=
17921792

17931793
/-- Type quantifiers: n : Nat, 0 ≤ n ∧ n ≤ 31 -/
17941794
def wX (n : Nat) (value : (BitVec 64)) : SailM Unit := do
1795-
bif (bne n 31)
1795+
bif (n != 31)
17961796
then writeRegRef (GetElem?.getElem! GPRs n) value
17971797
else (pure ())
17981798

17991799
/-- Type quantifiers: n : Nat, 0 ≤ n ∧ n ≤ 31 -/
18001800
def rX (n : Nat) : SailM (BitVec 64) := do
1801-
bif (bne n 31)
1801+
bif (n != 31)
18021802
then (reg_deref (GetElem?.getElem! GPRs n))
18031803
else (pure (0x0000000000000000 : (BitVec 64)))
18041804

@@ -1812,29 +1812,29 @@ def decodeLoadStoreRegister (opc : (BitVec 2)) (Rm : (BitVec 5)) (option_v : (Bi
18121812
let t : reg_index := (BitVec.toNat Rt)
18131813
let n : reg_index := (BitVec.toNat Rn)
18141814
let m : reg_index := (BitVec.toNat Rm)
1815-
bif (Bool.or (bne option_v (0b011 : (BitVec 3))) (BEq.beq S 1#1))
1815+
bif ((option_v != (0b011 : (BitVec 3))) || (S == 1#1))
18161816
then none
18171817
else
1818-
(bif (BEq.beq opc (0b00 : (BitVec 2)))
1818+
(bif (opc == (0b00 : (BitVec 2)))
18191819
then (some (LoadRegister (t, n, m)))
18201820
else
1821-
(bif (BEq.beq opc (0b01 : (BitVec 2)))
1821+
(bif (opc == (0b01 : (BitVec 2)))
18221822
then (some (StoreRegister (t, n, m)))
18231823
else none))
18241824

18251825
def decodeExclusiveOr (sf : (BitVec 1)) (shift : (BitVec 2)) (N : (BitVec 1)) (Rm : (BitVec 5)) (imm6 : (BitVec 6)) (Rn : (BitVec 5)) (Rd : (BitVec 5)) : (Option ast) :=
18261826
let d : reg_index := (BitVec.toNat Rd)
18271827
let n : reg_index := (BitVec.toNat Rn)
18281828
let m : reg_index := (BitVec.toNat Rm)
1829-
bif (Bool.and (BEq.beq sf 0#1) (BEq.beq (BitVec.access imm6 5) 1#1))
1829+
bif ((sf == 0#1) && ((BitVec.access imm6 5) == 1#1))
18301830
then none
18311831
else
1832-
(bif (bne imm6 (0b000000 : (BitVec 6)))
1832+
(bif (imm6 != (0b000000 : (BitVec 6)))
18331833
then none
18341834
else (some (ExclusiveOr (d, n, m))))
18351835

18361836
def decodeDataMemoryBarrier (CRm : (BitVec 4)) : (Option ast) :=
1837-
bif (bne CRm (0xF : (BitVec 4)))
1837+
bif (CRm != (0xF : (BitVec 4)))
18381838
then none
18391839
else (some (DataMemoryBarrier ()))
18401840

@@ -1920,7 +1920,7 @@ def execute_DataMemoryBarrier (_ : Unit) : SailM Unit := do
19201920
/-- Type quantifiers: t : Nat, 0 ≤ t ∧ t ≤ 31 -/
19211921
def execute_CompareAndBranch (t : Nat) (offset : (BitVec 64)) : SailM Unit := do
19221922
let operand ← do (rX t)
1923-
bif (BEq.beq operand (0x0000000000000000 : (BitVec 64)))
1923+
bif (operand == (0x0000000000000000 : (BitVec 64)))
19241924
then
19251925
(do
19261926
let base ← do (rPC ())

test/lean/append.expected.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ open option
4747

4848
/-- Type quantifiers: k_ex688# : Bool, k_ex687# : Bool -/
4949
def neq_bool (x : Bool) (y : Bool) : Bool :=
50-
(Bool.not (BEq.beq x y))
50+
(! (x == y))
5151

5252
/-- Type quantifiers: x : Int -/
5353
def __id (x : Int) : Int :=
@@ -85,10 +85,10 @@ def _shr_int_general (m : Int) (n : Int) : Int :=
8585

8686
/-- Type quantifiers: m : Int, n : Int -/
8787
def fdiv_int (n : Int) (m : Int) : Int :=
88-
bif (Bool.and (n <b 0) (m >b 0))
88+
bif ((n <b 0) && (m >b 0))
8989
then ((Int.tdiv (n +i 1) m) -i 1)
9090
else
91-
(bif (Bool.and (n >b 0) (m <b 0))
91+
(bif ((n >b 0) && (m <b 0))
9292
then ((Int.tdiv (n -i 1) m) -i 1)
9393
else (Int.tdiv n m))
9494

0 commit comments

Comments
 (0)