-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-118423: Add INSTRUCTION_SIZE
macro to code generator
#125467
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
Changes from 8 commits
ec8c701
09c2f59
287eb92
c76fce4
e3f3b07
ed5b375
870341d
421ebda
5154f7f
e7e83dc
101a5fd
1338628
ee461d5
7135103
715ce31
8235321
148070e
3e6b592
6e78ec0
75e6f6c
a3c0d10
7235d2d
5cfb423
2190784
33343dd
f9ecb16
abfaaff
3f3ad10
a8f72ef
8138a06
772f803
a718cfb
a10d4ee
3ae7a5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add a new ``INSTRUCTION_SIZE`` macro to the cases generator which returns | ||
the current instruction size. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import dataclasses | ||
tomasr8 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
from pathlib import Path | ||
from typing import TextIO | ||
|
||
|
@@ -118,7 +119,8 @@ def __init__(self, out: CWriter): | |
"PyStackRef_CLOSE": self.stackref_close, | ||
"PyStackRef_CLOSE_SPECIALIZED": self.stackref_close, | ||
"PyStackRef_AsPyObjectSteal": self.stackref_steal, | ||
"DISPATCH": self.dispatch | ||
"DISPATCH": self.dispatch, | ||
"INSTRUCTION_SIZE": self.instruction_size, | ||
} | ||
self.out = out | ||
|
||
|
@@ -357,6 +359,19 @@ def reload_stack( | |
self.emit_reload(storage) | ||
return True | ||
|
||
def instruction_size(self, | ||
tkn: Token, | ||
tkn_iter: TokenIterator, | ||
uop: Uop, | ||
storage: Storage, | ||
inst: Instruction | None | ||
) -> bool: | ||
"""Replace the INSTRUCTION_SIZE macro with the size of the current instruction.""" | ||
size = inst.size if inst else 1 + uop.size | ||
|
||
params = dataclasses.asdict(tkn) | {"text": str(size)} | ||
self.out.emit(Token(**params)) | ||
return True | ||
|
||
def _print_storage(self, storage: Storage) -> None: | ||
if PRINT_STACKS: | ||
self.out.start_line() | ||
|
@@ -496,7 +511,6 @@ def _emit_block( | |
raise analysis_error(ex.args[0], tkn) from None | ||
raise analysis_error("Expecting closing brace. Reached end of file", tkn) | ||
|
||
|
||
def emit_tokens( | ||
self, | ||
uop: Uop, | ||
|
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.
Add a test for another instruction that is a different length, but uses
OP
: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.
Added!
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 test should fail, as the
INSTRUCTION_SIZE
is inconsistent.The tier 2
INSTRUCTION_SIZE
cannot be both 1 and 2.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.
Right, sorry I mistakenly thought it should only fail for tier 2 hence I was only checking the instruction in the tier 2 generator. I extended the check to tier 1 as well and the test now fails as expected.