Match X86 register names to number.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77404 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 12e9f93..f172c1d 100644
--- a/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -42,6 +42,13 @@
   bool ParseOperand(X86Operand &Op);
 
   bool ParseMemOperand(X86Operand &Op);
+  
+  /// @name Auto-generated Match Functions
+  /// {  
+
+  bool MatchRegisterName(const StringRef &Name, unsigned &RegNo);
+
+  /// }
 
 public:
   X86ATTAsmParser(const Target &T, MCAsmParser &_Parser)
@@ -118,10 +125,17 @@
 //
 
 bool X86ATTAsmParser::ParseRegister(X86Operand &Op) {
-  assert(getLexer().is(AsmToken::Register) && "Invalid token kind!");
+  AsmToken Tok = getLexer().getTok();
+  assert(Tok.is(AsmToken::Register) && "Invalid token kind!");
 
-  // FIXME: Decode register number.
-  Op = X86Operand::CreateReg(123);
+  // FIXME: Validate register for the current architecture; we have to do
+  // validation later, so maybe there is no need for this here.
+  unsigned RegNo;
+  assert(Tok.getString().startswith("%") && "Invalid register name!");
+  if (MatchRegisterName(Tok.getString().substr(1), RegNo))
+    return Error(Tok.getLoc(), "invalid register name");
+
+  Op = X86Operand::CreateReg(RegNo);
   getLexer().Lex(); // Eat register token.
 
   return false;
@@ -308,3 +322,5 @@
   RegisterAsmParser<X86ATTAsmParser> X(TheX86_32Target);
   RegisterAsmParser<X86ATTAsmParser> Y(TheX86_64Target);
 }
+
+#include "X86GenAsmMatcher.inc"