Search in sources :

Example 31 with FrameSlot

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());
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) CallTarget(com.oracle.truffle.api.CallTarget) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 32 with FrameSlot

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();
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) FrameInstanceVisitor(com.oracle.truffle.api.frame.FrameInstanceVisitor) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Frame(com.oracle.truffle.api.frame.Frame) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Test(org.junit.Test)

Example 33 with FrameSlot

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());
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) CallTarget(com.oracle.truffle.api.CallTarget) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 34 with FrameSlot

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);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) CallTarget(com.oracle.truffle.api.CallTarget) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 35 with FrameSlot

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);
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMAMD64Target(com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64Target)

Aggregations

FrameSlot (com.oracle.truffle.api.frame.FrameSlot)47 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)12 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)10 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)7 TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Type (com.oracle.truffle.llvm.runtime.types.Type)5 CallTarget (com.oracle.truffle.api.CallTarget)4 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)3 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)3 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 Frame (com.oracle.truffle.api.frame.Frame)2 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2