Skip to content

Commit

Permalink
* Move initialization of gqueues to a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
yoogx committed Oct 7, 2020
1 parent 6d2968f commit 8093955
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 83 deletions.
201 changes: 119 additions & 82 deletions src/backends/po_hi_c/ocarina-backends-po_hi_c-activity.adb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,96 @@ package body Ocarina.Backends.PO_HI_C.Activity is

Current_Device : Node_Id := No_Node;

function Task_Initialize (E : Node_Id) return Node_Id;
-- Return the snipet of code to initialize thread E

function Task_Initialize (E : Node_Id) return Node_Id is
S : constant Node_Id := Parent_Subcomponent (E);
Call_Parameters : List_Id;
N : Node_Id;
begin
if Has_Ports (E) then
-- Make the __po_hi_gqueue_init call

Call_Parameters := New_List (CTN.K_Parameter_List);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Enumerator_Name (S, Current_Device)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Define_Name (S, Nb_Ports => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Queue => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Fifo_Size => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_First => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Offsets => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Woffsets => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_N_Dest => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Destinations => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Used_Size => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_History => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Recent => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Empties => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Total_Fifo => True)),
Call_Parameters);

N := Make_Call_Profile (RE (RE_Gqueue_Init), Call_Parameters);
return N;
end if;

return No_Node;
end Task_Initialize;

-------------------
-- Task_Job_Body --
-------------------
Expand Down Expand Up @@ -1445,85 +1535,6 @@ package body Ocarina.Backends.PO_HI_C.Activity is
end;
end if;

if Has_Ports (E) then
-- Make the __po_hi_gqueue_init call

Call_Parameters := New_List (CTN.K_Parameter_List);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Enumerator_Name (S, Current_Device)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Define_Name (S, Nb_Ports => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Queue => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Fifo_Size => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_First => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Offsets => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Woffsets => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_N_Dest => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Destinations => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Used_Size => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_History => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Recent => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Empties => True)),
Call_Parameters);

Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Variable_Name (S, Port_Total_Fifo => True)),
Call_Parameters);

N := Make_Call_Profile (RE (RE_Gqueue_Init), Call_Parameters);
Append_Node_To_List (N, Statements);
end if;

Make_Activate_Entrypoint;

-- If the thread is sporadic or aperiodic, we generate the
Expand Down Expand Up @@ -1928,21 +1939,37 @@ package body Ocarina.Backends.PO_HI_C.Activity is
Statements : constant List_Id := New_List (CTN.K_Statement_List);
The_System : constant Node_Id :=
Parent_Component (Parent_Subcomponent (E));

Init_Spec : Node_Id;
Init_Declarations : constant List_Id
:= New_List (CTN.K_Declaration_List);
Init_Statements : constant List_Id
:= New_List (CTN.K_Statement_List);

begin
Push_Entity (P);
Push_Entity (U);
CTU.Set_Activity_Source (U);

Main_Deliver_Alternatives := New_List (CTN.K_Alternatives_List);

-- Define the __po_hi_main_initialize() function, in charge
-- of initializing all threads gqueues and other structures.

Init_Spec :=
Make_Function_Specification
(Defining_Identifier => RE (RE_Main_Initialize),
Parameters => New_List (CTN.K_Parameter_List),
Return_Type => New_Node (CTN.K_Void));
Append_Node_To_List (Init_Spec, CTN.Declarations (Current_File));

-- Visit all the subcomponents of the process

if not AAU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));

while Present (S) loop
if AAU.Is_Data (Corresponding_Instance (S)) then

N :=
Make_Variable_Declaration
(Map_C_Defining_Identifier (S),
Expand All @@ -1954,6 +1981,12 @@ package body Ocarina.Backends.PO_HI_C.Activity is
CTN.Declarations (Current_File));

Bind_AADL_To_Object (Identifier (S), N);

elsif AAU.Is_Thread (Corresponding_Instance (S)) then
Append_Node_To_List
(Task_Initialize (Corresponding_Instance (S)),
Init_Statements);

end if;
S := Next_Node (S);
end loop;
Expand All @@ -1963,7 +1996,6 @@ package body Ocarina.Backends.PO_HI_C.Activity is
S := First_Node (Subcomponents (E));

while Present (S) loop

if not AAU.Is_Data (Corresponding_Instance (S)) then
Visit (Corresponding_Instance (S));
end if;
Expand Down Expand Up @@ -1993,7 +2025,6 @@ package body Ocarina.Backends.PO_HI_C.Activity is
(CTN.Job_Node
(Backend_Node (Identifier (Parent_Subcomponent (E)))))
then

Append_Node_To_List
(Make_Variable_Declaration
(Defining_Identifier =>
Expand Down Expand Up @@ -2055,6 +2086,12 @@ package body Ocarina.Backends.PO_HI_C.Activity is
Declarations,
Statements);
Append_Node_To_List (N, CTN.Declarations (Current_File));
N :=
Make_Function_Implementation
(Init_Spec,
Init_Declarations,
Init_Statements);
Append_Node_To_List (N, CTN.Declarations (Current_File));
end if;

Pop_Entity; -- U
Expand Down
4 changes: 3 additions & 1 deletion src/backends/po_hi_c/ocarina-backends-po_hi_c-runtime.ads
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2020 ESA & ISAE. --
-- --
-- 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 @@ -137,6 +137,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Deployment_Endiannesses, -- __po_hi_deployment_endiannesses
RE_Sporadic_Wait_Release, -- __po_hi_sporadic_wait_release
RE_Transport_Send_Default, -- __po_hi_transport_send_default
RE_Main_Initialize, -- __po_hi_main_initialize
RE_Main_Deliver, -- __po_hi_main_deliver
RE_Msg_Reallocate, -- __po_hi_msg_reallocate
RE_Copy_Array, -- __po_hi_copy_array
Expand Down Expand Up @@ -344,6 +345,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Marshall_Asn1_Request => RH_Marshallers,
RE_Unmarshall_Asn1_Request => RH_Marshallers,
RE_Create_Periodic_Task => RH_PO_HI_Task,
RE_Main_Initialize => RH_Activity,
RE_Main_Deliver => RH_Activity,
RE_Create_Sporadic_Task => RH_PO_HI_Task,
RE_Compute_Miss => RH_PO_HI_Utils,
Expand Down

1 comment on commit 8093955

@yoogx
Copy link
Contributor Author

@yoogx yoogx commented on 8093955 Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For #267

Please sign in to comment.