P4C
The P4 Compiler
Loading...
Searching...
No Matches
linesOfCodeMetric.h
1/*
2Counts the number of "real" lines of code in the compiled program
3by inserting the numbers of lines which contain code into a set,
4and retrieving it's size at the end.
5*/
6
7#ifndef FRONTENDS_P4_METRICS_LINESOFCODEMETRIC_H_
8#define FRONTENDS_P4_METRICS_LINESOFCODEMETRIC_H_
9
10#include <filesystem>
11#include <string>
12#include <unordered_set>
13
14#include "frontends/p4/metrics/metricsStructure.h"
15#include "ir/ir.h"
16
17namespace P4 {
18
19class LinesOfCodeMetricPass : public Inspector {
20 private:
21 Metrics &metrics;
22 std::string sourceFile;
23 std::unordered_set<unsigned> lines;
24
25 public:
26 explicit LinesOfCodeMetricPass(Metrics &metricsRef, std::filesystem::path sourceFile)
27 : metrics(metricsRef), sourceFile(sourceFile.stem().string()) {
28 setName("LinesOfCodeMetricPass");
29 }
30
31 void postorder(const IR::Node *node) override;
32 void postorder(const IR::P4Program * /*program*/) override;
33};
34
35} // namespace P4
36
37#endif /* FRONTENDS_P4_METRICS_LINESOFCODEMETRIC_H_ */
Definition node.h:94
Definition visitor.h:413
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition metricsStructure.h:119