aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2016-05-17 05:49:14 +0200
committerTristan Gingold <tgingold@free.fr>2016-05-17 05:49:14 +0200
commit2c4f02de9ba36dbe52e661b50b67fbe14e92ae6e (patch)
tree14694b31fd2f25612d5a1f1487ec9106c5b9cbea
parent8574c1ae9bf66e3520985e0277a3847b1a210e2e (diff)
downloadghdl-2c4f02de9ba36dbe52e661b50b67fbe14e92ae6e.tar.gz
ghdl-2c4f02de9ba36dbe52e661b50b67fbe14e92ae6e.tar.bz2
ghdl-2c4f02de9ba36dbe52e661b50b67fbe14e92ae6e.zip
mhdlsim: add initial version of the vhdl part (as a library).
-rw-r--r--Makefile.in12
-rw-r--r--src/mhdlsim/grt-modules.adb41
-rw-r--r--src/mhdlsim/mhdlsim.adb71
-rw-r--r--src/mhdlsim/mhdlsim.ads23
4 files changed, 147 insertions, 0 deletions
diff --git a/Makefile.in b/Makefile.in
index 1075b50bd..4d043dd95 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -249,6 +249,18 @@ ghdl_simul: $(GRT_ADD_OBJS) $(GRT_SRC_DEPS) force
libs.vhdl.simul: ghdl_simul
$(MAKE) GHDL=ghdl_simul vhdl.libs.all
+################ mhdlsim (library for the vhdl part) ####################
+
+GHDL_MHDLSIM_INCFLAGS=$(GHDL_COMMON_INCFLAGS) -aI$(srcdir)/src/mhdlsim -aI$(srcdir)/src/ghdldrv -aI$(srcdir)/src/vhdl/simulate -aI$(srcdir)/src/grt
+
+libmhdlsimvhdl.a: $(GRT_ADD_OBJS) $(GRT_SRC_DEPS) force
+ $(GNATMAKE) -c mhdlsim $(GNATFLAGS) $(GHDL_MHDLSIM_INCFLAGS)
+ gnatbind -Lmhdlsim_vhdl_ mhdlsim.ali -O > mhdlsim.files
+ gnatbind -Lmhdlsim_vhdl_ mhdlsim.ali -K -Z > mhdlsim.link
+ $(GNATMAKE) -c b~mhdlsim.adb
+ rm -f $@
+ ar rc $@ b~mhdlsim.o `cat mhdlsim.files` $(GRT_ADD_OBJS)
+
################ ghwdump #################################################
GHWDUMP_OBJS=ghwdump.o ghwlib.o
diff --git a/src/mhdlsim/grt-modules.adb b/src/mhdlsim/grt-modules.adb
new file mode 100644
index 000000000..7f40b0536
--- /dev/null
+++ b/src/mhdlsim/grt-modules.adb
@@ -0,0 +1,41 @@
+-- GHDL Run Time (GRT) - Modules.
+-- Copyright (C) 2005 - 2014 Tristan Gingold
+--
+-- GHDL is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by the Free
+-- Software Foundation; either version 2, or (at your option) any later
+-- version.
+--
+-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or
+-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+-- for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- 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.
+--
+-- As a special exception, if other files instantiate generics from this
+-- unit, or you link this unit with other files to produce an executable,
+-- this unit does not by itself cause the resulting executable to be
+-- covered by the GNU General Public License. This exception does not
+-- however invalidate any other reasons why the executable file might be
+-- covered by the GNU Public License.
+with Grt.Vital_Annotate;
+with Grt.Disp_Tree;
+with Grt.Disp_Rti;
+with Grt.Psl;
+with Grt.Backtraces;
+
+package body Grt.Modules is
+ procedure Register_Modules is
+ begin
+ -- List of modules to be registered.
+ Grt.Disp_Tree.Register;
+ Grt.Vital_Annotate.Register;
+ Grt.Disp_Rti.Register;
+ Grt.Psl.Register;
+ Grt.Backtraces.Register;
+ end Register_Modules;
+end Grt.Modules;
diff --git a/src/mhdlsim/mhdlsim.adb b/src/mhdlsim/mhdlsim.adb
new file mode 100644
index 000000000..ba4a07700
--- /dev/null
+++ b/src/mhdlsim/mhdlsim.adb
@@ -0,0 +1,71 @@
+with Types; use Types;
+with Options;
+with Name_Table;
+with Iirs; use Iirs;
+with Libraries;
+with Errorout;
+with Ghdlcomp;
+with Ghdlsimul;
+
+package body Mhdlsim is
+ -- Top unit to elaborate or simulate. Might not be a VHDL unit.
+ Top_Name : Name_Id;
+ Top_Unit : Iir;
+
+ function Process_Param (Opt : Ghdl_C_String; Len : Natural)
+ return Integer is
+ begin
+ if Len > 3 and then Opt (1 .. 3) = "-e " then
+ -- Unit to elaborate
+ Top_Name := Name_Table.Get_Identifier (Opt (4 .. Len));
+ return 0;
+ elsif Options.Parse_Option (Opt (1 .. Len)) then
+ -- Ok.
+ return 0;
+ else
+ -- Error.
+ return 1;
+ end if;
+ end Process_Param;
+
+ procedure Analyze_Init is
+ begin
+ -- Load libraries...
+ Ghdlcomp.Compile_Analyze_Init (False);
+ end Analyze_Init;
+
+ function Analyze_File (File : Ghdl_C_String; Len : Natural)
+ return Integer is
+ begin
+ Ghdlcomp.Compile_Analyze_File (File (1 .. Len));
+ if Errorout.Nbr_Errors > 0 then
+ return 1;
+ else
+ return 0;
+ end if;
+ end Analyze_File;
+
+ function Known_Top_Unit return Integer
+ is
+ use Libraries;
+ begin
+ Top_Unit := Find_Primary_Unit (Work_Library, Top_Name);
+ return Boolean'Pos (Top_Unit /= Null_Iir);
+ end Known_Top_Unit;
+
+ procedure Elaborate is
+ begin
+ Ghdlcomp.Compile_Elaborate (new String'(Name_Table.Image (Top_Name)));
+ end Elaborate;
+
+ procedure Run is
+ begin
+ Ghdlcomp.Compile_Run;
+ end Run;
+
+ Gnat_Version : constant String := "unknown compiler version" & ASCII.NUL;
+ pragma Export (C, Gnat_Version, "__gnat_version");
+begin
+ -- TODO: set program name.
+ Ghdlsimul.Compile_Init;
+end Mhdlsim;
diff --git a/src/mhdlsim/mhdlsim.ads b/src/mhdlsim/mhdlsim.ads
new file mode 100644
index 000000000..ef1eed275
--- /dev/null
+++ b/src/mhdlsim/mhdlsim.ads
@@ -0,0 +1,23 @@
+with Grt.Types; use Grt.Types;
+
+package Mhdlsim is
+ function Process_Param (Opt : Ghdl_C_String; Len : Natural)
+ return Integer;
+ pragma Export (C, Process_Param, "mhdlsim_vhdl_process_param");
+
+ procedure Analyze_Init;
+ pragma Export (C, Analyze_Init, "mhdlsim_vhdl_analyze_init");
+
+ function Analyze_File (File : Ghdl_C_String; Len : Natural)
+ return Integer;
+ pragma Export (C, Analyze_File, "mhdlsim_vhdl_analyze_file");
+
+ function Known_Top_Unit return Integer;
+ pragma Export (C, Known_Top_Unit, "mhdlsim_vhdl_known_top_unit");
+
+ procedure Elaborate;
+ pragma Export (C, Elaborate, "mhdlsim_vhdl_elaborate");
+
+ procedure Run;
+ pragma Export (C, Run, "mhdlsim_vhdl_run");
+end Mhdlsim;