Commit Graph

250 Commits

Author SHA1 Message Date
Martin Whitaker 628f5645bf Fix file/line reported for duplicate parameter declarations.
We need to retain the old parameter information until we have reported
the error.
2019-09-27 22:19:30 +01: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
Martin Whitaker 55219773fd Allow nested scopes to use their parent's imports. 2019-09-27 22:19:30 +01: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 988816c0b1 Support separate compilation units in SystemVerilog.
The compilation unit scope is now treated as a specialised form of
package (with an automatically generated name). All items declared
outside a design element are added to the current compilation unit
package. Apart from when searching for a symbol, once we get into
elaboration we can treat these just like any other package.
2017-10-31 20:38:59 +00:00
Martin Whitaker 87cddf33dc Fix for GitHub issue #98 and #167
Two fixes needed:
  - when searching for a base class, we need to look in the root scope
    if the base class isn't found in the scope hierarchy
  - the classes in the root scope need to be stored in an ordered
    list, not a map, to ensure they are elaborated in the order they
    were declared. Without this, the compiler may try elaborating an
    extended class before its base class is known about.
2017-10-08 21:15:11 +01:00
Vamsi Vytla cfd3b893be Add support to handle attributes at module instantiation sites.
(* my_fancy_attribute *)
foobar1 foobar (clk(clk), rst(rst) ...);

  - Modifies PGModule to hold the attribute map (can be verified with pform_dump)
  - pform_make_modgate(s) bind the attributes from the parser to the above map
  - The attributes from PGModule are inserted into the NetScope of that module
    PGModule::elaborate_scope_mod_instances_
  - Currently these attributes automatically make it into netlist
  - These attributes are accessible via ivl_scope_attr_cnt and ivl_scope_attr_val
    from ivl_target.h
2017-03-16 07:41:10 -07:00
Johann Klammer 8bccbe7cb5 fix for const eval 2017-02-17 09:55:39 -08:00
Martin Whitaker 7bed181f68 Support timescales in design units that aren't inside a module.
SystemVerilog allows tasks, functions, and classes to be defined at the
root level or inside packages, so we can't rely on an enclosing module
being present to provide the timescale.
2016-07-22 22:48:20 +01:00
Larry Doolittle 4dd65926ae Spelling fixes 2015-08-17 11:35:10 -07:00
Martin Whitaker 5facf243cd Fix for br990 - handle empty expression in parameter assignment by name. 2015-08-07 21:11:07 +01:00
Martin Whitaker b400532169 Added support for interface declaration and instantiation.
modport and extern tf declarations are not yet supported.
2014-12-19 23:10:14 +00:00
Martin Whitaker 60ab1daa1f Restore some master branch fixes lost in the vec4-stack merge. 2014-12-07 12:10:15 +00:00
Stephen Williams 2aeb3871ed Merge branch 'master' into vec4-stack
This was a challenging merge...
Conflicts:
	elab_scope.cc
	synth2.cc
	tgt-vvp/eval_expr.c
	vvp/vthread.cc
2014-11-13 16:26:15 -08:00
Cary R 6948c27c2d Enumerations are compatible if their type definitions match. 2014-11-04 15:05:49 -08:00
Cary R 2e9c4cde55 More refined check for enumeration width and constant width 2014-11-04 12:10:38 -08:00
Cary R cc9fcfd13d Only a literal constant size has to match the enumeration width. 2014-11-03 19:46:10 -08:00
Cary R 4660e0bf2f Another tweak to the enumeration elaboration code 2014-11-02 20:26:36 -08:00
Cary R 1e7509a021 Update enumeration elaboration checks 2014-11-02 11:45:19 -08:00
Stephen Williams d5123011b3 Merge branch 'master' into vec4-stack
Conflicts:
	elab_scope.cc
