17#ifndef BACKENDS_TC_PNAPROGRAMSTRUCTURE_H_
18#define BACKENDS_TC_PNAPROGRAMSTRUCTURE_H_
20#include "backends/common/programStructure.h"
21#include "frontends/common/resolveReferences/referenceMap.h"
22#include "frontends/p4/typeMap.h"
24#include "lib/cstring.h"
43 unsigned scalars_width = 0;
44 unsigned error_width = 32;
45 unsigned bool_width = 1;
66 std::vector<const IR::ExternBlock *> globals;
70 : refMap(refMap), typeMap(typeMap) {
75 std::set<cstring> non_pipeline_controls;
76 std::set<cstring> pipeline_controls;
78 bool hasVisited(
const IR::Type_StructLike *st) {
79 if (
auto h = st->to<IR::Type_Header>())
80 return header_types.count(h->getName());
81 else if (
auto s = st->to<IR::Type_Struct>())
82 return metadata_types.count(s->getName());
83 else if (
auto u = st->to<IR::Type_HeaderUnion>())
84 return header_union_types.count(u->getName());
99 return ptName ==
"pna_main_parser_input_metadata_t" ||
100 ptName ==
"pna_main_input_metadata_t" || ptName ==
"pna_main_output_metadata_t";
109 CHECK_NULL(structure);
112 void modelError(
const char *format,
const IR::INode *node) {
114 (
cstring(format) +
"\nAre you using an up-to-date 'pna.p4'?").c_str(),
118 bool preorder(
const IR::ToplevelBlock *block)
override;
119 bool preorder(
const IR::PackageBlock *block)
override;
120 bool preorder(
const IR::ExternBlock *block)
override;
123 structure->block_type.clear();
124 structure->globals.clear();
125 return Inspector::init_apply(root);
136 : refMap(refMap), typeMap(typeMap), pinfo(pinfo) {
140 setName(
"InspectPnaProgram");
143 void postorder(
const IR::P4Parser *p)
override;
144 void postorder(
const IR::P4Control *c)
override;
145 void postorder(
const IR::Declaration_Instance *di)
override;
147 bool isHeaders(
const IR::Type_StructLike *st);
148 void addTypesAndInstances(
const IR::Type_StructLike *type,
bool meta);
149 void addHeaderType(
const IR::Type_StructLike *st);
150 void addHeaderInstance(
const IR::Type_StructLike *st,
cstring name);
151 bool preorder(
const IR::Declaration_Variable *dv)
override;
152 bool preorder(
const IR::Parameter *parameter)
override;
Definition backends/common/programStructure.h:32
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition tc/pnaProgramStructure.h:129
Definition tc/pnaProgramStructure.h:104
bool preorder(const IR::ToplevelBlock *block) override
Definition tc/pnaProgramStructure.cpp:221
Definition tc/pnaProgramStructure.h:34
static bool isStandardMetadata(cstring ptName)
Definition tc/pnaProgramStructure.h:98
static bool isCounterMetadata(cstring ptName)
Definition tc/pnaProgramStructure.h:92
Definition ordered_map.h:32
This file defines functions for the pass to generate the introspection file.
Definition tc/backend.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51