Do not set width too small to hold significant bits.
This commit is contained in:
parent
e78af393de
commit
906c7b4783
178
iverilog.c
178
iverilog.c
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: iverilog.c,v 1.4 2000/04/23 21:14:32 steve Exp $"
|
#ident "$Id: iverilog.c,v 1.5 2000/04/26 03:33:32 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -36,27 +36,44 @@ const char*start = 0;
|
||||||
|
|
||||||
int verbose_flag = 0;
|
int verbose_flag = 0;
|
||||||
|
|
||||||
static char cmdline[8192];
|
char tmp[4096];
|
||||||
|
|
||||||
static int t_null()
|
static int t_null(char*cmd, unsigned ncmd)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
strcat(cmdline, " | ");
|
sprintf(tmp, " | %s/ivl ", base);
|
||||||
strcat(cmdline, base);
|
rc = strlen(tmp);
|
||||||
strcat(cmdline, "/ivl ");
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
ncmd += rc;
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
strcat(cmdline, " -s ");
|
sprintf(tmp, " -s%s", start);
|
||||||
strcat(cmdline, start);
|
rc = strlen(tmp);
|
||||||
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
}
|
}
|
||||||
if (verbose_flag)
|
|
||||||
strcat(cmdline, "-v ");
|
if (verbose_flag) {
|
||||||
strcat(cmdline, "-- -");
|
sprintf(tmp, " -v");
|
||||||
|
rc = strlen(tmp);
|
||||||
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(tmp, " -- -");
|
||||||
|
rc = strlen(tmp);
|
||||||
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
|
|
||||||
if (verbose_flag)
|
if (verbose_flag)
|
||||||
printf("translate: %s\n", cmdline);
|
printf("translate: %s\n", cmd);
|
||||||
|
|
||||||
rc = system(cmdline);
|
rc = system(cmd);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,71 +82,93 @@ static int t_null()
|
||||||
* ivl translator to get C++, then run g++ to make an executable
|
* ivl translator to get C++, then run g++ to make an executable
|
||||||
* program out of that.
|
* program out of that.
|
||||||
*/
|
*/
|
||||||
static int t_vvm()
|
static int t_vvm(char*cmd, unsigned ncmd)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
strcat(cmdline, " | ");
|
sprintf(tmp, " | %s/ivl -o %s.cc -tvvm -Fcprop -Fnodangle -fVPI_MODULE_PATH=%s", base, opath, base);
|
||||||
strcat(cmdline, base);
|
|
||||||
strcat(cmdline, "/ivl -o ");
|
|
||||||
strcat(cmdline, opath);
|
|
||||||
strcat(cmdline, ".cc -tvvm -Fcprop -Fnodangle -fVPI_MODULE_PATH=");
|
|
||||||
strcat(cmdline, base);
|
|
||||||
if (start) {
|
|
||||||
strcat(cmdline, " -s ");
|
|
||||||
strcat(cmdline, start);
|
|
||||||
}
|
|
||||||
strcat(cmdline, " -- -");
|
|
||||||
if (verbose_flag)
|
|
||||||
printf("translate: %s\n", cmdline);
|
|
||||||
rc = system(cmdline);
|
|
||||||
|
|
||||||
|
rc = strlen(tmp);
|
||||||
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
|
|
||||||
|
if (start) {
|
||||||
|
sprintf(tmp, " -s%s", start);
|
||||||
|
rc = strlen(tmp);
|
||||||
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
|
}
|
||||||
|
sprintf(tmp, " -- -");
|
||||||
|
rc = strlen(tmp);
|
||||||
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
|
|
||||||
|
if (verbose_flag)
|
||||||
|
printf("translate: %s\n", cmd);
|
||||||
|
|
||||||
|
rc = system(cmd);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
fprintf(stderr, "errors translating Verilog program.\n");
|
fprintf(stderr, "errors translating Verilog program.\n");
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(cmdline, "g++ -O -rdynamic -fno-exceptions -o %s -I%s "
|
sprintf(tmp, "g++ -O -rdynamic -fno-exceptions -o %s -I%s "
|
||||||
"-L%s %s.cc -lvvm -ldl", opath, base, base, opath);
|
"-L%s %s.cc -lvvm -ldl", opath, base, base, opath);
|
||||||
|
|
||||||
if (verbose_flag)
|
if (verbose_flag)
|
||||||
printf("compile: %s\n", cmdline);
|
printf("compile: %s\n", tmp);
|
||||||
|
|
||||||
rc = system(cmdline);
|
rc = system(tmp);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
fprintf(stderr, "errors compiling translated program.\n");
|
fprintf(stderr, "errors compiling translated program.\n");
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(cmdline, "%s.cc", opath);
|
sprintf(tmp, "%s.cc", opath);
|
||||||
unlink(cmdline);
|
unlink(tmp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int t_xnf()
|
static int t_xnf(char*cmd, unsigned ncmd)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
strcat(cmdline, " | ");
|
sprintf(tmp, " | %s/ivl -o %s -txnf -Fcprop -Fsynth -Fnodangle -Fxnfio", base, opath);
|
||||||
strcat(cmdline, base);
|
|
||||||
strcat(cmdline, "/ivl -o ");
|
rc = strlen(tmp);
|
||||||
strcat(cmdline, opath);
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
strcat(cmdline, " -s ");
|
sprintf(tmp, " -s%s", start);
|
||||||
strcat(cmdline, start);
|
rc = strlen(tmp);
|
||||||
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
}
|
}
|
||||||
strcat(cmdline, " -txnf -Fcprop -Fsynth -Fnodangle -Fxnfio");
|
sprintf(tmp, " -- -");
|
||||||
strcat(cmdline, " -- -");
|
rc = strlen(tmp);
|
||||||
|
cmd = realloc(cmd, ncmd+rc+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += rc;
|
||||||
|
|
||||||
if (verbose_flag)
|
if (verbose_flag)
|
||||||
printf("translate: %s\n", cmdline);
|
printf("translate: %s\n", cmd);
|
||||||
rc = system(cmdline);
|
|
||||||
|
rc = system(cmd);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
char*cmd;
|
||||||
|
unsigned ncmd;
|
||||||
int e_flag = 0;
|
int e_flag = 0;
|
||||||
int opt, idx;
|
int opt, idx;
|
||||||
char*cp;
|
char*cp;
|
||||||
|
|
@ -161,47 +200,53 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now collect the verilog source files. */
|
|
||||||
|
|
||||||
strcpy(cmdline, base);
|
|
||||||
cp = cmdline + strlen(cmdline);
|
|
||||||
strcpy(cp, "/ivlpp");
|
|
||||||
cp += strlen(cp);
|
|
||||||
if (verbose_flag) {
|
|
||||||
strcpy(cp, " -v");
|
|
||||||
cp += strlen(cp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind == argc) {
|
if (optind == argc) {
|
||||||
fprintf(stderr, "%s: No input files.\n", argv[0]);
|
fprintf(stderr, "%s: No input files.\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Start building the preprocess command line. */
|
||||||
|
|
||||||
|
sprintf(tmp, "%s/ivlpp");
|
||||||
|
if (verbose_flag)
|
||||||
|
strcat(tmp, " -v");
|
||||||
|
|
||||||
|
ncmd = strlen(tmp);
|
||||||
|
cmd = malloc(ncmd + 1);
|
||||||
|
|
||||||
|
/* Add all the verilog source files to the preprocess command line. */
|
||||||
|
|
||||||
for (idx = optind ; idx < argc ; idx += 1) {
|
for (idx = optind ; idx < argc ; idx += 1) {
|
||||||
sprintf(cp, " %s", argv[idx]);
|
sprintf(tmp, " %s", argv[idx]);
|
||||||
cp += strlen(cp);
|
cmd = realloc(cmd, ncmd+strlen(tmp)+1);
|
||||||
|
strcat(cmd, tmp);
|
||||||
|
ncmd += strlen(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* If the -E flag was given on the command line, then all we
|
/* If the -E flag was given on the command line, then all we
|
||||||
do is run the preprocessor and put the output where the
|
do is run the preprocessor and put the output where the
|
||||||
user wants it. */
|
user wants it. */
|
||||||
if (e_flag) {
|
if (e_flag) {
|
||||||
if (strcmp(opath,"-") != 0) {
|
if (strcmp(opath,"-") != 0) {
|
||||||
sprintf(cp, " > %s", opath);
|
sprintf(tmp, " > %s", opath);
|
||||||
cp += strlen(cp);
|
cmd = realloc(cmd, ncmd+strlen(tmp)+1);
|
||||||
|
strcpy(cmd+ncmd, tmp);
|
||||||
|
ncmd += strlen(tmp);
|
||||||
}
|
}
|
||||||
if (verbose_flag)
|
|
||||||
printf("preprocess: %s\n", cmdline);
|
|
||||||
|
|
||||||
return system(cmdline);
|
if (verbose_flag)
|
||||||
|
printf("preprocess: %s\n", cmd);
|
||||||
|
|
||||||
|
return system(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(targ,"null") == 0)
|
if (strcmp(targ,"null") == 0)
|
||||||
return t_null();
|
return t_null(cmd, ncmd);
|
||||||
else if (strcmp(targ,"vvm") == 0)
|
else if (strcmp(targ,"vvm") == 0)
|
||||||
return t_vvm();
|
return t_vvm(cmd, ncmd);
|
||||||
else if (strcmp(targ,"xnf") == 0)
|
else if (strcmp(targ,"xnf") == 0)
|
||||||
return t_xnf();
|
return t_xnf(cmd, ncmd);
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "Unknown target: %s\n", targ);
|
fprintf(stderr, "Unknown target: %s\n", targ);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -212,6 +257,9 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: iverilog.c,v $
|
* $Log: iverilog.c,v $
|
||||||
|
* Revision 1.5 2000/04/26 03:33:32 steve
|
||||||
|
* Do not set width too small to hold significant bits.
|
||||||
|
*
|
||||||
* Revision 1.4 2000/04/23 21:14:32 steve
|
* Revision 1.4 2000/04/23 21:14:32 steve
|
||||||
* The -s flag.
|
* The -s flag.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
26
set_width.cc
26
set_width.cc
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT) && !defined(macintosh)
|
#if !defined(WINNT) && !defined(macintosh)
|
||||||
#ident "$Id: set_width.cc,v 1.10 2000/04/21 02:46:42 steve Exp $"
|
#ident "$Id: set_width.cc,v 1.11 2000/04/26 03:33:32 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -191,16 +191,27 @@ bool NetEConst::set_width(unsigned w)
|
||||||
|
|
||||||
value_ = tmp;
|
value_ = tmp;
|
||||||
|
|
||||||
|
expr_width(w);
|
||||||
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
verinum tmp (verinum::V0, w);
|
unsigned use_w = w;
|
||||||
for (unsigned idx = 0 ; idx < w ; idx += 1)
|
bool flag = true;
|
||||||
|
|
||||||
|
// Don't reduce a number too small to hold all the
|
||||||
|
// significant bits.
|
||||||
|
for (unsigned idx = w ; idx < value_.len() ; idx += 1)
|
||||||
|
if (value_[idx] != verinum::V0)
|
||||||
|
use_w = idx+1;
|
||||||
|
|
||||||
|
verinum tmp (verinum::V0, use_w);
|
||||||
|
for (unsigned idx = 0 ; idx < use_w ; idx += 1)
|
||||||
tmp.set(idx, value_[idx]);
|
tmp.set(idx, value_[idx]);
|
||||||
|
|
||||||
value_ = tmp;
|
value_ = tmp;
|
||||||
|
expr_width(use_w);
|
||||||
|
return use_w == w;
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_width(w);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetEMemory::set_width(unsigned w)
|
bool NetEMemory::set_width(unsigned w)
|
||||||
|
|
@ -275,6 +286,9 @@ bool NetEUnary::set_width(unsigned w)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: set_width.cc,v $
|
* $Log: set_width.cc,v $
|
||||||
|
* Revision 1.11 2000/04/26 03:33:32 steve
|
||||||
|
* Do not set width too small to hold significant bits.
|
||||||
|
*
|
||||||
* Revision 1.10 2000/04/21 02:46:42 steve
|
* Revision 1.10 2000/04/21 02:46:42 steve
|
||||||
* Many Unary operators have known widths.
|
* Many Unary operators have known widths.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue