Fix normal (non-array) hierarchy -auto-top.
authorJim Lawson <ucbjrl@berkeley.edu>
Tue, 19 Feb 2019 22:35:15 +0000 (14:35 -0800)
committerJim Lawson <ucbjrl@berkeley.edu>
Tue, 19 Feb 2019 22:35:15 +0000 (14:35 -0800)
Add simple test.

passes/hierarchy/hierarchy.cc
tests/various/hierarchy.sh [new file with mode: 0644]
tests/various/run-test.sh

index 332ebdfbb1ecec8155c269a35b445cc24b24b341..f112e969e72331bfaead0a89cd1d0397b03f9663 100644 (file)
@@ -523,15 +523,15 @@ int find_top_mod_score(Design *design, Module *module, dict<Module*, int> &db)
                        // Is this an array instance
                        if (celltype.substr(0, 7) == "$array:") {
                                celltype = basic_cell_type(celltype);
-                               // Is this cell is a module instance?
-                               if (celltype[0] != '$') {
-                                       auto instModule = design->module(celltype);
-                                       // If there is no instance for this, issue a warning.
-                                       if (instModule == NULL) {
-                                               log_warning("find_top_mod_score: no instance for %s.%s\n", celltype.c_str(), cell->name.c_str());
-                                       }
-                                       if (instModule != NULL)
-                                               score = max(score, find_top_mod_score(design, instModule, db) + 1);
+                       }
+                       // Is this cell a module instance?
+                       if (celltype[0] != '$') {
+                               auto instModule = design->module(celltype);
+                               // If there is no instance for this, issue a warning.
+                               if (instModule == NULL) {
+                                       log_warning("find_top_mod_score: no instance for %s.%s\n", celltype.c_str(), cell->name.c_str());
+                               } else {
+                                       score = max(score, find_top_mod_score(design, instModule, db) + 1);
                                }
                        }
                }
diff --git a/tests/various/hierarchy.sh b/tests/various/hierarchy.sh
new file mode 100644 (file)
index 0000000..dcb4dc0
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+# Simple test of hierarchy -auto-top.
+
+set -e
+
+../../yosys -q -s - <<- EOY 2>&1 | grep "Automatically selected TOP as design top module"
+  read_verilog << EOV
+    module TOP(a, y);
+      input a;
+      output [31:0] y;
+
+      aoi12 p [31:0] (a, y);
+    endmodule
+
+    module aoi12(a, y);
+      input a;
+      output y;
+      assign y = ~a;
+    endmodule
+  EOV
+  hierarchy -auto-top
+EOY
+
+../../yosys -q -s - <<- EOY 2>&1 | grep "Automatically selected TOP as design top module"
+  read_verilog << EOV
+    module aoi12(a, y);
+      input a;
+      output y;
+      assign y = ~a;
+    endmodule
+
+    module TOP(a, y);
+      input a;
+      output [31:0] y;
+
+      aoi12 foo (a, y);
+    endmodule
+  EOV
+  hierarchy -auto-top
+EOY
+
+../../yosys -q -s - <<- EOY 2>&1 | grep "Automatically selected noTop as design top module."
+  read_verilog << EOV
+    module aoi12(a, y);
+      input a;
+      output y;
+      assign y = ~a;
+    endmodule
+
+    module noTop(a, y);
+      input a;
+      output [31:0] y;
+    endmodule
+  EOV
+  hierarchy -auto-top
+EOY
index 67e1beb23b3a4fe2a48c13617cc8db2e4dd243c5..7cd1a8650f7b036119a730d1b55d07a88440a08e 100755 (executable)
@@ -1,6 +1,14 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -e
 for x in *.ys; do
        echo "Running $x.."
        ../../yosys -ql ${x%.ys}.log $x
 done
+# Run any .sh files in this directory (with the exception of the file - run-test.sh
+shell_tests=$(echo *.sh | sed -e 's/run-test.sh//')
+if [ "$shell_tests" ]; then
+    for s in $shell_tests; do
+        echo "Running $s.."
+        bash $s >& ${s%.sh}.log
+    done
+fi