Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Warzynski <andrzej.warzynski@arm.com>2022-03-04 16:05:21 +0300
committerAndrzej Warzynski <andrzej.warzynski@arm.com>2022-04-22 12:18:04 +0300
commit2186a4aea0e3e50e51b121d304889349c4e033ef (patch)
tree60b6a8c35a23ea0eb7e6b9a5d6099c6cb0bb91ad /flang/docs
parente69c21f75b233c69d454c03d5a9d99befe7ba76e (diff)
[flang] Make the plugin API independent of the driver internals
This patch adds a few new member methods in the `PluginParseTreeAction` frontend action base class. With these new methods, the plugin API becomes independent of the driver internals. In particular, plugin writers no longer require the `CompilerInstance.h` header file to access various driver data structures (instead, they can use newly added hooks). This change is desirable as `CompilerInstance.h` includes various headers from Clang (both explicitly and implicitly). Some of these header files are generated at build time (through TableGen) and including them creates a dependency on some of Clang's build targets. However, plugins in Flang should not depend on Clang build targets. Note that plugins might still work fine most of the time, even without this change and without adding Clang build targets as dependency in plugin's CMake definition. Indeed, these Clang build targets are often generated early in the build process. However, that's not guaranteed and we did notice that on occasions plugins would fail to build. Differential Revision: https://reviews.llvm.org/D120999
Diffstat (limited to 'flang/docs')
-rw-r--r--flang/docs/FlangDriver.md35
1 files changed, 20 insertions, 15 deletions
diff --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index cf363d19714f..ec7516274106 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -395,25 +395,30 @@ to run, so in order for your plugin to do something, you will need to implement
the `ExecuteAction` method in your plugin class. This method will contain the
implementation of what the plugin actually does, for example:
```cpp
+// Forward declaration
+struct ParseTreeVisitor;
+
void ExecuteAction() override {
- auto &parseTree{instance().parsing().parseTree()};
ParseTreeVisitor visitor;
- Fortran::parser::Walk(parseTree, visitor);
+ Fortran::parser::Walk(getParsing().parseTree(), visitor);
}
```
-In the example plugin, the `ExecuteAction` method first gets a reference to the
-parse tree, `instance().parsing().parseTree()`, then declares a `visitor`
-struct, before passing both of these to the `Fortran::parser::Walk` function
-that will traverse the parse tree. Implementation and details of the `Walk`
-function can be found in `flang/include/flang/Parser/parse-tree-visitor.h`.
-
-A `visitor` struct should define different `Pre` and `Post` functions that take
-the type of a specific `ParseTree` node as an argument. When the `Walk` function
-is traversing the parse tree, these functions will be run before/after a node
-of that type is visited. Template functions for `Pre`/`Post` are defined so that
-when a node is visited that you have not defined a function for, it will still
-be able to continue. `Pre` returns a `bool` indicating whether to visit that
-node's children or not. For example:
+In the example plugin, the `ExecuteAction` method first creates an instance of
+`visitor` struct, before passing it together with the parse tree to the
+`Fortran::parser::Walk` function that will traverse the parse tree. The parse
+tree will normally be generated by the frontend driver and can be retrieved in
+your plugin through the `getParsing()` member method. Implementation and
+details of the `Walk` function can be found in
+`flang/include/flang/Parser/parse-tree-visitor.h`.
+
+You will have to define your own `visitor` struct. It should define different
+`Pre` and `Post` functions that take the type of a specific `ParseTree` node as
+an argument. When the `Walk` function is traversing the parse tree, these
+functions will be run before/after a node of that type is visited. Template
+functions for `Pre`/`Post` are defined so that when a node is visited that you
+have not defined a function for, it will still be able to continue. `Pre`
+returns a `bool` indicating whether to visit that node's children or not. For
+example:
```cpp
struct ParseTreeVisitor {
template <typename A> bool Pre(const A&) { return true; }