mirror of https://github.com/zachjs/sv2v.git
fix infinite loop on mutually recursive functions
This commit is contained in:
parent
d847fdfaca
commit
6d2cdf1d21
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue