Store a MCSection in MCFragment.

Part of the work to merge MCSectionData into MCSection.

llvm-svn: 238160
This commit is contained in:
Rafael Espindola 2015-05-25 23:48:22 +00:00
parent a554c05d95
commit 8324c2f8be
7 changed files with 44 additions and 40 deletions

View File

@ -67,8 +67,8 @@ public:
private:
FragmentType Kind;
/// Parent - The data for the section this fragment is in.
MCSectionData *Parent;
/// The data for the section this fragment is in.
MCSection *Parent;
/// Atom - The atom this fragment is in, as represented by it's defining
/// symbol.
@ -89,7 +89,7 @@ private:
/// @}
protected:
MCFragment(FragmentType Kind, MCSectionData *Parent = nullptr);
MCFragment(FragmentType Kind, MCSection *Parent = nullptr);
public:
// Only for sentinel.
@ -98,8 +98,10 @@ public:
FragmentType getKind() const { return Kind; }
MCSectionData *getParent() const { return Parent; }
void setParent(MCSectionData *Value) { Parent = Value; }
MCSectionData *getParent() const {
return &Parent->getSectionData();
}
void setParent(MCSection *Value) { Parent = Value; }
const MCSymbol *getAtom() const { return Atom; }
void setAtom(const MCSymbol *Value) { Atom = Value; }
@ -138,8 +140,8 @@ class MCEncodedFragment : public MCFragment {
uint8_t BundlePadding;
public:
MCEncodedFragment(MCFragment::FragmentType FType, MCSectionData *SD = nullptr)
: MCFragment(FType, SD), BundlePadding(0) {}
MCEncodedFragment(MCFragment::FragmentType FType, MCSection *Sec = nullptr)
: MCFragment(FType, Sec), BundlePadding(0) {}
~MCEncodedFragment() override;
virtual SmallVectorImpl<char> &getContents() = 0;
@ -170,8 +172,8 @@ class MCEncodedFragmentWithFixups : public MCEncodedFragment {
public:
MCEncodedFragmentWithFixups(MCFragment::FragmentType FType,
MCSectionData *SD = nullptr)
: MCEncodedFragment(FType, SD) {}
MCSection *Sec = nullptr)
: MCEncodedFragment(FType, Sec) {}
~MCEncodedFragmentWithFixups() override;
@ -209,8 +211,8 @@ class MCDataFragment : public MCEncodedFragmentWithFixups {
SmallVector<MCFixup, 4> Fixups;
public:
MCDataFragment(MCSectionData *SD = nullptr)
: MCEncodedFragmentWithFixups(FT_Data, SD), HasInstructions(false),
MCDataFragment(MCSection *Sec = nullptr)
: MCEncodedFragmentWithFixups(FT_Data, Sec), HasInstructions(false),
AlignToBundleEnd(false) {}
SmallVectorImpl<char> &getContents() override { return Contents; }
@ -251,8 +253,9 @@ class MCCompactEncodedInstFragment : public MCEncodedFragment {
SmallVector<char, 4> Contents;
public:
MCCompactEncodedInstFragment(MCSectionData *SD = nullptr)
: MCEncodedFragment(FT_CompactEncodedInst, SD), AlignToBundleEnd(false) {}
MCCompactEncodedInstFragment(MCSection *Sec = nullptr)
: MCEncodedFragment(FT_CompactEncodedInst, Sec), AlignToBundleEnd(false) {
}
bool hasInstructions() const override { return true; }
@ -289,8 +292,8 @@ class MCRelaxableFragment : public MCEncodedFragmentWithFixups {
public:
MCRelaxableFragment(const MCInst &Inst, const MCSubtargetInfo &STI,
MCSectionData *SD = nullptr)
: MCEncodedFragmentWithFixups(FT_Relaxable, SD), Inst(Inst), STI(STI) {}
MCSection *Sec = nullptr)
: MCEncodedFragmentWithFixups(FT_Relaxable, Sec), Inst(Inst), STI(STI) {}
SmallVectorImpl<char> &getContents() override { return Contents; }
const SmallVectorImpl<char> &getContents() const override { return Contents; }
@ -340,8 +343,8 @@ class MCAlignFragment : public MCFragment {
public:
MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize,
unsigned MaxBytesToEmit, MCSectionData *SD = nullptr)
: MCFragment(FT_Align, SD), Alignment(Alignment), Value(Value),
unsigned MaxBytesToEmit, MCSection *Sec = nullptr)
: MCFragment(FT_Align, Sec), Alignment(Alignment), Value(Value),
ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit), EmitNops(false) {}
/// \name Accessors
@ -380,8 +383,8 @@ class MCFillFragment : public MCFragment {
public:
MCFillFragment(int64_t Value, unsigned ValueSize, uint64_t Size,
MCSectionData *SD = nullptr)
: MCFragment(FT_Fill, SD), Value(Value), ValueSize(ValueSize),
MCSection *Sec = nullptr)
: MCFragment(FT_Fill, Sec), Value(Value), ValueSize(ValueSize),
Size(Size) {
assert((!ValueSize || (Size % ValueSize) == 0) &&
"Fill size must be a multiple of the value size!");
@ -413,8 +416,8 @@ class MCOrgFragment : public MCFragment {
int8_t Value;
public:
MCOrgFragment(const MCExpr &Offset, int8_t Value, MCSectionData *SD = nullptr)
: MCFragment(FT_Org, SD), Offset(&Offset), Value(Value) {}
MCOrgFragment(const MCExpr &Offset, int8_t Value, MCSection *Sec = nullptr)
: MCFragment(FT_Org, Sec), Offset(&Offset), Value(Value) {}
/// \name Accessors
/// @{
@ -442,9 +445,8 @@ class MCLEBFragment : public MCFragment {
SmallString<8> Contents;
public:
MCLEBFragment(const MCExpr &Value_, bool IsSigned_,
MCSectionData *SD = nullptr)
: MCFragment(FT_LEB, SD), Value(&Value_), IsSigned(IsSigned_) {
MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSection *Sec = nullptr)
: MCFragment(FT_LEB, Sec), Value(&Value_), IsSigned(IsSigned_) {
Contents.push_back(0);
}
@ -480,8 +482,8 @@ class MCDwarfLineAddrFragment : public MCFragment {
public:
MCDwarfLineAddrFragment(int64_t LineDelta, const MCExpr &AddrDelta,
MCSectionData *SD = nullptr)
: MCFragment(FT_Dwarf, SD), LineDelta(LineDelta), AddrDelta(&AddrDelta) {
MCSection *Sec = nullptr)
: MCFragment(FT_Dwarf, Sec), LineDelta(LineDelta), AddrDelta(&AddrDelta) {
Contents.push_back(0);
}
@ -512,8 +514,8 @@ class MCDwarfCallFrameFragment : public MCFragment {
SmallString<8> Contents;
public:
MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSectionData *SD = nullptr)
: MCFragment(FT_DwarfFrame, SD), AddrDelta(&AddrDelta) {
MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr)
: MCFragment(FT_DwarfFrame, Sec), AddrDelta(&AddrDelta) {
Contents.push_back(0);
}

View File

@ -74,7 +74,7 @@ protected:
void insert(MCFragment *F) {
flushPendingLabels(F);
CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
F->setParent(CurSectionData);
F->setParent(&CurSectionData->getSection());
}
/// Get a data fragment to write into, creating a new one if the current

View File

@ -272,7 +272,7 @@ MCFragment::MCFragment() : Kind(FragmentType(~0)) {
MCFragment::~MCFragment() {
}
MCFragment::MCFragment(FragmentType Kind, MCSectionData *Parent)
MCFragment::MCFragment(FragmentType Kind, MCSection *Parent)
: Kind(Kind), Parent(Parent), Atom(nullptr), Offset(~UINT64_C(0)) {
if (Parent)
Parent->getFragmentList().push_back(this);
@ -317,7 +317,7 @@ MCSectionData::getSubsectionInsertionPoint(unsigned Subsection) {
MCFragment *F = new MCDataFragment();
SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
getFragmentList().insert(IP, F);
F->setParent(this);
F->setParent(&getSection());
}
return IP;
@ -859,7 +859,7 @@ void MCAssembler::Finish() {
// Create dummy fragments to eliminate any empty sections, this simplifies
// layout.
if (it->getFragmentList().empty())
new MCDataFragment(&it->getSectionData());
new MCDataFragment(&*it);
it->setOrdinal(SectionIndex++);
}

View File

@ -644,9 +644,10 @@ void MCELFStreamer::Flush() {
MCSection &Section = Symbol.getSection();
MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section);
new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment,
&SectData.getSection());
MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
MCFragment *F = new MCFillFragment(0, 0, Size, &SectData.getSection());
Symbol.getData().setFragment(F);
// Update the maximum alignment of the section if necessary.

View File

@ -418,9 +418,10 @@ void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
// Emit an align fragment if necessary.
if (ByteAlignment != 1)
new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectData);
new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment,
&SectData.getSection());
MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
MCFragment *F = new MCFillFragment(0, 0, Size, &SectData.getSection());
SD.setFragment(F);
AssignSection(Symbol, Section);

View File

@ -43,7 +43,7 @@ void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) {
if (!F) {
F = new MCDataFragment();
CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
F->setParent(CurSectionData);
F->setParent(&CurSectionData->getSection());
}
for (MCSymbolData *SD : PendingLabels) {
SD->setFragment(F);

View File

@ -231,10 +231,10 @@ void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
if (ByteAlignment != 1)
new MCAlignFragment(ByteAlignment, /*Value=*/0, /*ValueSize=*/0,
ByteAlignment, &SectionData);
ByteAlignment, &SectionData.getSection());
MCFillFragment *Fragment =
new MCFillFragment(/*Value=*/0, /*ValueSize=*/0, Size, &SectionData);
MCFillFragment *Fragment = new MCFillFragment(
/*Value=*/0, /*ValueSize=*/0, Size, &SectionData.getSection());
SD.setFragment(Fragment);
}