diff options
author | Tristan Gingold | 2015-05-15 20:44:05 +0200 |
---|---|---|
committer | Tristan Gingold | 2015-05-15 20:44:05 +0200 |
commit | 5835691d9afab34a0ce20c94f62243809db96f27 (patch) | |
tree | f4ea3f0fab2f5a1ec18aef56d3143ea5fc0af556 /src | |
parent | 4d370179c85343594e10999b66b3d014e2c552be (diff) | |
download | ghdl-5835691d9afab34a0ce20c94f62243809db96f27.tar.gz ghdl-5835691d9afab34a0ce20c94f62243809db96f27.tar.bz2 ghdl-5835691d9afab34a0ce20c94f62243809db96f27.zip |
Check enumeration overflow for succ/pred attributes.
Translate 'Leftof and 'Rightof.
Fix ticket 65.
Diffstat (limited to 'src')
-rw-r--r-- | src/vhdl/evaluation.adb | 10 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap14.adb | 36 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap7.adb | 4 |
3 files changed, 34 insertions, 16 deletions
diff --git a/src/vhdl/evaluation.adb b/src/vhdl/evaluation.adb index 3ce2b2d..ad464f7 100644 --- a/src/vhdl/evaluation.adb +++ b/src/vhdl/evaluation.adb @@ -1803,7 +1803,12 @@ package body Evaluation is return Build_Integer (Get_Value (Expr) + N, Origin); when Iir_Kind_Enumeration_Literal => P := Iir_Int64 (Get_Enum_Pos (Expr)) + N; - if P < 0 then + if P < 0 + or else (P >= Iir_Int64 + (Get_Nbr_Elements + (Get_Enumeration_Literal_List + (Get_Base_Type (Get_Type (Expr)))))) + then Warning_Msg_Sem ("static constant violates bounds", Expr); return Build_Overflow (Origin); else @@ -2240,10 +2245,9 @@ package body Evaluation is declare Rng : Iir; N : Iir_Int64; - Prefix_Type : Iir; + Prefix_Type : constant Iir := Get_Type (Get_Prefix (Expr)); Res : Iir; begin - Prefix_Type := Get_Type (Get_Prefix (Expr)); Rng := Eval_Static_Range (Prefix_Type); case Get_Direction (Rng) is when Iir_To => diff --git a/src/vhdl/translate/trans-chap14.adb b/src/vhdl/translate/trans-chap14.adb index 430edcc..b7fc93a 100644 --- a/src/vhdl/translate/trans-chap14.adb +++ b/src/vhdl/translate/trans-chap14.adb @@ -18,6 +18,7 @@ with Evaluation; use Evaluation; with Std_Package; use Std_Package; +with Errorout; use Errorout; with Iirs_Utils; use Iirs_Utils; with Trans_Decls; use Trans_Decls; with Trans.Chap3; @@ -287,22 +288,32 @@ package body Trans.Chap14 is function Translate_Succ_Pred_Attribute (Attr : Iir) return O_Enode is - Expr_Type : Iir; - Tinfo : Type_Info_Acc; + Expr_Type : constant Iir := Get_Type (Attr); + Tinfo : constant Type_Info_Acc := Get_Info (Expr_Type); Ttype : O_Tnode; Expr : O_Enode; - List : Iir_List; - Limit : Iir; - Is_Succ : Boolean; + Is_Inc : Boolean; Op : ON_Op_Kind; begin -- FIXME: should check bounds. - Expr_Type := Get_Type (Attr); - Tinfo := Get_Info (Expr_Type); Expr := Chap7.Translate_Expression (Get_Parameter (Attr), Expr_Type); Ttype := Tinfo.Ortho_Type (Mode_Value); - Is_Succ := Get_Kind (Attr) = Iir_Kind_Succ_Attribute; - if Is_Succ then + case Get_Kind (Attr) is + when Iir_Kind_Succ_Attribute => + Is_Inc := True; + when Iir_Kind_Pred_Attribute => + Is_Inc := False; + when Iir_Kind_Leftof_Attribute => + Is_Inc := + Get_Direction (Get_Range_Constraint (Expr_Type)) = Iir_Downto; + when Iir_Kind_Rightof_Attribute => + Is_Inc := + Get_Direction (Get_Range_Constraint (Expr_Type)) = Iir_To; + when others => + Error_Kind ("translate_succ_pred_attribute", Attr); + end case; + + if Is_Inc then Op := ON_Add_Ov; else Op := ON_Sub_Ov; @@ -313,12 +324,13 @@ package body Trans.Chap14 is | Type_Mode_E32 => -- Should check it is not the last. declare + List : constant Iir_List := Get_Enumeration_Literal_List + (Get_Base_Type (Expr_Type)); + Limit : Iir; L : O_Dnode; begin - List := Get_Enumeration_Literal_List (Get_Base_Type - (Expr_Type)); L := Create_Temp_Init (Ttype, Expr); - if Is_Succ then + if Is_Inc then Limit := Get_Last_Element (List); else Limit := Get_First_Element (List); diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb index f65d020..25f044a 100644 --- a/src/vhdl/translate/trans-chap7.adb +++ b/src/vhdl/translate/trans-chap7.adb @@ -4005,7 +4005,9 @@ package body Trans.Chap7 is return Chap14.Translate_Pos_Attribute (Expr, Res_Type); when Iir_Kind_Succ_Attribute - | Iir_Kind_Pred_Attribute => + | Iir_Kind_Pred_Attribute + | Iir_Kind_Leftof_Attribute + | Iir_Kind_Rightof_Attribute => return Chap14.Translate_Succ_Pred_Attribute (Expr); when Iir_Kind_Image_Attribute => |