Skip to content

Commit

Permalink
[analyzer] Allow egraph rewriter not to open the generated HTML direc…
Browse files Browse the repository at this point in the history
…tly (llvm#85515)

When developing on a headless device through SSH, we do not have a
browser or even an X environment. Hence, it would be more convenient if
the rewriter could stop before attempting to open the generated HTML
file. Then, it can be opened remotely through an HTML server.

This patch adds a new option `--dump-html-only` to make the rewriter
stop before opening the generated HTML in a browser. The new option is
marked in conflict with the existing `--dump-dot-only` option to prevent
unexpected behaviors.
  • Loading branch information
Snape3058 authored Mar 26, 2024
1 parent 29318ab commit 0c3e24f
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions clang/utils/analyzer/exploded-graph-rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,19 @@ def add_raw_line(self, raw_line):
# A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
# syntax highlighing.
class DotDumpVisitor:
def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only):
def __init__(
self, do_diffs, dark_mode, gray_mode, topo_mode, dump_html_only, dump_dot_only
):
assert not (dump_html_only and dump_dot_only), (
"Option dump_html_only and dump_dot_only are conflict, "
"they cannot be true at the same time."
)

self._do_diffs = do_diffs
self._dark_mode = dark_mode
self._gray_mode = gray_mode
self._topo_mode = topo_mode
self._dump_html_only = dump_html_only
self._dump_dot_only = dump_dot_only
self._output = []

Expand Down Expand Up @@ -998,6 +1006,8 @@ def write_temp_file(suffix, prefix, data):
'<html><body bgcolor="%s">%s</body></html>'
% ("#1a1a1a" if self._dark_mode else "white", svg),
)
if self._dump_html_only:
return
if sys.platform == "win32":
os.startfile(filename)
elif sys.platform == "darwin":
Expand Down Expand Up @@ -1176,7 +1186,17 @@ def main():
default=False,
help="black-and-white mode",
)
parser.add_argument(
dump_conflict = parser.add_mutually_exclusive_group()
dump_conflict.add_argument(
"--dump-html-only",
action="store_const",
dest="dump_html_only",
const=True,
default=False,
help="dump the rewritten egraph to a temporary HTML file, "
"but do not open it immediately as by default",
)
dump_conflict.add_argument(
"--dump-dot-only",
action="store_const",
dest="dump_dot_only",
Expand Down Expand Up @@ -1206,7 +1226,12 @@ def main():
explorer = BasicExplorer()

visitor = DotDumpVisitor(
args.diff, args.dark, args.gray, args.topology, args.dump_dot_only
args.diff,
args.dark,
args.gray,
args.topology,
args.dump_html_only,
args.dump_dot_only,
)

for trimmer in trimmers:
Expand Down

0 comments on commit 0c3e24f

Please sign in to comment.