2014-07-23 22:39:29 +02:00
|
|
|
#ifndef IVL_compiler_H
|
|
|
|
|
#define IVL_compiler_H
|
1999-06-06 22:42:48 +02:00
|
|
|
/*
|
2021-01-11 03:22:20 +01:00
|
|
|
* Copyright (c) 1999-2021 Stephen Williams (steve@icarus.com)
|
1999-06-06 22:42:48 +02:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1999-06-06 22:42:48 +02:00
|
|
|
*/
|
|
|
|
|
|
2001-10-21 01:02:39 +02:00
|
|
|
# include <list>
|
2003-09-25 02:25:14 +02:00
|
|
|
# include <map>
|
2004-03-09 05:29:42 +01:00
|
|
|
# include "netlist.h"
|
2003-03-01 07:25:30 +01:00
|
|
|
# include "StringHeap.h"
|
2001-10-21 01:02:39 +02:00
|
|
|
|
1999-06-06 22:42:48 +02:00
|
|
|
/*
|
|
|
|
|
* This defines constants and defaults for the compiler in general.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2007-10-09 04:58:49 +02:00
|
|
|
/*
|
|
|
|
|
* The integer_width is the width of integer variables. This is also
|
|
|
|
|
* the minimum width of unsized integers when they are found in
|
|
|
|
|
* self-determined contexts.
|
|
|
|
|
*/
|
2007-03-07 05:24:59 +01:00
|
|
|
extern unsigned integer_width;
|
1999-06-06 22:42:48 +02:00
|
|
|
|
2014-02-27 20:20:20 +01:00
|
|
|
/*
|
|
|
|
|
* The width_cap is the width limit for unsized expressions.
|
|
|
|
|
*/
|
|
|
|
|
extern unsigned width_cap;
|
|
|
|
|
|
2009-04-08 03:31:42 +02:00
|
|
|
/*
|
|
|
|
|
* This is the maximum number of recursive module loops allowed within
|
|
|
|
|
* a generate block.
|
|
|
|
|
*/
|
|
|
|
|
extern unsigned recursive_mod_limit;
|
|
|
|
|
|
2000-10-31 18:49:02 +01:00
|
|
|
/* The TIME_WIDTH is the width of time variables. */
|
|
|
|
|
#ifndef TIME_WIDTH
|
|
|
|
|
# define TIME_WIDTH 64
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-08-20 06:13:56 +02:00
|
|
|
/*
|
|
|
|
|
* When doing dynamic linking, we need a uniform way to identify the
|
|
|
|
|
* symbol. Some compilers put leading _, some trailing _. The
|
|
|
|
|
* configure script figures out which is the local convention and
|
|
|
|
|
* defines NEED_LU and NEED_TU as required.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef NEED_LU
|
|
|
|
|
#define LU "_"
|
|
|
|
|
#else
|
|
|
|
|
#define LU ""
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef NEED_TU
|
|
|
|
|
#define TU "_"
|
|
|
|
|
#else
|
|
|
|
|
#define TU ""
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2000-03-17 22:50:25 +01:00
|
|
|
/*
|
|
|
|
|
* These are flags to enable various sorts of warnings. By default all
|
2003-11-08 21:06:21 +01:00
|
|
|
* the warnings are off, the -W<list> parameter arranges for each to be
|
2004-10-04 03:10:51 +02:00
|
|
|
* enabled.
|
2000-03-17 22:50:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Implicit definitions of wires. */
|
|
|
|
|
extern bool warn_implicit;
|
|
|
|
|
|
2016-02-07 01:07:50 +01:00
|
|
|
/* Warn if dimensions of port or var/net are implicitly taken from
|
|
|
|
|
the input/output/inout declaration. */
|
|
|
|
|
extern bool warn_implicit_dimensions;
|
|
|
|
|
|
2003-01-30 17:23:07 +01:00
|
|
|
/* inherit timescales across files. */
|
2002-04-15 02:04:22 +02:00
|
|
|
extern bool warn_timescale;
|
|
|
|
|
|
2003-02-22 05:12:49 +01:00
|
|
|
/* Warn about legal but questionable module port bindings. */
|
|
|
|
|
extern bool warn_portbinding;
|
|
|
|
|
|
2009-08-25 19:31:08 +02:00
|
|
|
/* Warn about constant out of bound selects. */
|
|
|
|
|
extern bool warn_ob_select;
|
|
|
|
|
|
2008-04-22 20:32:10 +02:00
|
|
|
/* Warn about structures that may have infinite loops. */
|
|
|
|
|
extern bool warn_inf_loop;
|
|
|
|
|
|
2009-09-05 11:15:10 +02:00
|
|
|
/* Warn about always @* statements where a part or word select causes
|
|
|
|
|
sensitivity to an entire vector or array. */
|
|
|
|
|
extern bool warn_sens_entire_vec;
|
|
|
|
|
extern bool warn_sens_entire_arr;
|
|
|
|
|
|
2014-01-31 01:16:19 +01:00
|
|
|
/* Warn about level-appropriate anachronisms. */
|
2012-05-01 01:30:24 +02:00
|
|
|
extern bool warn_anachronisms;
|
|
|
|
|
|
2015-10-02 00:17:03 +02:00
|
|
|
/* Warn about nets that are references but not driven. */
|
|
|
|
|
extern bool warn_floating_nets;
|
|
|
|
|
|
2001-10-21 01:02:39 +02:00
|
|
|
/* This is true if verbose output is requested. */
|
|
|
|
|
extern bool verbose_flag;
|
|
|
|
|
|
2004-09-05 19:44:41 +02:00
|
|
|
extern bool debug_scopes;
|
2004-09-11 01:51:42 +02:00
|
|
|
extern bool debug_eval_tree;
|
2004-09-25 03:58:44 +02:00
|
|
|
extern bool debug_elaborate;
|
2013-03-18 01:44:15 +01:00
|
|
|
extern bool debug_emit;
|
2005-04-25 01:44:01 +02:00
|
|
|
extern bool debug_synth2;
|
2008-05-23 19:29:44 +02:00
|
|
|
extern bool debug_optimizer;
|
2004-09-05 19:44:41 +02:00
|
|
|
|
2017-03-21 16:34:44 +01:00
|
|
|
/* Ignore errors about missing modules */
|
|
|
|
|
extern bool ignore_missing_modules;
|
|
|
|
|
|
2017-10-15 12:45:35 +02:00
|
|
|
/* Treat each source file as a separate compilation unit (as defined
|
|
|
|
|
by SystemVerilog). */
|
|
|
|
|
extern bool separate_compilation;
|
|
|
|
|
|
2013-03-08 00:33:52 +01:00
|
|
|
/* Control evaluation of functions at compile time:
|
|
|
|
|
* 0 = only for functions in constant expressions
|
|
|
|
|
* 1 = only for automatic functions
|
|
|
|
|
* 2 = for all functions
|
|
|
|
|
* Level 2 should only be used if the user can guarantee that a
|
|
|
|
|
* function's local variables are never accessed from outside the
|
|
|
|
|
* function. */
|
|
|
|
|
extern unsigned opt_const_func;
|
|
|
|
|
|
2009-03-06 02:44:11 +01:00
|
|
|
/* Possibly temporary flag to control virtualization of pin arrays */
|
|
|
|
|
extern bool disable_virtual_pins;
|
|
|
|
|
|
2013-02-14 04:12:54 +01:00
|
|
|
/* The vlog95 code generator does not want the compiler to generate concat-Z
|
|
|
|
|
* LPM objects so this flag is used to block them from being generated. */
|
|
|
|
|
extern bool disable_concatz_generation;
|
|
|
|
|
|
2009-03-11 17:18:30 +01:00
|
|
|
/* Limit to size of devirtualized arrays */
|
|
|
|
|
extern unsigned long array_size_limit;
|
|
|
|
|
|
2003-11-13 06:55:33 +01:00
|
|
|
/* Path to a directory useful for finding subcomponents. */
|
|
|
|
|
extern const char*basedir;
|
|
|
|
|
|
2003-01-30 17:23:07 +01:00
|
|
|
/* This is an ordered list of library suffixes to search. */
|
2021-11-04 17:12:04 +01:00
|
|
|
extern std::list<const char*>library_suff;
|
2002-05-28 22:40:37 +02:00
|
|
|
extern int build_library_index(const char*path, bool key_case_sensitive);
|
2001-10-21 01:02:39 +02:00
|
|
|
|
2002-05-24 03:13:00 +02:00
|
|
|
/* This is the generation of Verilog that the compiler is asked to
|
2005-07-07 18:22:49 +02:00
|
|
|
support. Then there are also more detailed controls for more
|
2016-09-09 00:00:48 +02:00
|
|
|
specific language features. Note that the compiler often assumes
|
|
|
|
|
this is an ordered list. */
|
2002-05-24 03:13:00 +02:00
|
|
|
enum generation_t {
|
|
|
|
|
GN_VER1995 = 1,
|
2009-06-02 02:19:56 +02:00
|
|
|
GN_VER2001_NOCONFIG = 2,
|
|
|
|
|
GN_VER2001 = 3,
|
|
|
|
|
GN_VER2005 = 4,
|
2011-01-09 00:35:52 +01:00
|
|
|
GN_VER2005_SV = 5,
|
|
|
|
|
GN_VER2009 = 6,
|
2013-04-02 23:39:49 +02:00
|
|
|
GN_VER2012 = 7,
|
2009-06-02 02:19:56 +02:00
|
|
|
GN_DEFAULT = 4
|
2002-05-24 03:13:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern generation_t generation_flag;
|
2006-09-28 06:35:18 +02:00
|
|
|
|
2008-05-08 02:46:56 +02:00
|
|
|
/* If this flag is true, enable extended types support. */
|
2005-07-07 18:22:49 +02:00
|
|
|
extern bool gn_cadence_types_flag;
|
|
|
|
|
|
2008-05-08 02:46:56 +02:00
|
|
|
/* If this flag is true, enable miscellaneous extensions. */
|
|
|
|
|
extern bool gn_icarus_misc_flag;
|
2002-05-24 03:13:00 +02:00
|
|
|
|
2006-09-28 06:35:18 +02:00
|
|
|
/* If this flag is true, then elaborate specify blocks. If this flag
|
|
|
|
|
is false, then skip elaboration of specify behavior. */
|
|
|
|
|
extern bool gn_specify_blocks_flag;
|
|
|
|
|
|
2023-08-08 11:42:15 +02:00
|
|
|
/* If this flag is true, then add input/output buffers to modules so that
|
|
|
|
|
VVP can insert intermodpaths inbetween. If this flag
|
|
|
|
|
is false, then no input/output buffers are inserted if not needed. */
|
|
|
|
|
extern bool gn_interconnect_flag;
|
|
|
|
|
|
2019-10-05 14:37:03 +02:00
|
|
|
/* If this flag is true, then elaborate supported assertion statements. If
|
|
|
|
|
this flag is false, then stub out supported assertion statements. */
|
|
|
|
|
extern bool gn_supported_assertions_flag;
|
|
|
|
|
/* If this flag is true, then error on unsupported assertion statements. If
|
|
|
|
|
this flag is false, then stub out unsupported assertion statements. */
|
|
|
|
|
extern bool gn_unsupported_assertions_flag;
|
2013-12-02 03:31:06 +01:00
|
|
|
|
2008-05-03 01:28:48 +02:00
|
|
|
/* If this flag is true, then support/elaborate Verilog-AMS. */
|
|
|
|
|
extern bool gn_verilog_ams_flag;
|
|
|
|
|
|
2007-08-22 04:52:42 +02:00
|
|
|
/* If this flag is false a warning is printed when the port declaration
|
|
|
|
|
is scalar and the net/register definition is vectored. */
|
|
|
|
|
extern bool gn_io_range_error_flag;
|
|
|
|
|
|
2008-12-22 22:48:34 +01:00
|
|
|
/* If this flag is true, then force re-evaluation of user functions
|
|
|
|
|
in a continuous assignment when any part of the expression is
|
|
|
|
|
re-evaluated. */
|
|
|
|
|
extern bool gn_strict_ca_eval_flag;
|
|
|
|
|
|
2010-12-05 22:28:17 +01:00
|
|
|
/* If this flag is true, then force strict conformance to the IEEE
|
|
|
|
|
standard expression width rules. */
|
|
|
|
|
extern bool gn_strict_expr_width_flag;
|
|
|
|
|
|
2016-03-05 18:43:25 +01:00
|
|
|
/* If this flag is true, then don't add a for-loop control variable
|
|
|
|
|
to an implicit event_expression list if it is only used inside the
|
|
|
|
|
loop. */
|
|
|
|
|
extern bool gn_shared_loop_index_flag;
|
|
|
|
|
|
2016-09-09 00:00:48 +02:00
|
|
|
static inline bool gn_system_verilog(void)
|
2010-10-08 05:13:11 +02:00
|
|
|
{
|
2016-09-09 00:00:48 +02:00
|
|
|
if (generation_flag >= GN_VER2005_SV)
|
2010-10-08 05:13:11 +02:00
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 00:00:48 +02:00
|
|
|
/* If variables can be converted to uwires by a continuous assignment
|
|
|
|
|
(assuming no procedural assign), then return true. This will be true
|
|
|
|
|
for SystemVerilog */
|
|
|
|
|
static inline bool gn_var_can_be_uwire(void)
|
2010-10-31 22:07:38 +01:00
|
|
|
{
|
2016-09-09 00:00:48 +02:00
|
|
|
return gn_system_verilog();
|
2010-10-31 22:07:38 +01:00
|
|
|
}
|
|
|
|
|
|
2012-05-10 04:35:11 +02:00
|
|
|
static inline bool gn_modules_nest(void)
|
|
|
|
|
{
|
|
|
|
|
return gn_system_verilog();
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-01 07:07:09 +02:00
|
|
|
/* The bits of these GN_KEYWORDS_* constants define non-intersecting
|
|
|
|
|
sets of keywords. The compiler enables groups of keywords by setting
|
|
|
|
|
lexor_keyword_mask with the OR of the bits for the keywords to be
|
|
|
|
|
enabled. */
|
|
|
|
|
enum { GN_KEYWORDS_1364_1995 = 0x0001,
|
|
|
|
|
GN_KEYWORDS_1364_2001 = 0x0002,
|
|
|
|
|
GN_KEYWORDS_1364_2001_CONFIG = 0x0004,
|
|
|
|
|
GN_KEYWORDS_1364_2005 = 0x0008,
|
2008-05-03 01:28:48 +02:00
|
|
|
GN_KEYWORDS_VAMS_2_3 = 0x0010,
|
2011-01-09 00:35:52 +01:00
|
|
|
GN_KEYWORDS_1800_2005 = 0x0020,
|
|
|
|
|
GN_KEYWORDS_1800_2009 = 0x0040,
|
2013-04-02 23:39:49 +02:00
|
|
|
GN_KEYWORDS_1800_2012 = 0x0080,
|
2008-05-01 07:07:09 +02:00
|
|
|
GN_KEYWORDS_ICARUS = 0x8000
|
|
|
|
|
};
|
|
|
|
|
extern int lexor_keyword_mask;
|
|
|
|
|
|
2002-05-28 02:50:39 +02:00
|
|
|
/* This is the string to use to invoke the preprocessor. */
|
|
|
|
|
extern char*ivlpp_string;
|
|
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
extern std::map<perm_string,unsigned> missing_modules;
|
2003-03-01 07:25:30 +01:00
|
|
|
|
2007-04-19 04:52:53 +02:00
|
|
|
/* Files that are library files are in this map. The lexor compares
|
|
|
|
|
file names as it processes `line directives, and if the file name
|
|
|
|
|
matches an entry in this table, it will turn on the
|
|
|
|
|
library_active_flag so that modules know that they are in a
|
|
|
|
|
library. */
|
2021-11-04 17:12:04 +01:00
|
|
|
extern std::map<perm_string,bool> library_file_map;
|
2007-04-19 04:52:53 +02:00
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
/*
|
|
|
|
|
* the lex_strings are perm_strings made up of tokens from the source
|
|
|
|
|
* file. Identifiers are so likely to be used many times that it makes
|
|
|
|
|
* much sense to use a StringHeapLex to hold them.
|
|
|
|
|
*/
|
2003-03-01 07:25:30 +01:00
|
|
|
extern StringHeapLex lex_strings;
|
2010-11-21 00:09:32 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The ivl_target.h API in a variety of places keeps strings of
|
|
|
|
|
* bits. Manage these as perm_string in a StringHeap.
|
|
|
|
|
*/
|
|
|
|
|
extern StringHeapLex bits_strings;
|
2004-03-09 05:29:42 +01:00
|
|
|
|
2007-12-20 18:31:01 +01:00
|
|
|
/*
|
|
|
|
|
* The filename_strings are perm_strings for file names. They are put
|
|
|
|
|
* into their own StringHeapLex because these paths are used a *lot*
|
|
|
|
|
* and this makes them more sure to hash together.
|
|
|
|
|
*/
|
|
|
|
|
extern StringHeapLex filename_strings;
|
|
|
|
|
|
|
|
|
|
|
2004-03-09 05:29:42 +01:00
|
|
|
/*
|
|
|
|
|
* system task/function listings.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* This table describes all the return values of various system
|
|
|
|
|
* functions. This table is used to elaborate expressions that are
|
|
|
|
|
* system function calls.
|
|
|
|
|
*/
|
|
|
|
|
struct sfunc_return_type {
|
|
|
|
|
const char* name;
|
2005-07-11 18:56:50 +02:00
|
|
|
ivl_variable_type_t type;
|
2004-03-09 05:29:42 +01:00
|
|
|
unsigned wid;
|
2019-10-19 17:12:17 +02:00
|
|
|
bool signed_flag;
|
|
|
|
|
bool override_flag;
|
2004-03-09 05:29:42 +01:00
|
|
|
};
|
|
|
|
|
|
2019-10-21 14:40:40 +02:00
|
|
|
extern void add_sys_func(const struct sfunc_return_type&ret_type);
|
2004-03-09 05:29:42 +01:00
|
|
|
extern const struct sfunc_return_type* lookup_sys_func(const char*name);
|
2004-03-10 05:51:24 +01:00
|
|
|
extern int load_sys_func_table(const char*path);
|
2009-06-09 22:12:45 +02:00
|
|
|
extern void cleanup_sys_func_table();
|
2019-10-21 14:40:40 +02:00
|
|
|
/*
|
|
|
|
|
* This temporarily loads a VPI module, to determine the return values
|
|
|
|
|
* of system functions provided by that module, and adds the return values
|
|
|
|
|
* to the system function table.
|
|
|
|
|
*/
|
|
|
|
|
extern bool load_vpi_module(const char*path);
|
2004-03-09 05:29:42 +01:00
|
|
|
|
2010-08-12 04:01:58 +02:00
|
|
|
/*
|
|
|
|
|
* In system Verilog it is allowed with a warning to call a function
|
|
|
|
|
* as a task. You can even cast the return value away and have no
|
|
|
|
|
* warning message.
|
|
|
|
|
*/
|
|
|
|
|
extern ivl_sfunc_as_task_t def_sfunc_as_task;
|
|
|
|
|
|
2021-01-11 03:22:20 +01:00
|
|
|
extern void pre_process_failed(const char*text);
|
|
|
|
|
|
2014-07-23 22:39:29 +02:00
|
|
|
#endif /* IVL_compiler_H */
|