Search in sources :

Example 6 with LLVMParserException

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

the class LLScanner method parseGlobal.

private void parseGlobal(String line) {
    final Matcher matcher = GLOBAL_NAME_REGEX.matcher(line);
    if (matcher.matches()) {
        String globalName = matcher.group("globalName");
        globalName = LLVMIdentifier.toGlobalIdentifier(globalName);
        map.registerGlobal(globalName);
    } else {
        throw new LLVMParserException(getErrorMessage("global", line));
    }
}
Also used : Matcher(java.util.regex.Matcher) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 7 with LLVMParserException

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

the class LLScanner method parseInstruction.

private void parseInstruction(String line) {
    assert function != null;
    String id = null;
    Matcher matcher = VALUE_NAME_REGEX.matcher(line);
    if (matcher.matches()) {
        id = matcher.group("instructionName");
        id = LLVMIdentifier.toLocalIdentifier(id);
    }
    matcher = OP_NAME_REGEX.matcher(line);
    if (matcher.matches()) {
        id = matcher.group("instructionName");
    }
    if (id != null) {
        function.add(id, currentLine);
    } else {
        throw new LLVMParserException(getErrorMessage("instruction", line));
    }
}
Also used : Matcher(java.util.regex.Matcher) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 8 with LLVMParserException

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

the class LLScanner method findAndScanLLFile.

static LLSourceMap findAndScanLLFile(String bcPath, String pathMappings, LLVMContext context, List<LLVMSourceFileReference> sourceFileReferences) {
    if (bcPath == null) {
        return NOT_FOUND;
    }
    final TruffleFile llFile = findLLPathMapping(bcPath, pathMappings, context);
    if (llFile == null || !llFile.exists() || !llFile.isReadable()) {
        printWarning("Cannot find .ll file for %s (decrease %s logging level to disable this message)\n", bcPath, LLVMContext.llDebugLogger().getName());
        return NOT_FOUND;
    }
    try (BufferedReader llReader = llFile.newBufferedReader()) {
        final Source llSource = Source.newBuilder("llvm", llFile).mimeType("text/x-llvmir").build();
        final LLSourceMap sourceMap = new LLSourceMap(llSource);
        EconomicSet<LLVMSourceFileReference> sourceFileWorkset = createSourceFileSet(sourceFileReferences);
        if (sourceFileWorkset == null) {
            printVerbose("No source file checksums found in %s\n", bcPath);
        }
        final LLScanner scanner = new LLScanner(sourceMap, sourceFileWorkset);
        for (String line = llReader.readLine(); line != null; line = llReader.readLine()) {
            if (!scanner.continueAfter(line)) {
                break;
            }
        }
        if (sourceFileWorkset != null && !sourceFileWorkset.isEmpty()) {
            printVerbose("Checksums in the .ll file (%s) and the .bc file (%s) do not match!\n", llFile, bcPath);
            printVerbose("The following files have changed in the .bc file:\n");
            for (LLVMSourceFileReference sourceFileReference : sourceFileWorkset) {
                printVerbose("  %s\n", LLVMSourceFileReference.toString(sourceFileReference));
            }
        }
        return sourceMap;
    } catch (IOException e) {
        throw new LLVMParserException("Error while reading from file: " + llFile.getPath());
    }
}
Also used : BufferedReader(java.io.BufferedReader) TruffleFile(com.oracle.truffle.api.TruffleFile) IOException(java.io.IOException) LLVMSourceFileReference(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceFileReference) Source(com.oracle.truffle.api.source.Source) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 9 with LLVMParserException

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

the class LLScanner method beginFunction.

private void beginFunction(String line) {
    assert function == null;
    final Matcher matcher = FUNCTION_NAME_REGEX.matcher(line);
    if (matcher.matches()) {
        String functionName = matcher.group("functionNameUnquoted");
        if (functionName == null) {
            functionName = matcher.group("functionNameQuoted");
        }
        functionName = LLVMIdentifier.toGlobalIdentifier(functionName);
        function = new LLSourceMap.Function(functionName, currentLine);
        map.registerFunction(functionName, function);
    } else {
        throw new LLVMParserException(getErrorMessage("function", line));
    }
}
Also used : Matcher(java.util.regex.Matcher) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 10 with LLVMParserException

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

the class LLVMScanner method parseBitcode.

public static void parseBitcode(ByteSequence bitcode, ModelModule model, Source bcSource) {
    final BitStream bitstream = BitStream.create(bitcode);
    final BCFileRoot fileParser = new BCFileRoot(model, bcSource);
    final LLVMScanner scanner = new LLVMScanner(bitstream, fileParser);
    final long actualMagicWord = scanner.read(Integer.SIZE);
    if (actualMagicWord != Magic.BC_MAGIC_WORD.magic) {
        throw new LLVMParserException("Not a valid Bitcode File!");
    }
    scanner.scanToEnd();
    // the root block does not exist in the LLVM file and is therefore never exited by the
    // scanner
    fileParser.exit();
}
Also used : BCFileRoot(com.oracle.truffle.llvm.parser.listeners.BCFileRoot) 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