[llvm-commits] [llvm] r148591 - in /llvm/trunk: lib/Target/X86/AsmParser/X86AsmParser.cpp test/MC/X86/intel-syntax.s

Devang Patel dpatel at apple.com
Fri Jan 20 14:32:05 PST 2012


Author: dpatel
Date: Fri Jan 20 16:32:05 2012
New Revision: 148591

URL: http://llvm.org/viewvc/llvm-project?rev=148591&view=rev
Log:
Intel syntax: Robustify register parsing.

Modified:
    llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
    llvm/trunk/test/MC/X86/intel-syntax.s

Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=148591&r1=148590&r2=148591&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Fri Jan 20 16:32:05 2012
@@ -470,17 +470,20 @@
 bool X86AsmParser::ParseRegister(unsigned &RegNo,
                                  SMLoc &StartLoc, SMLoc &EndLoc) {
   RegNo = 0;
-  const AsmToken &TokPercent = Parser.getTok();
-  if (!getParser().getAssemblerDialect()) {
+  bool IntelSyntax = getParser().getAssemblerDialect();
+  if (!IntelSyntax) {
+    const AsmToken &TokPercent = Parser.getTok();
     assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!");
     StartLoc = TokPercent.getLoc();
     Parser.Lex(); // Eat percent token.
   }
 
   const AsmToken &Tok = Parser.getTok();
-  if (Tok.isNot(AsmToken::Identifier))
+  if (Tok.isNot(AsmToken::Identifier)) {
+    if (IntelSyntax) return true;
     return Error(StartLoc, "invalid register name",
                  SMRange(StartLoc, Tok.getEndLoc()));
+  }
 
   RegNo = MatchRegisterName(Tok.getString());
 
@@ -560,9 +563,11 @@
     }
   }
 
-  if (RegNo == 0)
+  if (RegNo == 0) {
+    if (IntelSyntax) return true;
     return Error(StartLoc, "invalid register name",
                  SMRange(StartLoc, Tok.getEndLoc()));
+  }
 
   EndLoc = Tok.getEndLoc();
   Parser.Lex(); // Eat identifier token.
@@ -575,16 +580,6 @@
   return ParseATTOperand();
 }
 
-/// getIntelRegister - If this is an intel register operand
-/// then return register number, otherwise return 0;
-static unsigned getIntelRegisterOperand(StringRef Str) {
-  unsigned RegNo = MatchRegisterName(Str);
-  // If the match failed, try the register name as lowercase.
-  if (RegNo == 0)
-    RegNo = MatchRegisterName(Str.lower());
-  return RegNo;
-}
-
 /// getIntelMemOperandSize - Return intel memory operand size.
 static unsigned getIntelMemOperandSize(StringRef OpStr) {
   unsigned Size = 0;
@@ -613,10 +608,7 @@
   
   if (getLexer().is(AsmToken::Identifier)) {
     // Parse BaseReg
-    BaseReg = getIntelRegisterOperand(Tok.getString());
-    if (BaseReg)
-      Parser.Lex();
-    else {
+    if (ParseRegister(BaseReg, Start, End)) {
       // Handle '[' 'symbol' ']'
       const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
       if (getParser().ParseExpression(Disp, End)) return 0;
@@ -645,20 +637,16 @@
       if (getLexer().is(AsmToken::Star)) {
         Parser.Lex();
         SMLoc IdxRegLoc = Parser.getTok().getLoc();
-        IndexReg = getIntelRegisterOperand(Parser.getTok().getString());
-        if (!IndexReg) return ErrorOperand(IdxRegLoc, "Expected register");
-        Parser.Lex(); // Eat register
+	if (ParseRegister(IndexReg, IdxRegLoc, End))
+	  return ErrorOperand(IdxRegLoc, "Expected register");
         Scale = Val;
       } else if (getLexer().is(AsmToken::RBrac)) {
         const MCExpr *ValExpr = MCConstantExpr::Create(Val, getContext());
         Disp = isPlus ? ValExpr : MCConstantExpr::Create(0-Val, getContext());
       } else
         return ErrorOperand(PlusLoc, "unexpected token after +");
-    } else if (getLexer().is(AsmToken::Identifier)) {
-      IndexReg = getIntelRegisterOperand(Tok.getString());
-      if (IndexReg)
-	Parser.Lex();
-    }
+    } else if (getLexer().is(AsmToken::Identifier))
+      ParseRegister(IndexReg, Start, End);
   }
 
   if (getLexer().isNot(AsmToken::RBrac))
@@ -713,8 +701,8 @@
   }
 
   // register
-  if(unsigned RegNo = getIntelRegisterOperand(TokenString)) {
-    Parser.Lex();
+  unsigned RegNo = 0;
+  if (!ParseRegister(RegNo, Start, End)) {
     End = Parser.getTok().getLoc();
     return X86Operand::CreateReg(RegNo, Start, End);
   }

Modified: llvm/trunk/test/MC/X86/intel-syntax.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/intel-syntax.s?rev=148591&r1=148590&r2=148591&view=diff
==============================================================================
--- llvm/trunk/test/MC/X86/intel-syntax.s (original)
+++ llvm/trunk/test/MC/X86/intel-syntax.s Fri Jan 20 16:32:05 2012
@@ -53,4 +53,6 @@
 	and	rax, 257
 // CHECK:	andq	$-257,	%rax
 	and	rax, -257
+// CHECK:	fld	%st(0)
+	fld	ST(0)
 	ret





More information about the llvm-commits mailing list