-
Notifications
You must be signed in to change notification settings - Fork 121
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 #894
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
dbf9caa
Working registers and tests
lfrenot df046ce
Fix lean style in state.ml
lfrenot 6840387
pretty printing fixes
lfrenot bce92f1
formatting
lfrenot 7966840
New monad definition
lfrenot ad58fe9
Registers in the state monad
lfrenot cf57e20
fixing read/write reg output
lfrenot f5ca2df
Merge branch 'sail2' into lean-register-clean
lfrenot fa92534
Fixing registers and bitfield
lfrenot 03c29dc
Fixing tests
lfrenot 5e1c018
fixing lean arrows
lfrenot 8a6f181
small style fix
lfrenot 7147adb
Changed registers to grouped in a hashmap
lfrenot e26c834
updated tests
lfrenot 44f78d8
adding section, camelCase function names, regRef functions
lfrenot eccf1c5
Moving attributes inside SailM's definition
lfrenot 33cd674
Replacing the Eqs with DecidableEq
lfrenot 059f39a
reducing bloat in Sail.lean with @
lfrenot bf43b0a
Cleaner PreSailM and RegisterState
lfrenot 1a29a4e
Small style fixes
lfrenot 4a6a309
Fixing RegisterRef
lfrenot 35fd62d
Assign deref support
lfrenot 5f1cf9a
formatting
lfrenot 05ea73d
Remove commented code
lfrenot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ bitfield cr_type : bits(8) = { | |
CR1 : 3 .. 2, | ||
CR3 : 1 .. 0 | ||
} | ||
|
||
register R : cr_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Out.Sail.Sail | ||
|
||
open Sail | ||
|
||
inductive Register : Type where | ||
| BIT | ||
| NAT | ||
| BOOL | ||
| INT | ||
| R1 | ||
| R0 | ||
deriving DecidableEq, Hashable | ||
open Register | ||
|
||
lfrenot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
abbrev RegisterType : Register → Type | ||
| .BIT => (BitVec 1) | ||
| .NAT => Nat | ||
| .BOOL => Bool | ||
| .INT => Int | ||
| .R1 => (BitVec 64) | ||
| .R0 => (BitVec 64) | ||
|
||
abbrev SailM := PreSailM RegisterType | ||
|
||
def test : SailM Int := do | ||
writeReg INT (HAdd.hAdd (← readReg INT) 1) | ||
readReg INT | ||
|
||
def initialize_registers : SailM Unit := do | ||
writeReg R0 sorry | ||
writeReg R1 sorry | ||
writeReg INT sorry | ||
writeReg BOOL sorry | ||
writeReg NAT sorry | ||
writeReg BIT sorry | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Lean actually need this? (It's to deal with a limitation of Coq's let-binding patterns.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lean can pattern match in let-bindings if there's a single constructor, is that enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's roughly what Coq allows, except with the limitation that you can't have type annotations deep inside the pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, now that I think about it, it may also have been to ensure that sufficient bitvector casts are inserted (e.g., when you have
bits(8 * 'n)
and needbits('n * 8)
.