MC: Parse .org directives.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 25 Jun 2009 22:44:51 +0000 (22:44 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 25 Jun 2009 22:44:51 +0000 (22:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74218 91177308-0d34-0410-b5e6-96231b3b80d8

test/MC/AsmParser/directive_org.s [new file with mode: 0644]
tools/llvm-mc/AsmParser.cpp
tools/llvm-mc/AsmParser.h

diff --git a/test/MC/AsmParser/directive_org.s b/test/MC/AsmParser/directive_org.s
new file mode 100644 (file)
index 0000000..ac50f63
--- /dev/null
@@ -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
index 25955187dab1156006359f1d5ade469216281545..2b697a66ad2a92fe03849902cd723607f6032b34 100644 (file)
@@ -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;
+}
index 4b51ab17ac2b9f79ae74591fc25a3349cc01022d..da256c275ca3073e6c29d012cef2f30b1c3731b5 100644 (file)
@@ -63,6 +63,7 @@ private:
   bool ParseDirectiveFill(); // ".fill"
   bool ParseDirectiveSpace(); // ".space"
   bool ParseDirectiveSet(); // ".set"
+  bool ParseDirectiveOrg(); // ".org"
   
 };