File indexing completed on 2026-05-10 08:42:54
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_TARGET_REGISTERFLAGS_H
0010 #define LLDB_TARGET_REGISTERFLAGS_H
0011
0012 #include <stdint.h>
0013 #include <string>
0014 #include <vector>
0015
0016 #include "llvm/ADT/StringSet.h"
0017
0018 namespace lldb_private {
0019
0020 class Stream;
0021 class Log;
0022
0023 class FieldEnum {
0024 public:
0025 struct Enumerator {
0026 uint64_t m_value;
0027
0028
0029 std::string m_name;
0030
0031 Enumerator(uint64_t value, std::string name)
0032 : m_value(value), m_name(std::move(name)) {}
0033
0034 void ToXML(Stream &strm) const;
0035
0036 void DumpToLog(Log *log) const;
0037 };
0038
0039 typedef std::vector<Enumerator> Enumerators;
0040
0041
0042
0043
0044 FieldEnum(std::string id, const Enumerators &enumerators);
0045
0046 const Enumerators &GetEnumerators() const { return m_enumerators; }
0047
0048 const std::string &GetID() const { return m_id; }
0049
0050 void ToXML(Stream &strm, unsigned size) const;
0051
0052 void DumpToLog(Log *log) const;
0053
0054 private:
0055 std::string m_id;
0056 Enumerators m_enumerators;
0057 };
0058
0059 class RegisterFlags {
0060 public:
0061 class Field {
0062 public:
0063
0064
0065 Field(std::string name, unsigned start, unsigned end);
0066
0067
0068 Field(std::string name, unsigned start, unsigned end,
0069 const FieldEnum *enum_type);
0070
0071
0072 Field(std::string name, unsigned bit_position);
0073
0074
0075 unsigned GetSizeInBits() const;
0076
0077
0078 static unsigned GetSizeInBits(unsigned start, unsigned end);
0079
0080
0081 uint64_t GetMask() const;
0082
0083
0084 uint64_t GetMaxValue() const;
0085
0086
0087 static uint64_t GetMaxValue(unsigned start, unsigned end);
0088
0089
0090 uint64_t GetValue(uint64_t register_value) const {
0091 return (register_value & GetMask()) >> m_start;
0092 }
0093
0094 const std::string &GetName() const { return m_name; }
0095 unsigned GetStart() const { return m_start; }
0096 unsigned GetEnd() const { return m_end; }
0097 const FieldEnum *GetEnum() const { return m_enum_type; }
0098 bool Overlaps(const Field &other) const;
0099 void DumpToLog(Log *log) const;
0100
0101
0102
0103 unsigned PaddingDistance(const Field &other) const;
0104
0105
0106
0107
0108 void ToXML(Stream &strm) const;
0109
0110 bool operator<(const Field &rhs) const {
0111 return GetStart() < rhs.GetStart();
0112 }
0113
0114 bool operator==(const Field &rhs) const {
0115 return (m_name == rhs.m_name) && (m_start == rhs.m_start) &&
0116 (m_end == rhs.m_end);
0117 }
0118
0119 private:
0120 std::string m_name;
0121
0122
0123
0124
0125
0126 unsigned m_start;
0127 unsigned m_end;
0128
0129 const FieldEnum *m_enum_type;
0130 };
0131
0132
0133
0134
0135
0136 RegisterFlags(std::string id, unsigned size,
0137 const std::vector<Field> &fields);
0138
0139
0140
0141
0142 void SetFields(const std::vector<Field> &fields);
0143
0144
0145
0146 std::string DumpEnums(uint32_t max_width) const;
0147
0148
0149
0150
0151
0152
0153
0154 template <typename T> T ReverseFieldOrder(T value) const {
0155 T ret = 0;
0156 unsigned shift = 0;
0157 for (auto field : GetFields()) {
0158 ret |= field.GetValue(value) << shift;
0159 shift += field.GetSizeInBits();
0160 }
0161
0162 return ret;
0163 }
0164
0165 const std::vector<Field> &GetFields() const { return m_fields; }
0166 const std::string &GetID() const { return m_id; }
0167 unsigned GetSize() const { return m_size; }
0168 void DumpToLog(Log *log) const;
0169
0170
0171
0172
0173
0174
0175 std::string AsTable(uint32_t max_width) const;
0176
0177
0178
0179 void ToXML(Stream &strm) const;
0180
0181
0182
0183
0184
0185
0186
0187 void EnumsToXML(Stream &strm, llvm::StringSet<> &seen) const;
0188
0189 private:
0190 const std::string m_id;
0191
0192 const unsigned m_size;
0193 std::vector<Field> m_fields;
0194 };
0195
0196 }
0197
0198 #endif