mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-28 06:24:57 +00:00
MC/AsmParser: Move ELF specific parser to ELFAsmParser.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108196 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -18,7 +18,6 @@
|
|||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
#include "llvm/MC/MCInst.h"
|
||||||
#include "llvm/MC/MCSectionELF.h"
|
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
#include "llvm/MC/MCSymbol.h"
|
#include "llvm/MC/MCSymbol.h"
|
||||||
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
|
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
|
||||||
@ -55,40 +54,12 @@ public:
|
|||||||
bool ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc); // ".loc"
|
bool ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc); // ".loc"
|
||||||
};
|
};
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
extern MCAsmParserExtension *createDarwinAsmParser();
|
extern MCAsmParserExtension *createDarwinAsmParser();
|
||||||
|
extern MCAsmParserExtension *createELFAsmParser();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +83,7 @@ AsmParser::AsmParser(const Target &T, SourceMgr &_SM, MCContext &_Ctx,
|
|||||||
PlatformParser = createDarwinAsmParser();
|
PlatformParser = createDarwinAsmParser();
|
||||||
PlatformParser->Initialize(*this);
|
PlatformParser->Initialize(*this);
|
||||||
} else {
|
} else {
|
||||||
PlatformParser = new ELFAsmParser;
|
PlatformParser = createELFAsmParser();
|
||||||
PlatformParser->Initialize(*this);
|
PlatformParser->Initialize(*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -815,18 +786,6 @@ bool AsmParser::ParseDirectiveSet() {
|
|||||||
return ParseAssignment(Name);
|
return ParseAssignment(Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
bool AsmParser::ParseEscapedString(std::string &Data) {
|
||||||
assert(getLexer().is(AsmToken::String) && "Unexpected current token!");
|
assert(getLexer().is(AsmToken::String) && "Unexpected current token!");
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ add_llvm_library(LLVMMCParser
|
|||||||
AsmLexer.cpp
|
AsmLexer.cpp
|
||||||
AsmParser.cpp
|
AsmParser.cpp
|
||||||
DarwinAsmParser.cpp
|
DarwinAsmParser.cpp
|
||||||
|
ELFAsmParser.cpp
|
||||||
MCAsmLexer.cpp
|
MCAsmLexer.cpp
|
||||||
MCAsmParser.cpp
|
MCAsmParser.cpp
|
||||||
MCAsmParserExtension.cpp
|
MCAsmParserExtension.cpp
|
||||||
|
68
lib/MC/MCParser/ELFAsmParser.cpp
Normal file
68
lib/MC/MCParser/ELFAsmParser.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
//===- ELFAsmParser.cpp - ELF Assembly Parser -----------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
|
||||||
|
#include "llvm/MC/MCSectionELF.h"
|
||||||
|
#include "llvm/MC/MCContext.h"
|
||||||
|
#include "llvm/MC/MCStreamer.h"
|
||||||
|
#include "llvm/MC/MCParser/MCAsmLexer.h"
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
|
||||||
|
MCAsmParserExtension *createELFAsmParser() {
|
||||||
|
return new ELFAsmParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user