-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Introduce GetElementPtr #9260
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
Merged
Merged
Changes from 2 commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -25,7 +25,8 @@ | |
from mypyc.ir.rtypes import ( | ||
RType, RInstance, RTuple, RVoid, is_bool_rprimitive, is_int_rprimitive, | ||
is_short_int_rprimitive, is_none_rprimitive, object_rprimitive, bool_rprimitive, | ||
short_int_rprimitive, int_rprimitive, void_rtype, is_c_py_ssize_t_rprimitive | ||
short_int_rprimitive, int_rprimitive, void_rtype, is_c_py_ssize_t_rprimitive, | ||
c_pyssize_t_rprimitive | ||
) | ||
from mypyc.common import short_name | ||
|
||
|
@@ -1372,6 +1373,28 @@ def accept(self, visitor: 'OpVisitor[T]') -> T: | |
return visitor.visit_load_mem(self) | ||
|
||
|
||
class GetElementPtr(RegisterOp): | ||
"""Get the address of a struct element""" | ||
error_kind = ERR_NEVER | ||
|
||
def __init__(self, src: Value, src_type: RType, index: int, line: int = -1) -> None: | ||
TH3CHARLie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super().__init__(line) | ||
self.type = c_pyssize_t_rprimitive | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Later on, this can be switched to a dedicated pointer rtype (which is still treated as an integer). |
||
self.src = src | ||
self.src_type = src_type | ||
self.index = index | ||
|
||
def sources(self) -> List[Value]: | ||
return [self.src] | ||
|
||
def to_str(self, env: Environment) -> str: | ||
return env.format("%r = get_element_ptr %r %r :: %r", self, self.src, | ||
self.index, self.src_type) | ||
TH3CHARLie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def accept(self, visitor: 'OpVisitor[T]') -> T: | ||
return visitor.visit_get_element_ptr(self) | ||
|
||
|
||
@trait | ||
class OpVisitor(Generic[T]): | ||
"""Generic visitor over ops (uses the visitor design pattern).""" | ||
|
@@ -1482,6 +1505,10 @@ def visit_binary_int_op(self, op: BinaryIntOp) -> T: | |
def visit_load_mem(self, op: LoadMem) -> T: | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def visit_get_element_ptr(self, op: GetElementPtr) -> T: | ||
raise NotImplementedError | ||
|
||
|
||
# TODO: Should this live somewhere else? | ||
LiteralsMap = Dict[Tuple[Type[object], Union[int, float, str, bytes, complex]], str] | ||
|
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.