From a8db86622841fe757bc440a858cdf7c576ce943c Mon Sep 17 00:00:00 2001 From: Jean-Luc Duprat Date: Tue, 10 Jan 2012 10:42:15 -0800 Subject: [PATCH] Python build compatible on both python 2 and 3 --- bitcode2cpp.py | 21 +++++++++++---------- stdlib2cpp.py | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/bitcode2cpp.py b/bitcode2cpp.py index 9e16ecea..d99e81a9 100755 --- a/bitcode2cpp.py +++ b/bitcode2cpp.py @@ -29,17 +29,18 @@ except IOError: sys.stderr.write("Couldn't open " + src) sys.exit(1) +width = 16; sys.stdout.write("unsigned char builtins_bitcode_" + target + "[] = {\n") -num = 0 -for line in as_out.stdout.readlines(): - length = length + len(line) - for c in line: - num+=1 - sys.stdout.write("0x%0.2X, " % ord(c)) - if num%16 == 0: - sys.stdout.write("\n"); -sys.stdout.write(" 0 };\n\n") -sys.stdout.write("int builtins_bitcode_" + target + "_length = " + str(length) + ";\n") + +data = as_out.stdout.read() +for i in range(0, len(data), 1): + sys.stdout.write("0x%0.2X, " % ord(data[i:i+1])) + + if i%width == (width-1): + sys.stdout.write("\n") + +sys.stdout.write("0x00 };\n\n") +sys.stdout.write("int builtins_bitcode_" + target + "_length = " + str(i) + ";\n") as_out.wait() diff --git a/stdlib2cpp.py b/stdlib2cpp.py index 1d083d80..d032d023 100755 --- a/stdlib2cpp.py +++ b/stdlib2cpp.py @@ -6,11 +6,13 @@ t=str(sys.argv[1]) sys.stdout.write("char stdlib_" + t + "_code[] = {\n") -num = 0 -for line in sys.stdin: - for c in line: - num+=1 - sys.stdout.write("0x%0.2X, " % ord(c)) - if num%16 == 0: - sys.stdout.write("\n") -sys.stdout.write("0 };\n") +width = 16 +data = sys.stdin.read() +for i in range(0, len(data), 1): + sys.stdout.write("0x%0.2X, " % ord(data[i:i+1])) + + if i%width == (width-1): + sys.stdout.write("\n") + +sys.stdout.write("0x00 };\n\n") +