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

Function main

tools/gen_struct_info.py:336–402  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

334
335
336def main(args):
337 global QUIET
338
339 parser = argparse.ArgumentParser(description='Generate JSON infos for structs.')
340 parser.add_argument('json', nargs='*',
341 help='JSON file with a list of structs and their fields (defaults to src/struct_info.json)',
342 default=DEFAULT_JSON_FILES)
343 parser.add_argument('-q', dest='quiet', action='store_true', default=False,
344 help='Don\'t output anything besides error messages.')
345 parser.add_argument('-o', dest='output', metavar='path', default=None,
346 help='Path to the JSON file that will be written. If omitted, the default location under `src` will be used.')
347 parser.add_argument('-I', dest='includes', metavar='dir', action='append', default=[],
348 help='Add directory to include search path')
349 parser.add_argument('-D', dest='defines', metavar='define', action='append', default=[],
350 help='Pass a define to the preprocessor')
351 parser.add_argument('-U', dest='undefines', metavar='undefine', action='append', default=[],
352 help='Pass an undefine to the preprocessor')
353 parser.add_argument('--wasm64', action='store_true',
354 help='use wasm64 architecture')
355 args = parser.parse_args(args)
356
357 QUIET = args.quiet
358
359 extra_cflags = []
360
361 if args.wasm64:
362 # Always use =2 here so that we don't generate a binary that actually requires
363 # memory64 to run. All we care about is that the output is correct.
364 extra_cflags += ['-sMEMORY64=2']
365
366 # Add the user options to the list as well.
367 for path in args.includes:
368 extra_cflags.append('-I' + path)
369
370 for arg in args.defines:
371 extra_cflags.append('-D' + arg)
372
373 for arg in args.undefines:
374 extra_cflags.append('-U' + arg)
375
376 # Look for structs in all passed headers.
377 info = {'defines': {}, 'structs': {}}
378
379 for f in args.json:
380 # This is a JSON file, parse it.
381 header_files = parse_json(f)
382 # Inspect all collected structs.
383 if 'internal' in f:
384 use_cflags = CFLAGS + extra_cflags + INTERNAL_CFLAGS
385 elif 'cxx' in f:
386 use_cflags = CFLAGS + extra_cflags + CXXFLAGS
387 else:
388 use_cflags = CFLAGS + extra_cflags
389 info_fragment = inspect_code(header_files, use_cflags)
390 merge_info(info, info_fragment)
391
392 if args.output:
393 output_file = args.output

Callers 1

gen_struct_info.pyFile · 0.70

Calls 6

parse_jsonFunction · 0.85
inspect_codeFunction · 0.85
merge_infoFunction · 0.85
output_jsonFunction · 0.85
appendMethod · 0.80
openFunction · 0.50

Tested by

no test coverage detected