From 566aad9e15047d9043d1c8ce3ab051c765a71e04 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 12 Aug 2000 16:34:37 +0000 Subject: [PATCH] Start stub for loadable targets. --- Makefile.in | 11 ++++-- configure.in | 6 +-- ivl_target.h | 81 +++++++++++++++++++++++++++++++++++++++ t-dll.cc | 91 ++++++++++++++++++++++++++++++++++++++++++++ targets.cc | 7 +++- tgt-stub/.cvsignore | 3 ++ tgt-stub/Makefile.in | 75 ++++++++++++++++++++++++++++++++++++ tgt-stub/stub.c | 57 +++++++++++++++++++++++++++ 8 files changed, 323 insertions(+), 8 deletions(-) create mode 100644 ivl_target.h create mode 100644 t-dll.cc create mode 100644 tgt-stub/.cvsignore create mode 100644 tgt-stub/Makefile.in create mode 100644 tgt-stub/stub.c diff --git a/Makefile.in b/Makefile.in index 18535bfd3..1ed8871de 100644 --- a/Makefile.in +++ b/Makefile.in @@ -18,7 +18,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.61 2000/07/14 06:12:56 steve Exp $" +#ident "$Id: Makefile.in,v 1.62 2000/08/12 16:34:37 steve Exp $" # # SHELL = /bin/sh @@ -36,6 +36,9 @@ libdir = $(exec_prefix)/lib mandir = @mandir@ includedir = $(prefix)/include +dllib=@DLLIB@ +rdynamic=@rdynamic@ + CC = @CC@ CXX = @CXX@ INSTALL = @INSTALL@ @@ -66,7 +69,7 @@ distclean: clean rm -f config.status config.cache config.log rm -f Makefile -TT = t-null.o t-verilog.o t-vvm.o t-xnf.o +TT = t-dll.o t-null.o t-verilog.o t-vvm.o t-xnf.o FF = nodangle.o synth.o syn-rules.o xnfio.o O = main.o cprop.o design_dump.o dup_expr.o elaborate.o elab_expr.o \ @@ -101,10 +104,10 @@ verilog: $(srcdir)/verilog.sh -e 's;@$(tmp4)@;@CXX@;' < $< > $@ ivl: $O - $(CXX) $(CXXFLAGS) -o ivl $O + $(CXX) $(CXXFLAGS) $(rdynamic) -o ivl $O $(dllib) iverilog: iverilog.c - $(CC) $(CPPFLAGS) -o iverilog -DCXX='"@CXX@"' -DIVL_ROOT='"@libdir@/ivl"' -DIVL_INC='"@includedir@"' -DIVL_LIB='"@libdir@"' -DDLLIB='"@DLLIB@"' iverilog.c + $(CC) $(CPPFLAGS) -o iverilog -DCXX='"@CXX@"' -DIVL_ROOT='"@libdir@/ivl"' -DIVL_INC='"@includedir@"' -DIVL_LIB='"@libdir@"' -DRDYNAMIC=\"$(rdynamic)\" -DDLLIB='"@DLLIB@"' iverilog.c %.o dep/%.d: %.cc @[ -d dep ] || mkdir dep diff --git a/configure.in b/configure.in index 6089ef2ac..fb043b22f 100644 --- a/configure.in +++ b/configure.in @@ -71,8 +71,8 @@ case "${host}" in esac -AC_DEFINE_UNQUOTED(RDYNAMIC,"${rdynamic}") +AC_SUBST(rdynamic) -AC_MSG_RESULT("$RDYNAMIC") +AC_MSG_RESULT($rdynamic) -AC_OUTPUT(Makefile vpi/Makefile ivlpp/Makefile vvm/Makefile) +AC_OUTPUT(Makefile vpi/Makefile ivlpp/Makefile vvm/Makefile tgt-stub/Makefile) diff --git a/ivl_target.h b/ivl_target.h new file mode 100644 index 000000000..51e0204f1 --- /dev/null +++ b/ivl_target.h @@ -0,0 +1,81 @@ +#ifndef __ivl_target_H +#define __ivl_target_H +/* + * Copyright (c) 2000 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(WINNT) && !defined(macintosh) +#ident "$Id: ivl_target.h,v 1.1 2000/08/12 16:34:37 steve Exp $" +#endif + +#ifdef __cplusplus +#define _BEGIN_DECL extern "C" { +#define _END_DECL } +#else +#define _BEGIN_DECL +#define _END_DECL +#endif + + +_BEGIN_DECL + +/* + * This header file describes the API for the loadable target + * module. The main program can load these modules and access the + * functions within the loaded module to implement the backend + * behavior. + */ + + +/* This is the opaque type of an entire design. This type is used when + requesting an operation that affects the entire netlist. */ +typedef struct ivl_design_s *ivl_design_t; + + +/* This function returns the string value of the named flag. The key + is used to select the flag. If the key does not exist or the flag + does not have a value, this function returns 0. */ +extern const char* ivl_get_flag(ivl_design_t, const char*key); + + + /* TARGET MODULE ENTRY POINTS */ + +/* target_start_design (required) + + The "target_start_design" function is called once before + any other functions in order to start the processing of the + netlist. The function returns a value <0 if there is an error. */ +typedef int (*start_design_f)(ivl_design_t); + + +/* target_end_design (required) + + The target_end_design function in the loaded module is called once + to clean up (for example to close files) from handling of the + netlist. */ +typedef void (*end_design_f)(ivl_design_t); + + +_END_DECL + +/* + * $Log: ivl_target.h,v $ + * Revision 1.1 2000/08/12 16:34:37 steve + * Start stub for loadable targets. + * + */ +#endif diff --git a/t-dll.cc b/t-dll.cc new file mode 100644 index 000000000..f2e110561 --- /dev/null +++ b/t-dll.cc @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2000 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(WINNT) && !defined(macintosh) +#ident "$Id: t-dll.cc,v 1.1 2000/08/12 16:34:37 steve Exp $" +#endif + +# include "target.h" +# include "ivl_target.h" +# include + +struct ivl_design_s { + const Design*des_; +}; + +/* + * The DLL target type loads a named object file to handle the process + * of scanning the netlist. When it is time to start the design, I + * locate and link in the desired DLL, then start calling methods. The + * DLL will call me back to get information out of the netlist in + * particular. + */ +struct dll_target : public target_t { + + bool start_design(const Design*); + void end_design(const Design*); + + void*dll_; + + struct ivl_design_s ivl_des; + + start_design_f start_design_; + end_design_f end_design_; + +} dll_target_obj; + + +bool dll_target::start_design(const Design*des) +{ + dll_ = dlopen(des->get_flag("DLL").c_str(), RTLD_NOW); + if (dll_ == 0) { + cerr << des->get_flag("DLL") << ": " << dlerror() << endl; + return false; + } + + ivl_des.des_ = des; + + start_design_ = (start_design_f)dlsym(dll_, "target_start_design"); + end_design_ = (end_design_f) dlsym(dll_, "target_end_design"); + (start_design_)(&ivl_des); + return true; +} + +void dll_target::end_design(const Design*) +{ + (end_design_)(&ivl_des); + dlclose(dll_); +} + +extern const struct target tgt_dll = { "dll", &dll_target_obj }; + + +/* THE FOLLOWING ARE FUNCTIONS THAT ARE CALLED FROM THE TARGET. */ + +extern "C" const char*ivl_get_flag(ivl_design_t des, const char*key) +{ + return des->des_->get_flag(key).c_str(); +} + +/* + * $Log: t-dll.cc,v $ + * Revision 1.1 2000/08/12 16:34:37 steve + * Start stub for loadable targets. + * + */ + diff --git a/targets.cc b/targets.cc index f69a720f3..dad859c12 100644 --- a/targets.cc +++ b/targets.cc @@ -17,11 +17,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: targets.cc,v 1.5 2000/02/23 02:56:56 steve Exp $" +#ident "$Id: targets.cc,v 1.6 2000/08/12 16:34:37 steve Exp $" #endif # include "target.h" +extern const struct target tgt_dll; extern const struct target tgt_null; //extern const struct target tgt_verilog; extern const struct target tgt_vvm; @@ -29,6 +30,7 @@ extern const struct target tgt_xnf; const struct target *target_table[] = { &tgt_null, + &tgt_dll, //&tgt_verilog, &tgt_vvm, &tgt_xnf, @@ -37,6 +39,9 @@ const struct target *target_table[] = { /* * $Log: targets.cc,v $ + * Revision 1.6 2000/08/12 16:34:37 steve + * Start stub for loadable targets. + * * Revision 1.5 2000/02/23 02:56:56 steve * Macintosh compilers do not support ident. * diff --git a/tgt-stub/.cvsignore b/tgt-stub/.cvsignore new file mode 100644 index 000000000..bc089632f --- /dev/null +++ b/tgt-stub/.cvsignore @@ -0,0 +1,3 @@ +stub.tgt +Makefile +dep diff --git a/tgt-stub/Makefile.in b/tgt-stub/Makefile.in new file mode 100644 index 000000000..274c9118b --- /dev/null +++ b/tgt-stub/Makefile.in @@ -0,0 +1,75 @@ +# +# This source code is free software; you can redistribute it +# and/or modify it in source code form under the terms of the GNU +# Library General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program 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 Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., +# 59 Temple Place - Suite 330 +# Boston, MA 02111-1307, USA +# +#ident "$Id: Makefile.in,v 1.1 2000/08/12 16:34:37 steve Exp $" +# +# +SHELL = /bin/sh + +VERSION = 0.0 + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +srcdir = @srcdir@ + +VPATH = $(srcdir) + +bindir = $(exec_prefix)/bin +libdir = $(exec_prefix)/lib +includedir = $(prefix)/include + +CC = @CC@ +CXX = @CXX@ +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ + +CPPFLAGS = @CPPFLAGS@ @DEFS@ -fpic +CXXFLAGS = @CXXFLAGS@ +LDFLAGS = @LDFLAGS@ + +all: stub.tgt + +%.o dep/%.d: %.c + @[ -d dep ] || mkdir dep + $(CC) -Wall $(CPPFLAGS) -I$(srcdir) -MD -c $< -o $*.o + mv $*.d dep + +O = stub.o + +stub.tgt: $O + $(CC) -shared -o $@ $O + +clean: + rm -f *.o dep/*.d + +install: all installdirs $(libdir)/ivl/stub.tgt \ + $(includedir)/vpi_user.h + +$(libdir)/ivl/stub.tgt: ./stub.tgt + $(INSTALL_DATA) ./stub.tgt $(libdir)/ivl/stub.tgt + + +installdirs: ../mkinstalldirs + $(srcdir)/../mkinstalldirs $(includedir) $(bindir) $(libdir)/ivl + +uninstall: + rm -f $(libdir)/ivl/stub.tgt + + +-include $(patsubst %.o, dep/%.d, $O) diff --git a/tgt-stub/stub.c b/tgt-stub/stub.c new file mode 100644 index 000000000..f740647ff --- /dev/null +++ b/tgt-stub/stub.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2000 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(WINNT) && !defined(macintosh) +#ident "$Id: stub.c,v 1.1 2000/08/12 16:34:37 steve Exp $" +#endif + +# include +# include + +static FILE*out; + +int target_start_design(ivl_design_t des) +{ + const char*path = ivl_get_flag(des, "-o"); + if (path == 0) { + return -1; + } + + out = fopen(path, "w"); + if (out == 0) { + perror(path); + return -2; + } + + fprintf(out, "STUB: start_design\n"); + return 0; +} + +void target_end_design(ivl_design_t des) +{ + fprintf(out, "STUB: end_design\n"); + fclose(out); +} + +/* + * $Log: stub.c,v $ + * Revision 1.1 2000/08/12 16:34:37 steve + * Start stub for loadable targets. + * + */ +