Skip to content
Snippets Groups Projects
Commit df1e7346 authored by Mick Jordan's avatar Mick Jordan
Browse files

use new NFI API in tools (gramRd)

parent fd8a873a
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.ffi.impl.interop.tools;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.r.runtime.data.RTruffleObject;
public class RConnGetCCall implements RTruffleObject {
public static boolean isInstance(TruffleObject value) {
return value instanceof RConnGetCCall;
}
@Override
public ForeignAccess getForeignAccess() {
return RConnGetCCallMRForeign.ACCESS;
}
}
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.ffi.impl.interop.tools;
import java.io.IOException;
import com.oracle.truffle.api.interop.MessageResolution;
import com.oracle.truffle.api.interop.Resolve;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.runtime.conn.RConnection;
@MessageResolution(receiverType = RConnGetCCall.class)
public class RConnGetCCallMR {
@Resolve(message = "EXECUTE")
public abstract static class RConnGetCCallExecute extends Node {
protected java.lang.Object access(@SuppressWarnings("unused") RConnGetCCall receiver, Object[] arguments) {
try {
return ((RConnection) arguments[0]).getc();
} catch (IOException ex) {
return -1;
}
}
}
@Resolve(message = "IS_EXECUTABLE")
public abstract static class RConnGetCCallIsExecutable extends Node {
protected Object access(@SuppressWarnings("unused") RConnGetCCall receiver) {
return true;
}
}
}
......@@ -22,20 +22,17 @@
*/
package com.oracle.truffle.r.ffi.impl.nfi;
import java.io.IOException;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.ffi.impl.common.Generic_Tools;
import com.oracle.truffle.r.ffi.impl.common.RFFIUtils;
import com.oracle.truffle.r.runtime.RInternalError;
import com.oracle.truffle.r.ffi.impl.interop.tools.RConnGetCCall;
import com.oracle.truffle.r.runtime.conn.RConnection;
import com.oracle.truffle.r.runtime.data.RLogicalVector;
import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.data.RTruffleObject;
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.ffi.DLL;
import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo;
......@@ -46,24 +43,6 @@ import com.oracle.truffle.r.runtime.ffi.ToolsRFFI;
public class TruffleNFI_Tools implements ToolsRFFI {
private static class TruffleNFI_ToolsRFFINode extends Generic_Tools.Generic_ToolsRFFINode {
private interface RConnGetC {
int getc(RConnection conn);
}
private static class RConnGetCImpl implements RConnGetC, RTruffleObject {
@Override
public int getc(RConnection conn) {
RFFIUtils.traceUpCall("getc");
try {
int r = conn.getc();
RFFIUtils.traceUpCallReturn("getc", r);
return r;
} catch (IOException ex) {
return -1;
}
}
}
private static boolean initialized;
@Child private DLLRFFI.DLSymNode dysymNode = DLLRFFI.DLSymNode.create();
......@@ -86,8 +65,8 @@ public class TruffleNFI_Tools implements ToolsRFFI {
Node bind = Message.createInvoke(1).createNode();
Node executeNode = Message.createExecute(1).createNode();
try {
TruffleObject function = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", "((object): sint32): void");
ForeignAccess.sendExecute(executeNode, function, new RConnGetCImpl());
TruffleObject function = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", "(env, (object): sint32): void");
ForeignAccess.sendExecute(executeNode, function, new RConnGetCCall());
} catch (InteropException t) {
throw RInternalError.shouldNotReachHere(t);
}
......
......@@ -341,12 +341,16 @@ public final class FFIProcessor extends AbstractProcessor {
return "uint8";
case "int":
return "sint32";
case "long":
return "sint64";
case "double":
return "double";
case "void":
return "void";
case "int[]":
return "[sint32]";
case "long[]":
return "[sint64]";
case "double[]":
return "[double]";
case "byte[]":
......
......@@ -30,7 +30,7 @@
#include <trufflenfi.h>
extern void init_memory();
extern void init_utils();
extern void init_utils(TruffleEnv* env);
// use for an unimplemented API function
void *unimplemented(char *msg) __attribute__((noreturn));
......
......@@ -65,7 +65,7 @@ $(OBJ)/%.o: $(GNUR_SRC)/%.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(OBJ)/gramRd_nfi.o: $(SRC)/truffle_nfi/gramRd_nfi.c
$(CC) $(CFLAGS) $(FFI_INCLUDES) -c $< -o $@
$(CC) $(CFLAGS) $(FFI_INCLUDES) $(NFI_INCLUDES) -c $< -o $@
$(OBJ)/gramRd_llvm.o: $(SRC)/truffle_llvm/gramRd_llvm.c
$(CC) $(CFLAGS) $(FFI_INCLUDES) $(SULONG_INCLUDES) -c $< -o $@
......
......@@ -21,10 +21,12 @@
* questions.
*/
#include "../gramRd_fastr.h"
#include <trufflenfi.h>
static int (*call_RConnGetC)(void *conn);
void gramRd_nfi_init(void *closure) {
void gramRd_nfi_init(TruffleEnv* env, void *closure) {
(*env)->newClosureRef(env, closure);
call_RConnGetC = closure;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment