Search in sources :

Example 6 with NativeLibraryDescriptor

use of com.oracle.truffle.nfi.types.NativeLibraryDescriptor in project graal by oracle.

the class ParseLibraryDescriptorTest method parseWithTwoFlags.

@Test
public void parseWithTwoFlags() {
    NativeLibraryDescriptor test = Parser.parseLibraryDescriptor("load(RTLD_NOW | RTLD_GLOBAL) testfile");
    Assert.assertEquals("file name", "testfile", test.getFilename());
    Assert.assertEquals("flag count", 2, test.getFlags().size());
    Assert.assertEquals("RTLD_NOW", test.getFlags().get(0));
    Assert.assertEquals("RTLD_GLOBAL", test.getFlags().get(1));
}
Also used : NativeLibraryDescriptor(com.oracle.truffle.nfi.types.NativeLibraryDescriptor) Test(org.junit.Test)

Example 7 with NativeLibraryDescriptor

use of com.oracle.truffle.nfi.types.NativeLibraryDescriptor in project graal by oracle.

the class ParseLibraryDescriptorTest method parseDefault.

@Test
public void parseDefault() {
    NativeLibraryDescriptor def = Parser.parseLibraryDescriptor("default");
    Assert.assertTrue("isDefaultLibrary", def.isDefaultLibrary());
}
Also used : NativeLibraryDescriptor(com.oracle.truffle.nfi.types.NativeLibraryDescriptor) Test(org.junit.Test)

Example 8 with NativeLibraryDescriptor

use of com.oracle.truffle.nfi.types.NativeLibraryDescriptor 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

NativeLibraryDescriptor (com.oracle.truffle.nfi.types.NativeLibraryDescriptor)8 Test (org.junit.Test)6 RootNode (com.oracle.truffle.api.nodes.RootNode)1 LLVMParserResult (com.oracle.truffle.llvm.parser.LLVMParserResult)1 ExternalLibrary (com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1