Skip to content

Commit 1231e10

Browse files
msimacektomasstupka
authored andcommitted
Track SourceRanges in the compiler
1 parent f2ea10f commit 1231e10

File tree

3 files changed

+98
-98
lines changed

3 files changed

+98
-98
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
import com.oracle.graal.python.pegparser.scope.Scope;
6363
import com.oracle.graal.python.pegparser.scope.ScopeEnvironment;
64+
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
6465

6566
public final class CompilationUnit {
6667
final String name;
@@ -87,11 +88,11 @@ public final class CompilationUnit {
8788
Block currentBlock = startBlock;
8889
int maxStackSize = 0;
8990

90-
final int startOffset;
91-
int currentOffset;
91+
SourceRange startLocation;
92+
SourceRange currentLocation;
9293

9394
CompilationUnit(CompilationScope scopeType, Scope scope, String name, CompilationUnit parent, int scopeDepth, int argCount, int positionalOnlyArgCount, int kwOnlyArgCount, boolean takesVarArgs,
94-
boolean takesVarKeywordArgs, int startOffset) {
95+
boolean takesVarKeywordArgs, SourceRange startLocation) {
9596
this.scopeType = scopeType;
9697
this.scope = scope;
9798
this.name = name;
@@ -100,8 +101,8 @@ public final class CompilationUnit {
100101
this.kwOnlyArgCount = kwOnlyArgCount;
101102
this.takesVarArgs = takesVarArgs;
102103
this.takesVarKeywordArgs = takesVarKeywordArgs;
103-
this.startOffset = startOffset;
104-
currentOffset = startOffset;
104+
this.startLocation = startLocation;
105+
currentLocation = startLocation;
105106

106107
if (scopeType == Class) {
107108
privateName = name;
@@ -168,8 +169,8 @@ private void addImplicitReturn() {
168169
b = b.next;
169170
}
170171
if (!b.isReturn()) {
171-
b.instr.add(new Instruction(OpCodes.LOAD_NONE, 0, null, null, 0));
172-
b.instr.add(new Instruction(OpCodes.RETURN_VALUE, 0, null, null, 0));
172+
b.instr.add(new Instruction(OpCodes.LOAD_NONE, 0, null, null, currentLocation));
173+
b.instr.add(new Instruction(OpCodes.RETURN_VALUE, 0, null, null, currentLocation));
173174
}
174175
}
175176

@@ -196,7 +197,7 @@ public CodeUnit assemble(int flags) {
196197

197198
Block b = startBlock;
198199
HashMap<Block, List<Block>> handlerBlocks = new HashMap<>();
199-
int lastSrcOffset = startOffset;
200+
int lastSrcOffset = startLocation.startOffset;
200201
while (b != null) {
201202
b.startBci = buf.size();
202203
BlockInfo.AbstractExceptionHandler handler = b.findExceptionHandler();
@@ -223,8 +224,8 @@ public CodeUnit assemble(int flags) {
223224
}
224225
for (Instruction i : b.instr) {
225226
emitBytecode(i, buf);
226-
insertSrcOffsetTable(i.srcOffset, lastSrcOffset, srcOffsets);
227-
lastSrcOffset = i.srcOffset;
227+
insertSrcOffsetTable(i.location.startOffset, lastSrcOffset, srcOffsets);
228+
lastSrcOffset = i.location.startOffset;
228229
}
229230
b.endBci = buf.size();
230231
b = b.next;
@@ -256,7 +257,7 @@ public CodeUnit assemble(int flags) {
256257
orderedKeys(constants, new Object[0]),
257258
orderedLong(primitiveConstants),
258259
exceptionHandlerRanges,
259-
startOffset);
260+
startLocation.startOffset);
260261
}
261262

262263
private void addExceptionRange(Collection<short[]> finishedExceptionHandlerRanges, int start, int end, int handler, int stackLevel) {
@@ -343,7 +344,7 @@ private void calculateJumpInstructionArguments() {
343344
if (target != null) {
344345
int targetPos = blockLocationMap.get(target);
345346
int distance = Math.abs(bci + instr.extensions() * 2 - targetPos);
346-
Instruction newInstr = new Instruction(instr.opcode, distance, instr.followingArgs, instr.target, instr.srcOffset);
347+
Instruction newInstr = new Instruction(instr.opcode, distance, instr.followingArgs, instr.target, instr.location);
347348
if (newInstr.extendedLength() != instr.extendedLength()) {
348349
repeat = true;
349350
}

0 commit comments

Comments
 (0)