diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-09-17 02:16:28 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-09-17 02:16:28 +0200 |
commit | b3a28203e95f68bd1007c4c11b44187ecabbf593 (patch) | |
tree | 114e02aa47dae4a5776692b81daeed24d25df97d /src/synth/synth-environment.adb | |
parent | 2ab83662516b7466e1870548cb8906e0842bb3ca (diff) | |
download | ghdl-b3a28203e95f68bd1007c4c11b44187ecabbf593.tar.gz ghdl-b3a28203e95f68bd1007c4c11b44187ecabbf593.tar.bz2 ghdl-b3a28203e95f68bd1007c4c11b44187ecabbf593.zip |
synth: fold addition on constant nets.
Diffstat (limited to 'src/synth/synth-environment.adb')
-rw-r--r-- | src/synth/synth-environment.adb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/synth/synth-environment.adb b/src/synth/synth-environment.adb index 5a517b7d5..1d054d21b 100644 --- a/src/synth/synth-environment.adb +++ b/src/synth/synth-environment.adb @@ -1104,6 +1104,51 @@ package body Synth.Environment is Phi_Assign (Ctxt, Dest, Pasgn); end Phi_Assign; + + -- Return the net driving WID when it is known to be possibly constant. + -- Return No_Net is not constant. + function Get_Const_Net_Maybe (Wid : Wire_Id) return Net + is + Wire_Rec : Wire_Id_Record renames Wire_Id_Table.Table (Wid); + Pasgn : Partial_Assign; + N : Net; + begin + if Wire_Rec.Kind /= Wire_Variable then + return No_Net; + end if; + if Wire_Rec.Cur_Assign = No_Seq_Assign then + return No_Net; + end if; + Pasgn := Get_Assign_Partial (Wire_Rec.Cur_Assign); + pragma Assert (Pasgn /= No_Partial_Assign); + if Get_Partial_Offset (Pasgn) /= 0 then + return No_Net; + end if; + N := Get_Partial_Value (Pasgn); + if Get_Width (N) /= Get_Width (Wire_Rec.Gate) then + return No_Net; + end if; + return N; + end Get_Const_Net_Maybe; + + function Is_Const_Wire (Wid : Wire_Id) return Boolean + is + N : constant Net := Get_Const_Net_Maybe (Wid); + begin + if N = No_Net then + return False; + else + return Is_Const_Net (N); + end if; + end Is_Const_Wire; + + function Get_Const_Wire (Wid : Wire_Id) return Net + is + N : constant Net := Get_Const_Net_Maybe (Wid); + begin + pragma Assert (N /= No_Net); + return N; + end Get_Const_Wire; begin Wire_Id_Table.Append ((Kind => Wire_None, Mark_Flag => False, |