4 * Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
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)
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
25 # include "parse_misc.h"
26 # include "vpi_user.h"
32 * The file names are kept in this vector. Entry 0 is "N/A" and 1 is
33 * for interactive commands.
35 extern vector
<const char*> file_names
;
38 * The functions described here are the compile time support
39 * functions. Various bits of the compile process are taken care of
40 * here. What is called when is mostly controlled by the parser.
42 * Before compilation takes place, the compile_init function must be
43 * called once to set stuff up.
46 extern void compile_init(void);
48 extern void compile_cleanup(void);
50 extern bool verbose_flag
;
53 * If this file opened, then write debug information to this
54 * file. This is used for debugging the VVP runtime itself.
56 extern ofstream debug_file
;
59 * Connect a list of symbols to a contiguous set of ipoints.
60 * Constants C<?> are handled by setting the ival of the ipoint.
62 extern void inputs_connect(vvp_net_t
*fdx
, unsigned argc
, struct symb_s
*argv
);
63 extern void input_connect(vvp_net_t
*fdx
, unsigned port
, char*label
);
66 * This function is an expansion of the inputs_connect function. It
67 * uses the inputs_connect function, but it creates vvp_wide_fun_t
68 * nodes to handle arbitrary width nodes, and connects those nodes to
69 * the vvp_wide_fun_core object passed in.
71 extern void wide_inputs_connect(vvp_wide_fun_core
*core
,
72 unsigned argc
, struct symb_s
*argv
);
74 extern vvp_net_t
* vvp_net_lookup(const char*label
);
75 extern vpiHandle
vvp_lookup_handle(const char*label
);
78 * Add a functor to the symbol table
80 extern void define_functor_symbol(const char*label
, vvp_net_t
*ipt
);
84 * This is a count of errors encountered during compilation. If this
85 * is non-zero, then simulation is not recommended.
87 extern unsigned compile_errors
;
89 extern const char* module_path
;
90 extern void compile_load_vpi_module(char*name
);
92 extern void compile_vpi_time_precision(long pre
);
95 * This function is called by the parser to compile a functor
96 * statement. The strings passed in are allocated by the lexor, but
97 * this function will free them. (Or save them permanently.) This
98 * includes the argv array and the strings it references.
100 * The argc and argv are a list of char* that are the port parameters
101 * of the functor. The compile should match those port parameters up
102 * to existing functors to manage the linking.
104 extern void compile_functor(char*label
, char*type
, unsigned width
,
105 unsigned ostr0
, unsigned ostr1
,
106 unsigned argc
, struct symb_s
*argv
);
110 * This is called by the parser to make a resolver. This is a special
111 * kind of functor; a strength aware functor. It has up to 4 inputs
112 * that are blended to make a resolved output. The type string selects
113 * a resolution algorithm.
115 extern void compile_resolver(char*label
, char*type
,
116 unsigned argc
, struct symb_s
*argv
);
118 extern void compile_concat(char*label
, unsigned w0
, unsigned w1
,
119 unsigned w2
, unsigned w3
,
120 unsigned argc
, struct symb_s
*argv
);
123 * Arrange for the system task/function call to have its compiletf
126 extern void compile_compiletf(struct __vpiSysTaskCall
*);
129 * Compile delay nodes of various form.
131 extern void compile_delay(char*label
, vvp_delay_t
*del
, struct symb_s input
);
132 extern void compile_delay(char*label
, unsigned argc
, struct symb_s
*argv
);
135 * This is called by the parser to create a part select node.
136 * See the PART SELECT STATEMENT section in the README.txt
138 extern void compile_part_select(char*label
, char*src
,
139 unsigned base
, unsigned wid
);
140 extern void compile_part_select_pv(char*label
, char*src
,
141 unsigned base
, unsigned wid
,
143 extern void compile_part_select_var(char*label
, char*src
,
144 char*var
, unsigned wid
);
147 * This is called by the parser to make the various arithmetic and
148 * comparison functors.
150 extern void compile_arith_pow(char*label
, long width
, bool signed_flag
,
151 unsigned argc
, struct symb_s
*argv
);
152 extern void compile_arith_div(char*label
, long width
, bool signed_flag
,
153 unsigned argc
, struct symb_s
*argv
);
154 extern void compile_arith_mod(char*label
, long width
,
155 unsigned argc
, struct symb_s
*argv
);
156 extern void compile_arith_mult(char*label
, long width
,
157 unsigned argc
, struct symb_s
*argv
);
158 extern void compile_arith_sum(char*label
, long width
,
159 unsigned argc
, struct symb_s
*argv
);
160 extern void compile_arith_sub(char*label
, long width
,
161 unsigned argc
, struct symb_s
*argv
);
162 extern void compile_cmp_eeq(char*label
, long width
,
163 unsigned argc
, struct symb_s
*argv
);
164 extern void compile_cmp_nee(char*label
, long width
,
165 unsigned argc
, struct symb_s
*argv
);
166 extern void compile_cmp_eq(char*label
, long width
,
167 unsigned argc
, struct symb_s
*argv
);
168 extern void compile_cmp_ne(char*label
, long width
,
169 unsigned argc
, struct symb_s
*argv
);
170 extern void compile_cmp_ge(char*label
, long width
, bool signed_flag
,
171 unsigned argc
, struct symb_s
*argv
);
172 extern void compile_cmp_gt(char*label
, long width
, bool signed_flag
,
173 unsigned argc
, struct symb_s
*argv
);
175 extern void compile_arith_mult_r(char*label
, unsigned argc
,
177 extern void compile_arith_pow_r(char*label
, unsigned argc
, struct symb_s
*argv
);
178 extern void compile_arith_div_r(char*label
, unsigned argc
, struct symb_s
*argv
);
179 extern void compile_arith_mod_r(char*label
, unsigned argc
, struct symb_s
*argv
);
180 extern void compile_arith_sum_r(char*label
, unsigned argc
, struct symb_s
*argv
);
181 extern void compile_arith_sub_r(char*label
, unsigned argc
, struct symb_s
*argv
);
182 extern void compile_cmp_eq_r(char*label
, unsigned argc
, struct symb_s
*argv
);
183 extern void compile_cmp_ne_r(char*label
, unsigned argc
, struct symb_s
*argv
);
184 extern void compile_cmp_ge_r(char*label
, unsigned argc
, struct symb_s
*argv
);
185 extern void compile_cmp_gt_r(char*label
, unsigned argc
, struct symb_s
*argv
);
187 extern void compile_dff(char*label
,
191 struct symb_s arg_a
);
194 extern __vpiModPath
* compile_modpath(char*label
,
197 extern void compile_modpath_src(__vpiModPath
*dst
,
201 int condit_input
, /* match with '0' */
202 struct symb_s path_term_input
,
204 extern void compile_modpath_src(__vpiModPath
*dst
,
208 struct symb_s condit_input
,
209 struct symb_s path_term_input
);
211 extern void compile_reduce_and(char*label
, struct symb_s arg
);
212 extern void compile_reduce_or(char*label
, struct symb_s arg
);
213 extern void compile_reduce_xor(char*label
, struct symb_s arg
);
214 extern void compile_reduce_nand(char*label
, struct symb_s arg
);
215 extern void compile_reduce_nor(char*label
, struct symb_s arg
);
216 extern void compile_reduce_xnor(char*label
, struct symb_s arg
);
218 extern void compile_extend_signed(char*label
, long width
, struct symb_s arg
);
220 extern void compile_sfunc(char*label
, char*name
, char*format_string
,
221 long file_idx
, long lineno
,
222 unsigned argc
, struct symb_s
*argv
);
223 extern void compile_repeat(char*label
, long width
, long repeat
,
226 extern void compile_shiftl(char*label
, long width
,
227 unsigned argc
, struct symb_s
*argv
);
228 extern void compile_shiftr(char*label
, long width
, bool signed_flag
,
229 unsigned argc
, struct symb_s
*argv
);
231 extern void compile_timescale(long units
, long precision
);
233 extern void compile_vpi_symbol(const char*label
, vpiHandle obj
);
234 extern void compile_vpi_lookup(vpiHandle
*objref
, char*label
);
236 extern void compile_param_string(char*label
, char*name
, char*value
,
237 long file_idx
, long lineno
);
238 extern void compile_param_logic(char*label
, char*name
, char*value
,
240 long file_idx
, long lineno
);
241 extern void compile_param_real(char*label
, char*name
, char*value
,
242 long file_idx
, long lineno
);
245 * This function schedules a lookup of an indexed label. The ref
246 * points to the vvp_net_t that receives the result. The result may
247 * be assigned later, if the symbol is defined later in the source
248 * file, so the memory that ref points to must persist.
250 * The text for the label will be deleted by this function, or the
251 * cleanup that completes the binding.
253 extern void functor_ref_lookup(vvp_net_t
**ref
, char*lab
);
256 * This function schedules a lookup of the labeled instruction. The
257 * code points to a code structure that points to the instruction
258 * field that receives the result, and the label is the name to
259 * lookup. The lookup will free the label text when it is done.
261 extern void code_label_lookup(struct vvp_code_s
*code
, char *label
);
264 * The `compile_udp_def' function creates a UDP. The `table' is a
265 * NULL terminated array of char*, as assembled by `compile_udp_table'.
266 * `compile_udp_table' is called with `table'==NULL to create a new
267 * table, or with an existing table to append to.
269 * `compile_udp_functor' creates a mode-3 functor referring to the
273 extern void compile_udp_def(int sequ
, char*label
, char *name
,
274 unsigned nin
, unsigned init
, char **table
);
276 extern void compile_udp_functor(char*label
, char*type
,
278 unsigned argc
, struct symb_s
*argv
);
280 extern char **compile_udp_table(char **table
, char *row
);
283 * Memory Instances, Ports, and Initialization
286 extern void compile_var_array(char*label
, char*name
,
288 int msb
, int lsb
, char signed_flag
);
289 extern void compile_real_array(char*label
, char*name
,
292 extern void compile_net_array(char*label
, char*name
,
293 int last
, int first
);
294 extern void compile_array_alias(char*label
, char*name
, char*src
);
296 extern void compile_array_port(char*label
, char*name
, char*addr
);
298 extern void compile_memory(char *label
, char *name
, int lsb
, int msb
,
299 unsigned idxs
, long *idx
);
301 extern void compile_memory_port(char *label
, char *memid
,
302 unsigned argc
, struct symb_s
*argv
);
304 extern void compile_memory_init(char *memid
, unsigned idx
, long val
);
307 * Compile the .ufunc statement.
309 extern void compile_ufunc(char*label
, char*code
, unsigned wid
,
310 unsigned argc
, struct symb_s
*argv
,
311 unsigned portc
, struct symb_s
*portv
,
315 * The compile_event function takes the parts of the event statement
316 * and makes the various objects needed to simulate it. This includes
317 * the functor that receives the signals and the event_t that holds
320 extern void compile_event(char*label
, char*type
,
321 unsigned argc
, struct symb_s
*argv
,
323 extern void compile_named_event(char*label
, char*type
);
327 * A code statement is a label, an opcode and up to 3 operands. There
328 * are a few lexical types that the parser recognizes of the operands,
329 * given by the ltype_e enumeration. The compile_code function takes
330 * the label, mnemonic and parsed operands and writes a properly
331 * formed instruction into the code space. The label is set into the
332 * symbol table with the address of the instruction.
335 #define OPERAND_MAX 3
336 enum ltype_e
{ L_NUMB
, L_SYMB
};
338 struct comp_operands_s
{
349 typedef struct comp_operands_s
*comp_operands_t
;
351 extern void compile_code(char*label
, char*mnem
, comp_operands_t opa
);
352 extern void compile_disable(char*label
, struct symb_s symb
);
354 extern void compile_vpi_call(char*label
, char*name
,
355 long file_idx
, long lineno
,
356 unsigned argc
, vpiHandle
*argv
);
358 /* Compile a function call. The vbit and vwid encode the return
359 type. If the vwid >0, the return type is a vector. If the vwid is
360 <0, the return type is -vpiRealConst or some other constant subtype
361 code that represents the function type. */
362 extern void compile_vpi_func_call(char*label
, char*name
,
363 unsigned vbit
, int vwid
,
364 long file_idx
, long lineno
,
365 unsigned argc
, vpiHandle
*argv
);
367 extern void compile_fork(char*label
, struct symb_s targ_s
,
368 struct symb_s scope_s
);
369 extern void compile_codelabel(char*label
);
372 * The parser uses these functions to compile .scope statements.
373 * The implementations of these live in the vpi_scope.cc file.
375 extern void compile_scope_decl(char*typ
, char*lab
, char*nam
,const char*tnam
,
376 char*par
, long file_idx
, long lineno
,
377 long def_file_idx
, long def_lineno
);
378 extern void compile_scope_recall(char*sym
);
381 * The parser uses this function to declare a thread. The start_sym is
382 * the start instruction, and must already be defined.
384 extern void compile_thread(char*start_sym
, char*flag
);
387 * This function is called to create a var vector with the given name.
389 extern void compile_variable(char*label
, char*name
,
390 int msb
, int lsb
, char signed_flag
,
392 extern void compile_var_real(char*label
, char*name
,
395 extern void compile_net(char*label
, char*name
,
396 int msb
, int lsb
, bool signed_flag
,
397 bool net8_flag
, bool local_flag
,
398 unsigned argc
, struct symb_s
*argv
);
399 extern void compile_net_real(char*label
, char*name
,
400 int msb
, int lsb
, bool local_flag
,
401 unsigned argc
, struct symb_s
*argv
);
403 extern void compile_netw(char*label
, char*array_symbol
,
404 unsigned long array_addr
,
405 int msb
, int lsb
, bool signed_flag
,
407 unsigned argc
, struct symb_s
*argv
);
408 extern void compile_netw_real(char*label
, char*array_symbol
,
410 unsigned argc
, struct symb_s
*argv
);
412 extern void compile_alias(char*label
, char*name
,
413 int msb
, int lsb
, bool signed_flag
,
414 unsigned argc
, struct symb_s
*argv
);
415 extern void compile_alias_real(char*label
, char*name
,
417 unsigned argc
, struct symb_s
*argv
);
418 extern void compile_aliasw(char*label
, char*array_symbol
,
419 unsigned long array_addr
, int msb
, int lsb
,
420 unsigned argc
, struct symb_s
*argv
);