diff --git a/midend/predication.cpp b/midend/predication.cpp index a160c8299c0..69f71517dc4 100644 --- a/midend/predication.cpp +++ b/midend/predication.cpp @@ -13,11 +13,120 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - #include "predication.h" #include "frontends/p4/cloner.h" + namespace P4 { +/// convert an expression into a string that uniqely identifies the value referenced +/// return null cstring if not a reference to a constant thing. +static cstring expr_name(const IR::Expression *exp) { + if (auto p = exp->to()) + return p->path->name; + if (auto m = exp->to()) { + if (auto base = expr_name(m->expr)) + return base + "." + m->member; + } else if (auto a = exp->to()) { + if (auto k = a->right->to()) + if (auto base = expr_name(a->left)) + return base + "." + std::to_string(k->asInt()); } + return cstring(); +} + +bool Predication::EmptyStatementRemover::preorder(IR::BlockStatement * block) { + for (auto iter = block->components.begin(); iter != block->components.end();) { + if ((*iter)->is()) { + iter = block->components.erase(iter); + } else if ((*iter)->is()) { + visit(*iter); + if ((*iter)->to()->components.size() == 0) { + iter = block->components.erase(iter); + } else { + iter++; + } + } else { + iter++; + } + } + return false; +} + +const IR::AssignmentStatement * +Predication::ExpressionReplacer::preorder(IR::AssignmentStatement * statement) { + // fill the conditions from context + while (context != nullptr) { + if (context->node->is()) { + conditions.push_back(context->node->to()->condition); + } + context = context->parent; + } + + if (!statement->right->is()) { + statement->right = new IR::Mux(conditions.back(), statement->left, statement->left); + } + visit(statement->right); + return statement; +} + +void Predication::ExpressionReplacer::emplaceExpression(IR::Mux * mux) { + auto condition = conditions[conditions.size() - currentNestingLevel]; + bool thenElsePass = travesalPath[currentNestingLevel - 1]; + mux->e0 = condition; + if (thenElsePass) { + mux->e1 = rightExpression; + } else { + mux->e2 = rightExpression; + } +} + +void Predication::ExpressionReplacer::visitThen(IR::Mux * mux) { + auto condition = conditions[conditions.size() - currentNestingLevel]; + auto statement = findContext(); + auto leftName = expr_name(statement->left); + auto thenExprName = expr_name(mux->e1); + if (expr_name(mux->e2) == expr_name(statement->left)) { + mux->e2 = statement->left; + } + if (mux->e1->is() || thenExprName.isNullOrEmpty() || thenExprName == leftName) { + if (!mux->e1->is()) { + mux->e1 = new IR::Mux(condition, statement->left, statement->left); + } + visit(mux->e1); + } +} + +void Predication::ExpressionReplacer::visitElse(IR::Mux * mux) { + auto condition = conditions[conditions.size() - currentNestingLevel]; + auto statement = findContext(); + auto leftName = expr_name(statement->left); + auto elseExprName = expr_name(mux->e2); + if (expr_name(mux->e1) == leftName) { + mux->e1 = statement->left; + mux->e1 = statement->left; + mux->e1 = statement->left; + } + if (mux->e2->is() || elseExprName.isNullOrEmpty() || elseExprName == leftName) { + if (!mux->e2->is()) { + mux->e2 = new IR::Mux(condition, statement->left, statement->left); + } + visit(mux->e2); + } +} + + +const IR::Mux * Predication::ExpressionReplacer::preorder(IR::Mux * mux) { + ++currentNestingLevel; + bool thenElsePass = travesalPath[currentNestingLevel - 1]; + if (currentNestingLevel == travesalPath.size()) { + emplaceExpression(mux); + } else if (thenElsePass) { + visitThen(mux); + } else { + visitElse(mux); + } + --currentNestingLevel; + return mux; +} const IR::Expression* Predication::clone(const IR::Expression* expression) { // We often need to clone expressions. This is necessary because @@ -28,13 +137,58 @@ const IR::Expression* Predication::clone(const IR::Expression* expression) { return expression->apply(cloner); } -const IR::Node* Predication::postorder(IR::AssignmentStatement* statement) { +const IR::Node* Predication::clone(const IR::AssignmentStatement* statement) { + // We often need to clone assignments. This is necessary because + // in the end we will generate different code for the different clones of + // an assignments. + ClonePathExpressions cloner; + return statement->apply(cloner); +} + +const IR::Node* Predication::preorder(IR::AssignmentStatement* statement) { if (!inside_action || ifNestingLevel == 0) return statement; + ExpressionReplacer replacer(clone(statement->right), travesalPath, getContext()); + // Referenced lvalue is not appeard before + dependencies.clear(); + visit(statement->right); + // print out dependencies + for (auto dependency : dependencies) { + if (liveAssignments.find(dependency) != liveAssignments.end()) { + // print out dependecy + currentBlock->push_back(liveAssignments[dependency]); + // remove from names to not duplicate + orderedNames.erase(dependency); + liveAssignments.erase(dependency); + } + } + auto statementName = expr_name(statement->left); + auto foundedAssignment = liveAssignments.find(statementName); + if (foundedAssignment != liveAssignments.end()) { + statement->right = foundedAssignment->second->right; + // move the lvalue assignment to the back + orderedNames.erase(statementName); + } + orderedNames.push_back(statementName); + auto updatedStatement = statement->apply(replacer); + auto rightStatement = clone(updatedStatement->to()->right); + liveAssignments[statementName] = new IR::AssignmentStatement(statement->left, rightStatement); + return new IR::EmptyStatement(); +} - auto right = new IR::Mux(predicate(), statement->right, clone(statement->left)); - statement->right = right; - return statement; +const IR::Node* Predication::preorder(IR::PathExpression * pathExpr) { + dependencies.push_back(expr_name(pathExpr)); + return pathExpr; +} +const IR::Node* Predication::preorder(IR::Member * member) { + visit(member->expr); + dependencies.push_back(expr_name(member)); + return member; +} +const IR::Node* Predication::preorder(IR::ArrayIndex * arrInd) { + visit(arrInd->left); + dependencies.push_back(expr_name(arrInd)); + return arrInd; } const IR::Node* Predication::preorder(IR::IfStatement* statement) { @@ -43,59 +197,29 @@ const IR::Node* Predication::preorder(IR::IfStatement* statement) { ++ifNestingLevel; auto rv = new IR::BlockStatement; - cstring conditionName = generator->newName("cond"); - auto condDecl = new IR::Declaration_Variable(conditionName, IR::Type::Boolean::get()); - rv->push_back(condDecl); - auto condition = new IR::PathExpression(IR::ID(conditionName)); - - // A vector for a new BlockStatement. - auto block = new IR::BlockStatement; - - const IR::Expression* previousPredicate = predicate(); // This may be nullptr - // a new name for the new predicate - cstring newPredName = generator->newName("pred"); - predicateName.push_back(newPredName); - auto decl = new IR::Declaration_Variable(newPredName, IR::Type::Boolean::get()); - block->push_back(decl); - // This evaluates the if condition. - // We are careful not to evaluate any conditional more times - // than in the original program, since the evaluation may have side-effects. - auto trueCond = new IR::AssignmentStatement(clone(condition), statement->condition); - block->push_back(trueCond); - - const IR::Expression* pred; - if (previousPredicate == nullptr) { - pred = clone(condition); - } else { - pred = new IR::LAnd(previousPredicate, clone(condition)); - } - auto truePred = new IR::AssignmentStatement(predicate(), pred); - block->push_back(truePred); - + currentBlock = rv; + travesalPath.push_back(true); visit(statement->ifTrue); - block->push_back(statement->ifTrue); + rv->push_back(statement->ifTrue); + // This evaluates else branch if (statement->ifFalse != nullptr) { - auto neg = new IR::LNot(clone(condition)); - auto falseCond = new IR::AssignmentStatement(clone(condition), neg); - block->push_back(falseCond); - if (previousPredicate == nullptr) { - pred = clone(condition); - } else { - pred = new IR::LAnd(clone(previousPredicate), clone(condition)); - } - auto falsePred = new IR::AssignmentStatement(predicate(), pred); - block->push_back(falsePred); - + travesalPath.back() = false; visit(statement->ifFalse); - block->push_back(statement->ifFalse); + rv->push_back(statement->ifFalse); } - rv->push_back(block); - predicateName.pop_back(); + for (auto exprName : orderedNames) { + rv->push_back(liveAssignments[exprName]); + } + liveAssignments.clear(); + orderedNames.clear(); + travesalPath.pop_back(); --ifNestingLevel; + prune(); - return rv; + + return rv->apply(remover); } const IR::Node* Predication::preorder(IR::P4Action* action) { diff --git a/midend/predication.h b/midend/predication.h index 818e4571779..04644e14cf5 100644 --- a/midend/predication.h +++ b/midend/predication.h @@ -23,51 +23,67 @@ limitations under the License. namespace P4 { /** - This pass operates on action bodies. It converts 'if' statements to '?:' expressions, if possible. Otherwise this pass will signal an error. This pass should be used only on architectures that do not support conditionals in actions. - For this to work all statements must be assignments or other ifs. - if (e) a = f(b); else c = f(d); -x = y; - becomes (actual implementatation is slightly optimized): - -bool cond; -bool predicate = true; { - bool predicate1; - cond = e; - predicate1 = predicate && cond; - a = predicate1 ? f(b) : a; - cond = !cond; - predicate1 = predicate && cond; - c = predicate ? f(d) : c; + a = e ? f(b) : a; + c = e ? c : f(d); } -x = predicate ? y : x; - -Not the most efficient conversion currently. -This could be made better by looking on both the "then" and "else" -branches, but in this way we cannot have two side-effects in the same -conditional statement. - */ class Predication final : public Transform { - NameGenerator* generator; + class EmptyStatementRemover final : public Modifier { + public: + EmptyStatementRemover() {} + bool preorder(IR::BlockStatement * block) override; + }; + + /** + * Private Transformer only for Predication pass. + * This pass operates on nested Mux expressions(?:). + * It replaces then and else expressions in Mux with + * the appropriate expression from assignment. + */ + class ExpressionReplacer final : public Transform { + private: + const IR::Expression * rightExpression; + const std::vector& travesalPath; + const Visitor::Context * context; + std::vector conditions; + unsigned currentNestingLevel = 0; + public: + explicit ExpressionReplacer(const IR::Expression * e, + std::vector& t, + const Visitor::Context * c) + : rightExpression(e), travesalPath(t), context(c) + { CHECK_NULL(e); } + const IR::Mux * preorder(IR::Mux * mux) override; + const IR::AssignmentStatement * preorder(IR::AssignmentStatement * statement) override; + void emplaceExpression(IR::Mux * mux); + void visitThen(IR::Mux * mux); + void visitElse(IR::Mux * mux); + }; + + EmptyStatementRemover remover; + IR::BlockStatement * currentBlock; bool inside_action; - std::vector predicateName; unsigned ifNestingLevel; + // Traverse path of nested if-else statements + // true at the end of the vector means that you are currently visiting 'then' branch' + // false at the end of the vector means that you are in the else branch of the if statement. + // Size of this vector is the current if nesting level. + std::vector travesalPath; + ordered_set orderedNames; + std::vector dependencies; + std::map liveAssignments; - const IR::Expression* predicate() const { - if (predicateName.empty()) - return nullptr; - return new IR::PathExpression(IR::ID(predicateName.back())); } const IR::Statement* error(const IR::Statement* statement) const { if (inside_action && ifNestingLevel > 0) ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, @@ -77,15 +93,19 @@ class Predication final : public Transform { } public: - explicit Predication(NameGenerator* generator) : generator(generator), - inside_action(false), ifNestingLevel(0) + explicit Predication(NameGenerator* generator) : + inside_action(false), ifNestingLevel(0) { CHECK_NULL(generator); setName("Predication"); } - const IR::Expression* clone(const IR::Expression* expression); + const IR::Node* clone(const IR::AssignmentStatement* statement); const IR::Node* preorder(IR::IfStatement* statement) override; const IR::Node* preorder(IR::P4Action* action) override; const IR::Node* postorder(IR::P4Action* action) override; - const IR::Node* postorder(IR::AssignmentStatement* statement) override; + const IR::Node* preorder(IR::AssignmentStatement* statement) override; + // Assignment dependecy checkers + const IR::Node* preorder(IR::PathExpression* pathExpr) override; + const IR::Node* preorder(IR::Member* member) override; + const IR::Node* preorder(IR::ArrayIndex* arrInd) override; // The presence of other statements makes predication impossible to apply const IR::Node* postorder(IR::MethodCallStatement* statement) override { return error(statement); } diff --git a/testdata/p4_14_samples_outputs/misc_prim-midend.p4 b/testdata/p4_14_samples_outputs/misc_prim-midend.p4 index f57344f050c..b679851ea79 100644 --- a/testdata/p4_14_samples_outputs/misc_prim-midend.p4 +++ b/testdata/p4_14_samples_outputs/misc_prim-midend.p4 @@ -36,11 +36,6 @@ parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout } control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { - bit<32> tmp; - bit<32> tmp_0; - int<32> tmp_1; - int<32> tmp_2; - int<32> tmp_3; @name(".NoAction") action NoAction_0() { } @name(".action_0") action action_0() { @@ -56,29 +51,19 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ hdr.pkt.field_a_32 = ~hdr.pkt.field_d_32; } @name(".action_4") action action_4(bit<32> param0) { - tmp = (hdr.pkt.field_d_32 <= param0 ? hdr.pkt.field_d_32 : tmp); - tmp = (!(hdr.pkt.field_d_32 <= param0) ? param0 : tmp); - hdr.pkt.field_a_32 = tmp; + hdr.pkt.field_a_32 = (hdr.pkt.field_d_32 <= param0 ? hdr.pkt.field_d_32 : param0); } @name(".action_5") action action_5(bit<32> param0) { - tmp_0 = (param0 >= hdr.pkt.field_d_32 ? param0 : tmp_0); - tmp_0 = (!(param0 >= hdr.pkt.field_d_32) ? hdr.pkt.field_d_32 : tmp_0); - hdr.pkt.field_a_32 = tmp_0; + hdr.pkt.field_a_32 = (param0 >= hdr.pkt.field_d_32 ? param0 : hdr.pkt.field_d_32); } @name(".action_6") action action_6() { - tmp_1 = ((int<32>)hdr.pkt.field_d_32 <= 32s7 ? (int<32>)hdr.pkt.field_d_32 : tmp_1); - tmp_1 = (!((int<32>)hdr.pkt.field_d_32 <= 32s7) ? 32s7 : tmp_1); - hdr.pkt.field_b_32 = tmp_1; + hdr.pkt.field_b_32 = ((int<32>)hdr.pkt.field_d_32 <= 32s7 ? (int<32>)hdr.pkt.field_d_32 : 32s7); } @name(".action_7") action action_7(int<32> param0) { - tmp_2 = (param0 >= (int<32>)hdr.pkt.field_d_32 ? param0 : tmp_2); - tmp_2 = (!(param0 >= (int<32>)hdr.pkt.field_d_32) ? (int<32>)hdr.pkt.field_d_32 : tmp_2); - hdr.pkt.field_b_32 = tmp_2; + hdr.pkt.field_b_32 = (param0 >= (int<32>)hdr.pkt.field_d_32 ? param0 : (int<32>)hdr.pkt.field_d_32); } @name(".action_8") action action_8(int<32> param0) { - tmp_3 = (hdr.pkt.field_x_32 >= param0 ? hdr.pkt.field_x_32 : tmp_3); - tmp_3 = (!(hdr.pkt.field_x_32 >= param0) ? param0 : tmp_3); - hdr.pkt.field_x_32 = tmp_3; + hdr.pkt.field_x_32 = (hdr.pkt.field_x_32 >= param0 ? hdr.pkt.field_x_32 : param0); } @name(".action_9") action action_9() { hdr.pkt.field_x_32 = hdr.pkt.field_x_32 >> 7; diff --git a/testdata/p4_14_samples_outputs/modify_conditionally-midend.p4 b/testdata/p4_14_samples_outputs/modify_conditionally-midend.p4 index 47ae69c7531..31e59268d5b 100644 --- a/testdata/p4_14_samples_outputs/modify_conditionally-midend.p4 +++ b/testdata/p4_14_samples_outputs/modify_conditionally-midend.p4 @@ -35,13 +35,10 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t } control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { - bit<8> tmp; @name(".NoAction") action NoAction_0() { } @name(".table0_actionlist") action table0_actionlist(bit<1> do_goto_table, bit<8> goto_table_id) { meta._metadata_global_do_goto_table0 = do_goto_table; - tmp = (do_goto_table != 1w0 ? goto_table_id : tmp); - tmp = (!(do_goto_table != 1w0) ? meta._metadata_global_goto_table_id1 : tmp); } @name(".table0") table table0_0 { actions = { diff --git a/testdata/p4_16_samples/nested_if_else.p4 b/testdata/p4_16_samples/nested_if_else.p4 new file mode 100644 index 00000000000..20ce2f51e98 --- /dev/null +++ b/testdata/p4_16_samples/nested_if_else.p4 @@ -0,0 +1,150 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 0x800; + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; + +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, + out headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + + state start { + transition parse_ethernet; + } + + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + TYPE_IPV4: parse_ipv4; + default: accept; + } + } + + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { } +} + +control MyIngress(inout headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + bool c = true; + bool c1 = true; + bool c2 = true; + bool c3 = true; + + action if_testing(out bit<16> value, in bit<8> offset) { + value = 0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + c = hdr.ipv4.identification > 16w0; + c1 = hdr.ipv4.identification > 16w1; + c2 = hdr.ipv4.identification > 16w2; + c3 = hdr.ipv4.identification > 16w3; + if (c) { + x = 16w1; + if (c1) { + x = x + 2; + } else { + x = x + 3; + } + x = x + 4; + } else if (c2) { + x = x + 5; + } else { + x = x + 6; + } + value = z + x + y; + } + + action ipv4_forward(){ + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + + action drop(){ + } + + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm; + } + actions = { + ipv4_forward; + drop; + NoAction; + } + size = 1024; + default_action = NoAction(); + } + + + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + apply { } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { } +} + +V1Switch( +MyParser(), +MyVerifyChecksum(), +MyIngress(), +MyEgress(), +MyComputeChecksum(), +MyDeparser() +) main; \ No newline at end of file diff --git a/testdata/p4_16_samples/nested_if_lvalue_dependencies.p4 b/testdata/p4_16_samples/nested_if_lvalue_dependencies.p4 new file mode 100644 index 00000000000..d48cc09903c --- /dev/null +++ b/testdata/p4_16_samples/nested_if_lvalue_dependencies.p4 @@ -0,0 +1,142 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 0x800; + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; + +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, + out headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + + state start { + transition parse_ethernet; + } + + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + TYPE_IPV4: parse_ipv4; + default: accept; + } + } + + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { } +} + +control MyIngress(inout headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + bool c = true; + + action if_testing(out bit<16> value, in bit<8> offset) { + value = 0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + + c = hdr.ipv4.identification > 16w0; + + if (c){ + x = 1; + y = 2; + z = x + y + 3; + y = 4; + x = 5; + z = z + x + y + 13; + } + + value = z + x + y; + } + + action ipv4_forward(){ + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + + action drop(){ + } + + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm; + } + actions = { + ipv4_forward; + drop; + NoAction; + } + size = 1024; + default_action = NoAction(); + } + + + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + apply { } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { } +} + +V1Switch( +MyParser(), +MyVerifyChecksum(), +MyIngress(), +MyEgress(), +MyComputeChecksum(), +MyDeparser() +) main; \ No newline at end of file diff --git a/testdata/p4_16_samples/nested_if_statement.p4 b/testdata/p4_16_samples/nested_if_statement.p4 new file mode 100644 index 00000000000..bb14d004e40 --- /dev/null +++ b/testdata/p4_16_samples/nested_if_statement.p4 @@ -0,0 +1,151 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 0x800; + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; + +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, + out headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + + state start { + transition parse_ethernet; + } + + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + TYPE_IPV4: parse_ipv4; + default: accept; + } + } + + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { } +} + +control MyIngress(inout headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + bool c = true; + bool c1 = true; + bool c2 = true; + bool c3 = true; + + action if_testing(out bit<16> value, in bit<8> offset) { + value = 0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + + c = hdr.ipv4.identification > 16w0; + c1 = hdr.ipv4.identification > 16w1; + c2 = hdr.ipv4.identification > 16w2; + c3 = hdr.ipv4.identification > 16w3; + + if(c){ + x = 0; + } else if(c1){ + x = 1; + } else if(c2){ + x = 2; + } else if (c3){ + x = 3; + } else { + x = 4; + } + + value = z + x + y; + } + + action ipv4_forward(){ + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + + action drop(){ + } + + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm; + } + actions = { + ipv4_forward; + drop; + NoAction; + } + size = 1024; + default_action = NoAction(); + } + + + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + apply { } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { } +} + +V1Switch( +MyParser(), +MyVerifyChecksum(), +MyIngress(), +MyEgress(), +MyComputeChecksum(), +MyDeparser() +) main; \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/action_call_table_ebpf-midend.p4 b/testdata/p4_16_samples_outputs/action_call_table_ebpf-midend.p4 index 1ce57873641..e5d1f38675b 100644 --- a/testdata/p4_16_samples_outputs/action_call_table_ebpf-midend.p4 +++ b/testdata/p4_16_samples_outputs/action_call_table_ebpf-midend.p4 @@ -12,9 +12,8 @@ parser prs(packet_in p, out Headers_t headers) { control pipe(inout Headers_t headers, out bool pass) { @name("pipe.Reject") action Reject(bit<8> rej, bit<8> bar) { - pass = (rej == 8w0 ? true : pass); - pass = (!(rej == 8w0) ? false : pass); - pass = (bar == 8w0 ? false : pass); + pass = (rej == 8w0 ? true : false); + pass = (bar == 8w0 ? false : (rej == 8w0 ? true : false)); } @name("pipe.t") table t_0 { actions = { diff --git a/testdata/p4_16_samples_outputs/issue210-midend.p4 b/testdata/p4_16_samples_outputs/issue210-midend.p4 index fd59ab0a3ad..ce624894f14 100644 --- a/testdata/p4_16_samples_outputs/issue210-midend.p4 +++ b/testdata/p4_16_samples_outputs/issue210-midend.p4 @@ -3,8 +3,7 @@ control Ing(out bit<32> a) { bool b_0; @name("Ing.cond") action cond() { - a = (b_0 ? 32w5 : a); - a = (!b_0 ? 32w10 : a); + a = (b_0 ? 32w5 : 32w10); } @hidden action issue210l30() { b_0 = true; diff --git a/testdata/p4_16_samples_outputs/issue232-bmv2-midend.p4 b/testdata/p4_16_samples_outputs/issue232-bmv2-midend.p4 index 448a52154ec..1194ee543ea 100644 --- a/testdata/p4_16_samples_outputs/issue232-bmv2-midend.p4 +++ b/testdata/p4_16_samples_outputs/issue232-bmv2-midend.p4 @@ -30,7 +30,6 @@ control Eg(inout Headers hdrs, inout Metadata meta, inout standard_metadata_t st Value val_0; @name("Eg.test") action test() { val_0.field1 = val_0.field1; - val_0.field1 = val_0.field1; } @hidden table tbl_test { actions = { diff --git a/testdata/p4_16_samples_outputs/issue242-midend.p4 b/testdata/p4_16_samples_outputs/issue242-midend.p4 index f912dab1bd4..f7f09a5f756 100644 --- a/testdata/p4_16_samples_outputs/issue242-midend.p4 +++ b/testdata/p4_16_samples_outputs/issue242-midend.p4 @@ -70,18 +70,12 @@ control Ing(inout Headers headers, inout Metadata meta, inout standard_metadata_ } control Eg(inout Headers hdrs, inout Metadata meta, inout standard_metadata_t standard_meta) { - bit<32> tmp; - bit<32> tmp_0; @name("Eg.debug") register>(32w100) debug_0; @name("Eg.reg") register>(32w1) reg_0; @name("Eg.test") action test() { - tmp = tmp; - tmp = 32w0; - tmp_0 = tmp_0; - tmp_0 = 32w0; - debug_0.write(32w0, tmp_0); - debug_0.write(32w1, tmp); - debug_0.write(32w2, tmp); + debug_0.write(32w0, 32w0); + debug_0.write(32w1, 32w0); + debug_0.write(32w2, 32w0); reg_0.write(32w0, 32w1); } @hidden table tbl_test { diff --git a/testdata/p4_16_samples_outputs/issue512-midend.p4 b/testdata/p4_16_samples_outputs/issue512-midend.p4 index 7a5440c6c89..5c76a4d8a11 100644 --- a/testdata/p4_16_samples_outputs/issue512-midend.p4 +++ b/testdata/p4_16_samples_outputs/issue512-midend.p4 @@ -31,12 +31,10 @@ parser parserI(packet_in pkt, out Parsed_packet hdr, inout mystruct1 meta, inout } control cIngress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) { - bool pred; @name("cIngress.foo") action foo() { meta.b = meta.b + 4w5; - pred = meta.b > 4w10; meta.b = (meta.b > 4w10 ? meta.b ^ 4w5 : meta.b); - meta.b = (!(pred ? true : false) ? meta.b + 4w5 : meta.b); + meta.b = (!(meta.b > 4w10 ? true : false) ? meta.b + 4w5 : meta.b); } @name("cIngress.guh") table guh_0 { key = { diff --git a/testdata/p4_16_samples_outputs/issue696-bmv2-midend.p4 b/testdata/p4_16_samples_outputs/issue696-bmv2-midend.p4 index ddd7b121391..9e979a18c9d 100644 --- a/testdata/p4_16_samples_outputs/issue696-bmv2-midend.p4 +++ b/testdata/p4_16_samples_outputs/issue696-bmv2-midend.p4 @@ -74,16 +74,10 @@ control Ing(inout Headers headers, inout Metadata meta, inout standard_metadata_ } control Eg(inout Headers hdrs, inout Metadata meta, inout standard_metadata_t standard_meta) { - bit<32> tmp; - bit<32> tmp_0; @name("Eg.test") action test() { - tmp = tmp; - tmp = 32w0; - tmp_0 = tmp_0; - tmp_0 = 32w0; - debug.write(32w0, tmp_0); - debug.write(32w1, tmp); - debug.write(32w2, tmp); + debug.write(32w0, 32w0); + debug.write(32w1, 32w0); + debug.write(32w2, 32w0); reg.write(32w0, 32w1); } @hidden table tbl_test { diff --git a/testdata/p4_16_samples_outputs/mux-bmv2-midend.p4 b/testdata/p4_16_samples_outputs/mux-bmv2-midend.p4 index f3473ac12ca..a809731835d 100644 --- a/testdata/p4_16_samples_outputs/mux-bmv2-midend.p4 +++ b/testdata/p4_16_samples_outputs/mux-bmv2-midend.p4 @@ -20,13 +20,10 @@ control Ing(inout Headers headers, inout Metadata meta, inout standard_metadata_ control Eg(inout Headers hdrs, inout Metadata meta, inout standard_metadata_t standard_meta) { bit<64> res_0; - bit<32> tmp; bit<64> val; @name("Eg.update") action update() { val = res_0; - tmp = res_0[31:0]; - tmp = tmp; - val[31:0] = tmp; + val[31:0] = res_0[31:0]; res_0 = val; } @hidden action muxbmv2l58() { diff --git a/testdata/p4_16_samples_outputs/nested_if_else-first.p4 b/testdata/p4_16_samples_outputs/nested_if_else-first.p4 new file mode 100644 index 00000000000..58ff1043b4e --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_else-first.p4 @@ -0,0 +1,129 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 16w0x800; +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + transition parse_ethernet; + } + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + bool c = true; + bool c1 = true; + bool c2 = true; + bool c3 = true; + action if_testing(out bit<16> value, in bit<8> offset) { + value = 16w0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + c = hdr.ipv4.identification > 16w0; + c1 = hdr.ipv4.identification > 16w1; + c2 = hdr.ipv4.identification > 16w2; + c3 = hdr.ipv4.identification > 16w3; + if (c) { + x = 16w1; + if (c1) { + x = x + 16w2; + } else { + x = x + 16w3; + } + x = x + 16w4; + } else if (c2) { + x = x + 16w5; + } else { + x = x + 16w6; + } + value = z + x + y; + } + action ipv4_forward() { + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + action drop() { + } + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction(); + } + size = 1024; + default_action = NoAction(); + } + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_else-frontend.p4 b/testdata/p4_16_samples_outputs/nested_if_else-frontend.p4 new file mode 100644 index 00000000000..bf7c98de65b --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_else-frontend.p4 @@ -0,0 +1,128 @@ +#include +#include + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".NoAction") action NoAction_0() { + } + bool c_0; + bool c1_0; + bool c2_0; + bit<16> x_0; + bit<16> y_0; + bit<16> z_0; + @name("MyIngress.ipv4_forward") action ipv4_forward() { + { + bit<16> value_1; + x_0 = hdr.ipv4.identification; + y_0 = hdr.ipv4.hdrChecksum; + z_0 = hdr.ipv4.totalLen; + c_0 = hdr.ipv4.identification > 16w0; + c1_0 = hdr.ipv4.identification > 16w1; + c2_0 = hdr.ipv4.identification > 16w2; + if (c_0) { + x_0 = 16w1; + if (c1_0) { + x_0 = x_0 + 16w2; + } else { + x_0 = x_0 + 16w3; + } + x_0 = x_0 + 16w4; + } else if (c2_0) { + x_0 = x_0 + 16w5; + } else { + x_0 = x_0 + 16w6; + } + value_1 = z_0 + x_0 + y_0; + hdr.ipv4.totalLen = value_1; + } + } + @name("MyIngress.drop") action drop() { + } + @name("MyIngress.ipv4_lpm") table ipv4_lpm_0 { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction_0(); + } + size = 1024; + default_action = NoAction_0(); + } + apply { + ipv4_lpm_0.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_else-midend.p4 b/testdata/p4_16_samples_outputs/nested_if_else-midend.p4 new file mode 100644 index 00000000000..7015b69cf69 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_else-midend.p4 @@ -0,0 +1,99 @@ +#include +#include + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".NoAction") action NoAction_0() { + } + @name("MyIngress.ipv4_forward") action ipv4_forward() { + hdr.ipv4.totalLen = hdr.ipv4.totalLen + (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))) : (hdr.ipv4.identification > 16w2 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))) + 16w5 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))))) : (hdr.ipv4.identification > 16w2 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))) : (hdr.ipv4.identification > 16w2 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))) + 16w5 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))))) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))) : (hdr.ipv4.identification > 16w2 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))) + 16w5 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification))) + 16w4 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + 16w3) : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w1 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + 16w2 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)))))) + 16w6)) + hdr.ipv4.hdrChecksum; + } + @name("MyIngress.drop") action drop() { + } + @name("MyIngress.ipv4_lpm") table ipv4_lpm_0 { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction_0(); + } + size = 1024; + default_action = NoAction_0(); + } + apply { + ipv4_lpm_0.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_else.p4 b/testdata/p4_16_samples_outputs/nested_if_else.p4 new file mode 100644 index 00000000000..ed801a6b6e2 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_else.p4 @@ -0,0 +1,139 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 0x800; + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; + +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + + state start { + transition parse_ethernet; + } + + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + TYPE_IPV4: parse_ipv4; + default: accept; + } + } + + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + bool c = true; + bool c1 = true; + bool c2 = true; + bool c3 = true; + + action if_testing(out bit<16> value, in bit<8> offset) { + value = 0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + c = hdr.ipv4.identification > 16w0; + c1 = hdr.ipv4.identification > 16w1; + c2 = hdr.ipv4.identification > 16w2; + c3 = hdr.ipv4.identification > 16w3; + if (c) { + x = 16w1; + if (c1) { + x = x + 2; + } else { + x = x + 3; + } + x = x + 4; + } else if (c2) { + x = x + 5; + } else { + x = x + 6; + } + value = z + x + y; + } + + action ipv4_forward(){ + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + + action drop(){ + } + + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm; + } + actions = { + ipv4_forward; + drop; + NoAction; + } + size = 1024; + default_action = NoAction(); + } + + + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch( MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser() ) main; \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/nested_if_else.p4-stderr b/testdata/p4_16_samples_outputs/nested_if_else.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/nested_if_else.p4.entries.txt b/testdata/p4_16_samples_outputs/nested_if_else.p4.entries.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/nested_if_else.p4.p4info.txt b/testdata/p4_16_samples_outputs/nested_if_else.p4.p4info.txt new file mode 100644 index 00000000000..864c1c3fd71 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_else.p4.p4info.txt @@ -0,0 +1,47 @@ +pkg_info { + arch: "v1model" +} +tables { + preamble { + id: 33574068 + name: "MyIngress.ipv4_lpm" + alias: "ipv4_lpm" + } + match_fields { + id: 1 + name: "hdr.ipv4.dstAddr" + bitwidth: 32 + match_type: LPM + } + action_refs { + id: 16799317 + } + action_refs { + id: 16805608 + } + action_refs { + id: 16800567 + } + size: 1024 +} +actions { + preamble { + id: 16800567 + name: "NoAction" + alias: "NoAction" + } +} +actions { + preamble { + id: 16799317 + name: "MyIngress.ipv4_forward" + alias: "ipv4_forward" + } +} +actions { + preamble { + id: 16805608 + name: "MyIngress.drop" + alias: "drop" + } +} diff --git a/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-first.p4 b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-first.p4 new file mode 100644 index 00000000000..0434a061423 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-first.p4 @@ -0,0 +1,118 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 16w0x800; +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + transition parse_ethernet; + } + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + bool c = true; + action if_testing(out bit<16> value, in bit<8> offset) { + value = 16w0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + c = hdr.ipv4.identification > 16w0; + if (c) { + x = 16w1; + y = 16w2; + z = x + y + 16w3; + y = 16w4; + x = 16w5; + z = z + x + y + 16w13; + } + value = z + x + y; + } + action ipv4_forward() { + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + action drop() { + } + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction(); + } + size = 1024; + default_action = NoAction(); + } + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-frontend.p4 b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-frontend.p4 new file mode 100644 index 00000000000..cc1ec2e7072 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-frontend.p4 @@ -0,0 +1,119 @@ +#include +#include + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".NoAction") action NoAction_0() { + } + bool c_0; + bit<16> x_0; + bit<16> y_0; + bit<16> z_0; + @name("MyIngress.ipv4_forward") action ipv4_forward() { + { + bit<16> value_1; + x_0 = hdr.ipv4.identification; + y_0 = hdr.ipv4.hdrChecksum; + z_0 = hdr.ipv4.totalLen; + c_0 = hdr.ipv4.identification > 16w0; + if (c_0) { + x_0 = 16w1; + y_0 = 16w2; + z_0 = x_0 + y_0 + 16w3; + y_0 = 16w4; + x_0 = 16w5; + z_0 = z_0 + x_0 + y_0 + 16w13; + } + value_1 = z_0 + x_0 + y_0; + hdr.ipv4.totalLen = value_1; + } + } + @name("MyIngress.drop") action drop() { + } + @name("MyIngress.ipv4_lpm") table ipv4_lpm_0 { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction_0(); + } + size = 1024; + default_action = NoAction_0(); + } + apply { + ipv4_lpm_0.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-midend.p4 b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-midend.p4 new file mode 100644 index 00000000000..1bb26c99b51 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies-midend.p4 @@ -0,0 +1,99 @@ +#include +#include + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".NoAction") action NoAction_0() { + } + @name("MyIngress.ipv4_forward") action ipv4_forward() { + hdr.ipv4.totalLen = (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + (hdr.ipv4.identification > 16w0 ? 16w2 : hdr.ipv4.hdrChecksum) + 16w3 : hdr.ipv4.totalLen) + (hdr.ipv4.identification > 16w0 ? 16w5 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + (hdr.ipv4.identification > 16w0 ? 16w4 : (hdr.ipv4.identification > 16w0 ? 16w2 : hdr.ipv4.hdrChecksum)) + 16w13 : (hdr.ipv4.identification > 16w0 ? (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification) + (hdr.ipv4.identification > 16w0 ? 16w2 : hdr.ipv4.hdrChecksum) + 16w3 : hdr.ipv4.totalLen)) + (hdr.ipv4.identification > 16w0 ? 16w5 : (hdr.ipv4.identification > 16w0 ? 16w1 : hdr.ipv4.identification)) + (hdr.ipv4.identification > 16w0 ? 16w4 : (hdr.ipv4.identification > 16w0 ? 16w2 : hdr.ipv4.hdrChecksum)); + } + @name("MyIngress.drop") action drop() { + } + @name("MyIngress.ipv4_lpm") table ipv4_lpm_0 { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction_0(); + } + size = 1024; + default_action = NoAction_0(); + } + apply { + ipv4_lpm_0.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4 b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4 new file mode 100644 index 00000000000..e4fada2ea27 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4 @@ -0,0 +1,131 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 0x800; + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; + +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + + state start { + transition parse_ethernet; + } + + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + TYPE_IPV4: parse_ipv4; + default: accept; + } + } + + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + bool c = true; + + action if_testing(out bit<16> value, in bit<8> offset) { + value = 0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + + c = hdr.ipv4.identification > 16w0; + + if (c){ + x = 1; + y = 2; + z = x + y + 3; + y = 4; + x = 5; + z = z + x + y + 13; + } + + value = z + x + y; + } + + action ipv4_forward(){ + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + + action drop(){ + } + + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm; + } + actions = { + ipv4_forward; + drop; + NoAction; + } + size = 1024; + default_action = NoAction(); + } + + + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch( MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser() ) main; diff --git a/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4-stderr b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4.entries.txt b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4.entries.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4.p4info.txt b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4.p4info.txt new file mode 100644 index 00000000000..864c1c3fd71 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_lvalue_dependencies.p4.p4info.txt @@ -0,0 +1,47 @@ +pkg_info { + arch: "v1model" +} +tables { + preamble { + id: 33574068 + name: "MyIngress.ipv4_lpm" + alias: "ipv4_lpm" + } + match_fields { + id: 1 + name: "hdr.ipv4.dstAddr" + bitwidth: 32 + match_type: LPM + } + action_refs { + id: 16799317 + } + action_refs { + id: 16805608 + } + action_refs { + id: 16800567 + } + size: 1024 +} +actions { + preamble { + id: 16800567 + name: "NoAction" + alias: "NoAction" + } +} +actions { + preamble { + id: 16799317 + name: "MyIngress.ipv4_forward" + alias: "ipv4_forward" + } +} +actions { + preamble { + id: 16805608 + name: "MyIngress.drop" + alias: "drop" + } +} diff --git a/testdata/p4_16_samples_outputs/nested_if_statement-first.p4 b/testdata/p4_16_samples_outputs/nested_if_statement-first.p4 new file mode 100644 index 00000000000..f112e5c2dbf --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_statement-first.p4 @@ -0,0 +1,127 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 16w0x800; +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + transition parse_ethernet; + } + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + bool c = true; + bool c1 = true; + bool c2 = true; + bool c3 = true; + action if_testing(out bit<16> value, in bit<8> offset) { + value = 16w0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + c = hdr.ipv4.identification > 16w0; + c1 = hdr.ipv4.identification > 16w1; + c2 = hdr.ipv4.identification > 16w2; + c3 = hdr.ipv4.identification > 16w3; + if (c) { + x = 16w0; + } else if (c1) { + x = 16w1; + } else if (c2) { + x = 16w2; + } else if (c3) { + x = 16w3; + } else { + x = 16w4; + } + value = z + x + y; + } + action ipv4_forward() { + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + action drop() { + } + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction(); + } + size = 1024; + default_action = NoAction(); + } + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_statement-frontend.p4 b/testdata/p4_16_samples_outputs/nested_if_statement-frontend.p4 new file mode 100644 index 00000000000..b8b4527e31a --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_statement-frontend.p4 @@ -0,0 +1,127 @@ +#include +#include + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".NoAction") action NoAction_0() { + } + bool c_0; + bool c1_0; + bool c2_0; + bool c3_0; + bit<16> x_0; + bit<16> y_0; + bit<16> z_0; + @name("MyIngress.ipv4_forward") action ipv4_forward() { + { + bit<16> value_1; + y_0 = hdr.ipv4.hdrChecksum; + z_0 = hdr.ipv4.totalLen; + c_0 = hdr.ipv4.identification > 16w0; + c1_0 = hdr.ipv4.identification > 16w1; + c2_0 = hdr.ipv4.identification > 16w2; + c3_0 = hdr.ipv4.identification > 16w3; + if (c_0) { + x_0 = 16w0; + } else if (c1_0) { + x_0 = 16w1; + } else if (c2_0) { + x_0 = 16w2; + } else if (c3_0) { + x_0 = 16w3; + } else { + x_0 = 16w4; + } + value_1 = z_0 + x_0 + y_0; + hdr.ipv4.totalLen = value_1; + } + } + @name("MyIngress.drop") action drop() { + } + @name("MyIngress.ipv4_lpm") table ipv4_lpm_0 { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction_0(); + } + size = 1024; + default_action = NoAction_0(); + } + apply { + ipv4_lpm_0.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_statement-midend.p4 b/testdata/p4_16_samples_outputs/nested_if_statement-midend.p4 new file mode 100644 index 00000000000..bb9347b5f1e --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_statement-midend.p4 @@ -0,0 +1,99 @@ +#include +#include + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + state start { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".NoAction") action NoAction_0() { + } + @name("MyIngress.ipv4_forward") action ipv4_forward() { + hdr.ipv4.totalLen = hdr.ipv4.totalLen + (hdr.ipv4.identification > 16w0 ? 16w0 : (hdr.ipv4.identification > 16w1 ? 16w1 : (hdr.ipv4.identification > 16w2 ? 16w2 : (hdr.ipv4.identification > 16w3 ? 16w3 : 16w4)))) + hdr.ipv4.hdrChecksum; + } + @name("MyIngress.drop") action drop() { + } + @name("MyIngress.ipv4_lpm") table ipv4_lpm_0 { + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr") ; + } + actions = { + ipv4_forward(); + drop(); + NoAction_0(); + } + size = 1024; + default_action = NoAction_0(); + } + apply { + ipv4_lpm_0.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main; + diff --git a/testdata/p4_16_samples_outputs/nested_if_statement.p4 b/testdata/p4_16_samples_outputs/nested_if_statement.p4 new file mode 100644 index 00000000000..01e99a308d2 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_statement.p4 @@ -0,0 +1,138 @@ +#include +#include + +const bit<16> TYPE_IPV4 = 0x800; + +typedef bit<48> macAddr_t; +typedef bit<32> ip4Addr_t; + +header ethernet_t { + macAddr_t dstAddr; + macAddr_t srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + ip4Addr_t srcAddr; + ip4Addr_t dstAddr; +} + +struct metadata { +} + +struct headers { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + + state start { + transition parse_ethernet; + } + + state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + TYPE_IPV4: parse_ipv4; + default: accept; + } + } + + state parse_ipv4 { + packet.extract(hdr.ipv4); + transition select(hdr.ipv4.protocol) { + default: accept; + } + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + bool c = true; + bool c1 = true; + bool c2 = true; + bool c3 = true; + + action if_testing(out bit<16> value, in bit<8> offset) { + value = 0; + bit<16> x = hdr.ipv4.identification; + bit<16> y = hdr.ipv4.hdrChecksum; + bit<16> z = hdr.ipv4.totalLen; + + c = hdr.ipv4.identification > 16w0; + c1 = hdr.ipv4.identification > 16w1; + c2 = hdr.ipv4.identification > 16w2; + c3 = hdr.ipv4.identification > 16w3; + + if(c){ + x = 0; + } else if(c1){ + x = 1; + } else if(c2){ + x = 2; + } else if (c3){ + x = 3; + } else { + x = 4; + } + + value = z + x + y; + } + + action ipv4_forward(){ + if_testing(hdr.ipv4.totalLen, hdr.ipv4.protocol); + } + action drop(){ + } + table ipv4_lpm { + key = { + hdr.ipv4.dstAddr: lpm; + } + actions = { + ipv4_forward; + drop; + NoAction; + } + size = 1024; + default_action = NoAction(); + } + + + apply { + ipv4_lpm.apply(); + } +} + +control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyDeparser(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch( MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser() ) main; diff --git a/testdata/p4_16_samples_outputs/nested_if_statement.p4-stderr b/testdata/p4_16_samples_outputs/nested_if_statement.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/nested_if_statement.p4.entries.txt b/testdata/p4_16_samples_outputs/nested_if_statement.p4.entries.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/nested_if_statement.p4.p4info.txt b/testdata/p4_16_samples_outputs/nested_if_statement.p4.p4info.txt new file mode 100644 index 00000000000..864c1c3fd71 --- /dev/null +++ b/testdata/p4_16_samples_outputs/nested_if_statement.p4.p4info.txt @@ -0,0 +1,47 @@ +pkg_info { + arch: "v1model" +} +tables { + preamble { + id: 33574068 + name: "MyIngress.ipv4_lpm" + alias: "ipv4_lpm" + } + match_fields { + id: 1 + name: "hdr.ipv4.dstAddr" + bitwidth: 32 + match_type: LPM + } + action_refs { + id: 16799317 + } + action_refs { + id: 16805608 + } + action_refs { + id: 16800567 + } + size: 1024 +} +actions { + preamble { + id: 16800567 + name: "NoAction" + alias: "NoAction" + } +} +actions { + preamble { + id: 16799317 + name: "MyIngress.ipv4_forward" + alias: "ipv4_forward" + } +} +actions { + preamble { + id: 16805608 + name: "MyIngress.drop" + alias: "drop" + } +}