[lldb] Implement GetValueTypeFromAddressType
authorAugusto Noronha <augusto2112@me.com>
Wed, 26 Apr 2023 11:00:01 +0000 (12:00 +0100)
committerAugusto Noronha <augusto2112@me.com>
Thu, 18 May 2023 17:29:15 +0000 (10:29 -0700)
Value::ValueType is a superset of AddressType. Add a function to
convert an AddressType into a Value::ValueType.

Differential Revision: https://reviews.llvm.org/D150826

lldb/include/lldb/Core/Value.h
lldb/source/Core/Value.cpp

index fdda9f1..ead23ac 100644 (file)
@@ -145,6 +145,8 @@ public:
 
   void Clear();
 
+  static ValueType GetValueTypeFromAddressType(AddressType address_type);
+
 protected:
   Scalar m_value;
   CompilerType m_compiler_type;
index ccd3609..5a2631c 100644 (file)
@@ -121,6 +121,20 @@ AddressType Value::GetValueAddressType() const {
   return eAddressTypeInvalid;
 }
 
+Value::ValueType Value::GetValueTypeFromAddressType(AddressType address_type) {
+  switch (address_type) {
+    case eAddressTypeFile:
+      return Value::ValueType::FileAddress;
+    case eAddressTypeLoad:
+      return Value::ValueType::LoadAddress;
+    case eAddressTypeHost:
+      return Value::ValueType::HostAddress;
+    case eAddressTypeInvalid:
+      return Value::ValueType::Invalid;
+  }
+  llvm_unreachable("Unexpected address type!");
+}
+
 RegisterInfo *Value::GetRegisterInfo() const {
   if (m_context_type == ContextType::RegisterInfo)
     return static_cast<RegisterInfo *>(m_context);