From 60f7dadad6b34741a9246373a985541bde89f697 Mon Sep 17 00:00:00 2001
From: Daniel Newbrook <dwn1c21@soton.ac.uk>
Date: Mon, 3 Jul 2023 09:27:27 +0100
Subject: [PATCH] Add recursiive read to flist tcl script

---
 fpga_imp/scripts/flist_to_tcl.py | 35 +++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/fpga_imp/scripts/flist_to_tcl.py b/fpga_imp/scripts/flist_to_tcl.py
index 8227e32..b5d8f4e 100644
--- a/fpga_imp/scripts/flist_to_tcl.py
+++ b/fpga_imp/scripts/flist_to_tcl.py
@@ -1,5 +1,5 @@
-import argparse
 import os
+import argparse
 parser = argparse.ArgumentParser(description="Take flist file for verilog simulation and convert to tcl readable",
                                  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
 parser.add_argument("-i", "--input", help="input flist file")
@@ -7,19 +7,40 @@ parser.add_argument("-o", "--output", help="output tcl file")
 args = parser.parse_args()
 config = vars(args)
 
-if not os.path.exists(config["output"]):
-    outfile = open(config["output"], "a")
 
-
-    for line in open(config["input"]):
+def readFlist(fname, outfile):
+    for line in open(fname):
         li = line.strip()
         if not li.startswith("//"):
-            if li.endswith(".v"):
+            if li.startswith("-f"):
+                #Read file and run readFlist 
+                li = li.replace("-f ","")
+                tmp = li.split('/')
+                tmp[0]=tmp[0].replace("$","")
+                tmp[0]=tmp[0].replace('(','')
+                tmp[0]=tmp[0].replace(')','')
+                print(tmp)
+                envPath = os.environ.get(tmp[0])
+                print(envPath)
+                tmp.pop(0)
+                infile = envPath
+                for dir in tmp:
+                    infile += '/' + dir
+                print(infile)
+                readFlist(infile,outfile)
+            elif li.endswith(".v"):
                 output = (line.rstrip()).replace("$","read_verilog $env")
                 outfile.write(output+'\n')
+    return
 
 
-    outfile.close()
+if not os.path.exists(config["output"]):
+    if os.path.exists(config["input"]):
+        outfile = open(config["output"], "a")
+        readFlist(config["input"],outfile)
+        outfile.close()
+    else:
+        print("ERROR: Input file does not exist")
 else:
     print("ERROR: Output file already exists")
 
-- 
GitLab