diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-08-13 07:53:09 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-08-13 07:53:09 +0200 |
commit | 7e91b1419cde2a00c9288c02cda256a054ed6a3f (patch) | |
tree | 10dcb172a22c93dd74adda6e8e6e0ed1677e95fb | |
parent | 9d61a62f96dc4897dadbf88f5f4ee199d20e0f8f (diff) | |
download | ghdl-7e91b1419cde2a00c9288c02cda256a054ed6a3f.tar.gz ghdl-7e91b1419cde2a00c9288c02cda256a054ed6a3f.tar.bz2 ghdl-7e91b1419cde2a00c9288c02cda256a054ed6a3f.zip |
libghdl: also add synthesis part. For #884
-rw-r--r-- | Makefile.in | 8 | ||||
-rw-r--r-- | src/ghdldrv/ghdlsynth.adb | 44 | ||||
-rw-r--r-- | src/ghdldrv/ghdlsynth.ads | 14 | ||||
-rw-r--r-- | src/synth/ghdlsynth.h | 7 | ||||
-rw-r--r-- | src/synth/libghdlsynth.adb | 33 | ||||
-rw-r--r-- | src/synth/libghdlsynth.ads | 8 | ||||
-rw-r--r-- | src/vhdl/libghdl/libghdl.ads | 2 |
7 files changed, 61 insertions, 55 deletions
diff --git a/Makefile.in b/Makefile.in index 0e7bf20c2..70a3a9863 100644 --- a/Makefile.in +++ b/Makefile.in @@ -380,20 +380,22 @@ uninstall.simul: uninstall.simul.program uninstall.vhdllib ################ libghdl (library for the vhdl part) #################### -LIBGHDL_INCFLAGS=$(GHDL_COMMON_INCFLAGS) -aI$(srcdir)/src/vhdl/libghdl -aI$(srcdir)/src/ghdldrv +LIBGHDL_INCFLAGS=$(GHDL_COMMON_INCFLAGS) -aI$(srcdir)/src/synth -aI$(srcdir)/src/vhdl/libghdl -aI$(srcdir)/src/ghdldrv libghdl_name=libghdl-$(libghdl_version)$(SOEXT) $(libghdl_name): $(GRT_SRC_DEPS) version.ads force - $(GNATMAKE) -I- -aI. -D pic -z libghdl -o $@ $(GNATFLAGS) $(PIC_FLAGS) $(LIBGHDL_INCFLAGS) -bargs -shared -Llibghdl_ -largs -shared $(SHLIB_FLAGS) + $(GNATMAKE) -I- -aI. -D pic -z libghdl -o $@ -gnat12 $(GNATFLAGS) $(PIC_FLAGS) $(LIBGHDL_INCFLAGS) -bargs -shared -Llibghdl_ -largs -shared $(SHLIB_FLAGS) all.libghdl.true: $(libghdl_name) all.libghdl.false: all.libghdl: all.libghdl.$(enable_libghdl) -install.libghdl.true: +install.libghdl.lib: $(INSTALL_PROGRAM) -p $(libghdl_name) $(DESTDIR)$(libdir)/ +install.libghdl.true: install.libghdl.lib + install.libghdl.false: install.libghdl: install.libghdl.$(enable_libghdl) diff --git a/src/ghdldrv/ghdlsynth.adb b/src/ghdldrv/ghdlsynth.adb index 1d4624985..87fde5b43 100644 --- a/src/ghdldrv/ghdlsynth.adb +++ b/src/ghdldrv/ghdlsynth.adb @@ -16,12 +16,15 @@ -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. +with GNAT.OS_Lib; use GNAT.OS_Lib; + with Types; use Types; with Ghdllocal; use Ghdllocal; with Ghdlcomp; use Ghdlcomp; with Ghdlmain; use Ghdlmain; with Options; use Options; with Errorout; +with Errorout.Console; with Libraries; with Flags; @@ -34,7 +37,6 @@ with Vhdl.Configuration; with Vhdl.Annotations; with Vhdl.Utils; -with Netlists; use Netlists; with Netlists.Dump; with Netlists.Disp_Vhdl; @@ -189,17 +191,42 @@ package body Ghdlsynth is return Config; end Ghdl_Synth_Configure; - function Ghdl_Synth (Args : Argument_List) return Module + function Ghdl_Synth (Argc : Natural; Argv : C_String_Array_Acc) + return Module is + Args : Argument_List (1 .. Argc); + Res : Module; + Cmd : Command_Acc; + First_Arg : Natural; Config : Node; begin - Config := Ghdl_Synth_Configure (Args); + -- Create arguments list. + for I in 0 .. Argc - 1 loop + declare + Arg : constant Ghdl_C_String := Argv (I); + begin + Args (I + 1) := new String'(Arg (1 .. strlen (Arg))); + end; + end loop; + + -- Find the command. This is a little bit convoluted... + Decode_Command_Options ("--synth", Cmd, Args, First_Arg); + -- Do the real work! + Config := Ghdl_Synth_Configure (Args (First_Arg .. Args'Last)); if Config = Null_Iir then return No_Module; end if; - return Synthesis.Synth_Design (Config); + Res := Synthesis.Synth_Design (Config); + return Res; + + exception + when Option_Error => + return No_Module; + when others => + -- Avoid possible issues with exceptions... + return No_Module; end Ghdl_Synth; procedure Perform_Action (Cmd : Command_Synth; @@ -225,7 +252,7 @@ package body Ghdlsynth is Netlists.Dump.Flag_Disp_Inline := Cmd.Disp_Inline; Netlists.Dump.Disp_Module (Res); when Format_Vhdl => - if True then + if Boolean'(True) then Ent := Vhdl.Utils.Get_Entity_From_Configuration (Config); Synth.Disp_Vhdl.Disp_Vhdl_Wrapper (Ent, Res); else @@ -238,4 +265,11 @@ package body Ghdlsynth is begin Ghdlmain.Register_Command (new Command_Synth); end Register_Commands; + + procedure Init_For_Ghdl_Synth is + begin + Ghdlsynth.Register_Commands; + Options.Initialize; + Errorout.Console.Install_Handler; + end Init_For_Ghdl_Synth; end Ghdlsynth; diff --git a/src/ghdldrv/ghdlsynth.ads b/src/ghdldrv/ghdlsynth.ads index f9a755c08..b4ad92b86 100644 --- a/src/ghdldrv/ghdlsynth.ads +++ b/src/ghdldrv/ghdlsynth.ads @@ -15,11 +15,19 @@ -- along with GCC; see the file COPYING. If not, write to the Free -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. -with Netlists; -with GNAT.OS_Lib; use GNAT.OS_Lib; +with Grt.Types; use Grt.Types; +with Netlists; use Netlists; package Ghdlsynth is procedure Register_Commands; - function Ghdl_Synth (Args : Argument_List) return Netlists.Module; + -- When used from a library, this init procedure must be called before + -- ghdl_synth. + procedure Init_For_Ghdl_Synth; + + type C_String_Array is array (Natural) of Ghdl_C_String; + type C_String_Array_Acc is access C_String_Array; + + function Ghdl_Synth (Argc : Natural; Argv : C_String_Array_Acc) + return Module; end Ghdlsynth; diff --git a/src/synth/ghdlsynth.h b/src/synth/ghdlsynth.h index 35d123f32..d8b5ec784 100644 --- a/src/synth/ghdlsynth.h +++ b/src/synth/ghdlsynth.h @@ -118,10 +118,10 @@ namespace GhdlSynth { GHDLSYNTH_ADA_WRAPPER_WWD(get_input_net, Net, Instance, Port_Idx); - extern "C" unsigned int libghdlsynth__synth(int argc, const char **argv); + extern "C" unsigned int ghdlsynth__ghdl_synth(int argc, const char **argv); inline Module ghdl_synth(int argc, const char **argv) { Module res; - res.id = libghdlsynth__synth(argc, argv); + res.id = ghdlsynth__ghdl_synth(argc, argv); return res; } @@ -129,6 +129,5 @@ namespace GhdlSynth { extern "C" void ghdlcomp__disp_config (void); // Initialize and finalize the whole library. - extern "C" void libghdlsynth_init (void); - extern "C" void libghdlsynth_final (void); + extern "C" void libghdl_init (void); }; diff --git a/src/synth/libghdlsynth.adb b/src/synth/libghdlsynth.adb index 0931b48b6..94fd62899 100644 --- a/src/synth/libghdlsynth.adb +++ b/src/synth/libghdlsynth.adb @@ -18,44 +18,11 @@ -- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, -- MA 02110-1301, USA. -with GNAT.OS_Lib; use GNAT.OS_Lib; - -with Ghdlmain; use Ghdlmain; with Ghdlsynth; with Options; use Options; with Errorout.Console; package body Libghdlsynth is - function Synth (Argc : Natural; Argv : C_String_Array_Acc) return Module - is - Args : Argument_List (1 .. Argc); - Res : Module; - Cmd : Command_Acc; - First_Arg : Natural; - begin - -- Create arguments list. - for I in 0 .. Argc - 1 loop - declare - Arg : constant Ghdl_C_String := Argv (I); - begin - Args (I + 1) := new String'(Arg (1 .. strlen (Arg))); - end; - end loop; - - -- Find the command. This is a little bit convoluted... - Decode_Command_Options ("--synth", Cmd, Args, First_Arg); - - -- Do the real work! - Res := Ghdlsynth.Ghdl_Synth (Args (First_Arg .. Args'Last)); - - return Res; - exception - when Option_Error => - return No_Module; - when others => - -- Avoid possible issues with exceptions... - return No_Module; - end Synth; Gnat_Version : constant String := "unknown compiler version" & ASCII.NUL; pragma Export (C, Gnat_Version, "__gnat_version"); diff --git a/src/synth/libghdlsynth.ads b/src/synth/libghdlsynth.ads index 0824dea69..97f5c3378 100644 --- a/src/synth/libghdlsynth.ads +++ b/src/synth/libghdlsynth.ads @@ -18,12 +18,6 @@ -- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, -- MA 02110-1301, USA. -with Grt.Types; use Grt.Types; -with Netlists; use Netlists; - package Libghdlsynth is - type C_String_Array is array (Natural) of Ghdl_C_String; - type C_String_Array_Acc is access C_String_Array; - - function Synth (Argc : Natural; Argv : C_String_Array_Acc) return Module; + pragma Elaborate_Body; end Libghdlsynth; diff --git a/src/vhdl/libghdl/libghdl.ads b/src/vhdl/libghdl/libghdl.ads index 4d1595a10..7d69cde23 100644 --- a/src/vhdl/libghdl/libghdl.ads +++ b/src/vhdl/libghdl/libghdl.ads @@ -18,6 +18,8 @@ with Types; use Types; with Vhdl.Nodes; use Vhdl.Nodes; +with Ghdlsynth_Maybe; +pragma Unreferenced (Ghdlsynth_Maybe); package Libghdl is -- Perform early initializations, and set hooks. |