Skip to content

Commit eb7dcc8

Browse files
committedFeb 12, 2017
sancov.py: [Py3] Get rid of "print" statement. Use print() or write() instead.
Differential Revision: https://reviews.llvm.org/D27405 llvm-svn: 294880
1 parent 4efbbce commit eb7dcc8

File tree

1 file changed

+28
-26
lines changed
  • compiler-rt/lib/sanitizer_common/scripts

1 file changed

+28
-26
lines changed
 

‎compiler-rt/lib/sanitizer_common/scripts/sancov.py

+28-26
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
prog_name = ""
1515

1616
def Usage():
17-
print >> sys.stderr, "Usage: \n" + \
18-
" " + prog_name + " merge FILE [FILE...] > OUTPUT\n" \
19-
" " + prog_name + " print FILE [FILE...]\n" \
20-
" " + prog_name + " unpack FILE [FILE...]\n" \
21-
" " + prog_name + " rawunpack FILE [FILE ...]\n" \
22-
" " + prog_name + " missing BINARY < LIST_OF_PCS\n"
17+
sys.stderr.write(
18+
"Usage: \n" + \
19+
" " + prog_name + " merge FILE [FILE...] > OUTPUT\n" \
20+
" " + prog_name + " print FILE [FILE...]\n" \
21+
" " + prog_name + " unpack FILE [FILE...]\n" \
22+
" " + prog_name + " rawunpack FILE [FILE ...]\n" \
23+
" " + prog_name + " missing BINARY < LIST_OF_PCS\n" \
24+
"\n")
2325
exit(1)
2426

2527
def CheckBits(bits):
@@ -78,19 +80,19 @@ def Merge(files):
7880
s = set()
7981
for f in files:
8082
s = s.union(set(ReadOneFile(f)))
81-
print >> sys.stderr, "%s: %d files merged; %d PCs total" % \
82-
(prog_name, len(files), len(s))
83+
sys.stderr.write(
84+
"%s: %d files merged; %d PCs total\n" % (prog_name, len(files), len(s))
85+
)
8386
return sorted(s)
8487

8588
def PrintFiles(files):
8689
if len(files) > 1:
8790
s = Merge(files)
8891
else: # If there is just on file, print the PCs in order.
8992
s = ReadOneFile(files[0])
90-
print >> sys.stderr, "%s: 1 file merged; %d PCs total" % \
91-
(prog_name, len(s))
93+
sys.stderr.write("%s: 1 file merged; %d PCs total\n" % (prog_name, len(s)))
9294
for i in s:
93-
print "0x%x" % i
95+
print("0x%x" % i)
9496

9597
def MergeAndPrint(files):
9698
if sys.stdout.isatty():
@@ -107,7 +109,7 @@ def MergeAndPrint(files):
107109

108110
def UnpackOneFile(path):
109111
with open(path, mode="rb") as f:
110-
print >> sys.stderr, "%s: unpacking %s" % (prog_name, path)
112+
sys.stderr.write("%s: unpacking %s\n" % (prog_name, path))
111113
while True:
112114
header = f.read(12)
113115
if not header: return
@@ -119,8 +121,7 @@ def UnpackOneFile(path):
119121
assert(len(module) == module_length)
120122
assert(len(blob) == blob_size)
121123
extracted_file = "%s.%d.sancov" % (module, pid)
122-
print >> sys.stderr, "%s: extracting %s" % \
123-
(prog_name, extracted_file)
124+
sys.stderr.write("%s: extracting %s\n" % (prog_name, extracted_file))
124125
# The packed file may contain multiple blobs for the same pid/module
125126
# pair. Append to the end of the file instead of overwriting.
126127
with open(extracted_file, 'ab') as f2:
@@ -136,7 +137,7 @@ def Unpack(files):
136137
def UnpackOneRawFile(path, map_path):
137138
mem_map = []
138139
with open(map_path, mode="rt") as f_map:
139-
print >> sys.stderr, "%s: reading map %s" % (prog_name, map_path)
140+
sys.stderr.write("%s: reading map %s\n" % (prog_name, map_path))
140141
bits = int(f_map.readline())
141142
if bits != 32 and bits != 64:
142143
raise Exception('Wrong bits size in the map')
@@ -150,7 +151,7 @@ def UnpackOneRawFile(path, map_path):
150151
mem_map_keys = [m[0] for m in mem_map]
151152

152153
with open(path, mode="rb") as f:
153-
print >> sys.stderr, "%s: unpacking %s" % (prog_name, path)
154+
sys.stderr.write("%s: unpacking %s\n" % (prog_name, path))
154155

155156
f.seek(0, 2)
156157
size = f.tell()
@@ -164,15 +165,15 @@ def UnpackOneRawFile(path, map_path):
164165
(start, end, base, module_path) = mem_map[map_idx]
165166
assert pc >= start
166167
if pc >= end:
167-
print >> sys.stderr, "warning: %s: pc %x outside of any known mapping" % (prog_name, pc)
168+
sys.stderr.write("warning: %s: pc %x outside of any known mapping\n" % (prog_name, pc))
168169
continue
169170
mem_map_pcs[map_idx].append(pc - base)
170171

171172
for ((start, end, base, module_path), pc_list) in zip(mem_map, mem_map_pcs):
172173
if len(pc_list) == 0: continue
173174
assert path.endswith('.sancov.raw')
174175
dst_path = module_path + '.' + os.path.basename(path)[:-4]
175-
print >> sys.stderr, "%s: writing %d PCs to %s" % (prog_name, len(pc_list), dst_path)
176+
sys.stderr.write("%s: writing %d PCs to %s\n" % (prog_name, len(pc_list), dst_path))
176177
sorted_pc_list = sorted(pc_list)
177178
pc_buffer = struct.pack(TypeCodeForStruct(bits) * len(pc_list), *sorted_pc_list)
178179
with open(dst_path, 'ab+') as f2:
@@ -207,18 +208,19 @@ def PrintMissing(binary):
207208
if not os.path.isfile(binary):
208209
raise Exception('File not found: %s' % binary)
209210
instrumented = GetInstrumentedPCs(binary)
210-
print >> sys.stderr, "%s: found %d instrumented PCs in %s" % (prog_name,
211-
len(instrumented),
212-
binary)
211+
sys.stderr.write("%s: found %d instrumented PCs in %s\n" % (prog_name,
212+
len(instrumented),
213+
binary))
213214
covered = set(int(line, 16) for line in sys.stdin)
214-
print >> sys.stderr, "%s: read %d PCs from stdin" % (prog_name, len(covered))
215+
sys.stderr.write("%s: read %d PCs from stdin\n" % (prog_name, len(covered)))
215216
missing = instrumented - covered
216-
print >> sys.stderr, "%s: %d PCs missing from coverage" % (prog_name, len(missing))
217+
sys.stderr.write("%s: %d PCs missing from coverage\n" % (prog_name, len(missing)))
217218
if (len(missing) > len(instrumented) - len(covered)):
218-
print >> sys.stderr, \
219-
"%s: WARNING: stdin contains PCs not found in binary" % prog_name
219+
sys.stderr.write(
220+
"%s: WARNING: stdin contains PCs not found in binary\n" % prog_name
221+
)
220222
for pc in sorted(missing):
221-
print "0x%x" % pc
223+
print("0x%x" % pc)
222224

223225
if __name__ == '__main__':
224226
prog_name = sys.argv[0]

0 commit comments

Comments
 (0)
Please sign in to comment.