use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class ContextThreadLocalTest method testCompilation.
@Test
public void testCompilation() {
ThreadLocal<Object> tl = createContextThreadLocal();
Object context1 = createContext();
CallTarget compiled = Truffle.getRuntime().createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
Object result = tl.get();
return result;
}
});
tl.set(context1);
for (int i = 0; i < 10000; i++) {
compiled.call();
}
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class RootNodeTest method testNotReplacable3.
@Test(expected = IllegalStateException.class)
@Ignore
public void testNotReplacable3() {
TestRootNode2 rootNode = new TestRootNode2();
rootNode.rootNodeAsChild = new Node() {
};
rootNode.adoptChildren();
rootNode.rootNodeAsChild.replace(new TestRootNode());
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class ChildrenNodesTest method testMultipleChildrenFields.
@Test
public void testMultipleChildrenFields() {
TruffleRuntime runtime = Truffle.getRuntime();
TestChildNode firstChild = new TestChildNode();
TestChildNode secondChild = new TestChildNode();
TestChildNode thirdChild = new TestChildNode();
TestChildNode forthChild = new TestChildNode();
TestRootNode rootNode = new TestRoot2Node(new TestChildNode[] { firstChild, secondChild }, new TestChildNode[] { thirdChild, forthChild });
CallTarget target = runtime.createCallTarget(rootNode);
Assert.assertEquals(rootNode, firstChild.getParent());
Assert.assertEquals(rootNode, secondChild.getParent());
Assert.assertEquals(rootNode, thirdChild.getParent());
Assert.assertEquals(rootNode, forthChild.getParent());
Iterator<Node> iterator = rootNode.getChildren().iterator();
Assert.assertEquals(firstChild, iterator.next());
Assert.assertEquals(secondChild, iterator.next());
Assert.assertEquals(thirdChild, iterator.next());
Assert.assertEquals(forthChild, iterator.next());
Assert.assertFalse(iterator.hasNext());
Object result = target.call();
Assert.assertEquals(2 * 42, result);
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class InterfaceChildFieldTest method testChild.
@Test
public void testChild() {
TruffleRuntime runtime = Truffle.getRuntime();
TestChildInterface leftChild = new TestLeafNode();
TestChildInterface rightChild = new TestLeafNode();
TestChildNode parent = new TestChildNode(leftChild, rightChild);
TestRootNode rootNode = new TestRootNode(parent);
CallTarget target = runtime.createCallTarget(rootNode);
Iterator<Node> iterator = parent.getChildren().iterator();
Assert.assertEquals(leftChild, iterator.next());
Assert.assertEquals(rightChild, iterator.next());
Assert.assertFalse(iterator.hasNext());
Object result = target.call();
Assert.assertEquals(42, result);
Assert.assertEquals(4, NodeUtil.countNodes(rootNode));
Assert.assertEquals(4, NodeUtil.countNodes(NodeUtil.cloneNode(rootNode)));
}
use of com.oracle.truffle.api.nodes.RootNode in project sulong by graalvm.
the class LLVMParserRuntime method parse.
public static LLVMParserResult parse(Source source, ExternalLibrary library, BitcodeParserResult parserResult, LLVMLanguage language, LLVMContext context, NodeFactory nodeFactory) {
ModelModule model = parserResult.getModel();
TargetDataLayout layout = model.getTargetDataLayout();
assert layout != null;
LLVMModelVisitor module = new LLVMModelVisitor();
model.accept(module);
DataLayoutConverter.DataSpecConverterImpl targetDataLayout = DataLayoutConverter.getConverter(layout.getDataLayout());
context.setDataLayoutConverter(targetDataLayout);
LLVMParserRuntime runtime = new LLVMParserRuntime(source, library, language, context, nodeFactory, module.getAliases());
runtime.registerFunctions(model);
LLVMSymbolReadResolver symbolResolver = new LLVMSymbolReadResolver(runtime, runtime.getGlobalFrameDescriptor());
LLVMExpressionNode[] globals = runtime.createGlobalVariableInitializationNodes(symbolResolver, module.getGlobals());
RootNode globalVarInits = nodeFactory.createStaticInitsRootNode(runtime, globals);
RootCallTarget globalVarInitsTarget = Truffle.getRuntime().createCallTarget(globalVarInits);
LLVMExpressionNode[] deallocs = runtime.getDeallocations();
RootNode globalVarDeallocs = nodeFactory.createStaticInitsRootNode(runtime, deallocs);
RootCallTarget globalVarDeallocsTarget = Truffle.getRuntime().createCallTarget(globalVarDeallocs);
RootCallTarget constructorFunctions = runtime.getConstructors(module.getGlobals());
RootCallTarget destructorFunctions = runtime.getDestructors(module.getGlobals());
if (context.getEnv().getOptions().get(SulongEngineOption.ENABLE_LVI)) {
final LLVMSourceContext sourceContext = context.getSourceContext();
model.getSourceGlobals().forEach((symbol, irValue) -> {
final LLVMExpressionNode node = symbolResolver.resolve(irValue);
final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
sourceContext.registerStatic(symbol, value);
});
model.getSourceStaticMembers().forEach(((type, symbol) -> {
final LLVMExpressionNode node = symbolResolver.resolve(symbol);
final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
type.setValue(value);
}));
}
RootCallTarget mainFunctionCallTarget = null;
if (runtime.getScope().functionExists("@main")) {
LLVMFunctionDescriptor mainDescriptor = runtime.getScope().getFunctionDescriptor("@main");
LLVMFunctionDescriptor startDescriptor = runtime.getScope().getFunctionDescriptor("@_start");
RootCallTarget startCallTarget = startDescriptor.getLLVMIRFunction();
String applicationPath = source.getPath() == null ? "" : source.getPath().toString();
RootNode globalFunction = nodeFactory.createGlobalRootNode(runtime, startCallTarget, mainDescriptor, applicationPath);
RootCallTarget globalFunctionRoot = Truffle.getRuntime().createCallTarget(globalFunction);
RootNode globalRootNode = nodeFactory.createGlobalRootNodeWrapping(runtime, globalFunctionRoot, startDescriptor.getType().getReturnType());
mainFunctionCallTarget = Truffle.getRuntime().createCallTarget(globalRootNode);
}
return new LLVMParserResult(runtime.getScope(), mainFunctionCallTarget, globalVarInitsTarget, globalVarDeallocsTarget, constructorFunctions, destructorFunctions);
}
Aggregations