Add system Verilog support for the Vivado builder
authorMartin Cornil <martin.cornil@railnova.eu>
Thu, 10 Oct 2019 12:06:37 +0000 (14:06 +0200)
committerMartin Cornil <martin.cornil@railnova.eu>
Thu, 10 Oct 2019 12:10:28 +0000 (14:10 +0200)
litex/build/generic_platform.py
litex/build/tools.py
litex/build/xilinx/vivado.py

index 7ea71752ec2bd0e6b9d45a9b36b6e92b5018a9ea..50af71275d5d39d8f8d72eede471da8357dff8ab 100644 (file)
@@ -334,7 +334,7 @@ class GenericPlatform:
         for f in filenames:
             self.add_source(os.path.join(path, f), language, library)
 
-    def add_source_dir(self, path, recursive=True, library=None):
+    def add_source_dir(self, path, recursive=True, language=None, library=None):
         dir_files = []
         if recursive:
             for root, dirs, files in os.walk(path):
@@ -345,9 +345,7 @@ class GenericPlatform:
                 if os.path.isfile(os.path.join(path, item)):
                     dir_files.append(os.path.join(path, item))
         for filename in dir_files:
-            language = tools.language_by_filename(filename)
-            if language is not None:
-                self.add_source(filename, language, library)
+            self.add_source(filename, language, library)
 
     def add_verilog_include_path(self, path):
         self.verilog_include_paths.add(os.path.abspath(path))
index 8132620129cf7edff3f43066d247a5db783aeaac..7a5bbbd06dad7463e58b26ea748cc629cc30f6e6 100644 (file)
@@ -19,8 +19,10 @@ def language_by_filename(name):
     extension = name.rsplit(".")[-1]
     if extension in ["v", "vh", "vo"]:
         return "verilog"
-    if extension in ["vhd", "vhdl", "vho"]:
+    elif extension in ["vhd", "vhdl", "vho"]:
         return "vhdl"
+    elif extension in ["sv"]:
+        return "systemverilog"
     return None
 
 
index f22b44c92617017e5a1b693c8f307213ed74e86e..540e030f16230c649e8d2267ed92a0c28131c094 100644 (file)
@@ -126,10 +126,16 @@ class XilinxVivadoToolchain:
             # "-include_dirs {}" crashes Vivado 2016.4
             for filename, language, library in sources:
                 filename_tcl = "{" + filename + "}"
-                tcl.append("add_files " + filename_tcl)
-                if language == "vhdl":
+                if ("systemverilog" == language):
+                    tcl.append("read_verilog -sv " + filename_tcl)
+                elif ("verilog" == language):
+                    tcl.append("read_verilog " + filename_tcl)
+                elif ("vhdl" == language):
+                    tcl.append("read_vhdl " + filename_tcl)
                     tcl.append("set_property library {} [get_files {}]"
                                .format(library, filename_tcl))
+                else:
+                    tcl.append("add_files " + filename_tcl)
         for filename in edifs:
             filename_tcl = "{" + filename + "}"
             tcl.append("read_edif " + filename_tcl)