[llvm-commits] [llvm] r108185 - /llvm/trunk/lib/MC/MCParser/AsmParser.cpp
Daniel Dunbar
daniel at zuster.org
Mon Jul 12 13:08:04 PDT 2010
Author: ddunbar
Date: Mon Jul 12 15:08:04 2010
New Revision: 108185
URL: http://llvm.org/viewvc/llvm-project?rev=108185&view=rev
Log:
MC/AsmParser: Add a basic ELFAsmParser extension.
Modified:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=108185&r1=108184&r2=108185&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Mon Jul 12 15:08:04 2010
@@ -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 @@
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 @@
if (_MAI.hasSubsectionsViaSymbols()) {
PlatformParser = new DarwinAsmParser;
PlatformParser->Initialize(*this);
+ } else {
+ PlatformParser = new ELFAsmParser;
+ PlatformParser->Initialize(*this);
}
}
@@ -1051,6 +1084,18 @@
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!");
More information about the llvm-commits
mailing list