2014-11-01 14:57:05 -07:00
Cary R c25538d750 Pass the integer type for enumerations to the IVL target stage 2014-10-31 18:09:19 -07:00
Cary R 4f62a0d1f2 Check enum trimmed bits for values with undefined bits
If an enumeration constant has undefined bits then we need to verify that
the bits that are trimmed match the MSB of the remaining bits.
2014-10-30 19:54:38 -07:00
Cary R e7df9774aa When comparing that an enumeration is in range cast the value to 2-state
When checking that an enumeration value is in range we need to cast it to
a 2-state value so that when we compare it we get a true or false value
instead of an undefined value. Undefined bits in the comparison return
undefined which is not logically false.
2014-10-30 18:23:47 -07:00
Stephen Williams a98f21aa65 Merge branch 'master' into vec4-stack
Conflicts:
	elab_lval.cc
	netmisc.cc
	tgt-vvp/eval_object.c
	tgt-vvp/vvp_process.c
	vvp/codes.h
	vvp/compile.cc
	vvp/opcodes.txt
	vvp/vpi_tasks.cc
	vvp/vpi_vthr_vector.cc
	vvp/vthread.cc
2014-10-21 09:12:02 -07:00
Stephen Williams 712f394224 Elaborate classes in packages. 2014-10-10 18:53:53 -07:00
Stephen Williams c5fee8bdb9 Elaborate root tasks/functions. 2014-09-30 16:06:32 -07:00
Stephen Williams 480668fee6 Add support for classes defined in $root scope. 2014-09-15 17:37:30 -07:00
Stephen Williams fa21527e9f Classes in $root scope up to elaboration. 2014-09-15 17:37:30 -07:00
Stephen Williams 697701a26e Sorry messages for property arrays. 2014-09-07 17:48:19 -07:00
Stephen Williams 1465fd1570 Class definitions may reference class types in containing scopes.
We need the scope where the class is defined so that it can find
types in that containing scope. Note that most definitions cannot
escape into the the lexical scope of the class, but some can.
2014-09-02 09:22:41 -07:00
Cary R 8c3f7d78b9 Partial fix for br956 (various enumeration bugs)
This patch fixes the following enumeration bugs:

When looking for an enumeration look in the current scope and then
recursively in any parent scope.

Add enumeration definitions to a package scope.
2014-08-28 13:02:42 -07:00
Stephen Williams f602ae84ab Elaborate foreach loops as synthetic for loops.
Create an implicit scope to hold the index variable, and
generate a for loop to perform the functionality of the
foreach.
2014-08-21 16:44:46 -07:00
Stephen Williams 2e2317b7c7 Generalize the hname_t to handle n-dimensional scope arrays.
... Not that they actually exist yet. But this fixes some symbol
search issues and makes room for this support in the future.
2014-04-06 08:40:09 -07:00
Stephen Williams b5e0099f28 Fix support for enum literals with undefined values. 2014-03-01 17:45:13 -08:00
Martin Whitaker a3450bf856 Fixes for GitHub issues 13 and 15.
The verinum arithmetic operators now observe the standard Verilog
rules for calculating the result width if all operands are sized.
If any operand is unsized, the result is lossless, as before.
They also now all observe the standard rules for handling partially
undefined operands (if any operand bit is 'x', the entire result is
'x').

