[MC/Mach-O] Add AsmParser support for .linker_option directive.
llvm-svn: 172778
This commit is contained in:
parent
4038fa3c82
commit
16004b8324
|
@ -20,6 +20,7 @@
|
||||||
#include "llvm/MC/MCDwarf.h"
|
#include "llvm/MC/MCDwarf.h"
|
||||||
#include "llvm/MC/MCWin64EH.h"
|
#include "llvm/MC/MCWin64EH.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCAsmBackend;
|
class MCAsmBackend;
|
||||||
|
@ -255,6 +256,10 @@ namespace llvm {
|
||||||
/// EmitAssemblerFlag - Note in the output the specified @p Flag.
|
/// EmitAssemblerFlag - Note in the output the specified @p Flag.
|
||||||
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
|
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
|
||||||
|
|
||||||
|
/// EmitLinkerOptions - Emit the given list @p Options of strings as linker
|
||||||
|
/// options into the output.
|
||||||
|
virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
|
||||||
|
|
||||||
/// EmitDataRegion - Note in the output the specified region @p Kind.
|
/// EmitDataRegion - Note in the output the specified region @p Kind.
|
||||||
virtual void EmitDataRegion(MCDataRegionType Kind) {}
|
virtual void EmitDataRegion(MCDataRegionType Kind) {}
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,7 @@ public:
|
||||||
virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
|
virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
|
||||||
MCSymbol *EHSymbol);
|
MCSymbol *EHSymbol);
|
||||||
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
|
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
|
||||||
|
virtual void EmitLinkerOptions(ArrayRef<std::string> Options);
|
||||||
virtual void EmitDataRegion(MCDataRegionType Kind);
|
virtual void EmitDataRegion(MCDataRegionType Kind);
|
||||||
virtual void EmitThumbFunc(MCSymbol *Func);
|
virtual void EmitThumbFunc(MCSymbol *Func);
|
||||||
|
|
||||||
|
@ -375,6 +376,15 @@ void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
|
||||||
EmitEOL();
|
EmitEOL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MCAsmStreamer::EmitLinkerOptions(ArrayRef<std::string> Options) {
|
||||||
|
assert(!Options.empty() && "At least one option is required!");
|
||||||
|
OS << "\t.linker_option \"" << Options[0] << '"';
|
||||||
|
for (ArrayRef<std::string>::iterator it = Options.begin() + 1,
|
||||||
|
ie = Options.end(); it != ie; ++it) {
|
||||||
|
OS << ", " << '"' << *it << '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
|
void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
|
||||||
MCContext &Ctx = getContext();
|
MCContext &Ctx = getContext();
|
||||||
const MCAsmInfo &MAI = Ctx.getAsmInfo();
|
const MCAsmInfo &MAI = Ctx.getAsmInfo();
|
||||||
|
|
|
@ -87,6 +87,8 @@ public:
|
||||||
AddDirectiveHandler<
|
AddDirectiveHandler<
|
||||||
&DarwinAsmParser::ParseSectionDirectiveLazySymbolPointers>(
|
&DarwinAsmParser::ParseSectionDirectiveLazySymbolPointers>(
|
||||||
".lazy_symbol_pointer");
|
".lazy_symbol_pointer");
|
||||||
|
AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveLinkerOption>(
|
||||||
|
".linker_option");
|
||||||
AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral16>(
|
AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral16>(
|
||||||
".literal16");
|
".literal16");
|
||||||
AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral4>(
|
AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral4>(
|
||||||
|
@ -163,6 +165,7 @@ public:
|
||||||
bool ParseDirectiveDesc(StringRef, SMLoc);
|
bool ParseDirectiveDesc(StringRef, SMLoc);
|
||||||
bool ParseDirectiveDumpOrLoad(StringRef, SMLoc);
|
bool ParseDirectiveDumpOrLoad(StringRef, SMLoc);
|
||||||
bool ParseDirectiveLsym(StringRef, SMLoc);
|
bool ParseDirectiveLsym(StringRef, SMLoc);
|
||||||
|
bool ParseDirectiveLinkerOption(StringRef, SMLoc);
|
||||||
bool ParseDirectiveSection(StringRef, SMLoc);
|
bool ParseDirectiveSection(StringRef, SMLoc);
|
||||||
bool ParseDirectivePushSection(StringRef, SMLoc);
|
bool ParseDirectivePushSection(StringRef, SMLoc);
|
||||||
bool ParseDirectivePopSection(StringRef, SMLoc);
|
bool ParseDirectivePopSection(StringRef, SMLoc);
|
||||||
|
@ -435,6 +438,33 @@ bool DarwinAsmParser::ParseDirectiveDumpOrLoad(StringRef Directive,
|
||||||
return Warning(IDLoc, "ignoring directive .load for now");
|
return Warning(IDLoc, "ignoring directive .load for now");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ParseDirectiveLinkerOption
|
||||||
|
/// ::= .linker_option "string" ( , "string" )*
|
||||||
|
bool DarwinAsmParser::ParseDirectiveLinkerOption(StringRef IDVal, SMLoc) {
|
||||||
|
SmallVector<std::string, 4> Args;
|
||||||
|
for (;;) {
|
||||||
|
if (getLexer().isNot(AsmToken::String))
|
||||||
|
return TokError("expected string in '" + Twine(IDVal) + "' directive");
|
||||||
|
|
||||||
|
std::string Data;
|
||||||
|
if (getParser().ParseEscapedString(Data))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Args.push_back(Data);
|
||||||
|
|
||||||
|
Lex();
|
||||||
|
if (getLexer().is(AsmToken::EndOfStatement))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (getLexer().isNot(AsmToken::Comma))
|
||||||
|
return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
|
||||||
|
Lex();
|
||||||
|
}
|
||||||
|
|
||||||
|
getStreamer().EmitLinkerOptions(Args);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// ParseDirectiveLsym
|
/// ParseDirectiveLsym
|
||||||
/// ::= .lsym identifier , expression
|
/// ::= .lsym identifier , expression
|
||||||
bool DarwinAsmParser::ParseDirectiveLsym(StringRef, SMLoc) {
|
bool DarwinAsmParser::ParseDirectiveLsym(StringRef, SMLoc) {
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
// RUN: not llvm-mc -triple x86_64-apple-darwin10 %s 2> %t.err > %t
|
||||||
|
// RUN: FileCheck --check-prefix=CHECK-OUTPUT < %t %s
|
||||||
|
// RUN: FileCheck --check-prefix=CHECK-ERROR < %t.err %s
|
||||||
|
|
||||||
|
// CHECK-OUTPUT: .linker_option "a"
|
||||||
|
.linker_option "a"
|
||||||
|
// CHECK-OUTPUT: .linker_option "a", "b"
|
||||||
|
.linker_option "a", "b"
|
||||||
|
// CHECK-OUTPUT-NOT: .linker_option
|
||||||
|
// CHECK-ERROR: expected string in '.linker_option' directive
|
||||||
|
// CHECK-ERROR: .linker_option 10
|
||||||
|
// CHECK-ERROR: ^
|
||||||
|
.linker_option 10
|
||||||
|
// CHECK-ERROR: expected string in '.linker_option' directive
|
||||||
|
// CHECK-ERROR: .linker_option "a",
|
||||||
|
// CHECK-ERROR: ^
|
||||||
|
.linker_option "a",
|
||||||
|
// CHECK-ERROR: unexpected token in '.linker_option' directive
|
||||||
|
// CHECK-ERROR: .linker_option "a" "b"
|
||||||
|
// CHECK-ERROR: ^
|
||||||
|
.linker_option "a" "b"
|
Loading…
Reference in New Issue