aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-07-15 18:39:57 +0200
committerTristan Gingold <tgingold@free.fr>2019-07-15 18:39:57 +0200
commit4b35c49030a2c4844539be20af3430fe709e9b8e (patch)
treebe02cfe7d415095fc6ed9d7231df05fde7ea86f0
parenta7ddd4a3ac9e48565dd3a0600358815ecbb5baab (diff)
downloadghdl-4b35c49030a2c4844539be20af3430fe709e9b8e.tar.gz
ghdl-4b35c49030a2c4844539be20af3430fe709e9b8e.tar.bz2
ghdl-4b35c49030a2c4844539be20af3430fe709e9b8e.zip
synth: handle choices by range in aggregates.
-rw-r--r--src/synth/synth-expr.adb21
-rw-r--r--src/synth/synth-stmts.adb18
-rw-r--r--src/synth/synth-stmts.ads6
3 files changed, 33 insertions, 12 deletions
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb
index 054ec43e2..d978c5676 100644
--- a/src/synth/synth-expr.adb
+++ b/src/synth/synth-expr.adb
@@ -33,7 +33,7 @@ with Vhdl.Annotations; use Vhdl.Annotations;
with Synth.Errors; use Synth.Errors;
with Synth.Types; use Synth.Types;
-with Synth.Stmts;
+with Synth.Stmts; use Synth.Stmts;
with Synth.Decls;
with Netlists.Gates; use Netlists.Gates;
@@ -265,7 +265,18 @@ package body Synth.Expr is
end if;
end;
when Iir_Kind_Choice_By_Range =>
- raise Internal_Error;
+ declare
+ Ch : constant Node := Get_Choice_Range (Assoc);
+ Rng : Value_Acc;
+ Val : Value_Acc;
+ begin
+ Rng := Synth_Range_Expression (Syn_Inst, Ch);
+ Val := Create_Value_Discrete (Rng.Rng.Left);
+ while In_Range (Rng, Val.Scal) loop
+ Set_Elem (Get_Index_Offset (Val, Bound, Ch));
+ Update_Index (Rng, Val.Scal);
+ end loop;
+ end;
when others =>
Error_Msg_Synth
(+Assoc, "unhandled association form");
@@ -1450,12 +1461,12 @@ package body Synth.Expr is
Subprg_Inst.Name := New_Internal_Name (Build_Context);
- Stmts.Synth_Subprogram_Association
+ Synth_Subprogram_Association
(Subprg_Inst, Syn_Inst, Inter_Chain, Assoc_Chain);
Decls.Synth_Declarations (Subprg_Inst, Get_Declaration_Chain (Bod));
- Stmts.Synth_Sequential_Statements
+ Synth_Sequential_Statements
(Subprg_Inst, Get_Sequential_Statement_Chain (Bod));
Res := Subprg_Inst.Return_Value;
@@ -1480,7 +1491,7 @@ package body Synth.Expr is
Areapools.Mark (M, Instance_Pool.all);
Subprg_Inst := Make_Instance (Syn_Inst, Get_Info (Imp));
- Stmts.Synth_Subprogram_Association
+ Synth_Subprogram_Association
(Subprg_Inst, Syn_Inst, Inter_Chain, Assoc_Chain);
case Def is
diff --git a/src/synth/synth-stmts.adb b/src/synth/synth-stmts.adb
index 056b4a354..8f169a492 100644
--- a/src/synth/synth-stmts.adb
+++ b/src/synth/synth-stmts.adb
@@ -20,7 +20,6 @@
with Ada.Unchecked_Deallocation;
-with Types; use Types;
with Grt.Algos;
with Areapools;
with Vhdl.Errors; use Vhdl.Errors;
@@ -899,6 +898,16 @@ package body Synth.Stmts is
end case;
end In_Range;
+ procedure Update_Index (Rng : Value_Acc; Idx : in out Int64) is
+ begin
+ case Rng.Rng.Dir is
+ when Iir_To =>
+ Idx := Idx + 1;
+ when Iir_Downto =>
+ Idx := Idx - 1;
+ end case;
+ end Update_Index;
+
procedure Synth_For_Loop_Statement
(Syn_Inst : Synth_Instance_Acc; Stmt : Node)
is
@@ -920,12 +929,7 @@ package body Synth.Stmts is
while In_Range (It_Rng, Val.Scal) loop
Synth_Sequential_Statements (Syn_Inst, Stmts);
- case It_Rng.Rng.Dir is
- when Iir_To =>
- Val.Scal := Val.Scal + 1;
- when Iir_Downto =>
- Val.Scal := Val.Scal - 1;
- end case;
+ Update_Index (It_Rng, Val.Scal);
end loop;
Destroy_Object (Syn_Inst, Iterator);
if It_Type /= Null_Node then
diff --git a/src/synth/synth-stmts.ads b/src/synth/synth-stmts.ads
index 8b3a68466..257acfdfd 100644
--- a/src/synth/synth-stmts.ads
+++ b/src/synth/synth-stmts.ads
@@ -18,6 +18,7 @@
-- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-- MA 02110-1301, USA.
+with Types; use Types;
with Vhdl.Nodes; use Vhdl.Nodes;
with Synth.Values; use Synth.Values;
with Synth.Context; use Synth.Context;
@@ -38,4 +39,9 @@ package Synth.Stmts is
-- Generate netlists for concurrent statements STMTS.
procedure Synth_Concurrent_Statements
(Syn_Inst : Synth_Instance_Acc; Stmts : Node);
+
+ -- For iterators.
+ function In_Range (Rng : Value_Acc; V : Int64) return Boolean;
+ procedure Update_Index (Rng : Value_Acc; Idx : in out Int64);
+
end Synth.Stmts;