aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoerg Sonnenberger <joerg@bec.de>2011-02-21 01:07:42 +0000
committerJoerg Sonnenberger <joerg@bec.de>2011-02-21 01:07:42 +0000
commit7d0805dcb82e9ba1d90ce8d702169683b9caded7 (patch)
tree1da9b4643bf13989ccd7b510d4cf678a6dce5a4a
parent8d7285d0e5eb5937a6682e884b883516377e903d (diff)
Use a vector of pairs to implement the section stack, not two
independent vectors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126099 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/MC/MCStreamer.h37
-rw-r--r--lib/MC/MCStreamer.cpp4
2 files changed, 18 insertions, 23 deletions
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index fc2451f9c1..4451199b7f 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/include/llvm/MC/MCStreamer.h
@@ -57,13 +57,10 @@ namespace llvm {
MCDwarfFrameInfo *getCurrentFrameInfo();
void EnsureValidFrame();
- /// CurSectionStack - This is stack of CurSection values saved by
- /// PushSection.
- SmallVector<const MCSection *, 4> CurSectionStack;
-
- /// PrevSectionStack - This is stack of PrevSection values saved by
- /// PushSection.
- SmallVector<const MCSection *, 4> PrevSectionStack;
+ /// SectionStack - This is stack of current and previous section
+ /// values saved by PushSection.
+ SmallVector<std::pair<const MCSection *,
+ const MCSection *>, 4> SectionStack;
protected:
MCStreamer(MCContext &Ctx);
@@ -117,16 +114,16 @@ namespace llvm {
/// getCurrentSection - Return the current section that the streamer is
/// emitting code to.
const MCSection *getCurrentSection() const {
- if (!CurSectionStack.empty())
- return CurSectionStack.back();
+ if (!SectionStack.empty())
+ return SectionStack.back().first;
return NULL;
}
/// getPreviousSection - Return the previous section that the streamer is
/// emitting code to.
const MCSection *getPreviousSection() const {
- if (!PrevSectionStack.empty())
- return PrevSectionStack.back();
+ if (!SectionStack.empty())
+ return SectionStack.back().second;
return NULL;
}
@@ -139,8 +136,8 @@ namespace llvm {
/// pushSection - Save the current and previous section on the
/// section stack.
void PushSection() {
- PrevSectionStack.push_back(getPreviousSection());
- CurSectionStack.push_back(getCurrentSection());
+ SectionStack.push_back(std::make_pair(getCurrentSection(),
+ getPreviousSection()));
}
/// popSection - Restore the current and previous section from
@@ -148,12 +145,10 @@ namespace llvm {
///
/// Returns false if the stack was empty.
bool PopSection() {
- if (PrevSectionStack.size() <= 1)
+ if (SectionStack.size() <= 1)
return false;
- assert(CurSectionStack.size() > 1);
- PrevSectionStack.pop_back();
- const MCSection *oldSection = CurSectionStack.pop_back_val();
- const MCSection *curSection = CurSectionStack.back();
+ const MCSection *oldSection = SectionStack.pop_back_val().first;
+ const MCSection *curSection = SectionStack.back().first;
if (oldSection != curSection)
ChangeSection(curSection);
@@ -166,10 +161,10 @@ namespace llvm {
/// This corresponds to assembler directives like .section, .text, etc.
void SwitchSection(const MCSection *Section) {
assert(Section && "Cannot switch to a null section!");
- const MCSection *curSection = CurSectionStack.back();
- PrevSectionStack.back() = curSection;
+ const MCSection *curSection = SectionStack.back().first;
+ SectionStack.back().second = curSection;
if (Section != curSection) {
- CurSectionStack.back() = Section;
+ SectionStack.back().first = Section;
ChangeSection(Section);
}
}
diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp
index 3dcdba1313..4b302c8602 100644
--- a/lib/MC/MCStreamer.cpp
+++ b/lib/MC/MCStreamer.cpp
@@ -20,8 +20,8 @@
using namespace llvm;
MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx) {
- PrevSectionStack.push_back(NULL);
- CurSectionStack.push_back(NULL);
+ const MCSection *section = NULL;
+ SectionStack.push_back(std::make_pair(section, section));
}
MCStreamer::~MCStreamer() {