summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-25 22:44:51 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-25 22:44:51 +0000
commit4a5a561a24747de53879e5d786accd4b99f5b656 (patch)
tree991935e4af37ca6935801182afde81dd0d849cba /llvm
parent95f48a5d871df42fa15ecd89d666aeae266f4c30 (diff)
downloadbcm5719-llvm-4a5a561a24747de53879e5d786accd4b99f5b656.tar.gz
bcm5719-llvm-4a5a561a24747de53879e5d786accd4b99f5b656.zip
MC: Parse .org directives.
llvm-svn: 74218
Diffstat (limited to 'llvm')
-rw-r--r--llvm/test/MC/AsmParser/directive_org.s11
-rw-r--r--llvm/tools/llvm-mc/AsmParser.cpp31
-rw-r--r--llvm/tools/llvm-mc/AsmParser.h1
3 files changed, 42 insertions, 1 deletions
diff --git a/llvm/test/MC/AsmParser/directive_org.s b/llvm/test/MC/AsmParser/directive_org.s
new file mode 100644
index 00000000000..ac50f635e6b
--- /dev/null
+++ b/llvm/test/MC/AsmParser/directive_org.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc %s > %t
+
+# RUN: grep -A 2 TEST0 %t > %t2
+# RUN: grep ".org 1, 0" %t2 | count 1
+TEST0:
+ .org 1
+
+# RUN: grep -A 2 TEST1 %t > %t2
+# RUN: grep ".org 1, 3" %t2 | count 1
+TEST1:
+ .org 1, 3
diff --git a/llvm/tools/llvm-mc/AsmParser.cpp b/llvm/tools/llvm-mc/AsmParser.cpp
index 25955187dab..2b697a66ad2 100644
--- a/llvm/tools/llvm-mc/AsmParser.cpp
+++ b/llvm/tools/llvm-mc/AsmParser.cpp
@@ -324,6 +324,8 @@ bool AsmParser::ParseStatement() {
return ParseDirectiveValue(8);
if (!strcmp(IDVal, ".fill"))
return ParseDirectiveFill();
+ if (!strcmp(IDVal, ".org"))
+ return ParseDirectiveOrg();
if (!strcmp(IDVal, ".space"))
return ParseDirectiveSpace();
@@ -332,7 +334,6 @@ bool AsmParser::ParseStatement() {
return false;
}
-
MCInst Inst;
if (ParseX86InstOperands(Inst))
return true;
@@ -558,3 +559,31 @@ bool AsmParser::ParseDirectiveFill() {
return false;
}
+
+/// ParseDirectiveOrg
+/// ::= .org expression [ , expression ]
+bool AsmParser::ParseDirectiveOrg() {
+ int64_t Offset;
+ if (ParseExpression(Offset))
+ return true;
+
+ // Parse optional fill expression.
+ int64_t FillExpr = 0;
+ if (Lexer.isNot(asmtok::EndOfStatement)) {
+ if (Lexer.isNot(asmtok::Comma))
+ return TokError("unexpected token in '.org' directive");
+ Lexer.Lex();
+
+ if (ParseExpression(FillExpr))
+ return true;
+
+ if (Lexer.isNot(asmtok::EndOfStatement))
+ return TokError("unexpected token in '.org' directive");
+ }
+
+ Lexer.Lex();
+
+ Out.EmitValueToOffset(MCValue::get(Offset), FillExpr);
+
+ return false;
+}
diff --git a/llvm/tools/llvm-mc/AsmParser.h b/llvm/tools/llvm-mc/AsmParser.h
index 4b51ab17ac2..da256c275ca 100644
--- a/llvm/tools/llvm-mc/AsmParser.h
+++ b/llvm/tools/llvm-mc/AsmParser.h
@@ -63,6 +63,7 @@ private:
bool ParseDirectiveFill(); // ".fill"
bool ParseDirectiveSpace(); // ".space"
bool ParseDirectiveSet(); // ".set"
+ bool ParseDirectiveOrg(); // ".org"
};
OpenPOWER on IntegriCloud