[llvm-commits] [llvm] r93899 - in /llvm/trunk/tools/llvm-mc: AsmParser.cpp AsmParser.h

Sean Callanan scallanan at apple.com
Tue Jan 19 12:22:31 PST 2010


Author: spyffe
Date: Tue Jan 19 14:22:31 2010
New Revision: 93899

URL: http://llvm.org/viewvc/llvm-project?rev=93899&view=rev
Log:
Added a Lex function to the AsmParser, to allow handling
of include directives to occur within the parser itself.
This will break the lexer's dependency on a SourceMgr as
input.

Modified:
    llvm/trunk/tools/llvm-mc/AsmParser.cpp
    llvm/trunk/tools/llvm-mc/AsmParser.h

Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=93899&r1=93898&r2=93899&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jan 19 14:22:31 2010
@@ -100,6 +100,10 @@
   return true;
 }
 
+const AsmToken &AsmParser::Lex() {
+  return Lexer.Lex();
+}
+
 bool AsmParser::Run() {
   // Create the initial section.
   //
@@ -111,7 +115,7 @@
 
 
   // Prime the lexer.
-  Lexer.Lex();
+  Lex();
   
   bool HadError = false;
   
@@ -178,11 +182,11 @@
 void AsmParser::EatToEndOfStatement() {
   while (Lexer.isNot(AsmToken::EndOfStatement) &&
          Lexer.isNot(AsmToken::Eof))
-    Lexer.Lex();
+    Lex();
   
   // Eat EOL.
   if (Lexer.is(AsmToken::EndOfStatement))
-    Lexer.Lex();
+    Lex();
 }
 
 
@@ -196,7 +200,7 @@
   if (Lexer.isNot(AsmToken::RParen))
     return TokError("expected ')' in parentheses expression");
   EndLoc = Lexer.getLoc();
-  Lexer.Lex();
+  Lex();
   return false;
 }
 
@@ -221,7 +225,7 @@
   default:
     return TokError("unknown token in expression");
   case AsmToken::Exclaim:
-    Lexer.Lex(); // Eat the operator.
+    Lex(); // Eat the operator.
     if (ParsePrimaryExpr(Res, EndLoc))
       return true;
     Res = MCUnaryExpr::CreateLNot(Res, getContext());
@@ -231,7 +235,7 @@
     // This is a symbol reference.
     MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
     EndLoc = Lexer.getLoc();
-    Lexer.Lex(); // Eat identifier.
+    Lex(); // Eat identifier.
 
     // If this is an absolute variable reference, substitute it now to preserve
     // semantics in the face of reassignment.
@@ -247,25 +251,25 @@
   case AsmToken::Integer:
     Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext());
     EndLoc = Lexer.getLoc();
-    Lexer.Lex(); // Eat token.
+    Lex(); // Eat token.
     return false;
   case AsmToken::LParen:
-    Lexer.Lex(); // Eat the '('.
+    Lex(); // Eat the '('.
     return ParseParenExpr(Res, EndLoc);
   case AsmToken::Minus:
-    Lexer.Lex(); // Eat the operator.
+    Lex(); // Eat the operator.
     if (ParsePrimaryExpr(Res, EndLoc))
       return true;
     Res = MCUnaryExpr::CreateMinus(Res, getContext());
     return false;
   case AsmToken::Plus:
-    Lexer.Lex(); // Eat the operator.
+    Lex(); // Eat the operator.
     if (ParsePrimaryExpr(Res, EndLoc))
       return true;
     Res = MCUnaryExpr::CreatePlus(Res, getContext());
     return false;
   case AsmToken::Tilde:
-    Lexer.Lex(); // Eat the operator.
+    Lex(); // Eat the operator.
     if (ParsePrimaryExpr(Res, EndLoc))
       return true;
     Res = MCUnaryExpr::CreateNot(Res, getContext());
@@ -398,7 +402,7 @@
     if (TokPrec < Precedence)
       return false;
     
-    Lexer.Lex();
+    Lex();
     
     // Eat the next primary expression.
     const MCExpr *RHS;
