summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-07-12 20:08:04 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-07-12 20:08:04 +0000
commit7a56fc224c80334269e08dc400b27c8513263848 (patch)
tree2e7ee0909f6cb23cab5d014d6b46f42b0a1d7702 /lib
parentaa099be71f5e7b6a71930259edd3d25e60cb4fe2 (diff)
downloadllvm-7a56fc224c80334269e08dc400b27c8513263848.tar.gz
llvm-7a56fc224c80334269e08dc400b27c8513263848.tar.bz2
llvm-7a56fc224c80334269e08dc400b27c8513263848.tar.xz
MC/AsmParser: Add a basic ELFAsmParser extension.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108185 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/MC/MCParser/AsmParser.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp
index 1328ae28ba..3af962330d 100644
--- a/lib/MC/MCParser/AsmParser.cpp
+++ b/lib/MC/MCParser/AsmParser.cpp
@@ -18,6 +18,7 @@
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
@@ -101,6 +102,35 @@ public:
bool ParseDirectiveZerofill(StringRef, SMLoc);
};
+class ELFAsmParser : public MCAsmParserExtension {
+ bool ParseSectionSwitch(StringRef Section, unsigned Type,
+ unsigned Flags, SectionKind Kind);
+
+public:
+ ELFAsmParser() {}
+
+ virtual void Initialize(MCAsmParser &Parser) {
+ // Call the base implementation.
+ this->MCAsmParserExtension::Initialize(Parser);
+
+ Parser.AddDirectiveHandler(this, ".data", MCAsmParser::DirectiveHandler(
+ &ELFAsmParser::ParseSectionDirectiveData));
+ Parser.AddDirectiveHandler(this, ".text", MCAsmParser::DirectiveHandler(
+ &ELFAsmParser::ParseSectionDirectiveText));
+ }
+
+ bool ParseSectionDirectiveData(StringRef, SMLoc) {
+ return ParseSectionSwitch(".data", MCSectionELF::SHT_PROGBITS,
+ MCSectionELF::SHF_WRITE |MCSectionELF::SHF_ALLOC,
+ SectionKind::getDataRel());
+ }
+ bool ParseSectionDirectiveText(StringRef, SMLoc) {
+ return ParseSectionSwitch(".text", MCSectionELF::SHT_PROGBITS,
+ MCSectionELF::SHF_EXECINSTR |
+ MCSectionELF::SHF_ALLOC, SectionKind::getText());
+ }
+};
+
}
enum { DEFAULT_ADDRSPACE = 0 };
@@ -122,6 +152,9 @@ AsmParser::AsmParser(const Target &T, SourceMgr &_SM, MCContext &_Ctx,
if (_MAI.hasSubsectionsViaSymbols()) {
PlatformParser = new DarwinAsmParser;
PlatformParser->Initialize(*this);
+ } else {
+ PlatformParser = new ELFAsmParser;
+ PlatformParser->Initialize(*this);
}
}
@@ -1051,6 +1084,18 @@ bool AsmParser::ParseDirectiveSectionSwitch(const char *Segment,
return false;
}
+bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
+ unsigned Flags, SectionKind Kind) {
+ if (getLexer().isNot(AsmToken::EndOfStatement))
+ return TokError("unexpected token in section switching directive");
+ Lex();
+
+ getStreamer().SwitchSection(getContext().getELFSection(
+ Section, Type, Flags, Kind));
+
+ return false;
+}
+
bool AsmParser::ParseEscapedString(std::string &Data) {
assert(getLexer().is(AsmToken::String) && "Unexpected current token!");