File tree Expand file tree Collapse file tree 3 files changed +30
-10
lines changed
Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -536,7 +536,6 @@ def get_instructions_bytes(
536536 yield instruction
537537 offset = next_offset (instruction .opcode , opc , instruction .offset )
538538
539-
540539class Bytecode :
541540 """Bytecode operations involving a Python code object.
542541
Original file line number Diff line number Diff line change 66from xdis .lineoffsets_graal import find_linestarts_graal
77from xdis .opcodes .base_graal import (
88 BINARY_OPS ,
9- COLLECTION_KIND ,
109 UNARY_OPS ,
10+ collection_to_str ,
1111 get_optype_graal ,
1212)
1313
@@ -167,7 +167,7 @@ def get_instructions_bytes_graal(
167167
168168 elif optype == "collection" :
169169 argval = arg
170- argrepr = COLLECTION_KIND . get (arg , "??" )
170+ argrepr = collection_to_str (arg )
171171 break
172172 elif opcode == opc .opmap ["UNPACK_EX" ]:
173173 argrepr = "%d, %d" % (arg , Byte .toUnsignedInt (following_args [0 ]))
Original file line number Diff line number Diff line change @@ -128,22 +128,43 @@ def findlabels(bytecode, opc):
128128 33 : "INPLACE_MATMUL" ,
129129}
130130
131+ COLLECTION_KIND_SHIFT = 5
132+ COLLECTION_KIND_MASK = (1 << COLLECTION_KIND_SHIFT ) - 1
131133COLLECTION_KIND = {
132- 32 : "list" ,
133- 67 : "tuple" , # Probably need to use a mask
134- 99 : "tuple" , # probably need to use a mask
135- 3 : "set" ,
136- 4 : "dict" ,
137- 5 : "kw" ,
138- 6 : "object" ,
134+ 0b001 : "list" ,
135+ 0b010 : "tuple" , # Probably need to use a mask
136+ 0b011 : "set" ,
137+ 0b100 : "dict" ,
138+ 0b101 : "PKeyword" ,
139+ 0b110 : "Object" ,
140+ # #
141+ # 99: "tuple", # probably need to use a mask
142+ # 160: "object",
143+ # 192: "object",
139144}
140145
146+ COLLECTION_KIND_ELEMENT = {
147+ 0 : "" ,
148+ 1 : "int" ,
149+ 2 : "long" ,
150+ 3 : "boolean" ,
151+ 4 : "double" ,
152+ 5 : "object"
153+ }
154+
155+
141156UNARY_OPS = {
142157 0 : "NOT" ,
143158 31 : "IS" ,
144159 30 : "IN" ,
145160}
146161
162+ def collection_to_str (collection_value : int ) -> str :
163+ kind = collection_value >> COLLECTION_KIND_SHIFT
164+ kind_str = COLLECTION_KIND .get (kind , "??" )
165+ element_type = collection_value & COLLECTION_KIND_MASK
166+ element_str = COLLECTION_KIND_ELEMENT .get (element_type , "??" )
167+ return f"{ kind_str } [{ element_str } ]"
147168
148169def binary_op_graal (
149170 loc : dict ,
You can’t perform that action at this time.
0 commit comments