From 5e435847b007766c4e6f6c27021918bbd22ecd58 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 25 May 2015 22:57:48 +0000 Subject: [PATCH] Move MCSectionData to MCSection.h. Another step in merging MCSectionData and MCSection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238158 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 70 +------------------------- include/llvm/MC/MCObjectStreamer.h | 1 + include/llvm/MC/MCSection.h | 80 ++++++++++++++++++++++++++++++ lib/MC/MCSection.cpp | 17 +++++++ 4 files changed, 99 insertions(+), 69 deletions(-) diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index cd39db4e68d..368846a6efe 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -21,6 +21,7 @@ #include "llvm/MC/MCFixup.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCLinkerOptimizationHint.h" +#include "llvm/MC/MCSection.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/Casting.h" @@ -530,75 +531,6 @@ public: } }; -// FIXME: Should this be a separate class, or just merged into MCSection? Since -// we anticipate the fast path being through an MCAssembler, the only reason to -// keep it out is for API abstraction. -class MCSectionData : public ilist_node { - friend class MCAsmLayout; - - MCSectionData(const MCSectionData &) = delete; - void operator=(const MCSectionData &) = delete; - -public: - typedef iplist FragmentListType; - - typedef FragmentListType::const_iterator const_iterator; - typedef FragmentListType::iterator iterator; - - typedef FragmentListType::const_reverse_iterator const_reverse_iterator; - typedef FragmentListType::reverse_iterator reverse_iterator; - -private: - FragmentListType Fragments; - MCSection *Section; - - /// \name Assembler Backend Data - /// @{ - // - // FIXME: This could all be kept private to the assembler implementation. - - /// Mapping from subsection number to insertion point for subsection numbers - /// below that number. - SmallVector, 1> SubsectionFragmentMap; - - /// @} - -public: - // Only for use as sentinel. - MCSectionData(); - MCSectionData(MCSection &Section); - - MCSection &getSection() const { return *Section; } - - /// \name Fragment Access - /// @{ - - const FragmentListType &getFragmentList() const { return Fragments; } - FragmentListType &getFragmentList() { return Fragments; } - - iterator begin() { return Fragments.begin(); } - const_iterator begin() const { return Fragments.begin(); } - - iterator end() { return Fragments.end(); } - const_iterator end() const { return Fragments.end(); } - - reverse_iterator rbegin() { return Fragments.rbegin(); } - const_reverse_iterator rbegin() const { return Fragments.rbegin(); } - - reverse_iterator rend() { return Fragments.rend(); } - const_reverse_iterator rend() const { return Fragments.rend(); } - - size_t size() const { return Fragments.size(); } - - bool empty() const { return Fragments.empty(); } - - iterator getSubsectionInsertionPoint(unsigned Subsection); - - void dump(); - - /// @} -}; - // FIXME: This really doesn't belong here. See comments below. struct IndirectSymbolData { MCSymbol *Symbol; diff --git a/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h index 646603975f5..71edf589b02 100644 --- a/include/llvm/MC/MCObjectStreamer.h +++ b/include/llvm/MC/MCObjectStreamer.h @@ -12,6 +12,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/MC/MCAssembler.h" +#include "llvm/MC/MCSection.h" #include "llvm/MC/MCStreamer.h" namespace llvm { diff --git a/include/llvm/MC/MCSection.h b/include/llvm/MC/MCSection.h index 4dbf4ba6f02..5b1aeda126d 100644 --- a/include/llvm/MC/MCSection.h +++ b/include/llvm/MC/MCSection.h @@ -14,17 +14,97 @@ #ifndef LLVM_MC_MCSECTION_H #define LLVM_MC_MCSECTION_H +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/ilist.h" +#include "llvm/ADT/ilist_node.h" #include "llvm/MC/SectionKind.h" #include "llvm/Support/Compiler.h" namespace llvm { +class MCAssembler; class MCAsmInfo; class MCContext; class MCExpr; +class MCFragment; +class MCSection; class MCSymbol; class raw_ostream; +class MCSectionData : public ilist_node { + friend class MCAsmLayout; + + MCSectionData(const MCSectionData &) = delete; + void operator=(const MCSectionData &) = delete; + +public: + typedef iplist FragmentListType; + + typedef FragmentListType::const_iterator const_iterator; + typedef FragmentListType::iterator iterator; + + typedef FragmentListType::const_reverse_iterator const_reverse_iterator; + typedef FragmentListType::reverse_iterator reverse_iterator; + +private: + FragmentListType Fragments; + MCSection *Section; + + /// \name Assembler Backend Data + /// @{ + // + // FIXME: This could all be kept private to the assembler implementation. + + /// Mapping from subsection number to insertion point for subsection numbers + /// below that number. + SmallVector, 1> SubsectionFragmentMap; + + /// @} + +public: + // Only for use as sentinel. + MCSectionData(); + MCSectionData(MCSection &Section); + + MCSection &getSection() const { return *Section; } + + /// \name Fragment Access + /// @{ + + const FragmentListType &getFragmentList() const { return Fragments; } + FragmentListType &getFragmentList() { return Fragments; } + + iterator begin(); + const_iterator begin() const { + return const_cast(this)->begin(); + } + + iterator end(); + const_iterator end() const { + return const_cast(this)->end(); + } + + reverse_iterator rbegin(); + const_reverse_iterator rbegin() const { + return const_cast(this)->rbegin(); + } + + reverse_iterator rend(); + const_reverse_iterator rend() const { + return const_cast(this)->rend(); + } + + size_t size() const; + + bool empty() const; + + iterator getSubsectionInsertionPoint(unsigned Subsection); + + void dump(); + + /// @} +}; + /// Instances of this class represent a uniqued identifier for a section in the /// current translation unit. The MCContext class uniques and creates these. class MCSection { diff --git a/lib/MC/MCSection.cpp b/lib/MC/MCSection.cpp index bf25f3cc163..523c53787ce 100644 --- a/lib/MC/MCSection.cpp +++ b/lib/MC/MCSection.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCSection.h" +#include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSymbol.h" @@ -47,3 +48,19 @@ void MCSection::setBundleLockState(BundleLockStateType NewState) { } ++BundleLockNestingDepth; } + +MCSectionData::iterator MCSectionData::begin() { return Fragments.begin(); } + +MCSectionData::iterator MCSectionData::end() { return Fragments.end(); } + +MCSectionData::reverse_iterator MCSectionData::rbegin() { + return Fragments.rbegin(); +} + +MCSectionData::reverse_iterator MCSectionData::rend() { + return Fragments.rend(); +} + +size_t MCSectionData::size() const { return Fragments.size(); } + +bool MCSectionData::empty() const { return Fragments.empty(); } -- 2.34.1