Mercurial > hg > truffle
changeset 17443:90c6a996f9cd
Truffle: add new callFunctionsWith builtin for SL Truffle tests.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 14 Oct 2014 20:02:44 +0200 |
parents | ecc27b9d2510 |
children | 2834b4432586 |
files | graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SLTruffleGraalTestSuite.java graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLCallFunctionsWithBuiltin.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java |
diffstat | 3 files changed, 68 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SLTruffleGraalTestSuite.java Tue Oct 14 18:12:24 2014 +0100 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SLTruffleGraalTestSuite.java Tue Oct 14 20:02:44 2014 +0200 @@ -47,6 +47,8 @@ SLTestRunner.installBuiltin(SLCallUntilOptimizedBuiltinFactory.getInstance()); SLTestRunner.installBuiltin(SLIsInlinedBuiltinFactory.getInstance()); SLTestRunner.installBuiltin(SLGenerateDummyNodesBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLCallFunctionsWithBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLIsCompilationConstantBuiltinFactory.getInstance()); /* test specific builtins */ SLTestRunner.installBuiltin(SLTestSlowPath01BuiltinFactory.getInstance());
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLCallFunctionsWithBuiltin.java Tue Oct 14 20:02:44 2014 +0200 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2014, 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.graal.truffle.test.builtins; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.api.source.*; +import com.oracle.truffle.sl.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +/** + * Returns all functions that start with test. + */ +@NodeInfo(shortName = "callFunctionsWith") +public abstract class SLCallFunctionsWithBuiltin extends SLGraalRuntimeBuiltin { + + @Child private IndirectCallNode indirectCall = Truffle.getRuntime().createIndirectCallNode(); + + @Specialization + public SLNull runTests(VirtualFrame frame, String startsWith, SLFunction harness) { + SLContext context = ((SLRootNode) getRootNode()).getSLContext(); + boolean found = false; + for (SLFunction function : context.getFunctionRegistry().getFunctions()) { + if (function.getName().startsWith(startsWith) && getSource(function) == getSource(harness) && getSource(function) != null) { + indirectCall.call(frame, harness.getCallTarget(), new Object[]{function}); + found = true; + } + } + if (!found) { + throw new SLAssertionError("No tests found to execute."); + } + return SLNull.SINGLETON; + } + + private static Source getSource(SLFunction function) { + SourceSection section = function.getCallTarget().getRootNode().getSourceSection(); + if (section != null) { + return section.getSource(); + } + return null; + } +}
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java Tue Oct 14 18:12:24 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java Tue Oct 14 20:02:44 2014 +0200 @@ -116,6 +116,7 @@ final SLFunctionBodyNode functionBodyNode = new SLFunctionBodyNode(functionSrc, methodBlock); final SLRootNode rootNode = new SLRootNode(this.context, frameDescriptor, functionBodyNode, functionName); + rootNode.assignSourceSection(functionSrc); context.getFunctionRegistry().register(functionName, rootNode);