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());
}
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);
}
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));
}
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());
}
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());
}
Aggregations