Skip to content
leissaPublic

About

A simple graph tool.

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

GraphTool

linux macos windows

A small tool that reads a subset from Graphviz' DOT language and calculates several dominance-related properties:

  • pre-, post-, and reverse-post order numbers for the input rooted at the entry and exit
  • dominance tree
  • postdominance tree
  • dominance frontiers
  • postdominance tree frontieres (aka control dependence)
  • optionally eliminate critical edges beforehand

Usage

Usage: graphtool [options] <file>

Computes dominance-related properties of a Graphviz DOT digraph.

Arguments:
  <file>                   Input file.

Options:
  -h, --help               Display this help and exit.
  -v, --version            Display version info and exit.
  -c, --crit               Eliminate critical edges.
  -V, --verbose            Raises the log level from error to warn (unreachable
                           nodes) and info (the chosen exit); repeatable.

Diagnostics:
      --loc-style <style>  How a diagnostic spells out a source location: `full`
                           (`path:row:col-row:col`), `rowcol` (`path:row:col`),
                           `row` (`path:row`), or msvc (`path(row,col)`).
      --no-snippet         Does not render the offending source line and caret
                           underneath a diagnostic.
      --gutter <width>     Width of a diagnostic's line-number column. [default:
                           `5`]
      --max-rows <num>     Maximum number of rows a diagnostic's snippet renders
                           before eliding its middle; `0` elides nothing.
                           [default: `8`]
      --max-errors <num>   Maximum number of errors to report before dropping
                           the rest; `0` reports all of them. [default: `0`]
      --werror             Treats warnings as errors.

The results are written next to `<file>` as `<file>.forward.dot`, `<file>.backward.dot`, `<file>.dom_tree.dot`, `<file>.postdom_tree.dot`, `<file>.dom_frontiers.dot`, and `<file>.postdom_frontiers.dot`.

Building

If you have a GitHub account setup with SSH, just do this:

git clone --recurse-submodules git@github.com:leissa/graphtool.git

Otherwise, clone via HTTPS:

git clone --recurse-submodules https://github.com/leissa/graphtool.git

Then, build with:

cd graphtool
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j $(nproc)

For a Release build simply use -DCMAKE_BUILD_TYPE=Release. GraphTool needs CMake 3.29 and a C++23 compiler; it builds upon FE, which lives in submodules/fe.

Invoke the GraphTool like so:

./build/bin/graphtool test/test.dot

Testing

test/run.sh is GraphTool's test suite. Every input in test/ yields two cases - <name> and <name>-c (the same input with -c) - and each case runs GraphTool in build/test/<case>/ and diffs all six results against the blessed copies test/golden/<case>.<suffix>.dot:

test/run.sh                  # run all cases
test/run.sh cytron cytron-c  # run only these two
test/run.sh --valgrind       # additionally demand a clean Valgrind report
test/run.sh --bless          # accept the current results as the new golden files

CMake registers one CTest per case - unless you configure with -DBUILD_TESTING=OFF - so the same suite also runs as:

make -C build test                               # or: ninja -C build test
ctest --test-dir build --output-on-failure       # if you want to see why a case failed

This is exactly what CI does, too.

Grammar

d = 'digraph' ID g                  (* digraph *)
g = '{' S '}'                       (* subgraph *)
S = s ... s                         (* statement list *)
s = ','
  | ';'
  | (ID | g) '->' ... '->' (ID | g) (* edge statement *)

where

  • ID = [a-zA-Z][a-zA-Z0-9]*

In addition, GraphTool supports

  • /* C-style */ and
  • // C++-style comments.

Entry & Exit

The first node mentioned is considered the entry, the last one the exit.

A node the entry does not reach takes no part in the forward results (forward, dom_tree, dom_frontiers), and a node that does not reach the exit takes no part in the backward ones (backward, postdom_tree, postdom_frontiers); see test/unreachable.dot. With -V, GraphTool logs each such node to stderr, and with -VV also the chosen exit:

I:test/unreachable.dot:9:5-9:7: exit is `_12`
W:test/unreachable.dot:6:5-6:6: `_9` is unreachable from entry `_1`
W:test/unreachable.dot:3:5-3:6: `_1` does not reach exit `_12`

About

A simple graph tool.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

Generated from leissa/let