diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 404ebe941..5fbfd4a19 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -1,7 +1,7 @@ %option prefix="yy" %{ /* - * Copyright (c) 1999-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2022 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 @@ -187,6 +187,7 @@ static int ma_parenthesis_level = 0; %option noyywrap %x PPINCLUDE +%x PPCCOMMENT %x DEF_NAME %x DEF_ESC %x DEF_ARG @@ -307,9 +308,23 @@ keywords (line|include|define|undef|ifdef|ifndef|else|elsif|endif) /* Catch single-line comments that share the line with an include * directive. And while I'm at it, I might as well preserve the * comment in the output stream. This will be printed after the - * file has been included. + * file has been included. For simplicity, if there is more than + * one comment on the line, only the first one will be preserved. */ -"//"[^\r\n]* { standby->comment = strdup(yytext); } +"//"[^\r\n]* | +"/*"[^\r\n]*"*/" { if (!standby->comment) standby->comment = strdup(yytext); } + + /* Now catch the start of a multi-line comment. In this case we + * discard the comment then execute the inclusion. + */ +"/*" { BEGIN(PPCCOMMENT); } + +[^\r\n] {} +\n\r | +\r\n | +\n | +\r { istack->lineno += 1; } +"*/" { yy_pop_state(); do_include(); } /* These finish the include directive (EOF or EOL) so I revert the * lexor state and execute the inclusion. diff --git a/ivtest/gold/br_gh782a.gold b/ivtest/gold/br_gh782a.gold new file mode 100644 index 000000000..a8bd5b601 --- /dev/null +++ b/ivtest/gold/br_gh782a.gold @@ -0,0 +1,9 @@ +File ./ivltests/br_gh782a.v line 4 +Included file ./ivltests/br_gh782a.vi line 1 +File ./ivltests/br_gh782a.v line 6 +Included file ./ivltests/br_gh782a.vi line 1 +File ./ivltests/br_gh782a.v line 8 +Included file ./ivltests/br_gh782a.vi line 1 +File ./ivltests/br_gh782a.v line 11 +Included file ./ivltests/br_gh782a.vi line 1 +File ./ivltests/br_gh782a.v line 14 diff --git a/ivtest/ivltests/br_gh782a.v b/ivtest/ivltests/br_gh782a.v new file mode 100644 index 000000000..59603c7d1 --- /dev/null +++ b/ivtest/ivltests/br_gh782a.v @@ -0,0 +1,17 @@ +module test; + +initial begin + $display("File %s line %0d", `__FILE__, `__LINE__); +`include "ivltests/br_gh782a.vi" // single line comment + $display("File %s line %0d", `__FILE__, `__LINE__); +`include "ivltests/br_gh782a.vi" /* another single line comment */ + $display("File %s line %0d", `__FILE__, `__LINE__); +`include "ivltests/br_gh782a.vi" /* multi-line + comment */ + $display("File %s line %0d", `__FILE__, `__LINE__); +`include "ivltests/br_gh782a.vi" /* single */ /* and + multi-line comment */ + $display("File %s line %0d", `__FILE__, `__LINE__); +end + +endmodule diff --git a/ivtest/ivltests/br_gh782a.vi b/ivtest/ivltests/br_gh782a.vi new file mode 100644 index 000000000..bb86b7382 --- /dev/null +++ b/ivtest/ivltests/br_gh782a.vi @@ -0,0 +1 @@ + $display("Included file %s line %0d", `__FILE__, `__LINE__); diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index e423c2a86..304cf1b49 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -220,6 +220,7 @@ br_gh661b normal,-g2009 ivltests br_gh672 normal,-g2009 ivltests br_gh699 CE,-g2009 ivltests br_gh756 normal,-g2009 ivltests +br_gh782a normal,-g2009 ivltests gold=br_gh782a.gold br_ml20171017 normal,-g2009 ivltests br_ml20180227 CE,-g2009 ivltests br_ml20180309a normal,-g2009 ivltests