diff --git a/src/Convert/Package.hs b/src/Convert/Package.hs index bf2ebdf..c6d9c3e 100644 --- a/src/Convert/Package.hs +++ b/src/Convert/Package.hs @@ -438,21 +438,23 @@ addItems pis existingPIs ((item, usedPIs) : items) = if not $ Set.disjoint existingPIs thisPI then -- this item was re-imported earlier in the module addItems pis existingPIs items - else if null itemsToAdd then + else if Map.null itemsToAdd then -- this item has no additional dependencies item : addItems pis (Set.union existingPIs thisPI) items else -- this item has at least one un-met dependency - addItems pis existingPIs (addUsedPIs chosen : (item, usedPIs) : items) + addItems remainingPIs existingPIs + (addUsedPIs chosenItem : (item, usedPIs) : items) where thisPI = case item of MIPackageItem packageItem -> Set.fromList $ piNames packageItem _ -> Set.empty neededPIs = Set.difference (Set.difference usedPIs existingPIs) thisPI - itemsToAdd = map MIPackageItem $ Map.elems $ - Map.restrictKeys pis neededPIs - chosen = head itemsToAdd + itemsToAdd = Map.restrictKeys pis neededPIs + (chosenName, chosenPI) = Map.findMin itemsToAdd + chosenItem = MIPackageItem chosenPI + remainingPIs = Map.delete chosenName pis addItems _ _ [] = [] -- augment a module item with the set of identifiers it uses diff --git a/test/basic/mutual_recursion.sv b/test/basic/mutual_recursion.sv new file mode 100644 index 0000000..dbbd400 --- /dev/null +++ b/test/basic/mutual_recursion.sv @@ -0,0 +1,24 @@ +module top; + function automatic integer bar; + input integer inp; + begin + if (inp == 0) + bar = 0; + else + bar = 1 + foo(inp - 1); + end + endfunction + function automatic integer foo; + input integer inp; + begin + if (inp == 0) + foo = 0; + else + foo = 1 + bar(inp - 1); + end + endfunction + initial begin + $display("%d", foo(10)); + $display("%d", bar(11)); + end +endmodule