llvm.org GIT mirror llvm / 747f7a4
[opt-viewer] Support unicode characters in function names This is a Swift feature. The output stream for the index page and the source HTML page is utf-8 now. The next patch will add the HTML magic to properly render these characters in the browser. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320725 91177308-0d34-0410-b5e6-96231b3b80d8 Adam Nemet 1 year, 8 months ago
7 changed file(s) with 207 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
0 --- !Passed
1 Pass: sil-inliner
2 Name: sil.Inlined
3 DebugLoc:
4 File: s.swift
5 Line: 12
6 Column: 16
7 Function: main
8 Args:
9 - Callee: '"s.• infix(_:_:)"'
10 DebugLoc:
11 File: s.swift
12 Line: 3
13 Column: 6
14 - String: ' inlined into '
15 - Caller: '"main"'
16 - String: ' (cost = '
17 - Cost: '2'
18 - String: ', benefit = '
19 - Benefit: '40'
20 - String: ')'
21 ...
0 infix operator •: AdditionPrecedence
1
2 func • (a: Int, b: Int) -> Int {
3 return a * b
4 }
5
6 @inline(never)
7 func g(a: Int) -> Int{
8 return a + 1
9 }
10
11 let i = g(a: 1 • 2)
0
1
2
3
4
5
6
7
8
9 Source Location
10 Hotness
11 Function
12 Pass
13
14
15
16 s.swift:12:16
17
18 main
19 sil-inliner
20
21
22
23
24
0
1
2
3
4
5
6
7
8
9
10 Line
11 Hotness
12 Optimization
13 Source
14 Inline Context
15
16
17
18
19
20 1
21
22
23
infix operator •: AdditionPrecedence
24
25
26
27 2
28
29
30
31
32
33
34 3
35
36
37
func • (a: Int, b: Int) -> Int {
38
39
40
41 4
42
43
44
  return a * b
45
46
47
48 5
49
50
51
}
52
53
54
55 6
56
57
58
59
60
61
62 7
63
64
65
@inline(never)
66
67
68
69 8
70
71
72
func g(a: Int) -> Int{
73
74
75
76 9
77
78
79
  return a + 1
80
81
82
83 10
84
85
86
}
87
88
89
90 11
91
92
93
94
95
96
97 12
98
99
100
let i = g(a: 1 • 2)
101
102
103
104
105
106 sil-inliner
107
               
"s.• infix(_:_:)" inlined into "main" (cost = 2, benefit = 40) 
108 main
109
110
111
112 13
113
114
115
116
117
118
119
120
121
0 RUN: %opt-viewer -s %p/Inputs/unicode-function-name -o %t %p/Inputs/unicode-function-name/s.opt.yaml --no-highlight --demangler=llvm-cxxfilt
1 RUN: diff %p/Outputs/unicode-function-name/index.html %t/index.html
2 RUN: diff %p/Outputs/unicode-function-name/s.swift.html %t/s.swift.html
3
4 # Also test the pygments code path without actually checking the output since
5 # that may slightly vary between pygment versions
6 RUN: %opt-viewer -s %p/Inputs/unicode-function-name -o %t.unused %p/Inputs/unicode-function-name/s.opt.yaml --demangler=llvm-cxxfilt
33
44 import argparse
55 import cgi
6 import codecs
67 import errno
78 import functools
89 from multiprocessing import cpu_count
5051 if os.path.exists(fn):
5152 existing_filename = fn
5253
53 self.stream = open(os.path.join(output_dir, optrecord.html_file_name(filename)), 'w')
54 self.stream = codecs.open(os.path.join(output_dir, optrecord.html_file_name(filename)), 'w', encoding='utf-8')
5455 if existing_filename:
5556 self.source_stream = open(existing_filename)
5657 else:
6869 file_text = stream.read()
6970
7071 if args.no_highlight:
71 html_highlighted = file_text
72 html_highlighted = file_text.decode('utf-8')
7273 else:
7374 html_highlighted = highlight(
7475 file_text,
7576 self.cpp_lexer,
7677 self.html_formatter)
7778
78 # On Python 3, pygments.highlight() returns a bytes object, not a str.
79 if sys.version_info >= (3, 0):
80 html_highlighted = html_highlighted.decode('utf-8')
79 # Note that the API is different between Python 2 and 3. On
80 # Python 3, pygments.highlight() returns a bytes object, so we
81 # have to decode. On Python 2, the output is str but since we
82 # support unicode characters and the output streams is unicode we
83 # decode too.
84 html_highlighted = html_highlighted.decode('utf-8')
8185
8286 # Take off the header and footer, these must be
8387 # reapplied line-wise, within the page structure
8589 html_highlighted = html_highlighted.replace('', '')
8690
8791 for (linenum, html_line) in enumerate(html_highlighted.split('\n'), start=1):
88 print('''
92 print(u'''
8993
9094 {linenum}
9195
110114 indent = line[:max(r.Column, 1) - 1]
111115 indent = re.sub('\S', ' ', indent)
112116
113 print('''
117 print(u'''
114118
115119
116120 {r.RelativeHotness}
152156
153157 class IndexRenderer:
154158 def __init__(self, output_dir, should_display_hotness):
155 self.stream = open(os.path.join(output_dir, 'index.html'), 'w')
159 self.stream = codecs.open(os.path.join(output_dir, 'index.html'), 'w', encoding='utf-8')
156160 self.should_display_hotness = should_display_hotness
157161
158162 def render_entry(self, r, odd):
159163 escaped_name = cgi.escape(r.DemangledFunctionName)
160 print('''
164 print(u'''
161165
162166 {r.DebugLocString}
163167 {r.RelativeHotness}
7878 def _reduce_memory(self):
7979 self.Pass = intern(self.Pass)
8080 self.Name = intern(self.Name)
81 self.Function = intern(self.Function)
81 try:
82 # Can't intern unicode strings.
83 self.Function = intern(self.Function)
84 except:
85 pass
8286
8387 def _reduce_memory_dict(old_dict):
8488 new_dict = dict()
155159
156160 if dl and key != 'Caller':
157161 dl_dict = dict(list(dl))
158 return "{}".format(
162 return u"{}".format(
159163 make_link(dl_dict['File'], dl_dict['Line']), value)
160164 else:
161165 return value