From ce07f2aa7735c267785115c23f28321f61c7b250 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 14 Sep 2011 18:08:52 -0700 Subject: [PATCH] intentionally do reSign in printing %d --- src/library.js | 16 +++++++++------- src/runtime.js | 2 +- tests/runner.py | 11 +++++++++-- tools/exec_llvm.py | 2 -- tools/shared.py | 1 + 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/library.js b/src/library.js index 1925fb041..84ea92438 100644 --- a/src/library.js +++ b/src/library.js @@ -2338,9 +2338,9 @@ LibraryManager.library = { var argText; var prefix = ''; if (next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0)) { - argText = currAbsArg.toString(10); + argText = reSign(currArg, 8 * argSize, 1).toString(10); } else if (next == 'u'.charCodeAt(0)) { - argText = unSign(currArg, 8 * argSize).toString(10); + argText = unSign(currArg, 8 * argSize, 1).toString(10); currArg = Math.abs(currArg); } else if (next == 'o'.charCodeAt(0)) { argText = (flagAlternative ? '0' : '') + currAbsArg.toString(8); @@ -2377,11 +2377,13 @@ LibraryManager.library = { } } - // Add sign. - if (currArg < 0) { - prefix = '-' + prefix; - } else if (flagAlwaysSigned) { - prefix = '+' + prefix; + // Add sign if needed + if (flagAlwaysSigned) { + if (currArg < 0) { + prefix = '-' + prefix; + } else { + prefix = '+' + prefix; + } } // Add padding. diff --git a/src/runtime.js b/src/runtime.js index 7e3c7b848..719be637a 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -268,7 +268,7 @@ function reSign(value, bits, ignore, sig) { #if CHECK_SIGNS var noted = false; #endif - if (value >= half) { + if (value >= half && (bits <= 32 || value > half)) { // for huge values, we can hit the precision limit and always get true here. so don't do that #if CHECK_SIGNS if (!ignore) { CorrectionsMonitor.note('ReSign', 0, sig); diff --git a/tests/runner.py b/tests/runner.py index f8d281ad3..d080694b3 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -217,7 +217,7 @@ class RunnerCore(unittest.TestCase): return ret def run_llvm_interpreter(self, args): - return Popen([LLVM_INTERPRETER] + args, stdout=PIPE, stderr=STDOUT).communicate()[0] + return Popen([EXEC_LLVM] + args, stdout=PIPE, stderr=STDOUT).communicate()[0] def build_native(self, filename, compiler='g++'): Popen([compiler, '-O3', filename, '-o', filename+'.native'], stdout=PIPE, stderr=STDOUT).communicate()[0] @@ -429,6 +429,13 @@ if 'benchmark' not in str(sys.argv): const signed char cvals[2] = { -1, -2 }; // compiler can store this is a string, so -1 becomes \FF, and needs re-signing int main() { + { + unsigned char x = 200; + printf("*%d*\\n", x); + unsigned char y = -22; + printf("*%d*\\n", y); + } + int varey = 100; unsigned int MAXEY = -1, MAXEY2 = -77; printf("*%u,%d,%u*\\n", MAXEY, varey >= MAXEY, MAXEY2); // 100 >= -1? not in unsigned! @@ -453,7 +460,7 @@ if 'benchmark' not in str(sys.argv): return 0; } ''' - self.do_test(src, '*4294967295,0,4294967219*\n*-1,1,-1,1*\n*-2,1,-2,1*\n*246,296*\n*1,0*') + self.do_test(src)#, '*4294967295,0,4294967219*\n*-1,1,-1,1*\n*-2,1,-2,1*\n*246,296*\n*1,0*') # Now let's see some code that should just work in USE_TYPED_ARRAYS == 2, but requires # corrections otherwise diff --git a/tools/exec_llvm.py b/tools/exec_llvm.py index aa18aa2b2..3b08111a3 100755 --- a/tools/exec_llvm.py +++ b/tools/exec_llvm.py @@ -41,8 +41,6 @@ def path_from_root(*pathelems): return os.path.join(os.path.sep, *(abspath.split(os.sep)[:-1] + list(pathelems))) exec(open(path_from_root('tools', 'shared.py'), 'r').read()) -print '// EXEC_LLVM: ', sys.argv - Popen([LLVM_OPT, sys.argv[1], '-strip-debug', '-o=' + sys.argv[1]+'.clean.bc']).communicate()[0] # Execute with empty environment - just like the JS script will have diff --git a/tools/shared.py b/tools/shared.py index 93c417a1f..029ca2f48 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -23,6 +23,7 @@ LLVM_INTERPRETER=os.path.expanduser(os.path.join(LLVM_ROOT, 'lli')) LLVM_COMPILER=os.path.expanduser(os.path.join(LLVM_ROOT, 'llc')) BINDINGS_GENERATOR = path_from_root('tools', 'bindings_generator.py') +EXEC_LLVM = path_from_root('tools', 'exec_llvm.py') # Engine tweaks