• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
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  */
15 
16 #ifndef PANDA_RUNTIME_INCLUDE_TOOLING_VREG_VALUE_H
17 #define PANDA_RUNTIME_INCLUDE_TOOLING_VREG_VALUE_H
18 
19 #include <cstdint>
20 
21 #include "libpandabase/macros.h"
22 #include "include/coretypes/tagged_value.h"
23 #include "include/typed_value.h"
24 
25 namespace ark::tooling {
26 class VRegValue {
27 public:
value_(value)28     constexpr explicit VRegValue(int64_t value = 0) : value_(value) {}
29 
GetValue()30     constexpr int64_t GetValue() const
31     {
32         return value_;
33     }
34 
SetValue(int64_t value)35     constexpr void SetValue(int64_t value)
36     {
37         value_ = value;
38     }
39 
ToTypedValue(panda_file::Type::TypeId typeId)40     TypedValue ToTypedValue(panda_file::Type::TypeId typeId)
41     {
42         switch (typeId) {
43             case panda_file::Type::TypeId::INVALID:
44                 return TypedValue::Invalid();
45             case panda_file::Type::TypeId::VOID:
46                 return TypedValue::Void();
47             case panda_file::Type::TypeId::U1:
48                 return TypedValue::U1(static_cast<bool>(GetValue()));
49             case panda_file::Type::TypeId::I8:
50                 return TypedValue::I8(static_cast<int8_t>(GetValue()));
51             case panda_file::Type::TypeId::U8:
52                 return TypedValue::U8(static_cast<uint8_t>(GetValue()));
53             case panda_file::Type::TypeId::I16:
54                 return TypedValue::I16(static_cast<int16_t>(GetValue()));
55             case panda_file::Type::TypeId::U16:
56                 return TypedValue::U16(static_cast<uint16_t>(GetValue()));
57             case panda_file::Type::TypeId::I32:
58                 return TypedValue::I32(static_cast<int32_t>(GetValue()));
59             case panda_file::Type::TypeId::U32:
60                 return TypedValue::U32(static_cast<uint32_t>(GetValue()));
61             case panda_file::Type::TypeId::F32:
62                 return TypedValue::F32(bit_cast<float>(static_cast<uint32_t>(GetValue())));
63             case panda_file::Type::TypeId::F64:
64                 return TypedValue::F64(bit_cast<double>(static_cast<uint64_t>(GetValue())));
65             case panda_file::Type::TypeId::I64:
66                 return TypedValue::I64(static_cast<int64_t>(GetValue()));
67             case panda_file::Type::TypeId::U64:
68                 return TypedValue::U64(static_cast<uint64_t>(GetValue()));
69             case panda_file::Type::TypeId::REFERENCE:
70                 return TypedValue::Reference(reinterpret_cast<ObjectHeader *>(GetValue()));
71             case panda_file::Type::TypeId::TAGGED:
72                 return TypedValue::Tagged(coretypes::TaggedValue(GetValue()));
73         }
74         UNREACHABLE();
75     }
76 
77     ~VRegValue() = default;
78 
79     DEFAULT_COPY_SEMANTIC(VRegValue);
80     DEFAULT_MOVE_SEMANTIC(VRegValue);
81 
82 private:
83     int64_t value_;
84 };
85 }  // namespace ark::tooling
86 
87 #endif  // PANDA_RUNTIME_INCLUDE_TOOLING_VREG_VALUE_H
88