aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-09-02 21:34:15 -0700
committeralon@honor <none@none>2010-09-02 21:34:15 -0700
commitab371a5c466d2ab5d441490d27e15d00085fbbc1 (patch)
tree638e4d1297380cce7c53978e9341cbca57955a7d
parent1ba6a6f48ff22002037b1628587bb49c75a56da7 (diff)
ptrtoint support, +test that includes scanning generated code
-rw-r--r--src/parser.js6
-rw-r--r--tests/runner.py27
2 files changed, 30 insertions, 3 deletions
diff --git a/src/parser.js b/src/parser.js
index 8936e87b..e37d408a 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -702,7 +702,7 @@ function intertyper(data) {
// mathops
substrate.addZyme('Mathops', {
selectItem: function(item) { return item.indent === -1 && item.tokens && item.tokens.length >= 3 &&
- ['add', 'sub', 'sdiv', 'mul', 'icmp', 'zext', 'urem', 'srem', 'fadd', 'fmul', 'fdiv', 'fcmp', 'uitofp', 'sitofp', 'fpext', 'fptoui', 'fptosi', 'trunc', 'sext', 'select', 'shl', 'shr', 'ashl', 'ashr', 'xor', 'or', 'and']
+ ['add', 'sub', 'sdiv', 'mul', 'icmp', 'zext', 'urem', 'srem', 'fadd', 'fmul', 'fdiv', 'fcmp', 'uitofp', 'sitofp', 'fpext', 'fptoui', 'fptosi', 'trunc', 'sext', 'select', 'shl', 'shr', 'ashl', 'ashr', 'xor', 'or', 'and', 'ptrtoint']
.indexOf(item.tokens[0].text) != -1 && !item.intertype },
processItem: function(item) {
item.intertype = 'mathop';
@@ -2261,6 +2261,10 @@ function JSify(data) {
}
case 'zext': case 'fpext': case 'trunc': case 'sext': return ident;
case 'select': return '(' + ident + ' ? ' + ident3 + ' : ' + ident4 + ')';
+ case 'ptrtoint': {
+ if (type.text != 'i8*') print('// XXX Warning: Risky ptrtoint operation on line ' + lineNum);
+ return ident;
+ }
default: throw 'Unknown mathcmp op: ' + item.op
}
} });
diff --git a/tests/runner.py b/tests/runner.py
index 165f2aa4..dba9333a 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -25,7 +25,7 @@ def timeout_run(proc, timeout, note):
return proc.communicate()[0]
class T(unittest.TestCase):
- def do_test(self, src, expected_output, args=[], output_nicerizer=None, no_python=False, no_build=False, main_file=None):
+ def do_test(self, src, expected_output, args=[], output_processor=None, output_nicerizer=None, no_python=False, no_build=False, main_file=None):
global DEBUG
dirname = TEMP_DIR + '/tmp' # tempfile.mkdtemp(dir=TEMP_DIR)
if not os.path.exists(dirname):
@@ -70,11 +70,13 @@ class T(unittest.TestCase):
if DEBUG: print output
cwd = os.getcwd()
os.chdir(path_from_root(['src']))
- output = timeout_run(Popen([PARSER_ENGINE] + PARSER_OPTS + [JS_COMPILER], stdin=open(filename + '.o.llvm', 'r'), stdout=open(filename + '.o.js', 'w'), stderr=STDOUT), 20, 'Parser')
+ output = timeout_run(Popen([PARSER_ENGINE] + PARSER_OPTS + [JS_COMPILER], stdin=open(filename + '.o.llvm', 'r'), stdout=open(filename + '.o.js', 'w'), stderr=STDOUT), 200, 'Parser')
os.chdir(cwd)
# return
if DEBUG: print output
output = open(filename + '.o.js').read()
+ if output_processor is not None:
+ output_processor(output)
if output is not None and 'Traceback' in output: print output; assert (0) # 'generating JavaScript failed'
if DEBUG: print "\nGenerated JavaScript:\n\n===\n\n%s\n\n===\n\n" % output
# if not DEBUG:
@@ -481,6 +483,27 @@ class T(unittest.TestCase):
'''
self.do_test(src, '*97,15,3,3029*')
+ def test_ptrtoint(self):
+ src = '''
+ #include <stdio.h>
+
+ int main( int argc, const char *argv[] ) {
+ char *a = new char[10];
+ char *a0 = a+0;
+ char *a5 = a+5;
+ int *b = new int[10];
+ int *b0 = b+0;
+ int *b5 = b+5;
+ int c = (int)b5-(int)b0; // Emscripten should warn!
+ int d = (int)b5-(int)b0; // Emscripten should warn!
+ printf("*%d*\\n", (int)a5-(int)a0);
+ return 0;
+ }
+ '''
+ runner = self
+ def check_warnings(output):
+ runner.assertEquals(filter(lambda line: 'Warning' in line, output.split('\n')).__len__(), 4)
+ self.do_test(src, '*5*', output_processor=check_warnings)
def test_memcpy(self):
src = '''