gfx/angle/src/compiler/ConstantUnion.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 //
michael@0 2 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
michael@0 3 // Use of this source code is governed by a BSD-style license that can be
michael@0 4 // found in the LICENSE file.
michael@0 5 //
michael@0 6
michael@0 7 #ifndef _CONSTANT_UNION_INCLUDED_
michael@0 8 #define _CONSTANT_UNION_INCLUDED_
michael@0 9
michael@0 10 #include <assert.h>
michael@0 11
michael@0 12 class ConstantUnion {
michael@0 13 public:
michael@0 14 POOL_ALLOCATOR_NEW_DELETE();
michael@0 15 ConstantUnion()
michael@0 16 {
michael@0 17 iConst = 0;
michael@0 18 type = EbtVoid;
michael@0 19 }
michael@0 20
michael@0 21 void setIConst(int i) {iConst = i; type = EbtInt; }
michael@0 22 void setFConst(float f) {fConst = f; type = EbtFloat; }
michael@0 23 void setBConst(bool b) {bConst = b; type = EbtBool; }
michael@0 24
michael@0 25 int getIConst() { return iConst; }
michael@0 26 float getFConst() { return fConst; }
michael@0 27 bool getBConst() { return bConst; }
michael@0 28 int getIConst() const { return iConst; }
michael@0 29 float getFConst() const { return fConst; }
michael@0 30 bool getBConst() const { return bConst; }
michael@0 31
michael@0 32 bool operator==(const int i) const
michael@0 33 {
michael@0 34 return i == iConst;
michael@0 35 }
michael@0 36
michael@0 37 bool operator==(const float f) const
michael@0 38 {
michael@0 39 return f == fConst;
michael@0 40 }
michael@0 41
michael@0 42 bool operator==(const bool b) const
michael@0 43 {
michael@0 44 return b == bConst;
michael@0 45 }
michael@0 46
michael@0 47 bool operator==(const ConstantUnion& constant) const
michael@0 48 {
michael@0 49 if (constant.type != type)
michael@0 50 return false;
michael@0 51
michael@0 52 switch (type) {
michael@0 53 case EbtInt:
michael@0 54 return constant.iConst == iConst;
michael@0 55 case EbtFloat:
michael@0 56 return constant.fConst == fConst;
michael@0 57 case EbtBool:
michael@0 58 return constant.bConst == bConst;
michael@0 59 default:
michael@0 60 return false;
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 bool operator!=(const int i) const
michael@0 65 {
michael@0 66 return !operator==(i);
michael@0 67 }
michael@0 68
michael@0 69 bool operator!=(const float f) const
michael@0 70 {
michael@0 71 return !operator==(f);
michael@0 72 }
michael@0 73
michael@0 74 bool operator!=(const bool b) const
michael@0 75 {
michael@0 76 return !operator==(b);
michael@0 77 }
michael@0 78
michael@0 79 bool operator!=(const ConstantUnion& constant) const
michael@0 80 {
michael@0 81 return !operator==(constant);
michael@0 82 }
michael@0 83
michael@0 84 bool operator>(const ConstantUnion& constant) const
michael@0 85 {
michael@0 86 assert(type == constant.type);
michael@0 87 switch (type) {
michael@0 88 case EbtInt:
michael@0 89 return iConst > constant.iConst;
michael@0 90 case EbtFloat:
michael@0 91 return fConst > constant.fConst;
michael@0 92 default:
michael@0 93 return false; // Invalid operation, handled at semantic analysis
michael@0 94 }
michael@0 95 }
michael@0 96
michael@0 97 bool operator<(const ConstantUnion& constant) const
michael@0 98 {
michael@0 99 assert(type == constant.type);
michael@0 100 switch (type) {
michael@0 101 case EbtInt:
michael@0 102 return iConst < constant.iConst;
michael@0 103 case EbtFloat:
michael@0 104 return fConst < constant.fConst;
michael@0 105 default:
michael@0 106 return false; // Invalid operation, handled at semantic analysis
michael@0 107 }
michael@0 108 }
michael@0 109
michael@0 110 ConstantUnion operator+(const ConstantUnion& constant) const
michael@0 111 {
michael@0 112 ConstantUnion returnValue;
michael@0 113 assert(type == constant.type);
michael@0 114 switch (type) {
michael@0 115 case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
michael@0 116 case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break;
michael@0 117 default: assert(false && "Default missing");
michael@0 118 }
michael@0 119
michael@0 120 return returnValue;
michael@0 121 }
michael@0 122
michael@0 123 ConstantUnion operator-(const ConstantUnion& constant) const
michael@0 124 {
michael@0 125 ConstantUnion returnValue;
michael@0 126 assert(type == constant.type);
michael@0 127 switch (type) {
michael@0 128 case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
michael@0 129 case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break;
michael@0 130 default: assert(false && "Default missing");
michael@0 131 }
michael@0 132
michael@0 133 return returnValue;
michael@0 134 }
michael@0 135
michael@0 136 ConstantUnion operator*(const ConstantUnion& constant) const
michael@0 137 {
michael@0 138 ConstantUnion returnValue;
michael@0 139 assert(type == constant.type);
michael@0 140 switch (type) {
michael@0 141 case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
michael@0 142 case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break;
michael@0 143 default: assert(false && "Default missing");
michael@0 144 }
michael@0 145
michael@0 146 return returnValue;
michael@0 147 }
michael@0 148
michael@0 149 ConstantUnion operator%(const ConstantUnion& constant) const
michael@0 150 {
michael@0 151 ConstantUnion returnValue;
michael@0 152 assert(type == constant.type);
michael@0 153 switch (type) {
michael@0 154 case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
michael@0 155 default: assert(false && "Default missing");
michael@0 156 }
michael@0 157
michael@0 158 return returnValue;
michael@0 159 }
michael@0 160
michael@0 161 ConstantUnion operator>>(const ConstantUnion& constant) const
michael@0 162 {
michael@0 163 ConstantUnion returnValue;
michael@0 164 assert(type == constant.type);
michael@0 165 switch (type) {
michael@0 166 case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
michael@0 167 default: assert(false && "Default missing");
michael@0 168 }
michael@0 169
michael@0 170 return returnValue;
michael@0 171 }
michael@0 172
michael@0 173 ConstantUnion operator<<(const ConstantUnion& constant) const
michael@0 174 {
michael@0 175 ConstantUnion returnValue;
michael@0 176 assert(type == constant.type);
michael@0 177 switch (type) {
michael@0 178 case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
michael@0 179 default: assert(false && "Default missing");
michael@0 180 }
michael@0 181
michael@0 182 return returnValue;
michael@0 183 }
michael@0 184
michael@0 185 ConstantUnion operator&(const ConstantUnion& constant) const
michael@0 186 {
michael@0 187 ConstantUnion returnValue;
michael@0 188 assert(type == constant.type);
michael@0 189 switch (type) {
michael@0 190 case EbtInt: returnValue.setIConst(iConst & constant.iConst); break;
michael@0 191 default: assert(false && "Default missing");
michael@0 192 }
michael@0 193
michael@0 194 return returnValue;
michael@0 195 }
michael@0 196
michael@0 197 ConstantUnion operator|(const ConstantUnion& constant) const
michael@0 198 {
michael@0 199 ConstantUnion returnValue;
michael@0 200 assert(type == constant.type);
michael@0 201 switch (type) {
michael@0 202 case EbtInt: returnValue.setIConst(iConst | constant.iConst); break;
michael@0 203 default: assert(false && "Default missing");
michael@0 204 }
michael@0 205
michael@0 206 return returnValue;
michael@0 207 }
michael@0 208
michael@0 209 ConstantUnion operator^(const ConstantUnion& constant) const
michael@0 210 {
michael@0 211 ConstantUnion returnValue;
michael@0 212 assert(type == constant.type);
michael@0 213 switch (type) {
michael@0 214 case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break;
michael@0 215 default: assert(false && "Default missing");
michael@0 216 }
michael@0 217
michael@0 218 return returnValue;
michael@0 219 }
michael@0 220
michael@0 221 ConstantUnion operator&&(const ConstantUnion& constant) const
michael@0 222 {
michael@0 223 ConstantUnion returnValue;
michael@0 224 assert(type == constant.type);
michael@0 225 switch (type) {
michael@0 226 case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
michael@0 227 default: assert(false && "Default missing");
michael@0 228 }
michael@0 229
michael@0 230 return returnValue;
michael@0 231 }
michael@0 232
michael@0 233 ConstantUnion operator||(const ConstantUnion& constant) const
michael@0 234 {
michael@0 235 ConstantUnion returnValue;
michael@0 236 assert(type == constant.type);
michael@0 237 switch (type) {
michael@0 238 case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
michael@0 239 default: assert(false && "Default missing");
michael@0 240 }
michael@0 241
michael@0 242 return returnValue;
michael@0 243 }
michael@0 244
michael@0 245 TBasicType getType() const { return type; }
michael@0 246 private:
michael@0 247
michael@0 248 union {
michael@0 249 int iConst; // used for ivec, scalar ints
michael@0 250 bool bConst; // used for bvec, scalar bools
michael@0 251 float fConst; // used for vec, mat, scalar floats
michael@0 252 } ;
michael@0 253
michael@0 254 TBasicType type;
michael@0 255 };
michael@0 256
michael@0 257 #endif // _CONSTANT_UNION_INCLUDED_

mercurial