Commit Graph

47 Commits

Author SHA1 Message Date
Cary R 860761f9c6 More cppcheck fixes - part 2 2025-10-20 23:54:15 -07:00
Cary R 47cf3707fc Fix some warnings from msys2 build 2024-12-28 10:09:01 -08:00
Martin Whitaker 82a122372b Handle optional condition/step when evaluating for loops at compile time.
This fixes the compiler segfault seen in issue #1143.
2024-07-09 22:06:41 +01:00
Lars-Peter Clausen 3fc6ab5afc Replace assert() with ivl_assert() where line information is available
`ivl_assert()` is similar to `assert()` except that it will also include
source file and line information about the expression for which the assert
was triggered.

Use `ivl_assert()` instead of `assert()` where the line information is
available. This will generate better bug reports and make it easier to
diagnose why an assert is triggered.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-06-16 05:06:15 -07:00
Lars-Peter Clausen ea3884fa1e Support continue/break in constant functions
Add support for `continue` and `break` in constant functions. This is done
in a similar way to how `disable` is implemented for constant functions.

Two new global flags are introduced `loop_break` and `loop_continue` that
get set when evaluating the corresponding statement. If either of these
flags are set all other statements are ignored until the end of a loop is
reached. At the end of the loop both `loop_break` and `loop_continue` get
cleared. If `loop_break` was set before clearing it the loop is exited.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-06-11 08:50:30 -07:00
Stephen Williams 6c9c876c83 Add compiler support for break and continue
This includes support at the parser (pform) through enaboration
and the netlist format for the break and continue statements.

Elaboration actually already worked for for-loops, but since the code
generators need more information, this is a rewire of that support to
be explicit about for-loops. This means they are not rewritten as fancy
while loops. The code generators will have to handle that.

Given the elaboration of for-loops now work, write the vvp code generator
support needed to implement it.

Now that for-loops are presented as for-loops to the code generator, the
vlog95 code generator doesn't need to infer them anymore. Generate the code
more directly.

Also update the tests list so that the vlog95_reg tests all pass.
2023-01-15 21:46:20 -08:00
Lars-Peter Clausen 0a2cbcb4b7 Remove pre C++11 compatibility code for unique_ptr
There is compatibility code that defines unique_ptr  as auto_ptr if the C++
version is before C++11.