@@ -426,7 +430,7 @@
 ///   ::= Label* Identifier OperandList* EndOfStatement
 bool AsmParser::ParseStatement() {
   if (Lexer.is(AsmToken::EndOfStatement)) {
-    Lexer.Lex();
+    Lex();
     return false;
   }
 
@@ -443,7 +447,7 @@
   switch (Lexer.getKind()) {
   case AsmToken::Colon: {
     // identifier ':'   -> Label.
-    Lexer.Lex();
+    Lex();
 
     // Diagnose attempt to use a variable as a label.
     //
@@ -462,7 +466,7 @@
 
   case AsmToken::Equal:
     // identifier '=' ... -> assignment statement
-    Lexer.Lex();
+    Lex();
 
     return ParseAssignment(IDVal);
 
@@ -734,7 +738,7 @@
     return TokError("unexpected token in argument list");
 
   // Eat the end of statement marker.
-  Lexer.Lex();
+  Lex();
   
 
   MCInst Inst;
@@ -771,7 +775,7 @@
     return TokError("unexpected token in assignment");
 
   // Eat the end of statement marker.
-  Lexer.Lex();
+  Lex();
 
   // Validate that the LHS is allowed to be a variable (either it has not been
   // used as a symbol, or it is an absolute symbol).
@@ -809,7 +813,7 @@
 
   Res = Lexer.getTok().getIdentifier();
 
-  Lexer.Lex(); // Consume the identifier token.
+  Lex(); // Consume the identifier token.
 
   return false;
 }
@@ -824,7 +828,7 @@
   
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in '.set'");
-  Lexer.Lex();
+  Lex();
 
   return ParseAssignment(Name);
 }
@@ -852,10 +856,10 @@
   StringRef EOL = Lexer.LexUntilEndOfStatement();
   SectionSpec.append(EOL.begin(), EOL.end());
 
-  Lexer.Lex();
+  Lex();
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.section' directive");
-  Lexer.Lex();
+  Lex();
 
 
   StringRef Segment, Section;
@@ -880,7 +884,7 @@
                                             unsigned StubSize) {
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in section switching directive");
-  Lexer.Lex();
+  Lex();
   
   // FIXME: Arch specific.
   Out.SwitchSection(getMachOSection(Segment, Section, TAA, StubSize,
@@ -974,18 +978,18 @@
       if (ZeroTerminated)
         Out.EmitBytes(StringRef("\0", 1), DEFAULT_ADDRSPACE);
       
-      Lexer.Lex();
+      Lex();
       
       if (Lexer.is(AsmToken::EndOfStatement))
         break;
 
       if (Lexer.isNot(AsmToken::Comma))
         return TokError("unexpected token in '.ascii' or '.asciz' directive");
-      Lexer.Lex();
+      Lex();
     }
   }
 
-  Lexer.Lex();
+  Lex();
   return false;
 }
 
@@ -1007,11 +1011,11 @@
       // FIXME: Improve diagnostic.
       if (Lexer.isNot(AsmToken::Comma))
         return TokError("unexpected token in directive");
-      Lexer.Lex();
+      Lex();
     }
   }
 
-  Lexer.Lex();
+  Lex();
   return false;
 }
 
@@ -1027,7 +1031,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement)) {
     if (Lexer.isNot(AsmToken::Comma))
       return TokError("unexpected token in '.space' directive");
-    Lexer.Lex();
+    Lex();
     
     if (ParseAbsoluteExpression(FillExpr))
       return true;
@@ -1038,7 +1042,7 @@
       return TokError("unexpected token in '.space' directive");
   }
 
-  Lexer.Lex();
+  Lex();
 
   if (NumBytes <= 0)
     return TokError("invalid number of bytes in '.space' directive");
@@ -1058,7 +1062,7 @@
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in '.fill' directive");
-  Lexer.Lex();
+  Lex();
   
   int64_t FillSize;
   if (ParseAbsoluteExpression(FillSize))
@@ -1066,7 +1070,7 @@
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in '.fill' directive");
-  Lexer.Lex();
+  Lex();
   
   int64_t FillExpr;
   if (ParseAbsoluteExpression(FillExpr))
@@ -1075,7 +1079,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.fill' directive");
   
-  Lexer.Lex();
+  Lex();
 
   if (FillSize != 1 && FillSize != 2 && FillSize != 4 && FillSize != 8)
     return TokError("invalid '.fill' size, expected 1, 2, 4, or 8");
@@ -1100,7 +1104,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement)) {
     if (Lexer.isNot(AsmToken::Comma))
       return TokError("unexpected token in '.org' directive");
-    Lexer.Lex();
+    Lex();
     
     if (ParseAbsoluteExpression(FillExpr))
       return true;
@@ -1109,7 +1113,7 @@
       return TokError("unexpected token in '.org' directive");
   }
 
-  Lexer.Lex();
+  Lex();
 
   // FIXME: Only limited forms of relocatable expressions are accepted here, it
   // has to be relative to the current section.
@@ -1133,7 +1137,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement)) {
     if (Lexer.isNot(AsmToken::Comma))
       return TokError("unexpected token in directive");
-    Lexer.Lex();
+    Lex();
 
     // The fill expression can be omitted while specifying a maximum number of
     // alignment bytes, e.g:
@@ -1147,7 +1151,7 @@
     if (Lexer.isNot(AsmToken::EndOfStatement)) {
       if (Lexer.isNot(AsmToken::Comma))
         return TokError("unexpected token in directive");
-      Lexer.Lex();
+      Lex();
 
       MaxBytesLoc = Lexer.getLoc();
       if (ParseAbsoluteExpression(MaxBytesToFill))
@@ -1158,7 +1162,7 @@
     }
   }
 
