amd/registers: expose the canonicalize.py program as a function
authorMarek Olšák <marek.olsak@amd.com>
Thu, 20 Aug 2020 08:02:10 +0000 (04:02 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 1 Sep 2020 12:45:45 +0000 (08:45 -0400)
Acked-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6423>

src/amd/registers/canonicalize.py

index 958f43894333de94d4d077b84f6592c4097c4a7c..a1b7023a20147e05c96db0b769029a07ff1a103e 100644 (file)
@@ -68,23 +68,24 @@ def deduce_missing_register_types(regdb):
                 regmap.type_ref = regtypename
 
 
-def main():
-    regdb_filename = sys.argv[1]
-    with open(regdb_filename, 'r') as filp:
-        regdb = RegisterDatabase.from_json(json.load(filp))
+def json_canonicalize(filp, chips = None):
+    regdb = RegisterDatabase.from_json(json.load(filp))
 
-    if len(sys.argv) > 2:
+    if chips is not None:
         for regmap in regdb.register_mappings():
             assert not hasattr(regmap, 'chips')
-            regmap.chips = [sys.argv[2]]
+            regmap.chips = [chips]
 
     deduplicate_enums(regdb)
     deduplicate_register_types(regdb)
     deduce_missing_register_types(regdb)
     regdb.garbage_collect()
 
-    print(regdb.encode_json_pretty())
+    return regdb.encode_json_pretty()
+
 
+def main():
+    print(json_canonicalize(open(sys.argv[1], 'r'), sys.argv[2]))
 
 if __name__ == '__main__':
     main()