[lld][WebAssembly] Perform data relocations during start function
[llvm-project.git] / lldb / source / Target / RegisterNumber.cpp
blobe5610bf588543fcc81114db838f044bb0b516601
1 //===-- RegisterNumber.cpp ------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Target/RegisterNumber.h"
10 #include "lldb/Target/RegisterContext.h"
11 #include "lldb/Target/Thread.h"
13 using namespace lldb_private;
15 RegisterNumber::RegisterNumber(lldb_private::Thread &thread,
16 lldb::RegisterKind kind, uint32_t num)
17 : m_reg_ctx_sp(thread.GetRegisterContext()), m_regnum(num), m_kind(kind),
18 m_kind_regnum_map(), m_name("") {
19 if (m_reg_ctx_sp.get()) {
20 const lldb_private::RegisterInfo *reginfo =
21 m_reg_ctx_sp->GetRegisterInfoAtIndex(
22 GetAsKind(lldb::eRegisterKindLLDB));
23 if (reginfo && reginfo->name) {
24 m_name = reginfo->name;
29 RegisterNumber::RegisterNumber() : m_reg_ctx_sp(), m_kind_regnum_map() {}
31 void RegisterNumber::init(lldb_private::Thread &thread, lldb::RegisterKind kind,
32 uint32_t num) {
33 m_reg_ctx_sp = thread.GetRegisterContext();
34 m_regnum = num;
35 m_kind = kind;
36 if (m_reg_ctx_sp.get()) {
37 const lldb_private::RegisterInfo *reginfo =
38 m_reg_ctx_sp->GetRegisterInfoAtIndex(
39 GetAsKind(lldb::eRegisterKindLLDB));
40 if (reginfo && reginfo->name) {
41 m_name = reginfo->name;
46 const RegisterNumber &RegisterNumber::operator=(const RegisterNumber &rhs) {
47 m_reg_ctx_sp = rhs.m_reg_ctx_sp;
48 m_regnum = rhs.m_regnum;
49 m_kind = rhs.m_kind;
50 for (auto it : rhs.m_kind_regnum_map)
51 m_kind_regnum_map[it.first] = it.second;
52 m_name = rhs.m_name;
53 return *this;
56 bool RegisterNumber::operator==(RegisterNumber &rhs) {
57 if (IsValid() != rhs.IsValid())
58 return false;
60 if (m_kind == rhs.m_kind) {
61 return m_regnum == rhs.m_regnum;
64 uint32_t rhs_regnum = rhs.GetAsKind(m_kind);
65 if (rhs_regnum != LLDB_INVALID_REGNUM) {
66 return m_regnum == rhs_regnum;
68 uint32_t lhs_regnum = GetAsKind(rhs.m_kind);
69 { return lhs_regnum == rhs.m_regnum; }
70 return false;
73 bool RegisterNumber::operator!=(RegisterNumber &rhs) { return !(*this == rhs); }
75 bool RegisterNumber::IsValid() const {
76 return m_reg_ctx_sp.get() && m_kind != lldb::kNumRegisterKinds &&
77 m_regnum != LLDB_INVALID_REGNUM;
80 uint32_t RegisterNumber::GetAsKind(lldb::RegisterKind kind) {
81 if (m_regnum == LLDB_INVALID_REGNUM)
82 return LLDB_INVALID_REGNUM;
84 if (kind == m_kind)
85 return m_regnum;
87 Collection::iterator iter = m_kind_regnum_map.find(kind);
88 if (iter != m_kind_regnum_map.end()) {
89 return iter->second;
91 uint32_t output_regnum = LLDB_INVALID_REGNUM;
92 if (m_reg_ctx_sp &&
93 m_reg_ctx_sp->ConvertBetweenRegisterKinds(m_kind, m_regnum, kind,
94 output_regnum) &&
95 output_regnum != LLDB_INVALID_REGNUM) {
96 m_kind_regnum_map[kind] = output_regnum;
98 return output_regnum;
101 uint32_t RegisterNumber::GetRegisterNumber() const { return m_regnum; }
103 lldb::RegisterKind RegisterNumber::GetRegisterKind() const { return m_kind; }
105 const char *RegisterNumber::GetName() { return m_name; }