Commit 451b4bc5 authored by julien.delange's avatar julien.delange
Browse files

improve thread support, generate operations, transactions



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@1351 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 093d03aa
......@@ -31,6 +31,8 @@
-- --
------------------------------------------------------------------------------
with Namet; use Namet;
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
......@@ -184,15 +186,79 @@ package body Ocarina.Backends.MAST.Main is
------------------
procedure Visit_Thread (E : Node_Id) is
S : Node_Id;
N : Node_Id;
S : Node_Id;
N : Node_Id;
Activation_Event : Node_Id;
Activation_Kind : Event_Kind := Regular;
Activation_Event_Name : Name_Id;
Output_Event : Node_Id;
Output_Event_Name : Name_Id;
Event_Handler : Node_Id;
Server_Sched_Name : Name_Id;
Operation_Name : Name_Id;
Operation : Node_Id;
begin
Set_Str_To_Name_Buffer ("");
Get_Name_String (Normalize_Name (Name (Identifier (E))));
Add_Str_To_Name_Buffer ("_operations");
Operation_Name := Name_Find;
Set_Str_To_Name_Buffer ("");
Get_Name_String (Normalize_Name (Name (Identifier (E))));
Add_Str_To_Name_Buffer ("_sched_server");
Server_Sched_Name := Name_Find;
N := Make_Scheduling_Server
(Normalize_Name (Name (Identifier (E))),
(Server_Sched_Name,
Normalize_Name (Name (Identifier (Get_Bound_Processor
(Parent_Component (Parent_Subcomponent (E)))))));
Append_Node_To_List (N, MTN.Declarations (MAST_File));
N := Make_Transaction
(Normalize_Name (Name (Identifier (E))), Regular);
Append_Node_To_List (N, MTN.Declarations (MAST_File));
Set_Str_To_Name_Buffer ("");
Get_Name_String (Normalize_Name (Name (Identifier (E))));
Add_Str_To_Name_Buffer ("_activation_event");
Activation_Event_Name := Name_Find;
if Get_Thread_Dispatch_Protocol (E) = Thread_Periodic then
Activation_Kind := Periodic;
elsif Get_Thread_Dispatch_Protocol (E) = Thread_Sporadic then
Activation_Kind := Sporadic;
else
Activation_Kind := Regular;
end if;
Activation_Event := Make_Event (Activation_Event_Name, Activation_Kind);
Append_Node_To_List
(Activation_Event, MTN.External_Events (N));
Set_Str_To_Name_Buffer ("");
Get_Name_String (Normalize_Name (Name (Identifier (E))));
Add_Str_To_Name_Buffer ("_output_event");
Output_Event_Name := Name_Find;
Output_Event := Make_Event (Output_Event_Name, Regular);
Append_Node_To_List
(Output_Event, MTN.Internal_Events (N));
Event_Handler := Make_Event_Handler
(Activity,
Activation_Event_Name,
Output_Event_Name,
Operation_Name,
Server_Sched_Name);
Append_Node_To_List
(Event_Handler, MTN.Event_Handlers (N));
Operation := Make_Operation (Operation_Name, Enclosing);
Append_Node_To_List (Operation, MTN.Declarations (MAST_File));
if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
......
......@@ -58,6 +58,10 @@ package body Ocarina.Backends.MAST_Tree.Generator is
procedure Generate_MAST_File (N : Node_Id);
procedure Generate_Processing_Resource (N : Node_Id);
procedure Generate_Scheduling_Server (N : Node_Id);
procedure Generate_Transaction (N : Node_Id);
procedure Generate_Event (N : Node_Id);
procedure Generate_Event_Handler (N : Node_Id);
procedure Generate_Operation (N : Node_Id);
procedure Write (T : Token_Type);
procedure Write_Line (T : Token_Type);
......@@ -156,12 +160,24 @@ package body Ocarina.Backends.MAST_Tree.Generator is
when K_Literal =>
Generate_Literal (N);
when K_Event =>
Generate_Event (N);
when K_Event_Handler =>
Generate_Event_Handler (N);
when K_Processing_Resource =>
Generate_Processing_Resource (N);
when K_Scheduling_Server =>
Generate_Scheduling_Server (N);
when K_Transaction =>
Generate_Transaction (N);
when K_Operation =>
Generate_Operation (N);
when others =>
Display_Error ("other element in generator", Fatal => False);
null;
......@@ -331,4 +347,256 @@ package body Ocarina.Backends.MAST_Tree.Generator is
Write_Line (");");
end Generate_Scheduling_Server;
--------------------------
-- Generate_Transaction --
--------------------------
procedure Generate_Transaction (N : Node_Id) is
F : Node_Id;
begin
Write_Line ("Transaction (");
Increment_Indentation;
Write_Indentation (-1);
if Is_Regular (N) then
Write_Line ("Type => Regular,");
elsif Is_Sporadic (N) then
Write_Line ("Type => Sporadic,");
else
Write_Line ("Type => Periodic,");
end if;
if not Is_Empty (External_Events (N))then
Write_Indentation (-1);
Write (Tok_External_Events);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write_Line (Tok_Left_Paren);
Increment_Indentation;
F := First_Node (External_Events (N));
while Present (F) loop
Write_Indentation (-1);
Generate (F);
if Present (Next_Node (F)) then
Write_Eol;
else
Write (Tok_Right_Paren);
Write_Line (Tok_Colon);
end if;
F := Next_Node (F);
end loop;
Decrement_Indentation;
end if;
if not Is_Empty (Internal_Events (N))then
Write_Indentation (-1);
Write (Tok_Internal_Events);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write_Line (Tok_Left_Paren);
Increment_Indentation;
F := First_Node (Internal_Events (N));
while Present (F) loop
Write_Indentation (-1);
Generate (F);
if Present (Next_Node (F)) then
Write_Eol;
else
Write (Tok_Right_Paren);
Write_Line (Tok_Colon);
end if;
F := Next_Node (F);
end loop;
Decrement_Indentation;
end if;
if not Is_Empty (Event_Handlers (N))then
Write_Indentation (-1);
Write (Tok_Event_Handlers);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write_Line (Tok_Left_Paren);
Increment_Indentation;
F := First_Node (Event_Handlers (N));
while Present (F) loop
Write_Indentation (-1);
Generate (F);
if Present (Next_Node (F)) then
Write_Eol;
else
Write (Tok_Right_Paren);
Write_Line (Tok_Colon);
end if;
F := Next_Node (F);
end loop;
Decrement_Indentation;
end if;
Write_Indentation (-1);
Write_Str ("Name => ");
Write_Name (Node_Name (N));
Write_Line (");");
end Generate_Transaction;
--------------------
-- Generate_Event --
--------------------
procedure Generate_Event (N : Node_Id) is
begin
Write (Tok_Left_Paren);
Write (Tok_Type);
Write_Space;
Write (Tok_Assign);
Write_Space;
if Is_Periodic (N) then
Write_Str ("periodic");
elsif Is_Sporadic (N) then
Write_Str ("sporadic");
else
Write_Str ("regular");
end if;
Write_Line (Tok_Colon);
if Timing_Requirements (N) /= No_Node then
Write_Indentation (-1);
Write (Tok_Timing_Requirements);
Write_Space;
Write (Tok_Assign);
Write_Space;
Generate (Timing_Requirements (N));
Write_Line (Tok_Colon);
end if;
Write_Indentation (-1);
Write (Tok_Name);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write_Name (Node_Name (N));
Write (Tok_Right_Paren);
end Generate_Event;
----------------------------
-- Generate_Event_Handler --
----------------------------
procedure Generate_Event_Handler (N : Node_Id) is
begin
Write (Tok_Left_Paren);
Write (Tok_Type);
Write_Space;
Write (Tok_Assign);
Write_Space;
if Is_Activity (N) then
Write_Str ("activity");
else
Write_Str ("unknown");
end if;
Write_Line (Tok_Colon);
Write_Indentation (-1);
Write (Tok_Output_Event);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write_Name (Output_Name (N));
Write_Line (Tok_Colon);
Write_Indentation (-1);
Write (Tok_Activity_Operation);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write_Name (Operation_Name (N));
Write_Line (Tok_Colon);
Write_Indentation (-1);
Write (Tok_Activity_Server);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write_Name (Server_Name (N));
Write_Line (Tok_Colon);
Write_Indentation (-1);
Write (Tok_Input_Event);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write_Name (Input_Name (N));
Write (Tok_Right_Paren);
end Generate_Event_Handler;
------------------------
-- Generate_Operation --
------------------------
procedure Generate_Operation (N : Node_Id) is
begin
Write_Line ("Operation (");
Increment_Indentation;
Write_Indentation (-1);
if Is_Simple (N) then
Write_Line ("Type => Simple,");
elsif Is_Composite (N) then
Write_Line ("Type => Composite,");
else
Write_Line ("Type => Enclosing,");
end if;
if Worst_Case_Execution_Time (N) /= No_Node then
Write_Indentation (-1);
Write (Tok_Worst_Case_Execution_Time);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write (Tok_Left_Paren);
Generate (Worst_Case_Execution_Time (N));
Write (Tok_Right_Paren);
Write_Line (Tok_Colon);
end if;
if Avg_Case_Execution_Time (N) /= No_Node then
Write_Indentation (-1);
Write (Tok_Avg_Case_Execution_Time);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write (Tok_Left_Paren);
Generate (Avg_Case_Execution_Time (N));
Write (Tok_Right_Paren);
Write_Line (Tok_Colon);
end if;
if Best_Case_Execution_Time (N) /= No_Node then
Write_Indentation (-1);
Write (Tok_Best_Case_Execution_Time);
Write_Space;
Write (Tok_Assign);
Write_Space;
Write (Tok_Left_Paren);
Generate (Best_Case_Execution_Time (N));
Write (Tok_Right_Paren);
Write_Line (Tok_Colon);
end if;
Write_Indentation (-1);
Write_Str ("Name => ");
Write_Name (Node_Name (N));
Write_Line (");");
end Generate_Operation;
end Ocarina.Backends.MAST_Tree.Generator;
......@@ -50,15 +50,6 @@ module Ocarina::Backends::MAST_Tree::Nodes {
boolean Is_Preassigned;
};
interface Operation : MAST_Node {
boolean Is_Simple;
boolean Is_Enclosing;
boolean Is_Composite;
Node_Id Worst_Case_Execution_Time;
Node_Id Best_Case_Execution_Time;
Node_Id Avg_Case_Execution_Time;
};
interface Scheduler : MAST_Node
{
Name_Id Host;
......@@ -83,11 +74,45 @@ module Ocarina::Backends::MAST_Tree::Nodes {
Node_Id Last_Node;
};
interface Operation : MAST_Node {
boolean Is_Simple;
boolean Is_Enclosing;
boolean Is_Composite;
List_Id Operations;
Node_Id Worst_Case_Execution_Time;
Node_Id Best_Case_Execution_Time;
Node_Id Avg_Case_Execution_Time;
};
interface Transaction : MAST_Node {
boolean Is_Regular;
List_Id External_Events;
List_Id Internal_Events;
List_Id Events_Handlers;
List_Id Event_Handlers;
};
interface Event : MAST_Node {
boolean Is_Regular;
boolean Is_Sporadic;
boolean Is_Periodic;
Node_Id Timing_Requirements;
Node_Id Min_Interarrival;
};
interface Event_Timing_Requirements : Node_Id {
boolean Is_Hard_Deadline;
Node_Id Deadline;
Name_Id Referenced_Event;
};
interface Event_Handler : Node_Id {
boolean Is_Activity;
Name_Id Input_Name;
Name_Id Output_Name;
Name_Id Operation_Name;
Name_Id Server_Name;
};
interface Defining_Identifier : Node_Id {
......
......@@ -563,4 +563,116 @@ package body Ocarina.Backends.MAST_Tree.Nutils is
return N;
end Make_Scheduling_Server;
----------------------
-- Make_Transaction --
----------------------
function Make_Transaction
(Trans_Name : Name_Id;
Trans_Type : Transaction_Kind)
return Node_Id is
N : Node_Id;
begin
N := New_Node (MTN.K_Transaction);
MTN.Set_Node_Name (N, Trans_Name);
if Trans_Type = Regular then
MTN.Set_Is_Regular (N, True);
end if;
MTN.Set_External_Events (N, New_List (MTN.K_List_Id));
MTN.Set_Internal_Events (N, New_List (MTN.K_List_Id));
MTN.Set_Event_Handlers (N, New_List (MTN.K_List_Id));
return N;
end Make_Transaction;
----------------
-- Make_Event --
----------------
function Make_Event
(E_Name : Name_Id;
E_Kind : Event_Kind) return Node_Id is
N : Node_Id;
begin
N := New_Node (MTN.K_Event);
MTN.Set_Node_Name (N, E_Name);
MTN.Set_Timing_Requirements (N, No_Node);
MTN.Set_Is_Regular (N, False);
MTN.Set_Is_Periodic (N, False);
MTN.Set_Is_Sporadic (N, False);
if E_Kind = Regular then
MTN.Set_Is_Regular (N, True);
elsif E_Kind = Sporadic then
MTN.Set_Is_Sporadic (N, True);
else
MTN.Set_Is_Periodic (N, True);
end if;
return N;
end Make_Event;
------------------------
-- Make_Event_Handler --
------------------------
function Make_Event_Handler
(Kind : Event_Handler_Kind;
Input_Event : Name_Id;
Output_Event : Name_Id;
Operation : Name_Id;
Server : Name_Id) return Node_Id is
N : Node_Id;
begin
N := New_Node (MTN.K_Event_Handler);
if Kind = Activity then
MTN.Set_Is_Activity (N, True);
end if;
MTN.Set_Input_Name (N, Input_Event);
MTN.Set_Output_Name (N, Output_Event);
MTN.Set_Operation_Name (N, Operation);
MTN.Set_Server_Name (N, Server);
return N;
end Make_Event_Handler;
--------------------
-- Make_Operation --
--------------------
function Make_Operation
(Op_Name : Name_Id;
Op_Kind : Operation_Kind;
Op_List : List_Id := No_List)
return Node_Id is
N : Node_Id;
begin
N := New_Node (MTN.K_Operation);
MTN.Set_Node_Name (N, Op_Name);
if Op_List /= No_List then
MTN.Set_Operations (N, Op_List);
end if;
MTN.Set_Is_Enclosing (N, False);
MTN.Set_Is_Composite (N, False);
MTN.Set_Is_Simple (N, False);
if Op_Kind = Enclosing then
MTN.Set_Is_Enclosing (N, True);
elsif Op_Kind = Composite then
MTN.Set_Is_Composite (N, True);
else
MTN.Set_Is_Simple (N, True);
end if;
MTN.Set_Worst_Case_Execution_Time (N, No_Node);
MTN.Set_Best_Case_Execution_Time (N, No_Node);
MTN.Set_Avg_Case_Execution_Time (N, No_Node);
return N;
end Make_Operation;
end Ocarina.Backends.MAST_Tree.Nutils;
......@@ -50,13 +50,19 @@ package Ocarina.Backends.MAST_Tree.Nutils is
-- Token name Token type
-- Keywords
Tok_First_Keyword,
Tok_Activity_Operation,
Tok_Activity_Server,
Tok_Avg_Case_Execution_Time,
Tok_Avg_Context_Switch,
Tok_Avg_ISR_Switch,
Tok_Best_Case_Execution_time,
Tok_Best_Context_Switch,
Tok_Best_ISR_Switch,
Tok_Event_Handlers,
Tok_External_Events,
Tok_Host,
Tok_Internal_Events,
Tok_Input_Event,
Tok_List_Of_Drivers,
Tok_Max_Blocking,
Tok_Max_Packet_Size,
......@@ -65,6 +71,7 @@ package Ocarina.Backends.MAST_Tree.Nutils is
Tok_Min_Packet_Size,
Tok_Min_Priority,
Tok_Name,
Tok_Output_Event,
Tok_Packet_Server,
Tok_Packet_Send_Operation,
Tok_Packet_Receive_Operation,
......@@ -77,6 +84,7 @@ package Ocarina.Backends.MAST_Tree.Nutils is
Tok_Server_Sched_Parameters,
Tok_Speed_Factor,
Tok_Throughput,
Tok_Timing_Requirements,
Tok_Type,
Tok_Worst_Case_Execution_Time,
Tok_Worst_Context_Switch,
......@@ -189,4 +197,38 @@ package Ocarina.Backends.MAST_Tree.Nutils is
Associated_Processor : Name_Id)
return Node_Id;
type Event_Kind is
(Periodic,