Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1 | // Copyright 2020 The Tint Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Ben Clayton | 01004b7 | 2022-04-28 18:49:04 +0000 | [diff] [blame] | 15 | #ifndef SRC_TINT_SEM_BOOL_H_ |
| 16 | #define SRC_TINT_SEM_BOOL_H_ |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 17 | |
| 18 | #include <string> |
| 19 | |
| 20 | #include "src/tint/sem/type.h" |
| 21 | |
| 22 | // X11 likes to #define Bool leading to confusing error messages. |
| 23 | // If its defined, undefine it. |
| 24 | #ifdef Bool |
| 25 | #undef Bool |
| 26 | #endif |
| 27 | |
dan sinclair | c990b3c | 2022-04-07 16:04:35 +0000 | [diff] [blame] | 28 | namespace tint::sem { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 29 | |
| 30 | /// A boolean type |
Ben Clayton | 41f8d2a | 2022-03-07 18:37:46 +0000 | [diff] [blame] | 31 | class Bool final : public Castable<Bool, Type> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame^] | 32 | public: |
| 33 | /// Constructor |
| 34 | Bool(); |
| 35 | /// Move constructor |
| 36 | Bool(Bool&&); |
| 37 | ~Bool() override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 38 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame^] | 39 | /// @returns a hash of the type. |
| 40 | size_t Hash() const override; |
Ben Clayton | 4391975 | 2022-03-07 17:05:28 +0000 | [diff] [blame] | 41 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame^] | 42 | /// @param other the other type to compare against |
| 43 | /// @returns true if the this type is equal to the given type |
| 44 | bool Equals(const Type& other) const override; |
Ben Clayton | 4391975 | 2022-03-07 17:05:28 +0000 | [diff] [blame] | 45 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame^] | 46 | /// @param symbols the program's symbol table |
| 47 | /// @returns the name for this type that closely resembles how it would be |
| 48 | /// declared in WGSL. |
| 49 | std::string FriendlyName(const SymbolTable& symbols) const override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 50 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame^] | 51 | /// @returns true if constructible as per |
| 52 | /// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types |
| 53 | bool IsConstructible() const override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 54 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame^] | 55 | /// @returns the size in bytes of the type. |
| 56 | /// @note: booleans are not host-sharable, but still may exist in workgroup |
| 57 | /// storage. |
| 58 | uint32_t Size() const override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 59 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame^] | 60 | /// @returns the alignment in bytes of the type. |
| 61 | /// @note: booleans are not host-sharable, but still may exist in workgroup |
| 62 | /// storage. |
| 63 | uint32_t Align() const override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
dan sinclair | c990b3c | 2022-04-07 16:04:35 +0000 | [diff] [blame] | 66 | } // namespace tint::sem |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 67 | |
Ben Clayton | 01004b7 | 2022-04-28 18:49:04 +0000 | [diff] [blame] | 68 | #endif // SRC_TINT_SEM_BOOL_H_ |