blob: dbec67ea67cebae0494f6efee7c5662c9a704b6c [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens01df23e2014-06-11 10:56:03 -04002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_CONSTANTUNION_H_
8#define COMPILER_TRANSLATOR_CONSTANTUNION_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009
alokp@chromium.org4e4facd2010-06-02 15:21:22 +000010#include <assert.h>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011
Jamie Madill47cb73a2016-09-09 11:41:44 -040012#include "compiler/translator/Common.h"
Jamie Madill6ba6ead2015-05-04 14:21:21 -040013#include "compiler/translator/BaseTypes.h"
14
Jamie Madill45bcc782016-11-07 13:58:48 -050015namespace sh
16{
17
Jamie Madill47cb73a2016-09-09 11:41:44 -040018class TDiagnostics;
19
20class TConstantUnion
21{
22 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040023 POOL_ALLOCATOR_NEW_DELETE();
Jamie Madill47cb73a2016-09-09 11:41:44 -040024 TConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
Jamie Madill47cb73a2016-09-09 11:41:44 -040026 bool cast(TBasicType newType, const TConstantUnion &constant);
Nicolas Capens01df23e2014-06-11 10:56:03 -040027
Jamie Madilld7b1ab52016-12-12 14:42:19 -050028 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.com4f39fd92010-03-08 20:26:45 +000048
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049 int getIConst() const { return iConst; }
Nicolas Capensc0f7c612013-06-05 11:46:09 -040050 unsigned int getUConst() const { return uConst; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000051 float getFConst() const { return fConst; }
52 bool getBConst() const { return bConst; }
53
Jamie Madill47cb73a2016-09-09 11:41:44 -040054 bool operator==(const int i) const;
55 bool operator==(const unsigned int u) const;
56 bool operator==(const float f) const;
57 bool operator==(const bool b) const;
58 bool operator==(const TConstantUnion &constant) const;
59 bool operator!=(const int i) const;
60 bool operator!=(const unsigned int u) const;
61 bool operator!=(const float f) const;
62 bool operator!=(const bool b) const;
63 bool operator!=(const TConstantUnion &constant) const;
64 bool operator>(const TConstantUnion &constant) const;
65 bool operator<(const TConstantUnion &constant) const;
66 static TConstantUnion add(const TConstantUnion &lhs,
67 const TConstantUnion &rhs,
Jamie Madill5db69f52016-09-15 12:47:32 -040068 TDiagnostics *diag,
69 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040070 static TConstantUnion sub(const TConstantUnion &lhs,
71 const TConstantUnion &rhs,
Jamie Madill5db69f52016-09-15 12:47:32 -040072 TDiagnostics *diag,
73 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040074 static TConstantUnion mul(const TConstantUnion &lhs,
75 const TConstantUnion &rhs,
Jamie Madill5db69f52016-09-15 12:47:32 -040076 TDiagnostics *diag,
77 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040078 TConstantUnion operator%(const TConstantUnion &constant) const;
Jamie Madill596018c2016-09-21 12:57:03 -040079 static TConstantUnion rshift(const TConstantUnion &lhs,
80 const TConstantUnion &rhs,
81 TDiagnostics *diag,
82 const TSourceLoc &line);
83 static TConstantUnion lshift(const TConstantUnion &lhs,
84 const TConstantUnion &rhs,
85 TDiagnostics *diag,
86 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040087 TConstantUnion operator&(const TConstantUnion &constant) const;
88 TConstantUnion operator|(const TConstantUnion &constant) const;
89 TConstantUnion operator^(const TConstantUnion &constant) const;
90 TConstantUnion operator&&(const TConstantUnion &constant) const;
91 TConstantUnion operator||(const TConstantUnion &constant) const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000092
alokp@chromium.org76b82082010-03-24 17:59:39 +000093 TBasicType getType() const { return type; }
Jamie Madill47cb73a2016-09-09 11:41:44 -040094 private:
95 union {
96 int iConst; // used for ivec, scalar ints
97 unsigned int uConst; // used for uvec, scalar uints
98 bool bConst; // used for bvec, scalar bools
99 float fConst; // used for vec, mat, scalar floats
100 };
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000101
102 TBasicType type;
103};
104
Jamie Madill45bcc782016-11-07 13:58:48 -0500105} // namespace sh
106
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500107#endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_