diff options
-rw-r--r-- | src/synth/synth-expr.adb | 22 | ||||
-rw-r--r-- | src/synth/synth-objtypes.adb | 11 | ||||
-rw-r--r-- | src/synth/synth-objtypes.ads | 8 |
3 files changed, 35 insertions, 6 deletions
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb index 4d8c1aec2..742274ec4 100644 --- a/src/synth/synth-expr.adb +++ b/src/synth/synth-expr.adb @@ -2170,12 +2170,22 @@ package body Synth.Expr is end if; end; when Iir_Kind_Simple_Name - | Iir_Kind_Selected_Name - | Iir_Kind_Interface_Signal_Declaration -- For PSL. - | Iir_Kind_Signal_Declaration -- For PSL. - | Iir_Kind_Implicit_Dereference - | Iir_Kind_Dereference => - return Synth_Name (Syn_Inst, Expr); + | Iir_Kind_Selected_Name + | Iir_Kind_Interface_Signal_Declaration -- For PSL. + | Iir_Kind_Signal_Declaration -- For PSL. + | Iir_Kind_Implicit_Dereference + | Iir_Kind_Dereference => + declare + Res : Valtyp; + begin + Res := Synth_Name (Syn_Inst, Expr); + if Res.Typ.W = 0 and then Res.Val.Kind /= Value_Memory then + -- This is a null object. As nothing can be done about it, + -- returns 0. + return Create_Value_Memtyp (Create_Memory_Zero (Res.Typ)); + end if; + return Res; + end; when Iir_Kind_Reference_Name => -- Only used for anonymous signals in internal association. return Synth_Expression_With_Type diff --git a/src/synth/synth-objtypes.adb b/src/synth/synth-objtypes.adb index 4b9e6ea54..4c615ca7e 100644 --- a/src/synth/synth-objtypes.adb +++ b/src/synth/synth-objtypes.adb @@ -770,6 +770,17 @@ package body Synth.Objtypes is return (Vtype, Alloc_Memory (Vtype)); end Create_Memory; + function Create_Memory_Zero (Vtype : Type_Acc) return Memtyp + is + Mem : Memory_Ptr; + begin + Mem := Alloc_Memory (Vtype); + for I in 1 .. Vtype.Sz loop + Write_U8 (Mem + (I - 1), 0); + end loop; + return (Vtype, Mem); + end Create_Memory_Zero; + function Create_Memory_U8 (Val : Ghdl_U8; Vtype : Type_Acc) return Memtyp is diff --git a/src/synth/synth-objtypes.ads b/src/synth/synth-objtypes.ads index dfc0f732b..ff456d35f 100644 --- a/src/synth/synth-objtypes.ads +++ b/src/synth/synth-objtypes.ads @@ -125,6 +125,10 @@ package Synth.Objtypes is Sz : Size_Type; -- Number of bits (when in a net) for this type. + -- Can be zero only if the type has only 0 or 1 value (like a discrete + -- type with 1 element, a null vector, or a null array). + -- For non synthesizable types (like files or protected type), just + -- use 32. W : Width; case Kind is @@ -292,6 +296,10 @@ package Synth.Objtypes is function Alloc_Memory (Vtype : Type_Acc) return Memory_Ptr; function Create_Memory (Vtype : Type_Acc) return Memtyp; + -- Like Create_Memory but initialize to 0. To be used only for types + -- of width 0. + function Create_Memory_Zero (Vtype : Type_Acc) return Memtyp; + function Is_Equal (L, R : Memtyp) return Boolean; procedure Copy_Memory (Dest : Memory_Ptr; Src : Memory_Ptr; Sz : Size_Type); |