Skip to content

Commit

Permalink
* Pass array and struct by reference
Browse files Browse the repository at this point in the history
       For #299
  • Loading branch information
yoogx committed Jan 7, 2022
1 parent 563ae64 commit b1295a7
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 37 deletions.
8 changes: 7 additions & 1 deletion src/backends/ocarina-backends-properties.ads
Expand Up @@ -7,7 +7,7 @@
-- S p e c --
-- --
-- Copyright (C) 2008-2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2020 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2022 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -301,6 +301,12 @@ package Ocarina.Backends.Properties is
-- representation kind has been specified by the user, returns
-- Data_None.

function By_Reference_Type (D : Node_Id) return Boolean is
(Get_Data_Representation (D) = Data_Array or else
Get_Data_Representation (D) = Data_Bounded_Array or else
Get_Data_Representation (D) = Data_Struct);
-- Return true if the data component should be passed by reference

function Get_Data_Digits (D : Node_Id) return Unsigned_Long_Long;
-- Return the value of the "data_digits" aadl property of a data
-- component. Return 0 if the property is not defined for the
Expand Down
11 changes: 3 additions & 8 deletions src/backends/po_hi_c/ocarina-backends-po_hi_c-activity.adb
Expand Up @@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 2008-2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2021 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2022 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -1227,9 +1227,7 @@ package body Ocarina.Backends.PO_HI_C.Activity is
Port_Request => True)),
Is_Pointer => True);

if Get_Data_Representation (D) /= Data_Array and then
Get_Data_Representation (D) /= Data_Struct
then
if By_Reference_Type (D) then
Append_Node_To_List (N, Call_Parameters);
else
Append_Node_To_List (Make_Variable_Address (N),
Expand All @@ -1238,13 +1236,10 @@ package body Ocarina.Backends.PO_HI_C.Activity is

N := Map_C_Data_Type_Designator (D);

if Get_Data_Representation (D) /= Data_Array and then
Get_Data_Representation (D) /= Data_Struct
then
if By_Reference_Type (D) then
N :=
Make_Parameter_Specification
(Map_C_Defining_Identifier (F), N);

else
N :=
Make_Parameter_Specification
Expand Down
89 changes: 61 additions & 28 deletions src/backends/po_hi_c/ocarina-backends-po_hi_c-marshallers.adb
Expand Up @@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 2008-2009 Telecom ParisTech, --
-- 2010-2019 ESA & ISAE, 2019-2020 OpenAADL --
-- 2010-2019 ESA & ISAE, 2019-2022 OpenAADL --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -171,13 +171,22 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
function Marshall_Type_Spec (E : Node_Id) return Node_Id is
N : Node_Id;
Parameters : constant List_Id := New_List (CTN.K_Parameter_List);
begin

Append_Node_To_List
(Make_Parameter_Specification
(Defining_Identifier => Make_Defining_Identifier (PN (P_Value)),
Parameter_Type => Map_C_Defining_Identifier (E)),
Parameters);
begin
if By_Reference_Type (E) then
Append_Node_To_List
(Make_Parameter_Specification
(Defining_Identifier => Make_Defining_Identifier (PN (P_Value)),
Parameter_Type =>
Make_Pointer_Type (Map_C_Defining_Identifier (E))),
Parameters);
else
Append_Node_To_List
(Make_Parameter_Specification
(Defining_Identifier => Make_Defining_Identifier (PN (P_Value)),
Parameter_Type => Map_C_Defining_Identifier (E)),
Parameters);
end if;

Append_Node_To_List
(Make_Parameter_Specification
Expand Down Expand Up @@ -675,7 +684,7 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
Make_Defining_Identifier (PN (P_Value)),
Defining_Identifier =>
Map_C_Defining_Identifier (C),
Is_Pointer => False),
Is_Pointer => By_Reference_Type (E)),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Message)),
Expand Down Expand Up @@ -720,7 +729,8 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_Length)),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Value))),
Make_Defining_Identifier (PN (P_Value)),
Is_Pointer => True), -- XXX
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Message)),
Expand All @@ -739,13 +749,14 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_Data)),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Value))),
Make_Defining_Identifier (PN (P_Value)),
Is_Pointer => True),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Message)),
Parameters);
Append_Node_To_List
(CTU.Get_Data_Size (E, Is_Pointer => False), Parameters);
(CTU.Get_Data_Size (E, Is_Pointer => True), Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Offset)),
Parameters);
Expand Down Expand Up @@ -1636,24 +1647,46 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is

Parameters := New_List (CTN.K_Parameter_List);

Append_Node_To_List
(Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier
(Map_C_Enumerator_Name (F)),
Aggregate_Name =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier
if By_Reference_Type (D) then
Append_Node_To_List
(Make_Variable_Address
(Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier
(Map_C_Enumerator_Name (F)),
Aggregate_Name =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier
(Map_C_Enumerator_Name (F)),
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Vars)))),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Request)),
Is_Pointer => True),
Parameters);
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Vars)))),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Request)),
Is_Pointer => True)),
Parameters);
else
Append_Node_To_List
(Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier
(Map_C_Enumerator_Name (F)),
Aggregate_Name =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier
(Map_C_Enumerator_Name (F)),
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Vars)))),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Request)),
Is_Pointer => True),
Parameters);
end if;

Append_Node_To_List
(Make_Defining_Identifier (PN (P_Message)),
Expand Down

0 comments on commit b1295a7

Please sign in to comment.