diff options
author | 2022-07-22 16:40:50 +0000 | |
---|---|---|
committer | 2022-07-22 17:05:04 +0000 | |
commit | 846439dd97d45e0e08af14269708511646a9add1 (patch) | |
tree | a57ecac15d86d7a21bf2752ae6df5d380c6f5df5 /clang | |
parent | [libc] Don't call user comparator function for equal pointers (diff) | |
download | llvm-project-846439dd97d45e0e08af14269708511646a9add1.tar.gz llvm-project-846439dd97d45e0e08af14269708511646a9add1.tar.bz2 llvm-project-846439dd97d45e0e08af14269708511646a9add1.zip |
[Flang] Generate documentation for compiler flags
This patch aims to create a webpage to document
Flang's command line options on https://flang.llvm.org/docs/
in a similar way to Clang's
https://clang.llvm.org/docs/ClangCommandLineReference.html
This is done by using clang_tablegen to generate an .rst
file from Options.td (which is current shared with Clang)
For this to work, ClangOptionDocEmitter.cpp was updated
to allow specific Flang flags to be included,
rather than bulk excluding clang flags.
Note:
Some headings in the generated documentation will incorrectly
contain references to Clang, e.g.
"Flags controlling the behaviour of Clang during compilation"
This is because Options.td (Which is shared between both Clang and Flang)
contains hard-coded DocBrief sections. I couldn't find a non-intrusive way
to make this target-dependant, as such I've left this as is, and it will need revisiting later.
Reviewed By: awarzynski
Differential Revision: https://reviews.llvm.org/D129864
Diffstat (limited to 'clang')
-rw-r--r-- | clang/utils/TableGen/ClangOptionDocEmitter.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp b/clang/utils/TableGen/ClangOptionDocEmitter.cpp index 6c24ad2bdcc5..75f5d057c33a 100644 --- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp +++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp @@ -168,6 +168,29 @@ bool hasFlag(const Record *OptionOrGroup, StringRef OptionFlag) { return false; } +bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) { + assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags"); + for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags")) + if (hasFlag(OptionOrGroup, Inclusion)) + return true; + return false; +} + +bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) { + if (isIncluded(Group.Group, DocInfo)) + return true; + for (auto &O : Group.Options) + if (isIncluded(O.Option, DocInfo)) + return true; + for (auto &G : Group.Groups) { + if (isIncluded(G.Group, DocInfo)) + return true; + if (isGroupIncluded(G, DocInfo)) + return true; + } + return false; +} + bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) { // FIXME: Provide a flag to specify the set of exclusions. for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags")) @@ -304,6 +327,8 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo, raw_ostream &OS) { if (isExcluded(Option.Option, DocInfo)) return; + if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, DocInfo)) + return; if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" || Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT") return; @@ -379,6 +404,9 @@ void emitGroup(int Depth, const DocumentedGroup &Group, const Record *DocInfo, if (isExcluded(Group.Group, DocInfo)) return; + if (DocInfo->getValue("IncludedFlags") && !isGroupIncluded(Group, DocInfo)) + return; + emitHeading(Depth, getRSTStringWithTextFallback(Group.Group, "DocName", "Name"), OS); |