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"
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>();
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>();
68 auto *orig = getOriginal<T>();
69 if (structure->_map.count(orig)) {
70 auto result = structure->_map.at(orig);
78 CHECK_NULL(structure);
81 const IR::Node *postorder(IR::Declaration_Instance *node) {
82 return substitute<IR::Declaration_Instance>(node);
85 const IR::Node *postorder(IR::MethodCallStatement *node) {
86 return substitute<IR::MethodCallStatement>(node);
89 const IR::Node *postorder(IR::Property *node) {
return substitute<IR::Property>(node); }
91 const IR::Node *postorder(IR::BFN::TnaControl *node)
override;
93 const IR::P4Control *convert(
const IR::Node *node) {
94 auto conv = node->apply(*
this);
95 auto result = conv->
to<IR::P4Control>();
96 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce a control", node);
104 CHECK_NULL(structure);
106 const IR::Node *preorder(IR::P4Control *node)
override;
112 CHECK_NULL(structure);
120 CHECK_NULL(structure);
122 const IR::Node *preorder(IR::P4Control *node)
override;
128 CHECK_NULL(structure);
139 template <
typename T>
141 auto *orig = getOriginal<T>();
142 if (structure->_map.count(orig)) {
143 auto result = structure->_map.at(orig);
151 CHECK_NULL(structure);
154 const IR::Node *postorder(IR::AssignmentStatement *node) {
155 return substitute<IR::AssignmentStatement>(node);
158 const IR::Node *postorder(IR::SelectExpression *node) {
159 return substitute<IR::SelectExpression>(node);
162 const IR::Node *postorder(IR::Member *node) {
return substitute<IR::Member>(node); }
164 const IR::P4Parser *convert(
const IR::Node *node) {
165 auto conv = node->apply(*
this);
166 auto result = conv->
to<IR::P4Parser>();
167 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce a parser", node);
175 CHECK_NULL(structure);
177 const IR::Node *postorder(IR::P4Parser *node)
override;
183 CHECK_NULL(structure);
185 const IR::Node *postorder(IR::Declaration_Variable *node)
override;
186 const IR::Node *postorder(IR::P4Parser *node)
override;
197 CHECK_NULL(structure);
199 const IR::Node *postorder(IR::Member *node)
override;
200 const IR::Declaration_Instance *convertExternInstance(
const IR::Node *node) {
201 auto conv = node->apply(*
this);
202 auto result = conv->
to<IR::Declaration_Instance>();
203 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce an extern instance", node);
206 const IR::MethodCallExpression *convertExternCall(
const IR::Node *node) {
207 auto conv = node->apply(*
this);
208 auto result = conv->
to<IR::MethodCallExpression>();
209 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce an extern method call",
214 const IR::Statement *convertExternFunction(
const IR::Node *node) {
215 auto conv = node->apply(*
this);
216 auto result = conv->
to<IR::Statement>();
217 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce an extern method call",
223 auto conv = node->apply(*
this);
235 CHECK_NULL(structure);
237 const IR::Node *postorder(IR::MethodCallStatement *node)
override;
238 const IR::Expression *cast_if_needed(
const IR::Expression *expr,
int srcWidth,
int dstWidth);
244 CHECK_NULL(structure);
246 const IR::Node *postorder(IR::MethodCallStatement *node)
override;
254 {
"HashAlgorithm"_cs,
"HashAlgorithm_t"_cs},
255 {
"CounterType"_cs,
"CounterType_t"_cs},
256 {
"MeterType"_cs,
"MeterType_t"_cs},
257 {
"CloneType"_cs,
nullptr},
260 {
"crc16"_cs,
"CRC16"_cs},
261 {
"csum16"_cs,
"CSUM16"_cs},
262 {
"packets"_cs,
"PACKETS"_cs},
263 {
"bytes"_cs,
"BYTES"_cs},
264 {
"packets_and_bytes"_cs,
"PACKETS_AND_BYTES"_cs},
265 {
"crc32"_cs,
"CRC32"_cs},
266 {
"identity"_cs,
"IDENTITY"_cs},
267 {
"random"_cs,
"RANDOM"_cs}};
272 CHECK_NULL(structure);
274 const IR::Node *postorder(IR::Type_Name *node)
override;
275 const IR::Node *postorder(IR::TypeNameExpression *node)
override;
276 const IR::Node *postorder(IR::Member *node)
override;
282 CHECK_NULL(structure);
293 CHECK_NULL(structure);
295 const IR::Node *postorder(IR::AssignmentStatement *node)
override;
Definition v1_converters.h:62
Definition v1_converters.h:109
const IR::Node * preorder(IR::P4Control *node) override
Definition v1_converters.cpp:150
Definition v1_converters.h:125
const IR::Node * preorder(IR::P4Control *node) override
Definition v1_converters.cpp:303
Definition v1_converters.h:180
Definition v1_converters.h:34
Definition v1_converters.h:191
Definition v1_converters.h:101
Definition v1_converters.h:117
Definition v1_converters.h:172
Definition v1_converters.h:228
Definition v1_converters.h:135
Definition v1_converters.h:290
Definition v1_converters.h:279
const IR::Node * postorder(IR::Member *node) override
map path expression
Definition v1_converters.cpp:575
Definition v1_converters.h:241
Definition v1_converters.h:48
Definition v1_converters.h:251
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