Beispiel #1
0
Given two files with the same function names in them, merges in n functions from the latter from the start,
order taken as from the first file. This is useful for bisection: 0 means the left file is the output,
and a big enough n means the right file is the output. if left is ok and right shows a bug, then the n
where a change occurs shows which function is the culprit.
'''

from __future__ import print_function
import os, sys, shutil

sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from tools import asm_module, shared

left = sys.argv[1]
left_asm = asm_module.AsmModule(left)

right = sys.argv[2]
right_asm = asm_module.AsmModule(right)

n = int(sys.argv[3])

out = sys.argv[4]

funcs = list(left_asm.funcs)
print('total funcs:', len(funcs))
left_map = left_asm.get_funcs_map()
right_map = right_asm.get_funcs_map()

n = min(n, len(funcs))
Beispiel #2
0
statement. You can add a third param to customize that. If the third param is 'swap-in', it will emit code to swap this asm module in, instead of the default one.

XXX this probably doesn't work with closure compiler advanced yet XXX
'''

import os, sys

sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from tools import asm_module

infile = sys.argv[1]
outfile = sys.argv[2]
extra = sys.argv[3] if len(sys.argv) >= 4 else ';'

module = asm_module.AsmModule(infile).asm_js

if extra == 'swap-in':
  # we do |var asm = | just like the original codebase, so that gets overridden anyhow (assuming global scripts).
  extra = r''' (Module.asmGlobalArg, Module.asmLibraryArg, Module['buffer']);
 // special fixups
 asm.stackRestore(Module['asm'].stackSave()); // if this fails, make sure the original was built to be swappable (-s SWAPPABLE_ASM_MODULE=1)
 // Finish swap
 Module['asm'] = asm;
 if (Module['onAsmSwap']) Module['onAsmSwap']();
'''
elif extra == 'just-func':
  module = module[module.find('=')+1:] # strip the initial "var asm =" bit, leave just the raw module as a function
  extra = ';'

open(outfile, 'w').write(module + extra)