Introduce PCB code generator.

This commit is contained in:
Stephen Williams 2011-12-20 14:16:54 -06:00
parent b37d806ee1
commit 9075326bb7
10 changed files with 432 additions and 2 deletions

1
.gitignore vendored
View File

@ -28,6 +28,7 @@ Makefile
/_pli_types.h
config.h
/tgt-pcb/pcb_config.h
/tgt-vvp/vvp_config.h
/tgt-vhdl/vhdl_config.h
/vpi/vpi_config.h

View File

@ -39,7 +39,7 @@ srcdir = @srcdir@
datarootdir = @datarootdir@
SUBDIRS = ivlpp vhdlpp vvp vpi libveriuser cadpli tgt-null tgt-stub tgt-vvp \
tgt-vhdl tgt-vlog95 driver
tgt-vhdl tgt-vlog95 tgt-pcb driver
# Only run distclean for these directories.
NOTUSED = tgt-fpga tgt-pal tgt-verilog

View File

@ -8,6 +8,7 @@ AC_CONFIG_HEADER(vpi/vpi_config.h)
AC_CONFIG_HEADER(libveriuser/config.h)
AC_CONFIG_HEADER(tgt-vvp/vvp_config.h)
AC_CONFIG_HEADER(tgt-vhdl/vhdl_config.h)
AC_CONFIG_HEADER(tgt-pcb/pcb_config.h)
AC_CANONICAL_HOST
dnl Checks for programs.
@ -299,4 +300,4 @@ AC_MSG_RESULT(ok)
# XXX disable tgt-fpga for the moment
AC_OUTPUT(Makefile ivlpp/Makefile vhdlpp/Makefile vvp/Makefile vpi/Makefile driver/Makefile driver-vpi/Makefile cadpli/Makefile libveriuser/Makefile tgt-null/Makefile tgt-stub/Makefile tgt-vvp/Makefile tgt-vhdl/Makefile tgt-fpga/Makefile tgt-verilog/Makefile tgt-pal/Makefile tgt-vlog95/Makefile)
AC_OUTPUT(Makefile ivlpp/Makefile vhdlpp/Makefile vvp/Makefile vpi/Makefile driver/Makefile driver-vpi/Makefile cadpli/Makefile libveriuser/Makefile tgt-null/Makefile tgt-stub/Makefile tgt-vvp/Makefile tgt-vhdl/Makefile tgt-fpga/Makefile tgt-verilog/Makefile tgt-pal/Makefile tgt-vlog95/Makefile tgt-pcb/Makefile)

109
tgt-pcb/Makefile.in Normal file
View File

