17 #ifndef BACKENDS_DPDK_DPDKCHECKEXTERNINVOCATION_H_
18 #define BACKENDS_DPDK_DPDKCHECKEXTERNINVOCATION_H_
20 #include "frontends/p4/methodInstance.h"
22 #include "ir/visitor.h"
23 #include "midend/checkExternInvocationCommon.h"
47 void initPipeConstraints()
override {
49 validInMainControl.setbit(MAIN_CONTROL);
55 cstring getBlockName(
int bit)
override {
56 static const char *lookup[] = {
"main parser",
"pre control",
"main control",
58 BUG_CHECK(
sizeof(lookup) /
sizeof(lookup[0]) == BLOCK_COUNT,
"Bad lookup table");
59 return lookup[bit % BLOCK_COUNT];
62 const IR::P4Parser *getParser(
const cstring parserName) {
63 if (
auto p = findContext<IR::P4Parser>()) {
64 if (structure->parsers.count(parserName) != 0 &&
65 structure->parsers.at(parserName)->name == p->name) {
72 const IR::P4Control *getControl(
const cstring controlName) {
73 if (
auto c = findContext<IR::P4Control>()) {
74 if (structure->pipelines.count(controlName) != 0 &&
75 structure->pipelines.at(controlName)->name == c->name) {
82 const IR::P4Control *getDeparser(
const cstring deparserName) {
83 if (
auto d = findContext<IR::P4Control>()) {
84 if (structure->deparsers.count(deparserName) != 0 &&
85 structure->deparsers.at(deparserName)->name == d->name) {
92 void checkBlock(
const IR::MethodCallExpression *expr,
const cstring externType,
96 LOG4(
"externType: " << externType <<
", externName: " << externName);
98 if (pipeConstraints.count(externType)) {
99 if (
auto block = getParser(
"MainParserT")) {
100 LOG4(
"MainParser: " << (
void *)block <<
" " << dbp(block));
101 pos.setbit(MAIN_PARSER);
103 }
else if (
auto block = getControl(
"PreControlT")) {
104 LOG4(
"PreControl: " << (
void *)block <<
" " << dbp(block));
105 pos.setbit(PRE_CONTROL);
107 }
else if (
auto block = getControl(
"MainControlT")) {
108 LOG4(
"MainControl: " << (
void *)block <<
" " << dbp(block));
109 pos.setbit(MAIN_CONTROL);
111 }
else if (
auto block = getDeparser(
"MainDeparserT")) {
112 LOG4(
"MainDeparser: " << (
void *)block <<
" " << dbp(block));
113 pos.setbit(MAIN_DEPARSER);
119 LOG1(
"Pipe constraints not defined for: " << externType);
124 const IR::MethodCallExpression *expr)
override {
125 LOG3(
"ExternMethod: " << extMethod <<
", MethodCallExpression: " << expr);
126 checkBlock(expr, extMethod->originalExternType->name, extMethod->
object->
getName().name);
130 const IR::MethodCallExpression *expr)
override {
131 LOG3(
"ExternFunction: " << extFunction <<
", MethodCallExpression: " << expr);
132 checkBlock(expr, expr->method->toString(),
"");
139 initPipeConstraints();
155 : refMap(refMap), typeMap(typeMap), structure(structure) {}
157 bool preorder(
const IR::P4Program *program) {
158 if (structure->
isPNA()) {
159 LOG1(
"Checking extern invocations for PNA architecture.");
161 program->apply(*checker);
162 }
else if (structure->
isPSA()) {
163 LOG1(
"Checking extern invocations for PSA architecture.");
166 LOG1(
"Unknown architecture: " << structure->p4arch <<
", not checking constraints.");
Class which chooses the correct class for checking the constraints for invocations of extern methods ...
Definition: dpdkCheckExternInvocation.h:147
Class for checking constraints for invocations of PNA architecture extern methods and functions.
Definition: dpdkCheckExternInvocation.h:36
virtual ID getName() const =0
Definition: visitor.h:396
Base class which can be used to prepare classes for checking constraints for invocations of externs (...
Definition: checkExternInvocationCommon.h:41
void setPipeConstraints(cstring extType, bitvec vec)
Set the pipe (parser/control block) constraints.
Definition: checkExternInvocationCommon.h:116
void checkPipeConstraints(cstring extType, bitvec bv, const IR::MethodCallExpression *expr, cstring extName, cstring pipe)
Check if the invocation of extern object method or extern function is valid in the block where it is ...
Definition: checkExternInvocationCommon.h:138
Definition: methodInstance.h:176
Definition: methodInstance.h:144
const IR::IDeclaration * object
Definition: methodInstance.h:79
Class used to encode maps from paths to declarations.
Definition: referenceMap.h:66
Definition: backend.cpp:35
Definition: applyOptionsPragmas.cpp:24
Definition: dpdkProgramStructure.h:14
bool isPSA(void)
Predicate that states whether architecture is PSA or not.
Definition: dpdkProgramStructure.h:89
bool isPNA(void)
Predicate that states whether architecture is PNA or not.
Definition: dpdkProgramStructure.h:99