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 psa_gress_t {
26 INGRESS,
27 EGRESS,
28};
29
30enum block_t {
31 PARSER,
32 PIPELINE,
33 DEPARSER,
34};
35
37 public:
40
41 public:
43 : PortableProgramStructure(refMap, typeMap) {}
44
47 static bool isCounterMetadata(cstring ptName) { return !strcmp(ptName, "PSA_CounterType_t"); }
48
51 static bool isStandardMetadata(cstring ptName) {
52 return (!strcmp(ptName, "psa_ingress_parser_input_metadata_t") ||
53 !strcmp(ptName, "psa_egress_parser_input_metadata_t") ||
54 !strcmp(ptName, "psa_ingress_input_metadata_t") ||
55 !strcmp(ptName, "psa_ingress_output_metadata_t") ||
56 !strcmp(ptName, "psa_egress_input_metadata_t") ||
57 !strcmp(ptName, "psa_egress_deparser_input_metadata_t") ||
58 !strcmp(ptName, "psa_egress_output_metadata_t"));
59 }
60};
61
63 PsaProgramStructure *structure;
64
65 public:
66 explicit ParsePsaArchitecture(PsaProgramStructure *structure) : structure(structure) {
67 CHECK_NULL(structure);
68 }
69
70 void modelError(const char *format, const IR::INode *node) {
71 ::P4::error(ErrorType::ERR_MODEL,
72 (cstring(format) + "\nAre you using an up-to-date 'psa.p4'?").c_str(),
73 node->getNode());
74 }
75
76 bool preorder(const IR::PackageBlock *block) override;
77 bool preorder(const IR::ExternBlock *block) override;
78
79 profile_t init_apply(const IR::Node *root) override {
80 structure->block_type.clear();
81 structure->globals.clear();
82 return Inspector::init_apply(root);
83 }
84};
85
88
89 public:
91 : InspectPortableProgram(refMap, typeMap), pinfo(pinfo) {
92 CHECK_NULL(pinfo);
93 setName("InspectPsaProgram");
94 }
95
96 void postorder(const IR::P4Parser *p) override;
97 void postorder(const IR::P4Control *c) override;
98 void postorder(const IR::Declaration_Instance *di) override;
99
100 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
101 void addHeaderType(const IR::Type_StructLike *st);
102 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
103 bool preorder(const IR::Declaration_Variable *dv) override;
104 bool preorder(const IR::Parameter *parameter) override;
105};
106
107} // namespace P4
108
109#endif /* BACKENDS_COMMON_PSAPROGRAMSTRUCTURE_H_ */
Definition node.h:66
Definition node.h:95
Definition portableProgramStructure.h:84
Definition psaProgramStructure.h:86
Definition portableProgramStructure.h:79
Definition psaProgramStructure.h:62
Definition portableProgramStructure.h:29
Definition psaProgramStructure.h:36
static bool isCounterMetadata(cstring ptName)
Definition psaProgramStructure.h:47
ordered_map< const IR::Node *, std::pair< psa_gress_t, block_t > > block_type
Architecture related information.
Definition psaProgramStructure.h:39
static bool isStandardMetadata(cstring ptName)
Definition psaProgramStructure.h:51
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 lib/error.h:51