diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-04-09 11:31:53 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-04-09 11:31:53 -0700 |
commit | c5425d7d8c38ca1f9617b9823b1cc231bdc73314 (patch) | |
tree | e86059c153bab64dbba12bad88159d930e2da267 | |
parent | 62c67168ae0bcbca6f17cd9af5e6057117697b6e (diff) |
fix handling of blockaddresses > 255 in the new unified memory initializer world; fixes #1048
-rwxr-xr-x | emscripten.py | 10 | ||||
-rwxr-xr-x | tests/runner.py | 19 |
2 files changed, 25 insertions, 4 deletions
diff --git a/emscripten.py b/emscripten.py index 8f68ee77..efa6894a 100755 --- a/emscripten.py +++ b/emscripten.py @@ -306,18 +306,20 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, i += 2 forwarded_json['Functions']['nextIndex'] = i + def split_32(x): + x = int(x) + return '%d,%d,%d,%d' % (x&255, (x >> 8)&255, (x >> 16)&255, (x >> 24)&255) + indexing = forwarded_json['Functions']['indexedFunctions'] def indexize(js): # In the global initial allocation, we need to split up into Uint8 format - def split_32(x): - x = int(x) - return '%d,%d,%d,%d' % (x&255, (x >> 8)&255, (x >> 16)&255, (x >> 24)&255) ret = re.sub(r"\"?'?{{ FI_([\w\d_$]+) }}'?\"?,0,0,0", lambda m: split_32(indexing.get(m.groups(0)[0]) or 0), js) return re.sub(r"'{{ FI_([\w\d_$]+) }}'", lambda m: str(indexing.get(m.groups(0)[0]) or 0), ret) blockaddrs = forwarded_json['Functions']['blockAddresses'] def blockaddrsize(js): - return re.sub(r'{{{ BA_([\w\d_$]+)\|([\w\d_$]+) }}}', lambda m: str(blockaddrs[m.groups(0)[0]][m.groups(0)[1]]), js) + ret = re.sub(r'"?{{{ BA_([\w\d_$]+)\|([\w\d_$]+) }}}"?,0,0,0', lambda m: split_32(blockaddrs[m.groups(0)[0]][m.groups(0)[1]]), js) + return re.sub(r'"?{{{ BA_([\w\d_$]+)\|([\w\d_$]+) }}}"?', lambda m: str(blockaddrs[m.groups(0)[0]][m.groups(0)[1]]), ret) #if DEBUG: outfile.write('// pre\n') outfile.write(blockaddrsize(indexize(pre))) diff --git a/tests/runner.py b/tests/runner.py index e6d5b330..1965cad9 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -3728,6 +3728,25 @@ def process(filename): ''' self.do_run(src, 'good\nbad') + def test_indirectbr_many(self): + if Settings.USE_TYPED_ARRAYS != 2: return self.skip('blockaddr > 255 requires ta2') + + blocks = range(1500) + init = ', '.join(['&&B%d' % b for b in blocks]) + defs = '\n'.join(['B%d: printf("%d\\n"); return 0;' % (b,b) for b in blocks]) + src = ''' + #include <stdio.h> + int main(int argc, char **argv) { + printf("\\n"); + const void *addrs[] = { %s }; + goto *addrs[argc*argc + 1000]; + +%s + return 0; + } + ''' % (init, defs) + self.do_run(src, '\n1001\n') + def test_pack(self): src = ''' #include <stdio.h> |