Support the include directive.

This commit is contained in:
steve 1998-12-09 04:02:47 +00:00
parent ed02ae33c7
commit 45f45f73b7
4 changed files with 109 additions and 21 deletions

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: lexor.lex,v 1.5 1998/11/25 02:35:53 steve Exp $"
#ident "$Id: lexor.lex,v 1.6 1998/12/09 04:02:47 steve Exp $"
#endif
//# define YYSTYPE lexval
@ -30,7 +30,7 @@
# include <ctype.h>
extern FILE*vl_input;
extern const char*vl_file;
extern string vl_file;
# define YY_USER_INIT reset_lexor();
# define yylval VLlval
@ -38,17 +38,18 @@ extern YYLTYPE yylloc;
static void reset_lexor();
static int check_identifier(const char*name);
static void ppinclude_filename();
static void ppdo_include();
static verinum*make_sized_binary(const char*txt);
static verinum*make_sized_octal(const char*txt);
static verinum*make_sized_hex(const char*txt);
%}
%option noyywrap
%x CCOMMENT
%x CSTRING
%s UDPTABLE
%x PPINCLUDE
%%
@ -138,6 +139,20 @@ static verinum*make_sized_hex(const char*txt);
delete[]bits;
return NUMBER; }
`include {
BEGIN(PPINCLUDE); }
<PPINCLUDE>\"[^\"]*\" {
ppinclude_filename(); }
<PPINCLUDE>[ \t\b\f\r] { ; }
<PPINCLUDE>\n {
BEGIN(0);
yylloc.first_line += 1;
ppdo_include(); }
. { cerr << yylloc.first_line << ": unmatched character (";
if (isgraph(yytext[0]))
cerr << yytext[0];
@ -449,9 +464,71 @@ static verinum*make_sized_hex(const char*txt)
return new verinum(bits, size);
}
struct include_stack_t {
string path;
FILE*file;
unsigned lineno;
YY_BUFFER_STATE yybs;
struct include_stack_t*next;
};
static include_stack_t*include_stack = 0;
static string ppinclude_path;
static void ppinclude_filename()
{
ppinclude_path = yytext+1;
ppinclude_path = ppinclude_path.substr(0, ppinclude_path.length()-1);
}
static void ppdo_include()
{
FILE*file = fopen(ppinclude_path.c_str(), "r");
if (file == 0) {
cerr << ppinclude_path << ": Unable to open include file." << endl;
return;
}
include_stack_t*isp = new include_stack_t;
isp->path = vl_file;
isp->file = vl_input;
isp->lineno = yylloc.first_line;
isp->next = include_stack;
isp->yybs = YY_CURRENT_BUFFER;
vl_file = ppinclude_path;
vl_input = file;
yylloc.first_line = 1;
yylloc.text = vl_file.c_str();
yy_switch_to_buffer(yy_new_buffer(vl_input, YY_BUF_SIZE));
include_stack = isp;
}
static int yywrap()
{
include_stack_t*isp = include_stack;
if (isp == 0)
return 1;
yy_delete_buffer(YY_CURRENT_BUFFER);
fclose(vl_input);
vl_input = isp->file;
vl_file = isp->path;
yy_switch_to_buffer(isp->yybs);
yylloc.first_line = isp->lineno;
yylloc.text = vl_file.c_str();
include_stack = isp->next;
delete isp;
return 0;
}
static void reset_lexor()
{
yyrestart(vl_input);
include_stack = 0;
yylloc.first_line = 1;
yylloc.text = vl_file;
yylloc.text = vl_file.c_str();
}

16
main.cc
View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: main.cc,v 1.9 1998/12/07 04:53:17 steve Exp $"
#ident "$Id: main.cc,v 1.10 1998/12/09 04:02:47 steve Exp $"
#endif
# include <stdio.h>
@ -32,7 +32,6 @@
extern void pform_parse();
const char*vl_file = "";
const char*target = "verilog";
string start_module = "";
@ -151,18 +150,10 @@ int main(int argc, char*argv[])
return 1;
}
/* Open the input (source) file. */
vl_file = argv[optind];
FILE*input = fopen(vl_file, "r");
if (input == 0) {
cerr << "Unable to open " <<vl_file << "." << endl;
return 1;
}
/* Parse the input. Make the pform. */
map<string,Module*> modules;
map<string,PUdp*> primitives;
int rc = pform_parse(input, modules, primitives);
int rc = pform_parse(argv[optind], modules, primitives);
if (rc) {
return rc;
@ -231,6 +222,9 @@ int main(int argc, char*argv[])
/*
* $Log: main.cc,v $
* Revision 1.10 1998/12/09 04:02:47 steve
* Support the include directive.
*
* Revision 1.9 1998/12/07 04:53:17 steve
* Generate OBUF or IBUF attributes (and the gates
* to garry them) where a wire is a pad. This involved

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: pform.cc,v 1.6 1998/12/01 00:42:14 steve Exp $"
#ident "$Id: pform.cc,v 1.7 1998/12/09 04:02:47 steve Exp $"
#endif
# include "pform.h"
@ -28,6 +28,11 @@
# include <assert.h>
# include <typeinfo>
/*
* The lexor accesses the vl_* variables.
*/
string vl_file = "";
extern int VLparse();
static Module*cur_module = 0;
@ -463,10 +468,16 @@ Statement* pform_make_calltask(string*name, list<PExpr*>*parms)
}
FILE*vl_input = 0;
int pform_parse(FILE*input, map<string,Module*>&modules,
int pform_parse(const char*path, map<string,Module*>&modules,
map<string,PUdp*>&prim)
{
vl_input = input;
vl_file = path;
vl_input = fopen(path, "r");
if (vl_input == 0) {
cerr << "Unable to open " <<vl_file << "." << endl;
return 11;
}
error_count = 0;
warn_count = 0;
int rc = VLparse();
@ -482,6 +493,9 @@ int pform_parse(FILE*input, map<string,Module*>&modules,
/*
* $Log: pform.cc,v $
* Revision 1.7 1998/12/09 04:02:47 steve
* Support the include directive.
*
* Revision 1.6 1998/12/01 00:42:14 steve
* Elaborate UDP devices,
* Support UDP type attributes, and

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: pform.h,v 1.4 1998/12/01 00:42:14 steve Exp $"
#ident "$Id: pform.h,v 1.5 1998/12/09 04:02:47 steve Exp $"
#endif
# include "netlist.h"
@ -126,12 +126,15 @@ extern void pform_make_pgassign(const string&lval, PExpr*sel, PExpr*rval);
* parses the source file and places all the modules it finds into the
* mod list. The dump function dumps a module to the output stream.
*/
extern int pform_parse(FILE*, map<string,Module*>&mod,
extern int pform_parse(const char*path, map<string,Module*>&mod,
map<string,PUdp*>&prim);
extern void pform_dump(ostream&out, Module*mod);
/*
* $Log: pform.h,v $
* Revision 1.5 1998/12/09 04:02:47 steve
* Support the include directive.
*
* Revision 1.4 1998/12/01 00:42:14 steve
* Elaborate UDP devices,
* Support UDP type attributes, and