8#ifndef BACKENDS_TC_PNAPROGRAMSTRUCTURE_H_
9#define BACKENDS_TC_PNAPROGRAMSTRUCTURE_H_
11#include "backends/common/programStructure.h"
12#include "frontends/common/resolveReferences/referenceMap.h"
13#include "frontends/p4/typeMap.h"
15#include "lib/cstring.h"
34 unsigned scalars_width = 0;
35 unsigned error_width = 32;
36 unsigned bool_width = 1;
57 std::vector<const IR::ExternBlock *> globals;
61 : refMap(refMap), typeMap(typeMap) {
66 std::set<cstring> non_pipeline_controls;
67 std::set<cstring> pipeline_controls;
69 bool hasVisited(
const IR::Type_StructLike *st) {
70 if (
auto h = st->to<IR::Type_Header>())
71 return header_types.count(h->getName());
72 else if (
auto s = st->to<IR::Type_Struct>())
73 return metadata_types.count(s->getName());
74 else if (
auto u = st->to<IR::Type_HeaderUnion>())
75 return header_union_types.count(u->getName());
90 return ptName ==
"pna_main_parser_input_metadata_t" ||
91 ptName ==
"pna_main_input_metadata_t" || ptName ==
"pna_main_output_metadata_t";
95class ParsePnaArchitecture :
public Inspector {
100 CHECK_NULL(structure);
103 void modelError(
const char *format,
const IR::INode *node) {
105 (
cstring(format) +
"\nAre you using an up-to-date 'pna.p4'?").c_str(),
109 bool preorder(
const IR::ToplevelBlock *block)
override;
110 bool preorder(
const IR::PackageBlock *block)
override;
111 bool preorder(
const IR::ExternBlock *block)
override;
114 structure->block_type.clear();
115 structure->globals.clear();
116 return Inspector::init_apply(root);
120class InspectPnaProgram :
public Inspector {
127 : refMap(refMap), typeMap(typeMap), pinfo(pinfo) {
131 setName(
"InspectPnaProgram");
134 void postorder(
const IR::P4Parser *p)
override;
135 void postorder(
const IR::P4Control *c)
override;
136 void postorder(
const IR::Declaration_Instance *di)
override;
138 bool isHeaders(
const IR::Type_StructLike *st);
139 void addTypesAndInstances(
const IR::Type_StructLike *type,
bool meta);
140 void addHeaderType(
const IR::Type_StructLike *st);
141 void addHeaderInstance(
const IR::Type_StructLike *st,
cstring name);
142 bool preorder(
const IR::Declaration_Variable *dv)
override;
143 bool preorder(
const IR::Parameter *parameter)
override;
Definition backends/common/programStructure.h:23
Class used to encode maps from paths to declarations.
Definition referenceMap.h:67
bool preorder(const IR::ToplevelBlock *block) override
Definition tc/pnaProgramStructure.cpp:210
Definition tc/pnaProgramStructure.h:25
static bool isStandardMetadata(cstring ptName)
Definition tc/pnaProgramStructure.h:89
static bool isCounterMetadata(cstring ptName)
Definition tc/pnaProgramStructure.h:83
Definition ordered_map.h:32
This file defines functions for the pass to generate the introspection file.
Definition tc/backend.cpp:17
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58