From: Dmitry Selyutin Date: Thu, 21 Sep 2023 17:53:37 +0000 (+0300) Subject: syscalls: introduce generation mode X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f701588eaa0a79d391fc6753892d4321bdc11717;p=openpower-isa.git syscalls: introduce generation mode --- diff --git a/src/openpower/syscalls/__main__.py b/src/openpower/syscalls/__main__.py index 0375d36f..eefa2304 100644 --- a/src/openpower/syscalls/__main__.py +++ b/src/openpower/syscalls/__main__.py @@ -140,16 +140,7 @@ def collect_sysargs(tree): yield (name, dict(zip(arguments[1::2], arguments[0::2]))) -def main(): - parser = argparse.ArgumentParser("lscmg", - description="Linux system calls mapping generator") - parser.add_argument("tree", - help="path to kernel source tree", - type=pathlib.Path) - - arguments = dict(vars(parser.parse_args())) - - tree = arguments.pop("tree") +def generate_json(tree): tree = tree.expanduser() table = { "sysnums": dict(collect_sysnums(tree=tree)), @@ -158,5 +149,22 @@ def main(): print(json.dumps(table, indent=4)) +def main(): + main_parser = argparse.ArgumentParser("lscmg", + description="Linux system calls mapping generator") + main_subparsers = main_parser.add_subparsers(dest="generate", required=True) + + json_parser = main_subparsers.add_parser("json") + json_parser.add_argument("tree", + help="path to kernel source tree", + type=pathlib.Path) + json_parser.set_defaults(generate=generate_json) + + arguments = dict(vars(main_parser.parse_args())) + generate = arguments.pop("generate") + + return generate(**arguments) + + if __name__ == "__main__": main()