Skip to content
Snippets Groups Projects
Commit 6d24a7dc authored by stepan's avatar stepan
Browse files

Refactoring: only one common implementation of ToolsRFFI

parent 1faa99ad
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2015, 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.common;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.runtime.RInternalError;
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.env.REnvironment;
import com.oracle.truffle.r.runtime.ffi.CallRFFI;
import com.oracle.truffle.r.runtime.ffi.DLL;
import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo;
import com.oracle.truffle.r.runtime.ffi.DLL.SymbolHandle;
import com.oracle.truffle.r.runtime.ffi.NativeCallInfo;
import com.oracle.truffle.r.runtime.ffi.RFFIFactory;
import com.oracle.truffle.r.runtime.ffi.ToolsRFFI;
public class Generic_Tools implements ToolsRFFI {
public static class Generic_ToolsRFFINode extends Node implements ParseRdNode {
private static final String C_PARSE_RD = "C_parseRd";
protected static final String TOOLS = "tools";
@Child private CallRFFI.InvokeCallNode callRFFINode = RFFIFactory.getCallRFFI().createInvokeCallNode();
@Child private DLL.RFindSymbolNode findSymbolNode = DLL.RFindSymbolNode.create();
@CompilationFinal private NativeCallInfo nativeCallInfo;
/**
* Invoke C implementation, N.B., code is not thread safe.
*/
@Override
public Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros,
RLogicalVector warndups) {
synchronized (Generic_Tools.class) {
try {
if (nativeCallInfo == null) {
// lookup entry point (assert library is loaded)
DLLInfo toolsDLLInfo = DLL.findLibrary(TOOLS);
assert toolsDLLInfo != null;
SymbolHandle symbolHandle = findSymbolNode.execute(C_PARSE_RD, TOOLS, DLL.RegisteredNativeSymbol.any());
assert symbolHandle != DLL.SYMBOL_NOT_FOUND;
nativeCallInfo = new NativeCallInfo(C_PARSE_RD, symbolHandle, toolsDLLInfo);
}
return callRFFINode.dispatch(nativeCallInfo,
new Object[]{con, srcfile, verbose, fragment, basename, warningCalls, macros, warndups});
} catch (Throwable ex) {
throw RInternalError.shouldNotReachHere(ex, "error during Rd parsing" + ex.getMessage());
}
}
}
}
@Override
public ParseRdNode createParseRdNode() {
return new Generic_ToolsRFFINode();
}
}
...@@ -34,6 +34,7 @@ import com.oracle.truffle.r.runtime.ffi.NativeFunction; ...@@ -34,6 +34,7 @@ import com.oracle.truffle.r.runtime.ffi.NativeFunction;
import com.oracle.truffle.r.runtime.ffi.PCRERFFI; import com.oracle.truffle.r.runtime.ffi.PCRERFFI;
import com.oracle.truffle.r.runtime.ffi.RFFIContext; import com.oracle.truffle.r.runtime.ffi.RFFIContext;
import com.oracle.truffle.r.runtime.ffi.StatsRFFI; import com.oracle.truffle.r.runtime.ffi.StatsRFFI;
import com.oracle.truffle.r.runtime.ffi.ToolsRFFI;
import com.oracle.truffle.r.runtime.ffi.ZipRFFI; import com.oracle.truffle.r.runtime.ffi.ZipRFFI;
/** /**
...@@ -49,7 +50,7 @@ final class TruffleLLVM_Context extends RFFIContext { ...@@ -49,7 +50,7 @@ final class TruffleLLVM_Context extends RFFIContext {
super(new TruffleLLVM_C(), new BaseRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new TruffleLLVM_Call(), new TruffleLLVM_DLL(), new TruffleLLVM_UserRng(), super(new TruffleLLVM_C(), new BaseRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new TruffleLLVM_Call(), new TruffleLLVM_DLL(), new TruffleLLVM_UserRng(),
new ZipRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new PCRERFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new ZipRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new PCRERFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE),
new LapackRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new StatsRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new LapackRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE), new StatsRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE),
new TruffleLLVM_Tools(), new TruffleLLVM_REmbed(), new MiscRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE)); new ToolsRFFI(), new TruffleLLVM_REmbed(), new MiscRFFI(TruffleLLVM_DownCallNodeFactory.INSTANCE));
} }
static TruffleLLVM_Context getContextState() { static TruffleLLVM_Context getContextState() {
......
/*
* Copyright (c) 2014, 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.llvm;
import com.oracle.truffle.r.ffi.impl.common.Generic_Tools;
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.env.REnvironment;
import com.oracle.truffle.r.runtime.ffi.ToolsRFFI;
public class TruffleLLVM_Tools implements ToolsRFFI {
private static class TruffleLLVM_ToolsRFFINode extends Generic_Tools.Generic_ToolsRFFINode {
/**
* Invoke C implementation, N.B., code is not thread safe.
*/
@Override
public Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros,
RLogicalVector warndups) {
return super.execute(con, srcfile, verbose, fragment, basename, warningCalls, macros, warndups);
}
}
@Override
public ParseRdNode createParseRdNode() {
return new TruffleLLVM_ToolsRFFINode();
}
}
...@@ -108,12 +108,7 @@ public final class Managed_RFFIFactory extends RFFIFactory { ...@@ -108,12 +108,7 @@ public final class Managed_RFFIFactory extends RFFIFactory {
throw unsupported("user defined RNG"); throw unsupported("user defined RNG");
} }
}, new ZipRFFI(Managed_DownCallNodeFactory.INSTANCE), new PCRERFFI(Managed_DownCallNodeFactory.INSTANCE), new LapackRFFI(Managed_DownCallNodeFactory.INSTANCE), }, new ZipRFFI(Managed_DownCallNodeFactory.INSTANCE), new PCRERFFI(Managed_DownCallNodeFactory.INSTANCE), new LapackRFFI(Managed_DownCallNodeFactory.INSTANCE),
new StatsRFFI(Managed_DownCallNodeFactory.INSTANCE), new ToolsRFFI() { new StatsRFFI(Managed_DownCallNodeFactory.INSTANCE), new ToolsRFFI(), new Managed_REmbedRFFI(), new MiscRFFI(Managed_DownCallNodeFactory.INSTANCE));
@Override
public ParseRdNode createParseRdNode() {
throw unsupported("parseRD");
}
}, new Managed_REmbedRFFI(), new MiscRFFI(Managed_DownCallNodeFactory.INSTANCE));
} }
private static class IgnoreUpCallExceptionNode extends Node implements HandleUpCallExceptionNode { private static class IgnoreUpCallExceptionNode extends Node implements HandleUpCallExceptionNode {
......
...@@ -62,6 +62,7 @@ import com.oracle.truffle.r.runtime.ffi.PCRERFFI; ...@@ -62,6 +62,7 @@ import com.oracle.truffle.r.runtime.ffi.PCRERFFI;
import com.oracle.truffle.r.runtime.ffi.RFFIContext; import com.oracle.truffle.r.runtime.ffi.RFFIContext;
import com.oracle.truffle.r.runtime.ffi.RFFIVariables; import com.oracle.truffle.r.runtime.ffi.RFFIVariables;
import com.oracle.truffle.r.runtime.ffi.StatsRFFI; import com.oracle.truffle.r.runtime.ffi.StatsRFFI;
import com.oracle.truffle.r.runtime.ffi.ToolsRFFI;
import com.oracle.truffle.r.runtime.ffi.ZipRFFI; import com.oracle.truffle.r.runtime.ffi.ZipRFFI;
import sun.misc.Unsafe; import sun.misc.Unsafe;
...@@ -92,7 +93,7 @@ final class TruffleNFI_Context extends RFFIContext { ...@@ -92,7 +93,7 @@ final class TruffleNFI_Context extends RFFIContext {
TruffleNFI_Context() { TruffleNFI_Context() {
super(new TruffleNFI_C(), new BaseRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new TruffleNFI_Call(), new TruffleNFI_DLL(), new TruffleNFI_UserRng(), super(new TruffleNFI_C(), new BaseRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new TruffleNFI_Call(), new TruffleNFI_DLL(), new TruffleNFI_UserRng(),
new ZipRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new PCRERFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new LapackRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new ZipRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new PCRERFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new LapackRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE),
new StatsRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new TruffleNFI_Tools(), new TruffleNFI_REmbed(), new MiscRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE)); new StatsRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE), new ToolsRFFI(), new TruffleNFI_REmbed(), new MiscRFFI(TruffleNFI_DownCallNodeFactory.INSTANCE));
// forward constructor // forward constructor
} }
......
/*
* Copyright (c) 2014, 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.nfi;
import com.oracle.truffle.r.ffi.impl.common.Generic_Tools;
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.env.REnvironment;
import com.oracle.truffle.r.runtime.ffi.ToolsRFFI;
public class TruffleNFI_Tools implements ToolsRFFI {
private static class TruffleNFI_ToolsRFFINode extends Generic_Tools.Generic_ToolsRFFINode {
@Override
public Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros,
RLogicalVector warndups) {
return super.execute(con, srcfile, verbose, fragment, basename, warningCalls, macros, warndups);
}
}
@Override
public ParseRdNode createParseRdNode() {
return new TruffleNFI_ToolsRFFINode();
}
}
/* /*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -22,17 +22,30 @@ ...@@ -22,17 +22,30 @@
*/ */
package com.oracle.truffle.r.runtime.ffi; package com.oracle.truffle.r.runtime.ffi;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeInterface; import com.oracle.truffle.api.nodes.NodeInterface;
import com.oracle.truffle.r.runtime.RInternalError;
import com.oracle.truffle.r.runtime.conn.RConnection; import com.oracle.truffle.r.runtime.conn.RConnection;
import com.oracle.truffle.r.runtime.data.RLogicalVector; import com.oracle.truffle.r.runtime.data.RLogicalVector;
import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.env.REnvironment; import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo;
import com.oracle.truffle.r.runtime.ffi.DLL.SymbolHandle;
/** /**
* Interface to native (C) methods provided by the {@code tools} package. * Interface to native (C) methods provided by the {@code tools} package.
*/ */
public interface ToolsRFFI { public final class ToolsRFFI {
interface ParseRdNode extends NodeInterface { public static class ParseRdNode extends Node {
private static final String C_PARSE_RD = "C_parseRd";
protected static final String TOOLS = "tools";
@Child private CallRFFI.InvokeCallNode callRFFINode = RFFIFactory.getCallRFFI().createInvokeCallNode();
@Child private DLL.RFindSymbolNode findSymbolNode = DLL.RFindSymbolNode.create();
@CompilationFinal private NativeCallInfo nativeCallInfo;
/** /**
* This invokes the Rd parser, written in C, and part of GnuR, that does its work using the * This invokes the Rd parser, written in C, and part of GnuR, that does its work using the
* R FFI interface. The R code initially invokes this via {@code .External2(C_parseRd, ...)} * R FFI interface. The R code initially invokes this via {@code .External2(C_parseRd, ...)}
...@@ -41,9 +54,28 @@ public interface ToolsRFFI { ...@@ -41,9 +54,28 @@ public interface ToolsRFFI {
* code. We can't go straight to the GnuR C entry point as that makes GnuR-specific * code. We can't go straight to the GnuR C entry point as that makes GnuR-specific
* assumptions about, for example, how connections are implemented. * assumptions about, for example, how connections are implemented.
*/ */
Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros, public Object execute(RConnection con, REnvironment srcfile, RLogicalVector verbose, RLogicalVector fragment, RStringVector basename, RLogicalVector warningCalls, Object macros,
RLogicalVector warndups); RLogicalVector warndups) {
synchronized (ToolsRFFI.class) {
try {
if (nativeCallInfo == null) {
// lookup entry point (assert library is loaded)
DLLInfo toolsDLLInfo = DLL.findLibrary(TOOLS);
assert toolsDLLInfo != null;
SymbolHandle symbolHandle = findSymbolNode.execute(C_PARSE_RD, TOOLS, DLL.RegisteredNativeSymbol.any());
assert symbolHandle != DLL.SYMBOL_NOT_FOUND;
nativeCallInfo = new NativeCallInfo(C_PARSE_RD, symbolHandle, toolsDLLInfo);
}
return callRFFINode.dispatch(nativeCallInfo,
new Object[]{con, srcfile, verbose, fragment, basename, warningCalls, macros, warndups});
} catch (Throwable ex) {
throw RInternalError.shouldNotReachHere(ex, "error during Rd parsing" + ex.getMessage());
}
}
}
} }
ParseRdNode createParseRdNode(); public ParseRdNode createParseRdNode() {
return new ParseRdNode();
}
} }
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