I've also added the unary '-' operator, and renamed v_not() to be
the unary '~' operator. This has allowed some simplification in
other parts of the compiler.
2014-02-25 20:39:21 +00:00
Stephen Williams fc42f40770 Fix problem with enum types in re-used modules
When a module is instantiated multiple times, the enum
types contained within would cause trouble. This fixes
that by elaborating in proper scope context.
2014-01-11 19:19:15 -08:00
Stephen Williams a3b29dd70b Handle enumeration literals that are in $root. 2014-01-11 19:19:14 -08:00
Stephen Williams 819770a6c4 Handle enumerations as packed struct/union members.
There were also some subtleties related to using enumerations
from typedefs and using them in multiple places. Fix various
bugs related to those issues.
2013-12-07 12:20:28 -08:00
Stephen Williams 9bd9c8f301 Implement class extends arguments.
This implements constructor arguments right after the base class
name in the class extends syntax.
2013-11-10 18:03:19 -08:00
Stephen Williams f16fd03dab Elaborate PChainConstructor calls.
It is better to leave the handling of PChainConstructor calls to
the elaboration, instead of stripping them out early. This allows
for handling the arguments of the chain constructor in the correct
scope.
2013-11-10 18:03:19 -08:00
Stephen Williams a7d8c983ba Blend initializer statements into any explicit constructor.
If there is an explicit constructor, then blend all the statements
of the implicit constructor into it so that there is only one
constructor function.
2013-11-10 18:03:19 -08:00
Stephen Williams d192f545ac Chain class instance constructors with arguments. 2013-11-10 18:03:19 -08:00
Stephen Williams 9f83882bcc Parse/elaborate class derivation
This gets us down to working classes, but does not yet implement
calls to the parent constructor, implicitly or explicitly.
2013-11-10 18:03:19 -08:00
Cary R d8f945be23 Add support for SV do/while 2013-09-16 20:02:09 -07:00
Stephen Williams cf47a759d1 Implement the "local" class member protection.
Test during elaboration that the member really is
accessible in the context where the elaboration
happens.
2013-07-02 20:16:47 -07:00
Stephen Williams 046535cfbb Blend implicit constructor with explicit constructor
Class types that have both implicit construction and
an explicit constructor can blend the implicit and
explicit construction into the "new" function defined
by the user. This doesn't change the behavior any, but
removes a function call and related scope.
2013-07-02 20:16:47 -07:00
Stephen Williams 75b4b94061 Elaborate implicit initializers
Remaining pform fixup of property initializers, and
elaboration and code generation for implicit constructor.
2013-07-02 20:16:46 -07:00
Stephen Williams d346fb098f Collect initializer statements in the pform. 2013-07-02 20:16:46 -07:00
Cary R 431d62185b vlog95: Emit a new doing a shallow copy as an error. 2013-04-30 11:52:52 -07:00
Stephen Williams de6c57d661 Elaborate classes in lexical order so that mutual references work. 2013-04-28 16:28:24 -07:00
Stephen Williams 20ee350601 Generalize user defined function return type handling.
I'm gonna need functions to return class objects, so generalize
the output types of user defined functions.
2013-04-20 16:38:35 -07:00
Stephen Williams 4ad556d464 Update some copyright notices. 2013-04-08 18:35:37 -07:00
Stephen Williams 44cd9158e8 Elaborate parameters, tasks and functions in packages.
Get the elaboration to happen all the way to the ivl_target
interface.
2013-04-08 18:20:39 -07:00
Stephen Williams 17330a3073 Elaborate class task and function methods.
The parse of class methods already works, this patch forms
the methods into their own scopes, and elaborates those scopes.
The "this"
2013-03-24 15:12:35 -07:00
Stephen Williams fac5cbca43 Handle this as special identifier strings. / Organize pform class member binding 2013-03-24 15:03:52 -07:00
Stephen Williams 60cb78e4ab Add packages and their own scope.
This makes <pkg>::<name> work properly, and also makes the
package descriptions available through VPI.
2013-02-17 17:00:15 -08:00
Stephen Williams 318a4033b8 Flesh out class type elaboration
Add properties to the classes, and elaborate expressions that
have class properties. Describe class object property references
all the way down to the stub target.
2012-12-10 19:20:02 -08:00
Stephen Williams 77d24cd095 Elaborate class_new and (null) expressions
This gets the types right for class_new and null expressions, and
elaborate them down to the ivl_target.h API.
2012-12-10 19:13:43 -08:00
Cary R e0f82981e7 Remove some compiler warnings 2012-09-24 10:28:17 -07:00
Stephen Williams 0bdabab4fb Rework packed dimensions handling
Make packed structs more obviously parts of a vector.
Handle arrays of structs in certain cases.
2012-09-03 16:00:10 -07:00
Arun Persaud f5aafc32f9 updated FSF-address 2012-08-29 10:12:10 -07:00
Martin Whitaker 1f152aa838 Fix for pr3557493.
defparam assignments found inside a generate block were being stored
in the enclosing module scope. They should be stored in the generate
block scope.

