4 * Copyright (c) 2001-2005 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
22 # include "vvp_config.h"
23 # include "ivl_target.h"
27 * The target_design entry opens the output file that receives the
28 * compiled design, and sets the vvp_out to the descriptor.
33 * Mangle all non-symbol characters in an identifier, quotes in names
35 extern const char *vvp_mangle_id(const char *);
36 extern const char *vvp_mangle_name(const char *);
39 * This generates a string from a signal that uniquely identifies
40 * that signal with letters that can be used in a label.
42 * NOTE: vvp_signal_label should be removed. All it does is a %p of
43 * the pointer, and return a pointer to a static. The code that wants
44 * to reference a signal needs to use the format V_%p, so the presence
45 * of this function is just plain inconsistent.
47 extern const char* vvp_signal_label(ivl_signal_t sig
);
49 extern unsigned width_of_nexus(ivl_nexus_t nex
);
50 extern ivl_variable_type_t
data_type_of_nexus(ivl_nexus_t nex
);
53 * This function draws a process (initial or always) into the output
54 * file. It normally returns 0, but returns !0 of there is some sort
57 extern int draw_process(ivl_process_t net
, void*x
);
59 extern int draw_task_definition(ivl_scope_t scope
);
60 extern int draw_func_definition(ivl_scope_t scope
);
62 extern int draw_scope(ivl_scope_t scope
, ivl_scope_t parent
);
64 extern void draw_lpm_mux(ivl_lpm_t net
);
66 extern struct vector_info
draw_ufunc_expr(ivl_expr_t exp
, unsigned wid
);
67 extern int draw_ufunc_real(ivl_expr_t exp
);
72 * draw_modpath arranges for a .modpath record to be written out.
74 * cleanup_modpath() cleans up any pending .modpath records that may
75 * have been scheduled by draw_modpath() but not yet writte.
77 * Note: draw_modpath drive_label must be malloc'ed by the
78 * caller. This function will free the string sometime in the future.
80 extern void draw_modpath(ivl_signal_t path_sig
, char*drive_label
);
81 extern void cleanup_modpath(void);
84 * This function draws the execution of a vpi_call statement, along
85 * with the tricky handling of arguments. If this is called with a
86 * statement handle, it will generate a %vpi_call
87 * instruction. Otherwise, it will generate a %vpi_func instruction.
89 extern void draw_vpi_task_call(ivl_statement_t net
);
91 extern struct vector_info
draw_vpi_func_call(ivl_expr_t exp
,
93 extern int draw_vpi_rfunc_call(ivl_expr_t exp
);
96 * Given a nexus, draw a string that represents the functor output
97 * that feeds the nexus. This function can be used to get the input to
98 * a functor, event, or even a %load in cases where I have the
99 * ivl_nexus_t object. The draw_net_input function will get the string
100 * cached in the nexus, if there is one, or will generate a string and
103 extern const char* draw_net_input(ivl_nexus_t nex
);
106 * This function is different from draw_net_input in that it will
107 * return a reference to a net as its first choice. This reference
108 * will follow the net value, even if the net is assigned or
109 * forced. The draw_net_input above will return a reference to the
110 * *input* to the net and so will not follow direct assignments to
111 * the net. This function will not return references to local signals,
112 * and will in those cases resort to the net input, or a non-local
113 * signal if one exists for the nexus.
115 extern const char*draw_input_from_net(ivl_nexus_t nex
);
118 * The draw_eval_expr function writes out the code to evaluate a
119 * behavioral expression.
121 * Expression results are placed into a vector allocated in the bit
122 * space of the thread. The vector_info structure represents that
123 * allocation. When the caller is done with the bits, it must release
124 * the vector with clr_vector so that the code generator can reuse
127 * The stuff_ok_flag is normally empty. Bits in the bitmask are set
128 * true in cases where certain special situations are allows. This
129 * might allow deeper expressions to make assumptions about the
132 * STUFF_OK_XZ -- This bit is set if the code processing the result
133 * doesn't distinguish between x and z values.
135 * STUFF_OK_47 -- This bit is set if the node is allowed to leave a
136 * result in any of the 4-7 vthread bits.
138 * STUFF_OK_RO -- This bit is set if the node is allowed to nest its
139 * allocation from vector. It is only true if the client is not
140 * planning to use this vector as an output. This matters only
141 * if the expression might be found in the lookaside table, and
142 * therefore might be multiply allocated if allowed.
149 extern struct vector_info
draw_eval_expr(ivl_expr_t exp
, int stuff_ok_flag
);
150 extern struct vector_info
draw_eval_expr_wid(ivl_expr_t exp
, unsigned w
,
152 #define STUFF_OK_XZ 0x0001
153 #define STUFF_OK_47 0x0002
154 #define STUFF_OK_RO 0x0004
157 * This evaluates an expression and leaves the result in the numbered
158 * integer index register. It also will set bit-4 to 1 if the value is
159 * not fully defined (i.e. contains x or z).
161 extern void draw_eval_expr_into_integer(ivl_expr_t expr
, unsigned ix
);
164 * These functions manage vector allocation in the thread register
165 * space. They presume that we work on one thread at a time, to
169 * Return the base of an allocated vector in the thread. The bits
170 * are marked allocated in the process.
173 * Clear a vector previously allocated.
175 * The thread vector allocator also keeps a lookaside of expression
176 * results that are stored in register bit. This lookaside can be used
177 * by the code generator to notice that certain expression bits are
178 * already calculated, and can be reused.
180 * clear_expression_lookaside
181 * Clear the lookaside tables for the current thread. This must be
182 * called before starting a new thread, and around basic blocks
183 * that are entered from unknown places.
185 * save_expression_lookaside
186 * Mark the given expression as available in the given register
187 * bits. This remains until the lookaside is cleared. This does not
188 * clear the allocation, it is still necessary to call clr_vector.
190 * save_signal_lookaside
191 * Mark the given signal as available in the given register bits.
192 * This is different from a given expression, in that the signal
193 * lookaside is in addition to the expression lookaside. The signal
194 * lookaside is specifically to save on unnecessary loads of a
195 * signal recently written.
197 * allocate_vector_exp
198 * This function attempts to locate the expression in the
199 * lookaside. If it finds it, return a reallocated base for the
200 * expression. Otherwise, return 0.
202 * The allocate_vector and allocate_vector_exp calls must have
203 * matching call to clr_vector. Although the allocate_vector will
204 * never reallocate a vector already allocated, the allocate_vector_exp
205 * might, so it is possible for allocations to nest in that
206 * manner. The exclusive_flag to allocate_vector_exp will prevent
207 * nested allocations. This is needed where the expression result is
208 * expected to be overwritten.
210 extern unsigned allocate_vector(unsigned wid
);
211 extern void clr_vector(struct vector_info vec
);
213 extern void clear_expression_lookaside(void);
214 extern void save_expression_lookaside(unsigned addr
,
217 extern void save_signal_lookaside(unsigned addr
,
218 ivl_signal_t sig
, unsigned use_word
,
221 extern unsigned allocate_vector_exp(ivl_expr_t exp
, unsigned wid
,
224 extern int number_is_unknown(ivl_expr_t ex
);
225 extern int number_is_immediate(ivl_expr_t ex
, unsigned lim_wid
);
226 extern unsigned long get_number_immediate(ivl_expr_t ex
);
229 * draw_eval_real evaluates real value expressions. The return code
230 * from the function is the index of the word register that contains
233 extern int draw_eval_real(ivl_expr_t ex
);
236 * draw_eval_bool64 evaluates a bool expression. The return code from
237 * the function is the index of the word register that contains the
238 * result. The word is allocated widh allocate_word(), so the caller
239 * must arrange for it to be released with clr_word(). The width must
240 * be such that it fits in a 64bit word.
242 extern int draw_eval_bool64(ivl_expr_t ex
);
245 * These functions manage word register allocation.
247 extern int allocate_word(void);
248 extern void clr_word(int idx
);
251 * These are used to count labels as I generate code.
253 extern unsigned local_count
;
254 extern unsigned thread_count
;