daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 01df23e | 2014-06-11 10:56:03 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 7 | #ifndef COMPILER_TRANSLATOR_CONSTANTUNION_H_ |
| 8 | #define COMPILER_TRANSLATOR_CONSTANTUNION_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 9 | |
alokp@chromium.org | 4e4facd | 2010-06-02 15:21:22 +0000 | [diff] [blame] | 10 | #include <assert.h> |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 11 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 12 | #include "compiler/translator/Common.h" |
Jamie Madill | 6ba6ead | 2015-05-04 14:21:21 -0400 | [diff] [blame] | 13 | #include "compiler/translator/BaseTypes.h" |
| 14 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame^] | 15 | namespace sh |
| 16 | { |
| 17 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 18 | class TDiagnostics; |
| 19 | |
| 20 | class TConstantUnion |
| 21 | { |
| 22 | public: |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 23 | POOL_ALLOCATOR_NEW_DELETE(); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 24 | TConstantUnion(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 25 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 26 | bool cast(TBasicType newType, const TConstantUnion &constant); |
Nicolas Capens | 01df23e | 2014-06-11 10:56:03 -0400 | [diff] [blame] | 27 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 28 | void setIConst(int i) {iConst = i; type = EbtInt; } |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 29 | void setUConst(unsigned int u) { uConst = u; type = EbtUInt; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 30 | void setFConst(float f) {fConst = f; type = EbtFloat; } |
| 31 | void setBConst(bool b) {bConst = b; type = EbtBool; } |
| 32 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 33 | int getIConst() const { return iConst; } |
Nicolas Capens | c0f7c61 | 2013-06-05 11:46:09 -0400 | [diff] [blame] | 34 | unsigned int getUConst() const { return uConst; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 35 | float getFConst() const { return fConst; } |
| 36 | bool getBConst() const { return bConst; } |
| 37 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 38 | bool operator==(const int i) const; |
| 39 | bool operator==(const unsigned int u) const; |
| 40 | bool operator==(const float f) const; |
| 41 | bool operator==(const bool b) const; |
| 42 | bool operator==(const TConstantUnion &constant) const; |
| 43 | bool operator!=(const int i) const; |
| 44 | bool operator!=(const unsigned int u) const; |
| 45 | bool operator!=(const float f) const; |
| 46 | bool operator!=(const bool b) const; |
| 47 | bool operator!=(const TConstantUnion &constant) const; |
| 48 | bool operator>(const TConstantUnion &constant) const; |
| 49 | bool operator<(const TConstantUnion &constant) const; |
| 50 | static TConstantUnion add(const TConstantUnion &lhs, |
| 51 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame] | 52 | TDiagnostics *diag, |
| 53 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 54 | static TConstantUnion sub(const TConstantUnion &lhs, |
| 55 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame] | 56 | TDiagnostics *diag, |
| 57 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 58 | static TConstantUnion mul(const TConstantUnion &lhs, |
| 59 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame] | 60 | TDiagnostics *diag, |
| 61 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 62 | TConstantUnion operator%(const TConstantUnion &constant) const; |
Jamie Madill | 596018c | 2016-09-21 12:57:03 -0400 | [diff] [blame] | 63 | static TConstantUnion rshift(const TConstantUnion &lhs, |
| 64 | const TConstantUnion &rhs, |
| 65 | TDiagnostics *diag, |
| 66 | const TSourceLoc &line); |
| 67 | static TConstantUnion lshift(const TConstantUnion &lhs, |
| 68 | const TConstantUnion &rhs, |
| 69 | TDiagnostics *diag, |
| 70 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 71 | TConstantUnion operator&(const TConstantUnion &constant) const; |
| 72 | TConstantUnion operator|(const TConstantUnion &constant) const; |
| 73 | TConstantUnion operator^(const TConstantUnion &constant) const; |
| 74 | TConstantUnion operator&&(const TConstantUnion &constant) const; |
| 75 | TConstantUnion operator||(const TConstantUnion &constant) const; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 76 | |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 77 | TBasicType getType() const { return type; } |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 78 | private: |
| 79 | union { |
| 80 | int iConst; // used for ivec, scalar ints |
| 81 | unsigned int uConst; // used for uvec, scalar uints |
| 82 | bool bConst; // used for bvec, scalar bools |
| 83 | float fConst; // used for vec, mat, scalar floats |
| 84 | }; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 85 | |
| 86 | TBasicType type; |
| 87 | }; |
| 88 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame^] | 89 | } // namespace sh |
| 90 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 91 | #endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_ |