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

Method hardcode_arguments

test/test_benchmark.py:449–473  ·  view source on GitHub ↗

Avoid depending on argument reception from the commandline, where possible. Here we take the command line arguments and embed them directly into `main` function. If we cannot find a `main` function, or if we have more than one argument, we do not do any embedding, and the resulting test

(self, code, args)

Source from the content-addressed store, hash-verified

447 utils.write_file('stats.json', json.dumps(output, indent=2) + '\n')
448
449 def hardcode_arguments(self, code, args):
450 """Avoid depending on argument reception from the commandline, where possible.
451
452 Here we take the command line arguments and embed them directly into `main` function.
453 If we cannot find a `main` function, or if we have more than one argument, we
454 do not do any embedding, and the resulting test will depend on arguments being
455 passed via argv (which works in most environments).
456 """
457 if not code or 'int main()' in code:
458 return code
459 # We only know how to embed a single argument
460 if len(args) != 1:
461 return code
462 main_pattern = 'int main(int argc, char **argv)'
463 assert main_pattern in code
464 code = code.replace(main_pattern, 'int benchmark_main(int argc, char **argv)')
465 code += '''
466 int main() {
467 int newArgc = 2;
468 char* newArgv[] = { (char*)"./program.exe", (char*)"%s" };
469 int ret = benchmark_main(newArgc, newArgv);
470 return ret;
471 }
472 ''' % args[0]
473 return code
474
475 def do_benchmark(self, name, src, expected_output='FAIL', args=None,
476 emcc_args=None, native_args=None, shared_args=None,

Callers 1

do_benchmarkMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected