diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-07-04 12:17:06 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-07-04 12:17:06 -0700 |
commit | 1aeee076cf70038b44ca84f9565bfb16d1401d87 (patch) | |
tree | 42e8b8ee92c6f54a32dae4ef3df4becdb84e6c66 /tools | |
parent | a4262aa2c9028145516c1a23cbdc6b7b8a42b353 (diff) |
ensure binding functions are not DFE'd away
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bindings_generator.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/tools/bindings_generator.py b/tools/bindings_generator.py index 99d5e889..81d1a0fe 100644 --- a/tools/bindings_generator.py +++ b/tools/bindings_generator.py @@ -51,6 +51,8 @@ for header in sys.argv[2:]: # Second pass - generate bindings +funcs = [] + gen_c = open(basename + '.c', 'w') gen_js = open(basename + '.js', 'w') @@ -83,6 +85,8 @@ for cname, clazz in classes.iteritems(): } ''' % (ret, fullname, typedargs, callprefix, mname, justargs)) + funcs.append('emscripten_bind_' + fullname) + # JS if constructor: @@ -99,10 +103,33 @@ function %s(%s) { } ''' % (cname, mname, justargs, 'return ' if ret != 'void' else '', fullname, (', ' if len(justargs) > 0 else '') + justargs)) + # Finish up -gen_c.write('\n}\n') -gen_c.close() +gen_c.write(''' +} + +#include <stdio.h> +struct EmscriptenEnsurer +{ + EmscriptenEnsurer() { + // Actually use the binding functions, so DFE will not eliminate them + int sum = 0; + void *seen = (void*)%s; +''' % funcs[0]) + +for func in funcs[1:]: + gen_c.write(''' sum += (void*)%s == seen; +''' % func) + +gen_c.write(''' printf("(%d)\\n", sum); + } +}; + +EmscriptenEnsurer emscriptenEnsurer; +''') + +gen_c.close() gen_js.close() |