Search in sources :

Example 1 with LLVMParserResult

use of com.oracle.truffle.llvm.parser.LLVMParserResult in project sulong by graalvm.

the class Runner method parse.

private LLVMParserResult parse(LLVMLanguage language, LLVMContext context, Source source, ExternalLibrary library, ByteBuffer bytes) throws IOException {
    assert library != null;
    BitcodeParserResult bitcodeParserResult = BitcodeParserResult.getFromSource(source, bytes);
    context.addLibraryPaths(bitcodeParserResult.getLibraryPaths());
    List<String> libraries = bitcodeParserResult.getLibraries();
    if (!libraries.isEmpty()) {
        ExternalLibrary[] libs = context.addExternalLibraries(libraries);
        LLVMParserResult[] parserResults = parse(language, context, libs);
        handleParserResult(context, parserResults);
    }
    return LLVMParserRuntime.parse(source, library, bitcodeParserResult, language, context, nodeFactory);
}
Also used : ExternalLibrary(com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary) LLVMParserResult(com.oracle.truffle.llvm.parser.LLVMParserResult) BitcodeParserResult(com.oracle.truffle.llvm.parser.BitcodeParserResult)

Example 2 with LLVMParserResult

use of com.oracle.truffle.llvm.parser.LLVMParserResult in project sulong by graalvm.

the class Runner method parse.

private LLVMParserResult[] parse(LLVMLanguage language, LLVMContext context, ExternalLibrary[] libs) {
    LLVMParserResult[] parserResults = new LLVMParserResult[libs.length];
    for (int i = 0; i < libs.length; i++) {
        ExternalLibrary lib = libs[i];
        if (!lib.isParsed()) {
            try {
                Path path = lib.getPath();
                byte[] bytes = Files.readAllBytes(path);
                // at the moment, we don't need the bitcode as the content of the source
                Source source = Source.newBuilder(path.toString()).mimeType(LLVMLanguage.LLVM_BITCODE_MIME_TYPE).name(path.getFileName().toString()).build();
                parserResults[i] = parse(language, context, source, lib, ByteBuffer.wrap(bytes));
                lib.setParsed();
            } catch (Throwable t) {
                throw new RuntimeException("Error while trying to parse " + lib.getName(), t);
            }
        }
    }
    return parserResults;
}
Also used : Path(java.nio.file.Path) ExternalLibrary(com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary) LLVMParserResult(com.oracle.truffle.llvm.parser.LLVMParserResult) Source(com.oracle.truffle.api.source.Source)

Example 3 with LLVMParserResult

use of com.oracle.truffle.llvm.parser.LLVMParserResult in project sulong by graalvm.

the class Runner method parse.

/**
 * Parse bitcode data and do first initializations to prepare bitcode execution.
 */
public CallTarget parse(LLVMLanguage language, LLVMContext context, Source source) throws IOException {
    initializeContext(language, context);
    try {
        ByteBuffer bytes;
        ExternalLibrary library;
        if (source.getMimeType().equals(LLVMLanguage.LLVM_BITCODE_BASE64_MIME_TYPE)) {
            bytes = ByteBuffer.wrap(decodeBase64(source.getCharacters()));
            library = new ExternalLibrary("<STREAM>");
        } else if (source.getMimeType().equals(LLVMLanguage.LLVM_SULONG_TYPE)) {
            NativeLibraryDescriptor descriptor = Parser.parseLibraryDescriptor(source.getCharacters());
            String filename = descriptor.getFilename();
            bytes = read(filename);
            library = new ExternalLibrary(Paths.get(filename), null);
        } else if (source.getPath() != null) {
            bytes = read(source.getPath());
            library = new ExternalLibrary(Paths.get(source.getPath()), null);
        } else {
            throw new IllegalStateException();
        }
        LLVMParserResult parserResult = parse(language, context, source, library, bytes);
        handleParserResult(context, parserResult);
        return createLibraryCallTarget(context, library, parserResult);
    } catch (Throwable t) {
        throw new IOException("Error while trying to parse " + source.getPath(), t);
    }
}
Also used : ExternalLibrary(com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary) NativeLibraryDescriptor(com.oracle.truffle.nfi.types.NativeLibraryDescriptor) LLVMParserResult(com.oracle.truffle.llvm.parser.LLVMParserResult) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

LLVMParserResult (com.oracle.truffle.llvm.parser.LLVMParserResult)3 ExternalLibrary (com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary)3 Source (com.oracle.truffle.api.source.Source)1 BitcodeParserResult (com.oracle.truffle.llvm.parser.BitcodeParserResult)1 NativeLibraryDescriptor (com.oracle.truffle.nfi.types.NativeLibraryDescriptor)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Path (java.nio.file.Path)1