Skip to content

Commit

Permalink
Lean: Use generated sail_model_init function
Browse files Browse the repository at this point in the history
Brings the number of passing test cases up to 161
  • Loading branch information
Alasdair committed Mar 3, 2025
1 parent 2d3900c commit f24c9f3
Show file tree
Hide file tree
Showing 34 changed files with 95 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/sail_lean_backend/pretty_print_lean.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ let doc_instantiations ctx env =
^^ hardline

let main_function_stub has_registers =
let main_call = if has_registers then "(initialize_registers >=> sail_main)" else "sail_main" in
let main_call = if has_registers then "(sail_model_init >=> sail_main)" else "sail_main" in
nest 2
(separate hardline
[
Expand Down
1 change: 1 addition & 0 deletions src/sail_lean_backend/sail_plugin_lean.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ let lean_rewrites =
(* ("prover_regstate", [Bool_arg false]); *)
(* ("remove_assert", rewrite_ast_remove_assert); *)
("top_sort_defs", []);
("add_register_init_function", []);
("const_prop_mutrec", [String_arg "coq"]);
("exp_lift_assign", []);
("early_return", []);
Expand Down
3 changes: 3 additions & 0 deletions test/lean/SailTinyArm.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,9 @@ def initialize_registers (_ : Unit) : SailM Unit := do
writeReg R1 (← (undefined_bitvector 64))
writeReg R0 (← (undefined_bitvector 64))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/append.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def unif_vector_subrange (i : Nat) (v : (BitVec (8 * i + 8))) : (BitVec 8) :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/atom_bool.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def foo (_ : Unit) : Bool :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/bitfield.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def _set_cr_type_LT (r_ref : (RegisterRef (BitVec 8))) (v : (BitVec 1)) : SailM
def initialize_registers (_ : Unit) : SailM Unit := do
writeReg R (← (undefined_cr_type ()))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/bitvec_operation.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def vector_literal (x : Int) (y : Int) : (Vector Int 2) :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/early_return.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ def initialize_registers (_ : Unit) : SailM Unit := do
writeReg r_C (← (undefined_E ()))
writeReg r (← (undefined_nat ()))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/enum.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def num_of_E (arg_ : E) : Int :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/errors.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def test_assert (b : Bool) : SailM (BitVec 1) := do
def initialize_registers (_ : Unit) : SailM Unit := do
writeReg dummy (← (undefined_bit ()))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/extern.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ def extern_hex_str_upper (_ : Unit) : String :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/extern_bitvec.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def extern_vector_length (x : (Vector Int 3)) : Int :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/implicit.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def slice_mask2 {n : _} (i : (BitVec n)) (l : (BitVec n)) (b : Bool) : (BitVec n
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/ite.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def initialize_registers (_ : Unit) : SailM Unit := do
writeReg R (← (undefined_nat ()))
writeReg B (← (undefined_bool ()))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/let.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def baz (_ : Unit) : SailM (BitVec 16) := do
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/loop.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def while_loopmultiplevar (m : Nat) (n : Nat) : Nat := Id.run do
def initialize_registers (_ : Unit) : SailM Unit := do
writeReg r (← (undefined_nat ()))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/mapping.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ def size_bits3_backwards_matches (arg_ : (BitVec 2)) : Bool :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/match.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ def initialize_registers (_ : Unit) : SailM Unit := do
writeReg r_B (← (undefined_E ()))
writeReg r_C (← (undefined_E ()))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/match_bv.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def write_CSR2 (v__30 : (BitVec 12)) : SailM Bool := do
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/option.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def option_match (x : (Option Unit)) (y : (BitVec 1)) : (Option (BitVec 1)) :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/range.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def f_unkn (x : Int) : Int :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/register_vector.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ def initialize_registers (_ : Unit) : SailM Unit := do
writeReg R1 (← (undefined_bitvector 64))
writeReg R0 (← (undefined_bitvector 64))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/registers.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def initialize_registers (_ : Unit) : SailM Unit := do
writeReg NAT (← (undefined_nat ()))
writeReg BIT (← (undefined_bit ()))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/riscv_duopod.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def initialize_registers (_ : Unit) : SailM Unit := do
writeReg nextPC (← (undefined_bitvector 64))
writeReg Xs (← (undefined_vector 32 (← (undefined_bitvector 64))))

def sail_model_init (x_0 : Unit) : SailM Unit := do
(initialize_registers ())

end Functions
open Functions

7 changes: 0 additions & 7 deletions test/lean/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
'primop',
'poly_pair',
'assign_rename_bug',
'config',
'cheri128_hsb',
'union_variant_names',
'lib_hex_bits',
Expand All @@ -53,7 +52,6 @@
'spc_mappings',
'concurrency_interface',
'vector_example',
'reg_init_let',
'for_shadow',
'list_torture',
'option_nest',
Expand All @@ -65,22 +63,17 @@
'type_if_bits',
'poly_union',
'nexp_simp_euclidian',
'config_register_ones',
'toplevel_tyvar',
'ediv_from_tdiv',
'concurrency_interface_write',
'read_write_ram',
'issue136',
'fail_exception',
'natural_sort_reg',
'option_option',
'anf_as_pattern',
'poly_mapping',
'real_prop',
'vector_init',
'partial_mapping',
'lib_dec_bits',
'list_list_eq',
'constructor247',
'config_vec_list',
'deep_poly_nest',
Expand Down
3 changes: 3 additions & 0 deletions test/lean/struct.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def match_struct (value : My_struct) : SailM Int := do
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/struct_of_enum.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def undefined_s_test (_ : Unit) : SailM s_test := do
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/trivial.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def foo (y : Unit) : Unit :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/tuples.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def tuple2 (_ : Unit) : SailM (Int × Int) := do
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/type_kid.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def foo (x : k_a) : (k_a × k_a) :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/typedef.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def uses_xlen_term (_ : Unit) : Int :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/typquant.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def termination (n : Nat) : Int :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/undefined.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def bar (n : Int) : SailM (Vector Int 4) := do
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

3 changes: 3 additions & 0 deletions test/lean/union.expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def use_is_none (opt : (my_option k_a)) : Bool :=
def initialize_registers (_ : Unit) : Unit :=
()

def sail_model_init (x_0 : Unit) : Unit :=
(initialize_registers ())

end Functions
open Functions

0 comments on commit f24c9f3

Please sign in to comment.