From cb024436717e81efcb6cefb7f1c16ecb86e21afa Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 16 Oct 2019 19:59:02 +0200 Subject: netlists: add remove_instance. --- src/synth/netlists.adb | 32 ++++++++++++++++++++++++++++++++ src/synth/netlists.ads | 3 +++ 2 files changed, 35 insertions(+) (limited to 'src') diff --git a/src/synth/netlists.adb b/src/synth/netlists.adb index ec63c36a1..91bbd94e3 100644 --- a/src/synth/netlists.adb +++ b/src/synth/netlists.adb @@ -353,6 +353,38 @@ package body Netlists is Inst_Ent.Next_Instance := No_Instance; end Extract_Instance; + function Check_Connected (Inst : Instance) return Boolean + is + Nbr_Outputs : constant Port_Idx := Get_Nbr_Outputs (Inst); + Nbr_Inputs : constant Port_Idx := Get_Nbr_Inputs (Inst); + begin + -- Check that all outputs are unused. + if Nbr_Outputs > 1 then + for K in 0 .. Nbr_Outputs - 1 loop + if Is_Connected (Get_Output (Inst, K)) then + return True; + end if; + end loop; + end if; + + -- First disconnect inputs. + if Nbr_Inputs > 0 then + for K in 0 .. Nbr_Inputs - 1 loop + if Get_Driver (Get_Input (Inst, K)) /= No_Net then + return True; + end if; + end loop; + end if; + + return False; + end Check_Connected; + + procedure Remove_Instance (Inst : Instance) is + begin + pragma Assert (not Check_Connected (Inst)); + Extract_Instance (Inst); + end Remove_Instance; + function New_Instance_Internal (Parent : Module; M : Module; Name : Sname; diff --git a/src/synth/netlists.ads b/src/synth/netlists.ads index c1371c835..5e1146fb1 100644 --- a/src/synth/netlists.ads +++ b/src/synth/netlists.ads @@ -369,6 +369,9 @@ private -- instances. procedure Extract_Instance (Inst : Instance); + -- Remove and free the unconnected instance INST. + procedure Remove_Instance (Inst : Instance); + type Input is new Uns32; No_Input : constant Input := 0; -- cgit v1.2.3