[llvm-commits] [llvm] r77341 - /llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp

Daniel Dunbar daniel at zuster.org
Tue Jul 28 11:17:27 PDT 2009


Author: ddunbar
Date: Tue Jul 28 13:17:26 2009
New Revision: 77341

URL: http://llvm.org/viewvc/llvm-project?rev=77341&view=rev
Log:
Switch X86 assembly parser to using the generic lexer interface.

Modified:
    llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp

Modified: llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp?rev=77341&r1=77340&r2=77341&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp (original)
+++ llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp Tue Jul 28 13:17:26 2009
@@ -81,17 +81,17 @@
 };
 
 bool AsmParser::ParseX86Register(X86Operand &Op) {
-  assert(Lexer.getKind() == AsmToken::Register && "Invalid token kind!");
+  assert(getLexer().is(AsmToken::Register) && "Invalid token kind!");
 
   // FIXME: Decode register number.
   Op = X86Operand::CreateReg(123);
-  Lexer.Lex(); // Eat register token.
+  getLexer().Lex(); // Eat register token.
 
   return false;
 }
 
 bool AsmParser::ParseX86Operand(X86Operand &Op) {
-  switch (Lexer.getKind()) {
+  switch (getLexer().getKind()) {
   default:
     return ParseX86MemOperand(Op);
   case AsmToken::Register:
@@ -100,7 +100,7 @@
     return ParseX86Register(Op);
   case AsmToken::Dollar: {
     // $42 -> immediate.
-    Lexer.Lex();
+    getLexer().Lex();
     MCValue Val;
     if (ParseRelocatableExpression(Val))
       return true;
@@ -108,9 +108,9 @@
     return false;
   }
   case AsmToken::Star: {
-    Lexer.Lex(); // Eat the star.
+    getLexer().Lex(); // Eat the star.
     
-    if (Lexer.is(AsmToken::Register)) {
+    if (getLexer().is(AsmToken::Register)) {
       if (ParseX86Register(Op))
         return true;
     } else if (ParseX86MemOperand(Op))
@@ -132,24 +132,24 @@
   // only way to do this without lookahead is to eat the ( and see what is after
   // it.
   MCValue Disp = MCValue::get(0, 0, 0);
-  if (Lexer.isNot(AsmToken::LParen)) {
+  if (getLexer().isNot(AsmToken::LParen)) {
     if (ParseRelocatableExpression(Disp)) return true;
     
     // After parsing the base expression we could either have a parenthesized
     // memory address or not.  If not, return now.  If so, eat the (.
-    if (Lexer.isNot(AsmToken::LParen)) {
+    if (getLexer().isNot(AsmToken::LParen)) {
       Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 0);
       return false;
     }
     
     // Eat the '('.
-    Lexer.Lex();
+    getLexer().Lex();
   } else {
     // Okay, we have a '('.  We don't know if this is an expression or not, but
     // so we have to eat the ( to see beyond it.
-    Lexer.Lex(); // Eat the '('.
+    getLexer().Lex(); // Eat the '('.
     
-    if (Lexer.is(AsmToken::Register) || Lexer.is(AsmToken::Comma)) {
+    if (getLexer().is(AsmToken::Register) || getLexer().is(AsmToken::Comma)) {
       // Nothing to do here, fall into the code below with the '(' part of the
       // memory operand consumed.
     } else {
@@ -159,13 +159,13 @@
       
       // After parsing the base expression we could either have a parenthesized
       // memory address or not.  If not, return now.  If so, eat the (.
-      if (Lexer.isNot(AsmToken::LParen)) {
+      if (getLexer().isNot(AsmToken::LParen)) {
         Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 0);
         return false;
       }
       
       // Eat the '('.
-      Lexer.Lex();
+      getLexer().Lex();
     }
   }
   
@@ -173,14 +173,14 @@
   // the rest of the memory operand.
   unsigned BaseReg = 0, IndexReg = 0, Scale = 0;
   
-  if (Lexer.is(AsmToken::Register)) {
+  if (getLexer().is(AsmToken::Register)) {
     if (ParseX86Register(Op))
       return true;
     BaseReg = Op.getReg();
   }
   
-  if (Lexer.is(AsmToken::Comma)) {
-    Lexer.Lex(); // Eat the comma.
+  if (getLexer().is(AsmToken::Comma)) {
+    getLexer().Lex(); // Eat the comma.
 
     // Following the comma we should have either an index register, or a scale
     // value. We don't support the later form, but we want to parse it
@@ -188,20 +188,20 @@
     //
     // Not that even though it would be completely consistent to support syntax
     // like "1(%eax,,1)", the assembler doesn't.
-    if (Lexer.is(AsmToken::Register)) {
+    if (getLexer().is(AsmToken::Register)) {
       if (ParseX86Register(Op))
         return true;
       IndexReg = Op.getReg();
       Scale = 1;      // If not specified, the scale defaults to 1.
     
-      if (Lexer.isNot(AsmToken::RParen)) {
+      if (getLexer().isNot(AsmToken::RParen)) {
         // Parse the scale amount:
         //  ::= ',' [scale-expression]
-        if (Lexer.isNot(AsmToken::Comma))
+        if (getLexer().isNot(AsmToken::Comma))
           return true;
-        Lexer.Lex(); // Eat the comma.
+        getLexer().Lex(); // Eat the comma.
 
-        if (Lexer.isNot(AsmToken::RParen)) {
+        if (getLexer().isNot(AsmToken::RParen)) {
           int64_t ScaleVal;
           if (ParseAbsoluteExpression(ScaleVal))
             return true;
@@ -212,10 +212,10 @@
           Scale = (unsigned)ScaleVal;
         }
       }
-    } else if (Lexer.isNot(AsmToken::RParen)) {
+    } else if (getLexer().isNot(AsmToken::RParen)) {
       // Otherwise we have the unsupported form of a scale amount without an
       // index.
-      SMLoc Loc = Lexer.getLoc();
+      SMLoc Loc = getLexer().getTok().getLoc();
 
       int64_t Value;
       if (ParseAbsoluteExpression(Value))
@@ -226,9 +226,9 @@
   }
   
   // Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
-  if (Lexer.isNot(AsmToken::RParen))
+  if (getLexer().isNot(AsmToken::RParen))
     return TokError("unexpected token in memory operand");
-  Lexer.Lex(); // Eat the ')'.
+  getLexer().Lex(); // Eat the ')'.
   
   Op = X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale);
   return false;
@@ -247,14 +247,14 @@
 bool AsmParser::ParseX86InstOperands(const StringRef &InstName, MCInst &Inst) {
   llvm::SmallVector<X86Operand, 3> Operands;
 
-  if (Lexer.isNot(AsmToken::EndOfStatement)) {
+  if (getLexer().isNot(AsmToken::EndOfStatement)) {
     // Read the first operand.
     Operands.push_back(X86Operand());
     if (ParseX86Operand(Operands.back()))
       return true;
     
-    while (Lexer.is(AsmToken::Comma)) {
-      Lexer.Lex();  // Eat the comma.
+    while (getLexer().is(AsmToken::Comma)) {
+      getLexer().Lex();  // Eat the comma.
       
       // Parse and remember the operand.
       Operands.push_back(X86Operand());





More information about the llvm-commits mailing list