19#ifndef BACKENDS_TOFINO_BF_P4C_ARCH_PSA_PSA_CONVERTERS_H_
20#define BACKENDS_TOFINO_BF_P4C_ARCH_PSA_PSA_CONVERTERS_H_
24#include "frontends/p4/cloner.h"
25#include "frontends/p4/coreLibrary.h"
27#include "lib/safe_vector.h"
28#include "programStructure.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 ExternConverter :
public Transform {
67 explicit ExternConverter(
ProgramStructure *structure) : structure(structure) {
68 CHECK_NULL(structure);
71 auto conv = node->apply(*
this);
76class HashConverter :
public ExternConverter {
78 explicit HashConverter(
ProgramStructure *structure) : ExternConverter(structure) {
79 CHECK_NULL(structure);
81 const IR::Node *postorder(IR::MethodCallExpression *node)
override;
84class RandomConverter :
public ExternConverter {
86 explicit RandomConverter(
ProgramStructure *structure) : ExternConverter(structure) {
87 CHECK_NULL(structure);
89 const IR::Node *postorder(IR::MethodCallExpression *node)
override;
92class MeterConverter :
public ExternConverter {
94 explicit MeterConverter(
ProgramStructure *structure) : ExternConverter(structure) {
95 CHECK_NULL(structure);
97 const IR::Node *postorder(IR::MethodCallExpression *node)
override;
100class ParserConverter :
public Transform {
104 template <
typename T>
106 auto *orig = getOriginal<T>();
107 if (structure->_map.count(orig)) {
108 auto result = structure->_map.at(orig);
115 explicit ParserConverter(
ProgramStructure *structure) : structure(structure) {
116 CHECK_NULL(structure);
118 const IR::Node *postorder(IR::Declaration_Instance *decl)
override;
119 const IR::Node *postorder(IR::StatOrDecl *node)
override;
120 const IR::Node *postorder(IR::MethodCallExpression *node)
override;
121 const IR::P4Parser *convert(
const IR::Node *node) {
122 auto conv = node->apply(*
this);
123 auto result = conv->
to<IR::P4Parser>();
124 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce a parser", node);
129class IngressParserConverter :
public ParserConverter {
131 explicit IngressParserConverter(
ProgramStructure *structure) : ParserConverter(structure) {
132 CHECK_NULL(structure);
134 const IR::Node *postorder(IR::P4Parser *node)
override;
137class EgressParserConverter :
public ParserConverter {
139 explicit EgressParserConverter(
ProgramStructure *structure) : ParserConverter(structure) {
140 CHECK_NULL(structure);
145class ControlConverter :
public Transform {
149 template <
typename T>
151 auto *orig = getOriginal<T>();
152 if (structure->_map.count(orig)) {
153 auto result = structure->_map.at(orig);
160 explicit ControlConverter(
ProgramStructure *structure) : structure(structure) {
161 CHECK_NULL(structure);
163 const IR::Node *postorder(IR::MethodCallExpression *node)
override;
164 const IR::Node *postorder(IR::Declaration_Instance *node)
override;
165 const IR::Node *postorder(IR::IfStatement *node)
override;
166 const IR::Node *postorder(IR::StatOrDecl *node)
override;
167 const IR::Node *postorder(IR::Property *node)
override;
168 const IR::Node *postorder(IR::Member *node)
override;
169 const IR::P4Control *convert(
const IR::Node *node) {
170 auto conv = node->apply(*
this);
171 auto result = conv->
to<IR::P4Control>();
172 BUG_CHECK(result !=
nullptr,
"Conversion of %1% did not produce a control", node);
177class IngressControlConverter :
public ControlConverter {
179 explicit IngressControlConverter(
ProgramStructure *structure) : ControlConverter(structure) {
180 CHECK_NULL(structure);
182 const IR::Node *postorder(IR::P4Control *node)
override;
185class EgressControlConverter :
public ControlConverter {
187 explicit EgressControlConverter(
ProgramStructure *structure) : ControlConverter(structure) {
188 CHECK_NULL(structure);
193class IngressDeparserConverter :
public ControlConverter {
195 explicit IngressDeparserConverter(
ProgramStructure *structure) : ControlConverter(structure) {
196 CHECK_NULL(structure);
198 const IR::Node *postorder(IR::P4Control *node)
override;
201class EgressDeparserConverter :
public ControlConverter {
203 explicit EgressDeparserConverter(
ProgramStructure *structure) : ControlConverter(structure) {
204 CHECK_NULL(structure);
206 const IR::Node *postorder(IR::P4Control *node)
override;
209class TypeNameExpressionConverter :
public ExpressionConverter {
212 {
"PSA_HashAlgorithm_t"_cs, std::make_pair(
"HashAlgorithm_t"_cs,
false)},
213 {
"PSA_CounterType_t"_cs, std::make_pair(
"CounterType_t"_cs,
false)},
214 {
"PSA_MeterType_t"_cs, std::make_pair(
"MeterType_t"_cs,
false)},
215 {
"PSA_MeterColor_t"_cs, std::make_pair(
"MeterColor_t"_cs,
true)}};
221 : ExpressionConverter(structure) {
222 CHECK_NULL(structure);
224 const IR::Node *postorder(IR::TypeNameExpression *node)
override;
225 const IR::Node *postorder(IR::Member *mem)
override;
228class TypeNameConverter :
public Transform {
233 {
"PSA_HashAlgorithm_t"_cs, std::make_pair(
"HashAlgorithm_t"_cs,
false)},
234 {
"PSA_CounterType_t"_cs, std::make_pair(
"CounterType_t"_cs,
false)},
235 {
"PSA_MeterType_t"_cs, std::make_pair(
"MeterType_t"_cs,
false)},
236 {
"PSA_MeterColor_t"_cs, std::make_pair(
"MeterColor_t"_cs,
true)}};
239 explicit TypeNameConverter(
ProgramStructure *structure) : structure(structure) {
240 CHECK_NULL(structure);
242 const IR::Node *postorder(IR::Type_Name *node)
override;
245class PathExpressionConverter :
public ExpressionConverter {
247 explicit PathExpressionConverter(
ProgramStructure *structure) : ExpressionConverter(structure) {
248 CHECK_NULL(structure);
const IR::Node * postorder(IR::P4Control *node) override
Definition psa_converters.cpp:349
const IR::Node * postorder(IR::P4Parser *node) override
Definition psa_converters.cpp:212
const IR::Node * postorder(IR::Member *node) override
map path expression
Definition psa_converters.cpp:631
Definition ordered_map.h:32
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Definition backends/tofino/bf-p4c/arch/psa/programStructure.h:99
T * to() noexcept
Definition rtti.h:226