Commit 20f5c284 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files
parents f0d3c11b 485db820
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2018 ESA & ISAE. --
-- Copyright (C) 2018-2019 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- --
......@@ -299,17 +299,22 @@ package body Ocarina.Backends.AIR_Conf.Partitions is
-- MaxMessageSize
if Get_Data_Size (Corresponding_Instance (F)) /= Null_Size then
Q := Make_Literal (XV.New_Numeric_Value (1024, 1, 10));
-- Q :=
-- Make_Literal
-- (XV.New_Numeric_Value
-- (To_Bytes
-- (Get_Data_Size (Corresponding_Instance (F))),
-- 1,
-- 10));
-- If data size is specified, use this value, add
-- 40 to take into account PolyORB-HI/C header
-- (conservative value).
Q :=
Make_Literal
(XV.New_Numeric_Value
(40 + To_Bytes
(Get_Data_Size (Corresponding_Instance (F))),
1,
10));
else
Q := Make_Literal (XV.New_Numeric_Value (1, 1, 10));
Display_Located_Error
(Loc (F),
"No data size given for data size",
Fatal => True);
end if;
Set_Str_To_Name_Buffer ("MaxMessageSize");
......
......@@ -38,8 +38,17 @@ package Ocarina.Backends.C_Common.BA is
-- having the same identifiers. It returns the declarations list of
-- the generated C-subprogram.
procedure Map_C_Behavior_Actions (S : Node_Id;
Declarations : List_Id;
Statements : List_Id);
procedure Map_C_Behavior_Transitions (S : Node_Id;
Declarations : List_Id;
Statements : List_Id);
function Get_Behavior_Specification (S : Node_Id) return Node_Id;
function Is_To_Make_Init_Sequence (S : Node_Id) return Boolean;
function Make_Specification_Of_BA_Related_Function
(S : Node_Id;
BA_Body : Boolean := False;
BA_Initialization : Boolean := False) return Node_Id;
end Ocarina.Backends.C_Common.BA;
......@@ -1032,8 +1032,9 @@ package body Ocarina.Backends.C_Common.Mapping is
-----------------------
function Map_C_Define_Name
(E : Node_Id;
Nb_Ports : Boolean := False) return Name_Id
(E : Node_Id;
Nb_Ports : Boolean := False;
Nb_States : Boolean := False) return Name_Id
is
C_Name : Name_Id;
begin
......@@ -1048,6 +1049,8 @@ package body Ocarina.Backends.C_Common.Mapping is
Get_Name_String_And_Append (C_Name);
if Nb_Ports then
Add_Str_To_Name_Buffer ("_NB_PORTS");
elsif Nb_States then
Add_Str_To_Name_Buffer ("_nb_states");
end if;
else
raise Program_Error with "Wrong node kind for Map_C_Enumerator_Name";
......@@ -1080,7 +1083,11 @@ package body Ocarina.Backends.C_Common.Mapping is
Port_Destinations : Boolean := False;
Port_Total_Fifo : Boolean := False;
Port_Request : Boolean := False;
Request_Variable : Boolean := False) return Name_Id
Request_Variable : Boolean := False;
State_Name_T : Boolean := False;
State_T : Boolean := False;
States_Array : Boolean := False;
Current_State : Boolean := False) return Name_Id
is
C_Name : Name_Id;
begin
......@@ -1134,6 +1141,14 @@ package body Ocarina.Backends.C_Common.Mapping is
Add_Str_To_Name_Buffer ("_request");
elsif Request_Variable then
Add_Str_To_Name_Buffer ("_request_var");
elsif State_Name_T then
Add_Str_To_Name_Buffer ("_state_name_t");
elsif State_T then
Add_Str_To_Name_Buffer ("_state_t");
elsif States_Array then
Add_Str_To_Name_Buffer ("_states_array");
elsif Current_State then
Add_Str_To_Name_Buffer ("_current_state");
end if;
C_Name := Name_Find;
......@@ -1141,6 +1156,36 @@ package body Ocarina.Backends.C_Common.Mapping is
return C_Name;
end Map_C_Variable_Name;
------------------------------------
-- Map_C_BA_Related_Function_Name --
------------------------------------
function Map_C_BA_Related_Function_Name
(E : Node_Id;
BA_Body : Boolean := False;
States_Initialization : Boolean := False;
BA_Initialization : Boolean := False) return Name_Id
is
C_Name : Name_Id;
begin
C_Name := To_C_Name (Display_Name (Identifier (E)));
Get_Name_String (C_Name);
if BA_Body then
Add_Str_To_Name_Buffer ("_ba_body");
elsif States_Initialization then
Add_Str_To_Name_Buffer ("_states_initialization");
elsif BA_Initialization then
Add_Str_To_Name_Buffer ("_ba_initialization");
end if;
C_Name := Name_Find;
return C_Name;
end Map_C_BA_Related_Function_Name;
--------------------------
-- Map_C_Operation_Name --
--------------------------
......@@ -2930,10 +2975,9 @@ package body Ocarina.Backends.C_Common.Mapping is
-- condition with a Behavior_Action_Block.
-- Thus, we need to map the Behavior_Action_Block
-- To C-statements in the generated C-subprogram
-- Map_C_Behavior_Variables (S,Declarations);
CCBA.Map_C_Behavior_Variables (S, Declarations);
CCBA.Map_C_Behavior_Actions (S, Declarations, Statements);
CCBA.Map_C_Behavior_Transitions (S, Declarations, Statements);
return CTU.Make_Function_Implementation
(Spec,
......
......@@ -77,8 +77,9 @@ package Ocarina.Backends.C_Common.Mapping is
Port_Type : Boolean := False;
Local_Port : Boolean := False) return Name_Id;
function Map_C_Define_Name
(E : Node_Id;
Nb_Ports : Boolean := False) return Name_Id;
(E : Node_Id;
Nb_Ports : Boolean := False;
Nb_States : Boolean := False) return Name_Id;
function Map_C_Full_Parameter_Name
(Spg : Node_Id;
P : Node_Id;
......@@ -143,7 +144,17 @@ package Ocarina.Backends.C_Common.Mapping is
Port_Destinations : Boolean := False;
Port_Total_Fifo : Boolean := False;
Port_Request : Boolean := False;
Request_Variable : Boolean := False) return Name_Id;
Request_Variable : Boolean := False;
State_Name_T : Boolean := False;
State_T : Boolean := False;
States_Array : Boolean := False;
Current_State : Boolean := False) return Name_Id;
function Map_C_BA_Related_Function_Name
(E : Node_Id;
BA_Body : Boolean := False;
States_Initialization : Boolean := False;
BA_Initialization : Boolean := False) return Name_Id;
function Map_Port_Data_With_Virtual_Bus
(E : Node_Id;
......
......@@ -41,7 +41,8 @@ with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.C_Common.Mapping;
with Ocarina.Backends.PO_HI_C.Runtime;
with Ocarina.Backends.C_Common.BA;
with Ocarina.Namet;
with Ocarina.ME_AADL_BA.BA_Tree.Nutils;
with Ocarina.ME_AADL_BA.BA_Tree.Nodes;
package body Ocarina.Backends.C_Common.Subprograms is
......@@ -53,7 +54,6 @@ package body Ocarina.Backends.C_Common.Subprograms is
use Ocarina.Backends.C_Tree.Nutils;
use Ocarina.Backends.C_Common.Mapping;
use Ocarina.Backends.C_Common.BA;
use Ocarina.Namet;
use Ocarina.Backends.PO_HI_C.Runtime;
package PHCR renames Ocarina.Backends.PO_HI_C.Runtime;
......@@ -61,6 +61,8 @@ package body Ocarina.Backends.C_Common.Subprograms is
package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
package CTN renames Ocarina.Backends.C_Tree.Nodes;
package BANu renames Ocarina.ME_AADL_BA.BA_Tree.Nutils;
package BATN renames Ocarina.ME_AADL_BA.BA_Tree.Nodes;
C_Root : Node_Id;
......@@ -586,8 +588,7 @@ package body Ocarina.Backends.C_Common.Subprograms is
Spg_Call : Node_Id;
Feature : Node_Id;
N : Node_Id;
Def_Idt : Node_Id;
Parameter_List : constant List_Id := New_List (CTN.K_List_Id);
S : constant Node_Id := Parent_Subcomponent (E);
begin
if Has_In_Ports (E) then
Feature := First_Node (Features (E));
......@@ -631,24 +632,37 @@ package body Ocarina.Backends.C_Common.Subprograms is
if Has_Behavior_Specification (E) then
Set_Str_To_Name_Buffer ("");
N := Make_Extern_Entity_Declaration
(Make_Specification_Of_BA_Related_Function (E, BA_Body => True));
Get_Name_String (Name (Identifier (E)));
Add_Str_To_Name_Buffer ("_ba_body");
Def_Idt := Make_Defining_Identifier (Name_Find);
N :=
Make_Parameter_Specification
(Make_Defining_Identifier (PN (P_Self)),
Parameter_Type => RE (RE_Task_Id));
Append_Node_To_List (N, Parameter_List);
Append_Node_To_List (N, CTN.Declarations (Current_File));
N := Make_Function_Specification
(Defining_Identifier => Def_Idt,
Parameters => Parameter_List,
Return_Type => New_Node (CTN.K_Void));
declare
BA : Node_Id;
begin
BA := Get_Behavior_Specification (E);
if BANu.Length (BATN.States (BA)) > 1 then
N :=
Make_Extern_Entity_Declaration
(Make_Function_Specification
(Defining_Identifier => Make_Defining_Identifier
(Map_C_BA_Related_Function_Name
(S, States_Initialization => True)),
Parameters => No_List,
Return_Type => New_Node (CTN.K_Void)));
Append_Node_To_List (N,
CTN.Declarations (Current_File));
if Is_To_Make_Init_Sequence (E) then
N := Make_Extern_Entity_Declaration
(Make_Specification_Of_BA_Related_Function
(E, BA_Initialization => True));
Append_Node_To_List (N, CTN.Declarations (Current_File));
Append_Node_To_List (N, CTN.Declarations (Current_File));
end if;
end if;
end;
end if;
......@@ -1192,9 +1206,6 @@ package body Ocarina.Backends.C_Common.Subprograms is
Call_Seq : Node_Id;
Spg_Call : Node_Id;
Feature : Node_Id;
N : Node_Id;
Def_Idt : Node_Id;
Parameter_List : constant List_Id := New_List (CTN.K_List_Id);
Declarations : constant List_Id :=
New_List (CTN.K_Declaration_List);
Statements : constant List_Id := New_List (CTN.K_Statement_List);
......@@ -1241,32 +1252,8 @@ package body Ocarina.Backends.C_Common.Subprograms is
if Has_Behavior_Specification (E) then
Set_Str_To_Name_Buffer ("");
Get_Name_String (Name (Identifier (E)));
Add_Str_To_Name_Buffer ("_ba_body");
Def_Idt := Make_Defining_Identifier (Name_Find);
N :=
Make_Parameter_Specification
(Make_Defining_Identifier (PN (P_Self)),
Parameter_Type => RE (RE_Task_Id));
Append_Node_To_List (N, Parameter_List);
N := Make_Function_Specification
(Defining_Identifier => Def_Idt,
Parameters => Parameter_List,
Return_Type => New_Node (CTN.K_Void));
Map_C_Behavior_Transitions (E, Declarations, Statements);
Map_C_Behavior_Variables (E, Declarations);
Map_C_Behavior_Actions (E, Declarations, Statements);
N := Make_Function_Implementation
(Specification => N,
Declarations => Declarations,
Statements => Statements);
Append_Node_To_List (N, CTN.Declarations (Current_File));
end if;
end Visit_Thread_Instance;
......
......@@ -4134,7 +4134,11 @@ package body Ocarina.Backends.Utils is
end if;
end loop;
return Number_Of_Cores;
if Number_Of_Cores /= 0 then
return Number_Of_Cores;
else
return 1;
end if;
end Get_Number_Of_Cores;
------------------------------
......
......@@ -43,6 +43,9 @@ with Ocarina.Backends.C_Common.Mapping;
with Ocarina.Backends.PO_HI_C.Runtime;
with Ocarina.Backends.C_Values;
with Ocarina.Backends.Messages;
with Ocarina.Backends.C_Common.BA;
with Ocarina.ME_AADL_BA.BA_Tree.Nutils;
with Ocarina.ME_AADL_BA.BA_Tree.Nodes;
package body Ocarina.Backends.PO_HI_C.Activity is
......@@ -56,12 +59,15 @@ package body Ocarina.Backends.PO_HI_C.Activity is
use Ocarina.Backends.C_Common.Mapping;
use Ocarina.Backends.PO_HI_C.Runtime;
use Ocarina.Backends.Messages;
use Ocarina.Backends.C_Common.BA;
package AAU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
package AAN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
package CTN renames Ocarina.Backends.C_Tree.Nodes;
package CTU renames Ocarina.Backends.C_Tree.Nutils;
package CV renames Ocarina.Backends.C_Values;
package BATN renames Ocarina.ME_AADL_BA.BA_Tree.Nodes;
package BANu renames Ocarina.ME_AADL_BA.BA_Tree.Nutils;
Current_Device : Node_Id := No_Node;
......@@ -357,14 +363,15 @@ package body Ocarina.Backends.PO_HI_C.Activity is
Get_Thread_Dispatch_Protocol (E);
Impl_Kind : constant Supported_Thread_Implementation :=
Get_Thread_Implementation_Kind (E);
Call_Parameters : List_Id;
N : Node_Id;
Call_Parameters : List_Id;
Call_Parameters_Of_BA_Initialization_Function : List_Id;
N, N1 : Node_Id;
procedure Make_Wait_Event;
procedure Make_Call_Sequence;
procedure Make_Set_Out_Ports;
procedure Make_Send_Out_Ports;
procedure Make_Task_Blocking;
procedure Make_Send_Out_Ports (WStats : List_Id);
procedure Make_Task_Blocking (WStats : List_Id);
procedure Make_Fetch_In_Ports;
procedure Make_Wait_Offset;
procedure Make_Thread_Compute_Entrypoint;
......@@ -525,7 +532,7 @@ package body Ocarina.Backends.PO_HI_C.Activity is
-- Make_Task_Blocking --
------------------------
procedure Make_Task_Blocking is
procedure Make_Task_Blocking (WStats : List_Id) is
begin
-- Make the __po_hi_wait_for_next_period call
......@@ -545,7 +552,7 @@ package body Ocarina.Backends.PO_HI_C.Activity is
CTU.Make_Call_Profile
(RE (RE_Wait_For_Next_Period),
Call_Parameters);
Append_Node_To_List (N, WStatements);
Append_Node_To_List (N, WStats);
end Make_Task_Blocking;
------------------------
......@@ -710,13 +717,14 @@ package body Ocarina.Backends.PO_HI_C.Activity is
-- Make_Send_Out_Ports --
-------------------------
procedure Make_Send_Out_Ports is
procedure Make_Send_Out_Ports (WStats : List_Id) is
N : Node_Id;
F : Node_Id;
Error_Already_Defined : Boolean := False;
Decl : Node_Id;
begin
N := Message_Comment ("Send the OUT ports");
Append_Node_To_List (N, WStatements);
Append_Node_To_List (N, WStats);
F := First_Node (Features (E));
......@@ -756,14 +764,33 @@ package body Ocarina.Backends.PO_HI_C.Activity is
0,
10)))),
Statements => Make_List_Id (N)),
WStatements);
WStats);
else
N :=
Make_Assignment_Statement
(Variable_Identifier =>
Make_Defining_Identifier (VN (V_Error)),
Expression => N);
Append_Node_To_List (N, WStatements);
Append_Node_To_List (N, WStats);
declare
use Ocarina.Backends.C_Tree.Nodes;
begin
Decl := CTN.First_Node (Declarations);
while Present (Decl) loop
if CTN.Kind (Decl) = CTN.K_Variable_Declaration
and then
Get_Name_String
(CTN.Name (CTN.Defining_Identifier (Decl)))
= Get_Name_String (VN (V_Error))
then
Error_Already_Defined := True;
end if;
exit when Error_Already_Defined;
Decl := CTN.Next_Node (Decl);
end loop;
end;
if not Error_Already_Defined then
N :=
......@@ -807,7 +834,7 @@ package body Ocarina.Backends.PO_HI_C.Activity is
Op_Not_Equal,
RE (RE_SUCCESS)),
Statements => Then_Statements);
Append_Node_To_List (N, WStatements);
Append_Node_To_List (N, WStats);
end if;
end;
......@@ -1118,9 +1145,7 @@ package body Ocarina.Backends.PO_HI_C.Activity is
----------------------------------------
procedure Make_Thread_Behavior_Specification is
N : Node_Id;
Parameter_List : constant List_Id := New_List (CTN.K_List_Id);
Def_Idt : Node_Id;
N, N1 : Node_Id;
begin
-- Add_Include (RH (RH_Subprograms));
......@@ -1135,43 +1160,43 @@ package body Ocarina.Backends.PO_HI_C.Activity is
N := Make_Defining_Identifier (Map_C_Enumerator_Name (S));
Append_Node_To_List (N, Call_Parameters);
N :=
Make_Parameter_Specification
(Make_Defining_Identifier (PN (P_Self)),
Parameter_Type => RE (RE_Task_Id));
Append_Node_To_List (N, Parameter_List);
if P = Thread_Sporadic then
Set_Str_To_Name_Buffer ("");
Get_Name_String (Name (Identifier (E)));
Add_Str_To_Name_Buffer ("_ba_body");
Def_Idt := Make_Defining_Identifier (Name_Find);
N := Make_Variable_Address
(Make_Defining_Identifier (VN (V_Port)));
Append_Node_To_List (N, Call_Parameters);
if P = Thread_Sporadic then
end if;
-- add data subcomponents of the thread to the call_parameters
-- of the procedure <<thread_instance_name>>_ba_body
Append_Node_To_List
(Make_Defining_Identifier (VN (V_Port)),
Call_Parameters);
if not AAU.Is_Empty (Subcomponents (E)) then
N1 := First_Node (Subcomponents (E));
N :=
Make_Parameter_Specification
(Make_Defining_Identifier (VN (V_Port)),
Parameter_Type => RE (RE_Port_T));
Append_Node_To_List (N, Parameter_List);
while Present (N1) loop
if AAU.Is_Data (Corresponding_Instance (N1)) then
N :=
Make_Variable_Address
(Map_C_Defining_Identifier (N1));
Append_Node_To_List (N, Call_Parameters);
end if;
N1 := Next_Node (N1);
end loop;
end if;
N :=
Make_Extern_Entity_Declaration
(Make_Function_Specification
(Defining_Identifier => Def_Idt,
Parameters => Parameter_List,
Return_Type => New_Node (CTN.K_Void)));
N := Make_Extern_Entity_Declaration
(Make_Specification_Of_BA_Related_Function
(E, BA_Body => True));
Append_Node_To_List (N, CTN.Declarations (Current_File));
N :=
Make_Call_Profile
(Defining_Identifier => Def_Idt,
(Defining_Identifier => Make_Defining_Identifier
(Map_C_BA_Related_Function_Name (S, BA_Body => True)),
Parameters => Call_Parameters);
Append_Node_To_List (N, WStatements);
......@@ -1208,6 +1233,39 @@ package body Ocarina.Backends.PO_HI_C.Activity is
Check_Thread_Consistency (E);
-- Visit the data subcomponents of the thread
if not AAU.Is_Empty (Subcomponents (E)) then
N1 := First_Node (Subcomponents (E));
while Present (N1) loop
if AAU.Is_Data (Corresponding_Instance (N1)) then
N :=
Make_Variable_Declaration
(Map_C_Defining_Identifier (N1),
Map_C_Data_Type_Designator
(Corresponding_Instance (N1)));
Append_Node_To_List (N, Declarations);
end if;
N1 := Next_Node (N1);
end loop;
end if;
if not AAU.Is_Empty (Subcomponents (E)) then
N1 := First_Node (Subcomponents (E));
while Present (N1) loop
if not AAU.Is_Data (Corresponding_Instance (N1)) then
Visit (Corresponding_Instance (N1));
end if;
N1 := Next_Node (N1);
end loop;
end if;
if Has_Ports (E) then
-- Make the __po_hi_gqueue_init call
......@@ -1327,7 +1385,7 @@ package body Ocarina.Backends.PO_HI_C.Activity is
-- Send OUT ports
if Has_Out_Ports (E) then
Make_Send_Out_Ports;
Make_Send_Out_Ports (WStatements);
end if;
when Thread_With_Compute_Entrypoint =>
......@@ -1344,7 +1402,7 @@ package body Ocarina.Backends.PO_HI_C.Activity is
-- OUT ports.
if Has_Out_Ports (E) then
Make_Send_Out_Ports;
Make_Send_Out_Ports (WStatements);
end if;
when Thread_With_Port_Compute_Entrypoint =>
......@@ -1361,13 +1419,56 @@ package body Ocarina.Backends.PO_HI_C.Activity is
-- ports.