Commit 6b44ae66 authored by yoogx's avatar yoogx
Browse files

* Add preliminary support for C++

parent e60e4cd8
...@@ -336,6 +336,10 @@ package body Ocarina.Backends.Build_Utils is ...@@ -336,6 +336,10 @@ package body Ocarina.Backends.Build_Utils is
-- The C source files that may implement some subprograms of -- The C source files that may implement some subprograms of
-- the current node (absolute or relative path). -- the current node (absolute or relative path).
CPP_Sources : Name_Tables.Instance;
-- The C source files that may implement some subprograms of
-- the current node (absolute or relative path).
C_Libraries : Name_Tables.Instance; C_Libraries : Name_Tables.Instance;
-- The C libraries that may contain the binary code of some -- The C libraries that may contain the binary code of some
-- subprograms of the current node (absolute or relative -- subprograms of the current node (absolute or relative
...@@ -385,11 +389,12 @@ package body Ocarina.Backends.Build_Utils is ...@@ -385,11 +389,12 @@ package body Ocarina.Backends.Build_Utils is
procedure Ada_C_Command_Line_Flags procedure Ada_C_Command_Line_Flags
(Ada_Sources : Name_Tables.Instance; (Ada_Sources : Name_Tables.Instance;
C_Sources : Name_Tables.Instance; C_Sources : Name_Tables.Instance;
CPP_Sources : Name_Tables.Instance;
C_Libraries : Name_Tables.Instance); C_Libraries : Name_Tables.Instance);
procedure Compile_Ada_Files (Ada_Sources : Name_Tables.Instance); procedure Compile_Ada_Files (Ada_Sources : Name_Tables.Instance);
procedure Compile_C_Files (C_Sources : Name_Tables.Instance); procedure Compile_C_Files (C_Sources : Name_Tables.Instance);
procedure Compile_CPP_Files (CPP_Sources : Name_Tables.Instance);
-- Generate a makefile target to compile C_Sources C files -- Generate a makefile target to compile C_Sources C files
procedure Handle_C_Source procedure Handle_C_Source
...@@ -403,6 +408,17 @@ package body Ocarina.Backends.Build_Utils is ...@@ -403,6 +408,17 @@ package body Ocarina.Backends.Build_Utils is
-- is the node for which the source files are given, it is used -- is the node for which the source files are given, it is used
-- to resolve relative paths through its absolute location. -- to resolve relative paths through its absolute location.
procedure Handle_CPP_Source
(E : Node_Id;
Implem_Name : Name_Id;
Source_Files : Name_Array;
M : Makefile_Type;
Custom_Source_Dir : Name_Id := No_Name);
-- Update the makefile structure by adding necessary paths to
-- sources or libraries provided by the 'Source_Files' array. E
-- is the node for which the source files are given, it is used
-- to resolve relative paths through its absolute location.
procedure Handle_Ada_Source procedure Handle_Ada_Source
(E : Node_Id; (E : Node_Id;
Implem_Name : Name_Id; Implem_Name : Name_Id;
...@@ -518,8 +534,9 @@ package body Ocarina.Backends.Build_Utils is ...@@ -518,8 +534,9 @@ package body Ocarina.Backends.Build_Utils is
begin begin
-- Ensure the user gives at most one source file (.c) -- Ensure the user gives at most one source file (.c)
if Source_Files'Length > 1 and then if Source_Files'Length > 1
Get_Current_Backend_Kind = PolyORB_HI_Ada then and then Get_Current_Backend_Kind = PolyORB_HI_Ada
then
Display_Located_Error Display_Located_Error
(Loc (E), (Loc (E),
"more than one source files for a C subprogram", "more than one source files for a C subprogram",
...@@ -616,6 +633,7 @@ package body Ocarina.Backends.Build_Utils is ...@@ -616,6 +633,7 @@ package body Ocarina.Backends.Build_Utils is
Source_Dirname); Source_Dirname);
Set_Name_Table_Byte (Name_Find, 1); Set_Name_Table_Byte (Name_Find, 1);
end if; end if;
else else
Set_Str_To_Name_Buffer (Binding_Key); Set_Str_To_Name_Buffer (Binding_Key);
Get_Name_String (Source_Dirname); Get_Name_String (Source_Dirname);
...@@ -633,6 +651,121 @@ package body Ocarina.Backends.Build_Utils is ...@@ -633,6 +651,121 @@ package body Ocarina.Backends.Build_Utils is
end if; end if;
end Handle_C_Source; end Handle_C_Source;
-----------------------
-- Handle_CPP_Source --
-----------------------
procedure Handle_CPP_Source
(E : Node_Id;
Implem_Name : Name_Id;
Source_Files : Name_Array;
M : Makefile_Type;
Custom_Source_Dir : Name_Id := No_Name)
is
Source_Basename : Name_Id;
Source_Dirname : Name_Id;
S_Name : Name_Id;
Binding_Key : constant String := "%user_src_dir%";
begin
-- Ensure the user gives at most one source file (.cc)
if Source_Files'Length > 1
and then Get_Current_Backend_Kind = PolyORB_HI_Ada
then
Display_Located_Error
(Loc (E),
"more than one source files for a C subprogram",
Fatal => True);
end if;
if Source_Files'Length = 0 and then Implem_Name /= No_Name then
-- This means that the user did not provide source file
-- names for the C implementation but did provide the
-- implementation name. Therefore, the corresponding
-- source files have conventional names and are located
-- at the same directory as the AADL file.
Split_Path
(Implem_Name,
Loc (E).Dir_Name,
Source_Basename,
Source_Dirname);
if Custom_Source_Dir /= No_Name then
Source_Dirname := Custom_Source_Dir;
end if;
Set_Str_To_Name_Buffer (Binding_Key);
Get_Name_String_And_Append (Source_Dirname);
Get_Name_String_And_Append (M.Node_Name);
if Get_Name_Table_Byte (Name_Find) = 0 then
Name_Tables.Append
(M.User_Source_Dirs,
Source_Dirname);
Set_Name_Table_Byte (Name_Find, 1);
end if;
elsif Source_Files'Length /= 0 then
for J in Source_Files'Range loop
-- Ensure the source is added only once per node
Get_Name_String (Source_Files (J));
Get_Name_String_And_Append (M.Node_Name);
Add_Str_To_Name_Buffer ("%source_text%");
S_Name := Name_Find;
if Get_Name_Table_Info (S_Name) = 0 then
Set_Name_Table_Info (S_Name, 1);
Get_Name_String (Source_Files (J));
Split_Path
(Source_Files (J),
Loc (E).Dir_Name,
Source_Basename,
Source_Dirname);
if Custom_Source_Dir /= No_Name then
Source_Dirname := Custom_Source_Dir;
end if;
Get_Name_String (Source_Basename);
if Name_Buffer (Name_Len - 2 .. Name_Len) = ".cc" then
Get_Name_String (Source_Dirname);
Get_Name_String_And_Append (Source_Basename);
Name_Tables.Append (M.CPP_Sources, Name_Find);
Set_Str_To_Name_Buffer (Binding_Key);
Get_Name_String (Source_Dirname);
Get_Name_String_And_Append (M.Node_Name);
if Get_Name_Table_Byte (Name_Find) = 0 then
Name_Tables.Append
(M.User_Source_Dirs,
Source_Dirname);
Set_Name_Table_Byte (Name_Find, 1);
end if;
else
Set_Str_To_Name_Buffer (Binding_Key);
Get_Name_String (Source_Dirname);
Get_Name_String_And_Append (M.Node_Name);
if Get_Name_Table_Byte (Name_Find) = 0 then
Name_Tables.Append
(M.User_Source_Dirs,
Source_Dirname);
Set_Name_Table_Byte (Name_Find, 1);
end if;
end if;
end if;
end loop;
end if;
end Handle_CPP_Source;
----------- -----------
-- Visit -- -- Visit --
----------- -----------
...@@ -842,6 +975,7 @@ package body Ocarina.Backends.Build_Utils is ...@@ -842,6 +975,7 @@ package body Ocarina.Backends.Build_Utils is
Name_Tables.Init (M.Ada_Sources); Name_Tables.Init (M.Ada_Sources);
Name_Tables.Init (M.Asn_Sources); Name_Tables.Init (M.Asn_Sources);
Name_Tables.Init (M.C_Sources); Name_Tables.Init (M.C_Sources);
Name_Tables.Init (M.CPP_Sources);
Name_Tables.Init (M.C_Objs); Name_Tables.Init (M.C_Objs);
Name_Tables.Init (M.C_Libraries); Name_Tables.Init (M.C_Libraries);
Name_Tables.Init (M.User_Source_Dirs); Name_Tables.Init (M.User_Source_Dirs);
...@@ -1068,6 +1202,15 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1068,6 +1202,15 @@ package body Ocarina.Backends.Build_Utils is
Handle_C_Source (E, Source_Name, Source_Files, M); Handle_C_Source (E, Source_Name, Source_Files, M);
when Subprogram_Opaque_CPP =>
-- If the subprogram is implemented by C source files,
-- add the files to the C_Files list of the makefile
-- structure. If the subprogram is implemented by a C
-- library, add the files to the C_Libraries list of
-- the makefile structure.
Handle_CPP_Source (E, Source_Name, Source_Files, M);
when Subprogram_Opaque_Ada_95 => when Subprogram_Opaque_Ada_95 =>
-- If the subprogram is implemented by Ada source files, -- If the subprogram is implemented by Ada source files,
-- add the files to the Ada_Files list of the makefile -- add the files to the Ada_Files list of the makefile
...@@ -1092,8 +1235,7 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1092,8 +1235,7 @@ package body Ocarina.Backends.Build_Utils is
Get_Name_String (Simulink_Dir); Get_Name_String (Simulink_Dir);
Add_Str_To_Name_Buffer ("/"); Add_Str_To_Name_Buffer ("/");
Add_Str_To_Name_Buffer ("/*.o"); Add_Str_To_Name_Buffer ("/*.o");
Name_Tables.Append Name_Tables.Append (M.C_Objs, Name_Find);
(M.C_Objs, Name_Find);
when others => when others =>
null; null;
...@@ -1322,7 +1464,7 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1322,7 +1464,7 @@ package body Ocarina.Backends.Build_Utils is
end if; end if;
Ada_C_Command_Line_Flags Ada_C_Command_Line_Flags
(M.Ada_Sources, M.C_Sources, M.C_Libraries); (M.Ada_Sources, M.C_Sources, M.CPP_Sources, M.C_Libraries);
if Length (M.Ada_Sources) > 0 then if Length (M.Ada_Sources) > 0 then
Write_Line ("USER_LD=gnatlink `cat ali_file`"); Write_Line ("USER_LD=gnatlink `cat ali_file`");
...@@ -1330,7 +1472,7 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1330,7 +1472,7 @@ package body Ocarina.Backends.Build_Utils is
else else
Write_Str ("C_OBJECTS="); Write_Str ("C_OBJECTS=");
Ada_C_Command_Line_Flags Ada_C_Command_Line_Flags
(M.Ada_Sources, M.C_Sources, M.C_Libraries); (M.Ada_Sources, M.C_Sources, M.CPP_Sources, M.C_Libraries);
end if; end if;
Write_Eol; Write_Eol;
...@@ -1357,6 +1499,9 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1357,6 +1499,9 @@ package body Ocarina.Backends.Build_Utils is
Compile_C_Files (M.C_Sources); Compile_C_Files (M.C_Sources);
Write_Eol; Write_Eol;
Compile_CPP_Files (M.CPP_Sources);
Write_Eol;
Compile_Ada_Files (M.Ada_Sources); Compile_Ada_Files (M.Ada_Sources);
Write_Eol; Write_Eol;
...@@ -1559,6 +1704,7 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1559,6 +1704,7 @@ package body Ocarina.Backends.Build_Utils is
procedure Ada_C_Command_Line_Flags procedure Ada_C_Command_Line_Flags
(Ada_Sources : Name_Tables.Instance; (Ada_Sources : Name_Tables.Instance;
C_Sources : Name_Tables.Instance; C_Sources : Name_Tables.Instance;
CPP_Sources : Name_Tables.Instance;
C_Libraries : Name_Tables.Instance) is C_Libraries : Name_Tables.Instance) is
begin begin
if Length (Ada_Sources) > 0 if Length (Ada_Sources) > 0
...@@ -1600,6 +1746,22 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1600,6 +1746,22 @@ package body Ocarina.Backends.Build_Utils is
end loop; end loop;
end if; end if;
if Length (CPP_Sources) > 0 then
for J in Name_Tables.First .. Name_Tables.Last (CPP_Sources) loop
Get_Name_String (CPP_Sources.Table (J));
Set_Str_To_Name_Buffer
(Base_Name (Name_Buffer (1 .. Name_Len)));
Name_Buffer (Name_Len - 1 .. Name_Len) := "o ";
Write_Name (Name_Find);
exit when J = Name_Tables.Last (CPP_Sources);
Write_Line (" \");
Write_Str (ASCII.HT & " ");
end loop;
end if;
-- In case of C libraries or objects, we add the -- In case of C libraries or objects, we add the
-- corresponding option. -- corresponding option.
...@@ -1637,6 +1799,9 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1637,6 +1799,9 @@ package body Ocarina.Backends.Build_Utils is
end if; end if;
Write_Eol; Write_Eol;
if Length (CPP_Sources) > 0 then
Write_Line ("USE_CPP_LINKER = true");
end if;
end Ada_C_Command_Line_Flags; end Ada_C_Command_Line_Flags;
--------------------- ---------------------
...@@ -1694,6 +1859,61 @@ package body Ocarina.Backends.Build_Utils is ...@@ -1694,6 +1859,61 @@ package body Ocarina.Backends.Build_Utils is
end if; end if;
end Compile_C_Files; end Compile_C_Files;
-----------------------
-- Compile_CPP_Files --
-----------------------
procedure Compile_CPP_Files (CPP_Sources : Name_Tables.Instance) is
begin
Write_Line ("compile-cpp-files:");
if Length (CPP_Sources) > 0 then
for J in Name_Tables.First .. Name_Tables.Last (CPP_Sources) loop
declare
O_File : Name_Id;
Include_Dir : Name_Id;
begin
Get_Name_String (CPP_Sources.Table (J));
Name_Buffer (Name_Len - 1 .. Name_Len) := "o ";
Set_Str_To_Name_Buffer
(Base_Name (Name_Buffer (1 .. Name_Len)));
O_File := Name_Find;
Get_Name_String (CPP_Sources.Table (J));
while (Name_Buffer (Name_Len) /= Directory_Separator)
and then
Name_Len > 0 loop
Name_Len := Name_Len - 1;
end loop;
if Name_Len > 0 then
Set_Str_To_Name_Buffer
(Name_Buffer (1 .. Name_Len));
Include_Dir := Name_Find;
else
Include_Dir := No_Name;
end if;
Write_Char (ASCII.HT);
Write_Str ("$(CC) -c $(INCLUDE) $(CFLAGS) ");
if Include_Dir /= No_Name then
Write_Str ("-I");
Write_Str ("'");
Write_Name (Include_Dir);
Write_Str ("'");
end if;
Write_Str (" '");
Write_Name (CPP_Sources.Table (J));
Write_Str ("' -o ");
Write_Name (O_File);
Write_Eol;
end;
end loop;
end if;
end Compile_CPP_Files;
----------------------- -----------------------
-- Compile_Ada_Files -- -- Compile_Ada_Files --
----------------------- -----------------------
......
...@@ -2320,6 +2320,7 @@ package body Ocarina.Backends.C_Common.Mapping is ...@@ -2320,6 +2320,7 @@ package body Ocarina.Backends.C_Common.Mapping is
(Spec, Declarations, Statements); (Spec, Declarations, Statements);
when Subprogram_Opaque_C when Subprogram_Opaque_C
| Subprogram_Opaque_CPP
| Subprogram_Default => | Subprogram_Default =>
-- Create function to lock the data. -- Create function to lock the data.
......
...@@ -1535,7 +1535,6 @@ package body Ocarina.Backends.Properties is ...@@ -1535,7 +1535,6 @@ package body Ocarina.Backends.Properties is
when Language_SDL when Language_SDL
| Language_SDL_RTDS | Language_SDL_RTDS
| Language_System_C | Language_System_C
| Language_CPP
| Language_SDL_OpenGEODE | Language_SDL_OpenGEODE
| Language_VHDL => | Language_VHDL =>
-- A subprogram having this language as implementation -- A subprogram having this language as implementation
...@@ -1569,6 +1568,32 @@ package body Ocarina.Backends.Properties is ...@@ -1569,6 +1568,32 @@ package body Ocarina.Backends.Properties is
return Subprogram_Opaque_C; return Subprogram_Opaque_C;
end if; end if;
when Language_CPP =>
if Src_Name /= No_Name or else Src_Files'Length > 0 then
if not Is_Empty (AIN.Calls (S)) and then
not Is_Empty (AIN.Subprogram_Calls
(AIN.First_Node (AIN.Calls (S))))
then
-- A subprogram having CPP as implementation
-- language, an implementation name and a *non
-- null* call sequence list is not supported yet.
return Subprogram_Unknown;
else
-- A subprogram having CPP as implementation
-- language, an implementation name and a *null*
-- call sequence list is an opaque C subprogram.
return Subprogram_Opaque_CPP;
end if;
else
-- A subprogram having CPP as implementation language
-- and a null source name and a null source text is a
-- wrong built subprogram.
return Subprogram_Opaque_CPP;
end if;
when Language_RTSJ => when Language_RTSJ =>
if Src_Name /= No_Name or else Src_Files'Length > 0 then if Src_Name /= No_Name or else Src_Files'Length > 0 then
if not Is_Empty (AIN.Calls (S)) and then if not Is_Empty (AIN.Calls (S)) and then
......
...@@ -514,6 +514,7 @@ package Ocarina.Backends.Properties is ...@@ -514,6 +514,7 @@ package Ocarina.Backends.Properties is
Subprogram_Opaque_Ada_95, Subprogram_Opaque_Ada_95,
Subprogram_Opaque_Ada_95_Transfo, Subprogram_Opaque_Ada_95_Transfo,
Subprogram_Opaque_C, Subprogram_Opaque_C,
Subprogram_Opaque_CPP,
Subprogram_Opaque_RTSJ, Subprogram_Opaque_RTSJ,
Subprogram_Simulink, Subprogram_Simulink,
Subprogram_Scade, Subprogram_Scade,
......
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