aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-28 14:21:45 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-03 15:31:03 -0700
commit11db72239d48da525e0978a608e4cdfb91168981 (patch)
treeccb07b0571c8b4305544eeb4e333ceb224f4f3f3
parent0de466d64e4cf3e8466c03731f18012688d5ea78 (diff)
apply replacements to module defs, and add testing for merging of overlapping global initializers
-rw-r--r--emlink.py9
-rwxr-xr-xtests/runner.py17
2 files changed, 25 insertions, 1 deletions
diff --git a/emlink.py b/emlink.py
index 66c81342..f37e8253 100644
--- a/emlink.py
+++ b/emlink.py
@@ -146,7 +146,14 @@ class AsmModule():
main.exports_js = 'return {' + ','.join(list(exports)) + '};\n})\n'
# post
- new_module_defs = self.module_defs.difference(main.module_defs)
+ def rep_def(deff):
+ key = deff.split(' ')[1]
+ if key in replacements:
+ rep = replacements[key]
+ return 'var %s = Module["%s"] = asm["%s"];\n' % (rep, rep, rep)
+ return deff
+ my_module_defs = map(rep_def, self.module_defs)
+ new_module_defs = set(my_module_defs).difference(main.module_defs)
if len(new_module_defs) > 0:
position = main.post_js.find('Runtime.') # Runtime is the start of the hardcoded ones
main.post_js = main.post_js[:position] + ''.join(list(new_module_defs)) + '\n' + main.post_js[position:]
diff --git a/tests/runner.py b/tests/runner.py
index 3bd39036..a1cec46e 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10668,6 +10668,23 @@ f.close()
void nothing() {}
''', 'a new Class\n')
+ # Multiple global initializers (LLVM generates overlapping names for them)
+ test('global inits', r'''
+ #include <stdio.h>
+ struct Class {
+ Class(const char *name) { printf("new %s\n", name); }
+ };
+ ''', r'''
+ #include "header.h"
+ static Class c("main");
+ int main() {
+ return 0;
+ }
+ ''', r'''
+ #include "header.h"
+ static Class c("side");
+ ''', ['new main\nnew side\n', 'new side\nnew main\n'])
+
def test_symlink(self):
if os.name == 'nt':
return self.skip('Windows FS does not need to be tested for symlinks support, since it does not have them.')