Also removed the genvar list from the PGenerate class, as this is
already declared in the base LexicalScope class.
2012-08-21 17:46:34 -07:00
Martin Whitaker 0d0e6d7845 Fix elaboration order in generate blocks.
Currently, localparam declarations inside generate blocks are
elaborated after any nested generate constructs are elaborated.
This prevents the localparams being used by the nested constructs.
Reversing the elaboration order fixes this bug.
2012-07-01 12:07:49 -07:00
Andrew Stevens 9b3d20239a Extend VPI and build to for SIMetrix cosimulation
Added: basic vpiPort VPI Objects for vpiModulkes
    vpiDirection, vpiPortIndex,   vpiName, vpiSize attributes

   Since ports do not exist as net-like entities (nets either side
   module instance boundaries are in effect connect directly in
   the language front-ends internal representation) the port information
   is effectively just meta-data passed through t-dll  interface and
   output as a additional annotation of module scopes in vvp.

Added: vpiLocalParam attribute for vpiParameter VPI objects

Added: support build for 32-bit target on 64-bit host (--with-m32
   option to configure.in and minor tweaks to Makefiles and systemc-vpi).
2012-06-07 08:00:02 -07:00
Stephen Williams 6a57764e0e Elaborate fork-join_none and fork-join_any statements. 2012-05-27 18:26:53 -07:00
Stephen Williams 8154ce2a4a Reword how we enforce program block constraints
Making the scope type NESTED_MODULE was just plain wrong, because
it didn't really encapsulate the meaning of program blocks OR
nested modules. So instead create nested_module() and program_block()
flags and use those to test scope constraints.
2012-05-27 18:26:53 -07:00
Stephen Williams dfe7beec31 Allow modules (and program blocks in particular) to nest.
An important advantage of program blocks is its ability to nest
within a module. This winds up also allowing modules to nest, which
is legal but presumably less used feature.
2012-05-27 18:26:53 -07:00
Martin Whitaker 509ec1dcb1 Simplify parameter handling in the elaborated netlist.
A NetScope object currently has two lists of parameters, 'parameters'
and 'localparams'. However, user-declared localparams are stored in
the 'parameters' list, and 'localparams' is only used for adding
genvar values to the parameter list. There seems no good reason to
maintain separate lists, as the lists are merged before being passed
to the target DLL. This is most likely a hang-over from older code.
2012-05-17 16:29:06 -07:00
Martin Whitaker 44c5a37ab8 Allow specparam declarations outside specify blocks.
This patch extends the compiler to support all specparam declarations
allowed by the 1364-2005 standard. For compatibility with other
simulators, it allows specparam values to be used in any constant
expression, but outputs a warning message and disables run-time
annotation of a specparam if it is used in an expression that must
be evaluated at compile time.
2012-05-17 16:18:38 -07:00
Stephen Williams 69c10c4722 Handle case generate under a conditional generate that is unnamed.
When a conditional statement is unnamed, it doesn't create a scope
and we get into "direct" generate scheme elaboration. This direct
elaboration needs to handle case generate schemes.
2012-04-30 16:00:25 -07:00
Stephen Williams 13348ba7ac Ranges are ranges, not expression lists.
This is a cleanup in preparation for better support of range lists.
(cherry picked from commit 8f7cf3255acad55841f8b3725e3786ef49daad68)

Conflicts:

	PTask.h
	elab_scope.cc
	elab_sig.cc
	parse.y
	pform.cc
	pform.h
	pform_types.h

