blob: 6699c18b9ecb1a29dfbca7dc619fc63cabb8086a [file] [log] [blame]
dan sinclair724a70f2023-03-08 21:19:13 +00001// 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 sinclair97c37272023-07-24 17:11:53 +000015#ifndef SRC_TINT_LANG_CORE_IR_CONVERT_H_
16#define SRC_TINT_LANG_CORE_IR_CONVERT_H_
dan sinclair724a70f2023-03-08 21:19:13 +000017
dan sinclaird8a06ae2023-09-06 19:26:56 +000018#include <string>
19
dan sinclair97c37272023-07-24 17:11:53 +000020#include "src/tint/lang/core/ir/call.h"
dan sinclair352f8c82023-07-21 00:40:07 +000021#include "src/tint/lang/core/type/type.h"
dan sinclair22b4dd22023-07-21 00:40:07 +000022#include "src/tint/utils/rtti/castable.h"
dan sinclair724a70f2023-03-08 21:19:13 +000023
dan sinclair6f138fe2023-08-15 21:29:34 +000024namespace tint::core::ir {
dan sinclair724a70f2023-03-08 21:19:13 +000025
26/// A value conversion instruction in the IR.
dan sinclair16cb4bd2023-09-21 08:52:11 +000027class Convert final : public Castable<Convert, Call> {
dan sinclair724a70f2023-03-08 21:19:13 +000028 public:
dan sinclair4934dc02023-06-16 12:11:56 +000029 /// The offset in Operands() for the value
30 static constexpr size_t kValueOperandOffset = 0;
31
dan sinclair724a70f2023-03-08 21:19:13 +000032 /// Constructor
dan sinclair0d80c3d2023-06-19 13:32:03 +000033 /// @param result the result value
Ben Clayton4abe1b02023-06-09 18:20:18 +000034 /// @param value the value to convert
dan sinclair0d80c3d2023-06-19 13:32:03 +000035 Convert(InstructionResult* result, Value* value);
dan sinclair724a70f2023-03-08 21:19:13 +000036 ~Convert() override;
dan sinclair4bf1d072023-07-13 20:18:59 +000037
dan sinclair16cb4bd2023-09-21 08:52:11 +000038 /// @copydoc Instruction::Clone()
39 Convert* Clone(CloneContext& ctx) override;
40
dan sinclair4bf1d072023-07-13 20:18:59 +000041 /// @returns the friendly name for the instruction
dan sinclaird8a06ae2023-09-06 19:26:56 +000042 std::string FriendlyName() override { return "convert"; }
dan sinclair724a70f2023-03-08 21:19:13 +000043};
44
dan sinclair6f138fe2023-08-15 21:29:34 +000045} // namespace tint::core::ir
dan sinclair724a70f2023-03-08 21:19:13 +000046
dan sinclair97c37272023-07-24 17:11:53 +000047#endif // SRC_TINT_LANG_CORE_IR_CONVERT_H_