aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemscripten.py59
1 files changed, 29 insertions, 30 deletions
diff --git a/emscripten.py b/emscripten.py
index 2f55825c..89a54fa9 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -100,42 +100,40 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
ll = open(infile).read()
scan(ll, settings)
total_ll_size = len(ll)
- ll = None # allow collection
if DEBUG: logging.debug(' emscript: scan took %s seconds' % (time.time() - t))
# Split input into the relevant parts for each phase
+
+ if DEBUG: t = time.time()
+
pre = []
funcs = [] # split up functions here, for parallelism later
- meta = [] # needed by each function XXX
- if DEBUG: t = time.time()
- in_func = False
- ll_lines = open(infile).readlines()
- curr_func = None
- for line in ll_lines:
- if in_func:
- curr_func.append(line)
- if line.startswith('}'):
- in_func = False
- funcs.append((curr_func[0], ''.join(curr_func))) # use the entire line as the identifier
- # pre needs to know about all implemented functions, even for non-pre func
- pre.append(curr_func[0])
- pre.append(line)
- curr_func = None
- else:
- if line.startswith(';'): continue
- if line.startswith('define '):
- in_func = True
- curr_func = [line]
- elif line.find(' = type { ') > 0:
- pre.append(line) # type
- elif line.startswith('!'):
- if line.startswith('!llvm.module'): continue # we can ignore that
- meta.append(line) # metadata
- else:
- pre.append(line) # pre needs it so we know about globals in pre and funcs. So emit globals there
- ll_lines = None
- meta = ''.join(meta)
+ meta_start = ll.find('\n!')
+ if meta_start > 0:
+ meta = ll[meta_start:]
+ else:
+ meta = ''
+ meta_start = -1
+
+ func_start = 0
+ last = func_start
+ while 1:
+ last = func_start
+ func_start = ll.find('\ndefine ', func_start)
+ if func_start > last:
+ pre.append(ll[last:min(func_start+1, meta_start)] + '\n')
+ if func_start < 0:
+ pre.append(ll[last:meta_start] + '\n')
+ break
+ header = ll[func_start+1:ll.find('\n', func_start+1)+1]
+ end = ll.find('\n}', func_start)
+ last = end+3
+ funcs.append((header, ll[func_start+1:last]))
+ pre.append(header + '}\n')
+ func_start = last
+ ll = None
+
if DEBUG and len(meta) > 1024*1024: logging.debug('emscript warning: large amounts of metadata, will slow things down')
if DEBUG: logging.debug(' emscript: split took %s seconds' % (time.time() - t))
@@ -195,6 +193,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
jcache.set(shortkey, keys, out)
pre, forwarded_data = out.split('//FORWARDED_DATA:')
forwarded_file = temp_files.get('.json').name
+ pre_input = None
open(forwarded_file, 'w').write(forwarded_data)
if DEBUG: logging.debug(' emscript: phase 1 took %s seconds' % (time.time() - t))