From 6266bf8c49ecf5d04d6de11b9d4d1064bbd84bcd Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 7 May 2021 19:19:26 +0200 Subject: netlists-cleanup: do not remove self-assigned output gate --- src/synth/netlists-cleanup.adb | 53 ++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'src') 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; -- cgit v1.2.3