-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Make dumping work with the irM.instN
tagged InstId format
#6168
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 1 commit
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 |
---|---|---|
|
@@ -44,13 +44,14 @@ def print_usage() -> None: | |
Dumps the value of an associated ID, using the C++ Dump() functions. | ||
|
||
Usage: | ||
dump <CONTEXT> [<EXPR>|-- <EXPR>|<TYPE><ID>|<TYPE> <ID>] | ||
dump <CONTEXT> [<EXPR>|-- <EXPR>|<TYPE><ID>|<IR>.<TYPE><ID>] | ||
|
||
Args: | ||
CONTEXT is the dump context, such a SemIR::Context reference, a SemIR::File, | ||
a Parse::Context, or a Lex::TokenizeBuffer. | ||
EXPR is a C++ expression such as a variable name. Use `--` to prevent it from | ||
being treated as a TYPE and ID. | ||
IR is the CheckIRId(N) in the form `irN`. | ||
|
||
TYPE can be `inst`, `constant`, `generic`, `impl`, `entity_name`, etc. See | ||
the `Label` string in `IdBase` classes to find possible TYPE names, | ||
though only Id types that have a matching `Make...Id()` function are | ||
|
@@ -74,8 +75,13 @@ def print_usage() -> None: | |
|
||
context = args[0] | ||
|
||
# The set of "Make" functions in dump.cpp. | ||
# The set of "Make" functions in dump.cpp. These use ADL to find the factory | ||
# function in `context/` or in `sem_ir/`. | ||
danakj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
id_types = { | ||
"inst": "MakeInstId", | ||
} | ||
# These id types don't have an IdTag embedded in them. | ||
untagged_id_types = { | ||
"class": "SemIR::MakeClassId", | ||
"constant": "SemIR::MakeConstantId", | ||
"symbolic_constant": "SemIR::MakeSymbolicConstantId", | ||
|
@@ -85,7 +91,6 @@ def print_usage() -> None: | |
"generic": "SemIR::MakeGenericId", | ||
"impl": "SemIR::MakeImplId", | ||
"inst_block": "SemIR::MakeInstBlockId", | ||
"inst": "SemIR::MakeInstId", | ||
"interface": "SemIR::MakeInterfaceId", | ||
"name": "SemIR::MakeNameId", | ||
"name_scope": "SemIR::MakeNameScopeId", | ||
|
@@ -110,27 +115,31 @@ def print_dump(context: str, expr: str) -> None: | |
|
||
# Try to find a type + id from the input args. If not, the id will be passed | ||
# through directly to C++, as it can be a variable name. | ||
id_type = None | ||
found_id_type = False | ||
|
||
# Look for <type><id> as a single argument. | ||
if m := re.fullmatch("([a-z_]+)(\\d+)", args[1]): | ||
if m[1] in id_types: | ||
# Look for <irN>.<type><id> as a single argument. | ||
if m := re.fullmatch("ir(\\d+)\\.([a-z_]+)(\\d+)", args[1]): | ||
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. Had you considered making this optional (e.g.. 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. The arguments to the |
||
if m[2] in id_types: | ||
if len(args) != 2: | ||
print_usage() | ||
return | ||
id_type = m[1] | ||
print_dump(context, f"{id_types[id_type]}({m[2]})") | ||
id_type = m[2] | ||
print_dump( | ||
context, f"{id_types[id_type]}({context}, {m[1]}, {m[3]})" | ||
) | ||
found_id_type = True | ||
|
||
# Look for <type> <id> as two arguments. | ||
if not id_type: | ||
if args[1] in id_types: | ||
if len(args) != 3: | ||
# Look for <type><id> as a single argument. | ||
if m := re.fullmatch("([a-z_]+)(\\d+)", args[1]): | ||
if m[1] in untagged_id_types: | ||
danakj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(args) != 2: | ||
print_usage() | ||
return | ||
id_type = args[1] | ||
print_dump(context, f"{id_types[id_type]}({args[2]})") | ||
id_type = m[1] | ||
print_dump(context, f"{untagged_id_types[id_type]}({m[2]})") | ||
found_id_type = True | ||
|
||
if not id_type: | ||
if not found_id_type: | ||
# Use `--` to escape a variable name like `inst22`. | ||
if args[1] == "--": | ||
expr = " ".join(args[2:]) | ||
|
Uh oh!
There was an error while loading. Please reload this page.