Skip to content

Cleanups: doc comments, debugging, fix type name collision #10

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

Merged
merged 3 commits into from
Jul 10, 2022
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
4 changes: 2 additions & 2 deletions cfg/Instructions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ string TAbsurd::showRaw(const core::GlobalState &gs, const CFG &cfg, int tabs) c
this->what.showRaw(gs, cfg, tabs + 1));
}

string LocalOccurrence::toString(const core::GlobalState &gs, core::FileRef file, const CFG &cfg) const {
return fmt::format("local_occ {} @ {}", this->variable.toString(gs, cfg), core::Loc(file, this->loc).toString(gs));
string LocalOccurrence::showRaw(const core::GlobalState &gs, core::FileRef file, const CFG &cfg) const {
return fmt::format("local_occ {} @ {}", this->variable.toString(gs, cfg), core::Loc(file, this->loc).showRaw(gs));
}

string VariableUseSite::toString(const core::GlobalState &gs, const CFG &cfg) const {
Expand Down
2 changes: 1 addition & 1 deletion cfg/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct LocalOccurrence final {
return {variable, core::LocOffsets::none()};
}

std::string toString(const core::GlobalState &gs, core::FileRef file, const CFG &cfg) const;
std::string showRaw(const core::GlobalState &gs, core::FileRef file, const CFG &cfg) const;
};

class VariableUseSite final {
Expand Down
17 changes: 10 additions & 7 deletions scip_indexer/SCIPIndexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static bool isTemporary(const core::GlobalState &gs, const core::LocalVariable &
n == Names::unconditional();
}

struct LocalOccurrence {
struct OwnedLocal {
/// Parent method.
const core::SymbolRef owner;
/// Counter corresponding to the local's definition, unique within a method.
Expand Down Expand Up @@ -272,7 +272,7 @@ class SCIPState {
}

public:
absl::Status saveDefinition(const core::GlobalState &gs, core::FileRef file, LocalOccurrence occ) {
absl::Status saveDefinition(const core::GlobalState &gs, core::FileRef file, OwnedLocal occ) {
return this->saveDefinitionImpl(gs, file, occ.toString(gs, file), core::Loc(file, occ.offsets));
}

Expand All @@ -296,8 +296,7 @@ class SCIPState {
return this->saveDefinitionImpl(gs, file, symbolString, occLocStatus.value());
}

absl::Status saveReference(const core::GlobalState &gs, core::FileRef file, LocalOccurrence occ,
int32_t symbol_roles) {
absl::Status saveReference(const core::GlobalState &gs, core::FileRef file, OwnedLocal occ, int32_t symbol_roles) {
return this->saveReferenceImpl(gs, file, occ.toString(gs, file), occ.offsets, symbol_roles);
}

Expand Down Expand Up @@ -361,6 +360,7 @@ class CFGTraversal final {
UnorderedMap<const cfg::BasicBlock *, UnorderedMap<cfg::LocalRef, core::Loc>> blockLocals;
UnorderedMap<cfg::LocalRef, uint32_t> functionLocals;

// Local variable counter that is reset for every function.
uint32_t counter = 0;
SCIPState &scipState;
core::Context ctx;
Expand All @@ -387,6 +387,9 @@ class CFGTraversal final {
RValue,
};

// Emit an occurrence for a local variable if applicable.
//
// Returns true if an occurrence was emitted.
bool emitLocalOccurrence(const cfg::CFG &cfg, const cfg::BasicBlock *bb, cfg::LocalOccurrence local,
ValueCategory category) {
auto localRef = local.variable;
Expand Down Expand Up @@ -436,10 +439,10 @@ class CFGTraversal final {
absl::Status status;
if (isDefinition) {
status = this->scipState.saveDefinition(this->ctx.state, this->ctx.file,
LocalOccurrence{this->ctx.owner, localId, local.loc});
OwnedLocal{this->ctx.owner, localId, local.loc});
} else {
status = this->scipState.saveReference(this->ctx.state, this->ctx.file,
LocalOccurrence{this->ctx.owner, localId, local.loc}, referenceRole);
OwnedLocal{this->ctx.owner, localId, local.loc}, referenceRole);
}
ENFORCE_NO_TIMER(status.ok());
return true;
Expand Down Expand Up @@ -550,7 +553,7 @@ class CFGTraversal final {
// Emit references for arguments
for (auto &arg : send->args) {
// NOTE: For constructs like a += b, the instruction sequence ends up being:
// $tmp = $b
// $tmp = $a
// $a = $tmp.+($b)
// The location for $tmp will point to $a in the source. However, the second one is a read,
// and the first one is a write. Instead of emitting two occurrences, it'd be nice to emit
Expand Down