fix the asmparser so that the target is responsible for skipping to
authorChris Lattner <sabre@nondot.org>
Sat, 11 Sep 2010 16:18:25 +0000 (16:18 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 11 Sep 2010 16:18:25 +0000 (16:18 +0000)
the end of the line on a parser error, allowing skipping to happen
for syntactic errors but not for semantic errors.  Before we would
miss emitting a diagnostic about the second line, because we skipped
it due to the semantic error on the first line:

  foo %eax
  bar %al

This fixes rdar://8414033 - llvm-mc ignores lines after an invalid instruction mnemonic errors

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113688 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/MCAsmParser.h
lib/MC/MCParser/AsmParser.cpp
lib/Target/ARM/AsmParser/ARMAsmParser.cpp
lib/Target/X86/AsmParser/X86AsmParser.cpp

index b37d46cc5a25ddd4bc42b32d91d388055e976bc9..6e1e2e3ece5440d6377e27aab6f0721885a59f8c 100644 (file)
@@ -99,6 +99,10 @@ public:
   /// will be either the EndOfStatement or EOF.
   virtual StringRef ParseStringToEndOfStatement() = 0;
 
+  /// EatToEndOfStatement - Skip to the end of the current statement, for error
+  /// recovery.
+  virtual void EatToEndOfStatement() = 0;
+  
   /// ParseExpression - Parse an arbitrary expression.
   ///
   /// @param Res - The value of the expression. The result is undefined
index 13aaeba156cf6ea7bf4265c0397d763e7a5ae4a3..0a664fd876ac35fd77a8cb7d8ef5fbc96a2c0442 100644 (file)
@@ -965,7 +965,9 @@ bool AsmParser::ParseStatement() {
   for (unsigned i = 0, e = ParsedOperands.size(); i != e; ++i)
     delete ParsedOperands[i];
 
-  return HadError;
+  // Don't skip the rest of the line, the instruction parser is responsible for
+  // that.
+  return false;
 }
 
 MacroInstantiation::MacroInstantiation(const Macro *M, SMLoc IL, SMLoc EL,
index f44470b2c1b514bc5002c7a6efb8a635f5d9e7c1..62712fc5be5020fff9b30c5be17b4d76d9f7e509 100644 (file)
@@ -726,22 +726,29 @@ bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
   if (getLexer().isNot(AsmToken::EndOfStatement)) {
     // Read the first operand.
     OwningPtr<ARMOperand> Op;
-    if (ParseOperand(Op)) return true;
+    if (ParseOperand(Op)) {
+      Parser.EatToEndOfStatement();
+      return true;
+    }
     Operands.push_back(Op.take());
 
     while (getLexer().is(AsmToken::Comma)) {
       Parser.Lex();  // Eat the comma.
 
       // Parse and remember the operand.
-      if (ParseOperand(Op)) return true;
+      if (ParseOperand(Op)) {
+        Parser.EatToEndOfStatement();
+        return true;
+      }
       Operands.push_back(Op.take());
     }
   }
   
-  if (getLexer().isNot(AsmToken::EndOfStatement))
+  if (getLexer().isNot(AsmToken::EndOfStatement)) {
+    Parser.EatToEndOfStatement();
     return TokError("unexpected token in argument list");
+  }
   Parser.Lex(); // Consume the EndOfStatement
-  
   return false;
 }
 
index 7e9dacf776003ca51b3a3f4b6d2e7cf6bb446478..a6b2b77a4acfea1e1c075e7c347ee725c736f7c9 100644 (file)
@@ -785,8 +785,10 @@ ParseInstruction(StringRef Name, SMLoc NameLoc,
     // Read the first operand.
     if (X86Operand *Op = ParseOperand())
       Operands.push_back(Op);
-    else
+    else {
+      Parser.EatToEndOfStatement();
       return true;
+    }
 
     while (getLexer().is(AsmToken::Comma)) {
       Parser.Lex();  // Eat the comma.
@@ -794,12 +796,16 @@ ParseInstruction(StringRef Name, SMLoc NameLoc,
       // Parse and remember the operand.
       if (X86Operand *Op = ParseOperand())
         Operands.push_back(Op);
-      else
+      else {
+        Parser.EatToEndOfStatement();
         return true;
+      }
     }
     
-    if (getLexer().isNot(AsmToken::EndOfStatement))
+    if (getLexer().isNot(AsmToken::EndOfStatement)) {
+      Parser.EatToEndOfStatement();
       return TokError("unexpected token in argument list");
+    }
   }
   
   if (getLexer().is(AsmToken::EndOfStatement))