#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/MCFragment.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/Support/Compiler.h"
namespace llvm {
class MCAsmInfo;
class MCAssembler;
class MCContext;
class MCExpr;
class MCFragment;
class MCSection;
class MCSymbol;
class raw_ostream;
template<>
struct ilist_node_traits<MCFragment> {
MCFragment *createNode(const MCFragment &V);
static void deleteNode(MCFragment *V);
void addNodeToList(MCFragment *) {}
void removeNodeFromList(MCFragment *) {}
void transferNodesFromList(ilist_node_traits & ,
ilist_iterator<MCFragment> ,
ilist_iterator<MCFragment> ) {}
};
class MCSection {
public:
enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
enum BundleLockStateType {
NotBundleLocked,
BundleLocked,
BundleLockedAlignToEnd
};
typedef iplist<MCFragment> 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:
MCSection(const MCSection &) = delete;
void operator=(const MCSection &) = delete;
MCSymbol *Begin;
MCSymbol *End = nullptr;
unsigned Alignment = 1;
unsigned Ordinal = 0;
unsigned LayoutOrder;
BundleLockStateType BundleLockState = NotBundleLocked;
unsigned BundleLockNestingDepth = 0;
unsigned BundleGroupBeforeFirstInst : 1;
unsigned HasInstructions : 1;
unsigned IsRegistered : 1;
MCDummyFragment DummyFragment;
FragmentListType Fragments;
SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
protected:
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin);
SectionVariant Variant;
SectionKind Kind;
~MCSection();
public:
SectionKind getKind() const { return Kind; }
SectionVariant getVariant() const { return Variant; }
MCSymbol *getBeginSymbol() { return Begin; }
const MCSymbol *getBeginSymbol() const {
return const_cast<MCSection *>(this)->getBeginSymbol();
}
void setBeginSymbol(MCSymbol *Sym) {
assert(!Begin);
Begin = Sym;
}
MCSymbol *getEndSymbol(MCContext &Ctx);
bool hasEnded() const;
unsigned getAlignment() const { return Alignment; }
void setAlignment(unsigned Value) { Alignment = Value; }
unsigned getOrdinal() const { return Ordinal; }
void setOrdinal(unsigned Value) { Ordinal = Value; }
unsigned getLayoutOrder() const { return LayoutOrder; }
void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
BundleLockStateType getBundleLockState() const { return BundleLockState; }
void setBundleLockState(BundleLockStateType NewState);
bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
bool isBundleGroupBeforeFirstInst() const {
return BundleGroupBeforeFirstInst;
}
void setBundleGroupBeforeFirstInst(bool IsFirst) {
BundleGroupBeforeFirstInst = IsFirst;
}
bool hasInstructions() const { return HasInstructions; }
void setHasInstructions(bool Value) { HasInstructions = Value; }
bool isRegistered() const { return IsRegistered; }
void setIsRegistered(bool Value) { IsRegistered = Value; }
MCSection::FragmentListType &getFragmentList() { return Fragments; }
const MCSection::FragmentListType &getFragmentList() const {
return const_cast<MCSection *>(this)->getFragmentList();
}
static FragmentListType MCSection::*getSublistAccess(MCFragment *) {
return &MCSection::Fragments;
}
const MCDummyFragment &getDummyFragment() const { return DummyFragment; }
MCDummyFragment &getDummyFragment() { return DummyFragment; }
MCSection::iterator begin();
MCSection::const_iterator begin() const {
return const_cast<MCSection *>(this)->begin();
}
MCSection::iterator end();
MCSection::const_iterator end() const {
return const_cast<MCSection *>(this)->end();
}
MCSection::reverse_iterator rbegin();
MCSection::const_reverse_iterator rbegin() const {
return const_cast<MCSection *>(this)->rbegin();
}
MCSection::reverse_iterator rend();
MCSection::const_reverse_iterator rend() const {
return const_cast<MCSection *>(this)->rend();
}
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection);
void dump();
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
const MCExpr *Subsection) const = 0;
virtual bool UseCodeAlign() const = 0;
virtual bool isVirtualSection() const = 0;
};
}
#endif