17#ifndef BACKENDS_COMMON_PROGRAMSTRUCTURE_H_
18#define BACKENDS_COMMON_PROGRAMSTRUCTURE_H_
20#include "backends/common/metermap.h"
22#include "ir/visitor.h"
23#include "lib/ordered_map.h"
24#include "lib/ordered_set.h"
28using ResourceMap = ordered_map<const IR::Node *, const IR::CompileTimeValue *>;
44 std::vector<const IR::Declaration_Variable *>
variables;
68 setName(
"DiscoverStructure");
70 void postorder(
const IR::ParameterList *paramList)
override;
71 void postorder(
const IR::P4Action *action)
override;
72 void postorder(
const IR::Declaration_Variable *decl)
override;
73 void postorder(
const IR::Type_Error *errors)
override;
74 void postorder(
const IR::Declaration_MatchKind *kind)
override;
86 CHECK_NULL(resourceMap);
89 bool preorder(
const IR::ControlBlock *control)
override {
90 resourceMap->emplace(control->container, control);
91 for (
auto cv : control->constantValue) {
92 resourceMap->emplace(cv.first, cv.second);
95 for (
const auto *c : control->container->controlLocals) {
96 if (c->is<IR::InstantiatedBlock>()) {
97 resourceMap->emplace(c, control->getValue(c));
103 bool preorder(
const IR::ParserBlock *parser)
override {
104 resourceMap->emplace(parser->container, parser);
105 for (
auto cv : parser->constantValue) {
106 resourceMap->emplace(cv.first, cv.second);
107 if (cv.second->is<IR::Block>()) {
108 visit(cv.second->getNode());
112 for (
const auto *c : parser->container->parserLocals) {
113 if (c->is<IR::InstantiatedBlock>()) {
114 resourceMap->emplace(c, parser->getValue(c));
120 bool preorder(
const IR::TableBlock *table)
override {
121 resourceMap->emplace(table->container, table);
122 for (
auto cv : table->constantValue) {
123 resourceMap->emplace(cv.first, cv.second);
124 if (cv.second->is<IR::Block>()) {
125 visit(cv.second->getNode());
131 bool preorder(
const IR::PackageBlock *package)
override {
132 for (
auto cv : package->constantValue) {
133 if (cv.second->is<IR::Block>()) {
134 visit(cv.second->getNode());
140 bool preorder(
const IR::ToplevelBlock *tlb)
override {
141 const auto *
package = tlb->getMain();
Definition backends/common/programStructure.h:81
Definition backends/common/programStructure.h:63
Definition backends/common/programStructure.h:32
ordered_map< cstring, const IR::P4Table * > directCounterMap
All the direct counters. (TODO: This should be PSA-specific or V1MODEL-specific.)
Definition backends/common/programStructure.h:50
ordered_map< const IR::Parameter *, unsigned > index
Definition backends/common/programStructure.h:38
std::set< cstring > match_kinds
All match kinds.
Definition backends/common/programStructure.h:56
ordered_set< const IR::Parameter * > nonActionParameters
Parameters of controls/parsers.
Definition backends/common/programStructure.h:40
DirectMeterMap directMeterMap
All the direct meters. (TODO: This should be PSA-specific or V1MODEL-specific.)
Definition backends/common/programStructure.h:48
ordered_map< const IR::IDeclaration *, unsigned int > errorCodesMap
All error codes.
Definition backends/common/programStructure.h:46
std::vector< const IR::Declaration_Variable * > variables
All local variables.
Definition backends/common/programStructure.h:44
ResourceMap resourceMap
map IR node to compile-time allocated resource blocks.
Definition backends/common/programStructure.h:58
ordered_map< const IR::P4Action *, const IR::P4Control * > actions
Map action to parent control.
Definition backends/common/programStructure.h:35
std::map< const IR::StructField *, cstring > scalarMetadataFields
Definition backends/common/programStructure.h:54
ordered_map< const IR::P4Action *, unsigned > ids
For each action its json id.
Definition backends/common/programStructure.h:42
Definition ordered_map.h:32
Definition ordered_set.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24