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

Mbudiu #41

Closed
wants to merge 4 commits into from
Closed
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
16 changes: 8 additions & 8 deletions backends/bmv2/inlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ const IR::Node* SimpleControlsInliner::preorder(IR::P4Control* caller) {

workToDo = &toInline->callerToWork[orig];
LOG1("Simple inliner " << caller);
auto stateful = new IR::NameMap<IR::Declaration, ordered_map>();
for (auto s : *caller->statefulEnumerator()) {
auto stateful = new IR::IndexedVector<IR::Declaration>();
for (auto s : *caller->stateful) {
auto inst = s->to<IR::Declaration_Instance>();
if (inst == nullptr ||
workToDo->declToCallee.find(inst) == workToDo->declToCallee.end()) {
// If some element with the same name is already there we don't reinsert it
// since this program is generated from a P4 v1.0 program by duplicating
// elements.
if (stateful->getUnique(s->name) == nullptr)
stateful->addUnique(s->name, s);
if (stateful->getDeclaration(s->name) == nullptr)
stateful->push_back(s);
} else {
auto callee = workToDo->declToCallee[inst];
CHECK_NULL(callee);
Expand All @@ -47,17 +47,17 @@ const IR::Node* SimpleControlsInliner::preorder(IR::P4Control* caller) {
auto clone = callee->getNode()->apply(sp);
if (clone == nullptr)
return caller;
for (auto i : *clone->to<IR::P4Control>()->statefulEnumerator()) {
if (stateful->getUnique(i->name) == nullptr)
stateful->addUnique(i->name, i);
for (auto i : *clone->to<IR::P4Control>()->stateful) {
if (stateful->getDeclaration(i->name) == nullptr)
stateful->push_back(i);
}
workToDo->declToCallee[inst] = clone->to<IR::IContainer>();
}
}

visit(caller->body);
auto result = new IR::P4Control(caller->srcInfo, caller->name, caller->type,
caller->constructorParams, std::move(*stateful),
caller->constructorParams, stateful,
caller->body);
list->replace(orig, result);
workToDo = nullptr;
Expand Down
14 changes: 7 additions & 7 deletions backends/bmv2/jsonconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void JsonConverter::addToFieldList(const IR::Expression* expr, Util::JsonArray*
if (type->is<IR::Type_StructLike>()) {
// recursively add all fields
auto st = type->to<IR::Type_StructLike>();
for (auto f : *st->getEnumerator()) {
for (auto f : *st->fields) {
auto member = new IR::Member(Util::SourceInfo(), expr, f->name);
typeMap->setType(member, typeMap->getType(f, true));
addToFieldList(member, fl);
Expand Down Expand Up @@ -1288,7 +1288,7 @@ Util::IJson* JsonConverter::convertControl(const IR::ControlBlock* block, cstrin
tables->append(exitTable);
}

for (auto c : *cont->statefulEnumerator()) {
for (auto c : *cont->stateful) {
if (c->is<IR::Declaration_Constant>() ||
c->is<IR::Declaration_Variable>() ||
c->is<IR::P4Action>() ||
Expand Down Expand Up @@ -1400,7 +1400,7 @@ unsigned JsonConverter::nextId(cstring group) {
void JsonConverter::addHeaderStacks(const IR::Type_Struct* headersStruct,
Util::JsonArray* headers, Util::JsonArray* headerTypes,
Util::JsonArray* stacks, std::set<cstring> &headerTypesDone) {
for (auto f : *headersStruct->getEnumerator()) {
for (auto f : *headersStruct->fields) {
auto ft = typeMap->getType(f->type, true);
auto stack = ft->to<IR::Type_Stack>();
if (stack == nullptr)
Expand Down Expand Up @@ -1647,7 +1647,7 @@ void JsonConverter::createForceArith(const IR::Type* meta, cstring name,
Util::JsonArray* force) const {
BUG_CHECK(meta->is<IR::Type_Struct>(), "Expected a struct type");
auto st = meta->to<IR::Type_StructLike>();
for (auto f : *st->getEnumerator()) {
for (auto f : *st->fields) {
auto field = pushNewArray(force);
field->append(name);
field->append(f->name.name);
Expand Down Expand Up @@ -1697,7 +1697,7 @@ void JsonConverter::addTypesAndInstances(const IR::Type_StructLike* type, bool m
Util::JsonArray* headerTypes, Util::JsonArray* instances,
std::set<cstring> &headerTypesCreated) {
// TODO: this is wrong if the structs are more deeply nested.
for (auto f : *type->getEnumerator()) {
for (auto f : *type->fields) {
auto ft = typeMap->getType(f->type, true);
if (ft->is<IR::Type_StructLike>()) {
auto st = ft->to<IR::Type_StructLike>();
Expand All @@ -1709,7 +1709,7 @@ void JsonConverter::addTypesAndInstances(const IR::Type_StructLike* type, bool m
}
}

for (auto f : *type->getEnumerator()) {
for (auto f : *type->fields) {
auto ft = typeMap->getType(f->type, true);
if (ft->is<IR::Type_StructLike>()) {
auto json = new Util::JsonObject();
Expand All @@ -1732,7 +1732,7 @@ Util::IJson* JsonConverter::typeToJson(const IR::Type_StructLike* st) {
result->emplace("name", nameFromAnnotation(st->annotations, st->name.name));
result->emplace("id", nextId("header_types"));
auto fields = mkArrayField(result, "fields");
for (auto f : *st->getEnumerator()) {
for (auto f : *st->fields) {
auto field = pushNewArray(fields);
field->append(f->name.name);
auto ftype = typeMap->getType(f->type, true);
Expand Down
36 changes: 17 additions & 19 deletions backends/ebpf/codeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ bool CodeGenInspector::preorder(const IR::Type_Enum* type) {
builder->append(type->name);
builder->spc();
builder->blockStart();
for (auto e : *type->getEnumerator()) {
for (auto e : *type->getDeclarations()) {
builder->emitIndent();
builder->append(e->name.name);
builder->append(e->getName().name);
builder->appendLine(",");
}
builder->blockEnd(true);
Expand Down Expand Up @@ -235,22 +235,20 @@ void CodeGenInspector::widthCheck(const IR::Node* node) const {
::error("%1%: Computations on %2% bits not supported", node, tb->size);
}

#define VECTOR_VISIT(T) \
bool CodeGenInspector::preorder(const IR::Vector<IR::T> *v) { \
if (v == nullptr) return false; \
bool first = true; \
VecPrint sep = getSep(); \
for (auto a : *v) { \
if (!first) { \
builder->append(sep.separator); } \
if (sep.separator.endsWith("\n")) { \
builder->emitIndent(); } \
first = false; \
visit(a); } \
if (!v->empty() && !sep.terminator.isNullOrEmpty()) { \
builder->append(sep.terminator); } \
return false; }

VECTOR_VISIT(StatOrDecl)
bool CodeGenInspector::preorder(const IR::IndexedVector<IR::StatOrDecl> *v) {
if (v == nullptr) return false;
bool first = true;
VecPrint sep = getSep();
for (auto a : *v) {
if (!first) {
builder->append(sep.separator); }
if (sep.separator.endsWith("\n")) {
builder->emitIndent(); }
first = false;
visit(a); }
if (!v->empty() && !sep.terminator.isNullOrEmpty()) {
builder->append(sep.terminator); }
return false;
}

} // namespace EBPF
2 changes: 1 addition & 1 deletion backends/ebpf/codeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CodeGenInspector : public Inspector {
bool preorder(const IR::Equ* e) override { return comparison(e); }
bool preorder(const IR::Neq* e) override { return comparison(e); }

bool preorder(const IR::Vector<IR::StatOrDecl>* v) override;
bool preorder(const IR::IndexedVector<IR::StatOrDecl>* v) override;
bool preorder(const IR::Path* path) override;

bool preorder(const IR::Type_Typedef* type) override;
Expand Down
6 changes: 3 additions & 3 deletions backends/ebpf/ebpfControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ bool EBPFControl::build() {
return false;
}

auto it = pl->parameters.begin();
headers = it->second;
auto it = pl->parameters->begin();
headers = *it;
++it;
accept = it->second;
accept = *it;

for (auto c : controlBlock->constantValue) {
auto b = c.second;
Expand Down
4 changes: 2 additions & 2 deletions backends/ebpf/ebpfObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class ErrorCodesVisitor : public Inspector {
public:
explicit ErrorCodesVisitor(CodeBuilder* builder) : builder(builder) {}
bool preorder(const IR::Declaration_Errors* errors) override {
for (auto m : *errors->getEnumerator()) {
for (auto m : *errors->getDeclarations()) {
builder->emitIndent();
builder->appendFormat("%s,\n", m->name.name.c_str());
builder->appendFormat("%s,\n", m->getName().name.c_str());
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions backends/ebpf/ebpfParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ StateTranslationVisitor::compileExtract(const IR::Vector<IR::Expression>* args)
}

unsigned alignment = 0;
for (auto f : *ht->getEnumerator()) {
for (auto f : *ht->fields) {
auto ftype = state->parser->typeMap->getType(f);
auto etype = EBPFTypeFactory::instance->create(ftype);
auto et = dynamic_cast<IHasWidth*>(etype);
Expand Down Expand Up @@ -327,9 +327,9 @@ bool EBPFParser::build() {
}

// TODO: more checks on these parameter types
auto it = pl->parameters.begin();
packet = it->second; ++it;
headers = it->second;
auto it = pl->parameters->begin();
packet = *it; ++it;
headers = *it;
for (auto state : *parserBlock->container->states) {
auto ps = new EBPFParserState(state, this);
states.push_back(ps);
Expand Down
2 changes: 1 addition & 1 deletion backends/ebpf/ebpfType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ EBPFStructType::EBPFStructType(const IR::Type_StructLike* strct) :
width = 0;
implWidth = 0;

for (auto f : *strct->getEnumerator()) {
for (auto f : *strct->fields) {
auto type = EBPFTypeFactory::instance->create(f->type);
auto wt = dynamic_cast<IHasWidth*>(type);
if (wt == nullptr) {
Expand Down
Loading