Skip to content

Commit

Permalink
Preserve the original name when renaming declarations in the inlining…
Browse files Browse the repository at this point in the history
… pass.
  • Loading branch information
fruffy committed Aug 15, 2024
1 parent 39d9d44 commit a9726e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions frontends/p4/inlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,26 @@ class Substitutions : public SubstituteParameters {
}
const IR::Node *postorder(IR::P4Table *table) override {
auto orig = getOriginal<IR::IDeclaration>();
cstring newName = renameMap->getName(orig);
cstring extName = renameMap->getExtName(orig);
auto newName = renameMap->getName(orig);
auto extName = renameMap->getExtName(orig);
LOG3("Renaming " << dbp(orig) << " to " << newName << " (" << extName << ")");
auto annos = setNameAnnotation(extName, table->annotations);
auto result = new IR::P4Table(table->srcInfo, newName, annos, table->properties);
return result;
}
const IR::Node *postorder(IR::P4ValueSet *set) override {
auto orig = getOriginal<IR::IDeclaration>();
cstring newName = renameMap->getName(orig);
cstring extName = renameMap->getExtName(orig);
auto newName = renameMap->getName(orig);
auto extName = renameMap->getExtName(orig);
LOG3("Renaming " << dbp(orig) << " to " << newName << "(" << extName << ")");
auto annos = setNameAnnotation(extName, set->annotations);
auto result = new IR::P4ValueSet(set->srcInfo, newName, annos, set->elementType, set->size);
return result;
}
const IR::Node *postorder(IR::P4Action *action) override {
auto orig = getOriginal<IR::IDeclaration>();
cstring newName = renameMap->getName(orig);
cstring extName = renameMap->getExtName(orig);
auto newName = renameMap->getName(orig);
auto extName = renameMap->getExtName(orig);
LOG3("Renaming " << dbp(orig) << " to " << newName << "(" << extName << ")");
auto annos = setNameAnnotation(extName, action->annotations);
auto result =
Expand All @@ -273,8 +273,8 @@ class Substitutions : public SubstituteParameters {
}
const IR::Node *postorder(IR::Declaration_Instance *instance) override {
auto orig = getOriginal<IR::IDeclaration>();
cstring newName = renameMap->getName(orig);
cstring extName = renameMap->getExtName(orig);
auto newName = renameMap->getName(orig);
auto extName = renameMap->getExtName(orig);
LOG3("Renaming " << dbp(orig) << " to " << newName << "(" << extName << ")");
auto annos = setNameAnnotation(extName, instance->annotations);
instance->name = newName;
Expand Down Expand Up @@ -303,7 +303,7 @@ class Substitutions : public SubstituteParameters {
return value;
}

cstring newName;
IR::ID newName;
if (renameMap->isRenamed(decl))
newName = renameMap->getName(decl);
else
Expand Down
12 changes: 6 additions & 6 deletions frontends/p4/inlining.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ struct CallInfo : public IHasDbPrint {
};

class SymRenameMap {
std::map<const IR::IDeclaration *, cstring> internalName;
std::map<const IR::IDeclaration *, cstring> externalName;
std::map<const IR::IDeclaration *, IR::ID> internalName;
std::map<const IR::IDeclaration *, IR::ID> externalName;

public:
void setNewName(const IR::IDeclaration *decl, cstring name, cstring extName) {
CHECK_NULL(decl);
BUG_CHECK(!name.isNullOrEmpty() && !extName.isNullOrEmpty(), "Empty name");
LOG3("setNewName " << dbp(decl) << " to " << name);
if (internalName.find(decl) != internalName.end()) BUG("%1%: already renamed", decl);
internalName.emplace(decl, name);
externalName.emplace(decl, extName);
internalName.emplace(decl, IR::ID(name, decl->toString()));
externalName.emplace(decl, IR::ID(extName, decl->externalName()));
}
cstring getName(const IR::IDeclaration *decl) const {
IR::ID getName(const IR::IDeclaration *decl) const {
CHECK_NULL(decl);
BUG_CHECK(internalName.find(decl) != internalName.end(), "%1%: no new name", decl);
auto result = ::P4::get(internalName, decl);
return result;
}
cstring getExtName(const IR::IDeclaration *decl) const {
IR::ID getExtName(const IR::IDeclaration *decl) const {
CHECK_NULL(decl);
BUG_CHECK(externalName.find(decl) != externalName.end(), "%1%: no external name", decl);
auto result = ::P4::get(externalName, decl);
Expand Down

0 comments on commit a9726e7

Please sign in to comment.