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

Use newtype for physical and virtual addresses #434

Open
Timmmm opened this issue Mar 18, 2024 · 0 comments
Open

Use newtype for physical and virtual addresses #434

Timmmm opened this issue Mar 18, 2024 · 0 comments
Labels
refactor Code clean up

Comments

@Timmmm
Copy link
Collaborator

Timmmm commented Mar 18, 2024

For clarify and to avoid mixing them up, we can use Sail's newtype feature to create distinct types for physical and virtual addresses. For example:

newtype physaddr = physaddr : xlenbits
newtype virtaddr = virtaddr : xlenbits

function translate(virtaddr(vaddr) : virtaddr) -> physaddr = physaddr(vaddr + 1)

function main() -> unit = {
  let x = physaddr(zeros(32));

  let y = translate(x)
}

This will give a compile time error since we accidentally passed a physical address into translate().

See #433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code clean up
Projects
None yet
Development

No branches or pull requests

1 participant