Search in sources :

Example 1 with NativeLibraryDescriptor

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

the class ParseLibraryDescriptorTest method parseFileIdent.

@Test
public void parseFileIdent() {
    NativeLibraryDescriptor test = Parser.parseLibraryDescriptor("load /test/path/file.so");
    Assert.assertEquals("file name", "/test/path/file.so", test.getFilename());
}
Also used : NativeLibraryDescriptor(com.oracle.truffle.nfi.types.NativeLibraryDescriptor) Test(org.junit.Test)

Example 2 with NativeLibraryDescriptor

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

the class NFILanguageImpl method parse.

@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    CharSequence library = request.getSource().getCharacters();
    RootNode root;
    NativeLibraryDescriptor descriptor = Parser.parseLibraryDescriptor(library);
    NFIContext ctx = getContextReference().get();
    if (descriptor.isDefaultLibrary()) {
        root = new GetDefaultLibraryNode();
    } else {
        int flags = 0;
        boolean lazyOrNow = false;
        if (descriptor.getFlags() != null) {
            for (String flag : descriptor.getFlags()) {
                switch(flag) {
                    case "RTLD_GLOBAL":
                        flags |= ctx.RTLD_GLOBAL;
                        break;
                    case "RTLD_LOCAL":
                        flags |= ctx.RTLD_LOCAL;
                        break;
                    case "RTLD_LAZY":
                        flags |= ctx.RTLD_LAZY;
                        lazyOrNow = true;
                        break;
                    case "RTLD_NOW":
                        flags |= ctx.RTLD_NOW;
                        lazyOrNow = true;
                        break;
                }
            }
        }
        if (!lazyOrNow) {
            // default to 'RTLD_NOW' if neither 'RTLD_LAZY' nor 'RTLD_NOW' was specified
            flags |= ctx.RTLD_NOW;
        }
        root = new LoadLibraryNode(this, descriptor.getFilename(), flags);
    }
    return Truffle.getRuntime().createCallTarget(root);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) NativeLibraryDescriptor(com.oracle.truffle.nfi.types.NativeLibraryDescriptor)

Example 3 with NativeLibraryDescriptor

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

the class ParseLibraryDescriptorTest method parseWithOneFlag.

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

Example 4 with NativeLibraryDescriptor

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

the class ParseLibraryDescriptorTest method parseFileStringSingle.

@Test
public void parseFileStringSingle() {
    NativeLibraryDescriptor test = Parser.parseLibraryDescriptor("load 'test filename'");
    Assert.assertEquals("file name", "test filename", test.getFilename());
}
Also used : NativeLibraryDescriptor(com.oracle.truffle.nfi.types.NativeLibraryDescriptor) Test(org.junit.Test)

Example 5 with NativeLibraryDescriptor

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

the class ParseLibraryDescriptorTest method parseFileStringDouble.

@Test
public void parseFileStringDouble() {
    NativeLibraryDescriptor test = Parser.parseLibraryDescriptor("load \"test filename\"");
    Assert.assertEquals("file name", "test filename", test.getFilename());
}
Also used : NativeLibraryDescriptor(com.oracle.truffle.nfi.types.NativeLibraryDescriptor) Test(org.junit.Test)

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