Commit 706a49eb authored by jdelange's avatar jdelange

* ocarina-backends-c_tree-nutils.ads

   - Add V_Lua_Context variable name

 * ocarina-backends-po_hi_c-runtime.ads
   - Add RE_LUA_Get_String
   - Add RE_LUA_Get_Number
   - Add RE_LUA_Get_Boolean
   - Add RE_LUA_Push_String
   - Add RE_LUA_Push_Number
   - Add RE_LUA_Push_Boolean
   - Add RE_LUA_Perform_Function_Call
   - Add RE_LUA_Init_Function_Call

 * ocarina-backends-c_common-mapping.adb
   - Adapt with the new PolyORB-HI-C interface


   


git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@3673 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent f60a240d
......@@ -2124,6 +2124,7 @@ package body Ocarina.Backends.C_Common.Mapping is
Declarations : constant List_Id := New_List (CTN.K_Declaration_List);
Statements : constant List_Id := New_List (CTN.K_Statement_List);
Call_Profile : List_Id := New_List (CTN.K_Parameter_Profile);
D : Node_Id;
N : Node_Id;
P : Node_Id;
T : Node_Id;
......@@ -2134,6 +2135,8 @@ package body Ocarina.Backends.C_Common.Mapping is
Call_Parameters : List_Id;
Return_Code_Declared : Boolean := False;
Function_Call : Node_Id;
Function_Name : Node_Id;
Param_Representation : Supported_Data_Representation;
begin
case Get_Subprogram_Kind (S) is
when Subprogram_Empty =>
......@@ -2154,30 +2157,164 @@ package body Ocarina.Backends.C_Common.Mapping is
Fatal => True);
end if;
Append_Node_To_List
(Make_Variable_Declaration
(Defining_Identifier =>
Make_Defining_Identifier (VN (V_Lua_Context)),
Used_Type =>
RE (RE_Lua_Context_T)),
Declarations);
Append_Node_To_List
(Make_Variable_Address
(Make_Defining_Identifier (VN (V_Lua_Context))),
Call_Profile);
Append_Node_To_List
(Make_Literal
(C_Values.New_Pointed_Char_Value
(Get_Source_Text (S)(1))),
Call_Profile);
Append_Node_To_List
(CTU.Make_Call_Profile
(RE (RE_LUA_Load), Call_Profile),
Statements);
if Get_Source_Name (S) /= No_Name then
-- Init the function call of the LUA function
Call_Profile := New_List (CTN.K_Parameter_Profile);
Append_Node_To_List
(Make_Variable_Address
(Make_Defining_Identifier (VN (V_Lua_Context))),
Call_Profile);
Append_Node_To_List
(Make_Literal
(C_Values.New_Pointed_Char_Value
(Get_Source_Name (S))),
Call_Profile);
else
Append_Node_To_List
(CTU.Make_Call_Profile
(RE (RE_LUA_Init_Function_Call), Call_Profile),
Statements);
-- Push all the IN parameters on the stack
if not AINU.Is_Empty (Features (S)) then
Feature := AIN.First_Node (Features (S));
while Present (Feature) loop
if Kind (Feature) = K_Parameter_Instance and then
Is_In (Feature) then
D := Corresponding_Instance (Feature);
Param_Representation := Get_Data_Representation (D);
Call_Profile := New_List (CTN.K_Parameter_Profile);
Append_Node_To_List
(Make_Variable_Address
(Make_Defining_Identifier (VN (V_Lua_Context))),
Call_Profile);
Append_Node_To_List
(Map_C_Defining_Identifier (Feature),
Call_Profile);
if Param_Representation = Data_Integer then
Function_Name := RE (RE_Lua_Push_Number);
elsif Param_Representation = Data_String then
Function_Name := RE (RE_Lua_Push_String);
elsif Param_Representation = Data_Boolean then
Function_Name := RE (RE_Lua_Push_Boolean);
else
Display_Located_Error
(AIN.Loc (Feature),
"Type of this feature is not supported " &
"for LUA interface",
Fatal => True);
end if;
Append_Node_To_List
(CTU.Make_Call_Profile
(Function_Name, Call_Profile),
Statements);
end if;
Feature := AIN.Next_Node (Feature);
end loop;
end if;
-- Perform the function call of the LUA function
Call_Profile := New_List (CTN.K_Parameter_Profile);
Append_Node_To_List
(Make_Defining_Identifier (CONST (C_Null),
C_Conversion => False),
(Make_Variable_Address
(Make_Defining_Identifier (VN (V_Lua_Context))),
Call_Profile);
end if;
Append_Node_To_List
(CTU.Make_Call_Profile
(RE (RE_LUA_Perform_Function_Call), Call_Profile),
Statements);
Append_Node_To_List
(CTU.Make_Call_Profile
(RE (RE_LUA_Load), Call_Profile),
Statements);
-- Get all the OUT parameters from LUA to C.
if not AINU.Is_Empty (Features (S)) then
Feature := AIN.First_Node (Features (S));
while Present (Feature) loop
if Kind (Feature) = K_Parameter_Instance and then
Is_Out (Feature) then
D := Corresponding_Instance (Feature);
Param_Representation := Get_Data_Representation (D);
Call_Profile := New_List (CTN.K_Parameter_Profile);
Append_Node_To_List
(Make_Variable_Address
(Make_Defining_Identifier (VN (V_Lua_Context))),
Call_Profile);
Append_Node_To_List
(Make_Literal
(C_Values.New_Pointed_Char_Value
(To_C_Name
(AIN.Name
(AIN.Identifier (Feature))))),
Call_Profile);
Append_Node_To_List
(Map_C_Defining_Identifier (Feature),
Call_Profile);
if Param_Representation = Data_Integer then
Function_Name := RE (RE_Lua_Get_Number);
elsif Param_Representation = Data_String then
Function_Name := RE (RE_Lua_Get_String);
elsif Param_Representation = Data_Boolean then
Function_Name := RE (RE_Lua_Get_Boolean);
else
Display_Located_Error
(AIN.Loc (Feature),
"Type of this feature is not supported " &
"for LUA interface",
Fatal => True);
end if;
Append_Node_To_List
(CTU.Make_Call_Profile
(Function_Name, Call_Profile),
Statements);
end if;
Feature := AIN.Next_Node (Feature);
end loop;
end if;
end if;
return Make_Function_Implementation
(Spec, Declarations, Statements);
......
......@@ -205,6 +205,7 @@ package Ocarina.Backends.C_Tree.Nutils is
(V_Request,
V_Ret,
V_Tattr,
V_Lua_Context,
V_Next_Period,
V_Port_Global_To_Entity,
V_Port_Global_To_Local_Port,
......
......@@ -73,6 +73,14 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Initialize, -- __po_hi_initialize
RE_Initialize_Early, -- __po_hi_initialize_early
RE_LUA_Load, -- __po_hi_lua_load
RE_LUA_Init_Function_Call, -- __po_hi_lua_init_function_call
RE_LUA_Perform_Function_Call, -- __po_hi_lua_perform_function_call
RE_LUA_Push_Boolean, -- __po_hi_lua_push_boolean
RE_LUA_Push_Number, -- __po_hi_lua_push_number
RE_LUA_Push_String, -- __po_hi_lua_push_string
RE_LUA_Get_Boolean, -- __po_hi_lua_get_boolean
RE_LUA_Get_Number, -- __po_hi_lua_get_number
RE_LUA_Get_String, -- __po_hi_lua_get_string
RE_LUA_Load_File, -- __po_hi_lua_load_file
RE_LUA_Load_File_With_Function, -- __po_hi_lua_load_file_with_function
RE_Wait_Initialization, -- __po_hi_wait_initialization
......@@ -202,6 +210,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Request_T, -- __po_hi_request_t
RE_Protected_Protocol_T, -- __po_hi_protected_protocol_t
RE_Bool_T, -- __po_hi_bool_t
RE_Lua_Context_T, -- __po_hi_lua_context_t
RE_Asn1_Pkt_T, -- __po_hi_asn1_pkt_t
RE_Asn1_Buffer_T, -- __po_hi_asn1_buffer_t
RE_Time_T, -- __po_hi_time_t
......@@ -301,6 +310,14 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_LUA_Load => RH_PO_HI_Lua,
RE_LUA_Load_File => RH_PO_HI_Lua,
RE_LUA_Load_File_With_Function => RH_PO_HI_Lua,
RE_LUA_Init_Function_Call => RH_PO_HI_Lua,
RE_LUA_Perform_Function_Call => RH_PO_HI_Lua,
RE_LUA_Push_Boolean => RH_PO_HI_Lua,
RE_LUA_Push_Number => RH_PO_HI_Lua,
RE_LUA_Push_String => RH_PO_HI_Lua,
RE_LUA_Get_Boolean => RH_PO_HI_Lua,
RE_LUA_Get_Number => RH_PO_HI_Lua,
RE_LUA_Get_String => RH_PO_HI_Lua,
RE_Marshall_Request => RH_Marshallers,
RE_Unmarshall_Request => RH_Marshallers,
RE_Marshall_Asn1_Request => RH_Marshallers,
......@@ -355,6 +372,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Inetaddr_T => RH_PO_HI_Transport,
RE_Time_T => RH_PO_HI_Time,
RE_Byte_T => RH_PO_HI_Types,
RE_Lua_Context_T => RH_PO_HI_Lua,
RE_Asn1_Pkt_T => RH_PO_HI_Marshallers,
RE_Asn1_Buffer_T => RH_PO_HI_Marshallers,
RE_Bool_T => RH_PO_HI_Types,
......
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