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 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 28 | void setIConst(int i) |
| 29 | { |
| 30 | iConst = i; |
| 31 | type = EbtInt; |
| 32 | } |
| 33 | void setUConst(unsigned int u) |
| 34 | { |
| 35 | uConst = u; |
| 36 | type = EbtUInt; |
| 37 | } |
| 38 | void setFConst(float f) |
| 39 | { |
| 40 | fConst = f; |
| 41 | type = EbtFloat; |
| 42 | } |
| 43 | void setBConst(bool b) |
| 44 | { |
| 45 | bConst = b; |
| 46 | type = EbtBool; |
| 47 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 48 | |
Andrei Volykhin | a552707 | 2017-03-22 16:46:30 +0300 | [diff] [blame] | 49 | void setYuvCscStandardEXTConst(TYuvCscStandardEXT s) |
| 50 | { |
| 51 | yuvCscStandardEXTConst = s; |
| 52 | type = EbtYuvCscStandardEXT; |
| 53 | } |
| 54 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 55 | int getIConst() const { return iConst; } |
Nicolas Capens | c0f7c61 | 2013-06-05 11:46:09 -0400 | [diff] [blame] | 56 | unsigned int getUConst() const { return uConst; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 57 | float getFConst() const { return fConst; } |
| 58 | bool getBConst() const { return bConst; } |
Andrei Volykhin | a552707 | 2017-03-22 16:46:30 +0300 | [diff] [blame] | 59 | TYuvCscStandardEXT getYuvCscStandardEXTConst() const { return yuvCscStandardEXTConst; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 60 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 61 | bool operator==(const int i) const; |
| 62 | bool operator==(const unsigned int u) const; |
| 63 | bool operator==(const float f) const; |
| 64 | bool operator==(const bool b) const; |
Andrei Volykhin | a552707 | 2017-03-22 16:46:30 +0300 | [diff] [blame] | 65 | bool operator==(const TYuvCscStandardEXT s) const; |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 66 | bool operator==(const TConstantUnion &constant) const; |
| 67 | bool operator!=(const int i) const; |
| 68 | bool operator!=(const unsigned int u) const; |
| 69 | bool operator!=(const float f) const; |
| 70 | bool operator!=(const bool b) const; |
Andrei Volykhin | a552707 | 2017-03-22 16:46:30 +0300 | [diff] [blame] | 71 | bool operator!=(const TYuvCscStandardEXT s) const; |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 72 | bool operator!=(const TConstantUnion &constant) const; |
| 73 | bool operator>(const TConstantUnion &constant) const; |
| 74 | bool operator<(const TConstantUnion &constant) const; |
| 75 | static TConstantUnion add(const TConstantUnion &lhs, |
| 76 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame] | 77 | TDiagnostics *diag, |
| 78 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 79 | static TConstantUnion sub(const TConstantUnion &lhs, |
| 80 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame] | 81 | TDiagnostics *diag, |
| 82 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 83 | static TConstantUnion mul(const TConstantUnion &lhs, |
| 84 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame] | 85 | TDiagnostics *diag, |
| 86 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 87 | TConstantUnion operator%(const TConstantUnion &constant) const; |
Jamie Madill | 596018c | 2016-09-21 12:57:03 -0400 | [diff] [blame] | 88 | static TConstantUnion rshift(const TConstantUnion &lhs, |
| 89 | const TConstantUnion &rhs, |
| 90 | TDiagnostics *diag, |
| 91 | const TSourceLoc &line); |
| 92 | static TConstantUnion lshift(const TConstantUnion &lhs, |
| 93 | const TConstantUnion &rhs, |
| 94 | TDiagnostics *diag, |
| 95 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 96 | TConstantUnion operator&(const TConstantUnion &constant) const; |
| 97 | TConstantUnion operator|(const TConstantUnion &constant) const; |
| 98 | TConstantUnion operator^(const TConstantUnion &constant) const; |
| 99 | TConstantUnion operator&&(const TConstantUnion &constant) const; |
| 100 | TConstantUnion operator||(const TConstantUnion &constant) const; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 101 | |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 102 | TBasicType getType() const { return type; } |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 103 | private: |
| 104 | union { |
| 105 | int iConst; // used for ivec, scalar ints |
| 106 | unsigned int uConst; // used for uvec, scalar uints |
| 107 | bool bConst; // used for bvec, scalar bools |
| 108 | float fConst; // used for vec, mat, scalar floats |
Andrei Volykhin | a552707 | 2017-03-22 16:46:30 +0300 | [diff] [blame] | 109 | TYuvCscStandardEXT yuvCscStandardEXTConst; |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 110 | }; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 111 | |
| 112 | TBasicType type; |
| 113 | }; |
| 114 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 115 | } // namespace sh |
| 116 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 117 | #endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_ |