P4C
The P4 Compiler
Loading...
Searching...
No Matches
psaProgramStructure.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3Copyright 2022 VMware Inc.
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16*/
17
18#ifndef BACKENDS_COMMON_PSAPROGRAMSTRUCTURE_H_
19#define BACKENDS_COMMON_PSAPROGRAMSTRUCTURE_H_
20
21#include "portableProgramStructure.h"
22
23namespace P4 {
24
25enum gress_t { INGRESS, EGRESS };
26enum block_t {
27 PARSER,
28 PIPELINE,
29 DEPARSER,
30};
31
33 public:
36
37 public:
39 : PortableProgramStructure(refMap, typeMap) {}
40
43 static bool isCounterMetadata(cstring ptName) { return !strcmp(ptName, "PSA_CounterType_t"); }
44
47 static bool isStandardMetadata(cstring ptName) {
48 return (!strcmp(ptName, "psa_ingress_parser_input_metadata_t") ||
49 !strcmp(ptName, "psa_egress_parser_input_metadata_t") ||
50 !strcmp(ptName, "psa_ingress_input_metadata_t") ||
51 !strcmp(ptName, "psa_ingress_output_metadata_t") ||
52 !strcmp(ptName, "psa_egress_input_metadata_t") ||
53 !strcmp(ptName, "psa_egress_deparser_input_metadata_t") ||
54 !strcmp(ptName, "psa_egress_output_metadata_t"));
55 }
56};
57
59 PsaProgramStructure *structure;
60
61 public:
62 explicit ParsePsaArchitecture(PsaProgramStructure *structure) : structure(structure) {
63 CHECK_NULL(structure);
64 }
65
66 void modelError(const char *format, const IR::INode *node) {
67 ::P4::error(ErrorType::ERR_MODEL,
68 (cstring(format) + "\nAre you using an up-to-date 'psa.p4'?").c_str(),
69 node->getNode());
70 }
71
72 bool preorder(const IR::PackageBlock *block) override;
73 bool preorder(const IR::ExternBlock *block) override;
74
75 profile_t init_apply(const IR::Node *root) override {
76 structure->block_type.clear();
77 structure->globals.clear();
78 return Inspector::init_apply(root);
79 }
80};
81
84
85 public:
87 : InspectPortableProgram(refMap, typeMap), pinfo(pinfo) {
88 CHECK_NULL(pinfo);
89 setName("InspectPsaProgram");
90 }
91
92 void postorder(const IR::P4Parser *p) override;
93 void postorder(const IR::P4Control *c) override;
94 void postorder(const IR::Declaration_Instance *di) override;
95
96 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
97 void addHeaderType(const IR::Type_StructLike *st);
98 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
99 bool preorder(const IR::Declaration_Variable *dv) override;
100 bool preorder(const IR::Parameter *parameter) override;
101};
102
103} // namespace P4
104
105#endif /* BACKENDS_COMMON_PSAPROGRAMSTRUCTURE_H_ */
Definition node.h:66
Definition node.h:95
Definition portableProgramStructure.h:84
Definition psaProgramStructure.h:82
Definition portableProgramStructure.h:79
Definition psaProgramStructure.h:58
Definition portableProgramStructure.h:29
Definition psaProgramStructure.h:32
static bool isCounterMetadata(cstring ptName)
Definition psaProgramStructure.h:43
ordered_map< const IR::Node *, std::pair< gress_t, block_t > > block_type
Architecture related information.
Definition psaProgramStructure.h:35
static bool isStandardMetadata(cstring ptName)
Definition psaProgramStructure.h:47
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 applyOptionsPragmas.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition error.h:51