13#include "llvm/ADT/StringExtras.h"
21 : m_name(std::move(name)), m_start(start), m_end(end) {
22 assert(
m_start <=
m_end &&
"Start bit must be <= end bit.");
26 LLDB_LOG(
log,
" Name: \"{0}\" Start: {1} End: {2}", m_name.c_str(), m_start,
31 unsigned overlap_start = std::max(GetStart(), other.
GetStart());
32 unsigned overlap_end = std::min(GetEnd(), other.
GetEnd());
33 return overlap_start <= overlap_end;
37 assert(!Overlaps(other) &&
38 "Cannot get padding distance for overlapping fields.");
39 assert((other < (*
this)) &&
"Expected fields in MSB to LSB order.");
45 unsigned lhs_start = GetStart();
50 rhs_end = GetStart() + GetSizeInBits() - 1;
53 return lhs_start - rhs_end - 1;
59 assert(fields.size() &&
"Some fields must be provided.");
63 std::vector<Field> provided_fields = fields;
66 m_fields.reserve(provided_fields.size());
69 assert(std::is_sorted(provided_fields.rbegin(), provided_fields.rend()));
73 std::optional<Field> previous_field;
74 unsigned register_msb = (
m_size * 8) - 1;
75 for (
auto field : provided_fields) {
77 unsigned padding = previous_field->PaddingDistance(field);
80 unsigned end = previous_field->GetStart() - 1;
87 if (field.GetEnd() != register_msb)
88 m_fields.push_back(
Field(
"", field.GetEnd() + 1, register_msb));
91 previous_field = field;
95 if (previous_field && previous_field->GetStart() != 0)
96 m_fields.push_back(
Field(
"", 0, previous_field->GetStart() - 1));
100 const std::vector<Field> &fields)
112 unsigned column_width) {
113 unsigned pad = column_width - content.
GetString().size();
117 pad_l = std::string(pad / 2,
' ');
118 pad_r = std::string((pad / 2) + (pad % 2),
' ');
127static void EmitTable(std::string &out, std::array<std::string, 3> &table) {
129 for (std::string &line : table)
132 out += std::accumulate(table.begin() + 1, table.end(), table.front(),
133 [](std::string lhs,
const auto &rhs) {
134 return std::move(lhs) +
"\n" + rhs;
141 std::array<std::string, 3> lines;
142 uint32_t current_width = 0;
146 if (field.GetEnd() == field.GetStart())
147 position.
Printf(
" %d ", field.GetEnd());
149 position.
Printf(
" %d-%d ", field.GetEnd(), field.GetStart());
152 name.
Printf(
" %s ", field.GetName().c_str());
154 unsigned column_width = position.
GetString().size();
155 unsigned name_width = name.
GetString().size();
156 if (name_width > column_width)
157 column_width = name_width;
164 if (current_width && ((current_width + column_width + 1) >= max_width)) {
169 for (std::string &line : lines)
175 lines[0] += aligned_position.
GetString();
177 grid <<
'|' << std::string(column_width,
'-');
183 current_width += column_width + 1;
199 strm <<
"<flags id=\"" <<
GetID() <<
"\" ";
204 if (field.GetName().empty())
213 strm.
Indent(
"</flags>\n");
220 strm <<
"<field name=\"";
222 std::string escaped_name;
223 llvm::raw_string_ostream escape_strm(escaped_name);
224 llvm::printHTMLEscaped(
GetName(), escape_strm);
225 strm << escaped_name <<
"\" ";
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
static StreamString FormatCell(const StreamString &content, unsigned column_width)
static void EmitTable(std::string &out, std::array< std::string, 3 > &table)
bool Overlaps(const Field &other) const
unsigned GetSizeInBits() const
Get size of the field in bits. Will always be at least 1.
unsigned PaddingDistance(const Field &other) const
Return the number of bits between this field and the other, that are not covered by either field.
Field(std::string name, unsigned start, unsigned end)
Where start is the least significant bit and end is the most significant bit.
const std::string & GetName() const
unsigned GetStart() const
void ToXML(StreamString &strm) const
Output XML that describes this field, to be inserted into a target XML file.
unsigned m_start
Start/end bit positions.
RegisterFlags(std::string id, unsigned size, const std::vector< Field > &fields)
This assumes that:
std::vector< Field > m_fields
void SetFields(const std::vector< Field > &fields)
Replace all the fields with the new set of fields.
const unsigned m_size
Size in bytes.
const std::string & GetID() const
std::string AsTable(uint32_t max_width) const
Produce a text table showing the layout of all the fields.
void ToXML(StreamString &strm) const
llvm::StringRef GetString() const
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
void IndentMore(unsigned amount=2)
Increment the current indentation level.
A class that represents a running process on the host machine.