MIR Serialization: Serialize the 'volatile' machine memory operand flag.
[oota-llvm.git] / lib / CodeGen / MIRParser / MILexer.cpp
index 2104f002b1f59f401aef0a17c36d03725fe5fc9b..adc72e2a5668511a17cf1a9d07ef01dca9b7ee84 100644 (file)
@@ -156,6 +156,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
       .Case("x86_fp80", MIToken::kw_x86_fp80)
       .Case("fp128", MIToken::kw_fp128)
       .Case("ppc_fp128", MIToken::kw_ppc_fp128)
+      .Case("volatile", MIToken::kw_volatile)
       .Default(MIToken::Identifier);
 }
 
@@ -260,6 +261,16 @@ static Cursor maybeLexIRBlock(
                  Rule.size(), ErrorCallback);
 }
 
+static Cursor maybeLexIRValue(
+    Cursor C, MIToken &Token,
+    function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) {
+  const StringRef Rule = "%ir.";
+  if (!C.remaining().startswith(Rule))
+    return None;
+  return lexName(C, Token, MIToken::NamedIRValue, MIToken::QuotedNamedIRValue,
+                 Rule.size(), ErrorCallback);
+}
+
 static Cursor lexVirtualRegister(Cursor C, MIToken &Token) {
   auto Range = C;
   C.advance(); // Skip '%'
@@ -381,11 +392,17 @@ static MIToken::TokenKind symbolToken(char C) {
 }
 
 static Cursor maybeLexSymbol(Cursor C, MIToken &Token) {
-  auto Kind = symbolToken(C.peek());
+  MIToken::TokenKind Kind;
+  unsigned Length = 1;
+  if (C.peek() == ':' && C.peek(1) == ':') {
+    Kind = MIToken::coloncolon;
+    Length = 2;
+  } else
+    Kind = symbolToken(C.peek());
   if (Kind == MIToken::Error)
     return None;
   auto Range = C;
-  C.advance();
+  C.advance(Length);
   Token = MIToken(Kind, Range.upto(C));
   return C;
 }
@@ -413,6 +430,8 @@ StringRef llvm::lexMIToken(
     return R.remaining();
   if (Cursor R = maybeLexIRBlock(C, Token, ErrorCallback))
     return R.remaining();
+  if (Cursor R = maybeLexIRValue(C, Token, ErrorCallback))
+    return R.remaining();
   if (Cursor R = maybeLexRegister(C, Token))
     return R.remaining();
   if (Cursor R = maybeLexGlobalValue(C, Token, ErrorCallback))