aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2021-05-07 19:19:26 +0200
committerTristan Gingold <tgingold@free.fr>2021-05-07 19:19:26 +0200
commit6266bf8c49ecf5d04d6de11b9d4d1064bbd84bcd (patch)
tree583d7d7f6c4f6dac9b701fbe94a3994ddd0e49e2 /src
parentc14fc37207ff2f631c9fbd725c2ed03b9f5d1a02 (diff)
downloadghdl-6266bf8c49ecf5d04d6de11b9d4d1064bbd84bcd.tar.gz
ghdl-6266bf8c49ecf5d04d6de11b9d4d1064bbd84bcd.tar.bz2
ghdl-6266bf8c49ecf5d04d6de11b9d4d1064bbd84bcd.zip
netlists-cleanup: do not remove self-assigned output gate
Diffstat (limited to 'src')
-rw-r--r--src/synth/netlists-cleanup.adb53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/synth/netlists-cleanup.adb b/src/synth/netlists-cleanup.adb
index 2f741e3f3..d7d74b83d 100644
--- a/src/synth/netlists-cleanup.adb
+++ b/src/synth/netlists-cleanup.adb
@@ -112,6 +112,35 @@ package body Netlists.Cleanup is
end loop;
end Remove_Unconnected_Instances;
+ procedure Remove_Output_Gate (Inst : Instance)
+ is
+ use Netlists.Gates;
+ Inp : constant Input := Get_Input (Inst, 0);
+ In_Drv : constant Net := Get_Driver (Inp);
+ O : constant Net := Get_Output (Inst, 0);
+ begin
+ if In_Drv = O then
+ -- Connected to itself.
+ -- TODO: convert to initial value or to X.
+ return;
+ end if;
+
+ if In_Drv /= No_Net then
+ -- Only when the output is driven.
+ Disconnect (Inp);
+ Redirect_Inputs (O, In_Drv);
+ else
+ Disconnect (Get_First_Sink (O));
+ end if;
+
+ if Get_Id (Inst) = Id_Ioutput then
+ -- Disconnect the initial value.
+ Disconnect (Get_Input (Inst, 1));
+ end if;
+
+ Remove_Instance (Inst);
+ end Remove_Output_Gate;
+
procedure Remove_Output_Gates (M : Module)
is
use Netlists.Gates;
@@ -130,29 +159,7 @@ package body Netlists.Cleanup is
| Id_Nop =>
-- Keep gates with an attribute.
if not Has_Attribute (Inst) then
- declare
- Inp : Input;
- In_Drv : Net;
- O : Net;
- begin
- Inp := Get_Input (Inst, 0);
- In_Drv := Get_Driver (Inp);
- O := Get_Output (Inst, 0);
- if In_Drv /= No_Net then
- -- Only when the output is driven.
- Disconnect (Inp);
- Redirect_Inputs (O, In_Drv);
- else
- Disconnect (Get_First_Sink (O));
- end if;
-
- if Get_Id (Inst) = Id_Ioutput then
- -- Disconnect the initial value.
- Disconnect (Get_Input (Inst, 1));
- end if;
-
- Remove_Instance (Inst);
- end;
+ Remove_Output_Gate (Inst);
end if;
when others =>
null;