diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-01-06 09:33:14 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-01-06 09:33:14 +0100 |
commit | 612a472d6c9f01d7b361f7baec15fb52f24654ef (patch) | |
tree | 8dc3c892db52e3d0a86d02128fdd91aad8194945 /src/vhdl | |
parent | 6daac6c7f86fa911bf230fe69419c540d9609c71 (diff) | |
download | ghdl-612a472d6c9f01d7b361f7baec15fb52f24654ef.tar.gz ghdl-612a472d6c9f01d7b361f7baec15fb52f24654ef.tar.bz2 ghdl-612a472d6c9f01d7b361f7baec15fb52f24654ef.zip |
translate: refactoring of slice diff for enum types.
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/translate/trans-chap6.adb | 37 | ||||
-rw-r--r-- | src/vhdl/translate/trans.ads | 3 |
2 files changed, 31 insertions, 9 deletions
diff --git a/src/vhdl/translate/trans-chap6.adb b/src/vhdl/translate/trans-chap6.adb index 093e0de00..6e449725f 100644 --- a/src/vhdl/translate/trans-chap6.adb +++ b/src/vhdl/translate/trans-chap6.adb @@ -532,6 +532,7 @@ package body Trans.Chap6 is Slice_Range : Mnode; Prefix_Range : Mnode; + Diff_Type : O_Tnode; Diff : O_Dnode; Unsigned_Diff : O_Dnode; If_Blk, If_Blk1 : O_If_Block; @@ -646,7 +647,20 @@ package body Trans.Chap6 is Ghdl_Bool_Type)); New_Assign_Stmt (New_Obj (Unsigned_Diff), New_Lit (Ghdl_Index_0)); New_Else_Stmt (If_Blk); - Diff := Create_Temp (Index_Info.Ortho_Type (Mode_Value)); + + -- Use a signed intermediate type to do the substraction. This is + -- required for enum types. + case Type_Mode_Discrete (Index_Info.Type_Mode) is + when Type_Mode_B1 + | Type_Mode_E8 + | Type_Mode_E32 + | Type_Mode_I32 => + Diff_Type := Ghdl_I32_Type; + when Type_Mode_I64 => + Diff_Type := Ghdl_I64_Type; + end case; + + Diff := Create_Temp (Diff_Type); -- Compute the offset in the prefix. if not Static_Range then @@ -660,9 +674,12 @@ package body Trans.Chap6 is -- Diff = slice - bounds. New_Assign_Stmt (New_Obj (Diff), - New_Dyadic_Op (ON_Sub_Ov, - M2E (Chap3.Range_To_Left (Slice_Range)), - M2E (Chap3.Range_To_Left (Prefix_Range)))); + New_Dyadic_Op + (ON_Sub_Ov, + New_Convert_Ov (M2E (Chap3.Range_To_Left (Slice_Range)), + Diff_Type), + New_Convert_Ov (M2E (Chap3.Range_To_Left (Prefix_Range)), + Diff_Type))); end if; if not Static_Range then New_Else_Stmt (If_Blk1); @@ -672,9 +689,12 @@ package body Trans.Chap6 is -- Diff = bounds - slice. New_Assign_Stmt (New_Obj (Diff), - New_Dyadic_Op (ON_Sub_Ov, - M2E (Chap3.Range_To_Left (Prefix_Range)), - M2E (Chap3.Range_To_Left (Slice_Range)))); + New_Dyadic_Op + (ON_Sub_Ov, + New_Convert_Ov (M2E (Chap3.Range_To_Left (Prefix_Range)), + Diff_Type), + New_Convert_Ov (M2E (Chap3.Range_To_Left (Slice_Range)), + Diff_Type))); end if; if not Static_Range then Finish_If_Stmt (If_Blk1); @@ -694,8 +714,7 @@ package body Trans.Chap6 is Err_1 := New_Compare_Op (ON_Lt, New_Obj_Value (Diff), - New_Lit (New_Signed_Literal (Index_Info.Ortho_Type (Mode_Value), - 0)), + New_Lit (New_Signed_Literal (Diff_Type, 0)), Ghdl_Bool_Type); -- Bounds error if right of slice is after right of prefix. Err_2 := New_Compare_Op diff --git a/src/vhdl/translate/trans.ads b/src/vhdl/translate/trans.ads index a7968e20e..bceaf986d 100644 --- a/src/vhdl/translate/trans.ads +++ b/src/vhdl/translate/trans.ads @@ -1063,6 +1063,9 @@ package Trans is subtype Type_Mode_Valid is Type_Mode_Type range Type_Mode_B1 .. Type_Mode_Type'Last; + subtype Type_Mode_Discrete is Type_Mode_Type range + Type_Mode_B1 .. Type_Mode_I64; + subtype Type_Mode_Scalar is Type_Mode_Type range Type_Mode_B1 .. Type_Mode_F64; |