summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2009-07-14 21:35:03 +0000
committerKevin Enderby <enderby@apple.com>2009-07-14 21:35:03 +0000
commit711482476c55f99c34c516f9e035b7c59b00ef42 (patch)
treedde0a4d27bc9fbd9f5c3b641b02e1939de61d024
parent4cb73525a943d69da0f2b0c31c1a1d7f3cdd879d (diff)
downloadllvm-711482476c55f99c34c516f9e035b7c59b00ef42.tar.gz
llvm-711482476c55f99c34c516f9e035b7c59b00ef42.tar.bz2
llvm-711482476c55f99c34c516f9e035b7c59b00ef42.tar.xz
Added llvm-mc support for parsing the .lsym directive.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75685 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/MC/MCStreamer.h6
-rw-r--r--lib/MC/MCAsmStreamer.cpp6
-rw-r--r--test/MC/AsmParser/directive_lsym.s8
-rw-r--r--tools/llvm-mc/AsmParser.cpp32
-rw-r--r--tools/llvm-mc/AsmParser.h1
5 files changed, 53 insertions, 0 deletions
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index a418a0f0b0..d58c8ba87d 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/include/llvm/MC/MCStreamer.h
@@ -126,6 +126,12 @@ namespace llvm {
/// @param DescValue - The value to set into the n_desc field.
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
+ /// EmitLocalSymbol - Emit a local symbol of @param Value to @param Symbol.
+ ///
+ /// @param Symbol - The local symbol being created.
+ /// @param Value - The value for the symbol.
+ virtual void EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value) = 0;
+
/// EmitCommonSymbol - Emit a common or local common symbol of @param Size
/// with the @param Pow2Alignment if non-zero.
///
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp
index b3460080d7..ec99b108be 100644
--- a/lib/MC/MCAsmStreamer.cpp
+++ b/lib/MC/MCAsmStreamer.cpp
@@ -47,6 +47,8 @@ namespace {
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
+ virtual void EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value);
+
virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
unsigned Pow2Alignment, bool IsLocal);
@@ -172,6 +174,10 @@ void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
OS << ".desc" << ' ' << Symbol->getName() << ',' << DescValue << '\n';
}
+void MCAsmStreamer::EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value) {
+ OS << ".lsym" << ' ' << Symbol->getName() << ',' << Value << '\n';
+}
+
void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
unsigned Pow2Alignment, bool IsLocal) {
if (IsLocal)
diff --git a/test/MC/AsmParser/directive_lsym.s b/test/MC/AsmParser/directive_lsym.s
new file mode 100644
index 0000000000..a4437b9a89
--- /dev/null
+++ b/test/MC/AsmParser/directive_lsym.s
@@ -0,0 +1,8 @@
+# RUN: llvm-mc %s | FileCheck %s
+
+# CHECK: TEST0:
+# CHECK: .lsym bar,foo
+# CHECK: .lsym baz,3
+TEST0:
+ .lsym bar, foo
+ .lsym baz, 2+1
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp
index d94b7b3270..b4e0f5792a 100644
--- a/tools/llvm-mc/AsmParser.cpp
+++ b/tools/llvm-mc/AsmParser.cpp
@@ -528,6 +528,8 @@ bool AsmParser::ParseStatement() {
return ParseDirectiveDarwinZerofill();
if (!strcmp(IDVal, ".desc"))
return ParseDirectiveDarwinSymbolDesc();
+ if (!strcmp(IDVal, ".lsym"))
+ return ParseDirectiveDarwinLsym();
if (!strcmp(IDVal, ".subsections_via_symbols"))
return ParseDirectiveDarwinSubsectionsViaSymbols();
@@ -1126,3 +1128,33 @@ bool AsmParser::ParseDirectiveAbort() {
return false;
}
+
+/// ParseDirectiveLsym
+/// ::= .lsym identifier , expression
+bool AsmParser::ParseDirectiveDarwinLsym() {
+ if (Lexer.isNot(asmtok::Identifier))
+ return TokError("expected identifier in directive");
+
+ // handle the identifier as the key symbol.
+ SMLoc IDLoc = Lexer.getLoc();
+ MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
+ Lexer.Lex();
+
+ if (Lexer.isNot(asmtok::Comma))
+ return TokError("unexpected token in '.lsym' directive");
+ Lexer.Lex();
+
+ MCValue Expr;
+ if (ParseRelocatableExpression(Expr))
+ return true;
+
+ if (Lexer.isNot(asmtok::EndOfStatement))
+ return TokError("unexpected token in '.lsym' directive");
+
+ Lexer.Lex();
+
+ // Create the Sym with the value of the Expr
+ Out.EmitLocalSymbol(Sym, Expr);
+
+ return false;
+}
diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h
index b4f5e2d428..7d756376c5 100644
--- a/tools/llvm-mc/AsmParser.h
+++ b/tools/llvm-mc/AsmParser.h
@@ -110,6 +110,7 @@ private:
/// accepts a single symbol (which should be a label or an external).
bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
+ bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"