@ -0,0 +1,109 @@
#
# 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
#
SHELL = /bin/sh
suffix = @install_suffix@
prefix = @prefix@
exec_prefix = @exec_prefix@
srcdir = @srcdir@
VPATH = $(srcdir)
bindir = @bindir@
libdir = @libdir@
CC = @CC@
CXX = @CXX@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
ifeq (@srcdir@,.)
INCLUDE_PATH = -I. -I..
else
INCLUDE_PATH = -I. -I.. -I$(srcdir) -I$(srcdir)/..
endif
CPPFLAGS = $(INCLUDE_PATH) @CPPFLAGS@ @DEFS@ @PICFLAG@
CFLAGS = @WARNING_FLAGS@ @CFLAGS@
LDFLAGS = @LDFLAGS@
O = pcb.o scope.o show_netlist.o
all: dep pcb.tgt
check: all
clean:
rm -rf *.o dep pcb.tgt
distclean: clean
rm -f Makefile config.log
cppcheck: $(O:.o=.c)
cppcheck --enable=all -f $(INCLUDE_PATH) $^
Makefile: $(srcdir)/Makefile.in ../config.status
cd ..; ./config.status --file=tgt-pcb/$@
dep:
mkdir dep
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) @DEPENDENCY_FLAG@ -c $< -o $*.o
mv $*.d dep
%.o: %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) @DEPENDENCY_FLAG@ -c $< -o $*.o
mv $*.d dep
ifeq (@WIN32@,yes)
TGTLDFLAGS=-L.. -livl
TGTDEPLIBS=../libivl.a
else
TGTLDFLAGS=
TGTDEPLIBS=
endif
pcb.tgt: $O $(TGTDEPLIBS)
$(CC) @shared@ -o $@ $O $(TGTLDFLAGS)
install: all installdirs $(libdir)/ivl$(suffix)/pcb.tgt $(INSTALL_DOC) $(libdir)/ivl$(suffix)/pcb.conf $(libdir)/ivl$(suffix)/pcb-s.conf
$(libdir)/ivl$(suffix)/pcb.tgt: ./pcb.tgt
$(INSTALL_PROGRAM) ./pcb.tgt "$(DESTDIR)$(libdir)/ivl$(suffix)/pcb.tgt"
$(libdir)/ivl$(suffix)/pcb.conf: $(srcdir)/pcb.conf
$(INSTALL_DATA) $(srcdir)/pcb.conf "$(DESTDIR)$(libdir)/ivl$(suffix)/pcb.conf"
$(libdir)/ivl$(suffix)/pcb-s.conf: $(srcdir)/pcb-s.conf
$(INSTALL_DATA) $(srcdir)/pcb-s.conf "$(DESTDIR)$(libdir)/ivl$(suffix)/pcb-s.conf"
installdirs: $(srcdir)/../mkinstalldirs
$(srcdir)/../mkinstalldirs "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libdir)/ivl$(suffix)"
uninstall:
rm -f "$(DESTDIR)$(libdir)/ivl$(suffix)/pcb.tgt"
rm -f "$(DESTDIR)$(libdir)/ivl$(suffix)/pcb.conf"
rm -f "$(DESTDIR)$(libdir)/ivl$(suffix)/pcb-s.conf"
-include $(patsubst %.o, dep/%.d, $O)

91
tgt-pcb/pcb.cc Normal file
View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2011 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
*/
/*
* This is a PCB target module.
*/
# include "version_base.h"
# include "version_tag.h"
# include "pcb_config.h"
# include <string.h>
# include <stdio.h>
# include "pcb_priv.h"
# include "ivl_target.h"
static const char*version_string =
"Icarus Verilog PCB Netlist Generator " VERSION " (" VERSION_TAG ")\n\n"
"Copyright (c) 2011 Stephen Williams (steve@icarus.com)\n\n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 2 of the License, or\n"
" (at your option) any later version.\n"
"\n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License along\n"
" with this program; if not, write to the Free Software Foundation, Inc.,\n"
" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
;
int target_design(ivl_design_t des)
{
ivl_scope_t*root_scopes;
unsigned nroot;
unsigned idx;
FILE*fnet;
int rc = 0;
const char*path = ivl_design_flag(des, "-o");
if (path == 0) {
return -1;
}
fnet = fopen(path, "w");
if (fnet == 0) {
perror (path);
return -2;
}
ivl_design_roots(des, &root_scopes, &nroot);
for (idx = 0 ; idx < nroot ; idx += 1) {
int tmp = scan_scope(root_scopes[idx]);
if (tmp != 0) {
rc = tmp;
break;
}
}
show_netlist(fnet);
fclose(fnet);
return rc;
}
const char* target_query(const char*key)
{
if (strcmp(key,"version") == 0)
return version_string;
return 0;
}

3
tgt-pcb/pcb.conf Normal file
View File

@ -0,0 +1,3 @@
functor:cprop
functor:nodangle
flag:DLL=pcb.tgt

28
tgt-pcb/pcb_config.h.in Normal file
View File

@ -0,0 +1,28 @@
#ifndef __pcb_config_H
#define __pcb_config_H
/*
* Copyright (c) 2011 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
*/
# undef HAVE_STDINT_H
# undef HAVE_INTTYPES_H
# undef _LARGEFILE_SOURCE
# undef _LARGEFILE64_SOURCE
#endif /* __pcb_config_H */

39
tgt-pcb/pcb_priv.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef __pcb_priv_H
#define __pcb_priv_H
/*
* Copyright (c) 2011 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
*/
# include <string>
# include <set>
# include <list>
# include <cstdio>
# include <ivl_target.h>
extern int scan_scope(ivl_scope_t scope);
struct nexus_data {
std::string name;
std::set<std::string> pins;
};
extern std::list<struct nexus_data*> nexus_list;
extern void show_netlist(FILE*fnet);
#endif

