dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 1 | // Copyright 2023 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 | |
dan sinclair | 97c3727 | 2023-07-24 17:11:53 +0000 | [diff] [blame] | 15 | #ifndef SRC_TINT_LANG_CORE_IR_CONVERT_H_ |
| 16 | #define SRC_TINT_LANG_CORE_IR_CONVERT_H_ |
dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 17 | |
dan sinclair | d8a06ae | 2023-09-06 19:26:56 +0000 | [diff] [blame] | 18 | #include <string> |
| 19 | |
dan sinclair | 97c3727 | 2023-07-24 17:11:53 +0000 | [diff] [blame] | 20 | #include "src/tint/lang/core/ir/call.h" |
dan sinclair | 352f8c8 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 21 | #include "src/tint/lang/core/type/type.h" |
dan sinclair | 22b4dd2 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 22 | #include "src/tint/utils/rtti/castable.h" |
dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 23 | |
dan sinclair | 6f138fe | 2023-08-15 21:29:34 +0000 | [diff] [blame] | 24 | namespace tint::core::ir { |
dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 25 | |
| 26 | /// A value conversion instruction in the IR. |
dan sinclair | 16cb4bd | 2023-09-21 08:52:11 +0000 | [diff] [blame] | 27 | class Convert final : public Castable<Convert, Call> { |
dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 28 | public: |
dan sinclair | 4934dc0 | 2023-06-16 12:11:56 +0000 | [diff] [blame] | 29 | /// The offset in Operands() for the value |
| 30 | static constexpr size_t kValueOperandOffset = 0; |
| 31 | |
dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 32 | /// Constructor |
dan sinclair | 0d80c3d | 2023-06-19 13:32:03 +0000 | [diff] [blame] | 33 | /// @param result the result value |
Ben Clayton | 4abe1b0 | 2023-06-09 18:20:18 +0000 | [diff] [blame] | 34 | /// @param value the value to convert |
dan sinclair | 0d80c3d | 2023-06-19 13:32:03 +0000 | [diff] [blame] | 35 | Convert(InstructionResult* result, Value* value); |
dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 36 | ~Convert() override; |
dan sinclair | 4bf1d07 | 2023-07-13 20:18:59 +0000 | [diff] [blame] | 37 | |
dan sinclair | 16cb4bd | 2023-09-21 08:52:11 +0000 | [diff] [blame] | 38 | /// @copydoc Instruction::Clone() |
| 39 | Convert* Clone(CloneContext& ctx) override; |
| 40 | |
dan sinclair | 4bf1d07 | 2023-07-13 20:18:59 +0000 | [diff] [blame] | 41 | /// @returns the friendly name for the instruction |
dan sinclair | d8a06ae | 2023-09-06 19:26:56 +0000 | [diff] [blame] | 42 | std::string FriendlyName() override { return "convert"; } |
dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
dan sinclair | 6f138fe | 2023-08-15 21:29:34 +0000 | [diff] [blame] | 45 | } // namespace tint::core::ir |
dan sinclair | 724a70f | 2023-03-08 21:19:13 +0000 | [diff] [blame] | 46 | |
dan sinclair | 97c3727 | 2023-07-24 17:11:53 +0000 | [diff] [blame] | 47 | #endif // SRC_TINT_LANG_CORE_IR_CONVERT_H_ |