1 //===-- examples/flang-omp-report-plugin/flang-omp-report.cpp -------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // This plugin parses a Fortran source file and generates a YAML report with
9 // all the OpenMP constructs and clauses and which line they're located on.
11 // The plugin may be invoked as:
12 // ./bin/flang -fc1 -load lib/flangOmpReport.so -plugin flang-omp-report
15 //===----------------------------------------------------------------------===//
17 #include "FlangOmpReportVisitor.h"
19 #include "flang/Frontend/FrontendActions.h"
20 #include "flang/Frontend/FrontendPluginRegistry.h"
21 #include "flang/Parser/dump-parse-tree.h"
22 #include "llvm/Support/YAMLParser.h"
23 #include "llvm/Support/YAMLTraits.h"
25 using namespace Fortran::frontend
;
26 using namespace Fortran::parser
;
28 LLVM_YAML_IS_SEQUENCE_VECTOR(LogRecord
)
29 LLVM_YAML_IS_SEQUENCE_VECTOR(ClauseInfo
)
33 using llvm::yaml::MappingTraits
;
34 template <> struct MappingTraits
<ClauseInfo
> {
35 static void mapping(IO
&io
, ClauseInfo
&info
) {
36 io
.mapRequired("clause", info
.clause
);
37 io
.mapRequired("details", info
.clauseDetails
);
40 template <> struct MappingTraits
<LogRecord
> {
41 static void mapping(IO
&io
, LogRecord
&info
) {
42 io
.mapRequired("file", info
.file
);
43 io
.mapRequired("line", info
.line
);
44 io
.mapRequired("construct", info
.construct
);
45 io
.mapRequired("clauses", info
.clauses
);
51 class FlangOmpReport
: public PluginParseTreeAction
{
52 void executeAction() override
{
53 // Prepare the parse tree and the visitor
54 Parsing
&parsing
= getParsing();
55 OpenMPCounterVisitor visitor
;
56 visitor
.parsing
= &parsing
;
58 // Walk the parse tree
59 Walk(parsing
.parseTree(), visitor
);
62 std::unique_ptr
<llvm::raw_pwrite_stream
> OS
{
63 createOutputFile(/*extension=*/"yaml")};
64 llvm::yaml::Output
yout(*OS
);
66 yout
<< visitor
.constructClauses
;
70 static FrontendPluginRegistry::Add
<FlangOmpReport
> X("flang-omp-report",
71 "Generate a YAML summary of OpenMP constructs and clauses");