-  Lexer.Lex();
+  Lex();
 
   if (!HasFillExpr) {
     // FIXME: Sometimes fill with nop.
@@ -1216,11 +1220,11 @@
 
       if (Lexer.isNot(AsmToken::Comma))
         return TokError("unexpected token in directive");
-      Lexer.Lex();
+      Lex();
     }
   }
 
-  Lexer.Lex();
+  Lex();
   return false;  
 }
 
@@ -1236,7 +1240,7 @@
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in '.desc' directive");
-  Lexer.Lex();
+  Lex();
 
   SMLoc DescLoc = Lexer.getLoc();
   int64_t DescValue;
@@ -1246,7 +1250,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.desc' directive");
   
-  Lexer.Lex();
+  Lex();
 
   // Set the n_desc field of this Symbol to this DescValue
   Out.EmitSymbolDesc(Sym, DescValue);
@@ -1267,7 +1271,7 @@
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
-  Lexer.Lex();
+  Lex();
 
   int64_t Size;
   SMLoc SizeLoc = Lexer.getLoc();
@@ -1277,7 +1281,7 @@
   int64_t Pow2Alignment = 0;
   SMLoc Pow2AlignmentLoc;
   if (Lexer.is(AsmToken::Comma)) {
-    Lexer.Lex();
+    Lex();
     Pow2AlignmentLoc = Lexer.getLoc();
     if (ParseAbsoluteExpression(Pow2Alignment))
       return true;
@@ -1293,7 +1297,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.comm' or '.lcomm' directive");
   
-  Lexer.Lex();
+  Lex();
 
   // NOTE: a size of zero for a .comm should create a undefined symbol
   // but a size of .lcomm creates a bss symbol of size zero.
@@ -1334,17 +1338,17 @@
   if (Lexer.isNot(AsmToken::Identifier))
     return TokError("expected segment name after '.zerofill' directive");
   StringRef Segment = Lexer.getTok().getString();
-  Lexer.Lex();
+  Lex();
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
-  Lexer.Lex();
+  Lex();
  
   if (Lexer.isNot(AsmToken::Identifier))
     return TokError("expected section name after comma in '.zerofill' "
                     "directive");
   StringRef Section = Lexer.getTok().getString();
-  Lexer.Lex();
+  Lex();
 
   // If this is the end of the line all that was wanted was to create the
   // the section but with no symbol.
@@ -1358,7 +1362,7 @@
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
-  Lexer.Lex();
+  Lex();
 
   if (Lexer.isNot(AsmToken::Identifier))
     return TokError("expected identifier in directive");
@@ -1366,11 +1370,11 @@
   // handle the identifier as the key symbol.
   SMLoc IDLoc = Lexer.getLoc();
   MCSymbol *Sym = CreateSymbol(Lexer.getTok().getString());
-  Lexer.Lex();
+  Lex();
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
-  Lexer.Lex();
+  Lex();
 
   int64_t Size;
   SMLoc SizeLoc = Lexer.getLoc();
@@ -1380,7 +1384,7 @@
   int64_t Pow2Alignment = 0;
   SMLoc Pow2AlignmentLoc;
   if (Lexer.is(AsmToken::Comma)) {
-    Lexer.Lex();
+    Lex();
     Pow2AlignmentLoc = Lexer.getLoc();
     if (ParseAbsoluteExpression(Pow2Alignment))
       return true;
@@ -1389,7 +1393,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.zerofill' directive");
   
-  Lexer.Lex();
+  Lex();
 
   if (Size < 0)
     return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less "
@@ -1422,7 +1426,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.subsections_via_symbols' directive");
   
-  Lexer.Lex();
+  Lex();
 
   Out.EmitAssemblerFlag(MCStreamer::SubsectionsViaSymbols);
 
@@ -1442,13 +1446,13 @@
     
     Str = Lexer.getTok().getString();
 
-    Lexer.Lex();
+    Lex();
   }
 
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.abort' directive");
   
-  Lexer.Lex();
+  Lex();
 
   // FIXME: Handle here.
   if (Str.empty())
@@ -1471,7 +1475,7 @@
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("unexpected token in '.lsym' directive");
-  Lexer.Lex();
+  Lex();
 
   const MCExpr *Value;
   SMLoc StartLoc = Lexer.getLoc();
@@ -1481,7 +1485,7 @@
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.lsym' directive");
   
-  Lexer.Lex();
+  Lex();
 
   // We don't currently support this directive.
   //
@@ -1498,7 +1502,7 @@
   
   std::string Filename = Lexer.getTok().getString();
   SMLoc IncludeLoc = Lexer.getLoc();
-  Lexer.Lex();
+  Lex();
 
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.include' directive");
@@ -1524,12 +1528,12 @@
   if (Lexer.isNot(AsmToken::String))
     return TokError("expected string in '.dump' or '.load' directive");
   
-  Lexer.Lex();
+  Lex();
 
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.dump' or '.load' directive");
   
-  Lexer.Lex();
+  Lex();
 
   // FIXME: If/when .dump and .load are implemented they will be done in the
   // the assembly parser and not have any need for an MCStreamer API.
@@ -1545,7 +1549,7 @@
 /// ::= .if expression
 bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) {
   // Consume the identifier that was the .if directive
-  Lexer.Lex();
+  Lex();
 
   TheCondStack.push_back(TheCondState);
   TheCondState.TheCond = AsmCond::IfCond;
@@ -1560,7 +1564,7 @@
     if (Lexer.isNot(AsmToken::EndOfStatement))
       return TokError("unexpected token in '.if' directive");
     
-    Lexer.Lex();
+    Lex();
 
     TheCondState.CondMet = ExprValue;
     TheCondState.Ignore = !TheCondState.CondMet;
@@ -1579,7 +1583,7 @@
   TheCondState.TheCond = AsmCond::ElseIfCond;
 
   // Consume the identifier that was the .elseif directive
-  Lexer.Lex();
+  Lex();
 
   bool LastIgnoreState = false;
   if (!TheCondStack.empty())
@@ -1596,7 +1600,7 @@
     if (Lexer.isNot(AsmToken::EndOfStatement))
       return TokError("unexpected token in '.elseif' directive");
     
-    Lexer.Lex();
+    Lex();
     TheCondState.CondMet = ExprValue;
     TheCondState.Ignore = !TheCondState.CondMet;
   }
