Skip to content

Commit d48d528

Browse files
author
rocky
committed
Go over Graal bytecodes more.
1 parent 9cc9bd8 commit d48d528

File tree

7 files changed

+102
-82
lines changed

7 files changed

+102
-82
lines changed

xdis/bytecode_graal.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_instructions_bytes_graal(
7575
if opcode == opc.opmap["EXTENDED_ARG"]:
7676
argrepr = ""
7777
break
78-
elif opcode in (opc.opmap["LOAD_BYTE_0"], opc.opmap["LOAD_BYTE_I"]):
78+
elif opcode in (opc.opmap["LOAD_BYTE_O"], opc.opmap["LOAD_BYTE_I"]):
7979
argrepr = str(arg)
8080
argval = arg
8181
break
@@ -129,26 +129,27 @@ def get_instructions_bytes_graal(
129129
argrepr = names[arg]
130130
break
131131
elif opcode == opc.opmap["FORMAT_VALUE"]:
132-
kind = arg & FormatOptions.FVC_MASK
133-
if kind == opc.FormatOptions.FVC_ST:
132+
argval = arg
133+
kind = arg & 0x3
134+
if kind ==0x1:
134135
argrepr = "STR"
135136
break
136-
elif kind == opc.FormatOptions.FVC_REP:
137+
elif kind == 0x2:
137138
argrepr = "REPR"
138139
break
139-
elif opcode == opc.FormatOptions.FVC_ASCII:
140+
elif kind == 0x3:
140141
argrepr = "ASCII"
141142
break
142-
elif opcode == opc.FormatOptions.FVC_NONE:
143+
elif kind == 0:
143144
argrepr = "NONE"
144145
break
145146

146-
if (arg & FormatOptions.FVS_MASK) == FormatOptions.FVS_HAVE_SPEC:
147+
if (arg & 0x4) == 0x4:
147148
argrepr += " + SPEC"
148149
break
149150

150151
elif opcode == opc.opmap["CALL_METHOD"]:
151-
argrepr = "%2d" % arg
152+
argrepr = str(arg)
152153
break
153154

154155
elif opcode == "unary":

xdis/disasm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from xdis.codetype.base import iscode
3939
from xdis.cross_dis import format_code_info, format_exception_table
4040
from xdis.load import check_object_path, load_module
41-
from xdis.magics import PYTHON_MAGIC_INT
41+
from xdis.magics import GRAAL3_MAGICS, PYTHON_MAGIC_INT
4242
from xdis.op_imports import op_imports, remap_opcodes
4343
from xdis.version import __version__
4444
from xdis.version_info import (
@@ -198,7 +198,7 @@ def disco(
198198
show_source=show_source,
199199
methods=methods,
200200
file_offsets=file_offsets,
201-
is_unusual_bytecode=magic_int in (21290,),
201+
is_unusual_bytecode=magic_int in GRAAL3_MAGICS
202202
)
203203

204204

xdis/opcodes/opcode_310graal.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
# Performs subscript get operation - {@code a[b]}.
9292
# Pops: {@code b}, then {@code a}
9393
# Pushes: result
94-
def_op_graal(loc, "BINARY_SUBSCR", 0x8, 0, 2, 1)
94+
def_op_graal(loc, "BINARY_SUBSCR", 0x8, 1, 2, 0)
9595

9696
# Performs subscript set operation - {@code a[b] = c}.
9797
# Pops: {@code b}, then {@code a}, then {@code c}
@@ -118,8 +118,7 @@
118118
def_op_graal(loc, "GET_AWAITABLE", 0xD, 0, 1, 1)
119119

120120
# Pushes: {@code __build_class__} builtin
121-
# def_op_graal(loc, "LOAD_BUILD_CLASS", 0xe, 0, 0, 1)
122-
def_op_graal(loc, "LOAD_BUILD_CLASS", 0xE, 0, 0, 1) # This is wrong
121+
def_op_graal(loc, "LOAD_BUILD_CLASS", 0xE, 0, 1, 0)
123122

124123
# Pushes: {@code AssertionError} builtin exception type
125124
def_op_graal(loc, "LOAD_ASSERTION_ERROR", 0xF, 0, 0, 1)
@@ -256,7 +255,7 @@
256255
# {@link FormatOptions}.
257256
# Pushes: the formatted value
258257
def_op_graal(
259-
loc, "FORMAT_VALUE", 0x27, 1
258+
loc, "FORMAT_VALUE", 0x27, 2, 1, 1
260259
) # , (oparg, followingArgs, withJump) -> (oparg & FormatOptions.FVS_MASK) == FormatOptions.FVS_HAVE_SPEC ? 2 : 1, 1)
261260

262261
# Extends the immediate operand of the following instruction by its own operand shifted left by
@@ -276,7 +275,7 @@
276275
# names array ({@code co_names}).
277276
# Pops: module object
278277
# Pushes: module object, imported object
279-
name_op_graal(loc, "IMPORT_FROM", 0x2B, 1, 1, 2)
278+
name_op_graal(loc, "IMPORT_FROM", 0x2B, 1, 1, 1)
280279

281280
# Imports all names from a module of name determined by the immediate operand which indexes the
282281
# names array ({@code co_names}). The imported names are written to locals dict (can only be
@@ -436,7 +435,7 @@
436435
#
437436
# Pushes: call result
438437
#
439-
def_op_graal(loc, "CALL_FUNCTION_VARARGS", 0x4F, 0, 2, 1)
438+
def_op_graal(loc, "CALL_FUNCTION_VARARGS", 0x4F, 0, 2, 0)
440439

441440
# ----------------------
442441
# destructuring bytecodes
@@ -760,10 +759,14 @@
760759

761760
# Loads signed byte from immediate operand.
762761
#
763-
def_op_graal(loc, "LOAD_BYTE_0", 0x70, 1, 0, 1)
764-
#
762+
def_op_graal(loc, "LOAD_TRUE_O", 0x6C, 1, 0, 0)
763+
def_op_graal(loc, "LOAD_TRUE_B", 0x6D, 1, 0, 0)
764+
def_op_graal(loc, "LOAD_FALSE_O", 0x6E, 1, 0, 0)
765+
def_op_graal(loc, "LOAD_FALSE_B", 0x6F, 1, 0, 0)
766+
def_op_graal(loc, "LOAD_BYTE_O", 0x70, 1, 0, 1)
765767
def_op_graal(loc, "LOAD_BYTE_I", 0x71, 1, 0, 1)
766-
#
768+
def_op_graal(loc, "LOAD_INT_O", 0x72, 1, 0, 1)
769+
def_op_graal(loc, "LOAD_BYTE_I", 0x73, 1, 0, 1)
767770

768771

769772
update_sets(loc)

xdis/opcodes/opcode_311graal.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@
129129
def_op_graal(loc, "GET_ANEXT", 0xf, 0, 1, 1)
130130

131131
# Pushes: {@code __build_class__} builtin
132-
# def_op_graal(loc, "LOAD_BUILD_CLASS", 0xe, 0, 0, 1)
133-
def_op_graal(loc, "LOAD_BUILD_CLASS", 0x10, 0, 0, 1) # This is wrong
132+
def_op_graal(loc, "LOAD_BUILD_CLASS", 0x10, 0, 1, 0)
134133

135134
# Pushes: {@code AssertionError} builtin exception type
136135
def_op_graal(loc, "LOAD_ASSERTION_ERROR", 0x11, 0, 0, 1)
@@ -259,7 +258,7 @@
259258
# immediate operand values are illegal.
260259
# Pushes: the created slice object
261260
def_op_graal(
262-
loc, "BUILD_SLICE", 0x26, 1
261+
loc, "BUILD_SLICE", 0x26, 1, 0, 1
263262
) # (oparg, followingArgs, withJump) -> oparg, 1)
264263

265264
# Formats a value. If the immediate argument contains flag {@link FormatOptions#FVS_HAVE_SPEC},
@@ -269,7 +268,7 @@
269268
# {@link FormatOptions}.
270269
# Pushes: the formatted value
271270
def_op_graal(
272-
loc, "FORMAT_VALUE", 0x27, 1
271+
loc, "FORMAT_VALUE", 0x27, 2, 1, 1
273272
) # , (oparg, followingArgs, withJump) -> (oparg & FormatOptions.FVS_MASK) == FormatOptions.FVS_HAVE_SPEC ? 2 : 1, 1)
274273

275274
# Extends the immediate operand of the following instruction by its own operand shifted left by
@@ -289,7 +288,7 @@
289288
# names array ({@code co_names}).
290289
# Pops: module object
291290
# Pushes: module object, imported object
292-
name_op_graal(loc, "IMPORT_FROM", 0x2A, 1, 1, 2)
291+
name_op_graal(loc, "IMPORT_FROM", 0x2A, 1, 1, 1)
293292

294293
# Imports all names from a module of name determined by the immediate operand which indexes the
295294
# names array ({@code co_names}). The imported names are written to locals dict (can only be
@@ -449,7 +448,7 @@
449448
#
450449
# Pushes: call result
451450
#
452-
def_op_graal(loc, "CALL_FUNCTION_VARARGS", 0x46, 0, 2, 1)
451+
def_op_graal(loc, "CALL_FUNCTION_VARARGS", 0x46, 0, 2, 0)
453452

454453
# ----------------------
455454
# destructuring bytecodes
@@ -785,10 +784,14 @@
785784

786785
# Loads signed byte from immediate operand.
787786
#
788-
def_op_graal(loc, "LOAD_BYTE_0", 0x70, 1, 0, 1)
789-
#
787+
def_op_graal(loc, "LOAD_TRUE_O", 0x6C, 1, 0, 0)
788+
def_op_graal(loc, "LOAD_TRUE_B", 0x6D, 1, 0, 0)
789+
def_op_graal(loc, "LOAD_FALSE_O", 0x6E, 1, 0, 0)
790+
def_op_graal(loc, "LOAD_FALSE_B", 0x6F, 1, 0, 0)
791+
def_op_graal(loc, "LOAD_BYTE_O", 0x70, 1, 0, 1)
790792
def_op_graal(loc, "LOAD_BYTE_I", 0x71, 1, 0, 1)
791-
#
793+
def_op_graal(loc, "LOAD_INT_O", 0x72, 1, 0, 1)
794+
def_op_graal(loc, "LOAD_INT_I", 0x78, 1, 0, 1)
792795

793796

794797
update_sets(loc)

0 commit comments

Comments
 (0)