[flang] Support <name>=<integer> syntax in compiler directives
authorpeter klausler <pklausler@nvidia.com>
Fri, 17 Jul 2020 23:36:59 +0000 (16:36 -0700)
committerpeter klausler <pklausler@nvidia.com>
Sat, 18 Jul 2020 00:05:38 +0000 (17:05 -0700)
Accept name=value as part of a !DIR$ compiler directive.  These
are currently ignored in semantics, but we should recognize
more directive forms to facilitate testing.  In due course,
these placeholding directive parsers will be replaced.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84077

flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/Fortran-parsers.cpp
flang/lib/Parser/unparse.cpp

index 36e593e..02da3f5 100644 (file)
@@ -222,6 +222,7 @@ public:
   NODE(CommonStmt, Block)
   NODE(parser, CompilerDirective)
   NODE(CompilerDirective, IgnoreTKR)
+  NODE(CompilerDirective, NameValue)
   NODE(parser, ComplexLiteralConstant)
   NODE(parser, ComplexPart)
   NODE(parser, ComponentArraySpec)
index d9ecebf..4b34d2c 100644 (file)
@@ -3211,8 +3211,12 @@ struct CompilerDirective {
     TUPLE_CLASS_BOILERPLATE(IgnoreTKR);
     std::tuple<std::list<const char *>, Name> t;
   };
+  struct NameValue {
+    TUPLE_CLASS_BOILERPLATE(NameValue);
+    std::tuple<Name, std::optional<std::uint64_t>> t;
+  };
   CharBlock source;
-  std::variant<std::list<IgnoreTKR>, std::list<Name>> u;
+  std::variant<std::list<IgnoreTKR>, std::list<NameValue>> u;
 };
 
 // Legacy extensions
index 3192781..f461863 100644 (file)
@@ -1173,7 +1173,9 @@ constexpr auto ignore_tkr{
                              defaulted(parenthesized(some("tkr"_ch))), name))};
 TYPE_PARSER(
     beginDirective >> sourced(construct<CompilerDirective>(ignore_tkr) ||
-                          construct<CompilerDirective>("DIR$" >> many(name))) /
+                          construct<CompilerDirective>("DIR$" >>
+                              many(construct<CompilerDirective::NameValue>(
+                                  name, maybe("=" >> digitString64))))) /
         endDirective)
 
 TYPE_PARSER(extension<LanguageFeature::CrayPointer>(construct<BasedPointerStmt>(
index 99792cb..3b95636 100644 (file)
@@ -1761,7 +1761,9 @@ public:
               Word("!DIR$ IGNORE_TKR"); // emitted even if tkr list is empty
               Walk(" ", tkr, ", ");
             },
-            [&](const std::list<Name> &names) { Walk("!DIR$ ", names, " "); },
+            [&](const std::list<CompilerDirective::NameValue> &names) {
+              Walk("!DIR$ ", names, " ");
+            },
         },
         x.u);
     Put('\n');
@@ -1777,6 +1779,10 @@ public:
     }
     Walk(std::get<Name>(x.t));
   }
+  void Unparse(const CompilerDirective::NameValue &x) {
+    Walk(std::get<Name>(x.t));
+    Walk("=", std::get<std::optional<std::uint64_t>>(x.t));
+  }
 
   // OpenACC Directives & Clauses
   void Unparse(const AccAtomicCapture &x) {