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 ptName == "PNA_CounterType_t"; }
43
46 static bool isStandardMetadata(cstring ptName) {
47 return ptName == "pna_main_parser_input_metadata_t" ||
48 ptName == "pna_main_input_metadata_t" || ptName == "pna_main_output_metadata_t";
49 }
50};
51
53 PnaProgramStructure *structure;
54
55 public:
56 explicit ParsePnaArchitecture(PnaProgramStructure *structure) : structure(structure) {
57 CHECK_NULL(structure);
58 }
59
60 void modelError(const char *format, const IR::INode *node) {
61 ::P4::error(ErrorType::ERR_MODEL,
62 (cstring(format) + "\nAre you using an up-to-date 'pna.p4'?").c_str(),
63 node->getNode());
64 }
65
66 bool preorder(const IR::PackageBlock *block) override;
67 bool preorder(const IR::ExternBlock *block) override;
68
69 profile_t init_apply(const IR::Node *root) override {
70 structure->block_type.clear();
71 structure->globals.clear();
72 return Inspector::init_apply(root);
73 }
74};
75
78
79 public:
81 : InspectPortableProgram(refMap, typeMap), pinfo(pinfo) {
82 CHECK_NULL(pinfo);
83 setName("InspectPnaProgram");
84 }
85
86 void postorder(const IR::P4Parser *p) override;
87 void postorder(const IR::P4Control *c) override;
88 void postorder(const IR::Declaration_Instance *di) override;
89
90 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
91 void addHeaderType(const IR::Type_StructLike *st);
92 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
93 bool preorder(const IR::Declaration_Variable *dv) override;
94 bool preorder(const IR::Parameter *parameter) override;
95};
96
97} // namespace P4::BMV2
98
99#endif /* BACKENDS_BMV2_PNA_NIC_PNAPROGRAMSTRUCTURE_H_ */
Definition bmv2/pna_nic/pnaProgramStructure.h:76
Definition bmv2/pna_nic/pnaProgramStructure.h:52
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:94
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