121
tgt-pcb/scope.cc Normal file
View File

@ -0,0 +1,121 @@
/*
* Copyright (c) 2011 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
*/
# include "pcb_priv.h"
# include <cstring>
# include <cassert>
using namespace std;
list<struct nexus_data*> nexus_list;
static void sheet_box(ivl_scope_t scope);
static void black_box(ivl_scope_t scope);
static string wire_name(ivl_signal_t sig);
int scan_scope(ivl_scope_t scope)
{
int black_box_flag = 0;
int idx;
// Scan the attributes, looking in particular for the
// black_box attribute.
for (idx = 0 ; idx < ivl_scope_attr_cnt(scope) ; idx += 1) {
ivl_attribute_t attr = ivl_scope_attr_val(scope, idx);
if (strcmp(attr->key, "ivl_black_box") == 0)
black_box_flag = 1;
}
// If this scope is a black box, then process it
// so. Otherwise, process it as a sheet, which will recurse.
if (black_box_flag) {
black_box(scope);
} else {
sheet_box(scope);
}
return 0;
}
static int child_scan_fun(ivl_scope_t scope, void*)
{
int rc = scan_scope(scope);
return 0;
}
void sheet_box(ivl_scope_t scope)
{
printf("Sheet %s...\n", ivl_scope_name(scope));
unsigned sigs = ivl_scope_sigs(scope);
for (unsigned idx = 0 ; idx < sigs ; idx += 1) {
ivl_signal_t sig = ivl_scope_sig(scope, idx);
printf(" Wire %s\n", ivl_signal_basename(sig));
assert(ivl_signal_array_count(sig) == 1);
ivl_nexus_t nex = ivl_signal_nex(sig, 0);
struct nexus_data*nex_data = reinterpret_cast<nexus_data*>
(ivl_nexus_get_private(nex));
if (nex_data == 0) {
nex_data = new nexus_data;
nex_data->name = wire_name(sig);
nexus_list.push_back(nex_data);
ivl_nexus_set_private(nex, nex_data);
}
}
ivl_scope_children(scope, child_scan_fun, 0);
}
/*
* A black box is a component. Do not process the contents, other then
* to get at the ports that we'll attach to the netlist.
*/
static void black_box(ivl_scope_t scope)
{
assert(ivl_scope_type(scope) == IVL_SCT_MODULE);
printf(" Component %s is %s\n", ivl_scope_name(scope), ivl_scope_tname(scope));
unsigned sigs = ivl_scope_sigs(scope);
for (unsigned idx = 0 ; idx < sigs ; idx += 1) {
ivl_signal_t sig = ivl_scope_sig(scope, idx);
ivl_signal_port_t sip = ivl_signal_port(sig);
// Skip signals that are not ports.
if (sip == IVL_SIP_NONE)
continue;
assert(ivl_signal_array_count(sig) == 1);
ivl_nexus_t nex = ivl_signal_nex(sig, 0);
struct nexus_data*nex_data = reinterpret_cast<struct nexus_data*>(ivl_nexus_get_private(nex));
assert(nex_data);
string refdes = ivl_scope_basename(scope);
string pindes = ivl_signal_basename(sig);
string pin = refdes + "-" + pindes;
nex_data->pins.insert(pin);
printf(" port %s\n", ivl_signal_basename(sig));
}
}
static string wire_name(ivl_signal_t sig)
{
string res = ivl_signal_basename(sig);
return res;
}

37
tgt-pcb/show_netlist.cc Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2011 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
*/
# include "pcb_priv.h"
using namespace std;
void show_netlist(FILE*fnet)
{
for (list<nexus_data*>::iterator cur = nexus_list.begin()
; cur != nexus_list.end() ; ++ cur) {
nexus_data*curp = *cur;
fprintf(fnet, "%s", curp->name.c_str());
for (set<string>::const_iterator cp = curp->pins.begin()
; cp != curp->pins.end() ; ++ cp) {
fprintf(fnet, " %s", cp->c_str());
}
fprintf(fnet, "\n");
}
}