From ad38e58ef2412aaac7a5da1b15ca763787071742 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Tue, 2 Jul 2019 02:17:56 +0000 Subject: [PATCH] [analyzer] exploded-graph-rewriter: Implement a dark color scheme. Addresses a popular request. Activated via --dark. Differential Revision: https://reviews.llvm.org/D64056 llvm-svn: 364882 --- .../test/Analysis/exploded-graph-rewriter/edge.dot | 6 ++-- .../Analysis/exploded-graph-rewriter/empty.dot | 3 ++ .../exploded-graph-rewriter/environment.dot | 2 +- .../exploded-graph-rewriter/node_labels.dot | 22 +++++++++++++ .../objects_under_construction.cpp | 2 +- clang/utils/analyzer/exploded-graph-rewriter.py | 37 +++++++++++++++------- 6 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 clang/test/Analysis/exploded-graph-rewriter/node_labels.dot diff --git a/clang/test/Analysis/exploded-graph-rewriter/edge.dot b/clang/test/Analysis/exploded-graph-rewriter/edge.dot index fa4b017e..2d3a4fe 100644 --- a/clang/test/Analysis/exploded-graph-rewriter/edge.dot +++ b/clang/test/Analysis/exploded-graph-rewriter/edge.dot @@ -1,4 +1,5 @@ -// RUN: %exploded_graph_rewriter %s | FileCheck %s +// RUN: %exploded_graph_rewriter %s | FileCheck %s -check-prefix=LIGHT +// RUN: %exploded_graph_rewriter --dark %s | FileCheck %s -check-prefixes=DARK // FIXME: Substitution doesn't seem to work on Windows. // UNSUPPORTED: system-windows @@ -7,7 +8,8 @@ Node0x1 [shape=record,label= "{{ "node_id": 1, "pointer": "0x1", "program_state": null, "program_points": []}\l}"]; -// CHECK: Node0x1 -> Node0x2; +// LIGHT: Node0x1 -> Node0x2; +// DARK: Node0x1 -> Node0x2 [color="white"]; Node0x1 -> Node0x2; Node0x2 [shape=record,label= diff --git a/clang/test/Analysis/exploded-graph-rewriter/empty.dot b/clang/test/Analysis/exploded-graph-rewriter/empty.dot index 3e0733c..7f67e9c 100644 --- a/clang/test/Analysis/exploded-graph-rewriter/empty.dot +++ b/clang/test/Analysis/exploded-graph-rewriter/empty.dot @@ -1,4 +1,6 @@ // RUN: %exploded_graph_rewriter %s | FileCheck %s +// RUN: %exploded_graph_rewriter --dark %s | FileCheck %s \ +// RUN: -check-prefixes=CHECK,DARK // FIXME: Substitution doesn't seem to work on Windows. // UNSUPPORTED: system-windows @@ -8,5 +10,6 @@ digraph "Exploded Graph" { } // CHECK: digraph "ExplodedGraph" { +// DARK-NEXT: bgcolor="gray10"; // CHECK-NEXT: label=""; // CHECK-NEXT: } diff --git a/clang/test/Analysis/exploded-graph-rewriter/environment.dot b/clang/test/Analysis/exploded-graph-rewriter/environment.dot index 3a54c6e..8c45167 100644 --- a/clang/test/Analysis/exploded-graph-rewriter/environment.dot +++ b/clang/test/Analysis/exploded-graph-rewriter/environment.dot @@ -10,7 +10,7 @@ // CHECK-SAME: #0 Call // CHECK-SAME: // CHECK-SAME: -// CHECK-SAME: foo (line 4) +// CHECK-SAME: foo (line 4) // CHECK-SAME: // CHECK-SAME: // CHECK-SAME: diff --git a/clang/test/Analysis/exploded-graph-rewriter/node_labels.dot b/clang/test/Analysis/exploded-graph-rewriter/node_labels.dot new file mode 100644 index 0000000..60b2b29 --- /dev/null +++ b/clang/test/Analysis/exploded-graph-rewriter/node_labels.dot @@ -0,0 +1,22 @@ +// RUN: %exploded_graph_rewriter %s | FileCheck %s -check-prefixes=CHECK,LIGHT +// RUN: %exploded_graph_rewriter %s --dark | FileCheck %s \ +// RUN: -check-prefixes CHECK,DARK + +// FIXME: Substitution doesn't seem to work on Windows. +// UNSUPPORTED: system-windows + +// LIGHT: Node0x1 [shape=record,label=< +// DARK: Node0x1 [shape=record,color="white",fontcolor="gray80",label=< +// CHECK-SAME: +// LIGHT-SAME: +// DARK-SAME: +// CHECK-SAME: Node 1 (0x1) - State Unspecified +// CHECK-SAME: +// CHECK-SAME: +Node0x1 [shape=record,label= + "{ + { "node_id": 1, "pointer": "0x1", + "program_state": null, + "program_points": [] + } +\l}"]; diff --git a/clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp b/clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp index c2a805f..b3d4aef 100644 --- a/clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp +++ b/clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp @@ -17,7 +17,7 @@ void test() { // CHECK-SAME: // CHECK-SAME: #0 Call // CHECK-SAME: - // CHECK-SAME: test + // CHECK-SAME: test // CHECK-SAME: // CHECK-SAME: // CHECK-SAME: diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py b/clang/utils/analyzer/exploded-graph-rewriter.py index c5b9507..fffe2f5 100755 --- a/clang/utils/analyzer/exploded-graph-rewriter.py +++ b/clang/utils/analyzer/exploded-graph-rewriter.py @@ -334,9 +334,10 @@ class ExplodedGraph(object): # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based # syntax highlighing. class DotDumpVisitor(object): - def __init__(self, do_diffs): + def __init__(self, do_diffs, dark_mode): super(DotDumpVisitor, self).__init__() self._do_diffs = do_diffs + self._dark_mode = dark_mode @staticmethod def _dump_raw(s): @@ -363,6 +364,8 @@ class DotDumpVisitor(object): def visit_begin_graph(self, graph): self._graph = graph self._dump_raw('digraph "ExplodedGraph" {\n') + if self._dark_mode: + self._dump_raw('bgcolor="gray10";\n') self._dump_raw('label="";\n') def visit_program_point(self, p): @@ -372,7 +375,7 @@ class DotDumpVisitor(object): 'PostStmtPurgeDeadSymbols']: color = 'red' elif p.kind in ['CallEnter', 'CallExitBegin', 'CallExitEnd']: - color = 'blue' + color = 'dodgerblue' if self._dark_mode else 'blue' elif p.kind in ['Statement']: color = 'cyan4' else: @@ -436,7 +439,7 @@ class DotDumpVisitor(object): self._dump('%s' '%s' '' - '%s ' + '%s ' '%s' % (self._diff_plus_minus(is_added), lc.caption, lc.decl, @@ -451,9 +454,11 @@ class DotDumpVisitor(object): '%s' % (self._diff_plus_minus(is_added), b.stmt_id, - '' - '(%s)' % b.kind - if b.kind is not None else '', + '' + '%s' % ( + 'lavender' if self._dark_mode else 'darkgreen', + ('(%s)' % b.kind) if b.kind is not None else ' ' + ), b.pretty, f.bindings[b])) frames_updated = e.diff_frames(prev_e) if prev_e is not None else None @@ -615,12 +620,16 @@ class DotDumpVisitor(object): s, prev_s) def visit_node(self, node): - self._dump('%s [shape=record,label=<' + self._dump('%s [shape=record,' % (node.node_name())) + if self._dark_mode: + self._dump('color="white",fontcolor="gray80",') + self._dump('label=<
') - self._dump('' - % (node.node_id, node.ptr, node.state.state_id + % ("gray20" if self._dark_mode else "gray", + node.node_id, node.ptr, node.state.state_id if node.state is not None else 'Unspecified')) self._dump('
Node %d (%s) - ' + self._dump('
Node %d (%s) - ' 'State %s
') if len(node.points) > 1: @@ -645,7 +654,10 @@ class DotDumpVisitor(object): self._dump_raw('
>];\n') def visit_edge(self, pred, succ): - self._dump_raw('%s -> %s;\n' % (pred.node_name(), succ.node_name())) + self._dump_raw('%s -> %s%s;\n' % ( + pred.node_name(), succ.node_name(), + ' [color="white"]' if self._dark_mode else '' + )) def visit_end_of_graph(self): self._dump_raw('}\n') @@ -678,6 +690,9 @@ def main(): parser.add_argument('-d', '--diff', action='store_const', dest='diff', const=True, default=False, help='display differences between states') + parser.add_argument('--dark', action='store_const', dest='dark', + const=True, default=False, + help='dark mode') args = parser.parse_args() logging.basicConfig(level=args.loglevel) @@ -688,7 +703,7 @@ def main(): graph.add_raw_line(raw_line) explorer = Explorer() - visitor = DotDumpVisitor(args.diff) + visitor = DotDumpVisitor(args.diff, args.dark) explorer.explore(graph, visitor) -- 2.7.4