45 static bool checkSameKeyExpr(
const IR::Expression *
expr0,
const IR::Expression *
expr1) {
46 if (
expr0->node_type_name() !=
expr1->node_type_name())
return false;
47 if (
auto pe0 =
expr0->to<IR::PathExpression>()) {
48 auto pe1 =
expr1->to<IR::PathExpression>();
49 return pe0->path->name ==
pe1->path->name &&
pe0->path->absolute ==
pe1->path->absolute;
50 }
else if (
auto mem0 =
expr0->to<IR::Member>()) {
52 return checkSameKeyExpr(
mem0->expr,
mem1->expr) &&
mem0->member ==
mem1->member;
53 }
else if (
auto l0 =
expr0->to<IR::Literal>()) {
54 auto l1 =
expr1->to<IR::Literal>();
56 }
else if (
auto ai0 =
expr0->to<IR::ArrayIndex>()) {
57 auto ai1 =
expr1->to<IR::ArrayIndex>();
58 return checkSameKeyExpr(
ai0->left,
ai1->left) &&
59 checkSameKeyExpr(
ai0->right,
ai1->right);
66 refMap = ctxt->refMap;
67 typeMap = ctxt->typeMap;
70 bool preorder(
const IR::P4Table *table)
override {
71 auto implementation = table->properties->getProperty(
"implementation");
72 if (implementation ==
nullptr)
return false;
73 if (!implementation->value->is<IR::ExpressionValue>()) {
74 ::error(ErrorType::ERR_EXPECTED,
"%1%: expected expression for property",
78 auto propv = implementation->value->to<IR::ExpressionValue>();
79 if (!
propv->expression->is<IR::PathExpression>())
return false;
80 auto pathe =
propv->expression->to<IR::PathExpression>();
82 if (!decl->is<IR::Declaration_Instance>()) {
83 ::error(ErrorType::ERR_EXPECTED,
"%1%: expected a reference to an instance",
pathe);
87 if (!
dcltype->is<IR::Type_Extern>()) {
88 ::error(ErrorType::ERR_UNEXPECTED,
"%1%: unexpected type for implementation",
dcltype);
95 auto key = table->getKey();
97 for (
auto ke : key->keyElements) {
99 BUG_CHECK(
mt !=
nullptr,
"%1%: could not find declaration",
ke->matchType);
101 input.push_back(
ke->expression);
105 if (it == ctxt->selector_input_map.end()) {
110 auto cmp_inputs = [](
const SelectorInput &
i1,
const SelectorInput &
i2) {
111 if (
i1.size() !=
i2.size())
return false;
112 return std::equal(
i1.begin(),
i1.end(),
i2.begin(), checkSameKeyExpr);
116 ::error(ErrorType::ERR_INVALID,
117 "Action selector %1% is used by multiple tables with different selector inputs",