use of com.oracle.truffle.api.frame.FrameSlot in project graal by oracle.
the class ReturnTypeSpecializationTest method test.
@Test
public void test() {
TruffleRuntime runtime = Truffle.getRuntime();
FrameDescriptor frameDescriptor = new FrameDescriptor();
FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int);
TestRootNode rootNode = new TestRootNode(frameDescriptor, new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot));
CallTarget target = runtime.createCallTarget(rootNode);
Assert.assertEquals(FrameSlotKind.Int, slot.getKind());
Object result = target.call();
Assert.assertEquals("42", result);
Assert.assertEquals(FrameSlotKind.Object, slot.getKind());
}
use of com.oracle.truffle.api.frame.FrameSlot in project graal by oracle.
the class StackTraceTest method testFrameAccess.
@Test
public void testFrameAccess() {
CallTarget callTarget = createCallTarget(new TestCallWithCallTargetNode(null));
CallTarget indirect = createCallTarget(new TestCallWithIndirectTargetNode(callTarget));
CallTarget direct = createCallTarget(new TestCallWithDirectTargetNode(indirect));
CallTarget test = createCallTarget(new TestCallNode(null) {
@Override
Object execute(VirtualFrame frame) {
Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Object>() {
@SuppressWarnings("deprecation")
public Object visitFrame(FrameInstance frameInstance) {
Assert.assertNull(frameInstance.getFrame(FrameAccess.NONE));
Frame readOnlyFrame = frameInstance.getFrame(FrameAccess.READ_ONLY);
FrameSlot slot = readOnlyFrame.getFrameDescriptor().findFrameSlot("demo");
Assert.assertEquals(42, readOnlyFrame.getValue(slot));
Frame readWriteFrame = frameInstance.getFrame(FrameAccess.READ_WRITE);
Assert.assertEquals(42, readWriteFrame.getValue(slot));
readWriteFrame.setObject(slot, 43);
Frame materializedFrame = frameInstance.getFrame(FrameAccess.MATERIALIZE);
Assert.assertEquals(43, materializedFrame.getValue(slot));
materializedFrame.setObject(slot, 44);
Assert.assertEquals(44, readOnlyFrame.getValue(slot));
Assert.assertEquals(44, readWriteFrame.getValue(slot));
return null;
}
});
return null;
}
});
findTestCallNode(callTarget).setNext(test);
direct.call();
}
use of com.oracle.truffle.api.frame.FrameSlot in project graal by oracle.
the class FrameSlotTypeSpecializationTest method test.
@Test
public void test() {
TruffleRuntime runtime = Truffle.getRuntime();
FrameDescriptor frameDescriptor = new FrameDescriptor();
FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int);
TestRootNode rootNode = new TestRootNode(frameDescriptor, new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot));
CallTarget target = runtime.createCallTarget(rootNode);
Assert.assertEquals(FrameSlotKind.Int, slot.getKind());
Object result = target.call();
Assert.assertEquals("42", result);
Assert.assertEquals(FrameSlotKind.Object, slot.getKind());
}
use of com.oracle.truffle.api.frame.FrameSlot in project graal by oracle.
the class FrameTest method test.
@Test
public void test() throws SecurityException, IllegalArgumentException {
TruffleRuntime runtime = Truffle.getRuntime();
FrameDescriptor frameDescriptor = new FrameDescriptor();
String varName = "localVar";
FrameSlot slot = frameDescriptor.addFrameSlot(varName, FrameSlotKind.Int);
TestRootNode rootNode = new TestRootNode(frameDescriptor, new AssignLocal(slot), new ReadLocal(slot));
CallTarget target = runtime.createCallTarget(rootNode);
Object result = target.call();
Assert.assertEquals(42, result);
frameDescriptor.removeFrameSlot(varName);
boolean slotMissing = false;
try {
result = target.call();
} catch (IllegalArgumentException iae) {
slotMissing = true;
}
Assert.assertTrue(slotMissing);
}
use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.
the class AsmFactory method getTarget.
private LLVMAMD64Target getTarget(Type type, AsmOperand operand) {
if (operand instanceof AsmRegisterOperand) {
AsmRegisterOperand op = (AsmRegisterOperand) operand;
FrameSlot frame = getRegisterSlot(op.getBaseRegister());
int shift = op.getShift();
assert type == op.getType();
switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
case I8:
return new LLVMAMD64Target(frame, shift);
case I16:
case I32:
case I64:
return new LLVMAMD64Target(frame);
default:
throw new AsmParseException("unsupported operand type: " + op.getType());
}
} else if (operand instanceof AsmArgumentOperand) {
AsmArgumentOperand op = (AsmArgumentOperand) operand;
Argument info = argInfo.get(op.getIndex());
if (info.isMemory()) {
LLVMExpressionNode address = info.getAddress();
if (type instanceof PointerType) {
return new LLVMAMD64Target(address);
}
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
case I16:
case I32:
case I64:
return new LLVMAMD64Target(address);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else if (info.isRegister()) {
FrameSlot frame = getRegisterSlot(info.getRegister());
if (type instanceof PointerType || info.getType() instanceof PointerType) {
return new LLVMAMD64Target(frame);
}
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
case I16:
case I32:
case I64:
return new LLVMAMD64Target(frame);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else {
throw new AssertionError("this should not happen; " + info);
}
}
throw new AsmParseException("unsupported operand type: " + operand);
}
Aggregations