Commit 6d46a5e8 authored by yoogx's avatar yoogx

* Add support for Bounded_Array representation

        For openaadl/ocarina#119
parent 35b268be
...@@ -2165,7 +2165,11 @@ package body Ocarina.Backends.C_Tree.Nutils is ...@@ -2165,7 +2165,11 @@ package body Ocarina.Backends.C_Tree.Nutils is
-- Get_Data_Size -- -- Get_Data_Size --
------------------- -------------------
function Get_Data_Size (Data : Node_Id) return Node_Id is function Get_Data_Size (Data : Node_Id;
Is_Pointer : Boolean := False;
Maximum_Size : Boolean := False)
return Node_Id
is
Data_Representation : Supported_Data_Representation; Data_Representation : Supported_Data_Representation;
Value_UUL : Unsigned_Long_Long; Value_UUL : Unsigned_Long_Long;
Value_Node : Node_Id := No_Node; Value_Node : Node_Id := No_Node;
...@@ -2217,6 +2221,33 @@ package body Ocarina.Backends.C_Tree.Nutils is ...@@ -2217,6 +2221,33 @@ package body Ocarina.Backends.C_Tree.Nutils is
Get_Data_Size Get_Data_Size
(ATN.Entity (ATN.First_Node (Get_Base_Type (Data))))); (ATN.Entity (ATN.First_Node (Get_Base_Type (Data)))));
when Data_Bounded_Array =>
if Maximum_Size then
Value_Node :=
Make_Expression
(Left_Expr =>
Make_Literal (New_Int_Value (Dimension (1), 1, 10)),
Operator => Op_Asterisk,
Right_Expr =>
Get_Data_Size
(ATN.Entity (ATN.First_Node (Get_Base_Type (Data)))));
else
Value_Node :=
Make_Expression
(Left_Expr =>
Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_length)),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Value)),
Is_Pointer => Is_Pointer),
Operator => Op_Asterisk,
Right_Expr =>
Get_Data_Size
(ATN.Entity (ATN.First_Node (Get_Base_Type (Data)))));
end if;
when Data_None => when Data_None =>
Value_Node := Value_Node :=
Make_Call_Profile Make_Call_Profile
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. -- -- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2017 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -157,6 +157,8 @@ package Ocarina.Backends.C_Tree.Nutils is ...@@ -157,6 +157,8 @@ package Ocarina.Backends.C_Tree.Nutils is
P_Msg, P_Msg,
P_Request, P_Request,
P_Buffer, P_Buffer,
P_Data,
P_Length,
P_Status, P_Status,
P_Entity, P_Entity,
P_Task, P_Task,
...@@ -179,6 +181,8 @@ package Ocarina.Backends.C_Tree.Nutils is ...@@ -179,6 +181,8 @@ package Ocarina.Backends.C_Tree.Nutils is
M_Entry, M_Entry,
M_Entry_Point, M_Entry_Point,
M_Kind, M_Kind,
M_Data,
M_Length,
M_Msg, M_Msg,
M_Name, M_Name,
M_Base_Priority, M_Base_Priority,
...@@ -556,9 +560,15 @@ package Ocarina.Backends.C_Tree.Nutils is ...@@ -556,9 +560,15 @@ package Ocarina.Backends.C_Tree.Nutils is
(Array_Name : Node_Id; (Array_Name : Node_Id;
Array_Item : Node_Id) return Node_Id; Array_Item : Node_Id) return Node_Id;
function Get_Data_Size (Data : Node_Id) return Node_Id; function Get_Data_Size (Data : Node_Id;
-- Returns a node that represent an expression with the size Is_Pointer : Boolean := False;
-- (in bytes) of a data. Maximum_Size : Boolean := False)
return Node_Id;
-- Returns a node that represent an expression with the size (in
-- bytes) of a data.
-- Note: for some types like Bounded_Array, this expression is dynamic.
-- - Is_Pointer controls wether we build a pointer-like expresison;
-- - Maximum_Size returns the maximum size (static value).
procedure Add_Return_Variable_In_Parameters (Parameters : List_Id); procedure Add_Return_Variable_In_Parameters (Parameters : List_Id);
-- Add the name of the return variable in the list. -- Add the name of the return variable in the list.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. -- -- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2017 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -715,6 +715,53 @@ package body Ocarina.Backends.C_Common.Types is ...@@ -715,6 +715,53 @@ package body Ocarina.Backends.C_Common.Types is
(ATN.Entity (ATN.First_Node (Get_Base_Type (E))))); (ATN.Entity (ATN.First_Node (Get_Base_Type (E)))));
Append_Node_To_List (N, CTN.Declarations (Current_File)); Append_Node_To_List (N, CTN.Declarations (Current_File));
when Data_Bounded_Array =>
Visit_Data_Instance
(ATN.Entity (ATN.First_Node (Get_Base_Type (E))));
-- In the case of a bounded array, we generate a C
-- struct whose member are
--
-- 1) an anonymous array whose size is the upper
-- bound of the array, from "Dimension" property
N :=
Make_Member_Declaration
(Defining_Identifier =>
Make_Array_Declaration
(Defining_Identifier =>
Make_Defining_Identifier (PN (P_Data)),
Array_Size =>
Make_Literal
(CV.New_Int_Value
(Data_Array_Size (1),
0,
10))),
Used_Type =>
Map_C_Defining_Identifier
(ATN.Entity (ATN.First_Node (Get_Base_Type (E)))));
Append_Node_To_List (N, Struct_Members);
-- 2) length, giving the actual size used as a
-- 32bits integer
N :=
Make_Member_Declaration
(Defining_Identifier =>
Make_Defining_Identifier (PN (P_Length)),
Used_Type =>
PHR.RE (RE_Int32_T));
Append_Node_To_List (N, Struct_Members);
N :=
Make_Full_Type_Declaration
(Defining_Identifier =>
Map_C_Defining_Identifier (E),
Type_Definition =>
Make_Struct_Aggregate
(Members => Struct_Members));
Append_Node_To_List (N, CTN.Declarations (Current_File));
when Data_String => when Data_String =>
N := N :=
Make_Full_Type_Declaration Make_Full_Type_Declaration
......
...@@ -242,6 +242,7 @@ package body Ocarina.Backends.Properties is ...@@ -242,6 +242,7 @@ package body Ocarina.Backends.Properties is
Data_Array_Name : Name_Id; Data_Array_Name : Name_Id;
Data_Boolean_Name : Name_Id; Data_Boolean_Name : Name_Id;
Data_Bounded_Array_Name : Name_Id;
Data_Character_Name : Name_Id; Data_Character_Name : Name_Id;
Data_Enum_Name : Name_Id; Data_Enum_Name : Name_Id;
Data_Float_Name : Name_Id; Data_Float_Name : Name_Id;
...@@ -714,7 +715,9 @@ package body Ocarina.Backends.Properties is ...@@ -714,7 +715,9 @@ package body Ocarina.Backends.Properties is
-- case since the <..>_Name global variables are not (and -- case since the <..>_Name global variables are not (and
-- cannot be) static. -- cannot be) static.
if T_Name = Data_Array_Name then if T_Name = Data_Array_Name or else
T_Name = Data_Bounded_Array_Name
then
if not Is_Defined_List_Property (D, Dimension) then if not Is_Defined_List_Property (D, Dimension) then
Display_Located_Error Display_Located_Error
(ATN.Loc (D), (ATN.Loc (D),
...@@ -729,7 +732,11 @@ package body Ocarina.Backends.Properties is ...@@ -729,7 +732,11 @@ package body Ocarina.Backends.Properties is
Fatal => True); Fatal => True);
end if; end if;
return Data_Array; if T_Name = Data_Array_Name then
return Data_Array;
else
return Data_Bounded_Array;
end if;
elsif T_Name = Data_Boolean_Name then elsif T_Name = Data_Boolean_Name then
return Data_Boolean; return Data_Boolean;
...@@ -2953,6 +2960,7 @@ package body Ocarina.Backends.Properties is ...@@ -2953,6 +2960,7 @@ package body Ocarina.Backends.Properties is
Memory_Size := Get_String_Name ("memory_size"); Memory_Size := Get_String_Name ("memory_size");
Data_Array_Name := Get_String_Name ("array"); Data_Array_Name := Get_String_Name ("array");
Data_Boolean_Name := Get_String_Name ("boolean"); Data_Boolean_Name := Get_String_Name ("boolean");
Data_Bounded_Array_Name := Get_String_Name ("bounded_array");
Data_Character_Name := Get_String_Name ("character"); Data_Character_Name := Get_String_Name ("character");
Data_Enum_Name := Get_String_Name ("enum"); Data_Enum_Name := Get_String_Name ("enum");
Data_Float_Name := Get_String_Name ("float"); Data_Float_Name := Get_String_Name ("float");
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. -- -- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2017 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -227,6 +227,7 @@ package Ocarina.Backends.Properties is ...@@ -227,6 +227,7 @@ package Ocarina.Backends.Properties is
type Supported_Data_Representation is type Supported_Data_Representation is
(Data_Array, (Data_Array,
Data_Boolean, Data_Boolean,
Data_Bounded_Array,
Data_Character, Data_Character,
Data_Wide_Character, Data_Wide_Character,
Data_Enum, Data_Enum,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2006-2009 Telecom ParisTech, 2010-2015 ESA & ISAE. -- -- Copyright (C) 2006-2009 Telecom ParisTech, 2010-2017 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -1451,6 +1451,7 @@ package body Ocarina.Backends.PO_HI_Ada.Mapping is ...@@ -1451,6 +1451,7 @@ package body Ocarina.Backends.PO_HI_Ada.Mapping is
Data_Character => 8, -- Unique size Data_Character => 8, -- Unique size
Data_Wide_Character => 16, -- Unique size Data_Wide_Character => 16, -- Unique size
Data_Array => 0, -- Initial size Data_Array => 0, -- Initial size
Data_Bounded_Array => 0, -- Initial size
Data_Struct => 0, -- Initial size Data_Struct => 0, -- Initial size
Data_Union => 0, -- Initial size Data_Union => 0, -- Initial size
Data_With_Accessors => 0, -- Unsupported Data_With_Accessors => 0, -- Unsupported
...@@ -1468,6 +1469,7 @@ package body Ocarina.Backends.PO_HI_Ada.Mapping is ...@@ -1468,6 +1469,7 @@ package body Ocarina.Backends.PO_HI_Ada.Mapping is
Data_Character => 1, Data_Character => 1,
Data_Wide_Character => 2, Data_Wide_Character => 2,
Data_Array => 4, Data_Array => 4,
Data_Bounded_Array => 4,
Data_Struct => 4, Data_Struct => 4,
Data_Union => 4, Data_Union => 4,
Data_With_Accessors => 1, -- Unsupported Data_With_Accessors => 1, -- Unsupported
...@@ -1541,7 +1543,7 @@ package body Ocarina.Backends.PO_HI_Ada.Mapping is ...@@ -1541,7 +1543,7 @@ package body Ocarina.Backends.PO_HI_Ada.Mapping is
Result); Result);
end; end;
when Data_Array => when Data_Array | Data_Bounded_Array =>
declare declare
Dimension : constant ULL_Array := Get_Dimension (E); Dimension : constant ULL_Array := Get_Dimension (E);
Elt : constant Node_Id := Elt : constant Node_Id :=
......
...@@ -401,6 +401,9 @@ package body Ocarina.Backends.PO_HI_Ada.Types is ...@@ -401,6 +401,9 @@ package body Ocarina.Backends.PO_HI_Ada.Types is
Type_Definition => Type_Definition =>
Make_Derived_Type_Definition (RE (RE_Boolean))); Make_Derived_Type_Definition (RE (RE_Boolean)));
when Data_Bounded_Array =>
raise Program_Error; -- XXX
when Data_Character => when Data_Character =>
N := N :=
Make_Full_Type_Declaration Make_Full_Type_Declaration
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. -- -- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2017 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -1771,7 +1771,8 @@ package body Ocarina.Backends.PO_HI_C.Deployment is ...@@ -1771,7 +1771,8 @@ package body Ocarina.Backends.PO_HI_C.Deployment is
if Is_Data (F) then if Is_Data (F) then
Append_Node_To_List Append_Node_To_List
(Get_Data_Size (Corresponding_Instance (F)), (Get_Data_Size (Corresponding_Instance (F),
Maximum_Size => True),
CTN.Values (Global_Port_Data_Size)); CTN.Values (Global_Port_Data_Size));
end if; end if;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. -- -- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2017 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -706,6 +706,50 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is ...@@ -706,6 +706,50 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
N := Make_Call_Profile (RE (RE_Marshall_Array), Parameters); N := Make_Call_Profile (RE (RE_Marshall_Array), Parameters);
Append_Node_To_List (N, Statements); Append_Node_To_List (N, Statements);
when Data_Bounded_Array =>
-- In the case of a bounded array, we marshall first
-- the length of the array, then the actual buffer
-- 1/ Marshall buffer length
Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List
(Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_Length)),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Value))),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Message)),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Offset)),
Parameters);
N := Make_Call_Profile (RE (RE_Marshall_Int32), Parameters);
Append_Node_To_List (N, Statements);
-- 2/ Marshall buffer data
Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List
(Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_Data)),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Value))),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Message)),
Parameters);
Append_Node_To_List
(CTU.Get_Data_Size (E, Is_Pointer => False), Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Offset)),
Parameters);
N := Make_Call_Profile (RE (RE_Marshall_Array), Parameters);
Append_Node_To_List (N, Statements);
when Data_Enum => when Data_Enum =>
-- In C, an enumeration constant is equivalent to an -- In C, an enumeration constant is equivalent to an
-- int constant, therefore we marshall the value as an -- int constant, therefore we marshall the value as an
...@@ -837,10 +881,53 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is ...@@ -837,10 +881,53 @@ package body Ocarina.Backends.PO_HI_C.Marshallers is
N := Make_Call_Profile (RE (RE_Unmarshall_Array), Parameters); N := Make_Call_Profile (RE (RE_Unmarshall_Array), Parameters);
Append_Node_To_List (N, Statements); Append_Node_To_List (N, Statements);
when Data_Bounded_Array =>
Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List
(Make_Variable_Address
(Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_Length)),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Value)),
Is_Pointer => True)),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Message)),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Offset)),
Parameters);
N := Make_Call_Profile (RE (RE_Unmarshall_Int32), Parameters);
Append_Node_To_List (N, Statements);
-- 2/
Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List
(Make_Variable_Address
(Make_Member_Designator
(Defining_Identifier =>
Make_Defining_Identifier (MN (M_Data)),
Aggregate_Name =>
Make_Defining_Identifier (PN (P_Value)),
Is_Pointer => True)),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Message)),
Parameters);
Append_Node_To_List (CTU.Get_Data_Size (E, Is_Pointer => True),
Parameters);
Append_Node_To_List
(Make_Defining_Identifier (PN (P_Offset)),
Parameters);
N := Make_Call_Profile (RE (RE_Unmarshall_Array), Parameters);
Append_Node_To_List (N, Statements);
when Data_Enum => when Data_Enum =>
-- In C, an enumeration constant is equivalent to an -- In C, an enumeration constant is equivalent to an
-- int constant, therefore we unmarshall the value as -- int constant, therefore we unmarshall the value as
-- an __po_hi_int32 parameter. -- a __po_hi_int32 parameter.
-- XXX should be changed to an INT
Parameters := New_List (CTN.K_Parameter_List); Parameters := New_List (CTN.K_Parameter_List);
Append_Node_To_List Append_Node_To_List
......
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