Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous cleanups for P4Testgen. #4613

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backends/p4tools/common/core/z3_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const IR::Literal *Z3Solver::toLiteral(const z3::expr &e, const IR::Type *type)
// Handle booleans.
if (type->is<IR::Type::Boolean>()) {
BUG_CHECK(e.is_bool(), "Expected a boolean value: %1%", e);
return new IR::BoolLiteral(type, e.is_true());
return IR::getBoolLiteral(e.is_true());
}

// Handle bit vectors.
Expand Down
14 changes: 6 additions & 8 deletions backends/p4tools/common/lib/gen_eq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ const IR::Expression *equateListTypes(const IR::Expression *left, const IR::Expr
"different.",
leftElemsSize, rightElemsSize);

const IR::Expression *result = new IR::BoolLiteral(IR::Type::Boolean::get(), true);
bool firstLoop = true;
const IR::Expression *result = nullptr;
for (size_t i = 0; i < leftElems.size(); i++) {
const auto *conjunct = equate(leftElems.at(i), rightElems.at(i));
if (firstLoop) {
if (result == nullptr) {
result = conjunct;
firstLoop = false;
} else {
result = new IR::LAnd(IR::Type::Boolean::get(), result, conjunct);
}
Expand All @@ -62,7 +60,7 @@ const IR::Expression *equate(const IR::Expression *left, const IR::Expression *r

// A single default expression can be matched with a list expression.
if (left->is<IR::DefaultExpression>() || right->is<IR::DefaultExpression>()) {
return new IR::BoolLiteral(IR::Type::Boolean::get(), true);
return IR::getBoolLiteral(true);
}

// If we still have lists after unrolling, compare them.
Expand All @@ -82,9 +80,9 @@ const IR::Expression *equate(const IR::Expression *left, const IR::Expression *r
}

if (const auto *rangeKey = right->to<IR::Range>()) {
const auto *boolType = IR::Type::Boolean::get();
return new IR::LAnd(boolType, new IR::Leq(boolType, rangeKey->left, left),
new IR::Leq(boolType, left, rangeKey->right));
return new IR::LAnd(IR::Type::Boolean::get(),
new IR::Leq(IR::Type::Boolean::get(), rangeKey->left, left),
new IR::Leq(IR::Type::Boolean::get(), left, rangeKey->right));
}

return mkEq(left, right);
Expand Down
5 changes: 3 additions & 2 deletions backends/p4tools/modules/testgen/core/program_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ void ProgramInfo::produceCopyInOutCall(const IR::Parameter *param, size_t paramI
}
const auto *archPath = new IR::PathExpression(paramType, new IR::Path(archRef));
const auto *paramRef = new IR::PathExpression(paramType, new IR::Path(param->name));
const auto *paramDir = new IR::StringLiteral(directionToString(param->direction));
const auto *paramDir =
new IR::StringLiteral(IR::Type_String::get(), directionToString(param->direction));
if (copyIns != nullptr) {
// This mimicks the copy-in from the architecture environment.
const auto *copyInCall = new IR::MethodCallStatement(Utils::generateInternalMethodCall(
"copy_in", {archPath, paramRef, paramDir, new IR::BoolLiteral(false)}));
"copy_in", {archPath, paramRef, paramDir, IR::getBoolLiteral(false)}));
copyIns->emplace_back(copyInCall);
}
if (copyOuts != nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,12 @@ bool AbstractStepper::stepGetHeaderValidity(const IR::StateVariable &headerRef)
const auto *res = value->to<IR::BoolLiteral>();
BUG_CHECK(res, "%1%: expected a boolean", value);
if (res->value) {
state.replaceTopBody(
Continuation::Return(new IR::BoolLiteral(IR::Type::Boolean::get(), true)));
state.replaceTopBody(Continuation::Return(IR::getBoolLiteral(true)));
result->emplace_back(state);
return false;
}
}
state.replaceTopBody(
Continuation::Return(new IR::BoolLiteral(IR::Type::Boolean::get(), false)));
state.replaceTopBody(Continuation::Return(IR::getBoolLiteral(false)));
result->emplace_back(state);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "backends/p4tools/common/lib/variables.h"
#include "ir/declaration.h"
#include "ir/indexed_vector.h"
#include "ir/ir-generated.h"
#include "ir/irutils.h"
#include "ir/node.h"
#include "ir/solver.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
namespace P4Tools::P4Testgen::EBPF {

const IR::PathExpression EBPFConstants::ACCEPT_VAR =
IR::PathExpression(new IR::Type_Boolean(), new IR::Path("*accept"));
IR::PathExpression(IR::Type_Boolean::get(), new IR::Path("*accept"));

} // namespace P4Tools::P4Testgen::EBPF
2 changes: 1 addition & 1 deletion backends/p4tools/modules/testgen/targets/pna/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace P4Tools::P4Testgen::Pna {

const IR::Member PnaConstants::DROP_VAR =
IR::Member(new IR::Type_Boolean(), new IR::PathExpression("*pna_internal"), "drop_var");
IR::Member(IR::Type_Boolean::get(), new IR::PathExpression("*pna_internal"), "drop_var");
const IR::Member PnaConstants::OUTPUT_PORT_VAR = IR::Member(
new IR::Type_Bits(32, false), new IR::PathExpression("*pna_internal"), "output_port");
const IR::Member PnaConstants::PARSER_ERROR = IR::Member(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "backends/p4tools/common/core/z3_solver.h"
#include "backends/p4tools/common/lib/variables.h"
#include "ir/ir-generated.h"
#include "ir/ir.h"
#include "ir/irutils.h"
#include "lib/cstring.h"
Expand Down
2 changes: 1 addition & 1 deletion test/gtest/visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct MultiVisitInspector : public Inspector, virtual public P4::ResolutionCont
}
}

bool preorder(const IR::PathExpression *path) {
bool preorder(const IR::PathExpression *path) override {
visit_def(path);
return true;
}
Expand Down
Loading