[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)
Ella Ma via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 18 22:23:35 PDT 2024
https://github.com/Snape3058 updated https://github.com/llvm/llvm-project/pull/85515
>From 1d37cd1a7dac2ddb05fdcf125483991b3ac645d8 Mon Sep 17 00:00:00 2001
From: Ella Ma <alansnape3058 at gmail.com>
Date: Sat, 16 Mar 2024 18:25:12 +0800
Subject: [PATCH 1/3] allow egraph rewriter not to open html directly
---
.../utils/analyzer/exploded-graph-rewriter.py | 20 ++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py b/clang/utils/analyzer/exploded-graph-rewriter.py
index c7c6315a0a27d1..ffec964d8ef09a 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,12 +479,14 @@ 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_dot_only,
+ dump_html_only):
self._do_diffs = do_diffs
self._dark_mode = dark_mode
self._gray_mode = gray_mode
self._topo_mode = topo_mode
self._dump_dot_only = dump_dot_only
+ self._dump_html_only = dump_html_only
self._output = []
def _dump_raw(self, s):
@@ -998,6 +1000,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":
@@ -1176,7 +1180,8 @@ def main():
default=False,
help="black-and-white mode",
)
- parser.add_argument(
+ dump_conflict = parser.add_mutually_exclusive_group()
+ dump_conflict.add_argument(
"--dump-dot-only",
action="store_const",
dest="dump_dot_only",
@@ -1186,6 +1191,14 @@ def main():
"displaying it, dump the rewritten dot file "
"to stdout",
)
+ dump_conflict.add_argument(
+ "--dump-html-only",
+ action="store_const",
+ dest="dump_html_only",
+ const=True,
+ default=False,
+ help="do not open the generated HTML immediately",
+ )
args = parser.parse_args()
logging.basicConfig(level=args.loglevel)
@@ -1206,7 +1219,8 @@ 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_dot_only,
+ args.dump_html_only
)
for trimmer in trimmers:
>From 3e44fb5936e37f234d601e4070c9da445a2e53ba Mon Sep 17 00:00:00 2001
From: Ella Ma <alansnape3058 at gmail.com>
Date: Sat, 16 Mar 2024 19:15:11 +0800
Subject: [PATCH 2/3] fix format issues
---
clang/utils/analyzer/exploded-graph-rewriter.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py b/clang/utils/analyzer/exploded-graph-rewriter.py
index ffec964d8ef09a..1dc8a5337da598 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,8 +479,9 @@ 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,
- dump_html_only):
+ def __init__(
+ self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only, dump_html_only
+ ):
self._do_diffs = do_diffs
self._dark_mode = dark_mode
self._gray_mode = gray_mode
@@ -1219,8 +1220,12 @@ def main():
explorer = BasicExplorer()
visitor = DotDumpVisitor(
- args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
- args.dump_html_only
+ args.diff,
+ args.dark,
+ args.gray,
+ args.topology,
+ args.dump_dot_only,
+ args.dump_html_only,
)
for trimmer in trimmers:
>From d06079789551f11a8aa03e06d286d20f434be0fc Mon Sep 17 00:00:00 2001
From: Ella Ma <alansnape3058 at gmail.com>
Date: Tue, 19 Mar 2024 13:23:10 +0800
Subject: [PATCH 3/3] add assert to check the conflict; add detailed help msg;
swap the appearance dot and html
---
.../utils/analyzer/exploded-graph-rewriter.py | 28 +++++++++++--------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py b/clang/utils/analyzer/exploded-graph-rewriter.py
index 1dc8a5337da598..5eaa7738103f79 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -480,14 +480,19 @@ def add_raw_line(self, raw_line):
# syntax highlighing.
class DotDumpVisitor:
def __init__(
- self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only, dump_html_only
+ 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_dot_only = dump_dot_only
self._dump_html_only = dump_html_only
+ self._dump_dot_only = dump_dot_only
self._output = []
def _dump_raw(self, s):
@@ -1183,22 +1188,23 @@ def main():
)
dump_conflict = parser.add_mutually_exclusive_group()
dump_conflict.add_argument(
- "--dump-dot-only",
+ "--dump-html-only",
action="store_const",
- dest="dump_dot_only",
+ dest="dump_html_only",
const=True,
default=False,
- help="instead of writing an HTML file and immediately "
- "displaying it, dump the rewritten dot file "
- "to stdout",
+ help="dump the rewritten egraph to a temporary HTML file, "
+ "but do not open it immediately as by default",
)
dump_conflict.add_argument(
- "--dump-html-only",
+ "--dump-dot-only",
action="store_const",
- dest="dump_html_only",
+ dest="dump_dot_only",
const=True,
default=False,
- help="do not open the generated HTML immediately",
+ help="instead of writing an HTML file and immediately "
+ "displaying it, dump the rewritten dot file "
+ "to stdout",
)
args = parser.parse_args()
logging.basicConfig(level=args.loglevel)
@@ -1224,8 +1230,8 @@ def main():
args.dark,
args.gray,
args.topology,
- args.dump_dot_only,
args.dump_html_only,
+ args.dump_dot_only,
)
for trimmer in trimmers:
More information about the cfe-commits
mailing list