001/*
002 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.lir.jtt;
024
025import java.util.*;
026
027import jdk.internal.jvmci.common.*;
028import jdk.internal.jvmci.meta.*;
029
030import com.oracle.graal.lir.gen.*;
031
032public abstract class LIRTestSpecification {
033    private Value result;
034    private final HashMap<String, Value> output = new HashMap<>();
035
036    public void generate(LIRGeneratorTool gen) {
037        defaultHandler(gen);
038    }
039
040    public void generate(LIRGeneratorTool gen, Value arg0) {
041        defaultHandler(gen, arg0);
042    }
043
044    public void generate(LIRGeneratorTool gen, Value arg0, Value arg1) {
045        defaultHandler(gen, arg0, arg1);
046    }
047
048    public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2) {
049        defaultHandler(gen, arg0, arg1, arg2);
050    }
051
052    public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2, Value arg3) {
053        defaultHandler(gen, arg0, arg1, arg2, arg3);
054    }
055
056    public void generate(LIRGeneratorTool gen, Value arg0, Value arg1, Value arg2, Value arg3, Value arg4) {
057        defaultHandler(gen, arg0, arg1, arg2, arg3, arg4);
058    }
059
060    private static void defaultHandler(@SuppressWarnings("unused") LIRGeneratorTool gen, Value... args) {
061        throw new JVMCIError("LIRTestSpecification cannot handle generate() with %d arguments", args.length);
062    }
063
064    void generate(LIRGeneratorTool gen, Value[] values) {
065        if (values.length == 0) {
066            generate(gen);
067        } else if (values.length == 1) {
068            generate(gen, values[0]);
069        } else if (values.length == 2) {
070            generate(gen, values[0], values[1]);
071        } else if (values.length == 3) {
072            generate(gen, values[0], values[1], values[2]);
073        } else if (values.length == 4) {
074            generate(gen, values[0], values[1], values[2], values[3]);
075        } else if (values.length == 5) {
076            generate(gen, values[0], values[1], values[2], values[3], values[4]);
077        } else {
078            JVMCIError.unimplemented();
079        }
080
081    }
082
083    public void setOutput(String name, Value value) {
084        output.put(name, value);
085    }
086
087    public Value getOutput(String name) {
088        return output.get(name);
089    }
090
091    public void setResult(Value value) {
092        result = value;
093    }
094
095    public Value getResult() {
096        assert result != null : "Result not set (using setResult())";
097        return result;
098    }
099}