Skip to content

Commit 8b87755

Browse files
committed
Handle Address representation clauses
Use more General Exp_Value rather than IntVal to determine value of "Size" and "Component_Size" IntVal expects an integer literal whereas Exp_Value will accept a static expression and return its folded value.
1 parent de356ef commit 8b87755

File tree

1 file changed

+57
-37
lines changed

1 file changed

+57
-37
lines changed

gnat2goto/driver/tree_walk.adb

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
with Namet; use Namet;
22
with Nlists; use Nlists;
33
with Sem;
4+
with Sem_Eval; use Sem_Eval;
45
with Sem_Util; use Sem_Util;
56
with Sem_Aux; use Sem_Aux;
67
with Snames; use Snames;
@@ -4644,51 +4645,70 @@ package body Tree_Walk is
46444645
procedure Handle_Representation_Clause (N : Node_Id);
46454646
procedure Handle_Representation_Clause (N : Node_Id) is
46464647
Attr_Id : constant String := Get_Name_String (Chars (N));
4647-
Target_Name : constant Irep := Do_Identifier (Name (N));
4648-
Entity_Esize : constant Uint := Esize (Entity (N));
4649-
Target_Type_Irep : constant Irep :=
4650-
Follow_Symbol_Type (Get_Type (Target_Name), Global_Symbol_Table);
4651-
Expression_Value : constant Uint := Intval (Expression (N));
46524648
begin
4653-
pragma Assert (Kind (Target_Type_Irep) in Class_Type);
4654-
if Attr_Id = "size" then
4655-
4656-
-- Just check that the front-end already applied this size
4657-
-- clause, i .e. that the size of type-irep we already had
4658-
-- equals the entity type this clause is applied to (and the
4659-
-- size specified in this clause).
4660-
pragma Assert (Entity_Esize =
4661-
UI_From_Int (Int (Get_Width (Target_Type_Irep)))
4662-
and Entity_Esize = Expression_Value);
4649+
-- First check if it is an address clause which gnat2goto does not
4650+
-- currently handle
4651+
if Attr_Id = "address" then
4652+
Report_Unhandled_Node_Empty
4653+
(N, "Process_Declaration",
4654+
"Address representation clauses are not currently supported");
46634655
return;
4664-
elsif Attr_Id = "component_size" then
4665-
if not Is_Array_Type (Entity (N)) then
4666-
Report_Unhandled_Node_Empty (N, "Process_Declaration",
4667-
"Component size only supported for array types");
4668-
return;
4669-
end if;
4656+
elsif Attr_Id = "size" or else Attr_Id = "component_size" then
46704657
declare
4671-
Array_Data : constant Irep :=
4672-
Get_Data_Component_From_Type (Target_Type_Irep);
4673-
Target_Subtype : constant Irep :=
4674-
Follow_Symbol_Type (Get_Subtype (Get_Type (Array_Data)),
4675-
Global_Symbol_Table);
4676-
Target_Subtype_Width : constant Uint :=
4677-
UI_From_Int (Int (Get_Width (Target_Subtype)));
4658+
Target_Name : constant Irep := Do_Identifier (Name (N));
4659+
Entity_Esize : constant Uint := Esize (Entity (N));
4660+
Target_Type_Irep : constant Irep :=
4661+
Follow_Symbol_Type
4662+
(Get_Type (Target_Name), Global_Symbol_Table);
4663+
Expression_Value : constant Uint := Expr_Value (Expression (N));
46784664
begin
4679-
if Component_Size (Entity (N)) /= Expression_Value or
4680-
Target_Subtype_Width /= Expression_Value
4681-
then
4682-
Report_Unhandled_Node_Empty (N, "Process_Declaration",
4683-
"Having component sizes be different from the size of " &
4684-
"their underlying type is currently not supported");
4665+
pragma Assert (Kind (Target_Type_Irep) in Class_Type);
4666+
if Attr_Id = "size" then
4667+
4668+
-- Just check that the front-end already applied this size
4669+
-- clause, i .e. that the size of type-irep we already had
4670+
-- equals the entity type this clause is applied to (and the
4671+
-- size specified in this clause).
4672+
pragma Assert
4673+
(Entity_Esize =
4674+
UI_From_Int (Int (Get_Width (Target_Type_Irep)))
4675+
and Entity_Esize = Expression_Value);
4676+
return;
4677+
elsif Attr_Id = "component_size" then
4678+
if not Is_Array_Type (Entity (N)) then
4679+
Report_Unhandled_Node_Empty
4680+
(N, "Process_Declaration",
4681+
"Component size only supported for array types");
4682+
return;
4683+
end if;
4684+
declare
4685+
Array_Data : constant Irep :=
4686+
Get_Data_Component_From_Type (Target_Type_Irep);
4687+
Target_Subtype : constant Irep :=
4688+
Follow_Symbol_Type (Get_Subtype (Get_Type (Array_Data)),
4689+
Global_Symbol_Table);
4690+
Target_Subtype_Width : constant Uint :=
4691+
UI_From_Int (Int (Get_Width (Target_Subtype)));
4692+
begin
4693+
if Component_Size (Entity (N)) /= Expression_Value or
4694+
Target_Subtype_Width /= Expression_Value
4695+
then
4696+
Report_Unhandled_Node_Empty
4697+
(N, "Process_Declaration",
4698+
"Having component sizes be different from the "
4699+
& "size of their underlying type "
4700+
& "is currently not supported");
4701+
end if;
4702+
end;
4703+
return;
46854704
end if;
46864705
end;
4687-
return;
46884706
end if;
46894707

4690-
Report_Unhandled_Node_Empty (N, "Process_Declaration",
4691-
"Representation clause unsupported: " & Attr_Id);
4708+
Report_Unhandled_Node_Empty
4709+
(N, "Process_Declaration",
4710+
"Representation clause unsupported: " & Attr_Id);
4711+
46924712
end Handle_Representation_Clause;
46934713

46944714
begin

0 commit comments

Comments
 (0)