Search in sources :

Example 6 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class BasicNodeFactory method allocateGlobalIntern.

private static Object allocateGlobalIntern(LLVMParserRuntime runtime, final GlobalValueSymbol global, LLVMSourceSymbol sourceSymbol) {
    final Type resolvedType = ((PointerType) global.getType()).getPointeeType();
    final String name = global.getName();
    LLVMContext context = runtime.getContext();
    if (global.isExternal()) {
        NFIContextExtension nfiContextExtension = context.getContextExtension(NFIContextExtension.class);
        return LLVMGlobal.external(context, global, name, resolvedType, LLVMAddress.fromLong(nfiContextExtension.getNativeHandle(context, name)), sourceSymbol);
    } else {
        return LLVMGlobal.internal(context, global, name, resolvedType, sourceSymbol);
    }
}
Also used : LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) VariableBitWidthType(com.oracle.truffle.llvm.runtime.types.VariableBitWidthType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) LLVMInteropType(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) NFIContextExtension(com.oracle.truffle.llvm.runtime.NFIContextExtension)

Example 7 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class LLVMTruffleInvoke method doInvoke.

@ExplodeLoop
private Object doInvoke(VirtualFrame frame, TruffleObject value, String id, ContextReference<LLVMContext> contextReference, LLVMGetStackNode getStack) {
    Object[] evaluatedArgs = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
        evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
    }
    try {
        LLVMContext context = contextReference.get();
        LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
        Object rawValue;
        try (StackPointer save = stack.newFrame()) {
            rawValue = ForeignAccess.sendInvoke(foreignInvoke, value, id, evaluatedArgs);
        }
        return toLLVM.executeWithTarget(rawValue);
    } catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) ArityException(com.oracle.truffle.api.interop.ArityException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 8 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class LLVMPolyglotImport method doImport.

@Specialization
protected Object doImport(Object name, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
    String symbolName = readString.executeWithTarget(name);
    LLVMContext ctx = ctxRef.get();
    try {
        Object ret = ForeignAccess.sendRead(read, (TruffleObject) ctx.getEnv().getPolyglotBindings(), symbolName);
        return toLLVM.executeWithTarget(ret);
    } catch (InteropException ex) {
        throw ex.raise();
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 9 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class LLVMParserRuntime method parse.

public static LLVMParserResult parse(Source source, ExternalLibrary library, BitcodeParserResult parserResult, LLVMLanguage language, LLVMContext context, NodeFactory nodeFactory) {
    ModelModule model = parserResult.getModel();
    TargetDataLayout layout = model.getTargetDataLayout();
    assert layout != null;
    LLVMModelVisitor module = new LLVMModelVisitor();
    model.accept(module);
    DataLayoutConverter.DataSpecConverterImpl targetDataLayout = DataLayoutConverter.getConverter(layout.getDataLayout());
    context.setDataLayoutConverter(targetDataLayout);
    LLVMParserRuntime runtime = new LLVMParserRuntime(source, library, language, context, nodeFactory, module.getAliases());
    runtime.registerFunctions(model);
    LLVMSymbolReadResolver symbolResolver = new LLVMSymbolReadResolver(runtime, runtime.getGlobalFrameDescriptor());
    LLVMExpressionNode[] globals = runtime.createGlobalVariableInitializationNodes(symbolResolver, module.getGlobals());
    RootNode globalVarInits = nodeFactory.createStaticInitsRootNode(runtime, globals);
    RootCallTarget globalVarInitsTarget = Truffle.getRuntime().createCallTarget(globalVarInits);
    LLVMExpressionNode[] deallocs = runtime.getDeallocations();
    RootNode globalVarDeallocs = nodeFactory.createStaticInitsRootNode(runtime, deallocs);
    RootCallTarget globalVarDeallocsTarget = Truffle.getRuntime().createCallTarget(globalVarDeallocs);
    RootCallTarget constructorFunctions = runtime.getConstructors(module.getGlobals());
    RootCallTarget destructorFunctions = runtime.getDestructors(module.getGlobals());
    if (context.getEnv().getOptions().get(SulongEngineOption.ENABLE_LVI)) {
        final LLVMSourceContext sourceContext = context.getSourceContext();
        model.getSourceGlobals().forEach((symbol, irValue) -> {
            final LLVMExpressionNode node = symbolResolver.resolve(irValue);
            final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
            sourceContext.registerStatic(symbol, value);
        });
        model.getSourceStaticMembers().forEach(((type, symbol) -> {
            final LLVMExpressionNode node = symbolResolver.resolve(symbol);
            final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
            type.setValue(value);
        }));
    }
    RootCallTarget mainFunctionCallTarget = null;
    if (runtime.getScope().functionExists("@main")) {
        LLVMFunctionDescriptor mainDescriptor = runtime.getScope().getFunctionDescriptor("@main");
        LLVMFunctionDescriptor startDescriptor = runtime.getScope().getFunctionDescriptor("@_start");
        RootCallTarget startCallTarget = startDescriptor.getLLVMIRFunction();
        String applicationPath = source.getPath() == null ? "" : source.getPath().toString();
        RootNode globalFunction = nodeFactory.createGlobalRootNode(runtime, startCallTarget, mainDescriptor, applicationPath);
        RootCallTarget globalFunctionRoot = Truffle.getRuntime().createCallTarget(globalFunction);
        RootNode globalRootNode = nodeFactory.createGlobalRootNodeWrapping(runtime, globalFunctionRoot, startDescriptor.getType().getReturnType());
        mainFunctionCallTarget = Truffle.getRuntime().createCallTarget(globalRootNode);
    }
    return new LLVMParserResult(runtime.getScope(), mainFunctionCallTarget, globalVarInitsTarget, globalVarDeallocsTarget, constructorFunctions, destructorFunctions);
}
Also used : GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) DataLayoutConverter(com.oracle.truffle.llvm.runtime.datalayout.DataLayoutConverter) GlobalConstant(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalConstant) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) RootCallTarget(com.oracle.truffle.api.RootCallTarget) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) Pair(com.oracle.truffle.llvm.parser.util.Pair) Linkage(com.oracle.truffle.llvm.parser.model.enums.Linkage) LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) SulongEngineOption(com.oracle.truffle.llvm.runtime.options.SulongEngineOption) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ArrayList(java.util.ArrayList) FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) Type(com.oracle.truffle.llvm.runtime.types.Type) ModelModule(com.oracle.truffle.llvm.parser.model.ModelModule) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext) LLVMLanguage(com.oracle.truffle.llvm.runtime.LLVMLanguage) Map(java.util.Map) RootNode(com.oracle.truffle.api.nodes.RootNode) ArrayConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.ArrayConstant) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) ExternalLibrary(com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) TargetDataLayout(com.oracle.truffle.llvm.parser.model.target.TargetDataLayout) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebugValue) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMScope(com.oracle.truffle.llvm.runtime.LLVMScope) List(java.util.List) Source(com.oracle.truffle.api.source.Source) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) StructureConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.StructureConstant) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) Truffle(com.oracle.truffle.api.Truffle) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) Comparator(java.util.Comparator) RootNode(com.oracle.truffle.api.nodes.RootNode) TargetDataLayout(com.oracle.truffle.llvm.parser.model.target.TargetDataLayout) DataLayoutConverter(com.oracle.truffle.llvm.runtime.datalayout.DataLayoutConverter) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ModelModule(com.oracle.truffle.llvm.parser.model.ModelModule) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebugValue) RootCallTarget(com.oracle.truffle.api.RootCallTarget) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext)

Example 10 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class Sulong method parse.

@Override
protected CallTarget parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest request) throws Exception {
    Source source = request.getSource();
    LLVMContext context = findLLVMContext();
    return (new Runner(getNodeFactory(findLLVMContext().getEnv()))).parse(this, context, source);
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) Source(com.oracle.truffle.api.source.Source)

Aggregations

LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)11 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 NFIContextExtension (com.oracle.truffle.llvm.runtime.NFIContextExtension)4 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 Specialization (com.oracle.truffle.api.dsl.Specialization)2 InteropException (com.oracle.truffle.api.interop.InteropException)2 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)2 Source (com.oracle.truffle.api.source.Source)2 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)2 UnsupportedNativeTypeException (com.oracle.truffle.llvm.runtime.NFIContextExtension.UnsupportedNativeTypeException)2 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)2 Truffle (com.oracle.truffle.api.Truffle)1 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 ArityException (com.oracle.truffle.api.interop.ArityException)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1