@@ -44,13 +44,14 @@ def print_usage() -> None:
44
44
Dumps the value of an associated ID, using the C++ Dump() functions.
45
45
46
46
Usage:
47
- dump <CONTEXT> [<EXPR>|-- <EXPR>|<TYPE><ID>|<TYPE> <ID>]
47
+ dump <CONTEXT> [<EXPR>|-- <EXPR>|<TYPE><ID>|<IR>.< TYPE><ID>]
48
48
49
49
Args:
50
50
CONTEXT is the dump context, such a SemIR::Context reference, a SemIR::File,
51
51
a Parse::Context, or a Lex::TokenizeBuffer.
52
52
EXPR is a C++ expression such as a variable name. Use `--` to prevent it from
53
53
being treated as a TYPE and ID.
54
+ IR is the CheckIRId(N) in the form `irN`.
54
55
TYPE can be `inst`, `constant`, `generic`, `impl`, `entity_name`, etc. See
55
56
the `Label` string in `IdBase` classes to find possible TYPE names,
56
57
though only Id types that have a matching `Make...Id()` function are
@@ -74,8 +75,13 @@ def print_usage() -> None:
74
75
75
76
context = args [0 ]
76
77
77
- # The set of "Make" functions in dump.cpp.
78
+ # The set of "Make" functions in dump.cpp. These use ADL to find the factory
79
+ # function in `context/` or in `sem_ir/`.
78
80
id_types = {
81
+ "inst" : "MakeInstId" ,
82
+ }
83
+ # These id types don't have an IdTag embedded in them.
84
+ untagged_id_types = {
79
85
"class" : "SemIR::MakeClassId" ,
80
86
"constant" : "SemIR::MakeConstantId" ,
81
87
"symbolic_constant" : "SemIR::MakeSymbolicConstantId" ,
@@ -85,7 +91,6 @@ def print_usage() -> None:
85
91
"generic" : "SemIR::MakeGenericId" ,
86
92
"impl" : "SemIR::MakeImplId" ,
87
93
"inst_block" : "SemIR::MakeInstBlockId" ,
88
- "inst" : "SemIR::MakeInstId" ,
89
94
"interface" : "SemIR::MakeInterfaceId" ,
90
95
"name" : "SemIR::MakeNameId" ,
91
96
"name_scope" : "SemIR::MakeNameScopeId" ,
@@ -110,27 +115,31 @@ def print_dump(context: str, expr: str) -> None:
110
115
111
116
# Try to find a type + id from the input args. If not, the id will be passed
112
117
# through directly to C++, as it can be a variable name.
113
- id_type = None
118
+ found_id_type = False
114
119
115
- # Look for <type><id> as a single argument.
116
- if m := re .fullmatch ("([a-z_]+)(\\ d+)" , args [1 ]):
117
- if m [1 ] in id_types :
120
+ # Look for <irN>.< type><id> as a single argument.
121
+ if m := re .fullmatch ("ir( \\ d+) \\ . ([a-z_]+)(\\ d+)" , args [1 ]):
122
+ if m [2 ] in id_types :
118
123
if len (args ) != 2 :
119
124
print_usage ()
120
125
return
121
- id_type = m [1 ]
122
- print_dump (context , f"{ id_types [id_type ]} ({ m [2 ]} )" )
126
+ id_type = m [2 ]
127
+ print_dump (
128
+ context , f"{ id_types [id_type ]} ({ context } , { m [1 ]} , { m [3 ]} )"
129
+ )
130
+ found_id_type = True
123
131
124
- # Look for <type> <id> as two arguments .
125
- if not id_type :
126
- if args [1 ] in id_types :
127
- if len (args ) != 3 :
132
+ # Look for <type><id> as a single argument .
133
+ if m := re . fullmatch ( "([a-z_]+)( \\ d+)" , args [ 1 ]) :
134
+ if m [1 ] in untagged_id_types :
135
+ if len (args ) != 2 :
128
136
print_usage ()
129
137
return
130
- id_type = args [1 ]
131
- print_dump (context , f"{ id_types [id_type ]} ({ args [2 ]} )" )
138
+ id_type = m [1 ]
139
+ print_dump (context , f"{ untagged_id_types [id_type ]} ({ m [2 ]} )" )
140
+ found_id_type = True
132
141
133
- if not id_type :
142
+ if not found_id_type :
134
143
# Use `--` to escape a variable name like `inst22`.
135
144
if args [1 ] == "--" :
136
145
expr = " " .join (args [2 :])
0 commit comments