Commit Graph

206 Commits

Author SHA1 Message Date
Cary R cc496c3cf3 More ivl cppcheck cleanup 2025-10-23 10:01:06 -07:00
Martin Whitaker 2b01cf335c Increment line number when parsing "// synthesis" pragmas (issue #1242)
Thanks to Robert Lance for proposing the fix.
2025-05-11 11:38:28 +01:00
Cary R 527b0daed6 Fix some clang warnings 2024-11-26 23:33:52 -08:00
Martin Whitaker 8b3f0d63b4 Record the lexical order of identifiers whilst scanning the source files.
This is needed for detecting use before declaration. The lexical scanner
is the only place where we process the source text in strict lexical
order, so do it there.

As Verilog allows modules to span multiple source files, don't reset
the counter when we reset the lexor.
2024-02-19 18:13:05 +00:00
Martin Whitaker f31d0dcbc5 Zero-extend unsized signed based literal numbers when < integer_width bits.
Whilst the wording in the IEEE standards is ambiguous, discussions on
the standards committee mailing lists clarify that an unsized literal is
supposed to be the same size as an integer (as shown in IEEE 1364-2005
table 5-22). The token following the base format character is specified
to be an unsized number. So to maintain compatibility with the standards
and with other tools, if the unsigned number part of an unsized signed
based literal can be represented in less than integer_width bits and the
MSB is a '1', we need to add a leading zero to ensure it is zero-extended
when used in an expression.

This fixes issue #1082.
2024-01-28 11:51:42 +00:00
Cary R 76a65d5958 Add error message for bad line directives to ivlpp 2023-09-04 14:00:41 -07:00
Cary R 9e4c4d5460 `line directive line number must be > 0 and can have arbitrary space 2023-07-19 01:51:36 -07:00
Cary R dc8b7d0184 Cleanup some cppcheck warnings 2022-12-28 00:00:31 -08:00
Martin Whitaker 0271602260 Use consistent format for compiler lexor warning messages.
Capitalise the first word of the main message unless it's a Verilog
keyword. Use VLwarn() in preference to yywarn or direct output to cerr.
2022-12-22 11:03:11 +00:00
Martin Whitaker 82aedbc36c Don't automatically add the "warning: " prefix in VLwarn().
One variant did, the other variant didn't. As well as being a trap for
the unwary, this gets in the way of using yywarn/VLwarn for non-fatal
"sorry" messages.
2022-12-22 10:34:56 +00:00
Martin Whitaker 2e27b4393d Use consistent format for compiler lexor error messages.
Always prefix with "error: ". Capitalise the first word of the main
message unless it's a Verilog keyword. Use VLerror() in preference
to direct output to cerr.
2022-12-22 10:15:09 +00:00
Martin Whitaker 32f66511e0 Fix spelling of `pragma in scanner.
This does prove nobody is using it :-)
2022-12-21 12:11:41 +00:00
Martin Whitaker 7914f8ad9d Add a few comments in the compiler scanner. 2022-12-20 18:14:18 +00:00
Martin Whitaker 968f0d943e Catch unrecognised compiler directives in the compiler scanner.
Normally the preprocessor will catch these and report them as undefined
macros. But in case the compiler is run without the preprocessor, also
catch them in the compiler scanner. This will ensure the scanner properly
rejects directives that have additional garbage characters tacked on the
end.
2022-12-20 18:14:18 +00:00
Martin Whitaker cd0b360575 Support free-form `default_net_type directives. 2022-12-20 18:14:18 +00:00
Martin Whitaker 79a3d08d69 Support free-form `begin_keywords and `end_keywords directives. 2022-12-20 18:14:18 +00:00
Martin Whitaker 52f269649a Support free-form `(end)cell_define and `reset_all directives.
Also use VLerror for reporting errors.
2022-12-20 18:14:18 +00:00
Martin Whitaker 0dc64b99f3 Support free-form `(no)unconnected_drive directives.
Also use VLerror for reporting errors.
2022-12-20 18:14:18 +00:00
Martin Whitaker 59d70cad45 Support free-form `timescale directives with interspersed comments (issue #782)
Verilog compiler directives are free-form and, subject to semantic rules,
can appear anywhere in the source code. Whilst it is common practice to
write them on a separate line, we should handle all legal syntax.
2022-12-20 18:14:17 +00:00
Lars-Peter Clausen 2e0d6d5af1 Allow to attach additional information to typedefs
Currently typedefs are just a pointer to a data_type_t.

Currently typedefs are implemented by setting the name field of a
data_type_t when a typedef of the type is declared. This works mostly, but
there are some corner cases that can't be supported.

E.g. a typedef of a typedef does not work as it overwrites the name field
of the same data_type_t multiple times.

Forward typedefs can also not be supported since forward typedefs allow to
reference a type before it has been declared.

There are also some problems with type identifier references from a
higher-level scope if there is a type identifier in the current scope with
the same name, but it is declared after the type identifier has been
referenced. E.g. in the following x should be a vector fo width 8, but it
will be a vector of width 4, because while the right type is used it is
elaborated in the wrong scope.

```
localparam A = 8;
typedef logic [A-1:0] T;
module M;
  localparam A = 4;
  T x;
  typedef int T;
