1 /* 2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 package org.graalvm.compiler.lir.jtt; 26 27 import java.util.HashMap; 28 29 import org.graalvm.compiler.debug.GraalError; 30 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 31 32 import jdk.vm.ci.meta.Value; 33 34 public abstract class LIRTestSpecification { 35 private Value result; 36 private final HashMap<String, Value> output = new HashMap<>(); 37 generate(LIRGeneratorTool gen)38 public void generate(LIRGeneratorTool gen) { 39 defaultHandler(gen); 40 } 41 generate(LIRGeneratorTool gen, Value arg0)42 public void generate(LIRGeneratorTool gen, Value arg0) { 43 defaultHandler(gen, arg0); 44 } 45 generate(LIRGeneratorTool gen, Value arg0, Value arg1)46 public void generate(LIRGeneratorTool gen, Value arg0, Value arg1) { 47 defaultHandler(gen, arg0, arg1); 48 } 49 generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2)50 public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2) { 51 defaultHandler(gen, arg0, arg1, arg2); 52 } 53 generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2, Value arg3)54 public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2, Value arg3) { 55 defaultHandler(gen, arg0, arg1, arg2, arg3); 56 } 57 generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2, Value arg3, Value arg4)58 public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2, Value arg3, Value arg4) { 59 defaultHandler(gen, arg0, arg1, arg2, arg3, arg4); 60 } 61 defaultHandler(@uppressWarningsR) LIRGeneratorTool gen, Value... args)62 private static void defaultHandler(@SuppressWarnings("unused") LIRGeneratorTool gen, Value... args) { 63 throw new GraalError("LIRTestSpecification cannot handle generate() with %d arguments", args.length); 64 } 65 generate(LIRGeneratorTool gen, Value[] values)66 void generate(LIRGeneratorTool gen, Value[] values) { 67 if (values.length == 0) { 68 generate(gen); 69 } else if (values.length == 1) { 70 generate(gen, values[0]); 71 } else if (values.length == 2) { 72 generate(gen, values[0], values[1]); 73 } else if (values.length == 3) { 74 generate(gen, values[0], values[1], values[2]); 75 } else if (values.length == 4) { 76 generate(gen, values[0], values[1], values[2], values[3]); 77 } else if (values.length == 5) { 78 generate(gen, values[0], values[1], values[2], values[3], values[4]); 79 } else { 80 GraalError.unimplemented(); 81 } 82 83 } 84 setOutput(String name, Value value)85 public void setOutput(String name, Value value) { 86 output.put(name, value); 87 } 88 getOutput(String name)89 public Value getOutput(String name) { 90 return output.get(name); 91 } 92 setResult(Value value)93 public void setResult(Value value) { 94 result = value; 95 } 96 getResult()97 public Value getResult() { 98 return result; 99 } 100 } 101