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 package org.graalvm.compiler.lir.jtt;
  24 
  25 import java.util.HashMap;
  26 
  27 import org.graalvm.compiler.debug.GraalError;
  28 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  29 
  30 import jdk.vm.ci.meta.Value;
  31 
  32 public abstract class LIRTestSpecification {
  33     private Value result;
  34     private final HashMap<String, Value> output = new HashMap<>();
  35 
  36     public void generate(LIRGeneratorTool gen) {
  37         defaultHandler(gen);
  38     }
  39 
  40     public void generate(LIRGeneratorTool gen, Value arg0) {
  41         defaultHandler(gen, arg0);
  42     }
  43 
  44     public void generate(LIRGeneratorTool gen, Value arg0, Value arg1) {
  45         defaultHandler(gen, arg0, arg1);
  46     }
  47 
  48     public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2) {
  49         defaultHandler(gen, arg0, arg1, arg2);
  50     }
  51 
  52     public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2, Value arg3) {
  53         defaultHandler(gen, arg0, arg1, arg2, arg3);
  54     }
  55 
  56     public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2, Value arg3, Value arg4) {
  57         defaultHandler(gen, arg0, arg1, arg2, arg3, arg4);
  58     }
  59 
  60     private static void defaultHandler(@SuppressWarnings("unused") LIRGeneratorTool gen, Value... args) {
  61         throw new GraalError("LIRTestSpecification cannot handle generate() with %d arguments", args.length);
  62     }
  63 
  64     void generate(LIRGeneratorTool gen, Value[] values) {
  65         if (values.length == 0) {
  66             generate(gen);
  67         } else if (values.length == 1) {
  68             generate(gen, values[0]);
  69         } else if (values.length == 2) {
  70             generate(gen, values[0], values[1]);
  71         } else if (values.length == 3) {
  72             generate(gen, values[0], values[1], values[2]);
  73         } else if (values.length == 4) {
  74             generate(gen, values[0], values[1], values[2], values[3]);
  75         } else if (values.length == 5) {
  76             generate(gen, values[0], values[1], values[2], values[3], values[4]);
  77         } else {
  78             GraalError.unimplemented();
  79         }
  80 
  81     }
  82 
  83     public void setOutput(String name, Value value) {
  84         output.put(name, value);
  85     }
  86 
  87     public Value getOutput(String name) {
  88         return output.get(name);
  89     }
  90 
  91     public void setResult(Value value) {
  92         result = value;
  93     }
  94 
  95     public Value getResult() {
  96         return result;
  97     }
  98 }