Commit 94dfd8fd authored by julien.delange's avatar julien.delange
Browse files

* introduce new functions to handle ASN1 (un)marshallers


git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@708 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 965614e4
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2008-2010, GET-Telecom Paris. --
-- Copyright (C) 2008-2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
......@@ -2832,6 +2832,63 @@ package body Ocarina.Backends.C_Common.Mapping is
return (To_Lower (N));
end Map_Bus_Name;
----------------------------
-- Map_Port_Name_For_Asn1 --
----------------------------
function Map_Port_Name_For_Asn1
(E : Node_Id)
return Name_Id
is
N : Name_Id;
Thread_Name : Name_Id;
Parent_Name : Name_Id;
Containing_Thr : Node_Id;
begin
Containing_Thr := Parent_Subcomponent (Parent_Component (E));
Set_Str_To_Name_Buffer ("thread-");
Parent_Name := Display_Name
(Identifier
(Parent_Subcomponent
(Parent_Component
(Containing_Thr))));
Get_Name_String_And_Append (Parent_Name);
Add_Str_To_Name_Buffer ("-");
Get_Name_String_And_Append
(Display_Name
(Identifier
(Containing_Thr)));
Thread_Name := Name_Find;
Thread_Name := To_Lower (Thread_Name);
Set_Str_To_Name_Buffer ("port-");
Get_Name_String_And_Append (Thread_Name);
Add_Str_To_Name_Buffer ("-");
Get_Name_String_And_Append
(Display_Name (Identifier (E)));
N := Name_Find;
return (To_Lower (N));
end Map_Port_Name_For_Asn1;
------------------------------------
-- Map_Port_Name_Present_For_Asn1 --
------------------------------------
function Map_Port_Name_Present_For_Asn1
(E : Node_Id)
return Name_Id
is
N : Name_Id;
begin
Get_Name_String (Map_Port_Name_For_Asn1 (E));
Add_Str_To_Name_Buffer ("_PRESENT");
N := Name_Find;
N := Replace_Char (N, '-', '_');
return (Name_Find);
end Map_Port_Name_Present_For_Asn1;
--------------------------------------
-- Map_Port_Deployment_Destinations --
--------------------------------------
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 2008-2010, GET-Telecom Paris. --
-- Copyright (C) 2008-2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
......@@ -370,6 +370,14 @@ package Ocarina.Backends.C_Common.Mapping is
-- Returns the type identifier that should be used with a port
-- if this port is associated to virtual bus layers.
function Map_Port_Name_For_Asn1
(E : Node_Id) return Name_Id;
-- Map the name of a port for ASN1 marshalling.
function Map_Port_Name_Present_For_Asn1
(E : Node_Id) return Name_Id;
-- Map the name of a port for ASN1 marshalling.
procedure Handle_Virtual_Buses_Properties (Port : Node_Id);
-- Add properties relevant to virtual buses in the current C file.
-- It declares the following macros in deployment.h:
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 2008-2009, GET-Telecom Paris. --
-- Copyright (C) 2008-2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
......@@ -158,10 +158,12 @@ package Ocarina.Backends.C_Tree.Nutils is
P_Message,
P_Msg,
P_Request,
P_Buffer,
P_Status,
P_Entity,
P_Task,
P_Partition,
P_Pkt,
P_Port,
P_Error,
P_Offset,
......@@ -178,6 +180,8 @@ package Ocarina.Backends.C_Tree.Nutils is
M_Port,
M_Entry,
M_Entry_Point,
M_Kind,
M_Msg,
M_Name,
M_Base_Priority,
M_Priority,
......@@ -213,6 +217,7 @@ package Ocarina.Backends.C_Tree.Nutils is
V_Got_Data,
V_Entity,
V_Port,
V_Pkt,
V_Thread,
V_Error,
V_Error_Status,
......
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2008-2009, GET-Telecom Paris. --
-- Copyright (C) 2008-2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
......@@ -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;
......@@ -65,6 +67,9 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
Marshaller_Request_Spec : Node_Id;
Unmarshaller_Request_Spec : Node_Id;
Marshaller_Asn1_Request_Spec : Node_Id;
Unmarshaller_Asn1_Request_Spec : Node_Id;
-----------------
-- Header_File --
-----------------
......@@ -430,6 +435,60 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
Append_Node_To_List (Unmarshaller_Request_Spec,
CTN.Declarations (Current_File));
if Use_ASN1_Deployment then
-- Make the main marshall_asn1_request function
Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List
(Make_Parameter_Specification
(Defining_Identifier =>
Make_Defining_Identifier (PN (P_Request)),
Parameter_Type =>
Make_Pointer_Type (RE (RE_Request_T))),
Parameters);
Append_Node_To_List
(Make_Parameter_Specification
(Defining_Identifier =>
Make_Defining_Identifier (PN (P_Pkt)),
Parameter_Type =>
Make_Pointer_Type (RE (RE_Asn1_Pkt_T))),
Parameters);
Marshaller_Asn1_Request_Spec := Make_Function_Specification
(Defining_Identifier => RE (RE_Marshall_Asn1_Request),
Parameters => Parameters,
Return_Type => New_Node (CTN.K_Void));
Append_Node_To_List (Marshaller_Asn1_Request_Spec,
CTN.Declarations (Current_File));
-- Make the main unmarshall_request function
Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List
(Make_Parameter_Specification
(Defining_Identifier =>
Make_Defining_Identifier (PN (P_Request)),
Parameter_Type =>
Make_Pointer_Type (RE (RE_Request_T))),
Parameters);
Append_Node_To_List
(Make_Parameter_Specification
(Defining_Identifier =>
Make_Defining_Identifier (PN (P_Pkt)),
Parameter_Type =>
Make_Pointer_Type (RE (RE_Asn1_Pkt_T))),
Parameters);
Unmarshaller_Asn1_Request_Spec := Make_Function_Specification
(Defining_Identifier => RE (RE_Unmarshall_Asn1_Request),
Parameters => Parameters,
Return_Type => New_Node (CTN.K_Void));
Append_Node_To_List (Unmarshaller_Asn1_Request_Spec,
CTN.Declarations (Current_File));
end if;
-- Unmark all the marked types
Reset_Handlings;
......@@ -583,8 +642,10 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
function Get_Marshall_Function_Name (E : Node_Id) return Node_Id;
function Get_Unmarshall_Function_Name (E : Node_Id) return Node_Id;
Marshall_Alternatives : List_Id;
Unmarshall_Alternatives : List_Id;
Asn1_Marshall_Alternatives : List_Id;
Asn1_Unmarshall_Alternatives : List_Id;
Marshall_Alternatives : List_Id;
Unmarshall_Alternatives : List_Id;
-----------------------------
-- Make_Marshall_Type_Body --
......@@ -1125,8 +1186,10 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
Start_Recording_Handlings;
Marshall_Alternatives := New_List (CTN.K_Alternatives_List);
Unmarshall_Alternatives := New_List (CTN.K_Alternatives_List);
Asn1_Marshall_Alternatives := New_List (CTN.K_Alternatives_List);
Asn1_Unmarshall_Alternatives := New_List (CTN.K_Alternatives_List);
Marshall_Alternatives := New_List (CTN.K_Alternatives_List);
Unmarshall_Alternatives := New_List (CTN.K_Alternatives_List);
if not AAU.Is_Empty (Features (E)) then
C := First_Node (Features (E));
......@@ -1312,6 +1375,61 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
-- Unmark all the marked types
if Use_ASN1_Deployment then
if not Is_Empty (Asn1_Marshall_Alternatives) then
N := Make_Switch_Alternative
(No_List, No_List);
Append_Node_To_List (N, Asn1_Marshall_Alternatives);
N := Make_Switch_Statement
(Expression =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_Port)),
Aggregate_Name => Make_Defining_Identifier (VN (V_Request)),
Is_Pointer => True),
Alternatives => Asn1_Marshall_Alternatives);
else
N := Message_Comment
("No alternative was declared");
end if;
N := Make_Function_Implementation
(Marshaller_Asn1_Request_Spec,
No_List,
Make_List_Id (N));
Append_Node_To_List (N, CTN.Declarations (Current_File));
if not Is_Empty (Asn1_Unmarshall_Alternatives) then
N := Make_Switch_Alternative
(No_List, No_List);
Append_Node_To_List (N, Asn1_Unmarshall_Alternatives);
N := Make_Switch_Statement
(Expression =>
Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_Kind)),
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Msg))),
Aggregate_Name => Make_Defining_Identifier (VN (V_Pkt)),
Is_Pointer => True),
Alternatives => Asn1_Unmarshall_Alternatives);
else
N := Message_Comment
("No alternative was declared");
end if;
N := Make_Function_Implementation
(Unmarshaller_Asn1_Request_Spec,
Make_List_Id (N),
No_List);
Append_Node_To_List (N, CTN.Declarations (Current_File));
end if;
Reset_Handlings;
Pop_Entity; -- U
......@@ -1543,6 +1661,8 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
-- Now, add alternatives to the main switches to use
-- our marshallers functions.
-- First, handle the generic marshallers.
Switch_Statements := New_List (CTN.K_Statement_List);
Switch_Labels := New_List (CTN.K_Label_List);
Parameters := New_List (CTN.K_Parameter_List);
......@@ -1577,6 +1697,95 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
(Switch_Labels, Switch_Statements);
Append_Node_To_List (N, Marshall_Alternatives);
-- Then, handle the ASN1 marshallers
Switch_Statements := New_List (CTN.K_Statement_List);
Switch_Labels := New_List (CTN.K_Label_List);
Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List
(Make_Expression
(Left_Expr =>
Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
(Make_Defining_Identifier
(MN (M_Kind))),
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Msg))),
Aggregate_Name =>
Make_Defining_Identifier (VN (V_Pkt)),
Is_Pointer => True),
Operator => Op_Equal,
Right_Expr =>
Make_Defining_Identifier
(Map_Port_Name_Present_For_Asn1 (F),
C_Conversion => False)),
Switch_Statements);
Append_Node_To_List
(Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier
(Get_String_Name ("arr")),
Aggregate_Name =>
(Make_Defining_Identifier
(Map_Port_Name_For_Asn1 (F)))),
Aggregate_Name =>
(Make_Defining_Identifier
(Get_String_Name ("u")))),
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Msg))),
Aggregate_Name =>
Make_Defining_Identifier (VN (V_Pkt)),
Is_Pointer => True),
Parameters);
Append_Node_To_List
(Make_Variable_Address
(Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
(Make_Defining_Identifier
(Map_C_Enumerator_Name (F))),
Aggregate_Name =>
(Make_Defining_Identifier
(Map_C_Enumerator_Name (F)))),
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Vars))),
Aggregate_Name =>
Make_Defining_Identifier (VN (V_Request)),
Is_Pointer => True)),
Parameters);
Append_Node_To_List
(Get_Data_Size (Corresponding_Instance (F)),
Parameters);
N := Make_Call_Profile
(RE (RE_Copy_Array),
Parameters);
Append_Node_To_List
(N, Switch_Statements);
Append_Node_To_List
(Make_Defining_Identifier
(Map_C_Enumerator_Name (F)),
Switch_Labels);
N := Make_Switch_Alternative
(Switch_Labels, Switch_Statements);
Append_Node_To_List (N, Asn1_Marshall_Alternatives);
-- Make the alternative for the global unmarshall_request
-- function.
......@@ -1614,6 +1823,91 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
(Switch_Labels, Switch_Statements);
Append_Node_To_List (N, Unmarshall_Alternatives);
-- Then, handle the ASN1 unmarshallers
Switch_Statements := New_List (CTN.K_Statement_List);
Switch_Labels := New_List (CTN.K_Label_List);
Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List
(Make_Expression
(Left_Expr =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier (PN (P_Port)),
Aggregate_Name =>
Make_Defining_Identifier (VN (V_Request)),
Is_Pointer => True),
Operator => Op_Equal,
Right_Expr =>
Make_Defining_Identifier
(Map_C_Enumerator_Name (F))),
Switch_Statements);
Append_Node_To_List
(Make_Variable_Address
(Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
(Make_Defining_Identifier
(Map_C_Enumerator_Name (F))),
Aggregate_Name =>
(Make_Defining_Identifier
(Map_C_Enumerator_Name (F)))),
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Vars))),
Aggregate_Name =>
Make_Defining_Identifier (VN (V_Request)),
Is_Pointer => True)),
Parameters);
Append_Node_To_List
(Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier
(Get_String_Name ("arr")),
Aggregate_Name =>
(Make_Defining_Identifier
(Map_Port_Name_For_Asn1 (F)))),
Aggregate_Name =>
(Make_Defining_Identifier
(Get_String_Name ("u")))),
Aggregate_Name =>
Make_Defining_Identifier (MN (M_Msg))),
Aggregate_Name =>
Make_Defining_Identifier (VN (V_Pkt)),
Is_Pointer => True),
Parameters);
Append_Node_To_List
(Get_Data_Size (Corresponding_Instance (F)),
Parameters);
N := Make_Call_Profile
(RE (RE_Copy_Array),
Parameters);
Append_Node_To_List
(N, Switch_Statements);
Append_Node_To_List
(Make_Defining_Identifier
(Map_Port_Name_Present_For_Asn1 (F),
C_Conversion => False),
Switch_Labels);
N := Make_Switch_Alternative
(Switch_Labels, Switch_Statements);
Append_Node_To_List (N, Asn1_Unmarshall_Alternatives);
end if;
F := Next_Node (F);
end loop;
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 2008-2010, GET-Telecom Paris. --
-- Copyright (C) 2008-2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
......@@ -83,6 +83,8 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Unmarshall_Float64, -- __po_hi_unmarshall_float64
RE_Marshall_Request, -- __po_hi_marshall_request
RE_Unmarshall_Request, -- __po_hi_unmarshall_request
RE_Marshall_Asn1_Request, -- __po_hi_marshall_asn1_request
RE_Unmarshall_Asn1_Request, -- __po_hi_unmarshall_asn1_request
RE_Marshall_Int, -- __po_hi_marshall_int
RE_Unmarshall_Int, -- __po_hi_unmarshall_int
RE_Marshall_Int8, -- __po_hi_marshall_int8
......@@ -136,6 +138,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Wait_For_Tasks, -- __po_hi_wait_for_tasks
RE_Default_Priority, -- __PO_HI_DEFAULT_PRIORITY
RE_Marshallers_Asn1_Copy_Member, -- __PO_HI_MARSHALLERS_ASN1_COPY_MEMB
RE_Main_Type, -- __PO_HI_MAIN_TYPE
RE_Main_Args, -- __PO_HI_MAIN_ARGS
RE_Main_Name, -- __PO_HI_MAIN_NAME
......@@ -173,6 +176,9 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Operation_T, -- __po_hi_operation_t
RE_Request_T, -- __po_hi_request_t
RE_Bool_T, -- __po_hi_bool_t
RE_Asn1_Pkt_T, -- __po_hi_asn1_pkt_t
RE_Asn1_Buffer_T, -- __po_hi_asn1_buffer_t
RE_Byte_T, -- __po_hi_byte_t
RE_Uint64_T, -- __po_hi_uint64_t
RE_Uint32_T, -- __po_hi_uint32_t
RE_Uint16_T, -- __po_hi_uint16_t
......@@ -250,6 +256,8 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Unmarshall_Port => RH_PO_HI_Marshallers,
RE_Marshall_Request => RH_Marshallers,
RE_Unmarshall_Request => RH_Marshallers,
RE_Marshall_Asn1_Request => RH_Marshallers,
RE_Unmarshall_Asn1_Request => RH_Marshallers,
RE_Create_Periodic_Task => RH_PO_HI_Task,
RE_Main_Deliver => RH_Activity,
RE_Create_Sporadic_Task => RH_PO_HI_Task,
......@@ -294,6 +302,9 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Protected_T => RH_PO_HI_Protected,
RE_Inetport_T => RH_PO_HI_Transport,
RE_Inetaddr_T => RH_PO_HI_Transport,
RE_Byte_T => RH_PO_HI_Types,
RE_Asn1_Pkt_T => RH_PO_HI_Marshallers,
RE_Asn1_Buffer_T => RH_PO_HI_Marshallers,
RE_Bool_T => RH_PO_HI_Types,
RE_Uint8_T => RH_PO_HI_Types,
RE_Int8_T => RH_PO_HI_Types,
......@@ -312,6 +323,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
-- Runtime Constants associations
RE_Default_Priority => RH_PO_HI_Task,
RE_Marshallers_Asn1_Copy_Member => RH_PO_HI_Marshallers,
RE_Main_Type => RH_PO_HI_Task,
RE_Main_Args => RH_PO_HI_Task,
RE_Main_Name => RH_PO_HI_Task,
......
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