P4C
The P4 Compiler
Loading...
Searching...
No Matches
bmv2/pna_nic/pnaProgramStructure.h
1/*
2Copyright 2024 Marvell Technology, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef BACKENDS_BMV2_PNA_NIC_PNAPROGRAMSTRUCTURE_H_
18#define BACKENDS_BMV2_PNA_NIC_PNAPROGRAMSTRUCTURE_H_
19
20#include "backends/common/portableProgramStructure.h"
21
23namespace P4::BMV2 {
24
25enum pna_block_t {
26 MAIN_PARSER,
27 MAIN_CONTROL,
28 MAIN_DEPARSER,
29};
30
32 public:
35
36 public:
38 : PortableProgramStructure(refMap, typeMap) {}
39
42 static bool isCounterMetadata(cstring ptName) { return !strcmp(ptName, "PNA_CounterType_t"); }
43
46 static bool isStandardMetadata(cstring ptName) {
47 return (!strcmp(ptName, "pna_main_parser_input_metadata_t") ||
48 !strcmp(ptName, "pna_main_input_metadata_t") ||
49 !strcmp(ptName, "pna_main_output_metadata_t"));
50 }
51};
52
54 PnaProgramStructure *structure;
55
56 public:
57 explicit ParsePnaArchitecture(PnaProgramStructure *structure) : structure(structure) {
58 CHECK_NULL(structure);
59 }
60
61 void modelError(const char *format, const IR::INode *node) {
62 ::P4::error(ErrorType::ERR_MODEL,
63 (cstring(format) + "\nAre you using an up-to-date 'pna.p4'?").c_str(),
64 node->getNode());
65 }
66
67 bool preorder(const IR::PackageBlock *block) override;
68 bool preorder(const IR::ExternBlock *block) override;
69
70 profile_t init_apply(const IR::Node *root) override {
71 structure->block_type.clear();
72 structure->globals.clear();
73 return Inspector::init_apply(root);
74 }
75};
76
79
80 public:
82 : InspectPortableProgram(refMap, typeMap), pinfo(pinfo) {
83 CHECK_NULL(pinfo);
84 setName("InspectPnaProgram");
85 }
86
87 void postorder(const IR::P4Parser *p) override;
88 void postorder(const IR::P4Control *c) override;
89 void postorder(const IR::Declaration_Instance *di) override;
90
91 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
92 void addHeaderType(const IR::Type_StructLike *st);
93 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
94 bool preorder(const IR::Declaration_Variable *dv) override;
95 bool preorder(const IR::Parameter *parameter) override;
96};
97
98} // namespace P4::BMV2
99
100#endif /* BACKENDS_BMV2_PNA_NIC_PNAPROGRAMSTRUCTURE_H_ */
Definition bmv2/pna_nic/pnaProgramStructure.h:77
Definition bmv2/pna_nic/pnaProgramStructure.h:53
Definition bmv2/pna_nic/pnaProgramStructure.h:31
ordered_map< const IR::Node *, pna_block_t > block_type
Architecture related information.
Definition bmv2/pna_nic/pnaProgramStructure.h:34
static bool isStandardMetadata(cstring ptName)
Definition bmv2/pna_nic/pnaProgramStructure.h:46
static bool isCounterMetadata(cstring ptName)
Definition bmv2/pna_nic/pnaProgramStructure.h:42
Definition node.h:66
Definition node.h:95
Definition portableProgramStructure.h:84
Definition portableProgramStructure.h:79
Definition portableProgramStructure.h:29
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:41
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51