Commit 706a49eb authored by jdelange's avatar jdelange
Browse files

* 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 ...@@ -2124,6 +2124,7 @@ package body Ocarina.Backends.C_Common.Mapping is
Declarations : constant List_Id := New_List (CTN.K_Declaration_List); Declarations : constant List_Id := New_List (CTN.K_Declaration_List);
Statements : constant List_Id := New_List (CTN.K_Statement_List); Statements : constant List_Id := New_List (CTN.K_Statement_List);
Call_Profile : List_Id := New_List (CTN.K_Parameter_Profile); Call_Profile : List_Id := New_List (CTN.K_Parameter_Profile);
D : Node_Id;
N : Node_Id; N : Node_Id;
P : Node_Id; P : Node_Id;
T : Node_Id; T : Node_Id;
...@@ -2134,6 +2135,8 @@ package body Ocarina.Backends.C_Common.Mapping is ...@@ -2134,6 +2135,8 @@ package body Ocarina.Backends.C_Common.Mapping is
Call_Parameters : List_Id; Call_Parameters : List_Id;
Return_Code_Declared : Boolean := False; Return_Code_Declared : Boolean := False;
Function_Call : Node_Id; Function_Call : Node_Id;
Function_Name : Node_Id;
Param_Representation : Supported_Data_Representation;
begin begin
case Get_Subprogram_Kind (S) is case Get_Subprogram_Kind (S) is
when Subprogram_Empty => when Subprogram_Empty =>
...@@ -2154,30 +2157,164 @@ package body Ocarina.Backends.C_Common.Mapping is ...@@ -2154,30 +2157,164 @@ package body Ocarina.Backends.C_Common.Mapping is
Fatal => True); Fatal => True);
end if; 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 Append_Node_To_List
(Make_Literal (Make_Literal
(C_Values.New_Pointed_Char_Value (C_Values.New_Pointed_Char_Value
(Get_Source_Text (S)(1))), (Get_Source_Text (S)(1))),
Call_Profile); 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 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 Append_Node_To_List
(Make_Literal (Make_Literal
(C_Values.New_Pointed_Char_Value (C_Values.New_Pointed_Char_Value
(Get_Source_Name (S))), (Get_Source_Name (S))),
Call_Profile); 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 Append_Node_To_List
(Make_Defining_Identifier (CONST (C_Null), (Make_Variable_Address
C_Conversion => False), (Make_Defining_Identifier (VN (V_Lua_Context))),
Call_Profile); 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 -- Get all the OUT parameters from LUA to C.
(CTU.Make_Call_Profile if not AINU.Is_Empty (Features (S)) then
(RE (RE_LUA_Load), Call_Profile), Feature := AIN.First_Node (Features (S));
Statements);
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 return Make_Function_Implementation
(Spec, Declarations, Statements); (Spec, Declarations, Statements);
......
...@@ -205,6 +205,7 @@ package Ocarina.Backends.C_Tree.Nutils is ...@@ -205,6 +205,7 @@ package Ocarina.Backends.C_Tree.Nutils is
(V_Request, (V_Request,
V_Ret, V_Ret,
V_Tattr, V_Tattr,
V_Lua_Context,
V_Next_Period, V_Next_Period,
V_Port_Global_To_Entity, V_Port_Global_To_Entity,
V_Port_Global_To_Local_Port, V_Port_Global_To_Local_Port,
......
...@@ -73,6 +73,14 @@ package Ocarina.Backends.PO_HI_C.Runtime is ...@@ -73,6 +73,14 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Initialize, -- __po_hi_initialize RE_Initialize, -- __po_hi_initialize
RE_Initialize_Early, -- __po_hi_initialize_early RE_Initialize_Early, -- __po_hi_initialize_early
RE_LUA_Load, -- __po_hi_lua_load 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, -- __po_hi_lua_load_file
RE_LUA_Load_File_With_Function, -- __po_hi_lua_load_file_with_function RE_LUA_Load_File_With_Function, -- __po_hi_lua_load_file_with_function
RE_Wait_Initialization, -- __po_hi_wait_initialization RE_Wait_Initialization, -- __po_hi_wait_initialization
...@@ -202,6 +210,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is ...@@ -202,6 +210,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Request_T, -- __po_hi_request_t RE_Request_T, -- __po_hi_request_t
RE_Protected_Protocol_T, -- __po_hi_protected_protocol_t RE_Protected_Protocol_T, -- __po_hi_protected_protocol_t
RE_Bool_T, -- __po_hi_bool_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_Pkt_T, -- __po_hi_asn1_pkt_t
RE_Asn1_Buffer_T, -- __po_hi_asn1_buffer_t RE_Asn1_Buffer_T, -- __po_hi_asn1_buffer_t
RE_Time_T, -- __po_hi_time_t RE_Time_T, -- __po_hi_time_t
...@@ -301,6 +310,14 @@ package Ocarina.Backends.PO_HI_C.Runtime is ...@@ -301,6 +310,14 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_LUA_Load => RH_PO_HI_Lua, RE_LUA_Load => RH_PO_HI_Lua,
RE_LUA_Load_File => RH_PO_HI_Lua, RE_LUA_Load_File => RH_PO_HI_Lua,
RE_LUA_Load_File_With_Function => 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_Marshall_Request => RH_Marshallers,
RE_Unmarshall_Request => RH_Marshallers, RE_Unmarshall_Request => RH_Marshallers,
RE_Marshall_Asn1_Request => RH_Marshallers, RE_Marshall_Asn1_Request => RH_Marshallers,
...@@ -355,6 +372,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is ...@@ -355,6 +372,7 @@ package Ocarina.Backends.PO_HI_C.Runtime is
RE_Inetaddr_T => RH_PO_HI_Transport, RE_Inetaddr_T => RH_PO_HI_Transport,
RE_Time_T => RH_PO_HI_Time, RE_Time_T => RH_PO_HI_Time,
RE_Byte_T => RH_PO_HI_Types, 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_Pkt_T => RH_PO_HI_Marshallers,
RE_Asn1_Buffer_T => RH_PO_HI_Marshallers, RE_Asn1_Buffer_T => RH_PO_HI_Marshallers,
RE_Bool_T => RH_PO_HI_Types, RE_Bool_T => RH_PO_HI_Types,
......
Supports Markdown
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