From e25e6da9173b473bd7075dd8afb816dfd2bd90d8 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Grang Date: Fri, 11 Nov 2016 04:51:27 +0000 Subject: [PATCH] [opt-viewer] PEPify opt-viewer.py Reviewers: anemet Subscribers: fhahn Differential Revision: https://reviews.llvm.org/D26535 llvm-svn: 286564 --- llvm/utils/opt-viewer/opt-viewer.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/llvm/utils/opt-viewer/opt-viewer.py b/llvm/utils/opt-viewer/opt-viewer.py index 378c220..56332a0 100755 --- a/llvm/utils/opt-viewer/opt-viewer.py +++ b/llvm/utils/opt-viewer/opt-viewer.py @@ -24,10 +24,13 @@ parser.add_argument('-source-dir', '-s', default='', help='set source directory' args = parser.parse_args() p = subprocess.Popen(['c++filt', '-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + + def demangle(name): p.stdin.write(name + '\n') return p.stdout.readline().rstrip() + class Remark(yaml.YAMLObject): max_hotness = 1 # Map function names to their source location for function where inlining happened @@ -93,29 +96,38 @@ class Remark(yaml.YAMLObject): def key(self): return (self.__class__, self.Pass, self.Name, self.File, self.Line, self.Column, self.message) + class Analysis(Remark): yaml_tag = '!Analysis' @property - def color(self): return "white" + def color(self): + return "white" + class AnalysisFPCommute(Analysis): yaml_tag = '!AnalysisFPCommute' + class AnalysisAliasing(Analysis): yaml_tag = '!AnalysisAliasing' + class Passed(Remark): yaml_tag = '!Passed' @property - def color(self): return "green" + def color(self): + return "green" + class Missed(Remark): yaml_tag = '!Missed' @property - def color(self): return "red" + def color(self): + return "red" + class SourceFileRenderer: def __init__(self, filename): @@ -203,6 +215,7 @@ class SourceFileRenderer: def html_file_name(cls, filename): return filename.replace('/', '_') + ".html" + class IndexRenderer: def __init__(self): self.stream = open(os.path.join(args.output_dir, 'index.html'), 'w') @@ -240,7 +253,7 @@ class IndexRenderer: all_remarks = dict() -file_remarks = dict() +file_remarks = dict() for input_file in args.yaml_files: f = open(input_file) @@ -252,7 +265,7 @@ for input_file in args.yaml_files: continue all_remarks[remark.key] = remark - file_remarks.setdefault(remark.File, dict()).setdefault(remark.Line, []).append(remark); + file_remarks.setdefault(remark.File, dict()).setdefault(remark.Line, []).append(remark) Remark.max_hotness = max(Remark.max_hotness, remark.Hotness) -- 2.7.4