Skip to content

Commit

Permalink
Add ProgramStmt handler, print Program name
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaimov committed Dec 5, 2024
1 parent 6d3736a commit 205ace6
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/salt_instrument_flang_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,45 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

/* SALT-FM Flang Fortran Instrumentor Plugin */

#include "flang/Frontend/FrontendActions.h"
#include "flang/Frontend/FrontendPluginRegistry.h"
#include "flang/Parser/dump-parse-tree.h"
#include "flang/Parser/parsing.h"

using namespace Fortran::frontend;

/**
* The main action of the Salt instrumentor.
* Visits each node in the parse tree.
*/
class SaltInstrumentAction : public PluginParseTreeAction {

// Visitor struct that defines Pre/Post functions for different types of nodes
struct SaltInstrumentParseTreeVisitor {
// Default empty visit functions for otherwise unhandled types.
template <typename A> bool Pre(const A &) { return true; }
template <typename A> void Post(const A &) {}

// Override all types that we want to visit.
// Pre occurs when first visiting a node.
// Post occurs when returning from the node's children.
// See https://flang.llvm.org/docs/Parsing.html for information on the parse tree.
// There are three types of parse tree nodes:
// Wrappers, with a single data member, always named `v`.
// Tuples, encapsulating multiple values in a data member named `t` of type std::tuple.
// Discriminated unions, one of several types stored in data member named `u` of type std::variant.
// Use std::get() to retrieve value from `t` or `u`

bool Pre(const Fortran::parser::FunctionSubprogram &) {
isInSubprogram_ = true;
return true;
}

void Post(const Fortran::parser::ProgramStmt & program) {
llvm::outs() << "Program: \t"
<< program.v.ToString() << "\n";
}

void Post(const Fortran::parser::FunctionStmt &f) {
if (isInSubprogram_) {
llvm::outs() << "Function:\t"
Expand Down

0 comments on commit 205ace6

Please sign in to comment.