endmodule
```

Furthermore typedefs used for the type of ports are elaborated in the wrong
scope.

To handle these corner case issues introduce a data_type_t for typedefs.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 10:18:22 -08:00
Lloyd Parkes 31eab5b528 Put back the #include of <iostream> that I accidently removed when
I fixed up a misclick earlier.

It doesn't seem to be needed, but I should the the file as I found it.
2022-10-14 11:38:13 +13:00
Lloyd Parkes 6c975eb89c Add #include <cstdarg> to all source files that use va_list. 2022-10-12 15:31:35 +13:00
Stephen Williams 27d81bc610 Add support for logical implication
The "->" operator is rarely used, but exists. Unfortunately, the syntax
is tied up in a horrible mess with the System Verilog constraint list
syntax. Do some flex magic to make it all work.
2022-02-13 18:48:16 -08:00
Martin Whitaker ecbbb60fb6 Remove "using namespace std" from compiler header files and fix the fallout. 2021-11-04 16:55:03 +00:00
Cary R 60a77b08d2 Add compiler and the start of vvp support for ->> 2021-02-19 23:21:51 -08:00
Cary R 31a68fcd8a Report possible nested comments 2021-01-29 18:10:11 -08:00
Cary R 85e8cc6c5f Update some preprocessor error messages 2021-01-10 18:27:23 -08:00
Cary R 248aeeef66 Add support for \\\n being ignored in string constants 2020-12-30 18:00:39 -08:00
Cary R c003bcc59a Add support for <-> in constant and procedural contexts 2020-07-07 23:29:19 -07:00
Stephen Williams 1147881176 Merge branch 'master' of github.com:steveicarus/iverilog 2019-10-02 09:34:36 -07:00
Stephen Williams 30fbc020e6 Don't allow nil bytes in string literals. 2019-10-02 09:34:18 -07:00
Martin Whitaker d3bced57cc Correctly handle explicit and wildcard package imports.
Explicit imports should always conflict with local declarations using
the same name. Wildcard imports only conflict if they are referenced
before a local declaration with the same name.

This also unifies the detection of identifier conflicts.
2019-09-27 22:19:30 +01:00
Cary R 3fc9ad2db0 Add support for the wild compare operators ==? and !=? 2017-11-17 19:32:50 -08:00
Cary R f03033e612 Update flex destroy routines to work for version 2.6 and greater 2017-11-16 19:11:50 -08:00
Martin Whitaker fd807a7700 Rework handling of timescales in parser.
This implements and enforces the full set of rules for determining
timescales in SystemVerilog. The previous relaxation of the rules
that allowed timescales to be redefined within the compilation unit
scope has been removed. Time unit and precision redeclarations are
now recognised after a nested module declaration.
2017-11-05 17:50:05 +00:00
Martin Whitaker 913fb34799 Add support for the $unit scope identifier.
This relies on using the automatically generated name for the unit scope.
This could collide with an escaped identifier, so it would be better to
identify the scope by a reference to the PPackage object, but for now,
do it the easy way.
2017-10-31 20:39:49 +00:00
Martin Whitaker dfddbea26b First step towards supporting separate compilation units in SV.
This adds a -u option to the driver to allow the user to specify that
they want each source file to be treated as a separate compilation
unit, and modifies the compiler to accept a list of files (either on
the command line or via a file specified by a new -F option). This
list of files is then preprocessed and parsed separately, causing all
compiler directives (including macro definitions) to only apply to the
file containing them, as required by the SystemVerilog standard.
2017-10-31 20:36:27 +00:00
Martin Whitaker 3c9b39846c Use gn_system_verilog() where appropriate.
Replace explicit comparisons against generation_flag with calls to
the gn_system_verilog helper function, both for code clarity and
to fix a couple of bugs. Also simplify the implementation of the
function, as we already rely on the generation_flag enumeration
being an ordered list.
2016-09-08 23:00:48 +01:00
Stephen Williams 66de0fc3e2 Merge branch 'master' of github.com:steveicarus/iverilog 2015-09-22 16:15:47 -07:00
Stephen Williams 8803eb3288 Handle numeric literals with no digits. 2015-09-22 16:15:41 -07:00
Martin Whitaker a1e0040d82 Fix for GitHub issue #79 - literal numbers must have at least one digit.
The bug report was for an assertion failure when a number contained only
a lowline (e.g. 'b_), but the standard says that a number can't start
with a lowline (e.g. 'b_1). The parser already rejected these cases for
decimal numbers, but allowed them through for binary/octal/hex numbers.
2015-09-23 00:01:39 +01:00
Cary R 4ea512c4fd Require a space between the synthesis and translate_* key words 2014-08-11 15:05:03 -07:00
Stephen Williams 2d2a720ea8 Do a better job with synthesis translate pragmas. 2014-08-09 08:04:25 -07:00
Cary R 0a6d75f1db Fix some cppcheck warnings (format string vs argument mismatches) 2014-08-01 18:55:44 -07:00
Stephen Williams 14f597acdd Add support for synthesis translate meta-comments. 2014-07-15 18:03:40 -07:00
Stephen Williams a849249a86 Allow typedefs to override inherited type names. 2014-04-06 08:40:08 -07:00
Stephen Williams 49cf5556a2 Fix primitive table lexical analysis.
Sequences of digits in the table of a primitive may be matched
as decimal numbers instead of digits, and this breaks some
primitives.
2014-02-02 10:57:53 -08:00
Larry Doolittle be17bfc0e9 Spelling fixes
Mostly comments.
One user-visible string ("Evalutated to ") changed in the debug_eval_tree case.
2014-01-30 15:34:20 -08:00
Martin Whitaker 7e82a37fa3 Extend -gstrict-expr-width to cover unsized numbers.
To be strictly compliant with the standard and compatible with other
EDA tools, unsized numbers should be treated as having a fixed size
(the same size as an integer). The -gstrict-expr-width option is
extended to allow the user to enable this behaviour.
2013-10-20 23:16:11 +01:00
Cary R 07cc18284c Fix print token/argument mismatches and other cppcheck fixes 2013-09-09 13:34:38 -07:00