diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-04-09 21:24:04 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-04-09 21:24:36 +0200 |
commit | 32a60efc00452a5eb037f5d1f5dabb687c170c99 (patch) | |
tree | f38b3337d35da9479255e5a7e97934eb1ff2731a /src/synth/synth-context.adb | |
parent | db918fedf1af6da741bb6dd280719cb0f139b583 (diff) | |
download | ghdl-32a60efc00452a5eb037f5d1f5dabb687c170c99.tar.gz ghdl-32a60efc00452a5eb037f5d1f5dabb687c170c99.tar.bz2 ghdl-32a60efc00452a5eb037f5d1f5dabb687c170c99.zip |
synth: refactoring to store static values in wires.
Diffstat (limited to 'src/synth/synth-context.adb')
-rw-r--r-- | src/synth/synth-context.adb | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/src/synth/synth-context.adb b/src/synth/synth-context.adb index 576be4987..b02dcbc2e 100644 --- a/src/synth/synth-context.adb +++ b/src/synth/synth-context.adb @@ -20,7 +20,6 @@ with Ada.Unchecked_Deallocation; -with Types; use Types; with Name_Table; use Name_Table; with Vhdl.Errors; use Vhdl.Errors; @@ -435,17 +434,24 @@ package body Synth.Context is end loop; end Is_Full; - procedure Value2net - (Val : Valtyp; W : Width; Vec : in out Logvec_Array; Res : out Net) + procedure Value2net (Val : Memtyp; + Off : Uns32; + W : Width; + Vec : in out Logvec_Array; + Res : out Net) is - Off : Uns32; + Vec_Off : Uns32; Has_Zx : Boolean; Inst : Instance; Is_0, Is_X : Boolean; begin + -- First convert to logvec. Has_Zx := False; - Off := 0; - Value2logvec (Val, Vec, Off, Has_Zx); + Vec_Off := 0; + Value2logvec (Val, Off, W, Vec, Vec_Off, Has_Zx); + pragma Assert (Vec_Off = W); + + -- Then convert logvec to net. if W = 0 then -- For null range (like the null string literal "") Res := Build_Const_UB32 (Build_Context, 0, 0); @@ -481,6 +487,36 @@ package body Synth.Context is end if; end Value2net; + function Get_Partial_Memtyp_Net (Val : Memtyp; Off : Uns32; Wd : Width) + return Net + is + Nd : constant Digit_Index := Digit_Index ((Wd + 31) / 32); + Res : Net; + begin + if Nd > 64 then + declare + Vecp : Logvec_Array_Acc; + begin + Vecp := new Logvec_Array'(0 .. Nd - 1 => (0, 0)); + Value2net (Val, Off, Wd, Vecp.all, Res); + Free_Logvec_Array (Vecp); + return Res; + end; + else + declare + Vec : Logvec_Array (0 .. Nd - 1) := (others => (0, 0)); + begin + Value2net (Val, Off, Wd, Vec, Res); + return Res; + end; + end if; + end Get_Partial_Memtyp_Net; + + function Get_Memtyp_Net (Val : Memtyp) return Net is + begin + return Get_Partial_Memtyp_Net (Val, 0, Val.Typ.W); + end Get_Memtyp_Net; + function Get_Net (Val : Valtyp) return Net is begin case Val.Val.Kind is @@ -509,29 +545,7 @@ package body Synth.Context is end if; return Val.Val.C_Net; when Value_Memory => - declare - W : constant Width := Val.Typ.W; - Nd : constant Digit_Index := Digit_Index ((W + 31) / 32); - Res : Net; - begin - if Nd > 64 then - declare - Vecp : Logvec_Array_Acc; - begin - Vecp := new Logvec_Array'(0 .. Nd - 1 => (0, 0)); - Value2net (Val, W, Vecp.all, Res); - Free_Logvec_Array (Vecp); - return Res; - end; - else - declare - Vec : Logvec_Array (0 .. Nd - 1) := (others => (0, 0)); - begin - Value2net (Val, W, Vec, Res); - return Res; - end; - end if; - end; + return Get_Memtyp_Net (Get_Memtyp (Val)); when others => raise Internal_Error; end case; |