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

Update formatters (clang-format, isort, black) #4515

Merged
merged 2 commits into from
Mar 8, 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
5 changes: 2 additions & 3 deletions backends/bmv2/common/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,8 @@ unsigned ParserConverter::combine(const IR::Expression *keySet, const IR::ListEx
mask_value = Util::mask(width);
}
mask = Util::shift_left(mask, w) + mask_value;
LOG3("Shifting "
<< " into key " << key_value << " &&& " << mask_value << " result is " << value
<< " &&& " << mask);
LOG3("Shifting " << " into key " << key_value << " &&& " << mask_value << " result is "
<< value << " &&& " << mask);
index++;
}

Expand Down
9 changes: 3 additions & 6 deletions backends/bmv2/psa_switch/psaSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,7 @@ void ExternConverter_Hash::convertExternInstance(ConversionContext *ctxt, const
void ExternConverter_Checksum::convertExternInstance(UNUSED ConversionContext *ctxt,
UNUSED const IR::Declaration *c,
UNUSED const IR::ExternBlock *eb,
UNUSED const bool &emitExterns) { /* TODO */
}
UNUSED const bool &emitExterns) { /* TODO */ }

void ExternConverter_InternetChecksum::convertExternInstance(UNUSED ConversionContext *ctxt,
UNUSED const IR::Declaration *c,
Expand Down Expand Up @@ -972,8 +971,7 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c
void ExternConverter_Random::convertExternInstance(UNUSED ConversionContext *ctxt,
UNUSED const IR::Declaration *c,
UNUSED const IR::ExternBlock *eb,
UNUSED const bool &emitExterns) { /* TODO */
}
UNUSED const bool &emitExterns) { /* TODO */ }

void ExternConverter_ActionProfile::convertExternInstance(UNUSED ConversionContext *ctxt,
UNUSED const IR::Declaration *c,
Expand Down Expand Up @@ -1056,7 +1054,6 @@ void ExternConverter_ActionSelector::convertExternInstance(UNUSED ConversionCont
void ExternConverter_Digest::convertExternInstance(UNUSED ConversionContext *ctxt,
UNUSED const IR::Declaration *c,
UNUSED const IR::ExternBlock *eb,
UNUSED const bool &emitExterns) { /* TODO */
}
UNUSED const bool &emitExterns) { /* TODO */ }

} // namespace BMV2
13 changes: 4 additions & 9 deletions backends/dpdk/spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,21 +540,17 @@ std::ostream &IR::DpdkAction::toSpec(std::ostream &out) const {
}

std::ostream &IR::DpdkChecksumAddStatement::toSpec(std::ostream &out) const {
out << "ckadd "
<< "h.cksum_state." << intermediate_value << " " << DPDK::toStr(field);
out << "ckadd " << "h.cksum_state." << intermediate_value << " " << DPDK::toStr(field);
return out;
}

std::ostream &IR::DpdkChecksumSubStatement::toSpec(std::ostream &out) const {
out << "cksub "
<< "h.cksum_state." << intermediate_value << " " << DPDK::toStr(field);
out << "cksub " << "h.cksum_state." << intermediate_value << " " << DPDK::toStr(field);
return out;
}

std::ostream &IR::DpdkChecksumClearStatement::toSpec(std::ostream &out) const {
out << "mov "
<< "h.cksum_state." << intermediate_value << " "
<< "0x0";
out << "mov " << "h.cksum_state." << intermediate_value << " " << "0x0";
return out;
}

Expand All @@ -581,8 +577,7 @@ std::ostream &IR::DpdkGetHashStatement::toSpec(std::ostream &out) const {
}

std::ostream &IR::DpdkGetChecksumStatement::toSpec(std::ostream &out) const {
out << "mov " << DPDK::toStr(dst) << " "
<< "h.cksum_state." << intermediate_value;
out << "mov " << DPDK::toStr(dst) << " " << "h.cksum_state." << intermediate_value;
return out;
}

