utils/vlog: Fix model.xml includes and handling of modes

Signed-off-by: David Shah <davey1576@gmail.com>
diff --git a/tests/tests.sim.v b/tests/tests.sim.v
index 478cb36..77a073c 100644
--- a/tests/tests.sim.v
+++ b/tests/tests.sim.v
@@ -3,7 +3,7 @@
 `include "lut2/lut2.sim.v"
 
 
-(* MODES="ADD,LUT" *)
+(* MODES="ADD, LUT" *)
 module tests(input clk, a, b, ci, output q, co);
   parameter MODE = "ADD";
   wire d;
diff --git a/vlog_to_model.py b/vlog_to_model.py
index 862c1e5..d4e0d62 100755
--- a/vlog_to_model.py
+++ b/vlog_to_model.py
@@ -74,11 +74,16 @@
 tmod = yj.top_module
 models_xml = ET.Element("models", nsmap = {'xi': xi_url})
 
+inc_re = re.compile(r'^\s*`include\s+"([^"]+)"')
+
 deps_files = set()
-for mod in yj.all_modules():
-    if mod != top:
-        modfile = yj.get_module_file(mod)
-        deps_files.add(modfile)
+# XML dependencies need to correspond 1:1 with Verilog includes, so we have
+# to do this manually rather than using Yosys
+with open(args.infiles[0], 'r') as f:
+    for line in f:
+        im = inc_re.match(line)
+        if im:
+            deps_files.add(im.group(1))
 
 if len(deps_files) > 0:
     # Has dependencies, not a leaf model
diff --git a/vlog_to_pbtype.py b/vlog_to_pbtype.py
index 51e471b..d04cef0 100755
--- a/vlog_to_pbtype.py
+++ b/vlog_to_pbtype.py
@@ -302,9 +302,10 @@
 
     if has_modes:
         for mode in modes:
-            mode_xml = ET.SubElement(pb_type_xml, "mode", {"name" : mode})
+            smode = mode.strip()
+            mode_xml = ET.SubElement(pb_type_xml, "mode", {"name" : smode})
             # Rerun Yosys with mode parameter
-            mode_yj = YosysJson(yosys.run.vlog_to_json(args.infiles, False, False, mode, mod.name))
+            mode_yj = YosysJson(yosys.run.vlog_to_json(args.infiles, False, False, smode, mod.name))
             mode_mod = mode_yj.module(mod.name)
             make_pb_content(mode_mod, mode_xml, mod_pname, True)
     else: