arb_program_interface_query: set vs_input2[1][0] as valid name
[piglit.git] / tests / llvmpipe / glsl / call.h
blobafeaa745e8a47de642d21c42a9c675432d82f7d8
1 /*
2 * Copyright © 2012-2021 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 #pragma once
26 #include "operator.h"
28 namespace glsl
30 typedef Value(* CallFunction)(ShaderState& state, const std::vector<Value>&);
32 class Call : public Operator
34 public:
35 Call(const std::string& name, const CallFunction& function)
36 : Operator(Operator::CALL), mName(name), mFunction(function)
40 Call(const std::string& name, const CallFunction& function, Operator* arg1)
41 : Operator(Operator::CALL), mName(name), mFunction(function)
43 mArguments.push_back(arg1);
46 Call(const std::string& name, const CallFunction& function, Operator* arg1, Operator* arg2)
47 : Operator(Operator::CALL), mName(name), mFunction(function)
49 mArguments.push_back(arg1);
50 mArguments.push_back(arg2);
53 Call(const std::string& name, const CallFunction& function, Operator* arg1, Operator* arg2, Operator* arg3)
54 : Operator(Operator::CALL), mName(name), mFunction(function)
56 mArguments.push_back(arg1);
57 mArguments.push_back(arg2);
58 mArguments.push_back(arg3);
61 Call(const std::string& name, const CallFunction& function, const std::vector<Operator*>& args)
62 : Operator(Operator::CALL), mName(name), mFunction(function), mArguments(args)
66 ~Call()
68 for (std::vector<Operator*>::iterator itr = mArguments.begin(); itr != mArguments.end(); ++itr) {
69 delete *itr;
73 virtual Value execute(ShaderState& state) const
75 std::vector<Value> args;
76 for (std::vector<Operator*>::const_iterator itr = mArguments.begin(); itr != mArguments.end(); ++itr) {
77 args.push_back((*itr)->execute(state));
80 return (*mFunction)(state, args);
83 virtual std::string toGLSL() const
85 std::string glsl = mName + "(";
87 for (std::vector<Operator*>::const_iterator itr = mArguments.begin(); itr != mArguments.end(); ++itr) {
88 if (itr != mArguments.begin())
89 glsl += ", ";
91 glsl += (*itr)->toGLSL();
94 return glsl + ")";
97 protected:
98 std::string mName;
99 CallFunction mFunction;
100 std::vector<Operator*> mArguments;