Add AsmParser support for the ELF .previous directive. Patch by Roman Divacky.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112849 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2010-09-02 18:53:37 +00:00
parent 3e234e7579
commit 1674b0b0e4
7 changed files with 36 additions and 1 deletions

View File

@@ -54,6 +54,10 @@ namespace llvm {
/// kept up to date by SwitchSection. /// kept up to date by SwitchSection.
const MCSection *CurSection; 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: public:
virtual ~MCStreamer(); virtual ~MCStreamer();
@@ -96,6 +100,10 @@ namespace llvm {
/// emitting code to. /// emitting code to.
const MCSection *getCurrentSection() const { return CurSection; } 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 /// SwitchSection - Set the current section where code is being emitted to
/// @p Section. This is required to update CurSection. /// @p Section. This is required to update CurSection.
/// ///

View File

@@ -217,6 +217,7 @@ static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
void MCAsmStreamer::SwitchSection(const MCSection *Section) { void MCAsmStreamer::SwitchSection(const MCSection *Section) {
assert(Section && "Cannot switch to a null section!"); assert(Section && "Cannot switch to a null section!");
if (Section != CurSection) { if (Section != CurSection) {
PrevSection = CurSection;
CurSection = Section; CurSection = Section;
Section->PrintSwitchToSection(MAI, OS); Section->PrintSwitchToSection(MAI, OS);
} }

View File

@@ -26,6 +26,7 @@ namespace {
/// @{ /// @{
virtual void SwitchSection(const MCSection *Section) { virtual void SwitchSection(const MCSection *Section) {
PrevSection = CurSection;
CurSection = Section; CurSection = Section;
} }

View File

@@ -77,6 +77,7 @@ void MCObjectStreamer::SwitchSection(const MCSection *Section) {
// If already in this section, then this is a noop. // If already in this section, then this is a noop.
if (Section == CurSection) return; if (Section == CurSection) return;
PrevSection = CurSection;
CurSection = Section; CurSection = Section;
CurSectionData = &getAssembler().getOrCreateSectionData(*Section); CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
} }

View File

@@ -50,6 +50,7 @@ public:
AddDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size"); AddDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size");
AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".sleb128"); AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".sleb128");
AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".uleb128"); AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".uleb128");
AddDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(".previous");
} }
bool ParseSectionDirectiveData(StringRef, SMLoc) { bool ParseSectionDirectiveData(StringRef, SMLoc) {
@@ -111,6 +112,7 @@ public:
bool ParseDirectiveLEB128(StringRef, SMLoc); bool ParseDirectiveLEB128(StringRef, SMLoc);
bool ParseDirectiveSection(StringRef, SMLoc); bool ParseDirectiveSection(StringRef, SMLoc);
bool ParseDirectiveSize(StringRef, SMLoc); bool ParseDirectiveSize(StringRef, SMLoc);
bool ParseDirectivePrevious(StringRef, SMLoc);
}; };
} }
@@ -272,6 +274,14 @@ bool ELFAsmParser::ParseDirectiveLEB128(StringRef DirName, SMLoc) {
return TokError("LEB128 not supported yet"); 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 { namespace llvm {
MCAsmParserExtension *createELFAsmParser() { MCAsmParserExtension *createELFAsmParser() {

View File

@@ -15,7 +15,8 @@
#include <cstdlib> #include <cstdlib>
using namespace llvm; using namespace llvm;
MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0) { MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0),
PrevSection(0) {
} }
MCStreamer::~MCStreamer() { MCStreamer::~MCStreamer() {

View File

@@ -0,0 +1,13 @@
# RUN: llvm-mc -triple i386-pc-linux-gnu %s | FileCheck %s
.bss
# CHECK: .bss
.text
# CHECK: .text
.previous
# CHECK: .bss
.previous
# CHECK: .text