/// kept up to date by SwitchSection.
const MCSection *CurSection;
+ /// PrevSection - This is the previous section code is being emitted to, it is
+ /// kept up to date by SwitchSection.
+ const MCSection *PrevSection;
+
public:
virtual ~MCStreamer();
/// emitting code to.
const MCSection *getCurrentSection() const { return CurSection; }
+ /// getPreviousSection - Return the previous section that the streamer is
+ /// emitting code to.
+ const MCSection *getPreviousSection() const { return PrevSection; }
+
/// SwitchSection - Set the current section where code is being emitted to
/// @p Section. This is required to update CurSection.
///
void MCAsmStreamer::SwitchSection(const MCSection *Section) {
assert(Section && "Cannot switch to a null section!");
if (Section != CurSection) {
+ PrevSection = CurSection;
CurSection = Section;
Section->PrintSwitchToSection(MAI, OS);
}
/// @{
virtual void SwitchSection(const MCSection *Section) {
+ PrevSection = CurSection;
CurSection = Section;
}
// If already in this section, then this is a noop.
if (Section == CurSection) return;
+ PrevSection = CurSection;
CurSection = Section;
CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
}
AddDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size");
AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".sleb128");
AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".uleb128");
+ AddDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(".previous");
}
bool ParseSectionDirectiveData(StringRef, SMLoc) {
bool ParseDirectiveLEB128(StringRef, SMLoc);
bool ParseDirectiveSection(StringRef, SMLoc);
bool ParseDirectiveSize(StringRef, SMLoc);
+ bool ParseDirectivePrevious(StringRef, SMLoc);
};
}
return TokError("LEB128 not supported yet");
}
+bool ELFAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
+ const MCSection *PreviousSection = getStreamer().getPreviousSection();
+ if (PreviousSection != NULL)
+ getStreamer().SwitchSection(PreviousSection);
+
+ return false;
+}
+
namespace llvm {
MCAsmParserExtension *createELFAsmParser() {
#include <cstdlib>
using namespace llvm;
-MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0) {
+MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0),
+ PrevSection(0) {
}
MCStreamer::~MCStreamer() {
--- /dev/null
+# RUN: llvm-mc -triple i386-pc-linux-gnu %s | FileCheck %s
+
+.bss
+# CHECK: .bss
+
+.text
+# CHECK: .text
+
+.previous
+# CHECK: .bss
+
+.previous
+# CHECK: .text