Commit 20f5c284 authored by Maxime Perrotin's avatar Maxime Perrotin
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;
------------------------------
......
......@@ -1300,11 +1300,25 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
Value => Nb_Entities_Node);
Append_Node_To_List (N, CTN.Declarations (Current_File));
N :=
Make_Define_Statement
(Defining_Identifier => RE (RE_Nb_Ports),
Value => Total_Ports_Node);
Append_Node_To_List (N, CTN.Declarations (Current_File));
-- If there are ports in the local process, we generate a
-- macro indicating the total number of ports in the
-- application, otherwise we generate a value of 0 to avoid
-- dragging the whole transport logic. This may happen in
-- corner cases when using external API for communication.
if Nb_Ports_In_Process > 0 then
N :=
Make_Define_Statement
(Defining_Identifier => RE (RE_Nb_Ports),
Value => Total_Ports_Node);
Append_Node_To_List (N, CTN.Declarations (Current_File));
else
N :=
Make_Define_Statement
(Defining_Identifier => RE (RE_Nb_Ports),
Value => Make_Literal (New_Int_Value (0, 1, 10)));
Append_Node_To_List (N, CTN.Declarations (Current_File));
end if;
if not Is_Empty (Global_Port_List) then
if not Invalid_Global_Port_Added then
......
......@@ -142,8 +142,27 @@ package body Ocarina.Backends.PO_HI_C.Runtime is
Set_Name (RED (E), Name);
end loop;
for E in RB_Id loop
Set_Str_To_Name_Buffer (RB_Id'Image (E));
Set_Str_To_Name_Buffer ("__po_hi_" & Name_Buffer (4 .. Name_Len));
Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));
while Name_Buffer (Name_Len) in '0' .. '9'
or else Name_Buffer (Name_Len) = '_'
loop
Name_Len := Name_Len - 1;
end loop;
Name := Name_Find;
Name := To_Lower (Name);
RED (E) := New_Node (K_Defining_Identifier);
Set_Name (RED (E), Name);
end loop;
for E in RM_Id loop
Set_Str_To_Name_Buffer (RC_Id'Image (E));
Set_Str_To_Name_Buffer (RM_Id'Image (E));
Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));
Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));
......
......@@ -260,7 +260,17 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Local_Port, -- LOCAL_PORT
RE_PORT_VARIABLE, -- PORT_VARIABLE
RE_REQUEST_PORT -- REQUEST_PORT
RE_REQUEST_PORT, -- REQUEST_PORT
RE_Initial, -- __po_hi_initial
RE_Initial_Complete, -- __po_hi_initial_complete
RE_Initial_Complete_Final, -- __po_hi_initial_complete_final
RE_Initial_Final, -- __po_hi_initial_final
RE_Complete, -- __po_hi_complete
RE_Complete_Final, -- __po_hi_complete_final
RE_Final, -- __po_hi_final
RE_Execution, -- __po_hi_execution
RE_State_Kind_T -- __po_hi_state_kind_t
);
-- Runtime types
......@@ -270,6 +280,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
subtype RF_Id is RE_Id range RE_Null .. RE_Wait_For_Tasks;
subtype RV_Id is RE_Id range RE_Operation_Names .. RE_Port_Global_To_Local;
subtype RM_Id is RE_Id range RE_Local_Port .. RE_REQUEST_PORT;
subtype RB_Id is RE_Id range RE_Initial .. RE_State_Kind_T;
RE_Header_Table : constant array (RE_Id) of RH_Id :=
(RE_Null => RH_Null,
......@@ -479,7 +490,17 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Local_Port => RH_AADL,
RE_PORT_VARIABLE => RH_AADL,
RE_REQUEST_PORT => RH_AADL
RE_REQUEST_PORT => RH_AADL,
RE_Initial => RH_Null,
RE_Initial_Complete => RH_Null,
RE_Initial_Complete_Final => RH_Null,
RE_Initial_Final => RH_Null,
RE_Complete => RH_Null,
RE_Complete_Final => RH_Null,
RE_Final => RH_Null,
RE_Execution => RH_Null,
RE_State_Kind_T => RH_Null
);
procedure Initialize;
procedure Reset;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment