Skip to content

Commit

Permalink
MCAssembler: Clean up iterator types for Symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jul 5, 2024
1 parent 37bee25 commit 4a0aff1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
29 changes: 6 additions & 23 deletions llvm/include/llvm/MC/MCAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h"
Expand Down Expand Up @@ -56,18 +57,10 @@ class MCValue;
class MCAssembler {
public:
using SectionListType = std::vector<MCSection *>;
using SymbolDataListType = std::vector<const MCSymbol *>;

using const_iterator = pointee_iterator<SectionListType::const_iterator>;
using iterator = pointee_iterator<SectionListType::iterator>;

using const_symbol_iterator =
pointee_iterator<SymbolDataListType::const_iterator>;
using symbol_iterator = pointee_iterator<SymbolDataListType::iterator>;

using symbol_range = iterator_range<symbol_iterator>;
using const_symbol_range = iterator_range<const_symbol_iterator>;

/// MachO specific deployment target version info.
// A Major version of 0 indicates that no version information was supplied
// and so the corresponding load command should not be emitted.
Expand Down Expand Up @@ -98,7 +91,7 @@ class MCAssembler {

SectionListType Sections;

SymbolDataListType Symbols;
SmallVector<const MCSymbol *, 0> Symbols;

/// The list of linker options to propagate into the object file.
std::vector<std::vector<std::string>> LinkerOptions;
Expand Down Expand Up @@ -344,22 +337,12 @@ class MCAssembler {

size_t size() const { return Sections.size(); }

/// @}
/// \name Symbol List Access
/// @{
symbol_iterator symbol_begin() { return Symbols.begin(); }
const_symbol_iterator symbol_begin() const { return Symbols.begin(); }

symbol_iterator symbol_end() { return Symbols.end(); }
const_symbol_iterator symbol_end() const { return Symbols.end(); }

symbol_range symbols() { return make_range(symbol_begin(), symbol_end()); }
const_symbol_range symbols() const {
return make_range(symbol_begin(), symbol_end());
iterator_range<pointee_iterator<
typename SmallVector<const MCSymbol *, 0>::const_iterator>>
symbols() const {
return make_pointee_range(Symbols);
}

size_t symbol_size() const { return Symbols.size(); }

/// @}
/// \name Linker Option List Access
/// @{
Expand Down
12 changes: 8 additions & 4 deletions llvm/lib/MC/MCAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,11 +1346,15 @@ LLVM_DUMP_METHOD void MCAssembler::dump() const{
OS << "],\n";
OS << " Symbols:[";

for (const_symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
if (it != symbol_begin()) OS << ",\n ";
bool First = true;
for (const MCSymbol &Sym : symbols()) {
if (First)
First = false;
else
OS << ",\n ";
OS << "(";
it->dump();
OS << ", Index:" << it->getIndex() << ", ";
Sym.dump();
OS << ", Index:" << Sym.getIndex() << ", ";
OS << ")";
}
OS << "]>\n";
Expand Down

0 comments on commit 4a0aff1

Please sign in to comment.