diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-05-15 07:36:08 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-05-15 07:36:08 +0200 |
commit | c8c834c7c3934214fb039e8100eda2d8535c7174 (patch) | |
tree | de3c82876ad8322805681698872b69770ae423d6 | |
parent | 84f0148e9e01c14993d5473e66a4ad6eee819798 (diff) | |
download | ghdl-c8c834c7c3934214fb039e8100eda2d8535c7174.tar.gz ghdl-c8c834c7c3934214fb039e8100eda2d8535c7174.tar.bz2 ghdl-c8c834c7c3934214fb039e8100eda2d8535c7174.zip |
synth: handle null array comparison. Fix #1311
-rw-r--r-- | src/synth/netlists-folds.adb | 29 | ||||
-rw-r--r-- | src/synth/netlists-folds.ads | 9 | ||||
-rw-r--r-- | src/synth/synth-oper.adb | 18 |
3 files changed, 45 insertions, 11 deletions
diff --git a/src/synth/netlists-folds.adb b/src/synth/netlists-folds.adb index 9aa070238..c4138d0cd 100644 --- a/src/synth/netlists-folds.adb +++ b/src/synth/netlists-folds.adb @@ -20,7 +20,6 @@ with Types_Utils; use Types_Utils; -with Netlists.Gates; use Netlists.Gates; with Netlists.Utils; use Netlists.Utils; with Netlists.Locations; use Netlists.Locations; @@ -296,4 +295,32 @@ package body Netlists.Folds is Set_Location (N, Loc); return N; end Build2_And; + + function Build2_Compare (Ctxt : Context_Acc; + Id : Compare_Module_Id; + L, R : Net) return Net + is + W : constant Width := Get_Width (L); + begin + if W > 0 then + -- A real gate. + return Build_Compare (Ctxt, Id, L, R); + end if; + + pragma Assert (Get_Width (R) = 0); + case Id is + when Id_Eq + | Id_Sle + | Id_Ule + | Id_Sge + | Id_Uge => + return Build_Const_UB32 (Ctxt, 1, 1); + when Id_Ne + | Id_Slt + | Id_Ult + | Id_Sgt + | Id_Ugt => + return Build_Const_UB32 (Ctxt, 0, 1); + end case; + end Build2_Compare; end Netlists.Folds; diff --git a/src/synth/netlists-folds.ads b/src/synth/netlists-folds.ads index 1aa020df9..6c63f49bc 100644 --- a/src/synth/netlists-folds.ads +++ b/src/synth/netlists-folds.ads @@ -18,6 +18,7 @@ -- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, -- MA 02110-1301, USA. +with Netlists.Gates; use Netlists.Gates; with Netlists.Builders; use Netlists.Builders; package Netlists.Folds is @@ -78,5 +79,11 @@ package Netlists.Folds is -- If A is No_Net, simply return B so that it is possible to easily build -- chain of conditions. function Build2_And (Ctxt : Context_Acc; A, B : Net; Loc : Location_Type) - return Net; + return Net; + + -- Like Build_Compare but handle net of width 0. + function Build2_Compare (Ctxt : Context_Acc; + Id : Compare_Module_Id; + L, R : Net) return Net; + end Netlists.Folds; diff --git a/src/synth/synth-oper.adb b/src/synth/synth-oper.adb index 4e1c16cb8..c34ec4875 100644 --- a/src/synth/synth-oper.adb +++ b/src/synth/synth-oper.adb @@ -417,7 +417,7 @@ package body Synth.Oper is begin pragma Assert (Left_Type = Right_Type); pragma Assert (Res_Type = Expr_Typ); - N := Build_Compare + N := Build2_Compare (Ctxt, Id, Get_Net (Ctxt, Left), Get_Net (Ctxt, Right)); Set_Location (N, Expr); return Create_Value_Net (N, Res_Type); @@ -430,7 +430,7 @@ package body Synth.Oper is Sel, N : Net; begin pragma Assert (Left_Type = Right_Type); - Sel := Build_Compare (Ctxt, Id, L, R); + Sel := Build2_Compare (Ctxt, Id, L, R); Set_Location (Sel, Expr); N := Build_Mux2 (Ctxt, Sel, R, L); Set_Location (N, Expr); @@ -446,7 +446,7 @@ package body Synth.Oper is Warning_Msg_Synth (+Expr, "comparing non-numeric vector is unexpected"); if Left.Typ.W = Right.Typ.W then - N := Build_Compare + N := Build2_Compare (Ctxt, Id, Get_Net (Ctxt, Left), Get_Net (Ctxt, Right)); Set_Location (N, Expr); return Create_Value_Net (N, Res_Type); @@ -468,7 +468,7 @@ package body Synth.Oper is N : Net; begin N := Synth_Uresize (Ctxt, Right, Left.Typ.W, Expr); - N := Build_Compare (Ctxt, Id, Get_Net (Ctxt, Left), N); + N := Build2_Compare (Ctxt, Id, Get_Net (Ctxt, Left), N); Set_Location (N, Expr); return Create_Value_Net (N, Res_Type); end Synth_Compare_Uns_Nat; @@ -479,7 +479,7 @@ package body Synth.Oper is N : Net; begin N := Synth_Uresize (Ctxt, Left, Right.Typ.W, Expr); - N := Build_Compare (Ctxt, Id, Get_Net (Ctxt, Right), N); + N := Build2_Compare (Ctxt, Id, Get_Net (Ctxt, Right), N); Set_Location (N, Expr); return Create_Value_Net (N, Res_Type); end Synth_Compare_Nat_Uns; @@ -490,7 +490,7 @@ package body Synth.Oper is N : Net; begin N := Synth_Sresize (Ctxt, Right, Left.Typ.W, Expr); - N := Build_Compare (Ctxt, Id, Get_Net (Ctxt, Left), N); + N := Build2_Compare (Ctxt, Id, Get_Net (Ctxt, Left), N); Set_Location (N, Expr); return Create_Value_Net (N, Res_Typ); end Synth_Compare_Sgn_Int; @@ -501,7 +501,7 @@ package body Synth.Oper is N : Net; begin N := Synth_Sresize (Ctxt, Left, Right.Typ.W, Expr); - N := Build_Compare (Ctxt, Id, N, Get_Net (Ctxt, Right)); + N := Build2_Compare (Ctxt, Id, N, Get_Net (Ctxt, Right)); Set_Location (N, Expr); return Create_Value_Net (N, Res_Typ); end Synth_Compare_Int_Sgn; @@ -540,7 +540,7 @@ package body Synth.Oper is begin L1 := Synth_Uresize (Ctxt, Left, W, Expr); R1 := Synth_Uresize (Ctxt, Right, W, Expr); - N := Build_Compare (Ctxt, Id, L1, R1); + N := Build2_Compare (Ctxt, Id, L1, R1); Set_Location (N, Expr); return Create_Value_Net (N, Res_Type); end Synth_Compare_Uns_Uns; @@ -554,7 +554,7 @@ package body Synth.Oper is begin L1 := Synth_Sresize (Ctxt, Left, W, Expr); R1 := Synth_Sresize (Ctxt, Right, W, Expr); - N := Build_Compare (Ctxt, Id, L1, R1); + N := Build2_Compare (Ctxt, Id, L1, R1); Set_Location (N, Expr); return Create_Value_Net (N, Res_Typ); end Synth_Compare_Sgn_Sgn; |