MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / eval_ctors

Function eval_ctors

tools/building.py:443–487  ·  view source on GitHub ↗
(js_file, wasm_file, debug_info)

Source from the content-addressed store, hash-verified

441# evals ctors. if binaryen_bin is provided, it is the dir of the binaryen tool
442# for this, and we are in wasm mode
443def eval_ctors(js_file, wasm_file, debug_info):
444 CTOR_ADD_PATTERN = f"wasmExports['{WASM_CALL_CTORS}']();"
445
446 js = utils.read_file(js_file)
447
448 has_wasm_call_ctors = False
449
450 # eval the ctor caller as well as main, or, in standalone mode, the proper
451 # entry/init function
452 if not settings.STANDALONE_WASM:
453 ctors = []
454 kept_ctors = []
455 has_wasm_call_ctors = CTOR_ADD_PATTERN in js
456 if has_wasm_call_ctors:
457 ctors += [WASM_CALL_CTORS]
458 if settings.HAS_MAIN:
459 main = 'main'
460 if '__main_argc_argv' in settings.WASM_EXPORTS:
461 main = '__main_argc_argv'
462 ctors += [main]
463 # TODO perhaps remove the call to main from the JS? or is this an abi
464 # we want to preserve?
465 kept_ctors += [main]
466 if not ctors:
467 logger.info('ctor_evaller: no ctors')
468 return
469 args = ['--ctors=' + ','.join(ctors)]
470 if kept_ctors:
471 args += ['--kept-exports=' + ','.join(kept_ctors)]
472 else:
473 if settings.EXPECT_MAIN:
474 ctor = '_start'
475 else:
476 ctor = '_initialize'
477 args = ['--ctors=' + ctor, '--kept-exports=' + ctor]
478 if settings.EVAL_CTORS == 2:
479 args += ['--ignore-external-input']
480 logger.info('ctor_evaller: trying to eval global ctors (' + ' '.join(args) + ')')
481 out = run_binaryen_command('wasm-ctor-eval', wasm_file, wasm_file, args=args, stdout=PIPE, debug=debug_info)
482 logger.info('\n\n' + out)
483 num_successful = out.count('success on')
484 if num_successful and has_wasm_call_ctors:
485 js = js.replace(CTOR_ADD_PATTERN, '')
486 settings.WASM_EXPORTS.remove(WASM_CALL_CTORS)
487 utils.write_file(js_file, js)
488
489
490def get_closure_compiler():

Callers

nothing calls this directly

Calls 5

run_binaryen_commandFunction · 0.85
write_fileMethod · 0.80
countMethod · 0.65
joinMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected