aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-09-14 18:08:52 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-09-14 18:08:52 -0700
commitce07f2aa7735c267785115c23f28321f61c7b250 (patch)
tree03ea71dbf30887f38dc585b678d6299b5e608661
parent55013f30bce701468b5dcdd00dd0df3d53c75c33 (diff)
intentionally do reSign in printing %d
-rw-r--r--src/library.js16
-rw-r--r--src/runtime.js2
-rw-r--r--tests/runner.py11
-rwxr-xr-xtools/exec_llvm.py2
-rw-r--r--tools/shared.py1
5 files changed, 20 insertions, 12 deletions
diff --git a/src/library.js b/src/library.js
index 1925fb04..84ea9243 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 7e3c7b84..719be637 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 f8d281ad..d080694b 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 aa18aa2b..3b08111a 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 93c417a1..029ca2f4 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