Skip to content

Commit 606db35

Browse files
author
rocky
committed
Improve Graal disasembly and graal 3.12 opcodes
1 parent 68992da commit 606db35

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed
1.25 KB
Binary file not shown.
330 Bytes
Binary file not shown.

xdis/bytecode_graal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ def get_instructions_bytes_graal(
193193
arg = 0
194194
break
195195

196+
if arg_count == 0:
197+
arg = None
198+
196199
inst_size = (arg_count + 1) + (extended_arg_count * 2)
197200
start_offset = offset if opc.oppop[opcode] == 0 else None
198201

xdis/instruction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2024 by Rocky Bernstein
1+
# Copyright (c) 2018-2025 by Rocky Bernstein
22
#
33
# This program is free software; you can redistribute it and/or
44
# modify it under the terms of the GNU General Public License
@@ -434,7 +434,7 @@ def disassemble(
434434
new_instruction[-2] = new_repr
435435
new_instruction[-1] = start_offset
436436
del instructions[-1]
437-
# See comment above abut the use of self.__class__
437+
# See comment above about the use of self.__class__
438438
instructions.append(self.__class__(*new_instruction))
439439
argval = self.argval
440440
prefix = "" if argval is None else f"({argval}) | "

xdis/opcodes/opcode_312graal.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,17 @@
443443
#
444444
# Pushes: call result
445445
#
446-
call_op_graal(loc, "CALL_COMPREHENSION", 0x46, 0, 2, 1)
446+
call_op_graal(loc, "CALL_COMPREHENSION", 0x46, 0, 2)
447447
#
448448
# Calls a callable using an arguments array and keywords array.
449449
#
450450
# Pops: keyword args ({@code PKeyword[]}), then args ({@code Object[]}), then callable
451451
#
452452
# Pushes: call result
453453
#
454-
call_op_graal(loc, "CALL_FUNCTION_KW", 0x47, 0, 3, 1)
454+
call_op_graal(loc, "CALL_FUNCTION_KW", 0x47, 0, 3)
455+
arg_counts[0x47] = 0
456+
455457
#
456458
# Calls a callable using an arguments array. No keywords are passed.
457459
#
@@ -650,7 +652,7 @@
650652
# necessary for keyword arguments merge. Note it works with dicts. Keyword arrays need to be
651653
# converted to dicts first.
652654
#
653-
def_op_graal(loc, "KWARGS_DICT_MERGE", 0x5F, 0, 2, 1)
655+
def_op_graal(loc, "KWARGS_DICT_MERGE", 0x5F, 0, 2, 0)
654656
#
655657
# Create a single {@link PKeyword} object. The name is determined by the immediate operand
656658
# which indexes the names array ({@code co_names})
@@ -815,4 +817,9 @@
815817
# FOR_ITER*
816818
# BINARY_SUBSCR*
817819
# and MORE!
820+
821+
# Something is wrong here...
822+
collection_op_graal(loc, "COLLECTION_FROM_COLLECTION", 0xa0, 1, 1, 0)
823+
#
824+
818825
update_sets(loc)

xdis/unmarshal.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,12 @@ def t_code_old_or_graal(self, save_ref, bytes_for_s: bool = False):
10951095
def t_graal_CodeUnit(self, save_ref, bytes_for_s: bool = False):
10961096
"""
10971097
Graal Python code. This has fewer fields than Python
1098-
code. In particular, instructions are JVM bytecode.
1098+
code. Graal Python Bytecode is similar to Python Bytecode for
1099+
a given version, things are a little different, especially when it comes
1100+
to collections. Graal has intructions for homogeneous arrays.
1101+
1102+
Note that Graal's BytecodeCodeUnit has a dumpBytecode() method
1103+
to show assembly instructions.
10991104
"""
11001105

11011106
graal_bytecode_version = self.graal_readByte()

0 commit comments

Comments
 (0)