diff options
author | Fangrui Song <i@maskray.me> | 2024-06-22 19:44:52 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2024-06-22 19:44:52 -0700 |
commit | 05ba5c0648ae5e80d5afce270495bf3b1eef9af4 (patch) | |
tree | 576d79ebb285cacacc78dbcaef8e63f01b381b4b /llvm/lib/MC/MCStreamer.cpp | |
parent | f73ac218a666e2017565f2210b47332ddcf55f00 (diff) | |
download | llvm-05ba5c0648ae5e80d5afce270495bf3b1eef9af4.zip llvm-05ba5c0648ae5e80d5afce270495bf3b1eef9af4.tar.gz llvm-05ba5c0648ae5e80d5afce270495bf3b1eef9af4.tar.bz2 |
[MC] MCSectionSubPair: replace const MCExpr * with uint32_t
Diffstat (limited to 'llvm/lib/MC/MCStreamer.cpp')
-rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 680b056..4b86bc2 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -1242,13 +1242,57 @@ void MCStreamer::emitBundleLock(bool AlignToEnd) {} void MCStreamer::finishImpl() {} void MCStreamer::emitBundleUnlock() {} -void MCStreamer::switchSection(MCSection *Section, const MCExpr *Subsection) { +bool MCStreamer::popSection() { + if (SectionStack.size() <= 1) + return false; + auto I = SectionStack.end(); + --I; + MCSectionSubPair OldSec = I->first; + --I; + MCSectionSubPair NewSec = I->first; + + if (NewSec.first && OldSec != NewSec) + changeSection(NewSec.first, NewSec.second ? MCConstantExpr::create( + NewSec.second, getContext()) + : nullptr); + SectionStack.pop_back(); + return true; +} + +bool MCStreamer::subSection(const MCExpr *SubsecExpr) { + if (SectionStack.empty()) + return true; + + int64_t Subsec; + if (!SubsecExpr->evaluateAsAbsolute(Subsec, getAssemblerPtr())) { + getContext().reportError(SubsecExpr->getLoc(), + "cannot evaluate subsection number"); + return true; + } + if (!isUInt<31>(Subsec)) { + getContext().reportError(SubsecExpr->getLoc(), + "subsection number " + Twine(Subsec) + + " is not within [0,2147483647]"); + return true; + } + + MCSectionSubPair CurPair = SectionStack.back().first; + SectionStack.back().second = CurPair; + SectionStack.back().first.second = Subsec; + changeSection(CurPair.first, SubsecExpr); + return false; +} + +void MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) { assert(Section && "Cannot switch to a null section!"); MCSectionSubPair curSection = SectionStack.back().first; SectionStack.back().second = curSection; - if (MCSectionSubPair(Section, Subsection) != curSection) { - changeSection(Section, Subsection); - SectionStack.back().first = MCSectionSubPair(Section, Subsection); + uint32_t Subsec = 0; + if (SubsecExpr) + Subsec = cast<MCConstantExpr>(SubsecExpr)->getValue(); + if (MCSectionSubPair(Section, Subsec) != curSection) { + changeSection(Section, SubsecExpr); + SectionStack.back().first = MCSectionSubPair(Section, Subsec); assert(!Section->hasEnded() && "Section already ended"); MCSymbol *Sym = Section->getBeginSymbol(); if (Sym && !Sym->isInSection()) @@ -1256,6 +1300,12 @@ void MCStreamer::switchSection(MCSection *Section, const MCExpr *Subsection) { } } +void MCStreamer::switchSection(MCSection *Section, uint32_t Subsec) { + switchSection(Section, Subsec == 0 + ? nullptr + : MCConstantExpr::create(Subsec, getContext())); +} + MCSymbol *MCStreamer::endSection(MCSection *Section) { // TODO: keep track of the last subsection so that this symbol appears in the // correct place. |