aboutsummaryrefslogtreecommitdiff
path: root/emcc
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-01-04 14:36:02 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-01-04 14:36:02 -0800
commitc3c090dc47ac79a1b2523cc97bda5f3408db6b1a (patch)
treeab725c7f78be6332786e7116dec4b0d1ad2503f3 /emcc
parentc684311cd2df28a20cfb225e8c3428858d7bf251 (diff)
--js-transform option for emcc
Diffstat (limited to 'emcc')
-rwxr-xr-xemcc27
1 files changed, 23 insertions, 4 deletions
diff --git a/emcc b/emcc
index e08de1cb..131f9917 100755
--- a/emcc
+++ b/emcc
@@ -138,6 +138,20 @@ Options that are modified or new in %s include:
generated code!
--closure <on> 0: No closure compiler (default in -O0, -O1)
1: Run closure compiler (default in -O2, -O3)
+ --js-transform <cmd> <cmd> will be called on the generated code
+ before it is optimized. This lets you modify
+ the JavaScript, for example adding some code
+ or removing some code, in a way that those
+ modifications will be optimized together with
+ the generated code properly. <cmd> will be
+ called with the filename of the generated
+ code as a parameter; to modify the code, you
+ can read the original data and then append to
+ it or overwrite it with the modified data.
+ <cmd> is interpreted as a space-separated
+ list of arguments, for example, <cmd> of
+ "python processor.py" will cause a python
+ script to be run.
The target file, if specified (-o <target>), defines what will
be generated:
@@ -254,6 +268,7 @@ try:
opt_level = 0
llvm_opt_level = None
closure = None
+ js_transform = None
def check_bad_eq(arg):
assert '=' not in arg, 'Invalid parameter (do not use "=" with "--" options)'
@@ -277,6 +292,11 @@ try:
closure = int(newargs[i+1])
newargs[i] = ''
newargs[i+1] = ''
+ elif newargs[i].startswith('--js-transform'):
+ check_bad_eq(newargs[i])
+ js_transform = newargs[i+1]
+ newargs[i] = ''
+ newargs[i+1] = ''
elif newargs[i] == '-MF': # clang cannot handle this, so we fake it
f = open(newargs[i+1], 'w')
f.write('\n')
@@ -478,12 +498,11 @@ try:
if DEBUG: save_intermediate('original')
# Apply a source code transformation, if requested
- source_transform = os.environ.get('EMCC_JS_PROCESSOR')
- if source_transform:
- exec source_transform in locals()
+ if js_transform:
shutil.copyfile(final, final + '.tr.js')
final += '.tr.js'
- process(final)
+ if DEBUG: print >> sys.stderr, 'emcc: applying transform: %s' % js_transform
+ Popen(js_transform.split(' ') + [os.path.abspath(final)]).communicate()
if DEBUG: save_intermediate('transformed')
if opt_level >= 1: