Skip to content

Commit 117bb16

Browse files
committed
Implement the introduction of modular integer subtypes
By following the origin mod type and extracting the bounds.
1 parent deb4871 commit 117bb16

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

gnat2goto/driver/gnat2goto_itypes.adb

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ with GOTO_Utils; use GOTO_Utils;
66
with Range_Check; use Range_Check;
77
with Symbol_Table_Info; use Symbol_Table_Info;
88
with Tree_Walk; use Tree_Walk;
9+
with Follow; use Follow;
910

1011
package body Gnat2goto_Itypes is
1112

@@ -89,7 +90,8 @@ package body Gnat2goto_Itypes is
8990
when E_Signed_Integer_Type => Do_Itype_Integer_Type (N),
9091
when E_Floating_Point_Type => Create_Dummy_Irep,
9192
when E_Anonymous_Access_Type => Make_Pointer_Type
92-
(Base => Do_Type_Reference (Designated_Type (Etype (N)))),
93+
(Base => Do_Type_Reference (Designated_Type (Etype (N)))),
94+
when E_Modular_Integer_Subtype => Do_Modular_Integer_Subtype (N),
9395
when others => Report_Unhandled_Node_Irep (N, "Do_Itype_Definition",
9496
"Unknown Ekind"));
9597
end Do_Itype_Definition;
@@ -171,4 +173,58 @@ package body Gnat2goto_Itypes is
171173
return Do_Type_Reference (Etype (N));
172174
end Do_Itype_Record_Subtype;
173175

176+
function Do_Modular_Integer_Subtype (N : Entity_Id) return Irep is
177+
Modular_Type : constant Irep := Do_Type_Reference (Etype (N));
178+
Followed_Mod_Type : constant Irep :=
179+
Follow_Symbol_Type (Modular_Type, Global_Symbol_Table);
180+
181+
S_Range : constant Node_Id := Scalar_Range (N);
182+
Lower_Bound : constant Node_Id := Low_Bound (S_Range);
183+
Upper_Bound : constant Node_Id := High_Bound (S_Range);
184+
185+
Lower_Bound_Value : Integer;
186+
Upper_Bound_Value : Integer;
187+
begin
188+
pragma Assert (Kind (Followed_Mod_Type) in I_Unsignedbv_Type
189+
| I_Ada_Mod_Type);
190+
191+
case Nkind (Lower_Bound) is
192+
when N_Integer_Literal => Lower_Bound_Value :=
193+
Store_Nat_Bound (Bound_Type_Nat (Intval (Lower_Bound)));
194+
when N_Identifier => Lower_Bound_Value :=
195+
Store_Symbol_Bound (Bound_Type_Symbol (Lower_Bound));
196+
when others =>
197+
Report_Unhandled_Node_Empty (Lower_Bound,
198+
"Do_Base_Range_Constraint",
199+
"unsupported lower range kind");
200+
end case;
201+
202+
case Nkind (Upper_Bound) is
203+
when N_Integer_Literal => Upper_Bound_Value :=
204+
Store_Nat_Bound (Bound_Type_Nat (Intval (Upper_Bound)));
205+
when N_Identifier => Upper_Bound_Value :=
206+
Store_Symbol_Bound (Bound_Type_Symbol (Upper_Bound));
207+
when others =>
208+
Report_Unhandled_Node_Empty (Upper_Bound,
209+
"Do_Base_Range_Constraint",
210+
"unsupported upper range kind");
211+
end case;
212+
213+
if Kind (Followed_Mod_Type) = I_Ada_Mod_Type then
214+
return Make_Bounded_Mod_Type (I_Subtype => Make_Nil_Type,
215+
Width =>
216+
Get_Width (Followed_Mod_Type),
217+
Lower_Bound => Lower_Bound_Value,
218+
Ada_Mod_Max =>
219+
Get_Ada_Mod_Max (Followed_Mod_Type),
220+
Upper_Bound => Upper_Bound_Value);
221+
else
222+
return Make_Bounded_Unsignedbv_Type (I_Subtype => Make_Nil_Type,
223+
Width =>
224+
Get_Width (Followed_Mod_Type),
225+
Lower_Bound => Lower_Bound_Value,
226+
Upper_Bound => Upper_Bound_Value);
227+
end if;
228+
end Do_Modular_Integer_Subtype;
229+
174230
end Gnat2goto_Itypes;

gnat2goto/driver/gnat2goto_itypes.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ private
3030
function Do_Itype_Record_Subtype (N : Entity_Id) return Irep
3131
with Pre => Is_Itype (N) and then Ekind (N) = E_Record_Subtype;
3232

33+
function Do_Modular_Integer_Subtype (N : Entity_Id) return Irep
34+
with Pre => Is_Itype (N) and then Ekind (N) = E_Modular_Integer_Subtype;
35+
3336
end Gnat2goto_Itypes;

0 commit comments

Comments
 (0)