use of com.oracle.truffle.nfi.types.NativeSource in project graal by oracle.
the class ParseSourceTest method testWithPreBind.
@Test
public void testWithPreBind() {
NativeSource src = Parser.parseNFISource("load 'testfile' { sym1 (sint32):sint32; sym2 (double):void; }");
Assert.assertEquals("getLibraryDescriptor", "load 'testfile'", src.getLibraryDescriptor());
Assert.assertTrue("isDefaultBackend", src.isDefaultBackend());
Assert.assertEquals("preBoundSymbolsLength", 2, src.preBoundSymbolsLength());
Assert.assertEquals("getPreBoundSymbol(0)", "sym1", src.getPreBoundSymbol(0));
Assert.assertEquals("getPreBoundSignature(0)", "(sint32):sint32", src.getPreBoundSignature(0));
Assert.assertEquals("getPreBoundSymbol(1)", "sym2", src.getPreBoundSymbol(1));
Assert.assertEquals("getPreBoundSignature(1)", "(double):void", src.getPreBoundSignature(1));
}
use of com.oracle.truffle.nfi.types.NativeSource in project graal by oracle.
the class ParseSourceTest method testSimpleDescriptor.
private static void testSimpleDescriptor(String descriptor) {
NativeSource src = Parser.parseNFISource(descriptor);
Assert.assertEquals("getLibraryDescriptor", descriptor, src.getLibraryDescriptor());
Assert.assertTrue("isDefaultBackend", src.isDefaultBackend());
Assert.assertEquals("preBoundSymbolsLength", 0, src.preBoundSymbolsLength());
}
use of com.oracle.truffle.nfi.types.NativeSource in project graal by oracle.
the class ParseSourceTest method testWithBackend.
@Test
public void testWithBackend() {
NativeSource src = Parser.parseNFISource("with backend load 'testfile'");
Assert.assertEquals("getLibraryDescriptor", "load 'testfile'", src.getLibraryDescriptor());
Assert.assertEquals("preBoundSymbolsLength", 0, src.preBoundSymbolsLength());
Assert.assertFalse("isDefaultBackend", src.isDefaultBackend());
Assert.assertEquals("getNFIBackendId", "backend", src.getNFIBackendId());
}
use of com.oracle.truffle.nfi.types.NativeSource in project graal by oracle.
the class NFILanguage method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
CharSequence nfiSource = request.getSource().getCharacters();
NativeSource source = Parser.parseNFISource(nfiSource);
String backendId;
if (source.isDefaultBackend()) {
backendId = "native";
} else {
backendId = source.getNFIBackendId();
}
Source backendSource = Source.newBuilder(source.getLibraryDescriptor()).mimeType("trufflenfi/" + backendId).name("<nfi-impl>").build();
CallTarget backendTarget = getContextReference().get().env.parse(backendSource);
DirectCallNode loadLibrary = DirectCallNode.create(backendTarget);
return Truffle.getRuntime().createCallTarget(new NFIRootNode(this, loadLibrary, source));
}
Aggregations