Skip to content

Commit d51d6e5

Browse files
committed
CodeUnit: propagate source line number to PCode level
1 parent 667ab67 commit d51d6e5

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,9 @@ private CodeUnit readCodeUnit() {
11841184
long[] primitiveConstants = readLongArray();
11851185
short[] exceptionHandlerRanges = readShortArray();
11861186
int startOffset = readInt();
1187+
int startLine = readInt();
11871188
return new CodeUnit(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, stacksize, code, srcOffsetTable,
1188-
flags, names, varnames, cellvars, freevars, cell2arg, constants, primitiveConstants, exceptionHandlerRanges, startOffset);
1189+
flags, names, varnames, cellvars, freevars, cell2arg, constants, primitiveConstants, exceptionHandlerRanges, startOffset, startLine);
11891190
}
11901191

11911192
private void writeCodeUnit(CodeUnit code) throws IOException {
@@ -1212,6 +1213,7 @@ private void writeCodeUnit(CodeUnit code) throws IOException {
12121213
writeLongArray(code.primitiveConstants);
12131214
writeShortArray(code.exceptionHandlerRanges);
12141215
writeInt(code.startOffset);
1216+
writeInt(code.startLine);
12151217
}
12161218

12171219
private PCode readCode() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private static String getSourceSectionFileName(SourceSection src) {
253253
private static int extractFirstLineno(RootNode rootNode) {
254254
RootNode funcRootNode = rootNodeForExtraction(rootNode);
255255
if (funcRootNode instanceof PBytecodeRootNode) {
256-
return ((PBytecodeRootNode) funcRootNode).getStartOffset();
256+
return ((PBytecodeRootNode) funcRootNode).getCodeUnit().startLine;
257257
}
258258
SourceSection sourceSection = funcRootNode.getSourceSection();
259259
if (sourceSection != null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public final class CodeUnit {
9797
public final short[] exceptionHandlerRanges;
9898

9999
public final int startOffset;
100+
public final int startLine;
100101

101102
public final boolean lambda;
102103

@@ -105,7 +106,7 @@ public CodeUnit(TruffleString name, TruffleString qualname,
105106
byte[] code, byte[] linetable, int flags,
106107
TruffleString[] names, TruffleString[] varnames, TruffleString[] cellvars, TruffleString[] freevars, int[] cell2arg,
107108
Object[] constants, long[] primitiveConstants,
108-
short[] exceptionHandlerRanges, int startOffset) {
109+
short[] exceptionHandlerRanges, int startOffset, int startLine) {
109110
this.name = name;
110111
this.qualname = qualname != null ? qualname : name;
111112
this.argCount = argCount;
@@ -124,6 +125,7 @@ public CodeUnit(TruffleString name, TruffleString qualname,
124125
this.primitiveConstants = primitiveConstants;
125126
this.exceptionHandlerRanges = exceptionHandlerRanges;
126127
this.startOffset = startOffset;
128+
this.startLine = startLine;
127129
this.lambda = name.equalsUncached(BuiltinNames.T_LAMBDA_NAME, TS_ENCODING);
128130
}
129131

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CompilationUnit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ public CodeUnit assemble(int flags) {
260260
orderedKeys(constants, new Object[0]),
261261
orderedLong(primitiveConstants),
262262
exceptionHandlerRanges,
263-
startLocation.startOffset);
263+
startLocation.startOffset,
264+
startLocation.startLine);
264265
}
265266

266267
private void addExceptionRange(Collection<short[]> finishedExceptionHandlerRanges, int start, int end, int handler, int stackLevel) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ public final PCode createCode(RootCallTarget ct, int flags, int firstlineno, byt
10981098

10991099
public final PCode createCode(RootCallTarget callTarget, Signature signature, CodeUnit codeUnit) {
11001100
return createCode(callTarget, signature, codeUnit.varnames.length, codeUnit.stacksize, -1, codeUnit.constants, codeUnit.names,
1101-
codeUnit.varnames, codeUnit.freevars, codeUnit.cellvars, null, codeUnit.name, codeUnit.startOffset, codeUnit.srcOffsetTable);
1101+
codeUnit.varnames, codeUnit.freevars, codeUnit.cellvars, null, codeUnit.name, codeUnit.startLine, codeUnit.srcOffsetTable);
11021102
}
11031103

11041104
public final PCode createCode(RootCallTarget callTarget, Signature signature, int nlocals, int stacksize, int flags, Object[] constants, Object[] names, Object[] varnames,

0 commit comments

Comments
 (0)