Search in sources :

Example 1 with LLVMPolyglotException

use of com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException in project graal by oracle.

the class LLVMPolyglotEval method doEval.

@Specialization
protected Object doEval(Object idPointer, Object srcPointer, @Cached("createReadString()") LLVMReadStringNode readId, @Cached("createReadString()") LLVMReadStringNode readSrc, @Cached("createForeignToLLVM()") ForeignToLLVM toLLVM, @Cached BranchProfile exception) {
    try {
        CallTarget callTarget = getSource.execute(readId.executeWithTarget(idPointer), readSrc.executeWithTarget(srcPointer));
        Object foreign = callTarget.call();
        return toLLVM.executeWithTarget(foreign);
    } catch (IllegalStateException e) {
        // language id not found
        exception.enter();
        throw new LLVMPolyglotException(this, e.getMessage());
    }
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) LLVMPolyglotException(com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 2 with LLVMPolyglotException

use of com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException in project graal by oracle.

the class LLVMPolyglotNewInstance method doNew.

@Specialization
@ExplodeLoop
protected Object doNew(VirtualFrame frame, LLVMManagedPointer value, @Cached("createForeignToLLVM()") ForeignToLLVM toLLVM, @Cached BranchProfile exception) {
    Object foreign = asForeign.execute(value);
    Object[] evaluatedArgs = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
        evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
    }
    try {
        Object rawValue;
        rawValue = foreignNewInstance.instantiate(foreign, evaluatedArgs);
        return toLLVM.executeWithTarget(rawValue);
    } catch (UnsupportedMessageException e) {
        exception.enter();
        throw new LLVMPolyglotException(this, "Polyglot value cannot be instantiated.");
    } catch (UnsupportedTypeException e) {
        exception.enter();
        throw new LLVMPolyglotException(this, "Wrong argument type passed to polyglot_new_instance.");
    } catch (ArityException e) {
        exception.enter();
        throw new LLVMPolyglotException(this, "Wrong number of arguments passed to polyglot_new_instance, expected %d but got %d.", e.getExpectedMinArity(), e.getActualArity());
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) LLVMPolyglotException(com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException) ArityException(com.oracle.truffle.api.interop.ArityException) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 3 with LLVMPolyglotException

use of com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException in project graal by oracle.

the class LLVMPolyglotExport method doExport.

@Specialization
@GenerateAOT.Exclude
protected Object doExport(Object name, Object value, @CachedLibrary(limit = "3") InteropLibrary interop, @Cached BranchProfile exception) {
    String symbolName = readString.executeWithTarget(name);
    Object escaped = escape.executeWithTarget(value);
    try {
        interop.writeMember(getContext().getEnv().getPolyglotBindings(), symbolName, escaped);
    } catch (InteropException ex) {
        exception.enter();
        throw new LLVMPolyglotException(this, ex.getMessage());
    }
    return null;
}
Also used : LLVMPolyglotException(com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException) InteropException(com.oracle.truffle.api.interop.InteropException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 4 with LLVMPolyglotException

use of com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException in project graal by oracle.

the class LLVMTruffleWriteManagedToSymbol method write.

@TruffleBoundary
@Specialization
protected Object write(LLVMPointer address, Object value) {
    /*
         * The list of symbols should be all global symbols or all function symbols more over, the
         * list of symbols should all be pointing to the same value or function code, and they
         * should all have the same name.
         */
    List<LLVMSymbol> symbols = getContext().removeSymbolReverseMap(address);
    if (symbols == null) {
        throw new LLVMPolyglotException(this, "First argument to truffle_assign_managed must be a pointer to a symbol.");
    }
    Object newValue = value;
    boolean allGlobals = symbols.get(0).isGlobalVariable();
    LLVMContext ctx = LLVMContext.get(this);
    /*
         * The interop type of the global symbol has to be attached to the new object that's
         * replacing the global. This is done by creating a LLVMTypedForeignObject wrapping it
         * around the new object with the global's interop type.
         */
    if (allGlobals) {
        newValue = attachType.execute(value, symbols.get(0).asGlobalVariable().getInteropType(ctx));
    }
    /*
         * Every symbol in the symbol list should point to the same value even if they are stored in
         * different locations in the symbol table.
         */
    for (LLVMSymbol symbol : symbols) {
        assert allGlobals ? symbol.isGlobalVariable() : symbol.isFunction();
        ctx.setSymbol(symbol, LLVMPointer.cast(newValue));
    }
    ctx.registerSymbolReverseMap(symbols, LLVMPointer.cast(value));
    return newValue;
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) LLVMPolyglotException(com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Specialization (com.oracle.truffle.api.dsl.Specialization)4 LLVMPolyglotException (com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException)4 CallTarget (com.oracle.truffle.api.CallTarget)1 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 ArityException (com.oracle.truffle.api.interop.ArityException)1 InteropException (com.oracle.truffle.api.interop.InteropException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)1 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)1