aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-10-16 19:59:02 +0200
committerTristan Gingold <tgingold@free.fr>2019-10-16 19:59:02 +0200
commitcb024436717e81efcb6cefb7f1c16ecb86e21afa (patch)
treea3cd0ccd8dcc5fd508e725ab053bdab40f01a554 /src
parentbfdbb20572ee1181e6b16fd86ccdb03c8c8e5bf5 (diff)
downloadghdl-cb024436717e81efcb6cefb7f1c16ecb86e21afa.tar.gz
ghdl-cb024436717e81efcb6cefb7f1c16ecb86e21afa.tar.bz2
ghdl-cb024436717e81efcb6cefb7f1c16ecb86e21afa.zip
netlists: add remove_instance.
Diffstat (limited to 'src')
-rw-r--r--src/synth/netlists.adb32
-rw-r--r--src/synth/netlists.ads3
2 files changed, 35 insertions, 0 deletions
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;