@@ -1608,12 +1612,12 @@
 /// ::= .else
 bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) {
   // Consume the identifier that was the .else directive
-  Lexer.Lex();
+  Lex();
 
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.else' directive");
   
-  Lexer.Lex();
+  Lex();
 
   if (TheCondState.TheCond != AsmCond::IfCond &&
       TheCondState.TheCond != AsmCond::ElseIfCond)
@@ -1635,12 +1639,12 @@
 /// ::= .endif
 bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) {
   // Consume the identifier that was the .endif directive
-  Lexer.Lex();
+  Lex();
 
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.endif' directive");
   
-  Lexer.Lex();
+  Lex();
 
   if ((TheCondState.TheCond == AsmCond::NoCond) ||
       TheCondStack.empty())
@@ -1661,7 +1665,7 @@
   int64_t FileNumber = -1;
   if (Lexer.is(AsmToken::Integer)) {
     FileNumber = Lexer.getTok().getIntVal();
-    Lexer.Lex();
+    Lex();
     
     if (FileNumber < 1)
       return TokError("file number less than one");
@@ -1671,7 +1675,7 @@
     return TokError("unexpected token in '.file' directive");
   
   StringRef ATTRIBUTE_UNUSED FileName = Lexer.getTok().getString();
-  Lexer.Lex();
+  Lex();
 
   if (Lexer.isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.file' directive");
@@ -1690,7 +1694,7 @@
 
     int64_t LineNumber = Lexer.getTok().getIntVal();
     (void) LineNumber;
-    Lexer.Lex();
+    Lex();
 
     // FIXME: Do something with the .line.
   }
@@ -1713,14 +1717,14 @@
   (void) FileNumber;
   // FIXME: Validate file.
 
-  Lexer.Lex();
+  Lex();
   if (Lexer.isNot(AsmToken::EndOfStatement)) {
     if (Lexer.isNot(AsmToken::Integer))
       return TokError("unexpected token in '.loc' directive");
 
     int64_t Param2 = Lexer.getTok().getIntVal();
     (void) Param2;
-    Lexer.Lex();
+    Lex();
 
     if (Lexer.isNot(AsmToken::EndOfStatement)) {
       if (Lexer.isNot(AsmToken::Integer))
@@ -1728,7 +1732,7 @@
 
       int64_t Param3 = Lexer.getTok().getIntVal();
       (void) Param3;
-      Lexer.Lex();
+      Lex();
 
       // FIXME: Do something with the .loc.
     }

Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=93899&r1=93898&r2=93899&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Tue Jan 19 14:22:31 2010
@@ -25,6 +25,7 @@
 
 namespace llvm {
 class AsmCond;
+class AsmToken;
 class MCContext;
 class MCExpr;
 class MCInst;
@@ -79,6 +80,8 @@
   virtual void Warning(SMLoc L, const Twine &Meg);
   virtual bool Error(SMLoc L, const Twine &Msg);
 
+  const AsmToken &Lex();
+
   bool ParseExpression(const MCExpr *&Res);
   virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc);
   virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc);





More information about the llvm-commits mailing list