19#ifndef BF_P4C_ARCH_FROMV1_0_V1_CONVERTERS_H_
20#define BF_P4C_ARCH_FROMV1_0_V1_CONVERTERS_H_
24#include "frontends/p4/cloner.h"
25#include "frontends/p4/coreLibrary.h"
27#include "lib/safe_vector.h"
28#include "v1_program_structure.h"
34class ExpressionConverter :
public Transform {
39 explicit ExpressionConverter(
ProgramStructure *structure) : structure(structure) {
40 CHECK_NULL(structure);
42 const IR::Expression *convert(
const IR::Node *node) {
43 auto result = node->apply(*
this);
44 return result->
to<IR::Expression>();
48class StatementConverter :
public Transform {
53 explicit StatementConverter(
ProgramStructure *structure) : structure(structure) {
54 CHECK_NULL(structure);
56 const IR::Statement *convert(
const IR::Node *node) {
57 auto result = node->apply(*
this);
58 return result->
to<IR::Statement>();
62class ControlConverter :
public Transform {
68 auto *orig = getOriginal<T>();
69 if (structure->_map.count(orig)) {
70 auto result = structure->_map.at(orig);
77 explicit ControlConverter(
ProgramStructure *structure) : structure(structure) {
78 CHECK_NULL(structure);
81 const IR::Node *postorder(IR::Declaration_Instance *node)
override {
82 return substitute<IR::Declaration_Instance>(node);
85 const IR::Node *postorder(IR::MethodCallStatement *node)
override {
86 return substitute<IR::MethodCallStatement>(node);
89 const IR::Node *postorder(IR::Property *node)
override {
90 return substitute<IR::Property>(node);
93 const IR::Node *postorder(IR::BFN::TnaControl *node)
override;
95 const IR::P4Control *convert(
const IR::Node *node) {
96 auto conv = node->apply(*
this);
97 auto result = conv->
to<IR::P4Control>();
98 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce a control", node);
103class IngressControlConverter :
public ControlConverter {
105 explicit IngressControlConverter(
ProgramStructure *structure) : ControlConverter(structure) {
106 CHECK_NULL(structure);
108 const IR::Node *preorder(IR::P4Control *node)
override;
111class EgressControlConverter :
public ControlConverter {
113 explicit EgressControlConverter(
ProgramStructure *structure) : ControlConverter(structure) {
114 CHECK_NULL(structure);
119class IngressDeparserConverter :
public ControlConverter {
121 explicit IngressDeparserConverter(
ProgramStructure *structure) : ControlConverter(structure) {
122 CHECK_NULL(structure);
124 const IR::Node *preorder(IR::P4Control *node)
override;
127class EgressDeparserConverter :
public ControlConverter {
129 explicit EgressDeparserConverter(
ProgramStructure *structure) : ControlConverter(structure) {
130 CHECK_NULL(structure);
137class ParserConverter :
public Transform {
141 template <
typename T>
143 auto *orig = getOriginal<T>();
144 if (structure->_map.count(orig)) {
145 auto result = structure->_map.at(orig);
152 explicit ParserConverter(
ProgramStructure *structure) : structure(structure) {
153 CHECK_NULL(structure);
156 const IR::Node *postorder(IR::AssignmentStatement *node) {
157 return substitute<IR::AssignmentStatement>(node);
160 const IR::Node *postorder(IR::SelectExpression *node) {
161 return substitute<IR::SelectExpression>(node);
164 const IR::Node *postorder(IR::Member *node) {
return substitute<IR::Member>(node); }
166 const IR::P4Parser *convert(
const IR::Node *node) {
167 auto conv = node->apply(*
this);
168 auto result = conv->
to<IR::P4Parser>();
169 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce a parser", node);
174class IngressParserConverter :
public ParserConverter {
176 explicit IngressParserConverter(
ProgramStructure *structure) : ParserConverter(structure) {
177 CHECK_NULL(structure);
179 const IR::Node *postorder(IR::P4Parser *node)
override;
182class EgressParserConverter :
public ParserConverter {
184 explicit EgressParserConverter(
ProgramStructure *structure) : ParserConverter(structure) {
185 CHECK_NULL(structure);
187 const IR::Node *postorder(IR::Declaration_Variable *node)
override;
188 const IR::Node *postorder(IR::P4Parser *node)
override;
193class ExternConverter :
public Transform {
198 explicit ExternConverter(
ProgramStructure *structure) : structure(structure) {
199 CHECK_NULL(structure);
201 const IR::Node *postorder(IR::Member *node)
override;
202 const IR::Declaration_Instance *convertExternInstance(
const IR::Node *node) {
203 auto conv = node->apply(*
this);
204 auto result = conv->
to<IR::Declaration_Instance>();
205 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce an extern instance", node);
208 const IR::MethodCallExpression *convertExternCall(
const IR::Node *node) {
209 auto conv = node->apply(*
this);
210 auto result = conv->
to<IR::MethodCallExpression>();
211 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce an extern method call",
216 const IR::Statement *convertExternFunction(
const IR::Node *node) {
217 auto conv = node->apply(*
this);
218 auto result = conv->
to<IR::Statement>();
219 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce an extern method call",
225 auto conv = node->apply(*
this);
230class MeterConverter :
public ExternConverter {
236 : ExternConverter(structure), refMap(rm), direct(direct) {
237 CHECK_NULL(structure);
239 const IR::Node *postorder(IR::MethodCallStatement *node)
override;
240 const IR::Expression *cast_if_needed(
const IR::Expression *expr,
int srcWidth,
int dstWidth);
243class RegisterConverter :
public ExternConverter {
245 explicit RegisterConverter(
ProgramStructure *structure) : ExternConverter(structure) {
246 CHECK_NULL(structure);
248 const IR::Node *postorder(IR::MethodCallStatement *node)
override;
253class TypeNameExpressionConverter :
public ExpressionConverter {
256 {
"HashAlgorithm"_cs,
"HashAlgorithm_t"_cs},
257 {
"CounterType"_cs,
"CounterType_t"_cs},
258 {
"MeterType"_cs,
"MeterType_t"_cs},
259 {
"CloneType"_cs,
nullptr},
262 {
"crc16"_cs,
"CRC16"_cs},
263 {
"csum16"_cs,
"CSUM16"_cs},
264 {
"packets"_cs,
"PACKETS"_cs},
265 {
"bytes"_cs,
"BYTES"_cs},
266 {
"packets_and_bytes"_cs,
"PACKETS_AND_BYTES"_cs},
267 {
"crc32"_cs,
"CRC32"_cs},
268 {
"identity"_cs,
"IDENTITY"_cs},
269 {
"random"_cs,
"RANDOM"_cs}};
273 : ExpressionConverter(structure) {
274 CHECK_NULL(structure);
276 const IR::Node *postorder(IR::Type_Name *node)
override;
277 const IR::Node *postorder(IR::TypeNameExpression *node)
override;
278 const IR::Node *postorder(IR::Member *node)
override;
281class PathExpressionConverter :
public ExpressionConverter {
283 explicit PathExpressionConverter(
ProgramStructure *structure) : ExpressionConverter(structure) {
284 CHECK_NULL(structure);
292class ParserPriorityConverter :
public StatementConverter {
294 explicit ParserPriorityConverter(
ProgramStructure *structure) : StatementConverter(structure) {
295 CHECK_NULL(structure);
297 const IR::Node *postorder(IR::AssignmentStatement *node)
override;
const IR::Node * preorder(IR::P4Control *node) override
Definition v1_converters.cpp:151
const IR::Node * preorder(IR::P4Control *node) override
Definition v1_converters.cpp:304
const IR::Node * postorder(IR::Member *node) override
map path expression
Definition v1_converters.cpp:576
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition ordered_map.h:32
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Definition v1_program_structure.h:36
T * to() noexcept
Definition rtti.h:226