Expand Down
6 changes: 3 additions & 3 deletions backends/ebpf/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ class XdpTarget : public KernelSamplesTarget {
class BccTarget : public Target {
public:
BccTarget() : Target("BCC") {}
void emitLicense(Util::SourceCodeBuilder *, cstring) const override{};
void emitLicense(Util::SourceCodeBuilder *, cstring) const override {};
void emitCodeSection(Util::SourceCodeBuilder *, cstring) const override {}
void emitIncludes(Util::SourceCodeBuilder *builder) const override;
void emitResizeBuffer(Util::SourceCodeBuilder *, cstring, cstring) const override{};
void emitResizeBuffer(Util::SourceCodeBuilder *, cstring, cstring) const override {};
void emitTableLookup(Util::SourceCodeBuilder *builder, cstring tblName, cstring key,
cstring value) const override;
void emitTableUpdate(Util::SourceCodeBuilder *builder, cstring tblName, cstring key,
Expand Down Expand Up @@ -256,7 +256,7 @@ class TestTarget : public EBPF::KernelSamplesTarget {
public:
TestTarget() : KernelSamplesTarget(false, "Userspace Test") {}

void emitResizeBuffer(Util::SourceCodeBuilder *, cstring, cstring) const override{};
void emitResizeBuffer(Util::SourceCodeBuilder *, cstring, cstring) const override {};
void emitIncludes(Util::SourceCodeBuilder *builder) const override;
void emitTableDecl(Util::SourceCodeBuilder *builder, cstring tblName, TableKind tableKind,
cstring keyType, cstring valueType, unsigned size) const override;
Expand Down
3 changes: 1 addition & 2 deletions backends/p4tools/common/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

void printVersion(const char *binaryName) {
std::cout << binaryName << std::endl
<< "Version"
<< " " << P4TOOLS_VERSION_MAJOR << "." << P4TOOLS_VERSION_MINOR << "."
<< "Version" << " " << P4TOOLS_VERSION_MAJOR << "." << P4TOOLS_VERSION_MINOR << "."
<< P4TOOLS_VERSION_PATCH << P4TOOLS_VERSION_HASH << std::endl;
}
4 changes: 2 additions & 2 deletions backends/p4tools/modules/testgen/lib/execution_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ const std::vector<std::reference_wrapper<const TraceEvent>> &ExecutionState::get

const Continuation::Body &ExecutionState::getBody() const { return body; }

const std::stack<std::reference_wrapper<const ExecutionState::StackFrame>>
&ExecutionState::getStack() const {
const std::stack<std::reference_wrapper<const ExecutionState::StackFrame>> &
ExecutionState::getStack() const {
return stack;
}

Expand Down
9 changes: 3 additions & 6 deletions backends/p4tools/modules/testgen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ int main(int argc, char **argv) {
result = P4Tools::P4Testgen::Testgen().main(args);
} catch (const Util::CompilerBug &e) {
std::cerr << "Internal error: " << updateErrorMsg(e.what()) << "\n";
std::cerr << "Please submit a bug report with your code."
<< "\n";
std::cerr << "Please submit a bug report with your code." << "\n";
result = EXIT_FAILURE;
} catch (const Util::CompilerUnimplemented &e) {
std::cerr << updateErrorMsg(e.what()) << "\n";
Expand All @@ -45,12 +44,10 @@ int main(int argc, char **argv) {
result = EXIT_FAILURE;
} catch (const std::exception &e) {
std::cerr << "Internal error: " << updateErrorMsg(e.what()) << "\n";
std::cerr << "Please submit a bug report with your code."
<< "\n";
std::cerr << "Please submit a bug report with your code." << "\n";
result = EXIT_FAILURE;
} catch (...) {
std::cerr << "Internal error. Please submit a bug report with your code."
<< "\n";
std::cerr << "Internal error. Please submit a bug report with your code." << "\n";
result = EXIT_FAILURE;
}
P4Tools::printPerformanceReport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const IR::P4Table *Bmv2V1ModelProgramInfo::getTableofDirectExtern(

const ArchSpec &Bmv2V1ModelProgramInfo::getArchSpec() const { return ARCH_SPEC; }

const ordered_map<cstring, const IR::Type_Declaration *>
*Bmv2V1ModelProgramInfo::getProgrammableBlocks() const {
const ordered_map<cstring, const IR::Type_Declaration *> *
Bmv2V1ModelProgramInfo::getProgrammableBlocks() const {
return &programmableBlocks;
}

Expand Down
4 changes: 2 additions & 2 deletions backends/p4tools/modules/testgen/targets/bmv2/test_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ bool Bmv2V1ModelMeterValue::isDirectMeter() const { return isDirect; }
* Bmv2V1ModelActionProfile
* ========================================================================================= */

const std::vector<std::pair<cstring, std::vector<ActionArg>>>
*Bmv2V1ModelActionProfile::getActions() const {
const std::vector<std::pair<cstring, std::vector<ActionArg>>> *
Bmv2V1ModelActionProfile::getActions() const {
return &actions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ SharedPnaProgramInfo::SharedPnaProgramInfo(
concolicMethodImpls.add(*PnaDpdkConcolic::getPnaDpdkConcolicMethodImpls());
}

const ordered_map<cstring, const IR::Type_Declaration *>
*SharedPnaProgramInfo::getProgrammableBlocks() const {
const ordered_map<cstring, const IR::Type_Declaration *> *
SharedPnaProgramInfo::getProgrammableBlocks() const {
return &programmableBlocks;
}

Expand Down
8 changes: 4 additions & 4 deletions backends/ubpf/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class UbpfTarget : public EBPF::Target {
public:
UbpfTarget() : EBPF::Target("UBPF") {}

void emitLicense(Util::SourceCodeBuilder *, cstring) const override{};
void emitCodeSection(Util::SourceCodeBuilder *, cstring) const override{};
void emitLicense(Util::SourceCodeBuilder *, cstring) const override {};
void emitCodeSection(Util::SourceCodeBuilder *, cstring) const override {};
void emitIncludes(Util::SourceCodeBuilder *builder) const override;
void emitResizeBuffer(Util::SourceCodeBuilder *builder, cstring buffer,
cstring offsetVar) const override;
Expand All @@ -42,11 +42,11 @@ class UbpfTarget : public EBPF::Target {
void emitGetFromStandardMetadata(Util::SourceCodeBuilder *builder, cstring stdMetadataVar,
cstring metadataField) const;
void emitUserTableUpdate(UNUSED Util::SourceCodeBuilder *builder, UNUSED cstring tblName,
UNUSED cstring key, UNUSED cstring value) const override{};
UNUSED cstring key, UNUSED cstring value) const override {};
void emitTableDecl(Util::SourceCodeBuilder *builder, cstring tblName, EBPF::TableKind tableKind,
cstring keyType, cstring valueType, unsigned size) const override;
void emitMain(UNUSED Util::SourceCodeBuilder *builder, UNUSED cstring functionName,
UNUSED cstring argName) const override{};
UNUSED cstring argName) const override {};
void emitMain(Util::SourceCodeBuilder *builder, cstring functionName, cstring argName,
cstring standardMetadata) const;
void emitUbpfHelpers(EBPF::CodeBuilder *builder) const;
Expand Down
6 changes: 2 additions & 4 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,15 @@ const IR::Node *DoConstantFolding::postorder(IR::Add *e) {
}

const IR::Node *DoConstantFolding::postorder(IR::AddSat *e) {
return binary(
e, [](big_int a, big_int b) -> big_int { return a + b; }, true);
return binary(e, [](big_int a, big_int b) -> big_int { return a + b; }, true);
}

const IR::Node *DoConstantFolding::postorder(IR::Sub *e) {
return binary(e, [](big_int a, big_int b) -> big_int { return a - b; });
}

const IR::Node *DoConstantFolding::postorder(IR::SubSat *e) {
return binary(
e, [](big_int a, big_int b) -> big_int { return a - b; }, true);
return binary(e, [](big_int a, big_int b) -> big_int { return a - b; }, true);
}

const IR::Node *DoConstantFolding::postorder(IR::Mul *e) {
Expand Down
120 changes: 60 additions & 60 deletions ir/v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,84 +128,84 @@ void IR::Primitive::typecheck() const {
}

bool IR::Primitive::isOutput(int operand_index) const {
if (prim_info.count(name)) return (prim_info.at(name).out_operands >> operand_index) & 1;
return false;
if (prim_info.count(name)) return (prim_info.at(name).out_operands >> operand_index) & 1;
return false;
}

unsigned IR::Primitive::inferOperandTypes() const {
if (prim_info.count(name)) return prim_info.at(name).type_match_operands;
return 0;
if (prim_info.count(name)) return prim_info.at(name).type_match_operands;
return 0;
}

// infer the index width of a meter/counter/register based on the instance count
// default to 32 bits if we can't figure it out
int IR::Stateful::index_width() const {
return instance_count > 1 ? ceil_log2(instance_count) : 32;
return instance_count > 1 ? ceil_log2(instance_count) : 32;
}

static int inferIndexWidth(const IR::Expression *obj) {
if (auto *glob = obj->to<IR::GlobalRef>())
if (auto *sful = glob->obj->to<IR::Stateful>()) return sful->index_width();
return 32;
if (auto *glob = obj->to<IR::GlobalRef>())
if (auto *sful = glob->obj->to<IR::Stateful>()) return sful->index_width();
return 32;
}

const IR::Type *IR::Primitive::inferOperandType(int operand) const {
const IR::Type *rv = IR::Type::Unknown::get();
unsigned infer = 0;

if (prim_info.count(name)) infer = prim_info.at(name).type_match_operands;

if ((infer >> operand) & 1) {
for (auto o : operands) {
if ((infer & 1) && o->type != rv) {
rv = o->type;
break;
}
infer >>= 1;
const IR::Type *rv = IR::Type::Unknown::get();
unsigned infer = 0;

if (prim_info.count(name)) infer = prim_info.at(name).type_match_operands;

if ((infer >> operand) & 1) {
for (auto o : operands) {
if ((infer & 1) && o->type != rv) {
rv = o->type;
break;
}
return rv;
}
if (name == "truncate") return IR::Type::Bits::get(32);
if ((name == "count" || name == "execute_meter") && operand == 1)
return IR::Type::Bits::get(inferIndexWidth(operands.at(0)));
if (name.startsWith("execute_stateful") && operand == 1) return IR::Type::Bits::get(32);
if ((name == "clone_ingress_pkt_to_egress" || name == "clone_i2e" ||
name == "clone_egress_pkt_to_egress" || name == "clone_e2e") &&
operand == 0) {
return IR::Type::Bits::get(32);
}
if ((name == "execute") && operand == 2)
return IR::Type::Bits::get(inferIndexWidth(operands.at(0)));
if (name == "modify_field_conditionally" && operand == 1) return IR::Type::Bits::get(1);
if (name == "register_read" && operand == 2)
return IR::Type::Bits::get(inferIndexWidth(operands.at(1)));
if (name == "register_write" && operand == 1)
return IR::Type::Bits::get(inferIndexWidth(operands.at(0)));
if (name == "shift_left" && operand == 1) {
if (operands.at(0)->type->width_bits() > operands.at(1)->type->width_bits())
return operands.at(0)->type;
return IR::Type::Unknown::get();
}
if (name == "shift_right" && operand == 1) {
if (operands.at(0)->type->width_bits() > operands.at(1)->type->width_bits())
return operands.at(0)->type;
return IR::Type::Unknown::get();
infer >>= 1;
}
return rv;
}
if (name == "truncate") return IR::Type::Bits::get(32);
if ((name == "count" || name == "execute_meter") && operand == 1)
return IR::Type::Bits::get(inferIndexWidth(operands.at(0)));
if (name.startsWith("execute_stateful") && operand == 1) return IR::Type::Bits::get(32);
if ((name == "clone_ingress_pkt_to_egress" || name == "clone_i2e" ||
name == "clone_egress_pkt_to_egress" || name == "clone_e2e") &&
operand == 0) {
return IR::Type::Bits::get(32);
}
if ((name == "execute") && operand == 2)
return IR::Type::Bits::get(inferIndexWidth(operands.at(0)));
if (name == "modify_field_conditionally" && operand == 1) return IR::Type::Bits::get(1);
if (name == "register_read" && operand == 2)
return IR::Type::Bits::get(inferIndexWidth(operands.at(1)));
if (name == "register_write" && operand == 1)
return IR::Type::Bits::get(inferIndexWidth(operands.at(0)));
if (name == "shift_left" && operand == 1) {
if (operands.at(0)->type->width_bits() > operands.at(1)->type->width_bits())
return operands.at(0)->type;
return IR::Type::Unknown::get();
}
if (name == "shift_right" && operand == 1) {
if (operands.at(0)->type->width_bits() > operands.at(1)->type->width_bits())
return operands.at(0)->type;
return IR::Type::Unknown::get();
}
return rv;
}

IR::V1Program::V1Program() {
// This is used to typecheck P4-14 programs
auto *standard_metadata_t = new IR::Type_Struct(
"standard_metadata_t",
{new IR::StructField("ingress_port", IR::Type::Bits::get(9)),
new IR::StructField("packet_length", IR::Type::Bits::get(32)),
new IR::StructField("egress_spec", IR::Type::Bits::get(9)),
new IR::StructField("egress_port", IR::Type::Bits::get(9)),
new IR::StructField("egress_instance", IR::Type::Bits::get(16)),
new IR::StructField("instance_type", IR::Type::Bits::get(32)),
new IR::StructField("parser_status", IR::Type::Bits::get(8)),
new IR::StructField("parser_error_location", IR::Type::Bits::get(8))});
scope.add("standard_metadata_t", new IR::v1HeaderType(standard_metadata_t));
scope.add("standard_metadata", new IR::Metadata("standard_metadata", standard_metadata_t));
// This is used to typecheck P4-14 programs
auto *standard_metadata_t =
new IR::Type_Struct("standard_metadata_t",
{new IR::StructField("ingress_port", IR::Type::Bits::get(9)),
new IR::StructField("packet_length", IR::Type::Bits::get(32)),
new IR::StructField("egress_spec", IR::Type::Bits::get(9)),
new IR::StructField("egress_port", IR::Type::Bits::get(9)),
new IR::StructField("egress_instance", IR::Type::Bits::get(16)),
new IR::StructField("instance_type", IR::Type::Bits::get(32)),
new IR::StructField("parser_status", IR::Type::Bits::get(8)),
new IR::StructField("parser_error_location", IR::Type::Bits::get(8))});
scope.add("standard_metadata_t", new IR::v1HeaderType(standard_metadata_t));
scope.add("standard_metadata", new IR::Metadata("standard_metadata", standard_metadata_t));
}
4 changes: 2 additions & 2 deletions ir/visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,8 @@ std::ostream &operator<<(std::ostream &out, const ControlFlowVisitor::flow_join_
out << Brief;
for (auto &i : info.parents) {
out << Log::endl
<< " " << *i.first << " [" << i.first->id << "] "
<< "exist=" << i.second.exist << " visited=" << i.second.visited;
<< " " << *i.first << " [" << i.first->id << "] " << "exist=" << i.second.exist
<< " visited=" << i.second.visited;
}
dbsetflags(out, flags);
#endif
Expand Down
2 changes: 1 addition & 1 deletion lib/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ limitations under the License.
#include <set>

// Round up x/y, for integers
#define ROUNDUP(x, y) (((x) + (y)-1) / (y))
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y))
// Elements in an array
#define ELEMENTS(a) (sizeof(a) / sizeof(a[0]))

Expand Down
Loading
Loading