diff --git a/compiler.h b/compiler.h index de39e10c7..9440bd37e 100644 --- a/compiler.h +++ b/compiler.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: compiler.h,v 1.21 2004/03/09 04:29:42 steve Exp $" +#ident "$Id: compiler.h,v 1.22 2004/03/10 04:51:24 steve Exp $" #endif # include @@ -128,9 +128,13 @@ struct sfunc_return_type { }; extern const struct sfunc_return_type* lookup_sys_func(const char*name); +extern int load_sys_func_table(const char*path); /* * $Log: compiler.h,v $ + * Revision 1.22 2004/03/10 04:51:24 steve + * Add support for system function table files. + * * Revision 1.21 2004/03/09 04:29:42 steve * Separate out the lookup_sys_func table, for eventual * support for function type tables. @@ -154,11 +158,5 @@ extern const struct sfunc_return_type* lookup_sys_func(const char*name); * scope names and system task/function names * into this table. Also, permallocate event * names from the beginning. - * - * Revision 1.15 2003/02/22 04:12:49 steve - * Add the portbind warning. - * - * Revision 1.14 2003/01/30 16:23:07 steve - * Spelling fixes. */ #endif diff --git a/driver/iverilog.man b/driver/iverilog.man index 2f49760da..9b9bac17a 100644 --- a/driver/iverilog.man +++ b/driver/iverilog.man @@ -1,4 +1,4 @@ -.TH iverilog 1 "$Date: 2003/11/26 01:36:25 $" Version "$Date: 2003/11/26 01:36:25 $" +.TH iverilog 1 "$Date: 2004/03/10 04:51:25 $" Version "$Date: 2004/03/10 04:51:25 $" .SH NAME iverilog - Icarus Verilog compiler @@ -212,6 +212,33 @@ inherit timescale from another file. Both probably mean that timescales are inconsistent, and simulation timing can be confusing and dependent on compilation order. +.SH "SYSTEM FUNCTION TABLE FILES" +If the source file name as a \fB.sft\fP suffix, then it is taken to be +a system function table file. A System function table file is used to +describe to the compiler the return types for system functions. This +is necessary because the compiler needs this information to elaborate +expressions that contain these system functions, but cannot run the +sizetf functions since it has no run-time. + +The format of the table is ASCII, one function per line. Empty lines +are ignored, and lines that start with the '\fI#\fP' character are +comment lines. Each non-comment line starts with the function name, +then the vpi type (i.e. vpiSysFuncReal). The following types are +supported: + +.TP 8 +.B vpiSysFuncReal +The function returns a real/realtime value. + +.TP 8 +.B vpiSysFuncInt +The function returns an integer. + +.TP 8 +.B vpiSysFuncSized +The function returns a vector with the given width, and is signed or +unsigned according to the flag. + .SH "COMMAND FILES" The command file allows the user to place source file names and certain command line switches into a text file instead of on a long diff --git a/driver/main.c b/driver/main.c index 9f4d1cd07..eb2a8a513 100644 --- a/driver/main.c +++ b/driver/main.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: main.c,v 1.63 2004/02/15 18:03:30 steve Exp $" +#ident "$Id: main.c,v 1.64 2004/03/10 04:51:25 steve Exp $" #endif # include "config.h" @@ -368,10 +368,21 @@ void process_define(const char*name) } } +/* + * This function is called while processing a file name in a command + * file, or a file name on the command line. Look to see if there is a + * .sft suffix, and if so pass that as a sys_func file. Otherwise, it + * is a Verilog source file to be written into the file list. + */ void process_file_name(const char*name) { - fprintf(source_file, "%s\n", name); - source_count += 1; + if (strlen(name) > 4 && strcasecmp(".sft", name+strlen(name)-4) == 0) { + fprintf(iconfig_file,"sys_func:%s\n", name); + + } else { + fprintf(source_file, "%s\n", name); + source_count += 1; + } } int process_generation(const char*name) @@ -714,6 +725,9 @@ int main(int argc, char **argv) /* * $Log: main.c,v $ + * Revision 1.64 2004/03/10 04:51:25 steve + * Add support for system function table files. + * * Revision 1.63 2004/02/15 18:03:30 steve * Cleanup of warnings. * diff --git a/main.cc b/main.cc index b548c832a..e2a85ad95 100644 --- a/main.cc +++ b/main.cc @@ -19,7 +19,7 @@ const char COPYRIGHT[] = * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: main.cc,v 1.81 2004/02/18 17:11:56 steve Exp $" +#ident "$Id: main.cc,v 1.82 2004/03/10 04:51:24 steve Exp $" #endif # include "config.h" @@ -250,6 +250,9 @@ static void parm_to_flagmap(const string&flag) * out: * Path to the output file. * + * sys_func: + * Path to a system functions descriptor table + * * root: * Specify a root module. There may be multiple of this. * @@ -333,6 +336,9 @@ static void read_iconfig_file(const char*ipath) } else if (strcmp(buf, "out") == 0) { flags["-o"] = strdup(cp); + } else if (strcmp(buf, "sys_func") == 0) { + load_sys_func_table(cp); + } else if (strcmp(buf, "root") == 0) { roots.push_back(lex_strings.make(cp)); @@ -716,6 +722,9 @@ int main(int argc, char*argv[]) /* * $Log: main.cc,v $ + * Revision 1.82 2004/03/10 04:51:24 steve + * Add support for system function table files. + * * Revision 1.81 2004/02/18 17:11:56 steve * Use perm_strings for named langiage items. * diff --git a/sys_funcs.cc b/sys_funcs.cc index 01d618030..a67124af8 100644 --- a/sys_funcs.cc +++ b/sys_funcs.cc @@ -16,7 +16,7 @@ * 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: sys_funcs.cc,v 1.1 2004/03/09 04:29:42 steve Exp $" +#ident "$Id: sys_funcs.cc,v 1.2 2004/03/10 04:51:24 steve Exp $" # include "config.h" # include "compiler.h" @@ -38,11 +38,25 @@ static const struct sfunc_return_type sfunc_table[] = { { 0, NetExpr::ET_VECTOR, 32, 0 } }; +struct sfunc_return_type_cell : sfunc_return_type { + struct sfunc_return_type_cell*next; +}; + +static struct sfunc_return_type_cell*sfunc_stack = 0; const struct sfunc_return_type* lookup_sys_func(const char*name) { - unsigned idx = 0; + /* First, try to find then name in the function stack. */ + struct sfunc_return_type_cell*cur = sfunc_stack; + while (cur) { + if (strcmp(cur->name, name) == 0) + return cur; + cur = cur->next; + } + + /* Next, look in the core table. */ + unsigned idx = 0; while (sfunc_table[idx].name) { if (strcmp(sfunc_table[idx].name, name) == 0) @@ -51,18 +65,130 @@ const struct sfunc_return_type* lookup_sys_func(const char*name) idx += 1; } - /* No luch finding, so return the trailer, which give a + /* No luck finding, so return the trailer, which give a default description. */ return sfunc_table + idx; } +/* + * This function loads a system functions descriptor file with the + * format: + * + * [] + */ +int load_sys_func_table(const char*path) +{ + struct sfunc_return_type_cell*cell; + FILE*fd = fopen(path, "r"); + + if (fd == 0) + return -1; + + char buf[256]; + while (fgets(buf, sizeof buf, fd)) { + char*name = buf + strspn(buf, " \t\r\n"); + + /* Skip empty lines. */ + if (name[0] == 0) + continue; + /* Skip comment lines. */ + if (name[0] == '#') + continue; + + char*cp = name + strcspn(name, " \t\r\n"); + if (cp[0]) *cp++ = 0; + + cp += strspn(cp, " \t\r\n"); + + char*stype = cp; + if (stype[0] == 0) { + fprintf(stderr, "%s:%s: No function type?\n", + path, name); + continue; + } + + cp = stype + strcspn(stype, " \t\r\n"); + if (cp[0]) *cp++ = 0; + + if (strcmp(stype,"vpiSysFuncReal") == 0) { + cell = new struct sfunc_return_type_cell; + cell->name = lex_strings.add(name); + cell->type = NetExpr::ET_REAL; + cell->wid = 0; + cell->signed_flag = true; + cell->next = sfunc_stack; + sfunc_stack = cell; + continue; + } + + if (strcmp(stype,"vpiSysFuncInt") == 0) { + cell = new struct sfunc_return_type_cell; + cell->name = lex_strings.add(name); + cell->type = NetExpr::ET_VECTOR; + cell->wid = 32; + cell->signed_flag = true; + cell->next = sfunc_stack; + sfunc_stack = cell; + continue; + } + + /* If this is a sized integer, then parse the additional + arguments, the width (decimal) and the optional + signed/unsigned flag. */ + if (strcmp(stype,"vpiSysFuncSized") == 0) { + cp += strspn(cp, " \t\r\n"); + char*swidth = cp; + unsigned width = 32; + bool signed_flag = false; + + cp = swidth + strcspn(swidth, " \t\r\n"); + if (cp[0]) *cp++ = 0; + + width = strtoul(swidth, 0, 10); + + cp += strspn(cp, " \t\r\n"); + char*flag = cp; + + while (flag[0]) { + cp = flag + strcspn(flag, " \t\r\n"); + if (cp[0]) *cp++ = 0; + + if (strcmp(flag,"signed") == 0) { + signed_flag = true; + + } else if (strcmp(flag,"unsigned") == 0) { + signed_flag = false; + } + + flag = cp + strspn(cp, " \t\r\n"); + } + + cell = new struct sfunc_return_type_cell; + cell->name = lex_strings.add(name); + cell->type = NetExpr::ET_VECTOR; + cell->wid = width; + cell->signed_flag = signed_flag; + cell->next = sfunc_stack; + sfunc_stack = cell; + continue; + } + + fprintf(stderr, "%s:%s: Unknown type: %s\n", + path, name, stype); + } + + return 0; +} + /* * $Log: sys_funcs.cc,v $ + * Revision 1.2 2004/03/10 04:51:24 steve + * Add support for system function table files. + * * Revision 1.1 2004/03/09 04:29:42 steve * Separate out the lookup_sys_func table, for eventual * support for function type tables. * * Remove ipal compile flags. - * */