Skip to content

Commit

Permalink
Update to use new introspection API
Browse files Browse the repository at this point in the history
  • Loading branch information
DSouzaM committed Apr 5, 2024
1 parent 3bec5b4 commit f7c84aa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.bytecode.introspection.BytecodeIntrospection;
import com.oracle.truffle.api.bytecode.introspection.Instruction;
import com.oracle.truffle.api.bytecode.introspection.SourceInformation;
import com.oracle.truffle.api.bytecode.BytecodeIntrospection;
import com.oracle.truffle.api.bytecode.Instruction;
import com.oracle.truffle.api.bytecode.SourceInformation;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
Expand Down Expand Up @@ -354,7 +354,12 @@ Object positions(PCode self) {
List<PTuple> lines = new ArrayList<>();
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction();
for (Instruction instruction : rootNode.getIntrospectionData().getInstructions()) {
for (Instruction instruction : rootNode.getBytecodeNode().getInstructions()) {
if (instruction.isInstrumentation()) {
// Skip instrumented instructions. The co_positions array should agree
// with the logical instruction index.
continue;
}
SourceSection section = rootNode.getSourceSectionForLocation(instruction.getLocation());
lines.add(factory.createTuple(new int[]{
section.getStartLine(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ public int lastiToLine(int lasti) {
if (funcRootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) {
BytecodeNode bytecodeNode = bytecodeDSLRootNode.getBytecodeNode();
// Emulate CPython's fixed 2-word instructions.
BytecodeLocation location = BytecodeLocation.fromInstructionIndex((lasti + 1) / 2, bytecodeNode);
return location.findSourceLocation().getStartLine();
BytecodeLocation location = bytecodeNode.getBytecodeLocationFromInstructionIndex(lasti / 2);
return location.getSourceLocation().getStartLine();
}
} else if (funcRootNode instanceof PBytecodeRootNode bytecodeRootNode) {
return bytecodeRootNode.bciToLine(bytecodeRootNode.lastiToBci(lasti));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public static int bciToLasti(int bci, Node location) {
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
if (bci >= 0 && location instanceof BytecodeNode bytecodeNode) {
// Emulate CPython's fixed 2-word instructions.
return bytecodeNode.findInstructionIndex(bci) * 2;
return bytecodeNode.getBytecodeLocation(bci).getInstructionIndex() * 2;
}
} else {
if (location instanceof PBytecodeRootNode bytecodeRootNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public SourceSection getSourceSectionForLocation(int bci, BytecodeNode bytecodeN
if (bytecodeNode != null) {
BytecodeLocation bytecodeLocation = bytecodeNode.getBytecodeLocation(bci);
if (bytecodeLocation != null) {
sourceSection = bytecodeLocation.findSourceLocation();
sourceSection = bytecodeLocation.getSourceLocation();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
import com.oracle.graal.python.nodes.BuiltinNames;
import com.oracle.graal.python.nodes.bytecode.BytecodeFrameInfo;
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo;
import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode;
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.exception.TopLevelExceptionHandler;
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
Expand Down Expand Up @@ -116,7 +114,7 @@ private static int getLineno(Frame frame, Node location, FrameInstance frameInst
}

if (bytecodeNode != null) {
return bytecodeNode.getBytecodeLocation(frame, location).findSourceLocation().getStartLine();
return bytecodeNode.getBytecodeLocation(frame, location).getSourceLocation().getStartLine();
}
} else {
return ((BytecodeFrameInfo) frameInfo).getLine(frame);
Expand Down

0 comments on commit f7c84aa

Please sign in to comment.