[compiler-rt] r294880 - sancov.py: [Py3] Get rid of "print" statement. Use print() or write() instead.

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 11 16:26:28 PST 2017


Author: chapuni
Date: Sat Feb 11 18:26:28 2017
New Revision: 294880

URL: http://llvm.org/viewvc/llvm-project?rev=294880&view=rev
Log:
sancov.py: [Py3] Get rid of "print" statement. Use print() or write() instead.

Differential Revision: https://reviews.llvm.org/D27405

Modified:
    compiler-rt/trunk/lib/sanitizer_common/scripts/sancov.py

Modified: compiler-rt/trunk/lib/sanitizer_common/scripts/sancov.py
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/scripts/sancov.py?rev=294880&r1=294879&r2=294880&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/scripts/sancov.py (original)
+++ compiler-rt/trunk/lib/sanitizer_common/scripts/sancov.py Sat Feb 11 18:26:28 2017
@@ -14,12 +14,14 @@ import sys
 prog_name = ""
 
 def Usage():
-  print >> sys.stderr, "Usage: \n" + \
-      " " + prog_name + " merge FILE [FILE...] > OUTPUT\n" \
-      " " + prog_name + " print FILE [FILE...]\n" \
-      " " + prog_name + " unpack FILE [FILE...]\n" \
-      " " + prog_name + " rawunpack FILE [FILE ...]\n" \
-      " " + prog_name + " missing BINARY < LIST_OF_PCS\n"
+  sys.stderr.write(
+    "Usage: \n" + \
+    " " + prog_name + " merge FILE [FILE...] > OUTPUT\n" \
+    " " + prog_name + " print FILE [FILE...]\n" \
+    " " + prog_name + " unpack FILE [FILE...]\n" \
+    " " + prog_name + " rawunpack FILE [FILE ...]\n" \
+    " " + prog_name + " missing BINARY < LIST_OF_PCS\n" \
+    "\n")
   exit(1)
 
 def CheckBits(bits):
@@ -78,8 +80,9 @@ def Merge(files):
   s = set()
   for f in files:
     s = s.union(set(ReadOneFile(f)))
-  print >> sys.stderr, "%s: %d files merged; %d PCs total" % \
-    (prog_name, len(files), len(s))
+  sys.stderr.write(
+    "%s: %d files merged; %d PCs total\n" % (prog_name, len(files), len(s))
+  )
   return sorted(s)
 
 def PrintFiles(files):
@@ -87,10 +90,9 @@ def PrintFiles(files):
     s = Merge(files)
   else:  # If there is just on file, print the PCs in order.
     s = ReadOneFile(files[0])
-    print >> sys.stderr, "%s: 1 file merged; %d PCs total" % \
-      (prog_name, len(s))
+    sys.stderr.write("%s: 1 file merged; %d PCs total\n" % (prog_name, len(s)))
   for i in s:
-    print "0x%x" % i
+    print("0x%x" % i)
 
 def MergeAndPrint(files):
   if sys.stdout.isatty():
@@ -107,7 +109,7 @@ def MergeAndPrint(files):
 
 def UnpackOneFile(path):
   with open(path, mode="rb") as f:
-    print >> sys.stderr, "%s: unpacking %s" % (prog_name, path)
+    sys.stderr.write("%s: unpacking %s\n" % (prog_name, path))
     while True:
       header = f.read(12)
       if not header: return
@@ -119,8 +121,7 @@ def UnpackOneFile(path):
       assert(len(module) == module_length)
       assert(len(blob) == blob_size)
       extracted_file = "%s.%d.sancov" % (module, pid)
-      print >> sys.stderr, "%s: extracting %s" % \
-        (prog_name, extracted_file)
+      sys.stderr.write("%s: extracting %s\n" % (prog_name, extracted_file))
       # The packed file may contain multiple blobs for the same pid/module
       # pair. Append to the end of the file instead of overwriting.
       with open(extracted_file, 'ab') as f2:
@@ -136,7 +137,7 @@ def Unpack(files):
 def UnpackOneRawFile(path, map_path):
   mem_map = []
   with open(map_path, mode="rt") as f_map:
-    print >> sys.stderr, "%s: reading map %s" % (prog_name, map_path)
+    sys.stderr.write("%s: reading map %s\n" % (prog_name, map_path))
     bits = int(f_map.readline())
     if bits != 32 and bits != 64:
       raise Exception('Wrong bits size in the map')
@@ -150,7 +151,7 @@ def UnpackOneRawFile(path, map_path):
   mem_map_keys = [m[0] for m in mem_map]
 
   with open(path, mode="rb") as f:
-    print >> sys.stderr, "%s: unpacking %s" % (prog_name, path)
+    sys.stderr.write("%s: unpacking %s\n" % (prog_name, path))
 
     f.seek(0, 2)
     size = f.tell()
@@ -164,7 +165,7 @@ def UnpackOneRawFile(path, map_path):
       (start, end, base, module_path) = mem_map[map_idx]
       assert pc >= start
       if pc >= end:
-        print >> sys.stderr, "warning: %s: pc %x outside of any known mapping" % (prog_name, pc)
+        sys.stderr.write("warning: %s: pc %x outside of any known mapping\n" % (prog_name, pc))
         continue
       mem_map_pcs[map_idx].append(pc - base)
 
@@ -172,7 +173,7 @@ def UnpackOneRawFile(path, map_path):
       if len(pc_list) == 0: continue
       assert path.endswith('.sancov.raw')
       dst_path = module_path + '.' + os.path.basename(path)[:-4]
-      print >> sys.stderr, "%s: writing %d PCs to %s" % (prog_name, len(pc_list), dst_path)
+      sys.stderr.write("%s: writing %d PCs to %s\n" % (prog_name, len(pc_list), dst_path))
       sorted_pc_list = sorted(pc_list)
       pc_buffer = struct.pack(TypeCodeForStruct(bits) * len(pc_list), *sorted_pc_list)
       with open(dst_path, 'ab+') as f2:
@@ -207,18 +208,19 @@ def PrintMissing(binary):
   if not os.path.isfile(binary):
     raise Exception('File not found: %s' % binary)
   instrumented = GetInstrumentedPCs(binary)
-  print >> sys.stderr, "%s: found %d instrumented PCs in %s" % (prog_name,
-                                                                len(instrumented),
-                                                                binary)
+  sys.stderr.write("%s: found %d instrumented PCs in %s\n" % (prog_name,
+                                                              len(instrumented),
+                                                              binary))
   covered = set(int(line, 16) for line in sys.stdin)
-  print >> sys.stderr, "%s: read %d PCs from stdin" % (prog_name, len(covered))
+  sys.stderr.write("%s: read %d PCs from stdin\n" % (prog_name, len(covered)))
   missing = instrumented - covered
-  print >> sys.stderr, "%s: %d PCs missing from coverage" % (prog_name, len(missing))
+  sys.stderr.write("%s: %d PCs missing from coverage\n" % (prog_name, len(missing)))
   if (len(missing) > len(instrumented) - len(covered)):
-    print >> sys.stderr, \
-        "%s: WARNING: stdin contains PCs not found in binary" % prog_name
+    sys.stderr.write(
+      "%s: WARNING: stdin contains PCs not found in binary\n" % prog_name
+    )
   for pc in sorted(missing):
-    print "0x%x" % pc
+    print("0x%x" % pc)
 
 if __name__ == '__main__':
   prog_name = sys.argv[0]




More information about the llvm-commits mailing list