Skip to content

Commit 9cb5ef6

Browse files
committedApr 10, 2024
Update to use new introspection API
1 parent b06bf85 commit 9cb5ef6

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed
 

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import com.oracle.graal.python.util.PythonUtils;
7373
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7474
import com.oracle.truffle.api.bytecode.BytecodeIntrospection;
75+
import com.oracle.truffle.api.bytecode.Instruction;
7576
import com.oracle.truffle.api.bytecode.SourceInformation;
7677
import com.oracle.truffle.api.dsl.Bind;
7778
import com.oracle.truffle.api.dsl.Cached;
@@ -353,7 +354,12 @@ Object positions(PCode self) {
353354
List<PTuple> lines = new ArrayList<>();
354355
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
355356
PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction();
356-
for (Instruction instruction : rootNode.getIntrospectionData().getInstructions()) {
357+
for (Instruction instruction : rootNode.getBytecodeNode().getInstructions()) {
358+
if (instruction.isInstrumentation()) {
359+
// Skip instrumented instructions. The co_positions array should agree
360+
// with the logical instruction index.
361+
continue;
362+
}
357363
SourceSection section = rootNode.getSourceSectionForLocation(instruction.getLocation());
358364
lines.add(factory.createTuple(new int[]{
359365
section.getStartLine(),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ public int lastiToLine(int lasti) {
486486
if (funcRootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) {
487487
BytecodeNode bytecodeNode = bytecodeDSLRootNode.getBytecodeNode();
488488
// Emulate CPython's fixed 2-word instructions.
489-
BytecodeLocation location = BytecodeLocation.fromInstructionIndex((lasti + 1) / 2, bytecodeNode);
490-
return location.findSourceLocation().getStartLine();
489+
BytecodeLocation location = bytecodeNode.getBytecodeLocationFromInstructionIndex(lasti / 2);
490+
return location.getSourceLocation().getStartLine();
491491
}
492492
} else if (funcRootNode instanceof PBytecodeRootNode bytecodeRootNode) {
493493
return bytecodeRootNode.bciToLine(bytecodeRootNode.lastiToBci(lasti));

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public static int bciToLasti(int bci, Node location) {
332332
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
333333
if (bci >= 0 && location instanceof BytecodeNode bytecodeNode) {
334334
// Emulate CPython's fixed 2-word instructions.
335-
return bytecodeNode.findInstructionIndex(bci) * 2;
335+
return bytecodeNode.getBytecodeLocation(bci).getInstructionIndex() * 2;
336336
}
337337
} else {
338338
if (location instanceof PBytecodeRootNode bytecodeRootNode) {

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public SourceSection getSourceSectionForLocation(int bci, BytecodeNode bytecodeN
424424
if (bytecodeNode != null) {
425425
BytecodeLocation bytecodeLocation = bytecodeNode.getBytecodeLocation(bci);
426426
if (bytecodeLocation != null) {
427-
sourceSection = bytecodeLocation.findSourceLocation();
427+
sourceSection = bytecodeLocation.getSourceLocation();
428428
}
429429
}
430430

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
import com.oracle.graal.python.nodes.BuiltinNames;
5757
import com.oracle.graal.python.nodes.bytecode.BytecodeFrameInfo;
5858
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
59-
import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo;
60-
import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode;
6159
import com.oracle.graal.python.nodes.call.CallNode;
6260
import com.oracle.graal.python.nodes.exception.TopLevelExceptionHandler;
6361
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
@@ -116,7 +114,7 @@ private static int getLineno(Frame frame, Node location, FrameInstance frameInst
116114
}
117115

118116
if (bytecodeNode != null) {
119-
return bytecodeNode.getBytecodeLocation(frame, location).findSourceLocation().getStartLine();
117+
return bytecodeNode.getBytecodeLocation(frame, location).getSourceLocation().getStartLine();
120118
}
121119
} else {
122120
return ((BytecodeFrameInfo) frameInfo).getLine(frame);

0 commit comments

Comments
 (0)
Failed to load comments.