Skip to content

Commit 0c3e24f

Browse files
authored
[analyzer] Allow egraph rewriter not to open the generated HTML directly (#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.
1 parent 29318ab commit 0c3e24f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

clang/utils/analyzer/exploded-graph-rewriter.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,19 @@ def add_raw_line(self, raw_line):
479479
# A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
480480
# syntax highlighing.
481481
class DotDumpVisitor:
482-
def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only):
482+
def __init__(
483+
self, do_diffs, dark_mode, gray_mode, topo_mode, dump_html_only, dump_dot_only
484+
):
485+
assert not (dump_html_only and dump_dot_only), (
486+
"Option dump_html_only and dump_dot_only are conflict, "
487+
"they cannot be true at the same time."
488+
)
489+
483490
self._do_diffs = do_diffs
484491
self._dark_mode = dark_mode
485492
self._gray_mode = gray_mode
486493
self._topo_mode = topo_mode
494+
self._dump_html_only = dump_html_only
487495
self._dump_dot_only = dump_dot_only
488496
self._output = []
489497

@@ -998,6 +1006,8 @@ def write_temp_file(suffix, prefix, data):
9981006
'<html><body bgcolor="%s">%s</body></html>'
9991007
% ("#1a1a1a" if self._dark_mode else "white", svg),
10001008
)
1009+
if self._dump_html_only:
1010+
return
10011011
if sys.platform == "win32":
10021012
os.startfile(filename)
10031013
elif sys.platform == "darwin":
@@ -1176,7 +1186,17 @@ def main():
11761186
default=False,
11771187
help="black-and-white mode",
11781188
)
1179-
parser.add_argument(
1189+
dump_conflict = parser.add_mutually_exclusive_group()
1190+
dump_conflict.add_argument(
1191+
"--dump-html-only",
1192+
action="store_const",
1193+
dest="dump_html_only",
1194+
const=True,
1195+
default=False,
1196+
help="dump the rewritten egraph to a temporary HTML file, "
1197+
"but do not open it immediately as by default",
1198+
)
1199+
dump_conflict.add_argument(
11801200
"--dump-dot-only",
11811201
action="store_const",
11821202
dest="dump_dot_only",
@@ -1206,7 +1226,12 @@ def main():
12061226
explorer = BasicExplorer()
12071227

12081228
visitor = DotDumpVisitor(
1209-
args.diff, args.dark, args.gray, args.topology, args.dump_dot_only
1229+
args.diff,
1230+
args.dark,
1231+
args.gray,
1232+
args.topology,
1233+
args.dump_html_only,
1234+
args.dump_dot_only,
12101235
)
12111236

12121237
for trimmer in trimmers:

0 commit comments

Comments
 (0)