Search in sources :

Example 6 with ExternalLibrary

use of com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary 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

ExternalLibrary (com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary)6 LLVMParserResult (com.oracle.truffle.llvm.parser.LLVMParserResult)3 Source (com.oracle.truffle.api.source.Source)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 Truffle (com.oracle.truffle.api.Truffle)1 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 BitcodeParserResult (com.oracle.truffle.llvm.parser.BitcodeParserResult)1 ModelModule (com.oracle.truffle.llvm.parser.model.ModelModule)1 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)1 Linkage (com.oracle.truffle.llvm.parser.model.enums.Linkage)1 FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)1 ArrayConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.ArrayConstant)1 StructureConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.StructureConstant)1 GlobalAlias (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)1 GlobalConstant (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalConstant)1 GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)1 GlobalVariable (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable)1 TargetDataLayout (com.oracle.truffle.llvm.parser.model.target.TargetDataLayout)1