diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-07-01 06:27:44 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-07-01 06:27:44 +0200 |
commit | d49f9d7ddb86131c64524e8c1a9dc9d923b19dc6 (patch) | |
tree | a5b254461a3f1e8fb4aaed372394b7200cdc6321 /src/synth | |
parent | c428e11471d4323632305d0b8a665262af6a9a60 (diff) | |
download | ghdl-d49f9d7ddb86131c64524e8c1a9dc9d923b19dc6.tar.gz ghdl-d49f9d7ddb86131c64524e8c1a9dc9d923b19dc6.tar.bz2 ghdl-d49f9d7ddb86131c64524e8c1a9dc9d923b19dc6.zip |
synth: handle for-loop statements.
Diffstat (limited to 'src/synth')
-rw-r--r-- | src/synth/synth-expr.adb | 3 | ||||
-rw-r--r-- | src/synth/synth-stmts.adb | 38 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb index 4d80337b5..f48d881e8 100644 --- a/src/synth/synth-expr.adb +++ b/src/synth/synth-expr.adb @@ -869,7 +869,8 @@ package body Synth.Expr is when Iir_Kind_Interface_Signal_Declaration | Iir_Kind_Variable_Declaration | Iir_Kind_Signal_Declaration - | Iir_Kind_Constant_Declaration => + | Iir_Kind_Constant_Declaration + | Iir_Kind_Iterator_Declaration => return Get_Value (Syn_Inst, Name); when Iir_Kind_Enumeration_Literal => return Create_Value_Discrete (Int64 (Get_Enum_Pos (Name))); diff --git a/src/synth/synth-stmts.adb b/src/synth/synth-stmts.adb index f2d9f48e5..f0240836a 100644 --- a/src/synth/synth-stmts.adb +++ b/src/synth/synth-stmts.adb @@ -881,6 +881,42 @@ package body Synth.Stmts is Areapools.Release (M, Instance_Pool.all); end Synth_Procedure_Call; + function In_Range (Rng : Value_Acc; V : Int64) return Boolean is + begin + case Rng.Rng.Dir is + when Iir_To => + return V >= Rng.Rng.Left and then V <= Rng.Rng.Right; + when Iir_Downto => + return V <= Rng.Rng.Left and then V >= Rng.Rng.Right; + end case; + end In_Range; + + procedure Synth_For_Loop_Statement + (Syn_Inst : Synth_Instance_Acc; Stmt : Node) + is + Iterator : constant Node := Get_Parameter_Specification (Stmt); + Stmts : constant Node := Get_Sequential_Statement_Chain (Stmt); + It_Rng : Value_Acc; + Val : Value_Acc; + begin + Synth_Declaration_Type (Syn_Inst, Iterator); + -- Initial value. + It_Rng := Get_Value (Syn_Inst, Get_Type (Iterator)); + Val := Create_Value_Discrete (It_Rng.Rng.Left); + Create_Object (Syn_Inst, Iterator, Val); + + 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; + end loop; + -- Destroy ? + end Synth_For_Loop_Statement; + procedure Synth_Sequential_Statements (Syn_Inst : Synth_Instance_Acc; Stmts : Node) is @@ -897,6 +933,8 @@ package body Synth.Stmts is Synth_Variable_Assignment (Syn_Inst, Stmt); when Iir_Kind_Case_Statement => Synth_Case_Statement (Syn_Inst, Stmt); + when Iir_Kind_For_Loop_Statement => + Synth_For_Loop_Statement (Syn_Inst, Stmt); when Iir_Kind_Null_Statement => -- Easy null; |