From c7510177d5cd00b2db7cc97a4d60ac405f56f35d Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Thu, 21 Sep 2023 20:53:37 +0300 Subject: [PATCH] syscalls: introduce generation mode --- src/openpower/syscalls/__main__.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) 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() -- 2.30.2