arb_program_interface_query: set vs_input2[1][0] as valid name
[piglit.git] / tests / llvmpipe / glsl / binaryoperator.h
blobb6552b87d5544b2c80355ec00e6acf188e4d2ea8
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"
27 #include "constant.h"
29 namespace glsl
31 class BinaryOperator : public Operator
33 public:
34 enum bOperator {
35 ADD,
36 SUB,
37 MUL,
38 DIV,
39 MOV
42 public:
43 BinaryOperator(bOperator op, Operator* left, Operator* right)
44 : Operator(Operator::BINARY), mOperator(op), mLeft(left), mRight(right)
48 ~BinaryOperator()
50 if (mLeft)
51 delete mLeft;
53 if (mRight)
54 delete mRight;
57 virtual Value execute(ShaderState& state) const
59 switch (mOperator) {
60 case ADD:
61 return mLeft->execute(state) + mRight->execute(state);
62 case SUB:
63 return mLeft->execute(state) - mRight->execute(state);
64 case MUL:
65 return mLeft->execute(state) * mRight->execute(state);
66 case DIV:
67 return mLeft->execute(state) / mRight->execute(state);
68 case MOV:
69 assert(mLeft->operatorType() == Operator::CONSTANT);
70 ((Constant*)mLeft)->setValue(state, mRight->execute(state));
71 return mLeft->execute(state);
72 default:
73 return Value::vec4;
77 virtual std::string toGLSL() const
79 std::string glsl = mLeft->toGLSL() + " " + toOperatorString() + " " + mRight->toGLSL();
81 if (mOperator != MOV && (mLeft->operatorType() == Operator::BINARY || mRight->operatorType() == Operator::BINARY))
82 return std::string("(") + glsl + ")";
83 else
84 return glsl;
87 bOperator op() const
89 return mOperator;
92 Operator* left() const
94 return mLeft;
97 Operator* right() const
99 return mRight;
102 protected:
103 std::string toOperatorString() const
105 static const char* names[] = {
106 "+",
107 "-",
108 "*",
109 "/",
113 return names[mOperator];
116 protected:
117 bOperator mOperator;
118 Operator* mLeft;
119 Operator* mRight;