Search in sources :

Example 11 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.

the class PhiStampInferencePartialEvaluationTest method ifPhiStamp.

@Test
public void ifPhiStamp() {
    /*
         * The stamp of a phi should be inferred during partial evaluation so that its type
         * information can be used to devirtualize method calls.
         */
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new IfPhiStampTestNode();
    RootNode rootNode = new RootTestNode(fd, "ifPhiStamp", result);
    RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    callTarget.call(new Object[] { true });
    callTarget.call(new Object[] { false });
    // ensure method cannot be statically bound without receiver type info
    new D().get();
    assertPartialEvalNoInvokes(callTarget, new Object[] { true });
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 12 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project sulong by graalvm.

the class LLVMRunDestructorFunctions method runDestructorFunctions.

@TruffleBoundary
private void runDestructorFunctions() {
    // is only executed once per context so it will be executed in the interpreter only
    LLVMContext context = getContextReference().get();
    RootCallTarget[] targets = context.getDestructorFunctions().toArray(new RootCallTarget[0]);
    for (RootCallTarget target : targets) {
        try (StackPointer stackPointer = context.getThreadingStack().getStack().newFrame()) {
            callNode.call(target, new Object[] { stackPointer });
        }
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) RootCallTarget(com.oracle.truffle.api.RootCallTarget) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 13 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project sulong by graalvm.

the class LLVMContext method initialize.

public void initialize() {
    assert !initialized && !cleanupNecessary && globalScope.functionExists("@__sulong_init_context");
    if (!initialized) {
        initialized = true;
        cleanupNecessary = true;
        LLVMFunctionDescriptor initContextDescriptor = globalScope.getFunctionDescriptor("@__sulong_init_context");
        RootCallTarget initContextFunction = initContextDescriptor.getLLVMIRFunction();
        try (StackPointer stackPointer = threadingStack.getStack().newFrame()) {
            Object[] args = new Object[] { stackPointer, toTruffleObjects(getApplicationArguments()), toTruffleObjects(getEnvironmentVariables()) };
            initContextFunction.call(args);
        }
    }
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTypedForeignObject(com.oracle.truffle.llvm.runtime.interop.LLVMTypedForeignObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 14 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project sulong by graalvm.

the class NFIIntrinsicsProvider method registerTruffleIntrinsics.

protected void registerTruffleIntrinsics(NodeFactory nodeFactory) {
    LLVMNativeIntrinsicFactory polyglotImport = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_import", LLVMPolyglotImportNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_import", polyglotImport);
    factories.put("@truffle_import", polyglotImport);
    factories.put("@truffle_import_cached", polyglotImport);
    factories.put("@polyglot_export", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_export", LLVMPolyglotExportNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@polyglot_eval", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_eval", LLVMPolyglotEval.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    // 
    factories.put("@polyglot_is_value", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_is_value", LLVMPolyglotIsValueNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_is_number", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_is_number", LLVMPolyglotBoxedPredicateNodeGen.create(new IsNumber(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_is_boolean", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_is_boolean", LLVMPolyglotBoxedPredicateNodeGen.create(new IsBoolean(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_is_string", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_is_string", LLVMPolyglotBoxedPredicateNodeGen.create(new IsString(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_fits_in_i8", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_fits_in_i8", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInI8NodeGen.create(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_fits_in_i16", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_fits_in_i16", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInI16NodeGen.create(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_fits_in_i32", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_fits_in_i32", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInI32NodeGen.create(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_fits_in_i64", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_fits_in_i64", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInI64NodeGen.create(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_fits_in_float", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_fits_in_float", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInFloatNodeGen.create(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_fits_in_double", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_fits_in_double", LLVMPolyglotBoxedPredicateNodeGen.create(FitsInDoubleNodeGen.create(), LLVMArgNodeGen.create(1)));
        }
    });
    LLVMNativeIntrinsicFactory polyglotPutMember = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_put_member", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    };
    factories.put("@polyglot_put_member", polyglotPutMember);
    factories.put("@truffle_write", polyglotPutMember);
    factories.put("@truffle_write_i", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_i", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_l", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_l", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_c", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_c", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_f", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_f", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_d", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("truffle_write_d", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_b", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_b", LLVMTruffleWriteToNameNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    LLVMNativeIntrinsicFactory polyglotSetArrayElement = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_set_array_element", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    };
    factories.put("@polyglot_set_array_element", polyglotSetArrayElement);
    factories.put("@truffle_write_idx", polyglotSetArrayElement);
    factories.put("@truffle_write_idx_i", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_idx_i", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_idx_l", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_idx_l", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_idx_c", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_idx_c", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_idx_f", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_idx_f", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_idx_d", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_idx_d", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    factories.put("@truffle_write_idx_b", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_write_idx_b", LLVMTruffleWriteToIndexNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    LLVMNativeIntrinsicFactory polyglotGetMember = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_get_member", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.POINTER), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    };
    factories.put("@polyglot_get_member", polyglotGetMember);
    factories.put("@truffle_read", polyglotGetMember);
    factories.put("@truffle_read_i", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_i", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_l", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_l", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_c", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_c", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_f", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_f", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_d", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_d", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_b", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_b", LLVMTruffleReadFromNameNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    LLVMNativeIntrinsicFactory polyglotGetArrayElement = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_get_array_element", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.POINTER), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    };
    factories.put("@polyglot_get_array_element", polyglotGetArrayElement);
    factories.put("@truffle_read_idx", polyglotGetArrayElement);
    factories.put("@truffle_read_idx_i", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_idx_i", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_idx_l", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_idx_l", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_idx_c", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_idx_c", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_idx_f", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_idx_f", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_idx_d", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_idx_d", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_idx_b", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_idx_b", LLVMTruffleReadFromIndexNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    LLVMNativeIntrinsicFactory polyglotAsI8 = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_as_i8", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_as_i8", polyglotAsI8);
    factories.put("@truffle_unbox_c", polyglotAsI8);
    LLVMNativeIntrinsicFactory polyglotAsI16 = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_as_i16", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I16), LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_as_i16", polyglotAsI16);
    LLVMNativeIntrinsicFactory polyglotAsI32 = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_as_i32", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_as_i32", polyglotAsI32);
    factories.put("@truffle_unbox_i", polyglotAsI32);
    LLVMNativeIntrinsicFactory polyglotAsI64 = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_as_i64", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_as_i64", polyglotAsI64);
    factories.put("@truffle_unbox_l", polyglotAsI64);
    LLVMNativeIntrinsicFactory polyglotAsFloat = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_as_float", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_as_float", polyglotAsFloat);
    factories.put("@truffle_unbox_f", polyglotAsFloat);
    LLVMNativeIntrinsicFactory polyglotAsDouble = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_as_double", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_as_double", polyglotAsDouble);
    factories.put("@truffle_unbox_d", polyglotAsDouble);
    LLVMNativeIntrinsicFactory polyglotAsBoolean = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_as_boolean", LLVMTruffleUnboxNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_as_boolean", polyglotAsBoolean);
    factories.put("@truffle_unbox_b", polyglotAsBoolean);
    // 
    LLVMNativeIntrinsicFactory polyglotInvoke = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_invoke", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.POINTER), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    };
    factories.put("@polyglot_invoke", polyglotInvoke);
    factories.put("@truffle_invoke", polyglotInvoke);
    factories.put("@truffle_invoke_i", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_invoke_i", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_invoke_l", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_invoke_l", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_invoke_c", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_invoke_c", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_invoke_f", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_invoke_f", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_invoke_d", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_invoke_d", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_invoke_b", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_invoke_b", LLVMTruffleInvokeNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), argumentsArray(3, type.getArgumentTypes().length - 3), LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    // 
    factories.put("@truffle_execute", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_execute", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.POINTER), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_execute_i", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_execute_i", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I32), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_execute_l", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_execute_l", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I64), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_execute_c", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_execute_c", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I8), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_execute_f", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_execute_f", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.FLOAT), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_execute_d", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_execute_d", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.DOUBLE), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_execute_b", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_execute_b", LLVMTruffleExecuteNodeGen.create(ForeignToLLVM.create(ForeignToLLVMType.I1), argumentsArray(2, type.getArgumentTypes().length - 2), LLVMArgNodeGen.create(1)));
        }
    });
    // 
    factories.put("@truffle_address_to_function", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_address_to_function", LLVMTruffleAddressToFunctionNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    LLVMNativeIntrinsicFactory polyglotCanExecute = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_can_execute", LLVMTruffleIsExecutableNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_can_execute", polyglotCanExecute);
    factories.put("@truffle_is_executable", polyglotCanExecute);
    LLVMNativeIntrinsicFactory polyglotIsNull = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_is_null", LLVMTruffleIsNullNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_is_null", polyglotIsNull);
    factories.put("@truffle_is_null", polyglotIsNull);
    LLVMNativeIntrinsicFactory polyglotHasArrayElements = new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_has_array_elements", LLVMTruffleHasSizeNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    };
    factories.put("@polyglot_has_array_elements", polyglotHasArrayElements);
    factories.put("@truffle_has_size", polyglotHasArrayElements);
    factories.put("@polyglot_has_members", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_has_members", LLVMTruffleHasKeysNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_is_boxed", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_is_boxed", LLVMTruffleIsBoxedNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_get_array_size", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_get_array_size", LLVMTruffleGetSizeNodeGen.create(ForeignToLLVMType.I64, LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_get_size", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_get_size", LLVMTruffleGetSizeNodeGen.create(ForeignToLLVMType.I32, LLVMArgNodeGen.create(1)));
        }
    });
    // 
    factories.put("@polyglot_get_string_size", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_get_string_size", LLVMPolyglotGetStringSizeNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@polyglot_as_string", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_as_string", LLVMPolyglotAsString.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3), LLVMArgNodeGen.create(4)));
        }
    });
    factories.put("@polyglot_from_string", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_from_string", LLVMPolyglotFromString.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@polyglot_from_string_n", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@polyglot_from_string", LLVMPolyglotFromString.createN(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
    // 
    factories.put("@truffle_read_string", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_string", LLVMTruffleReadStringNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_read_n_string", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_n_string", LLVMTruffleReadNStringNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_read_bytes", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_bytes", LLVMTruffleReadBytesNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_read_n_bytes", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_read_n_bytes", LLVMTruffleReadNBytesNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_string_to_cstr", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_string_to_cstr", LLVMTruffleStringAsCStringNodeGen.create(nodeFactory.createAllocateString(), LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_free_cstr", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_free_cstr", LLVMTruffleFreeCStringNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_is_truffle_object", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_is_truffle_object", LLVMTruffleIsTruffleObjectNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_sulong_function_to_native_pointer", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_sulong_function_to_native_pointer", LLVMSulongFunctionToNativePointerNodeGen.create(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@truffle_load_library", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_load_library", LLVMLoadLibraryNodeGen.create(LLVMArgNodeGen.create(1)));
        }
    });
    factories.put("@truffle_polyglot_eval", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@truffle_polyglot_eval", LLVMPolyglotEval.createLegacy(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    // 
    factories.put("@__polyglot_as_typed", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@__polyglot_as_typed", LLVMPolyglotAsTyped.createStruct(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@__polyglot_as_typed_array", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@__polyglot_as_typed_array", LLVMPolyglotAsTyped.createArray(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@__polyglot_from_typed", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@__polyglot_from_typed", LLVMPolyglotFromTyped.createStruct(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2)));
        }
    });
    factories.put("@__polyglot_from_typed_array", new LLVMNativeIntrinsicFactory(true, true) {

        @Override
        protected RootCallTarget generate(FunctionType type) {
            return wrap("@__polyglot_from_typed_array", LLVMPolyglotFromTyped.createArray(LLVMArgNodeGen.create(1), LLVMArgNodeGen.create(2), LLVMArgNodeGen.create(3)));
        }
    });
}
Also used : IsBoolean(com.oracle.truffle.llvm.nodes.intrinsics.interop.LLVMPolyglotBoxedPredicate.IsBoolean) IsNumber(com.oracle.truffle.llvm.nodes.intrinsics.interop.LLVMPolyglotBoxedPredicate.IsNumber) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) IsString(com.oracle.truffle.llvm.nodes.intrinsics.interop.LLVMPolyglotBoxedPredicate.IsString) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 15 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project TrufflePascal by Aspect26.

the class SubroutineDescriptor method setRootNode.

public void setRootNode(RootNode rootNode) {
    RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    this.subroutine = new PascalSubroutine(callTarget);
}
Also used : PascalSubroutine(cz.cuni.mff.d3s.trupple.language.runtime.customvalues.PascalSubroutine) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Aggregations

RootCallTarget (com.oracle.truffle.api.RootCallTarget)26 RootNode (com.oracle.truffle.api.nodes.RootNode)8 CallTarget (com.oracle.truffle.api.CallTarget)4 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)4 Source (com.oracle.truffle.api.source.Source)4 Test (org.junit.Test)4 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)3 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 SourceSection (com.oracle.truffle.api.source.SourceSection)2 GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)2 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)2 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)2 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)2 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Truffle (com.oracle.truffle.api.Truffle)1 TruffleContext (com.oracle.truffle.api.TruffleContext)1 Env (com.oracle.truffle.api.TruffleLanguage.Env)1 ControlFlowException (com.oracle.truffle.api.nodes.ControlFlowException)1