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

Decoding variable-length instructions. #595

Open
kodyvajjha opened this issue Jun 19, 2024 · 1 comment
Open

Decoding variable-length instructions. #595

kodyvajjha opened this issue Jun 19, 2024 · 1 comment

Comments

@kodyvajjha
Copy link

I am trying to make a decode function dependently-typed as val decode : forall 'n, 'n <= 32. bits('n) -> option(ast) so that it could uniformly handle decoding variable-length instructions. But I am having trouble defining clauses of such a decode function with different size arguments in different clauses, e.g., I get a type error of the form:

14 |function clause decode 0xEA =  Some(IMP_OP(0xEA,NOP))
   |                       ^--^ checking function argument has type bitvector('n)
   | Failed to prove constraint: 8 == 'n

Perhaps this is not allowed or I am making a mistake somewhere? I could always define different decode functions for each allowed instruction length and piece them all together at the end, but I was wondering if my approach above works.

Thanks in advance!

@Alasdair
Copy link
Collaborator

Currently all the patterns in a function need to have the same width, so the way to go is indeed to have a scattered decode8, decode16, etc, and dispatch to them from a top-level decode function.

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

No branches or pull requests

2 participants