Commit 23c99ceb authored by hana's avatar hana

Update of LNT processor generation.

parent f4386e25
......@@ -756,7 +756,7 @@ package body Ocarina.Backends.Lnt.Components is
(Defining_Identifier : Node_Id;
Actual_Gates : List_Id := No_List;
Actual_Parameters : List_Id := No_List;
Is_Sporadic : boolean := false)
Is_Not_Periodic : Boolean := false)
return Node_Id
is
pragma Assert (Defining_Identifier /= No_Node);
......@@ -766,7 +766,7 @@ package body Ocarina.Backends.Lnt.Components is
Set_Identifier (N, Defining_Identifier);
Set_Actual_Gates (N, Actual_Gates);
Set_Actual_Parameters (N, Actual_Parameters);
Set_Is_Sporadic (N, Is_Sporadic);
Set_Is_Not_Periodic (N, Is_Not_Periodic);
return N;
end Make_Process_Instantiation_Statement;
......@@ -899,17 +899,21 @@ package body Ocarina.Backends.Lnt.Components is
---------------------------
function Make_Var_Loop_Select (Var_Dec : List_Id;
Out_Loop : List_Id;
In_Select : List_Id)
In_Select : List_Id;
With_Select : Boolean := true)
return Node_Id is
N : Node_Id;
N_Loop : Node_Id;
L_Var : List_Id;
begin
L_Var := Out_Loop;
N_Loop := Make_Loop_Statement
(New_List (Make_Select_Statement (In_Select)));
if With_Select then
N_Loop := Make_Loop_Statement
(New_List (Make_Select_Statement (In_Select)));
else
N_Loop := Make_Loop_Statement (In_Select);
end if;
Append_Node_To_List (N_Loop, L_Var);
N := Make_Var_Statement (Var_Dec, L_Var);
return N;
end Make_Var_Loop_Select;
......
......@@ -244,7 +244,7 @@ package Ocarina.Backends.Lnt.Components is
(Defining_Identifier : Node_Id;
Actual_Gates : List_Id := No_List;
Actual_Parameters : List_Id := No_List;
Is_Sporadic : boolean := false)
Is_Not_Periodic : Boolean := false)
return Node_Id;
function Make_Communication_Statement
......@@ -290,6 +290,7 @@ package Ocarina.Backends.Lnt.Components is
function Make_Var_Loop_Select (Var_Dec : List_Id;
Out_Loop : List_Id;
In_Select : List_Id)
In_Select : List_Id;
With_Select : Boolean := true)
return Node_Id;
end Ocarina.Backends.Lnt.Components;
......@@ -50,7 +50,7 @@ package body Ocarina.Backends.LNT.Tree_Generator is
procedure Get_N_Thread (Sys : Node_Id;
Thread_Number : in out Natural;
Sporadic_Thread_Number : in out Natural) is
Not_Periodic_Thread_Number : in out Natural) is
Sys_N : Node_Id;
Proc : Node_Id;
Proc_N : Node_Id;
......@@ -64,7 +64,7 @@ package body Ocarina.Backends.LNT.Tree_Generator is
if Get_Category_Of_Component (Proc) = CC_System then
Get_N_Thread (Proc,
Thread_Number,
Sporadic_Thread_Number);
Not_Periodic_Thread_Number);
end if;
if Get_Category_Of_Component (Proc) = CC_Process then
if not AINU.Is_Empty (Subcomponents (Proc)) then
......@@ -73,11 +73,11 @@ package body Ocarina.Backends.LNT.Tree_Generator is
Thr := Corresponding_Instance (Proc_N);
if Get_Category_Of_Component (Thr) = CC_Thread then
Thread_Number := Thread_Number + 1;
if (Get_Thread_Dispatch_Protocol (Thr) =
Thread_Sporadic)
if (Get_Thread_Dispatch_Protocol (Thr)
/= Thread_Periodic)
then
Sporadic_Thread_Number :=
Sporadic_Thread_Number + 1;
Not_Periodic_Thread_Number :=
Not_Periodic_Thread_Number + 1;
end if;
end if;
Proc_N := AIN.Next_Node (Proc_N);
......
......@@ -33,6 +33,6 @@ package Ocarina.Backends.LNT.Tree_Generator is
procedure Get_N_Thread (Sys : Node_Id;
Thread_Number : in out Natural;
Sporadic_Thread_Number : in out Natural);
Not_Periodic_Thread_Number : in out Natural);
end Ocarina.Backends.LNT.Tree_Generator;
......@@ -78,8 +78,8 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
procedure Find_Instance_By_Name (Key : Name_Id; Target : List_Id;
Instance : out Node_Id; Index : out Natural;
Is_Sporadic : out boolean);
function Is_Sporadic (Index : Natural; Target : List_Id)
Is_Not_Periodic : out boolean);
function Is_Not_Periodic (Index : Natural; Target : List_Id)
return boolean;
procedure Make_Process_Main;
......@@ -114,7 +114,6 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
L := Sources (S);
-- port_out thread, first connection 1-1
N_Connection := AIN.Item (AIN.First_Node (L));
while (AIN.Is_In (N_Connection)) loop
L := Sources (N_Connection);
N_Connection := AIN.Item (AIN.First_Node (L));
......@@ -155,6 +154,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
Connection);
end if;
-- Put_Line (Image (Connection));
return Connection;
end Make_Gate_Identifier;
......@@ -272,7 +272,13 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
S := AIN.Next_Node (S);
end loop;
end if;
if not AINU.Is_Empty (Connections (E)) then
S := AIN.First_Node (Connections (E));
while Present (S) loop
Put_Line (Image (AIN.Display_Name (AIN.Identifier (S))));
S := AIN.Next_Node (S);
end loop;
end if;
end Visit_System_Instance;
----------------------------
......@@ -457,7 +463,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
Aux_N_Port_4 : Node_Id;
N_Send : Name_Id;
Connection : Name_Id;
Is_Sporadic : boolean := false;
Is_Not_Periodic : boolean := false;
Thread_Identifier : constant Name_Id
:= New_Identifier (AIN.Display_Name
(AIN.Identifier (E)), "Thread_");
......@@ -468,7 +474,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
LNT_Thread_Instance_List,
Thread_Instance,
Index,
Is_Sporadic);
Is_Not_Periodic);
N_Activation := New_Identifier (
Remove_Prefix_From_Name (
......@@ -484,7 +490,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
Make_Gate_Declaration (
Make_Identifier ("LNT_Channel_Dispatch"),
Aux_N_Activation_2));
if Is_Sporadic then
if Is_Not_Periodic then
N_Event := New_Identifier (
Remove_Prefix_From_Name (
" ", Get_String_Name (Integer'Image (Index))),
......@@ -551,7 +557,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
No_List);
elsif AIN.Is_Event (S) then
-- event port
if Is_Sporadic then
if Is_Not_Periodic then
Aux_N_Event := BLNu.Make_Node_Container (N_Event);
Port_Gates_List := New_List (
Make_Identifier (N_SEND), -- SEND_
......@@ -635,7 +641,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
" ", Get_String_Name (Integer'Image (I))),
"ACTIVATION_");
BLNu.Append_Node_To_List (N_Activation, Processor_Gates_List);
if (Is_Sporadic (I, LNT_Thread_Instance_List)) then
if (Is_Not_Periodic (I, LNT_Thread_Instance_List)) then
N_Activation := New_Identifier (
Remove_Prefix_From_Name (
" ", Get_String_Name (Integer'Image (I))),
......@@ -668,7 +674,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
procedure Find_Instance_By_Name (Key : Name_Id; Target : List_Id;
Instance : out Node_Id;
Index : out Natural;
Is_Sporadic : out boolean)
Is_Not_Periodic : out boolean)
is
N : Node_Id;
Counter : Natural := 1;
......@@ -682,7 +688,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
if ((BLN.Name (BLN.Identifier (N)) = Key and then
BLNu.Is_Empty (Actual_Gates (N))))
then
Is_Sporadic := BLN.Is_Sporadic (N);
Is_Not_Periodic := BLN.Is_Not_Periodic (N);
Instance := N;
Index := Counter;
exit;
......@@ -693,7 +699,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
end if;
end Find_Instance_By_Name;
function Is_Sporadic (Index : Natural; Target : List_Id)
function Is_Not_Periodic (Index : Natural; Target : List_Id)
return boolean is
N : Node_Id;
Counter : Natural := 1;
......@@ -705,13 +711,13 @@ package body Ocarina.Backends.LNT.Tree_Generator_Main is
while Present (N) loop
if (Counter = Index) then
return BLN.Is_Sporadic (N);
return BLN.Is_Not_Periodic (N);
end if;
N := BLN.Next_Node (N);
Counter := Counter + 1;
end loop;
end if;
return false;
end Is_Sporadic;
end Is_Not_Periodic;
end Ocarina.Backends.LNT.Tree_Generator_Main;
......@@ -271,7 +271,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Port is
Definitions_List := New_List;
Add_LNT_Data_Port (Definitions_List);
Add_LNT_Event_Port (Definitions_List, false);
if (Sporadic_Thread_Number > 0) then
if (Not_Periodic_Thread_Number > 0) then
Add_LNT_Event_Port (Definitions_List, true);
end if;
......
......@@ -226,25 +226,28 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
Period : Natural;
Thread_Identifier : constant Name_Id
:= AIN.Display_Name (AIN.Identifier (E));
Dispatch : constant Supported_Thread_Dispatch_Protocol :=
Get_Thread_Dispatch_Protocol (E);
begin
Th.Identifier := New_Identifier (Thread_Identifier, "Thread_");
if (((Get_Thread_Dispatch_Protocol (E) = Thread_Periodic) or else
(Get_Thread_Dispatch_Protocol (E) = Thread_Sporadic)) and then
if (((Dispatch = Thread_Periodic) or else
(Dispatch = Thread_Sporadic) or else
(Dispatch = Thread_Timed) or else
(Dispatch = Thread_Hybrid)) and then
(Get_Execution_Time (E) /= Empty_Time_Array))
then
Period := Natural (Get_Thread_Period (E).T);
Th.Period := Period;
Th.Capacity := Natural (Get_Execution_Time (E)(1).T);
if (Get_Thread_Dispatch_Protocol (E) = Thread_Sporadic) then
Th.Is_Sporadic := true;
end if;
Th.Dispatch_Protocol := Dispatch;
T (Counter) := Th;
P (Counter) := Period;
Counter := Counter + 1;
else
Display_Located_Error (AIN.Loc (E),
"LNT generation requires the definition " &
"of Dispatch_Protocol (Periodic or Sporadic), " &
"of Dispatch_Protocol (Periodic, Sporadic," &
" Timed or Hybrid), " &
"Execution_Time and Period properties.",
Fatal => True);
end if;
......@@ -257,19 +260,22 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
N : Node_Id;
N_Sort : Node_Id;
L_While : List_Id;
L_Elsif_Then : List_Id;
L_Else_Running_State : List_Id;
N_Act : Node_Id;
N_Event : Node_Id;
Aux_Act_1 : Node_Id;
Aux_Act_2 : Node_Id;
Is_Not_Periodic : Boolean := true;
Threads : Thread_Array := T;
L_Processor_Gates : List_Id;
L_Thread_Activation : List_Id;
L_Threads_Array : List_Id;
L_In_Select : List_Id;
L_Stop_Orders : List_Id;
L_Incoming_Event : List_Id;
L_Thread_Activation : List_Id;
N_Ready_State : Node_Id;
Thread_Activation : Node_Id;
Aux_Thread_Activation : Node_Id;
L_In_Then : List_Id;
function Make_Var_declaration_List return List_Id;
function Make_Var_declaration_List
......@@ -295,7 +301,7 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
(Make_Identifier ("k"),
Make_Identifier ("Nat")), N_Var_Declarations);
if (Sporadic_Thread_Number > 0) then
if (Not_Periodic_Thread_Number > 0) then
BLNu.Append_Node_To_List (Make_Var_Declaration
(Make_Identifier ("Is_Activated"),
Make_Identifier ("bool")), N_Var_Declarations);
......@@ -321,8 +327,8 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
Quick_Sort_Threads (Threads);
L_Processor_Gates := New_List;
L_Stop_Orders := New_List;
L_Thread_Activation := New_List;
L_Stop_Orders := New_List;
L_Incoming_Event := New_List;
L_Threads_Array := New_List (
......@@ -338,14 +344,9 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
Make_Constructed_Pattern (
Make_Identifier ("LNT_Type_Thread"),
New_List (Make_Time_Const (0)))))));
for I in Threads'Range loop
-- instances list for Main generation
BLNu.Append_Node_To_List (
Make_Process_Instantiation_Statement (
Make_Identifier (Threads (I).Identifier),
No_List, No_List, Threads (I).Is_Sporadic),
LNT_Thread_Instance_List);
for I in Threads'Range loop
-- ACTIVATION_I identifier
N_Act := New_Identifier (
Remove_Prefix_From_Name (
" ", Get_String_Name (Integer'Image (I))),
......@@ -360,32 +361,8 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
N_Act),
L_Processor_Gates);
if (Threads (I).Is_Sporadic) then
N_Event := New_Identifier (
Remove_Prefix_From_Name (
" ", Get_String_Name (Integer'Image (I))),
"INCOMING_EVENT_");
BLNu.Append_Node_To_List (
Make_Gate_Declaration (
Make_Identifier ("LNT_Channel_Event"),
N_Event),
L_Processor_Gates);
BLNu.Append_Node_To_List (
Make_Process_Instantiation_Statement
(Make_Identifier ("Sporadic_Notif"),
New_List (N_Event),
New_List (
Make_Actual_Parameter
(Make_Identifier ("Threads"), false, true),
Make_Actual_Parameter
(Make_Identifier (Integer'Image (I))),
Make_Actual_Parameter
(Make_Identifier ("Counter")),
Make_Actual_Parameter
(Make_Identifier ("Is_Activated"), false, true))),
L_Incoming_Event);
end if;
BLNu.Append_Node_To_List (Aux_Act_2,
L_Thread_Activation);
BLNu.Append_Node_To_List (
Make_Communication_Statement
......@@ -393,28 +370,44 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
false, No_Node),
L_Stop_Orders);
BLNu.Append_Node_To_List (
Make_Process_Instantiation_Statement
(Make_Identifier ("Thread_Activation"),
New_List (Aux_Act_2),
New_List (
Make_Actual_Parameter
(Make_Identifier ("Threads"), false, true),
Make_Actual_Parameter
(Make_Identifier (Integer'Image (I))))),
L_Thread_Activation);
-- ---------------------------------------------
-- Thread ([0][1][2][3][4][5][6][7][8][9][10][11])
-- Thread ([C][P][0][1][0][P][0][0][0][1][1 ][0 ]) P
-- Thread ([C][P][0][0][0][P][0][0][0][1][0 ][1 ]) S
-- Thread ([C][P][0][0][0][P][0][0][0][1][1 ][2 ]) T
-- Thread ([C][P][0][0][0][P][0][0][0][1][1 ][3 ]) H
-- ---------------------------------------------
if (Threads (I).Is_Sporadic) then
BLNu.Append_Node_To_List (
Make_Array_Element_Assignment_Statement
(Make_Identifier ("Threads"),
Make_Identifier (Integer'Image (I)),
Make_Constructed_Pattern
(Make_Identifier ("LNT_Type_Thread"),
case Threads (I).Dispatch_Protocol is
when Thread_Periodic =>
Is_Not_Periodic := false;
BLNu.Append_Node_To_List (
Make_Array_Element_Assignment_Statement
(Make_Identifier ("Threads"),
Make_Identifier (Integer'Image (I)),
Make_Constructed_Pattern
(Make_Identifier ("LNT_Type_Thread"),
New_List (
Make_Time_Const (Threads (I).Capacity),
Make_Time_Const (Threads (I).Period),
Make_Time_Const (0),
Make_Time_Const (1),
Make_Time_Const (0),
Make_Time_Const (Threads (I).Period),
Make_Time_Const (0),
Make_Time_Const (0),
Make_Time_Const (0),
Make_Time_Const (1),
Make_Time_Const (1),
Make_Time_Const (0)))),
L_Threads_Array);
when Thread_Sporadic =>
BLNu.Append_Node_To_List (
Make_Array_Element_Assignment_Statement
(Make_Identifier ("Threads"),
Make_Identifier (Integer'Image (I)),
Make_Constructed_Pattern
(Make_Identifier ("LNT_Type_Thread"),
New_List (
Make_Time_Const (Threads (I).Capacity),
Make_Time_Const (Threads (I).Period),
......@@ -428,14 +421,85 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
Make_Time_Const (1),
Make_Time_Const (0),
Make_Time_Const (1)))),
L_Threads_Array);
else
BLNu.Append_Node_To_List (
Make_Array_Element_Assignment_Statement
(Make_Identifier ("Threads"),
Make_Identifier (Integer'Image (I)),
Make_Constructed_Pattern
(Make_Identifier ("LNT_Type_Thread"),
L_Threads_Array);
N_Event := New_Identifier (
Remove_Prefix_From_Name (
" ", Get_String_Name (Integer'Image (I))),
"INCOMING_EVENT_");
BLNu.Append_Node_To_List (
Make_Gate_Declaration (
Make_Identifier ("LNT_Channel_Event"),
N_Event),
L_Processor_Gates);
BLNu.Append_Node_To_List (
Make_Process_Instantiation_Statement
(Make_Identifier ("Sporadic_Notif"),
New_List (N_Event),
New_List (
Make_Actual_Parameter
(Make_Identifier ("Threads"), false, true),
Make_Actual_Parameter
(Make_Identifier (Integer'Image (I))),
Make_Actual_Parameter
(Make_Identifier ("Counter")),
Make_Actual_Parameter
(Make_Identifier ("Is_Activated"), false, true))),
L_Incoming_Event);
when Thread_Timed =>
BLNu.Append_Node_To_List (
Make_Array_Element_Assignment_Statement
(Make_Identifier ("Threads"),
Make_Identifier (Integer'Image (I)),
Make_Constructed_Pattern
(Make_Identifier ("LNT_Type_Thread"),
New_List (
Make_Time_Const (Threads (I).Capacity),
Make_Time_Const (Threads (I).Period),
Make_Time_Const (0),
Make_Time_Const (0),
Make_Time_Const (0),
Make_Time_Const (Threads (I).Period),
Make_Time_Const (0),
Make_Time_Const (0),
Make_Time_Const (0),
Make_Time_Const (1),
Make_Time_Const (1),
Make_Time_Const (2)))),
L_Threads_Array);
N_Event := New_Identifier (
Remove_Prefix_From_Name (
" ", Get_String_Name (Integer'Image (I))),
"INCOMING_EVENT_");
BLNu.Append_Node_To_List (
Make_Gate_Declaration (
Make_Identifier ("LNT_Channel_Event"),
N_Event),
L_Processor_Gates);
BLNu.Append_Node_To_List (
Make_Process_Instantiation_Statement
(Make_Identifier ("Timed_Hybrid_Notif"),
New_List (N_Event),
New_List (
Make_Actual_Parameter
(Make_Identifier ("Threads"), false, true),
Make_Actual_Parameter
(Make_Identifier (Integer'Image (I))),
Make_Actual_Parameter
(Make_Identifier ("Counter")),
Make_Actual_Parameter
(Make_Identifier ("Is_Activated"), false, true))),
L_Incoming_Event);
when Thread_Hybrid =>
BLNu.Append_Node_To_List (
Make_Array_Element_Assignment_Statement
(Make_Identifier ("Threads"),
Make_Identifier (Integer'Image (I)),
Make_Constructed_Pattern
(Make_Identifier ("LNT_Type_Thread"),
New_List (
Make_Time_Const (Threads (I).Capacity),
Make_Time_Const (Threads (I).Period),
......@@ -448,12 +512,56 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
Make_Time_Const (0),
Make_Time_Const (1),
Make_Time_Const (1),
Make_Time_Const (0)))),
L_Threads_Array);
end if;
Make_Time_Const (3)))),
L_Threads_Array);
N_Event := New_Identifier (
Remove_Prefix_From_Name (
" ", Get_String_Name (Integer'Image (I))),
"INCOMING_EVENT_");
BLNu.Append_Node_To_List (
Make_Gate_Declaration (
Make_Identifier ("LNT_Channel_Event"),
N_Event),
L_Processor_Gates);
BLNu.Append_Node_To_List (
Make_Process_Instantiation_Statement
(Make_Identifier ("Timed_Hybrid_Notif"),
New_List (N_Event),
New_List (
Make_Actual_Parameter
(Make_Identifier ("Threads"), false, true),
Make_Actual_Parameter
(Make_Identifier (Integer'Image (I))),
Make_Actual_Parameter
(Make_Identifier ("Counter")),
Make_Actual_Parameter
(Make_Identifier ("Is_Activated"), false, true))),
L_Incoming_Event);
when others =>
null;
end case;
-- instances list for Main generation
BLNu.Append_Node_To_List (
Make_Process_Instantiation_Statement (
Make_Identifier (Threads (I).Identifier),
No_List, No_List, Is_Not_Periodic),
LNT_Thread_Instance_List);
end loop;
Thread_Activation := Make_Process_Instantiation_Statement
(Make_Identifier ("Activate_k"),
L_Thread_Activation,
New_List (
Make_Actual_Parameter
(Make_Identifier ("Threads"), false, true),
Make_Actual_Parameter
(Make_Identifier ("k"))));
Aux_Thread_Activation := BLNu.Make_Node_Container (Thread_Activation);
L_Elsif_Then := New_List (
L_Else_Running_State := New_List (
Make_Assignment_Statement (
Make_Identifier ("Preempt"),
Make_Identifier ("true")),
......@@ -576,52 +684,34 @@ package body Ocarina.Backends.LNT.Tree_Generator_Processor is
Make_Identifier ("K"),
Make_Identifier ("TODO")))));
BLNu.Append_List_To_List (L_Thread_Activation, L_Elsif_Then);
if (Sporadic_Thread_Number > 0) then
BLNu.Append_Node_To_List (Make_Assignment_Statement
(Make_Identifier ("Is_Activated"),
Make_Identifier ("false")), L_Elsif_Then);
BLNu.Append_List_To_List (L_Incoming_Event, L_Elsif_Then);
BLNu.Append_Node_To_List (Make_If_Statement
(Make_Identifier ("Is_Activated"),
BLNu.Append_Node_To_List (Aux_Thread_Activation, L_Else_Running_State);
BLNu.Append_Node_To_List (Make_If_Statement
(Make_Identifier ("Preempt"),
New_List (Make_Assignment_Statement
(Make_Identifier ("k"),
Make_Nat (1))),
Make_Identifier ("I"))),
No_List,
New_List (Make_Assignment_Statement
(Make_Identifier ("k"),
Make_Infix_Function_Call_Expression
(Make_Identifier ("+"),
Make_Identifier ("k"),
Make_Nat (1))))), L_Elsif_Then);
end if;
Make_Nat (1))))),
L_Else_Running_State);