P4C
The P4 Compiler
Loading...
Searching...
No Matches
externalObjectsMetric.h
1/*
2Counts the number of external structure and function declarations
3and uses. When encountering an extern structure declaration, its
4method names are collected into "externFunctions". Encountering
5an extern method is counted as an extern structure use and as an extern
6function call too.
7*/
8
9#ifndef FRONTENDS_P4_METRICS_EXTERNALOBJECTSMETRIC_H_
10#define FRONTENDS_P4_METRICS_EXTERNALOBJECTSMETRIC_H_
11
12#include <set>
13
14#include "frontends/p4/metrics/metricsStructure.h"
15#include "ir/ir.h"
16
17namespace P4 {
18
19class ExternalObjectsMetricPass : public Inspector {
20 private:
21 ExternMetrics &metrics;
22 std::set<cstring> externFunctions; // Standalone extern functions.
23 std::set<cstring> externTypeNames; // Type names of extern structures.
24 std::map<cstring, std::set<cstring>> externMethods; // Tracks methods per extern.
25
26 public:
27 explicit ExternalObjectsMetricPass(Metrics &metricsRef) : metrics(metricsRef.externMetrics) {
28 setName("ExternalObjectsMetricPass");
29 }
30
32 void postorder(const IR::Type_Extern *node) override;
34 void postorder(const IR::Declaration_Instance *node) override;
36 void postorder(const IR::Member *node) override;
38 void postorder(const IR::Method *node) override;
40 void postorder(const IR::MethodCallExpression *node) override;
42 void postorder(const IR::P4Program * /*node*/) override;
43};
44
45} // namespace P4
46
47#endif /* FRONTENDS_P4_METRICS_EXTERNALOBJECTSMETRIC_H_ */
void postorder(const IR::Type_Extern *node) override
Extern structure declaration.
Definition externalObjectsMetric.cpp:5
Definition visitor.h:413
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition metricsStructure.h:53
Definition metricsStructure.h:119