Skip to content

Commit

Permalink
Improve const-correctness
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
  • Loading branch information
asl committed Sep 10, 2024
1 parent 31c4540 commit d01998e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
9 changes: 4 additions & 5 deletions frontends/p4/def_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ void ComputeWriteSet::enterScope(const IR::ParameterList *parameters,

if (parameters != nullptr) {
for (auto p : parameters->parameters) {
StorageLocation *loc = allDefinitions->getOrAddStorage(p);
const StorageLocation *loc = allDefinitions->getOrAddStorage(p);
if (loc == nullptr) continue;
if (p->direction == IR::Direction::In || p->direction == IR::Direction::InOut ||
p->direction == IR::Direction::None)
Expand All @@ -410,8 +410,7 @@ void ComputeWriteSet::enterScope(const IR::ParameterList *parameters,
if (locals != nullptr) {
for (auto d : *locals) {
if (d->is<IR::Declaration_Variable>()) {
StorageLocation *loc = allDefinitions->getOrAddStorage(d);
if (loc != nullptr) {
if (const StorageLocation *loc = allDefinitions->getOrAddStorage(d)) {
defs->setDefinition(loc, uninit);
defs->setDefinition(loc->getValidBits(), startPoints);
defs->setDefinition(loc->getLastIndexField(), startPoints);
Expand All @@ -434,7 +433,7 @@ void ComputeWriteSet::exitScope(const IR::ParameterList *parameters,
currentDefinitions = currentDefinitions->cloneDefinitions();
if (parameters != nullptr) {
for (auto p : parameters->parameters) {
StorageLocation *loc = allDefinitions->getStorage(p);
const StorageLocation *loc = allDefinitions->getStorage(p);
if (loc != nullptr) {
LOG5("Removing location " << loc);
currentDefinitions->removeLocation(loc);
Expand All @@ -444,7 +443,7 @@ void ComputeWriteSet::exitScope(const IR::ParameterList *parameters,
if (locals != nullptr) {
for (auto d : *locals) {
if (d->is<IR::Declaration_Variable>()) {
StorageLocation *loc = allDefinitions->getStorage(d);
const StorageLocation *loc = allDefinitions->getStorage(d);
if (loc != nullptr) {
LOG5("Removing location " << loc);
currentDefinitions->removeLocation(loc);
Expand Down
14 changes: 7 additions & 7 deletions frontends/p4/def_use.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class LocationSet : public IHasDbPrint {
/// Maps a declaration to its associated storage.
class StorageMap : public IHasDbPrint {
/// Storage location for each declaration.
hvec_map<const IR::IDeclaration *, StorageLocation *> storage;
hvec_map<const IR::IDeclaration *, const StorageLocation *> storage;
StorageFactory factory;

public:
Expand All @@ -366,19 +366,19 @@ class StorageMap : public IHasDbPrint {
CHECK_NULL(refMap);
CHECK_NULL(typeMap);
}
StorageLocation *add(const IR::IDeclaration *decl) {
const StorageLocation *add(const IR::IDeclaration *decl) {
CHECK_NULL(decl);
auto type = typeMap->getType(decl->getNode(), true);
auto loc = factory.create(type, decl->getName() + "/" + decl->externalName());
if (loc != nullptr) storage.emplace(decl, loc);
return loc;
}
StorageLocation *getOrAdd(const IR::IDeclaration *decl) {
auto s = getStorage(decl);
const StorageLocation *getOrAdd(const IR::IDeclaration *decl) {
const auto *s = getStorage(decl);
if (s != nullptr) return s;
return add(decl);
}
StorageLocation *getStorage(const IR::IDeclaration *decl) const {
const StorageLocation *getStorage(const IR::IDeclaration *decl) const {
CHECK_NULL(decl);
auto result = ::P4::get(storage, decl);
return result;
Expand Down Expand Up @@ -580,11 +580,11 @@ class AllDefinitions : public IHasDbPrint {
atPoint[point] = defs;
}

StorageLocation *getStorage(const IR::IDeclaration *decl) const {
const StorageLocation *getStorage(const IR::IDeclaration *decl) const {
return storageMap.getStorage(decl);
}

StorageLocation *getOrAddStorage(const IR::IDeclaration *decl) {
const StorageLocation *getOrAddStorage(const IR::IDeclaration *decl) {
return storageMap.getOrAdd(decl);
}

Expand Down

0 comments on commit d01998e

Please sign in to comment.