Search in sources :

Example 1 with BinaryParserResult

use of com.oracle.truffle.llvm.parser.binary.BinaryParserResult in project graal by oracle.

the class ParserDriver method parseLibraryWithSource.

/**
 * Parses a single bitcode module and returns its {@link LLVMParserResult}. Explicit and
 * implicit dependencies of {@code lib} are added to the . The returned {@link LLVMParserResult}
 * is also added to the.
 *
 * @param source the {@link Source} of the library to be parsed
 * @param bytes the bytes of the library to be parsed
 * @return the parser result corresponding to {@code lib}
 */
private LLVMParserResult parseLibraryWithSource(Source source, ByteSequence bytes) {
    BinaryParserResult binaryParserResult = BinaryParser.parse(bytes, source, context);
    if (binaryParserResult != null) {
        context.addLibraryPaths(binaryParserResult.getLibraryPaths());
        TruffleFile file = createTruffleFile(binaryParserResult.getLibraryName(), source.getPath(), binaryParserResult.getLocator(), "<source library>");
        processDependencies(binaryParserResult.getLibraryName(), file, binaryParserResult);
        return parseBinary(binaryParserResult, file);
    } else {
        LibraryLocator.traceDelegateNative(context, source);
        return null;
    }
}
Also used : BinaryParserResult(com.oracle.truffle.llvm.parser.binary.BinaryParserResult) TruffleFile(com.oracle.truffle.api.TruffleFile)

Example 2 with BinaryParserResult

use of com.oracle.truffle.llvm.parser.binary.BinaryParserResult in project graal by oracle.

the class ExtractBitcode method main.

public static void main(String[] args) {
    if (args.length != 2) {
        usage(System.err);
        System.exit(1);
    }
    try {
        String inName = args[0];
        String outName = args[1];
        InputStream in = inName.equals("-") ? System.in : new FileInputStream(inName);
        OutputStream out = outName.equals("-") ? System.out : new FileOutputStream(outName);
        ByteSequence bytes = readFully(in);
        BinaryParserResult result = BinaryParser.parse(bytes, null, null);
        if (result == null) {
            throw new IOException("No bitcode found in file '" + inName + "'");
        }
        out.write(result.getBitcode().toByteArray());
    } catch (IOException e) {
        System.err.println(e.getMessage());
        System.exit(2);
    }
}
Also used : BinaryParserResult(com.oracle.truffle.llvm.parser.binary.BinaryParserResult) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ByteSequence(org.graalvm.polyglot.io.ByteSequence)

Aggregations

BinaryParserResult (com.oracle.truffle.llvm.parser.binary.BinaryParserResult)2 TruffleFile (com.oracle.truffle.api.TruffleFile)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ByteSequence (org.graalvm.polyglot.io.ByteSequence)1