Verilog does not allow macro expansion in strings, and that's that.
But sometimes people want strings of a macro expansion, so add a
stringify syntax that does the trick.
Passing preprocessor definitions forward into library cells was broken
by this bug in processing the precompiled macro values that were written
by the main preprocessor.
Macro argument substitution used to just use strstr() to
find an argument that needed to be substituted. This is too
aggressive. It would do argument substitution in the middle
of keywords and other identifiers. A new routine is used
that verifies the character preceding the match is not
a normal identifier character [a-zA-Z0-9_$].
The updates to the do_include code destroyed the
handling of absolute paths; all of the code that
handles buffer-switching was erroneously placed
in just the relative-path branch. Thanks go to
Cary R. for pointing out the problem.
Now the common code has been extracted yet again,
and the notorious goto statement has been used
in favor redundancy.
The test vvp_reg.pl produces the same output as
before, so hopefully nothing new is broken.
Signed-off-by: Michael Witten <mfwitten@mit.edu>
The file lexor.lex was beginning to suffer a catastrophic
increase in entropy due mainly to the mingling of spaces
and tabs--an age-old problem that often finds itself as
the subject of many a religious war.
The key rule: Make it consistent in as many editors as
possible; this was achieved by converting all hard tabs
into soft tabs (composed of spaces) of width 4.
I couldn't help but make modifications to the code as I
tabifified, but most of the changes are strictly style.
While maintainers generally treat large scale whitespace and
formatting changes with much caution, I believe that the code
is now much more maintainable; moreover, the test suite
produces the same results as before.
Signed-off-by: Michael Witten <mfwitten@mit.edu>
Macro names cannot be compiler directive names.
Such trespasses are now recognized and reported:
(1) Offending `define lines are skipped.
(2) Offending macros meant to be expanded
are replaced with nothing.
Signed-off-by: Michael Witten <mfwitten@mit.edu>
The ordering of the logic was a little strange before.
Also, there were unnecessary operations, like the assert
and the include_dir[0]=0 business.
Signed-off-by: Michael Witten <mfwitten@mit.edu>
Discussions online and "standards" documents are never
conclusive, but the code that was present suggests that
iverilog adopts the sane practice of resolving relative
paths against the directory of the file that is currently
being processed.
Unfortunately, when a relative path is made absolute, the
code forgot to update the necessary include_stack_t object.
This has now been fixed.
Signed-off-by: Michael Witten <mfwitten@mit.edu>
When the lexical analyzer encounters and EOF, the
analyzer invokes yywrap() to determine what to do
next. The function determines one of two paths of
execution:
(1) If yywrap() returns 0, then the analyzer
assumes that yywrap() has setup a new input
source, and so scanning continues.
(2) If yywrap() returns non-zero, then the analyzer
assumes that yywrap() has not setup a new input
source, and so the analyzer proceeds to run the
matching EOF action (the default of which invokes
yyterminate()).
NOTE: The analyzer does not touch the start condition.
The old implementation was using yywrap() to destroy the current
input source and setup the next one. However, this causes problems
when the analyzer is in the middle of parsing some directive:
(1) Because yywrap() is called before any EOF action,
the include_stack_t structure is destroyed before
being used in the EOF action; the result is a segfault.
(2) Because yywrap() does not change the start condition,
any EOF action would occur completely out of context;
however, because of (1), this problem never cropped
up.
The new implementation simply:
(1) Employs "%option noyywrap", which effectively causes
the analyzer to act as though yywrap() produces a non-zero.
(2) Renames yywrap "load_next_input".
(3) Calls load_next_input() explicitly in exhaustive EOF actions,
so that control is more fine grained.
The added benefit is that the code that finishes parsing EOF terminated
directives now works properly; `include and `define directives previously
segfaulted in such situations.
Signed-off-by: Michael Witten <mfwitten@mit.edu>
This variable was used in yywrap purportedly to obviate
hidden access to a file that should be closable.
After investigating the code flex produces, it would
seem that these fears are unfounded.
Signed-off-by: Michael Witten <mfwitten@mit.edu>
The verilog preprocessing language is sufficiently simple
that the parser may be implemented by hand on top of the
lexical analyzer.
In fact, ivlpp was already implemented in this way; relevant
[bison] parser files specified no grammar, and the parser
entry-point (yyparse) was simply an indirect use of the lexical
analyzer (yylex).
Therefore, parse.y has been removed, invocations of yyparse()
have been replaced by yylex(), references to bison generated
files have been removed, and Makefile.in has been updated
accordingly.
Signed-off-by: Michael Witten <mfwitten@mit.edu>
Core preprocessor support for writing out and reading precompiled
defines. The preprocessor can read initial precompiled defines from
any number of specified source files, and can write all the defines
into a specified output file.
The patch for adding support for macros with arguments contained
a leftover debugging aid. This patch corrects the code. It also
should eliminate some compilation warnings.
This patch modifies the preprocessor to handle text macros with
arguments. It also fixes a bug that prevented a `line directive
being issued after a multi-line text macro had been instantiated.
For text macro substitutions the lexor did not allow leading underscores.
This patch fixes that omission. All other places that text macros may be
used appear to be correct.
C style comments were not recognized as comments in false or
suppressed sections of ifdef/etc. blocks. This prohibited an
unneeded endif/else/etc. from being commented out with this
style of comment.