give better error diagnostics, for example:
authorChris Lattner <sabre@nondot.org>
Thu, 28 Oct 2010 21:41:58 +0000 (21:41 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 28 Oct 2010 21:41:58 +0000 (21:41 +0000)
t.s:1:14: error: invalid operand for instruction
vldr.64 d17, [r0]
             ^

instead of:

t.s:1:1: error: unrecognized instruction
vldr.64 d17, [r0]
^

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

lib/Target/ARM/AsmParser/ARMAsmParser.cpp

index 9836ef598fd6b6f573e02450f99caaeed2c759c2..88b2c61604fcfc0b9972ef027e6f8a27656f1ebb 100644 (file)
@@ -759,14 +759,29 @@ MatchAndEmitInstruction(SMLoc IDLoc,
                         MCStreamer &Out) {
   MCInst Inst;
   unsigned ErrorInfo;
-  if (MatchInstructionImpl(Operands, Inst, ErrorInfo) == Match_Success) {
+  switch (MatchInstructionImpl(Operands, Inst, ErrorInfo)) {
+  case Match_Success:
     Out.EmitInstruction(Inst);
     return false;
+      
+  case Match_MissingFeature:
+    Error(IDLoc, "instruction requires a CPU feature not currently enabled");
+    return true;
+  case Match_InvalidOperand: {
+    SMLoc ErrorLoc = IDLoc;
+    if (ErrorInfo != ~0U) {
+      if (ErrorInfo >= Operands.size())
+        return Error(IDLoc, "too few operands for instruction");
+      
+      ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
+      if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
+    }
+    
+    return Error(ErrorLoc, "invalid operand for instruction");
+  }
+  case Match_MnemonicFail:
+    return Error(IDLoc, "unrecognized instruction mnemonic");
   }
-  
-  // FIXME: We should give nicer diagnostics about the exact failure.
-  Error(IDLoc, "unrecognized instruction");
-  return true;
 }