Commit 943b611c authored by julien.delange's avatar julien.delange

generate device subprograms, tasks and so on

able to begin to write drivers inside pohic



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@533 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 782df583
......@@ -868,11 +868,12 @@ package body Ocarina.Backends.C_Common.Mapping is
---------------------------
function Map_C_Enumerator_Name
(E : Node_Id;
Entity : Boolean := False;
Server : Boolean := False;
Port_Type : Boolean := False;
Local_Port : Boolean := False)
(E : Node_Id;
Custom_Parent : Node_Id := No_Node;
Entity : Boolean := False;
Server : Boolean := False;
Port_Type : Boolean := False;
Local_Port : Boolean := False)
return Name_Id
is
C_Name_1 : Name_Id;
......@@ -895,26 +896,27 @@ package body Ocarina.Backends.C_Common.Mapping is
Add_Str_To_Name_Buffer ("_global_");
Get_Name_String_And_Append (C_Name_1);
end if;
elsif AINU.Is_Subprogram (E)
or else (Present (Corresponding_Instance (E))
and then AINU.Is_Process (Corresponding_Instance (E)))
then
elsif AINU.Is_Subprogram (E) then
-- For subprograms and processes, the enemerator name is
-- mapped from the entity name.
Get_Name_String (CTU.To_C_Name (Display_Name (Identifier (E))));
Add_Str_To_Name_Buffer ("_k");
elsif (Present (Corresponding_Instance (E))
and then AINU.Is_Process_Or_Device
(Corresponding_Instance (E))) then
Get_Name_String (CTU.To_C_Name (Display_Name (Identifier (E))));
Add_Str_To_Name_Buffer ("_k");
elsif AINU.Is_Thread (Corresponding_Instance (E)) then
-- For threads, the enumerator name is mapped from the
-- containing process name and the thread subcomponent name.
if Parent_Subcomponent (Parent_Component (E)) = No_Node then
if Custom_Parent /= No_Node then
C_Name_1 := CTU.To_C_Name
(Display_Name
(Identifier
(Parent_Component
(E))));
(Parent_Subcomponent
(Custom_Parent))));
else
C_Name_1 := CTU.To_C_Name
(Display_Name
......
......@@ -65,11 +65,12 @@ package Ocarina.Backends.C_Common.Mapping is
function Map_Task_Job_Identifier (E : Node_Id) return Node_Id;
function Map_Time (T : Time_Type) return Node_Id;
function Map_C_Enum_Name (E : Node_Id; Enumerator : Name_Id) return Name_Id;
function Map_C_Enumerator_Name (E : Node_Id;
Entity : Boolean := False;
Server : Boolean := False;
Port_Type : Boolean := False;
Local_Port : Boolean := False)
function Map_C_Enumerator_Name (E : Node_Id;
Custom_Parent : Node_Id := No_Node;
Entity : Boolean := False;
Server : Boolean := False;
Port_Type : Boolean := False;
Local_Port : Boolean := False)
return Name_Id;
function Map_C_Define_Name
(E : Node_Id;
......
......@@ -42,8 +42,6 @@ with Ocarina.Backends.C_Tree.Nutils;
with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.C_Common.Mapping;
with Ocarina.Instances.Queries;
package body Ocarina.Backends.C_Common.Subprograms is
use Ocarina.ME_AADL;
......@@ -54,8 +52,6 @@ package body Ocarina.Backends.C_Common.Subprograms is
use Ocarina.Backends.C_Tree.Nutils;
use Ocarina.Backends.C_Common.Mapping;
use Ocarina.Instances.Queries;
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;
......@@ -159,19 +155,17 @@ package body Ocarina.Backends.C_Common.Subprograms is
Implementation : Node_Id;
S : Node_Id;
begin
if Get_Current_Backend_Kind = PolyORB_Kernel_C then
U := CTN.Distributed_Application_Unit
(CTN.Naming_Node (Backend_Node (Identifier (E))));
if Get_Current_Backend_Kind /= PolyORB_Kernel_C then
return;
end if;
U := CTN.Distributed_Application_Unit
(CTN.Naming_Node (Backend_Node (Identifier (E))));
P := CTN.Entity (U);
P := CTN.Entity (U);
Push_Entity (P);
Push_Entity (U);
Push_Entity (P);
Push_Entity (U);
end if;
Implementation := Get_Classifier_Property (E, "implemented_as");
Implementation := Get_Implementation (E);
if Implementation /= No_Node then
if not AINU.Is_Empty (AIN.Subcomponents (Implementation)) then
......@@ -182,14 +176,19 @@ package body Ocarina.Backends.C_Common.Subprograms is
(Corresponding_Instance (S), False);
end if;
if Get_Current_Backend_Kind = PolyORB_HI_C then
Visit_Component_Instance (Corresponding_Instance (S));
end if;
S := Next_Node (S);
end loop;
end if;
end if;
Pop_Entity; -- U
Pop_Entity; -- P
if Get_Current_Backend_Kind = PolyORB_Kernel_C then
Pop_Entity; -- U
Pop_Entity; -- P
end if;
end Visit_Device_Instance;
-------------------------
......@@ -277,6 +276,9 @@ package body Ocarina.Backends.C_Common.Subprograms is
U : Node_Id;
P : Node_Id;
S : Node_Id;
C : Node_Id;
The_System : constant Node_Id := Parent_Component
(Parent_Subcomponent (E));
begin
if Real_Process then
U := CTN.Distributed_Application_Unit
......@@ -305,6 +307,26 @@ package body Ocarina.Backends.C_Common.Subprograms is
end loop;
end if;
-- Visit all devices attached to the parent system that
-- share the same processor as process E.
if Get_Current_Backend_Kind = PolyORB_HI_C and then
not AINU.Is_Empty (Subcomponents (The_System)) then
C := First_Node (Subcomponents (The_System));
while Present (C) loop
if AINU.Is_Device (Corresponding_Instance (C))
and then
Get_Bound_Processor (Corresponding_Instance (C))
= Get_Bound_Processor (E)
then
-- Build the enumerator corresponding to the device
-- Note: we reuse the process name XXX
Visit_Device_Instance (Corresponding_Instance (C));
end if;
C := Next_Node (C);
end loop;
end if;
-- Unmark all the marked subprograms
Reset_Handlings;
......@@ -621,6 +643,9 @@ package body Ocarina.Backends.C_Common.Subprograms is
U : Node_Id;
P : Node_Id;
S : Node_Id;
C : Node_Id;
The_System : constant Node_Id := Parent_Component
(Parent_Subcomponent (E));
begin
if Real_Process then
U := CTN.Distributed_Application_Unit
......@@ -647,6 +672,21 @@ package body Ocarina.Backends.C_Common.Subprograms is
end loop;
end if;
if Get_Current_Backend_Kind = PolyORB_HI_C and then
not AINU.Is_Empty (Subcomponents (The_System)) then
C := First_Node (Subcomponents (The_System));
while Present (C) loop
if AINU.Is_Device (Corresponding_Instance (C))
and then
Get_Bound_Processor (Corresponding_Instance (C))
= Get_Bound_Processor (E)
then
Visit_Device_Instance (Corresponding_Instance (C));
end if;
C := Next_Node (C);
end loop;
end if;
-- Unmark all the marked subprograms
Reset_Handlings;
......@@ -818,20 +858,18 @@ package body Ocarina.Backends.C_Common.Subprograms is
Implementation : Node_Id;
S : Node_Id;
begin
if Get_Current_Backend_Kind = PolyORB_Kernel_C then
if Get_Current_Backend_Kind /= PolyORB_Kernel_C then
return;
end if;
U := CTN.Distributed_Application_Unit
(CTN.Naming_Node (Backend_Node (Identifier (E))));
U := CTN.Distributed_Application_Unit
(CTN.Naming_Node (Backend_Node (Identifier (E))));
P := CTN.Entity (U);
P := CTN.Entity (U);
Push_Entity (P);
Push_Entity (U);
Push_Entity (P);
Push_Entity (U);
end if;
Implementation := Get_Classifier_Property (E, "implemented_as");
Implementation := Get_Implementation (E);
if Implementation /= No_Node then
if not AINU.Is_Empty (AIN.Subcomponents (Implementation)) then
......@@ -842,14 +880,20 @@ package body Ocarina.Backends.C_Common.Subprograms is
(Corresponding_Instance (S), False);
end if;
if Get_Current_Backend_Kind = PolyORB_HI_C then
Visit_Component_Instance (Corresponding_Instance (S));
end if;
S := Next_Node (S);
end loop;
end if;
end if;
Pop_Entity; -- U
Pop_Entity; -- P
if Get_Current_Backend_Kind = PolyORB_Kernel_C then
Pop_Entity; -- U
Pop_Entity; -- P
end if;
end Visit_Device_Instance;
end Source_File;
......
......@@ -393,6 +393,8 @@ package body Ocarina.Backends.PO_HI_C.Activity is
Main_Deliver_Alternatives : List_Id;
Current_Device : Node_Id := No_Node;
-------------------
-- Task_Job_Body --
-------------------
......@@ -534,7 +536,11 @@ package body Ocarina.Backends.PO_HI_C.Activity is
-- Make the call to __po_hi_compute_next_period
Call_Parameters := New_List (CTN.K_Parameter_List);
N := Make_Defining_Identifier (Map_C_Enumerator_Name (S));
N := Make_Defining_Identifier
(Map_C_Enumerator_Name
(S,
Custom_Parent => Current_Device));
Append_Node_To_List (N, Call_Parameters);
N := CTU.Make_Call_Profile (RE (RE_Compute_Next_Period),
......@@ -551,7 +557,14 @@ package body Ocarina.Backends.PO_HI_C.Activity is
-- Make the __po_hi_wait_for_next_period call
Call_Parameters := New_List (CTN.K_Parameter_List);
N := Make_Defining_Identifier (Map_C_Enumerator_Name (S));
if Current_Device /= No_Node then
N := Make_Defining_Identifier
(Map_C_Enumerator_Name
(S,
Custom_Parent => Current_Device));
else
N := Make_Defining_Identifier (Map_C_Enumerator_Name (S));
end if;
Append_Node_To_List (N, Call_Parameters);
N := CTU.Make_Call_Profile (RE (RE_Wait_For_Next_Period),
......@@ -1277,7 +1290,8 @@ package body Ocarina.Backends.PO_HI_C.Activity is
N := CTU.Make_Call_Profile (RE (RE_Compute_Next_Period),
Make_List_Id
(Make_Defining_Identifier
(Map_C_Enumerator_Name (S))));
(Map_C_Enumerator_Name
(S, Current_Device))));
Append_Node_To_List (N, Statements);
end if;
......@@ -1529,6 +1543,8 @@ package body Ocarina.Backends.PO_HI_C.Activity is
Implementation : constant Node_Id := Get_Implementation (E);
S : Node_Id;
begin
Current_Device := E;
if Implementation /= No_Node then
if not AAU.Is_Empty (AAN.Subcomponents (Implementation)) then
S := First_Node (Subcomponents (Implementation));
......@@ -1538,6 +1554,8 @@ package body Ocarina.Backends.PO_HI_C.Activity is
end loop;
end if;
end if;
Current_Device := No_Node;
end Visit_Device_Instance;
---------------------------
......
......@@ -61,6 +61,7 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
use Ocarina.Backends.Properties;
use Ocarina.Backends.Messages;
package AAN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
package AAU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
package CV renames Ocarina.Backends.C_Values;
package CTN renames Ocarina.Backends.C_Tree.Nodes;
......@@ -79,6 +80,7 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
procedure Visit_Process_Instance (E : Node_Id);
procedure Visit_Thread_Instance (E : Node_Id);
procedure Visit_Subprogram_Instance (E : Node_Id);
procedure Visit_Device_Instance (E : Node_Id);
function Added_Internal_Name (P : Node_Id; E : Node_Id) return Name_Id;
function Is_Added (P : Node_Id; E : Node_Id) return Boolean;
......@@ -103,7 +105,7 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
Global_Port_List : List_Id;
Local_Port_List : List_Id;
Current_Process_Instance : Node_Id;
Current_Process_Instance : Node_Id := No_Node;
Global_Port_To_Entity : Node_Id;
Global_Port_To_Local : Node_Id;
......@@ -113,6 +115,9 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
Invalid_Global_Port_Added : Boolean := False;
Invalid_Entity_Added : Boolean := False;
Current_Device : Node_Id := No_Node;
-- Current_Process : Node_Id := No_Node;
-- Point to the process currently visited. When we visit a process
-- we look at all its ports and visit the called subprograms. So,
-- we need to know if these subprograms are linked with the currrent
......@@ -153,7 +158,10 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
N := Make_Expression
(Make_Defining_Identifier
(Map_C_Enumerator_Name (S, Entity => Is_Entity)),
(Map_C_Enumerator_Name
(S,
Custom_Parent => Current_Device,
Entity => Is_Entity)),
Op_Equal,
Make_Literal
(CV.New_Int_Value (Id, 0, 10)));
......@@ -245,11 +253,37 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
when CC_Subprogram =>
Visit_Subprogram_Instance (E);
when CC_Device =>
Visit_Device_Instance (E);
when others =>
null;
end case;
end Visit_Component_Instance;
---------------------------
-- Visit_Device_Instance --
---------------------------
procedure Visit_Device_Instance (E : Node_Id) is
Implementation : constant Node_Id := Get_Implementation (E);
N : Node_Id;
begin
Current_Device := E;
if Implementation /= No_Node then
if not AAU.Is_Empty (AAN.Subcomponents (Implementation)) then
N := First_Node (Subcomponents (Implementation));
while Present (N) loop
Visit_Component_Instance (Corresponding_Instance (N));
N := Next_Node (N);
end loop;
end if;
end if;
Current_Device := No_Node;
end Visit_Device_Instance;
----------------------------
-- Visit_Process_Instance --
----------------------------
......@@ -269,6 +303,8 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
Src : Node_Id;
Dst : Node_Id;
Parent : Node_Id;
The_System : constant Node_Id := Parent_Component
(Parent_Subcomponent (E));
begin
pragma Assert (AAU.Is_System (Root_Sys));
......@@ -314,6 +350,26 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
end loop;
end if;
-- Visit all devices attached to the parent system that
-- share the same processor as process E.
if not AAU.Is_Empty (Subcomponents (The_System)) then
C := First_Node (Subcomponents (The_System));
while Present (C) loop
if AAU.Is_Device (Corresponding_Instance (C))
and then
Get_Bound_Processor (Corresponding_Instance (C))
= Get_Bound_Processor (E)
then
-- Build the enumerator corresponding to the device
-- Note: we reuse the process name XXX
Visit_Device_Instance (Corresponding_Instance (C));
end if;
C := Next_Node (C);
end loop;
end if;
-- For each of the processes P connected to E, (1) we add an
-- enumerator corresponding to P and (2) for each one of the
-- threads of P, we add an enumerator.
......@@ -595,6 +651,8 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
Append_Node_To_List (N, CTN.Declarations (Current_File));
end if;
Current_Process_Instance := No_Node;
Pop_Entity; -- U
Pop_Entity; -- P
end Visit_Process_Instance;
......@@ -678,9 +736,15 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
(Present (Backend_Node (Identifier (S))) and then
No (CTN.Naming_Node (Backend_Node (Identifier (S)))))
then
N := Make_Defining_Identifier
(Map_C_Enumerator_Name (Parent_Subcomponent
(Parent_Component (Parent_Subcomponent (E)))));
if Current_Device /= No_Node then
N := Make_Defining_Identifier
(Map_C_Enumerator_Name
(Parent_Subcomponent (Current_Process_Instance)));
else
N := Make_Defining_Identifier
(Map_C_Enumerator_Name (Parent_Subcomponent
(Parent_Component (Parent_Subcomponent (E)))));
end if;
Bind_AADL_To_Naming (Identifier (S), N);
Append_Node_To_List (N, CTN.Values (Entity_Array));
end if;
......@@ -699,10 +763,29 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
Task_Identifier := Task_Identifier + 1;
end if;
if Current_Device /= No_Node and then
Current_Process_Instance /= No_Node and then
Get_Bound_Processor (Current_Device) =
Get_Bound_Processor (Current_Process_Instance) then
N := Make_Expression
(Make_Defining_Identifier
(Map_C_Enumerator_Name
(S, Custom_Parent => Current_Device, Entity => False)),
Op_Equal,
(Make_Literal
(CV.New_Int_Value (Task_Identifier, 0, 10))));
Append_Node_To_List
(N, Tasks_Enumerator_List);
Task_Identifier := Task_Identifier + 1;
end if;
-- Get the Process parent of the thread
P := Parent_Component (S);
pragma Assert (AAU.Is_Process (P));
if Current_Device /= No_Node then
P := Current_Device;
else
P := Parent_Component (S);
end if;
N := Make_Defining_Identifier
(Map_C_Enumerator_Name
......
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