aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-07-04 18:21:47 +0200
committerTristan Gingold <tgingold@free.fr>2019-07-04 18:21:47 +0200
commitbc88630cb8984977873f6acb7f03a1dd73e92305 (patch)
treee4ce0d27f2c0e5919a5d77d6e6d2f240821ae34b
parentea5dd7ef71213326abe9c30a50de9b9b431c7d6f (diff)
downloadghdl-bc88630cb8984977873f6acb7f03a1dd73e92305.tar.gz
ghdl-bc88630cb8984977873f6acb7f03a1dd73e92305.tar.bz2
ghdl-bc88630cb8984977873f6acb7f03a1dd73e92305.zip
synth: add concat_array function.
-rw-r--r--src/synth/synth-expr.adb80
-rw-r--r--src/synth/synth-expr.ads8
2 files changed, 52 insertions, 36 deletions
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb
index ad05921bb..bd48683a7 100644
--- a/src/synth/synth-expr.adb
+++ b/src/synth/synth-expr.adb
@@ -19,7 +19,6 @@
-- MA 02110-1301, USA.
with Ada.Unchecked_Conversion;
-with Ada.Unchecked_Deallocation;
with Types_Utils; use Types_Utils;
with Std_Names;
with Str_Table;
@@ -277,21 +276,57 @@ package body Synth.Expr is
end loop;
end Fill_Array_Aggregate;
- type Net_Array is array (Iir_Index32 range <>) of Net;
- type Net_Array_Acc is access Net_Array;
- procedure Free_Net_Array is new Ada.Unchecked_Deallocation
- (Net_Array, Net_Array_Acc);
+ procedure Concat_Array (Arr : in out Net_Array)
+ is
+ Last : Int32;
+ Idx, New_Idx : Int32;
+ begin
+ Last := Arr'Last;
+ while Last > Arr'First loop
+ Idx := Arr'First;
+ New_Idx := Arr'First - 1;
+ while Idx <= Last loop
+ -- Gather at most 4 nets.
+ New_Idx := New_Idx + 1;
+
+ if Idx = Last then
+ Arr (New_Idx) := Arr (Idx);
+ Idx := Idx + 1;
+ elsif Idx + 1 = Last then
+ Arr (New_Idx) := Build_Concat2
+ (Build_Context, Arr (Idx), Arr (Idx + 1));
+ Idx := Idx + 2;
+ elsif Idx + 2 = Last then
+ Arr (New_Idx) := Build_Concat3
+ (Build_Context, Arr (Idx), Arr (Idx + 1), Arr (Idx + 2));
+ Idx := Idx + 3;
+ else
+ Arr (New_Idx) := Build_Concat4
+ (Build_Context,
+ Arr (Idx), Arr (Idx + 1), Arr (Idx + 2), Arr (Idx + 3));
+ Idx := Idx + 4;
+ end if;
+ end loop;
+ Last := New_Idx;
+ end loop;
+ end Concat_Array;
+
+ function Concat_Array (Arr : Net_Array_Acc) return Net is
+ begin
+ Concat_Array (Arr.all);
+ return Arr (Arr'First);
+ end Concat_Array;
-- Convert the one-dimension VAL to a net by concatenating.
function Vectorize_Array (Val : Value_Acc; Etype : Node) return Value_Acc
is
Arr : Net_Array_Acc;
- Len : Iir_Index32;
- Idx, New_Idx : Iir_Index32;
+ Len : Int32;
+ Idx : Iir_Index32;
Res : Value_Acc;
begin
-- Dynamically allocate ARR to handle large arrays.
- Arr := new Net_Array (1 .. Val.Arr.Len);
+ Arr := new Net_Array (1 .. Int32 (Val.Arr.Len));
-- Gather consecutive constant values.
Idx := 1;
@@ -334,34 +369,7 @@ package body Synth.Expr is
end;
end loop;
- while Len > 1 loop
- Idx := 1;
- New_Idx := 0;
- while Idx <= Len loop
- -- Gather at most 4 nets.
- New_Idx := New_Idx + 1;
-
- if Idx = Len then
- Arr (New_Idx) := Arr (Idx);
- Idx := Idx + 1;
- elsif Idx + 1 = Len then
- Arr (New_Idx) := Build_Concat2
- (Build_Context, Arr (Idx), Arr (Idx + 1));
- Idx := Idx + 2;
- elsif Idx + 2 = Len then
- Arr (New_Idx) := Build_Concat3
- (Build_Context, Arr (Idx), Arr (Idx + 1), Arr (Idx + 2));
- Idx := Idx + 3;
- else
- Arr (New_Idx) := Build_Concat4
- (Build_Context,
- Arr (Idx), Arr (Idx + 1), Arr (Idx + 2), Arr (Idx + 3));
- Idx := Idx + 4;
- end if;
- end loop;
- Len := New_Idx;
- end loop;
-
+ Concat_Array (Arr (1 .. Len));
Res := Create_Value_Net (Arr (1), Val.Bounds.D (1));
Free_Net_Array (Arr);
diff --git a/src/synth/synth-expr.ads b/src/synth/synth-expr.ads
index f41eb626d..1599eb22e 100644
--- a/src/synth/synth-expr.ads
+++ b/src/synth/synth-expr.ads
@@ -18,6 +18,7 @@
-- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-- MA 02110-1301, USA.
+with Ada.Unchecked_Deallocation;
with Types; use Types;
with Netlists; use Netlists;
with Synth.Values; use Synth.Values;
@@ -35,6 +36,13 @@ package Synth.Expr is
function Bit_Extract (Val : Value_Acc; Off : Uns32) return Value_Acc;
+ type Net_Array is array (Int32 range <>) of Net;
+ type Net_Array_Acc is access Net_Array;
+ procedure Free_Net_Array is new Ada.Unchecked_Deallocation
+ (Net_Array, Net_Array_Acc);
+
+ function Concat_Array (Arr : Net_Array_Acc) return Net;
+
function Synth_Expression_With_Type
(Syn_Inst : Synth_Instance_Acc; Expr : Node; Expr_Type : Node)
return Value_Acc;