@@ -354,12 +354,21 @@ def graal_readStringArray(self) -> tuple[str, ...]:
354354 Python equvalent of Python Graal's readObjectArray() from
355355 MarshalModuleBuiltins.java
356356 """
357- length : int = int ( unpack ( "<i" , self .fp . read ( 4 ))[ 0 ] )
357+ length : int = self .graal_readInt ( )
358358 return tuple ([self .graal_readString () for _ in range (length )])
359359
360- def graal_readSparseTable (self ):
361- """ """
362- pass
360+ def graal_readSparseTable (self ) -> Dict [int , tuple ]:
361+ """
362+ Python equvalent of Python Graal's readObjectArray() from
363+ MarshalModuleBuiltins.java
364+ """
365+ self .graal_readInt () # the length return value isn't used.
366+ table = {} # new int[length][];
367+ while True :
368+ i = self .graal_readInt ()
369+ if i == - 1 :
370+ return table
371+ table [i ] = self .graal_readIntArray ()
363372
364373 def load (self ):
365374 """
@@ -876,6 +885,8 @@ def t_code_graal(self, save_ref, bytes_for_s: bool = False):
876885 else :
877886 code = self .t_graal_CodeUnit (save_ref = False , bytes_for_s = False )
878887 assert self .graal_code_info ["co_flags" ] == code .co_flags
888+
889+ # FIXME: add an assert self.fp.tell() has advanced to save_position?
879890 self .fp .seek (saved_position )
880891
881892 self .code_to_file_offsets [code ] = (
@@ -995,20 +1006,20 @@ def t_graal_CodeUnit(self, save_ref, bytes_for_s: bool = False):
9951006 code. In particular, instructions are JVM bytecode.
9961007 """
9971008
998- # This is Java code for how a CodeUnit (type "U") is dumped
999- # writeByte(Compiler.BYTECODE_VERSION);
1000- # writeString(code.name);
1001- # writeString(code.qualname);
1002- # writeInt(code.argCount);
1003- # writeInt(code.kwOnlyArgCount);
1004- # writeInt(code.positionalOnlyArgCount);
1005- # writeInt(code.stacksize);
1006- # writeBytes(code.code);
1007- # writeBytes(code.srcOffsetTable);
1008- # writeInt(code.flags);
1009-
10101009 graal_bytecode_version = self .graal_readByte ()
10111010 assert (21000 + graal_bytecode_version * 10 ) in GRAAL3_MAGICS
1011+
1012+ # This is Java code for how a CodeUnit (type "U") is read
1013+ # TruffleString name = readString();
1014+ # TruffleString qualname = readString();
1015+ # int argCount = readInt();
1016+ # int kwOnlyArgCount = readInt();
1017+ # int positionalOnlyArgCount = readInt();
1018+ # int stacksize = readInt();
1019+ # byte[] code = readBytes();
1020+ # byte[] srcOffsetTable = readBytes();
1021+ # int flags = readInt();
1022+
10121023 co_name = self .graal_readString ()
10131024 co_qualname = self .graal_readString ()
10141025 co_argcount = self .graal_readInt ()
@@ -1031,12 +1042,11 @@ def t_graal_CodeUnit(self, save_ref, bytes_for_s: bool = False):
10311042 co_cellvars = self .graal_readStringArray ()
10321043 co_freevars = self .graal_readStringArray ()
10331044
1034- # if (code.cell2arg != null) {
1035- # writeIntArray(code.cell2arg);
1036- # } else {
1037- # writeIntArray(PythonUtils.EMPTY_INT_ARRAY);
1038- # }
1039- # writeObjectArray(code.constants);
1045+ # int[] cell2arg = readIntArray();
1046+ # if (cell2arg.length == 0) {
1047+ # cell2arg = null;
1048+ # }
1049+ # Object[] constants = readObjectArray();
10401050
10411051 cell2arg = self .graal_readIntArray ()
10421052 co_consts = self .graal_readObjectArray ()
@@ -1069,23 +1079,23 @@ def t_graal_CodeUnit(self, save_ref, bytes_for_s: bool = False):
10691079 [self .graal_code_info ["co_codeunit_position" ], co_code_offset_in_file ]
10701080 )
10711081
1072- # writeLongArray(code.primitiveConstants);
1073- # writeIntArray(code.exceptionHandlerRanges);
1074- # writeInt(code.conditionProfileCount);
1075- # writeInt(code.startLine);
1076- # writeInt(code.startColumn);
1077- # writeInt(code.endLine);
1078- # writeInt(code.endColumn);
1079- # writeBytes(code.outputCanQuicken);
1080- # writeBytes(code.variableShouldUnbox);
1081- # writeSparseTable(code.generalizeInputsMap);
1082- # writeSparseTable(code.generalizeVarsMap);
1083-
10841082 # The data from the below is not used, but we run the
10851083 # the extraction to keep the self.fp location where it should for
10861084 # the situation that we have code objects inside the codes' co_consts
10871085 # table marshaled as an ObjectArray.
10881086
1087+ # long[] primitiveConstants = readLongArray();
1088+ # int[] exceptionHandlerRanges = readIntArray();
1089+ # int conditionProfileCount = readInt();
1090+ # int startLine = readInt();
1091+ # int startColumn = readInt();
1092+ # int endLine = readInt();
1093+ # int endColumn = readInt();
1094+ # byte[] outputCanQuicken = readBytes();
1095+ # byte[] variableShouldUnbox = readBytes();
1096+ # int[][] generalizeInputsMap = readSparseTable();
1097+ # int[][] generalizeVarsMap = readSparseTable();
1098+
10891099 primitive_constants = self .graal_readLongArray ()
10901100 exception_handler_ranges = self .graal_readIntArray ()
10911101 condition_profileCount = self .graal_readInt ()
0 commit comments