Signed-off-by: Stephen Williams <steve@icarus.com>
2012-04-10 14:29:28 -07:00
Stephen Williams f749867369 Rework rules for variable_dimensions, and support more syntax. 2012-03-02 18:34:43 -08:00
Cary R 3b6e26aa90 An enumeration cannot have duplicate values.
Add code to check that an enumeration does not have duplicate values.
2011-10-01 09:32:37 -07:00
Stephen Williams 52019b0e55 Merge branch 'master' into work8 2011-09-18 19:48:50 -07:00
Stephen Williams f0bf64271b SystemVerilog has more lax rules for function declarations.
Allow empty parameter lists
Allow lists of statements instead of simple statements.
2011-09-17 12:10:05 -07:00
Cary R b2ebc29c5a Fix some enum bugs.
This patch fixes a few more bugs in the enumeration code.

It add support for saving the file and line information to make
diagnostic messages better.

It updates some of the compiler warning messages to use the file
and line information.

It passes if the enumeration type is signed all the way to the
code generators.

It fixes the parser to correctly have the range after the signed
designation for the vector types.

It adds a warning that vvp does not currently support a negative
two state enumeration value.
2011-09-11 11:32:16 -07:00
Cary R fd4f07906d Check that enum initializations are in range.
This patch adds checks to verify that all enum initializations (explicit
or implicit) are in range.
2011-07-19 19:57:49 -07:00
Martin Whitaker 1e9f9685cc First step towards supporting constant user functions.
This patch allows the compiler to perform early elaboration
of functions if they are encountered in expressions that are
elaborated before the function would normally be elaborated.
This makes the function available for constant evaluation.
Suitable error messages are generated if a function that is
used in a constant expression is not a valid constant function.
2011-04-13 18:40:19 -07:00
Martin Whitaker 93067149f1 Rework of constant expression error reporting.
This patch changes the method used to signal that a constant expression
is being elaborated from flags stored in global variables to flags
passed down the call chain. It also generates more informative error
messages when variable references are found in a constant expression.
2011-04-06 18:50:53 -07:00
Cary R 2a0d33608f Fix spacing problems.
This patch fixes spacing problems in the source code, space/tab at
the end of line and space before tab.
2011-03-03 11:21:31 -08:00
Martin Whitaker 312b4da46f Expression width rework.
This patch is a major rework of expression elaboration and
evaluation in the compiler, aimed at better compliance with
the IEEE standard.
2011-03-01 18:13:26 -08:00
Martin Whitaker b89ab1f2b0 Cleanup after parameter expression rework.
This patch removes some code made redundant by the rework of
parameter expression evaluation. It also documents the new
-g option.
2010-12-06 14:56:59 -08:00
Martin Whitaker 275dde7712 Rework of parameter expression elaboration.
The compiler currently performs parameter expression elaboration before
performing parameter overrides. This means that the information needed
to correctly determine the expression type and width may not be available
at the time elaboration is performed. This patch reworks the code to
delay elaboration until after all overrides have been performed. It
also provides a new -g option that controls how the width of parameter
expressions is calculated when the parameter itself is unsized.
2010-12-06 14:56:50 -08:00
Stephen Williams 16e1570737 Merge branch 'master' into work2
Conflicts:
	elab_scope.cc
	net_nex_input.cc
	t-dll-api.cc
	vvp/parse.y
