From a54be8dae6854750800f0b702c1c8218d40391fc Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sun, 17 Jul 2022 20:58:36 -0400 Subject: [PATCH] instances supply names during reordering --- CHANGELOG.md | 1 + src/Convert/Package.hs | 6 +++++- test/core/reorder_shadow.sv | 29 +++++++++++++++++++++++++++++ test/core/reorder_shadow.v | 30 ++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/core/reorder_shadow.sv create mode 100644 test/core/reorder_shadow.v diff --git a/CHANGELOG.md b/CHANGELOG.md index fedd040..1dde2db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ accessed directly * Fixed conversion of casts using structs containing multi-dimensional fields * Fixed incorrect name resolution conflicts raised during interface inlining +* Fixed handling of interface instances which shadow other declarations ## v0.0.9 diff --git a/src/Convert/Package.hs b/src/Convert/Package.hs index 71c95e3..656cf0a 100644 --- a/src/Convert/Package.hs +++ b/src/Convert/Package.hs @@ -652,7 +652,7 @@ reorderGenItem item = item -- iteratively inserts missing package items exactly where they are needed addItems :: PIs -> Idents -> [(ModuleItem, Idents)] -> [ModuleItem] addItems pis existingPIs ((item, usedPIs) : items) = - if not $ Set.disjoint existingPIs thisPI then + if not $ forceKeep || Set.disjoint existingPIs thisPI then -- this item was re-imported earlier in the module addItems pis existingPIs items else if Map.null itemsToAdd then @@ -666,7 +666,11 @@ addItems pis existingPIs ((item, usedPIs) : items) = thisPI = case item of MIPackageItem packageItem -> Set.fromList $ piNames packageItem + Instance _ _ x _ _ -> Set.singleton x _ -> Set.empty + forceKeep = case item of + Instance{} -> True + _ -> False neededPIs = Set.difference (Set.difference usedPIs existingPIs) thisPI itemsToAdd = Map.restrictKeys pis neededPIs (chosenName, chosenPI) = Map.findMin itemsToAdd diff --git a/test/core/reorder_shadow.sv b/test/core/reorder_shadow.sv new file mode 100644 index 0000000..7192e15 --- /dev/null +++ b/test/core/reorder_shadow.sv @@ -0,0 +1,29 @@ +typedef logic over; + +interface intf; + logic [3:0] x; + assign x[0] = 0; + initial $display("intf x %b", x); +endinterface + +module mod(intf i); + assign i.x[1] = 1; + initial $display("mod i.x %b", i.x); +endmodule + +module check; + over y; + intf over(); + mod m(over); + assign over.x[2] = 1'bz; + initial $display("check over.x %b", over.x); + initial $display("check y %b", y); +endmodule + +module top; + check c(); + intf over(); + mod m(over); + assign over.x[2] = 1'bz; + initial $display("top over.x %b", over.x); +endmodule diff --git a/test/core/reorder_shadow.v b/test/core/reorder_shadow.v new file mode 100644 index 0000000..333c05d --- /dev/null +++ b/test/core/reorder_shadow.v @@ -0,0 +1,30 @@ +module check; + wire y; + if (1) begin : over + wire [3:0] x; + assign x[0] = 0; + initial $display("intf x %b", x); + end + if (1) begin : m + assign over.x[1] = 1; + initial $display("mod i.x %b", over.x); + end + assign over.x[2] = 1'bz; + initial $display("check over.x %b", over.x); + initial $display("check y %b", y); +endmodule + +module top; + check c(); + if (1) begin : over + wire [3:0] x; + assign x[0] = 0; + initial $display("intf x %b", x); + end + if (1) begin : m + assign over.x[1] = 1; + initial $display("mod i.x %b", over.x); + end + assign over.x[2] = 1'bz; + initial $display("top over.x %b", over.x); +endmodule