syscalls: introduce generation mode
authorDmitry Selyutin <ghostmansd@gmail.com>
Thu, 21 Sep 2023 17:53:37 +0000 (20:53 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 26 Sep 2023 21:08:32 +0000 (22:08 +0100)
src/openpower/syscalls/__main__.py

index 0375d36fdcb1b244a287bf79d67fb1eb28e4c462..eefa2304315c96640c6d9e941fb2a3dd58bfdbbe 100644 (file)
@@ -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()