pyfnwriter: introduce C mode
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 3 Dec 2023 11:56:10 +0000 (14:56 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 3 Dec 2023 11:56:10 +0000 (14:56 +0300)
src/openpower/decoder/pseudo/pyfnwriter.py

index ebb9158fe766106cac2c2f622f6e9610835d27ff..01c1ea8f93f423948c686ec42d81b3225d83077a 100644 (file)
@@ -35,12 +35,12 @@ class PyISAFnWriter(ISAFunctions):
         ISAFunctions.__init__(self)
         self.pages_written = []
 
-    def write_pysource(self, pagename):
+    def write_code(self, pagename, ext):
         self.pages_written.append(pagename)
         function = self.fns[pagename]
         isadir = get_isafn_src_dir()
         os.makedirs(isadir, exist_ok=True)
-        fname = os.path.join(isadir, "%s.py" % pagename)
+        fname = os.path.join(isadir, (pagename + ext))
         sourcecache = dict()
         check_in_gitignore(fname)
         with open(fname, "w") as f:
@@ -92,17 +92,24 @@ class PyISAFnWriter(ISAFunctions):
 def pyfnwriter():
     isa = PyISAFnWriter()
     write_isa_class = True
-    if len(sys.argv) == 1:  # quick way to do it
+    args = dict.fromkeys(sys.argv[1:])
+    ext = ".py"
+    if "--c" in args:
+        ext = ".c"
+        del args["--c"]
+    if len(args) == 0:  # quick way to do it
         log(dir(isa))
         sources = isa.fns.keys()
     else:
-        sources = sys.argv[1:]
+        sources = list(args)
         if sources[0] == "noall": # don't rewrite all.py
             write_isa_class = False
             sources.pop(0)
+    if ext == ".c":
+        raise NotImplementedError("C mode is not supported yet")
     log("sources", write_isa_class, sources)
     for source in sources:
-        isa.write_pysource(source)
+        isa.write_code(pagename=source, ext=ext)
     if write_isa_class:
         isa.write_isa_class()