But there are already other parts of the codebase that do require C++11 and
the minimum required version to build the project is C++11. So remove the
compat code as it is no longer needed.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-10-15 12:32:02 +02:00
Stephen Williams dc203a20ba Handle the error case that the rval fails
There are some cases where the r-value for an assignment just can't
be elaborated. Instead of segfaulting on the error, handle it by
assuming that the nullptr came from an error message, and ignore it
going forward.
2022-04-23 18:52:15 -07:00
Martin Whitaker 82caccd4eb Handle negative OOB access to local array in constant function (issue #674)
The word select expression is a zero-based canonical index, but the
expression evaluation may return a negative value.
2022-04-10 21:34:30 +01:00
Martin Whitaker 3b1b611a18 Fix evaluation of out-of-bounds bit/part-select in constant function (issue #531). 2021-07-30 20:34:47 +01:00
Cary R da7484eea1 Update compiler with suggestions from cppcheck 2021-01-02 14:04:46 -08:00
Martin Whitaker 78317a2799 Fix auto_ptr deprecated warnings when building with recent GCC. 2018-10-06 17:15:31 +01:00
Martin Whitaker 635adfc01e Fully support variable initialization in tasks/functions/named blocks. 2016-03-19 13:04:38 +00:00
Martin Whitaker 241b6723e5 Fix lval extension for compressed assignment in constant function.
The type of extension (zero/sign) is determined by the expression
type, not the operand type, so we need to cast to the expression
type before extending the value.
2016-02-23 16:46:26 +00:00
Martin Whitaker f9f51db7ba Extended constant function assignment operator support to real values.
Also output a "sorry" message if the LHS is a concatenation.
2016-02-22 23:31:35 +00:00
Martin Whitaker 74b8c04b91 Add support for SystemVerilog assignment operators in constant functions. 2016-02-22 22:22:22 +00:00
Stephen Williams f8dc430fe5 Add synthesis support for casez statements.
This generates an EQZ LPM device that carries the case-z-ness to
the code generator.

Also add to the vvp code generator support for the EQZ device so
that the synthesis results can be simulated.

Account for the wildcard devices in the sizer.
2014-06-13 18:01:41 -07:00
Stephen Williams be0c61051d Add synthesis of for-loops
This required keeping for-loops as actual things through the
netlist form so that the synthesizer can get at and understand
the parts of the for-loop. This may improve vvp code generation
in the future, but for now continue to present to the vvp code
generation the block-while form.
2014-05-08 15:05:08 -07: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
Cary R a196af8e15 Rework constant system function code and add $rtoi and $itor 2013-10-11 10:52:02 -07:00
Stephen Williams 7bc94d7810 Support functions that return void. 2013-09-20 20:44:57 -07:00
Cary R d8f945be23 Add support for SV do/while 2013-09-16 20:02:09 -07:00
Stephen Williams 3446455055 Support compile-time evaluation of named blocks. 2013-06-12 14:21:35 -07:00
Stephen Williams af304fea65 Fix repeated use of disabled const functions.
If constant functions are exited by a return/disable, fix
the leaked "disable" flag that causes blocks in the next
try at the function to not work.

There are also a lot of debug messages added to help find
this and similar problems.
2013-06-12 14:09:08 -07:00
Stephen Williams 5c00b96127 Handle constant functions from other scopes, i.e. packages. 2013-06-12 14:09:08 -07:00
Martin Whitaker 9a69fcff7b Handle out-of-bounds and undefined word indices in constant functions. 2013-05-18 19:39:24 +01:00
Martin Whitaker c4257ecfc9 Add support for array variables inside constant user functions. 2013-04-19 22:08:59 +01:00
Martin Whitaker a91840c15d Support concatenations in LHS of assignments in constant user functions. 2013-04-19 22:08:59 +01:00
Martin Whitaker 23dbfabb1e Further support for constant functions.
Add support for case, forever, and repeat statements in constant
functions. Also fix a bug in the constant function implementation
of NetESelect when used for zero/sign extension.
2013-04-07 19:13:30 +01:00
Martin Whitaker b80401e1ee Improved error reporting for constant user functions. 2013-03-24 14:43:10 -07:00
Martin Whitaker 1bcd3a97ad Support disable statements and system task calls in constant functions.
This patch implements the evaluate_function method for the NetDisable
and NetSTask classes. It also makes the checks for a function being
constant work when the function contains nested scopes (named blocks).
2013-03-24 14:42:59 -07:00
Martin Whitaker 5929a00845 Handle uninitialised variables in constant user functions. 2013-03-24 14:40:44 -07:00
Martin Whitaker 5d7558b5e0 Fix assigned vector size in constant user functions.
When assigning to a bit/logic variable, the RHS expression value
must be trimmed to match the size of the variable.
2013-03-24 14:40:10 -07:00
Martin Whitaker e8d4039175 Fix implicit casts in assignments (part 4).
This patch fixes a few issues/bugs that showed up when testing the
fixes for implicit casts:

1. Make the compile-time implementation of $abs, $min, and $max match
   the run-time behaviour (system functions can't be polymorphic).

2. Correctly set the type (signed/unsigned) of the result of an
   assignment inside a constant user function (the LHS should not
   inherit the type of the RHS).

3. Fix a bug in the verinum(double) constructor (insufficient bits
   were allocated in the case where the double value rounded up to
   the next power of two).
2013-03-24 13:50:59 -07:00
Martin Whitaker 8b70fefa59 Refactor eval_tree debug code.
This just pulls the eval_tree debug message generation into one place.
2013-02-08 11:22:49 -08:00
Martin Whitaker af91920a17 Add support for system function calls in constant functions. 2013-02-08 11:19:26 -08:00
Martin Whitaker 89244e0f70 Add support for concatenation operations in constant functions.
Also fix a compiler crash when attempting to evaluate a function
which has no valid statement(s) (due to earlier compilation errors).
2013-02-08 11:19:17 -08:00
Cary R 5830e65829 Fix space issues. 2013-02-04 12:17:41 -08:00
Martin Whitaker f3a51fdfd1 Factor out some common eval_tree code.
The eval_tree() function is identical in most of the NetEBinary and
NetEUnary sub-classes.
2013-02-04 12:17:29 -08:00
Martin Whitaker afd23d13d5 Add support for unary operators in constant user functions.
This patch implements the evaluate_function method for the NetEUnary
and NetEUReduce classes.
2013-02-04 12:17:05 -08:00
Martin Whitaker 11f479e028 Add support for all binary operators in constant user functions.
This patch implements the evaluate_function method for the NetEBBits,
NetEBDiv, NetEBLogic, NetEBMinMax, and NetEBPow classes. It also
factors out some common code into the NetEBinary class.
2013-02-04 12:16:51 -08:00
Arun Persaud f5aafc32f9 updated FSF-address 2012-08-29 10:12:10 -07:00
Larry Doolittle befff82655 Spelling fixes
Comments and debug messages.
2012-07-27 18:25:32 -07:00
Martin Whitaker 3354d83391 Support if statements and function calls in constant functions. 2012-06-06 19:34:08 -07:00
Stephen Williams 62b67c1843 More expression types supported during constant function evaluation. 2012-05-29 17:59:29 -07:00
Stephen Williams a5a7050120 More expression types work in constant functions. 2012-05-29 13:56:16 -07:00
Stephen Williams def9d0ea1d Basic infrastructure for compile-time function evaluation. 2012-05-29 10:02:10 -07:00