blob: f6222ce5a7d1222dd418b4e7a9860f21f4d0dad3 [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
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000028 void setIConst(int i) {iConst = i; type = EbtInt; }
shannonwoods@chromium.org3c9d95a2013-05-30 00:19:46 +000029 void setUConst(unsigned int u) { uConst = u; type = EbtUInt; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000030 void setFConst(float f) {fConst = f; type = EbtFloat; }
31 void setBConst(bool b) {bConst = b; type = EbtBool; }
32
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033 int getIConst() const { return iConst; }
Nicolas Capensc0f7c612013-06-05 11:46:09 -040034 unsigned int getUConst() const { return uConst; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000035 float getFConst() const { return fConst; }
36 bool getBConst() const { return bConst; }
37
Jamie Madill47cb73a2016-09-09 11:41:44 -040038 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 Madill5db69f52016-09-15 12:47:32 -040052 TDiagnostics *diag,
53 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040054 static TConstantUnion sub(const TConstantUnion &lhs,
55 const TConstantUnion &rhs,
Jamie Madill5db69f52016-09-15 12:47:32 -040056 TDiagnostics *diag,
57 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040058 static TConstantUnion mul(const TConstantUnion &lhs,
59 const TConstantUnion &rhs,
Jamie Madill5db69f52016-09-15 12:47:32 -040060 TDiagnostics *diag,
61 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040062 TConstantUnion operator%(const TConstantUnion &constant) const;
Jamie Madill596018c2016-09-21 12:57:03 -040063 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 Madill47cb73a2016-09-09 11:41:44 -040071 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.com4f39fd92010-03-08 20:26:45 +000076
alokp@chromium.org76b82082010-03-24 17:59:39 +000077 TBasicType getType() const { return type; }
Jamie Madill47cb73a2016-09-09 11:41:44 -040078 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.com4f39fd92010-03-08 20:26:45 +000085
86 TBasicType type;
87};
88
Jamie Madill45bcc782016-11-07 13:58:48 -050089} // namespace sh
90
Geoff Lang0a73dd82014-11-19 16:18:08 -050091#endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_