Skip to content

Commit

Permalink
[flang] Support <name>=<integer> syntax in compiler directives
Browse files Browse the repository at this point in the history
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
  • Loading branch information
klausler committed Jul 18, 2020
1 parent 0dfa4a8 commit 8e2b4e5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions flang/include/flang/Parser/dump-parse-tree.h
Expand Up @@ -222,6 +222,7 @@ class ParseTreeDumper {
NODE(CommonStmt, Block)
NODE(parser, CompilerDirective)
NODE(CompilerDirective, IgnoreTKR)
NODE(CompilerDirective, NameValue)
NODE(parser, ComplexLiteralConstant)
NODE(parser, ComplexPart)
NODE(parser, ComponentArraySpec)
Expand Down
6 changes: 5 additions & 1 deletion flang/include/flang/Parser/parse-tree.h
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion flang/lib/Parser/Fortran-parsers.cpp
Expand Up @@ -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>(
Expand Down
8 changes: 7 additions & 1 deletion flang/lib/Parser/unparse.cpp
Expand Up @@ -1761,7 +1761,9 @@ class UnparseVisitor {
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');
Expand All @@ -1777,6 +1779,10 @@ class UnparseVisitor {
}
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) {
Expand Down

0 comments on commit 8e2b4e5

Please sign in to comment.