Search in sources :

Example 1 with NativeSource

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));
}
Also used : NativeSource(com.oracle.truffle.nfi.types.NativeSource) Test(org.junit.Test)

Example 2 with NativeSource

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());
}
Also used : NativeSource(com.oracle.truffle.nfi.types.NativeSource)

Example 3 with NativeSource

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());
}
Also used : NativeSource(com.oracle.truffle.nfi.types.NativeSource) Test(org.junit.Test)

Example 4 with NativeSource

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));
}
Also used : NativeSource(com.oracle.truffle.nfi.types.NativeSource) CallTarget(com.oracle.truffle.api.CallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Source(com.oracle.truffle.api.source.Source) NativeSource(com.oracle.truffle.nfi.types.NativeSource)

Aggregations

NativeSource (com.oracle.truffle.nfi.types.NativeSource)4 Test (org.junit.Test)2 CallTarget (com.oracle.truffle.api.CallTarget)1 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)1 Source (com.oracle.truffle.api.source.Source)1