Skip to content
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
22 changes: 18 additions & 4 deletions cfg/CFG.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ string CFG::toString(const core::GlobalState &gs) const {
return to_string(buf);
}

string CFG::toTextualString(const core::GlobalState &gs) const {
string CFG::toTextualString(const core::GlobalState &gs, optional<core::FileRef> file) const {
fmt::memory_buffer buf;
string symbolName = this->symbol.showFullName(gs);
fmt::format_to(std::back_inserter(buf), "method {} {{\n\n", symbolName);
Expand All @@ -251,7 +251,7 @@ string CFG::toTextualString(const core::GlobalState &gs) const {
}
}

fmt::format_to(std::back_inserter(buf), "{}\n", basicBlock->toTextualString(gs, *this));
fmt::format_to(std::back_inserter(buf), "{}\n", basicBlock->toTextualString(gs, file, *this));
}
fmt::format_to(std::back_inserter(buf), "}}");
return to_string(buf);
Expand Down Expand Up @@ -366,7 +366,7 @@ string BasicBlock::toString(const core::GlobalState &gs, const CFG &cfg) const {
return to_string(buf);
}

string BasicBlock::toTextualString(const core::GlobalState &gs, const CFG &cfg) const {
string BasicBlock::toTextualString(const core::GlobalState &gs, optional<core::FileRef> file, const CFG &cfg) const {
fmt::memory_buffer buf;
fmt::format_to(std::back_inserter(buf), "bb{}[rubyRegionId={}, firstDead={}]({}):\n", this->id, this->rubyRegionId,
this->firstDeadInstructionIdx,
Expand All @@ -377,7 +377,21 @@ string BasicBlock::toTextualString(const core::GlobalState &gs, const CFG &cfg)
fmt::format_to(std::back_inserter(buf), " # outerLoops: {}\n", this->outerLoops);
}
for (const Binding &exp : this->exprs) {
fmt::format_to(std::back_inserter(buf), " {} = {}\n", exp.bind.toString(gs, cfg),
string positionText = "";
if (file) {
if (exp.loc.exists() && !exp.loc.empty()) {
auto lineCol = core::Loc(file.value(), exp.loc).position(gs);
positionText =
lineCol.first.line == lineCol.second.line
? fmt::format(" @ {}:{}-{}", lineCol.first.line, lineCol.first.column, lineCol.second.column)
: fmt::format(" @ {}:{}-{}:{}", lineCol.first.line, lineCol.first.column, lineCol.second.line,
lineCol.second.column);
} else {
positionText = " @ <>";
}
}

fmt::format_to(std::back_inserter(buf), " {}{} = {}\n", exp.bind.toString(gs, cfg), positionText,
exp.value.toString(gs, cfg));
}

Expand Down
4 changes: 2 additions & 2 deletions cfg/CFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class BasicBlock final {
std::optional<BlockExitCondInfo> maybeGetUpdateKnowledgeReceiver(const cfg::CFG &inWhat) const;

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

Expand Down Expand Up @@ -166,7 +166,7 @@ class CFG final {
// Abbreviated debug output in dot format, useful if you already know what you're looking at
std::string toString(const core::GlobalState &gs) const;
// As above, but without dot annotations
std::string toTextualString(const core::GlobalState &gs) const;
std::string toTextualString(const core::GlobalState &gs, std::optional<core::FileRef> = std::nullopt) const;
// Verbose debug output
std::string showRaw(core::Context ctx) const;

Expand Down
4 changes: 2 additions & 2 deletions docs/scip-ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ along with the control flow graph all at once.
Typically, I'll copy over the minimized code
to the root and run:

```
./bazel build //main:scip-ruby --config=dbg && ./bazel-out/darwin-dbg/bin/main/scip-ruby tmp.rb -p cfg-text --index-file /dev/null
```bash
./bazel build //main:scip-ruby --config=dbg && ./bazel-out/darwin-dbg/bin/main/scip-ruby tmp.rb -p cfg-text-loc --index-file /dev/null
```

Alternately, it may be useful to create a `tmp.rb`
Expand Down
2 changes: 2 additions & 0 deletions main/options/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const vector<PrintOptions> print_options({
{"cfg", &Printers::CFG},
{"cfg-raw", &Printers::CFGRaw},
{"cfg-text", &Printers::CFGText},
{"cfg-text-loc", &Printers::CFGTextLoc},
{"symbol-table", &Printers::SymbolTable},
{"symbol-table-raw", &Printers::SymbolTableRaw},
{"symbol-table-json", &Printers::SymbolTableJson},
Expand Down Expand Up @@ -128,6 +129,7 @@ vector<reference_wrapper<PrinterConfig>> Printers::printers() {
ASTRaw,
CFG,
CFGText,
CFGTextLoc,
CFGRaw,
SymbolTable,
SymbolTableRaw,
Expand Down
1 change: 1 addition & 0 deletions main/options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct Printers {
PrinterConfig ASTRaw;
PrinterConfig CFG;
PrinterConfig CFGText;
PrinterConfig CFGTextLoc;
PrinterConfig CFGRaw;
PrinterConfig TypedSource;
PrinterConfig SymbolTable;
Expand Down
3 changes: 3 additions & 0 deletions main/pipeline/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class CFGCollectorAndTyper {
if (print.CFGText.enabled) {
print.CFG.fmt("{}\n\n", cfg->toTextualString(ctx));
}
if (print.CFGTextLoc.enabled) {
print.CFG.fmt("{}\n\n", cfg->toTextualString(ctx, ctx.file));
}
if (print.CFGRaw.enabled) {
print.CFGRaw.fmt("{}\n\n", cfg->showRaw(ctx));
}
Expand Down