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

Prevent instructions from being instantiated with wrong operand types #8

Closed
wants to merge 1 commit into from
Closed

Prevent instructions from being instantiated with wrong operand types #8

wants to merge 1 commit into from

Conversation

tpwrules
Copy link
Collaborator

Fixes issue #6 by preventing non-registers from being put in place of register operands and vice versa. Only checks and prevents this when instantiating the instructions directly.

x = MOVI(R0, 0) # legal
y = MOVI(0, 0) # non-reg where reg expected
z = MOVI(R0, R0) # reg where non-reg expected
x.rsd = 0 # legal
x.imm = R0 # legal
a = MOVI(Reg(0), int(R0)) # legal, converts between register number and register object

@whitequark
Copy link
Owner

This definitely won't work. For one, it introduces a circular dependency between mc and instr. Also, mc is supposed to be independent of any particular ISA.

@tpwrules
Copy link
Collaborator Author

Well, it worked great for me :)

I decided that this should only be checked for when instantiating instructions because someone who is setting attributes or constructing Reg and Imm objects (e.g. the assembler) probably knows what they're doing. Otherwise, the conditions could be checked for in prepare, except that there's not immediately a way to construct the initial register objects if prepare doesn't accept integers.

Maybe a validation function could be attached to instr.Instr.formats or be a class attribute/method of mc.Operand subclasses. Not sure what to call it though, is_legal_instantiation?

@whitequark whitequark closed this Nov 10, 2019
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

Successfully merging this pull request may close these issues.

2 participants