Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lean: add support for register definitions #880

Closed
wants to merge 56 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
029ade9
First batch of features
lfrenot Dec 6, 2024
c6ccac3
Adding features
lfrenot Dec 6, 2024
c7573a8
formatting
lfrenot Dec 6, 2024
32bb33f
update_subrange implementation
lfrenot Dec 9, 2024
5dd4394
Cleanup registers
lfrenot Dec 9, 2024
1222d41
updated test
lfrenot Dec 9, 2024
41f93f2
formatting
lfrenot Dec 10, 2024
d3d373f
fix test name
lfrenot Dec 10, 2024
07efed6
fix expected output
lfrenot Dec 10, 2024
ebc978a
Capitalizing the Lean files
lfrenot Dec 17, 2024
7342888
Larger struct test file
lfrenot Dec 17, 2024
4a28244
Typo fixes
lfrenot Dec 17, 2024
ade2336
missing edit for the rebase
lfrenot Dec 17, 2024
c4f05a2
Removing useless changes
lfrenot Dec 20, 2024
08a2c79
Removing the addition import files
lfrenot Jan 10, 2025
e03b2a1
Adding back registerRef
lfrenot Jan 15, 2025
8c18e46
Formatting
lfrenot Jan 15, 2025
a1e5fc5
Fixing Lean style in Sail.lean
lfrenot Jan 15, 2025
ff25fd0
changing registerRef to UpperCamelCase
lfrenot Jan 16, 2025
86f5ae8
Fixing after rebase
lfrenot Jan 16, 2025
8c6815a
Adding a mk_struct test
lfrenot Jan 16, 2025
b34591d
updated test output for rebase
lfrenot Jan 16, 2025
8242d70
Lean style update
lfrenot Jan 16, 2025
6efe914
First batch of features
lfrenot Dec 6, 2024
c7be434
Adding features
lfrenot Dec 6, 2024
23d99b2
formatting
lfrenot Dec 6, 2024
0dddf29
update_subrange implementation
lfrenot Dec 9, 2024
9c454dd
Cleanup registers
lfrenot Dec 9, 2024
fdef34a
updated test
lfrenot Dec 9, 2024
2a2da2d
formatting
lfrenot Dec 10, 2024
777ba21
fix test name
lfrenot Dec 10, 2024
98d5eb3
fix expected output
lfrenot Dec 10, 2024
5208f08
Capitalizing the Lean files
lfrenot Dec 17, 2024
1b0f304
Larger struct test file
lfrenot Dec 17, 2024
44409f5
Typo fixes
lfrenot Dec 17, 2024
3254395
missing edit for the rebase
lfrenot Dec 17, 2024
2f44421
Removing useless changes
lfrenot Dec 20, 2024
27b82e7
Removing the addition import files
lfrenot Jan 10, 2025
bbae47d
Missed edit in rebasing
lfrenot Jan 10, 2025
6add173
first adding is_monadic
lfrenot Jan 10, 2025
d8c2868
internal_plet
lfrenot Jan 13, 2025
b30421f
add placeholer for state monad to stateful functions
javra Jan 13, 2025
aae09c2
changes after merge
lfrenot Jan 14, 2025
829d1d3
Adding test
lfrenot Jan 14, 2025
07fd6d3
fix in case of no register
lfrenot Jan 14, 2025
41bdd9d
removing extra hardline when there is no register
lfrenot Jan 14, 2025
e064d63
adding force-output to the lean tests
lfrenot Jan 14, 2025
77c8286
Starting to fix the broken tests
lfrenot Jan 15, 2025
2729634
Formatting
lfrenot Jan 15, 2025
88dce4a
Fix run_tests
lfrenot Jan 15, 2025
3bd8278
Actually fixing
lfrenot Jan 15, 2025
995a7b9
Fixing more tests
lfrenot Jan 15, 2025
750f250
Merge branch 'lean-record-features' into lean-register
lfrenot Jan 17, 2025
895353f
Merge branch 'sail2' into lean-register
lfrenot Jan 17, 2025
573e520
formating
lfrenot Jan 17, 2025
8de8351
final push before making a clean branch
lfrenot Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
changing registerRef to UpperCamelCase
lfrenot committed Jan 16, 2025
commit ff25fd03bd10677c23419a021593af67e930a141
2 changes: 1 addition & 1 deletion src/sail_lean_backend/Sail/Sail.lean
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def updateSubrange {w : Nat} (x : BitVec w) (hi lo : Nat) (y : BitVec (hi - lo +
end BitVec
end Sail

structure registerRef (regstate regval a : Type) where
structure RegisterRef (regstate regval a : Type) where
name : String
read_from : regstate -> a
write_to : a -> regstate -> regstate
3 changes: 2 additions & 1 deletion src/sail_lean_backend/pretty_print_lean.ml
Original file line number Diff line number Diff line change
@@ -138,7 +138,8 @@ let rec doc_typ ctxt (Typ_aux (t, _) as typ) =
| Typ_app (Id_aux (Id "atom", _), [A_aux (A_nexp (Nexp_aux (Nexp_var ki, _)), _)]) ->
string "Int" (* TODO This probably has to be generalized *)
| Typ_app (Id_aux (Id "register", _), t_app) ->
string "registerRef Unit Unit " (* TODO: Replace units with real types. *) ^^ separate_map comma (doc_typ_app ctxt) t_app
string "RegisterRef Unit Unit "
(* TODO: Replace units with real types. *) ^^ separate_map comma (doc_typ_app ctxt) t_app
| Typ_app (Id_aux (Id "implicit", _), [A_aux (A_nexp (Nexp_aux (Nexp_var ki, _)), _)]) ->
underscore (* TODO check if the type of implicit arguments can really be always inferred *)
| Typ_tuple ts -> parens (separate_map (space ^^ string "×" ^^ space) (doc_typ ctxt) ts)
12 changes: 6 additions & 6 deletions test/lean/bitfield.expected.lean
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ def _get_cr_type_bits (v : cr_type) : BitVec 8 :=
def _update_cr_type_bits (v : cr_type) (x : BitVec 8) : cr_type :=
{v with bits := (Sail.BitVec.updateSubrange v.bits (HSub.hSub 8 1) 0 x)}

def _set_cr_type_bits (r_ref : registerRef Unit Unit cr_type) (v : BitVec 8) : Unit :=
def _set_cr_type_bits (r_ref : RegisterRef Unit Unit cr_type) (v : BitVec 8) : Unit :=
sorry

def _get_cr_type_CR0 (v : cr_type) : BitVec 4 :=
@@ -25,7 +25,7 @@ def _get_cr_type_CR0 (v : cr_type) : BitVec 4 :=
def _update_cr_type_CR0 (v : cr_type) (x : BitVec 4) : cr_type :=
{v with bits := (Sail.BitVec.updateSubrange v.bits 7 4 x)}

def _set_cr_type_CR0 (r_ref : registerRef Unit Unit cr_type) (v : BitVec 4) : Unit :=
def _set_cr_type_CR0 (r_ref : RegisterRef Unit Unit cr_type) (v : BitVec 4) : Unit :=
sorry

def _get_cr_type_CR1 (v : cr_type) : BitVec 2 :=
@@ -34,7 +34,7 @@ def _get_cr_type_CR1 (v : cr_type) : BitVec 2 :=
def _update_cr_type_CR1 (v : cr_type) (x : BitVec 2) : cr_type :=
{v with bits := (Sail.BitVec.updateSubrange v.bits 3 2 x)}

def _set_cr_type_CR1 (r_ref : registerRef Unit Unit cr_type) (v : BitVec 2) : Unit :=
def _set_cr_type_CR1 (r_ref : RegisterRef Unit Unit cr_type) (v : BitVec 2) : Unit :=
sorry

def _get_cr_type_CR3 (v : cr_type) : BitVec 2 :=
@@ -43,7 +43,7 @@ def _get_cr_type_CR3 (v : cr_type) : BitVec 2 :=
def _update_cr_type_CR3 (v : cr_type) (x : BitVec 2) : cr_type :=
{v with bits := (Sail.BitVec.updateSubrange v.bits 1 0 x)}

def _set_cr_type_CR3 (r_ref : registerRef Unit Unit cr_type) (v : BitVec 2) : Unit :=
def _set_cr_type_CR3 (r_ref : RegisterRef Unit Unit cr_type) (v : BitVec 2) : Unit :=
sorry

def _get_cr_type_GT (v : cr_type) : BitVec 1 :=
@@ -52,7 +52,7 @@ def _get_cr_type_GT (v : cr_type) : BitVec 1 :=
def _update_cr_type_GT (v : cr_type) (x : BitVec 1) : cr_type :=
{v with bits := (Sail.BitVec.updateSubrange v.bits 6 6 x)}

def _set_cr_type_GT (r_ref : registerRef Unit Unit cr_type) (v : BitVec 1) : Unit :=
def _set_cr_type_GT (r_ref : RegisterRef Unit Unit cr_type) (v : BitVec 1) : Unit :=
sorry

def _get_cr_type_LT (v : cr_type) : BitVec 1 :=
@@ -61,7 +61,7 @@ def _get_cr_type_LT (v : cr_type) : BitVec 1 :=
def _update_cr_type_LT (v : cr_type) (x : BitVec 1) : cr_type :=
{v with bits := (Sail.BitVec.updateSubrange v.bits 7 7 x)}

def _set_cr_type_LT (r_ref : registerRef Unit Unit cr_type) (v : BitVec 1) : Unit :=
def _set_cr_type_LT (r_ref : RegisterRef Unit Unit cr_type) (v : BitVec 1) : Unit :=
sorry

def initialize_registers : Unit :=