implement error recovery in the llvm-mc parser. Feel the power!
authorChris Lattner <sabre@nondot.org>
Thu, 2 Jul 2009 21:53:43 +0000 (21:53 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 2 Jul 2009 21:53:43 +0000 (21:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74728 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-mc/AsmParser.cpp

index 339a16db8c228aa046ed6761d235e65775a804fd..f5bf589201204f76ddf09781bc3cdb6ee8f589d4 100644 (file)
@@ -40,11 +40,18 @@ bool AsmParser::Run() {
   // Prime the lexer.
   Lexer.Lex();
   
-  while (Lexer.isNot(asmtok::Eof))
-    if (ParseStatement())
-      return true;
+  bool HadError = false;
   
-  return false;
+  // While we have input, parse each statement.
+  while (Lexer.isNot(asmtok::Eof)) {
+    if (!ParseStatement()) continue;
+  
+    // If we had an error, remember it and recover by skipping to the next line.
+    HadError = true;
+    EatToEndOfStatement();
+  }
+  
+  return HadError;
 }
 
 /// EatToEndOfStatement - Throw away the rest of the line for testing purposes.