Search in sources :

Example 16 with LLVMParserException

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

the class Function method createAlloca.

private void createAlloca(RecordBuffer buffer) {
    long typeRecord = buffer.read();
    // type of count
    buffer.read();
    int count = getIndexAbsolute(buffer.read());
    long alignRecord = buffer.read();
    int align = getAlign(alignRecord & ~ALLOCA_FLAGSMASK);
    Type type = types.get(typeRecord);
    if ((alignRecord & ALLOCA_EXPLICITTYPEMASK) != 0L) {
        type = new PointerType(type);
    } else if (!(type instanceof PointerType)) {
        throw new LLVMParserException("Alloca with unexpected type: " + type);
    }
    emit(AllocateInstruction.fromSymbols(scope.getSymbols(), type, count, align));
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 17 with LLVMParserException

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

the class Module method skip.

@Override
public void skip(Block block, LLVMScanner.LazyScanner lazyScanner) {
    if (block == Block.FUNCTION) {
        if (functionQueue.isEmpty()) {
            throw new LLVMParserException("Missing Function Prototype in Bitcode File!");
        }
        final FunctionDefinition definition = functionQueue.removeFirst();
        module.addFunctionParser(definition, new LazyFunctionParser(lazyScanner, scope, types, definition, mode, paramAttributes, llSource));
    } else {
        ParserListener.super.skip(block, lazyScanner);
    }
}
Also used : LazyFunctionParser(com.oracle.truffle.llvm.parser.model.functions.LazyFunctionParser) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 18 with LLVMParserException

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

the class BlockAddressConstant method fromSymbols.

public static BlockAddressConstant fromSymbols(SymbolTable symbols, Type type, int function, int block) {
    final BlockAddressConstant constant = new BlockAddressConstant(type, block);
    final SymbolImpl functionSymbol = symbols.getForwardReferenced(function, constant);
    if (functionSymbol instanceof FunctionDefinition) {
        constant.function = (FunctionDefinition) functionSymbol;
    } else {
        throw new LLVMParserException("Illegal symbol for function in BlockAddressConstant: " + functionSymbol);
    }
    return constant;
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 19 with LLVMParserException

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

the class AggregateConstant method createFromData.

public static AggregateConstant createFromData(Type type, RecordBuffer buffer) {
    final AggregateConstant aggregateConstant;
    final Type elementType;
    if (type instanceof ArrayType) {
        final ArrayType arrayType = (ArrayType) type;
        elementType = arrayType.getElementType();
        aggregateConstant = new ArrayConstant(arrayType, buffer.size());
    } else if (type instanceof VectorType) {
        final VectorType vectorType = (VectorType) type;
        elementType = vectorType.getElementType();
        aggregateConstant = new VectorConstant((VectorType) type, buffer.size());
    } else {
        throw new LLVMParserException("Cannot create constant from data: " + type);
    }
    if (Type.isIntegerType(elementType)) {
        for (int i = 0; i < aggregateConstant.elements.length; i++) {
            aggregateConstant.elements[i] = IntegerConstant.createFromData(elementType, buffer);
        }
    } else if (Type.isFloatingpointType(elementType)) {
        for (int i = 0; i < aggregateConstant.elements.length; i++) {
            aggregateConstant.elements[i] = FloatingPointConstant.create(elementType, buffer);
        }
    } else {
        throw new LLVMParserException("No datum constant implementation for " + type);
    }
    return aggregateConstant;
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) Type(com.oracle.truffle.llvm.runtime.types.Type) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 20 with LLVMParserException

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

the class LoadModulesNode method loadModule.

@SuppressWarnings("unchecked")
private LLVMScopeChain loadModule(VirtualFrame frame, LLVMContext context) {
    stackAccess.executeEnter(frame, getContext().getThreadingStack().getStack());
    try {
        LLVMLoadingPhase phase;
        // instead of creating a llvm local scope, just create a llvm scope here, and then put
        // it inside the chains
        LLVMScopeChain headLocalScopeChain = null;
        LLVMScopeChain tailLocalScopeChain = null;
        BitSet visited = null;
        ArrayDeque<CallTarget> que = null;
        ArrayList<CallTarget> dependencies = null;
        LLVMScopeChain headResultScopeChain = null;
        LLVMScopeChain tailResultScopeChain = null;
        RTLDFlags localOrGlobal = RTLDFlags.RTLD_OPEN_DEFAULT;
        // check for arguments for dlOpen
        if (frame.getArguments().length > 0 && (frame.getArguments()[0] instanceof RTLDFlags)) {
            localOrGlobal = (RTLDFlags) frame.getArguments()[0];
        }
        /*
             * The arguments in the frames for every loading phase include: 1) The current loading
             * phase. 2) The visited set. The scope building, the external symbol, and overwriting
             * symbol phases all require an additional argument: 3) The RTLD flag, if the library is
             * loaded with RTLD_LOCAL or RTLD_GLOBAL. The scope building phase also have: 4) The
             * tail of the linked structure for local scope. 5) The que of library dependencies. 6)
             * The tail of the linked structure for returning result scope. The external symbol and
             * overwriting symbol phases require instead: 4) The head of the linked structure for
             * local scope.
             */
        if (frame.getArguments().length > 0 && (frame.getArguments()[0] instanceof LLVMLoadingPhase)) {
            phase = (LLVMLoadingPhase) frame.getArguments()[0];
            if (phase == LLVMLoadingPhase.BUILD_SCOPES || phase == LLVMLoadingPhase.BUILD_DEPENDENCY) {
                visited = (BitSet) frame.getArguments()[1];
            }
            if (phase == LLVMLoadingPhase.INIT_EXTERNALS || phase == LLVMLoadingPhase.INIT_OVERWRITE) {
                localOrGlobal = (RTLDFlags) frame.getArguments()[1];
                headLocalScopeChain = (LLVMScopeChain) frame.getArguments()[2];
            }
            if (phase == LLVMLoadingPhase.BUILD_SCOPES) {
                localOrGlobal = (RTLDFlags) frame.getArguments()[2];
            }
            if (phase == LLVMLoadingPhase.BUILD_DEPENDENCY) {
                dependencies = (ArrayList<CallTarget>) frame.getArguments()[2];
            }
            // Additional arguments are required for building the scopes.
            if (phase == LLVMLoadingPhase.BUILD_SCOPES) {
                tailLocalScopeChain = (LLVMScopeChain) frame.getArguments()[3];
                que = (ArrayDeque<CallTarget>) frame.getArguments()[4];
                tailResultScopeChain = (LLVMScopeChain) frame.getArguments()[5];
            }
        // For the root library, it is defined when either the frame has no argument, or
        // when the first argument is not one of the loading phases.
        } else if (frame.getArguments().length == 0 || !(frame.getArguments()[0] instanceof LLVMLoadingPhase)) {
            // create first and last of the scope chain.
            phase = LLVMLoadingPhase.ALL;
            headResultScopeChain = new LLVMScopeChain(bitcodeID, parserRuntime.getFileScope());
            tailResultScopeChain = headResultScopeChain;
            headLocalScopeChain = new LLVMScopeChain(bitcodeID, parserRuntime.getPublicFileScope());
            tailLocalScopeChain = headLocalScopeChain;
            visited = createBitset(libraryDependencies.length);
            que = new ArrayDeque<>();
            dependencies = new ArrayList<>();
        } else {
            throw new LLVMParserException("LoadModulesNode is called with unexpected arguments");
        }
        /*
             * The scope is built in parsing order, which requires breadth-first with a que.
             */
        if (LLVMLoadingPhase.BUILD_SCOPES.isActive(phase)) {
            int id = bitcodeID.getId();
            if (!visited.get(id)) {
                visited.set(id);
                if (LLVMLoadingPhase.ALL.isActive(phase)) {
                    context.addGlobalScope(new LLVMScopeChain(bitcodeID, parserRuntime.getPublicFileScope()));
                } else {
                    LLVMScopeChain currentLocalScopeChain = new LLVMScopeChain(bitcodeID, parserRuntime.getPublicFileScope());
                    LLVMScopeChain currentResultScopeChain = new LLVMScopeChain(bitcodeID, parserRuntime.getFileScope());
                    if (RTLDFlags.RTLD_OPEN_DEFAULT.isActive(localOrGlobal)) {
                        context.addGlobalScope(new LLVMScopeChain(bitcodeID, parserRuntime.getPublicFileScope()));
                        tailLocalScopeChain.concatNextChain(currentLocalScopeChain);
                        tailResultScopeChain.concatNextChain(currentResultScopeChain);
                    } else if (RTLDFlags.RTLD_LOCAL.isActive(localOrGlobal)) {
                        tailLocalScopeChain.concatNextChain(currentLocalScopeChain);
                    } else if (RTLDFlags.RTLD_GLOBAL.isActive(localOrGlobal)) {
                        tailLocalScopeChain.concatNextChain(currentLocalScopeChain);
                        context.addGlobalScope(new LLVMScopeChain(bitcodeID, parserRuntime.getPublicFileScope()));
                    } else {
                        throw new LLVMParserException(this, "Toplevel executable %s does not contain bitcode");
                    }
                }
                for (int i = 0; i < libraryDependencies.length; i++) {
                    CallTarget callTarget = libraryDependencies[i].execute();
                    if (callTarget != null) {
                        queAdd(que, callTarget);
                    }
                }
                if (LLVMLoadingPhase.ALL.isActive(phase)) {
                    while (!que.isEmpty()) {
                        // Foward the tail scope chain to the latest scope chain.
                        while (tailLocalScopeChain != null && tailLocalScopeChain.getNext() != null) {
                            tailLocalScopeChain = tailLocalScopeChain.getNext();
                        }
                        while (tailResultScopeChain != null && tailResultScopeChain.getNext() != null) {
                            tailResultScopeChain = tailResultScopeChain.getNext();
                        }
                        indirectCall.call(quePoll(que), LLVMLoadingPhase.BUILD_SCOPES, visited, localOrGlobal, tailLocalScopeChain, que, tailResultScopeChain);
                    }
                }
            }
        }
        if (context.isLibraryAlreadyLoaded(bitcodeID)) {
            if (RTLDFlags.RTLD_OPEN_DEFAULT.isActive(localOrGlobal)) {
                return headResultScopeChain;
            } else {
                return headLocalScopeChain;
            }
        }
        if (LLVMLoadingPhase.BUILD_DEPENDENCY.isActive(phase)) {
            if (LLVMLoadingPhase.ALL == phase) {
                visited.clear();
            }
            int id = bitcodeID.getId();
            if (!visited.get(id)) {
                visited.set(id);
                for (LoadDependencyNode libraryDependency : libraryDependencies) {
                    CallTarget lib = libraryDependency.execute();
                    if (lib != null) {
                        callDependencies.call(lib, LLVMLoadingPhase.BUILD_DEPENDENCY, visited, dependencies);
                    }
                }
                dependencies.add(this.getCallTarget());
            }
        }
        /*
             * The order of the initialization nodes is very important. The defined symbols and the
             * external symbols must be initialized before the global symbols can be initialized.
             * The overwriting of symbols can only be done once all the globals are initialized and
             * the symbol table has been allocated.
             */
        switch(phase) {
            case BUILD_SCOPES:
            case BUILD_DEPENDENCY:
                break;
            case ALL:
                assert dependencies != null;
                executeInitialiseAllPhase(dependencies, localOrGlobal, headLocalScopeChain);
                break;
            case INIT_SYMBOLS:
                executeInitialiseSymbolPhase(context);
                break;
            case INIT_EXTERNALS:
                initExternals.execute(context, headLocalScopeChain, localOrGlobal);
                break;
            case INIT_GLOBALS:
                initGlobals.execute(frame, context.getReadOnlyGlobals(bitcodeID));
                break;
            case INIT_OVERWRITE:
                initOverwrite.execute(context, headLocalScopeChain, localOrGlobal);
                break;
            case INIT_CONTEXT:
                initContext.execute(frame);
                break;
            case INIT_MODULE:
                initModules.execute(frame, context);
                break;
            case INIT_DONE:
                context.markLibraryLoaded(bitcodeID);
                break;
            default:
                throw CompilerDirectives.shouldNotReachHere("Unknown loading phase");
        }
        if (LLVMLoadingPhase.ALL == phase) {
            if (RTLDFlags.RTLD_OPEN_DEFAULT.isActive(localOrGlobal)) {
                return headResultScopeChain;
            } else {
                return headLocalScopeChain;
            }
        }
        return null;
    } finally {
        stackAccess.executeExit(frame);
    }
}
Also used : RTLDFlags(com.oracle.truffle.llvm.runtime.nodes.intrinsics.c.LLVMDLOpen.RTLDFlags) LLVMScopeChain(com.oracle.truffle.llvm.runtime.LLVMScopeChain) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Aggregations

LLVMParserException (com.oracle.truffle.llvm.runtime.except.LLVMParserException)32 Type (com.oracle.truffle.llvm.runtime.types.Type)12 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)11 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)10 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)10 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)9 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)9 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)7 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)6 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)6 ArrayList (java.util.ArrayList)6 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)5 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)5 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)5 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)4 TypeArrayBuilder (com.oracle.truffle.llvm.runtime.types.Type.TypeArrayBuilder)3 Matcher (java.util.regex.Matcher)3 CallTarget (com.oracle.truffle.api.CallTarget)2 TruffleFile (com.oracle.truffle.api.TruffleFile)2