1 #ifndef IVL_compiler_H
2 #define IVL_compiler_H
3 /*
4  * Copyright (c) 1999-2019 Stephen Williams (steve@icarus.com)
5  *
6  *    This source code is free software; you can redistribute it
7  *    and/or modify it in source code form under the terms of the GNU
8  *    General Public License as published by the Free Software
9  *    Foundation; either version 2 of the License, or (at your option)
10  *    any later version.
11  *
12  *    This program is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with this program; if not, write to the Free Software
19  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 # include  <list>
23 # include  <map>
24 # include  "netlist.h"
25 # include  "StringHeap.h"
26 
27 /*
28  * This defines constants and defaults for the compiler in general.
29  */
30 
31 
32 /*
33  * The integer_width is the width of integer variables. This is also
34  * the minimum width of unsized integers when they are found in
35  * self-determined contexts.
36  */
37 extern unsigned integer_width;
38 
39 /*
40  * The width_cap is the width limit for unsized expressions.
41  */
42 extern unsigned width_cap;
43 
44 /*
45  * This is the maximum number of recursive module loops allowed within
46  * a generate block.
47  */
48 extern unsigned recursive_mod_limit;
49 
50 /* The TIME_WIDTH is the width of time variables. */
51 #ifndef TIME_WIDTH
52 # define TIME_WIDTH 64
53 #endif
54 
55 /*
56  * When doing dynamic linking, we need a uniform way to identify the
57  * symbol. Some compilers put leading _, some trailing _. The
58  * configure script figures out which is the local convention and
59  * defines NEED_LU and NEED_TU as required.
60  */
61 #ifdef NEED_LU
62 #define LU "_"
63 #else
64 #define LU ""
65 #endif
66 
67 #ifdef NEED_TU
68 #define TU "_"
69 #else
70 #define TU ""
71 #endif
72 
73 
74 /*
75  * These are flags to enable various sorts of warnings. By default all
76  * the warnings are off, the -W<list> parameter arranges for each to be
77  * enabled.
78  */
79 
80 /* Implicit definitions of wires. */
81 extern bool warn_implicit;
82 
83 /* Warn if dimensions of port or var/net are implicitly taken from
84    the input/output/inout declaration. */
85 extern bool warn_implicit_dimensions;
86 
87 /* inherit timescales across files. */
88 extern bool warn_timescale;
89 
90 /* Warn about legal but questionable module port bindings. */
91 extern bool warn_portbinding;
92 
93 /* Warn about constant out of bound selects. */
94 extern bool warn_ob_select;
95 
96 /* Warn about structures that may have infinite loops. */
97 extern bool warn_inf_loop;
98 
99 /* Warn about always @* statements where a part or word select causes
100    sensitivity to an entire vector or array. */
101 extern bool warn_sens_entire_vec;
102 extern bool warn_sens_entire_arr;
103 
104 /* Warn about level-appropriate anachronisms. */
105 extern bool warn_anachronisms;
106 
107 /* Warn about nets that are references but not driven. */
108 extern bool warn_floating_nets;
109 
110 /* This is true if verbose output is requested. */
111 extern bool verbose_flag;
112 
113 extern bool debug_scopes;
114 extern bool debug_eval_tree;
115 extern bool debug_elaborate;
116 extern bool debug_emit;
117 extern bool debug_synth2;
118 extern bool debug_optimizer;
119 
120 /* Ignore errors about missing modules */
121 extern bool ignore_missing_modules;
122 
123 /* Treat each source file as a separate compilation unit (as defined
124    by SystemVerilog). */
125 extern bool separate_compilation;
126 
127 /* Control evaluation of functions at compile time:
128  *   0 = only for functions in constant expressions
129  *   1 = only for automatic functions
130  *   2 = for all functions
131  * Level 2 should only be used if the user can guarantee that a
132  * function's local variables are never accessed from outside the
133  * function. */
134 extern unsigned opt_const_func;
135 
136 /* Possibly temporary flag to control virtualization of pin arrays */
137 extern bool disable_virtual_pins;
138 
139 /* The vlog95 code generator does not want the compiler to generate concat-Z
140  * LPM objects so this flag is used to block them from being generated. */
141 extern bool disable_concatz_generation;
142 
143 /* Limit to size of devirtualized arrays */
144 extern unsigned long array_size_limit;
145 
146 /* Path to a directory useful for finding subcomponents. */
147 extern const char*basedir;
148 
149 /* This is an ordered list of library suffixes to search. */
150 extern list<const char*>library_suff;
151 extern int build_library_index(const char*path, bool key_case_sensitive);
152 
153 /* This is the generation of Verilog that the compiler is asked to
154    support. Then there are also more detailed controls for more
155    specific language features. Note that the compiler often assumes
156    this is an ordered list. */
157 enum generation_t {
158       GN_VER1995  = 1,
159       GN_VER2001_NOCONFIG  = 2,
160       GN_VER2001  = 3,
161       GN_VER2005  = 4,
162       GN_VER2005_SV  = 5,
163       GN_VER2009  = 6,
164       GN_VER2012  = 7,
165       GN_DEFAULT  = 4
166 };
167 
168 extern generation_t generation_flag;
169 
170 /* If this flag is true, enable extended types support. */
171 extern bool gn_cadence_types_flag;
172 
173 /* If this flag is true, enable miscellaneous extensions. */
174 extern bool gn_icarus_misc_flag;
175 
176 /* If this flag is true, then elaborate specify blocks. If this flag
177    is false, then skip elaboration of specify behavior. */
178 extern bool gn_specify_blocks_flag;
179 
180 /* If this flag is true, then elaborate supported assertion statements. If
181    this flag is false, then stub out supported assertion statements. */
182 extern bool gn_supported_assertions_flag;
183 /* If this flag is true, then error on unsupported assertion statements. If
184    this flag is false, then stub out unsupported assertion statements. */
185 extern bool gn_unsupported_assertions_flag;
186 
187 /* If this flag is true, then support/elaborate Verilog-AMS. */
188 extern bool gn_verilog_ams_flag;
189 
190 /* If this flag is false a warning is printed when the port declaration
191    is scalar and the net/register definition is vectored. */
192 extern bool gn_io_range_error_flag;
193 
194 /* If this flag is true, then force re-evaluation of user functions
195    in a continuous assignment when any part of the expression is
196    re-evaluated. */
197 extern bool gn_strict_ca_eval_flag;
198 
199 /* If this flag is true, then force strict conformance to the IEEE
200    standard expression width rules. */
201 extern bool gn_strict_expr_width_flag;
202 
203 /* If this flag is true, then don't add a for-loop control variable
204    to an implicit event_expression list if it is only used inside the
205    loop. */
206 extern bool gn_shared_loop_index_flag;
207 
gn_system_verilog(void)208 static inline bool gn_system_verilog(void)
209 {
210       if (generation_flag >= GN_VER2005_SV)
211 	    return true;
212       return false;
213 }
214 
215 /* If variables can be converted to uwires by a continuous assignment
216    (assuming no procedural assign), then return true. This will be true
217    for SystemVerilog */
gn_var_can_be_uwire(void)218 static inline bool gn_var_can_be_uwire(void)
219 {
220       return gn_system_verilog();
221 }
222 
gn_modules_nest(void)223 static inline bool gn_modules_nest(void)
224 {
225       return gn_system_verilog();
226 }
227 
228 /* The bits of these GN_KEYWORDS_* constants define non-intersecting
229    sets of keywords. The compiler enables groups of keywords by setting
230    lexor_keyword_mask with the OR of the bits for the keywords to be
231    enabled. */
232 enum { GN_KEYWORDS_1364_1995        = 0x0001,
233        GN_KEYWORDS_1364_2001        = 0x0002,
234        GN_KEYWORDS_1364_2001_CONFIG = 0x0004,
235        GN_KEYWORDS_1364_2005        = 0x0008,
236        GN_KEYWORDS_VAMS_2_3         = 0x0010,
237        GN_KEYWORDS_1800_2005        = 0x0020,
238        GN_KEYWORDS_1800_2009        = 0x0040,
239        GN_KEYWORDS_1800_2012        = 0x0080,
240        GN_KEYWORDS_ICARUS           = 0x8000
241 };
242 extern int lexor_keyword_mask;
243 
244   /* This is the string to use to invoke the preprocessor. */
245 extern char*ivlpp_string;
246 
247 extern map<perm_string,unsigned> missing_modules;
248 
249   /* Files that are library files are in this map. The lexor compares
250      file names as it processes `line directives, and if the file name
251      matches an entry in this table, it will turn on the
252      library_active_flag so that modules know that they are in a
253      library. */
254 extern map<perm_string,bool> library_file_map;
255 
256 /*
257  * the lex_strings are perm_strings made up of tokens from the source
258  * file. Identifiers are so likely to be used many times that it makes
259  * much sense to use a StringHeapLex to hold them.
260  */
261 extern StringHeapLex lex_strings;
262 
263 /*
264  * The ivl_target.h API in a variety of places keeps strings of
265  * bits. Manage these as perm_string in a StringHeap.
266  */
267 extern StringHeapLex bits_strings;
268 
269 /*
270  * The filename_strings are perm_strings for file names. They are put
271  * into their own StringHeapLex because these paths are used a *lot*
272  * and this makes them more sure to hash together.
273  */
274 extern StringHeapLex filename_strings;
275 
276 
277 /*
278  * system task/function listings.
279  */
280 /*
281  * This table describes all the return values of various system
282  * functions. This table is used to elaborate expressions that are
283  * system function calls.
284  */
285 struct sfunc_return_type {
286       const char*   name;
287       ivl_variable_type_t type;
288       unsigned      wid;
289       bool          signed_flag;
290       bool          override_flag;
291 };
292 
293 extern void add_sys_func(const struct sfunc_return_type&ret_type);
294 extern const struct sfunc_return_type* lookup_sys_func(const char*name);
295 extern int load_sys_func_table(const char*path);
296 extern void cleanup_sys_func_table();
297 /*
298  * This temporarily loads a VPI module, to determine the return values
299  * of system functions provided by that module, and adds the return values
300  * to the system function table.
301  */
302 extern bool load_vpi_module(const char*path);
303 
304 /*
305  * In system Verilog it is allowed with a warning to call a function
306  * as a task. You can even cast the return value away and have no
307  * warning message.
308  */
309 extern ivl_sfunc_as_task_t def_sfunc_as_task;
310 
311 #endif /* IVL_compiler_H */
312