2010-11-28 08:38:40 -08:00
Stephen Williams 3b91a22791 Get the width of an enumeration name right during elaboration. 2010-11-22 18:55:27 -08:00
Stephen Williams de215f1f8d Describe enum type to code generators
This gets the enumeration type through to the ivl_target API so
that code generators can do something with it. Generate stub
output with tgt-stub, and generate the proper vvp run time to
make simple enumerations work from end to end.
2010-11-20 15:09:32 -08:00
Stephen Williams 27dfdf99dd Enumeration element values can be expressions
Allow more complex enumeration expressions, which means putting
off the evaluation of the expression values until elaboration.
2010-11-12 18:47:06 -08:00
Stephen Williams 2f474358d9 Support enumeration element ranges.
This also fixes:
Set verinum.has_sign() correctly for enum values.
2010-11-09 21:05:47 -08:00
Stephen Williams 5e2c0e5d04 Better handling of width of enum literals in expressions. 2010-11-07 09:58:00 -08:00
Stephen Williams cd6c6c7a70 Get the netenum_t base type data from the pform.
The pform propagates the parsed enum base type information
to the elaborator so that the base type can be fully elaborated.
This is necessary to get the types of the enumeration literals
correct.
2010-11-03 20:11:19 -07:00
Stephen Williams 5b5a6b05b7 Test type correctness during elaboration.
Create a netenum_t class to carry the enumeration type in the
netlist.h structures, and use that type to check enumerations
with assignments.
2010-11-02 20:16:42 -07:00
Cary R bb5ca97f2d Fix some -Wextra warnings and some other bug fixes/enhancements.
This patch covers more than it should. It removes many of the -Wextra
warnings in the main ivl directory. It also makes some minor code
improvements, adds support for constant logicals in eval_tree (&&/||),
adds support for correctly sign extending === and !==, it starts to
standardize the eval_tree debug messages and fixes a strength bug
in the target interface (found with -Wextra). The rest of the warnings
and eval_tree() rework will need to come as a second patch.
2010-11-02 11:05:11 -07:00
Cary R 225ca1e205 Change iterators to use prefix ++ since it is more efficient.
This patch changes all the iterator code to use a prefix ++ instead
of postfix since it is more efficient (no need for a temporary). It
is likely that the compiler could optimize this away, but lets make
it efficient from the start.
2010-11-02 10:43:16 -07:00
Stephen Williams a14fa038b4 Enum names in r-value expressions
When enum names are used as r-values in expressions, use their
values. Treat the enum names similar to (but not exactly as)
localparams so that they fit into the rest of the elaboration
flow naturally.
2010-10-31 11:26:09 -07:00
Stephen Williams cced1e771b Remove some uses of the svector template.
I'm adding more uses of the make_range_from_width function, so
it seems like time to get rid of its use of the svector template.
This thread led to a lot of other uses of svector that had to
also be removed.
2010-10-25 19:36:44 -07:00
Cary R 1993bf6f69 Remove malloc.h support and for C++ files use <c...> include files.
The functions (malloc, free, etc.) that used to be provided in
malloc.h are now provided in cstdlib for C++ files and stdlib.h for
C files. Since we require a C99 compliant compiler it makes sense
that malloc.h is no longer needed.

This patch also modifies all the C++ files to use the <c...>
version of the standard C header files (e.g. <cstdlib> vs
<stdlib.h>). Some of the files used the C++ version and others did
not. There are still a few other header changes that could be done,
but this takes care of much of it.
2010-06-01 08:56:30 -07:00
Cary R 128f3d29cc Fix new shadow issues and add -Wshadow to gcc compile.
Some new shadow issues have crept in. This patch fixes these new
issues and adds -Wshadow to the normal warning flags to keep any
new occurrences from happening.
2010-05-13 19:04:13 -07:00
Cary R b91657dbb9 Fix a few more cppcheck issues.
Here are some more cleanups recommended by cppcheck. Mostly fixing the
variable scope and removing some unneeded code.
2010-04-23 11:40:26 -07:00
Martin Whitaker f95593716f Fix for pr2924354.
Creation of implicit nets requires knowledge of whether an identifier
has been declared before it is used. Currently implicit nets are
created during elaboration, but by this stage the order of declaration
and use is not known. This patch moves the creation of implicit nets
into the parser stage.
2010-01-23 09:10:00 -08:00
Cary R 8abf303753 Don't replace parameter overrides that did not evaluate.
Trying to replace a parameter override that did not evaluate
correctly can lead to a crash, so just skip the substitution.
2009-10-13 21:28:37 -07:00