first commit
[sv2nmigen.git] / parse.py
1 # %{
2 # /*
3 # * Copyright (c) 1998-2017 Stephen Williams (steve@icarus.com)
4 # * Copyright CERN 2012-2013 / 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 "config.h"
23 #
24 # # include "parse_misc.h"
25 # # include "compiler.h"
26 # # include "pform.h"
27 # # include "Statement.h"
28 # # include "PSpec.h"
29 # # include <stack>
30 # # include <cstring>
31 # # include <sstream>
32 #
33 # class PSpecPath;
34 #
35 # extern void lex_end_table();
36 #
37 # static list<pform_range_t>* param_active_range = 0;
38 # static bool param_active_signed = false;
39 # static ivl_variable_type_t param_active_type = IVL_VT_LOGIC;
40 #
41 # /* Port declaration lists use this structure for context. */
42 # static struct {
43 # NetNet::Type port_net_type;
44 # NetNet::PortType port_type;
45 # data_type_t* data_type;
46 # } port_declaration_context = {NetNet::NONE, NetNet::NOT_A_PORT, 0};
47 #
48 # /* Modport port declaration lists use this structure for context. */
49 # enum modport_port_type_t { MP_NONE, MP_SIMPLE, MP_TF, MP_CLOCKING };
50 # static struct {
51 # modport_port_type_t type;
52 # union {
53 # NetNet::PortType direction;
54 # bool is_import;
55 # };
56 # } last_modport_port = { MP_NONE, {NetNet::NOT_A_PORT}};
57 #
58 # /* The task and function rules need to briefly hold the pointer to the
59 # task/function that is currently in progress. */
60 # static PTask* current_task = 0;
61 # static PFunction* current_function = 0;
62 # static stack<PBlock*> current_block_stack;
63 #
64 # /* The variable declaration rules need to know if a lifetime has been
65 # specified. */
66 # static LexicalScope::lifetime_t var_lifetime;
67 #
68 # static pform_name_t* pform_create_this(void)
69 # {
70 # name_component_t name (perm_string::literal("@"));
71 # pform_name_t*res = new pform_name_t;
72 # res->push_back(name);
73 # return res;
74 # }
75 #
76 # static pform_name_t* pform_create_super(void)
77 # {
78 # name_component_t name (perm_string::literal("#"));
79 # pform_name_t*res = new pform_name_t;
80 # res->push_back(name);
81 # return res;
82 # }
83 #
84 # /* This is used to keep track of the extra arguments after the notifier
85 # * in the $setuphold and $recrem timing checks. This allows us to print
86 # * a warning message that the delayed signals will not be created. We
87 # * need to do this since not driving these signals creates real
88 # * simulation issues. */
89 # static unsigned args_after_notifier;
90 #
91 # /* The rules sometimes push attributes into a global context where
92 # sub-rules may grab them. This makes parser rules a little easier to
93 # write in some cases. */
94 # static list<named_pexpr_t>*attributes_in_context = 0;
95 #
96 # /* Later version of bison (including 1.35) will not compile in stack
97 # extension if the output is compiled with C++ and either the YYSTYPE
98 # or YYLTYPE are provided by the source code. However, I can get the
99 # old behavior back by defining these symbols. */
100 # # define YYSTYPE_IS_TRIVIAL 1
101 # # define YYLTYPE_IS_TRIVIAL 1
102 #
103 # /* Recent version of bison expect that the user supply a
104 # YYLLOC_DEFAULT macro that makes up a yylloc value from existing
105 # values. I need to supply an explicit version to account for the
106 # text field, that otherwise won't be copied.
107 #
108 # The YYLLOC_DEFAULT blends the file range for the tokens of Rhs
109 # rule, which has N tokens.
110 # */
111 # # define YYLLOC_DEFAULT(Current, Rhs, N) do { \
112 # if (N) { \
113 # (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
114 # (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
115 # (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
116 # (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
117 # (Current).text = YYRHSLOC (Rhs, 1).text; \
118 # } else { \
119 # (Current).first_line = YYRHSLOC (Rhs, 0).last_line; \
120 # (Current).first_column = YYRHSLOC (Rhs, 0).last_column; \
121 # (Current).last_line = YYRHSLOC (Rhs, 0).last_line; \
122 # (Current).last_column = YYRHSLOC (Rhs, 0).last_column; \
123 # (Current).text = YYRHSLOC (Rhs, 0).text; \
124 # } \
125 # } while (0)
126 #
127 # /*
128 # * These are some common strength pairs that are used as defaults when
129 # * the user is not otherwise specific.
130 # */
131 # static const struct str_pair_t pull_strength = { IVL_DR_PULL, IVL_DR_PULL };
132 # static const struct str_pair_t str_strength = { IVL_DR_STRONG, IVL_DR_STRONG };
133 #
134 # static list<pform_port_t>* make_port_list(char*id, list<pform_range_t>*udims, PExpr*expr)
135 # {
136 # list<pform_port_t>*tmp = new list<pform_port_t>;
137 # tmp->push_back(pform_port_t(lex_strings.make(id), udims, expr));
138 # delete[]id;
139 # return tmp;
140 # }
141 # static list<pform_port_t>* make_port_list(list<pform_port_t>*tmp,
142 # char*id, list<pform_range_t>*udims, PExpr*expr)
143 # {
144 # tmp->push_back(pform_port_t(lex_strings.make(id), udims, expr));
145 # delete[]id;
146 # return tmp;
147 # }
148 #
149 # list<pform_range_t>* make_range_from_width(uint64_t wid)
150 # {
151 # pform_range_t range;
152 # range.first = new PENumber(new verinum(wid-1, integer_width));
153 # range.second = new PENumber(new verinum((uint64_t)0, integer_width));
154 #
155 # list<pform_range_t>*rlist = new list<pform_range_t>;
156 # rlist->push_back(range);
157 # return rlist;
158 # }
159 #
160 # static list<perm_string>* list_from_identifier(char*id)
161 # {
162 # list<perm_string>*tmp = new list<perm_string>;
163 # tmp->push_back(lex_strings.make(id));
164 # delete[]id;
165 # return tmp;
166 # }
167 #
168 # static list<perm_string>* list_from_identifier(list<perm_string>*tmp, char*id)
169 # {
170 # tmp->push_back(lex_strings.make(id));
171 # delete[]id;
172 # return tmp;
173 # }
174 #
175 # list<pform_range_t>* copy_range(list<pform_range_t>* orig)
176 # {
177 # list<pform_range_t>*copy = 0;
178 #
179 # if (orig)
180 # copy = new list<pform_range_t> (*orig);
181 #
182 # return copy;
183 # }
184 #
185 # template <class T> void append(vector<T>&out, const vector<T>&in)
186 # {
187 # for (size_t idx = 0 ; idx < in.size() ; idx += 1)
188 # out.push_back(in[idx]);
189 # }
190 #
191 # /*
192 # * Look at the list and pull null pointers off the end.
193 # */
194 # static void strip_tail_items(list<PExpr*>*lst)
195 # {
196 # while (! lst->empty()) {
197 # if (lst->back() != 0)
198 # return;
199 # lst->pop_back();
200 # }
201 # }
202 #
203 # /*
204 # * This is a shorthand for making a PECallFunction that takes a single
205 # * arg. This is used by some of the code that detects built-ins.
206 # */
207 # static PECallFunction*make_call_function(perm_string tn, PExpr*arg)
208 # {
209 # vector<PExpr*> parms(1);
210 # parms[0] = arg;
211 # PECallFunction*tmp = new PECallFunction(tn, parms);
212 # return tmp;
213 # }
214 #
215 # static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2)
216 # {
217 # vector<PExpr*> parms(2);
218 # parms[0] = arg1;
219 # parms[1] = arg2;
220 # PECallFunction*tmp = new PECallFunction(tn, parms);
221 # return tmp;
222 # }
223 #
224 # static list<named_pexpr_t>* make_named_numbers(perm_string name, long first, long last, PExpr*val =0)
225 # {
226 # list<named_pexpr_t>*lst = new list<named_pexpr_t>;
227 # named_pexpr_t tmp;
228 # // We are counting up.
229 # if (first <= last) {
230 # for (long idx = first ; idx <= last ; idx += 1) {
231 # ostringstream buf;
232 # buf << name.str() << idx << ends;
233 # tmp.name = lex_strings.make(buf.str());
234 # tmp.parm = val;
235 # val = 0;
236 # lst->push_back(tmp);
237 # }
238 # // We are counting down.
239 # } else {
240 # for (long idx = first ; idx >= last ; idx -= 1) {
241 # ostringstream buf;
242 # buf << name.str() << idx << ends;
243 # tmp.name = lex_strings.make(buf.str());
244 # tmp.parm = val;
245 # val = 0;
246 # lst->push_back(tmp);
247 # }
248 # }
249 # return lst;
250 # }
251 #
252 # static list<named_pexpr_t>* make_named_number(perm_string name, PExpr*val =0)
253 # {
254 # list<named_pexpr_t>*lst = new list<named_pexpr_t>;
255 # named_pexpr_t tmp;
256 # tmp.name = name;
257 # tmp.parm = val;
258 # lst->push_back(tmp);
259 # return lst;
260 # }
261 #
262 # static long check_enum_seq_value(const YYLTYPE&loc, verinum *arg, bool zero_ok)
263 # {
264 # long value = 1;
265 # // We can never have an undefined value in an enumeration name
266 # // declaration sequence.
267 # if (! arg->is_defined()) {
268 # yyerror(loc, "error: undefined value used in enum name sequence.");
269 # // We can never have a negative value in an enumeration name
270 # // declaration sequence.
271 # } else if (arg->is_negative()) {
272 # yyerror(loc, "error: negative value used in enum name sequence.");
273 # } else {
274 # value = arg->as_ulong();
275 # // We cannot have a zero enumeration name declaration count.
276 # if (! zero_ok && (value == 0)) {
277 # yyerror(loc, "error: zero count used in enum name sequence.");
278 # value = 1;
279 # }
280 # }
281 # return value;
282 # }
283 #
284 # static void current_task_set_statement(const YYLTYPE&loc, vector<Statement*>*s)
285 # {
286 # if (s == 0) {
287 # /* if the statement list is null, then the parser
288 # detected the case that there are no statements in the
289 # task. If this is SystemVerilog, handle it as an
290 # an empty block. */
291 # if (!gn_system_verilog()) {
292 # yyerror(loc, "error: Support for empty tasks requires SystemVerilog.");
293 # }
294 # PBlock*tmp = new PBlock(PBlock::BL_SEQ);
295 # FILE_NAME(tmp, loc);
296 # current_task->set_statement(tmp);
297 # return;
298 # }
299 # assert(s);
300 #
301 # /* An empty vector represents one or more null statements. Handle
302 # this as a simple null statement. */
303 # if (s->empty())
304 # return;
305 #
306 # /* A vector of 1 is handled as a simple statement. */
307 # if (s->size() == 1) {
308 # current_task->set_statement((*s)[0]);
309 # return;
310 # }
311 #
312 # if (!gn_system_verilog()) {
313 # yyerror(loc, "error: Task body with multiple statements requires SystemVerilog.");
314 # }
315 #
316 # PBlock*tmp = new PBlock(PBlock::BL_SEQ);
317 # FILE_NAME(tmp, loc);
318 # tmp->set_statement(*s);
319 # current_task->set_statement(tmp);
320 # }
321 #
322 # static void current_function_set_statement(const YYLTYPE&loc, vector<Statement*>*s)
323 # {
324 # if (s == 0) {
325 # /* if the statement list is null, then the parser
326 # detected the case that there are no statements in the
327 # task. If this is SystemVerilog, handle it as an
328 # an empty block. */
329 # if (!gn_system_verilog()) {
330 # yyerror(loc, "error: Support for empty functions requires SystemVerilog.");
331 # }
332 # PBlock*tmp = new PBlock(PBlock::BL_SEQ);
333 # FILE_NAME(tmp, loc);
334 # current_function->set_statement(tmp);
335 # return;
336 # }
337 # assert(s);
338 #
339 # /* An empty vector represents one or more null statements. Handle
340 # this as a simple null statement. */
341 # if (s->empty())
342 # return;
343 #
344 # /* A vector of 1 is handled as a simple statement. */
345 # if (s->size() == 1) {
346 # current_function->set_statement((*s)[0]);
347 # return;
348 # }
349 #
350 # if (!gn_system_verilog()) {
351 # yyerror(loc, "error: Function body with multiple statements requires SystemVerilog.");
352 # }
353 #
354 # PBlock*tmp = new PBlock(PBlock::BL_SEQ);
355 # FILE_NAME(tmp, loc);
356 # tmp->set_statement(*s);
357 # current_function->set_statement(tmp);
358 # }
359 #
360 # %}
361 ('tokens = ', "['IDENTIFIER', 'SYSTEM_IDENTIFIER', 'STRING', 'TIME_LITERAL', 'TYPE_IDENTIFIER', 'PACKAGE_IDENTIFIER', 'DISCIPLINE_IDENTIFIER', 'PATHPULSE_IDENTIFIER', 'BASED_NUMBER', 'DEC_NUMBER', 'UNBASED_NUMBER', 'REALTIME', 'K_PLUS_EQ', 'K_MINUS_EQ', 'K_INCR', 'K_DECR', 'K_LE', 'K_GE', 'K_EG', 'K_EQ', 'K_NE', 'K_CEQ', 'K_CNE', 'K_WEQ', 'K_WNE', 'K_LP', 'K_LS', 'K_RS', 'K_RSS', 'K_SG', 'K_CONTRIBUTE', 'K_PO_POS', 'K_PO_NEG', 'K_POW', 'K_PSTAR', 'K_STARP', 'K_DOTSTAR', 'K_LOR', 'K_LAND', 'K_NAND', 'K_NOR', 'K_NXOR', 'K_TRIGGER', 'K_SCOPE_RES', 'K_edge_descriptor', 'K_always', 'K_and', 'K_assign', 'K_begin', 'K_buf', 'K_bufif0', 'K_bufif1', 'K_case', 'K_casex', 'K_casez', 'K_cmos', 'K_deassign', 'K_default', 'K_defparam', 'K_disable', 'K_edge', 'K_else', 'K_end', 'K_endcase', 'K_endfunction', 'K_endmodule', 'K_endprimitive', 'K_endspecify', 'K_endtable', 'K_endtask', 'K_event', 'K_for', 'K_force', 'K_forever', 'K_fork', 'K_function', 'K_highz0', 'K_highz1', 'K_if', 'K_ifnone', 'K_initial', 'K_inout', 'K_input', 'K_integer', 'K_join', 'K_large', 'K_macromodule', 'K_medium', 'K_module', 'K_nand', 'K_negedge', 'K_nmos', 'K_nor', 'K_not', 'K_notif0', 'K_notif1', 'K_or', 'K_output', 'K_parameter', 'K_pmos', 'K_posedge', 'K_primitive', 'K_pull0', 'K_pull1', 'K_pulldown', 'K_pullup', 'K_rcmos', 'K_real', 'K_realtime', 'K_reg', 'K_release', 'K_repeat', 'K_rnmos', 'K_rpmos', 'K_rtran', 'K_rtranif0', 'K_rtranif1', 'K_scalared', 'K_small', 'K_specify', 'K_specparam', 'K_strong0', 'K_strong1', 'K_supply0', 'K_supply1', 'K_table', 'K_task', 'K_time', 'K_tran', 'K_tranif0', 'K_tranif1', 'K_tri', 'K_tri0', 'K_tri1', 'K_triand', 'K_trior', 'K_trireg', 'K_vectored', 'K_wait', 'K_wand', 'K_weak0', 'K_weak1', 'K_while', 'K_wire', 'K_wor', 'K_xnor', 'K_xor', 'K_Shold', 'K_Snochange', 'K_Speriod', 'K_Srecovery', 'K_Ssetup', 'K_Ssetuphold', 'K_Sskew', 'K_Swidth', 'KK_attribute', 'K_bool', 'K_logic', 'K_automatic', 'K_endgenerate', 'K_generate', 'K_genvar', 'K_localparam', 'K_noshowcancelled', 'K_pulsestyle_onevent', 'K_pulsestyle_ondetect', 'K_showcancelled', 'K_signed', 'K_unsigned', 'K_Sfullskew', 'K_Srecrem', 'K_Sremoval', 'K_Stimeskew', 'K_cell', 'K_config', 'K_design', 'K_endconfig', 'K_incdir', 'K_include', 'K_instance', 'K_liblist', 'K_library', 'K_use', 'K_wone', 'K_uwire', 'K_alias', 'K_always_comb', 'K_always_ff', 'K_always_latch', 'K_assert', 'K_assume', 'K_before', 'K_bind', 'K_bins', 'K_binsof', 'K_bit', 'K_break', 'K_byte', 'K_chandle', 'K_class', 'K_clocking', 'K_const', 'K_constraint', 'K_context', 'K_continue', 'K_cover', 'K_covergroup', 'K_coverpoint', 'K_cross', 'K_dist', 'K_do', 'K_endclass', 'K_endclocking', 'K_endgroup', 'K_endinterface', 'K_endpackage', 'K_endprogram', 'K_endproperty', 'K_endsequence', 'K_enum', 'K_expect', 'K_export', 'K_extends', 'K_extern', 'K_final', 'K_first_match', 'K_foreach', 'K_forkjoin', 'K_iff', 'K_ignore_bins', 'K_illegal_bins', 'K_import', 'K_inside', 'K_int', 'K_interface', 'K_intersect', 'K_join_any', 'K_join_none', 'K_local', 'K_longint', 'K_matches', 'K_modport', 'K_new', 'K_null', 'K_package', 'K_packed', 'K_priority', 'K_program', 'K_property', 'K_protected', 'K_pure', 'K_rand', 'K_randc', 'K_randcase', 'K_randsequence', 'K_ref', 'K_return', 'K_sequence', 'K_shortint', 'K_shortreal', 'K_solve', 'K_static', 'K_string', 'K_struct', 'K_super', 'K_tagged', 'K_this', 'K_throughout', 'K_timeprecision', 'K_timeunit', 'K_type', 'K_typedef', 'K_union', 'K_unique', 'K_var', 'K_virtual', 'K_void', 'K_wait_order', 'K_wildcard', 'K_with', 'K_within', 'K_accept_on', 'K_checker', 'K_endchecker', 'K_eventually', 'K_global', 'K_implies', 'K_let', 'K_nexttime', 'K_reject_on', 'K_restrict', 'K_s_always', 'K_s_eventually', 'K_s_nexttime', 'K_s_until', 'K_s_until_with', 'K_strong', 'K_sync_accept_on', 'K_sync_reject_on', 'K_unique0', 'K_until', 'K_until_with', 'K_untyped', 'K_weak', 'K_implements', 'K_interconnect', 'K_nettype', 'K_soft', 'K_above', 'K_abs', 'K_absdelay', 'K_abstol', 'K_access', 'K_acos', 'K_acosh', 'K_ac_stim', 'K_aliasparam', 'K_analog', 'K_analysis', 'K_asin', 'K_asinh', 'K_atan', 'K_atan2', 'K_atanh', 'K_branch', 'K_ceil', 'K_connect', 'K_connectmodule', 'K_connectrules', 'K_continuous', 'K_cos', 'K_cosh', 'K_ddt', 'K_ddt_nature', 'K_ddx', 'K_discipline', 'K_discrete', 'K_domain', 'K_driver_update', 'K_endconnectrules', 'K_enddiscipline', 'K_endnature', 'K_endparamset', 'K_exclude', 'K_exp', 'K_final_step', 'K_flicker_noise', 'K_floor', 'K_flow', 'K_from', 'K_ground', 'K_hypot', 'K_idt', 'K_idtmod', 'K_idt_nature', 'K_inf', 'K_initial_step', 'K_laplace_nd', 'K_laplace_np', 'K_laplace_zd', 'K_laplace_zp', 'K_last_crossing', 'K_limexp', 'K_ln', 'K_log', 'K_max', 'K_merged', 'K_min', 'K_nature', 'K_net_resolution', 'K_noise_table', 'K_paramset', 'K_potential', 'K_pow', 'K_resolveto', 'K_sin', 'K_sinh', 'K_slew', 'K_split', 'K_sqrt', 'K_tan', 'K_tanh', 'K_timer', 'K_transition', 'K_units', 'K_white_noise', 'K_wreal', 'K_zi_nd', 'K_zi_np', 'K_zi_zd', 'K_zi_zp', 'K_TAND', 'K_PLUS_EQ', 'K_MINUS_EQ', 'K_MUL_EQ', 'K_DIV_EQ', 'K_MOD_EQ', 'K_AND_EQ', 'K_OR_EQ', 'K_XOR_EQ', 'K_LS_EQ', 'K_RS_EQ', 'K_RSS_EQ', 'K_inside', 'K_LOR', 'K_LAND', 'K_NXOR', 'K_NOR', 'K_NAND', 'K_EQ', 'K_NE', 'K_CEQ', 'K_CNE', 'K_WEQ', 'K_WNE', 'K_GE', 'K_LE', 'K_LS', 'K_RS', 'K_RSS', 'K_POW', 'UNARY_PREC', 'less_than_K_else', 'K_else', 'K_exclude', 'no_timeunits_declaration', 'one_timeunits_declaration', 'K_timeunit', 'K_timeprecision']")
362 ()
363 ('precedence = ', '[(\'right\', \'K_PLUS_EQ\', \'K_MINUS_EQ\', \'K_MUL_EQ\', \'K_DIV_EQ\', \'K_MOD_EQ\', \'K_AND_EQ\', \'K_OR_EQ\'), (\'right\', \'K_XOR_EQ\', \'K_LS_EQ\', \'K_RS_EQ\', \'K_RSS_EQ\'), (\'right\', "\'?\'", "\':\'", \'K_inside\'), (\'left\', \'K_LOR\'), (\'left\', \'K_LAND\'), (\'left\', "\'|\'"), (\'left\', "\'^\'", \'K_NXOR\', \'K_NOR\'), (\'left\', "\'&\'", \'K_NAND\'), (\'left\', \'K_EQ\', \'K_NE\', \'K_CEQ\', \'K_CNE\', \'K_WEQ\', \'K_WNE\'), (\'left\', \'K_GE\', \'K_LE\', "\'<\'", "\'>\'"), (\'left\', \'K_LS\', \'K_RS\', \'K_RSS\'), (\'left\', "\'+\'", "\'-\'"), (\'left\', "\'*\'", "\'/\'", "\'%\'"), (\'left\', \'K_POW\'), (\'left\', \'UNARY_PREC\'), (\'nonassoc\', \'less_than_K_else\'), (\'nonassoc\', \'K_else\'), (\'nonassoc\', "\'(\'"), (\'nonassoc\', \'K_exclude\'), (\'nonassoc\', \'no_timeunits_declaration\'), (\'nonassoc\', \'one_timeunits_declaration\'), (\'nonassoc\', \'K_timeunit\', \'K_timeprecision\')]')
364 ()
365 # -------------- RULES ----------------
366 ()
367 def p_source_text_1(p):
368 '''source_text : timeunits_declaration_opt _embed0_source_text description_list '''
369 print(p)
370 ()
371 def p_source_text_2(p):
372 '''source_text : '''
373 print(p)
374 ()
375 def p__embed0_source_text(p):
376 '''_embed0_source_text : '''
377 # { pform_set_scope_timescale(yyloc); }
378 ()
379 def p_assertion_item_1(p):
380 '''assertion_item : concurrent_assertion_item '''
381 print(p)
382 ()
383 def p_assignment_pattern_1(p):
384 '''assignment_pattern : K_LP expression_list_proper '}' '''
385 print(p)
386 # { PEAssignPattern*tmp = new PEAssignPattern(*$2);
387 # FILE_NAME(tmp, @1);
388 # delete $2;
389 # $$ = tmp;
390 # }
391 ()
392 def p_assignment_pattern_2(p):
393 '''assignment_pattern : K_LP '}' '''
394 print(p)
395 # { PEAssignPattern*tmp = new PEAssignPattern;
396 # FILE_NAME(tmp, @1);
397 # $$ = tmp;
398 # }
399 ()
400 def p_block_identifier_opt_1(p):
401 '''block_identifier_opt : IDENTIFIER ':' '''
402 print(p)
403 ()
404 def p_block_identifier_opt_2(p):
405 '''block_identifier_opt : '''
406 print(p)
407 ()
408 def p_class_declaration_1(p):
409 '''class_declaration : K_virtual_opt K_class lifetime_opt class_identifier class_declaration_extends_opt ';' _embed0_class_declaration class_items_opt K_endclass _embed1_class_declaration class_declaration_endlabel_opt '''
410 print(p)
411 # { // Wrap up the class.
412 # if ($11 && $4 && $4->name != $11) {
413 # yyerror(@11, "error: Class end label doesn't match class name.");
414 # delete[]$11;
415 # }
416 # }
417 ()
418 def p__embed0_class_declaration(p):
419 '''_embed0_class_declaration : '''
420 # { pform_start_class_declaration(@2, $4, $5.type, $5.exprs, $3); }
421 ()
422 def p__embed1_class_declaration(p):
423 '''_embed1_class_declaration : '''
424 # { // Process a class.
425 # pform_end_class_declaration(@9);
426 # }
427 ()
428 def p_class_constraint_1(p):
429 '''class_constraint : constraint_prototype '''
430 print(p)
431 ()
432 def p_class_constraint_2(p):
433 '''class_constraint : constraint_declaration '''
434 print(p)
435 ()
436 def p_class_identifier_1(p):
437 '''class_identifier : IDENTIFIER '''
438 print(p)
439 # { // Create a synthetic typedef for the class name so that the
440 # // lexor detects the name as a type.
441 # perm_string name = lex_strings.make($1);
442 # class_type_t*tmp = new class_type_t(name);
443 # FILE_NAME(tmp, @1);
444 # pform_set_typedef(name, tmp, NULL);
445 # delete[]$1;
446 # $$ = tmp;
447 # }
448 ()
449 def p_class_identifier_2(p):
450 '''class_identifier : TYPE_IDENTIFIER '''
451 print(p)
452 # { class_type_t*tmp = dynamic_cast<class_type_t*>($1.type);
453 # if (tmp == 0) {
454 # yyerror(@1, "Type name \"%s\"is not a predeclared class name.", $1.text);
455 # }
456 # delete[]$1.text;
457 # $$ = tmp;
458 # }
459 ()
460 def p_class_declaration_endlabel_opt_1(p):
461 '''class_declaration_endlabel_opt : ':' TYPE_IDENTIFIER '''
462 print(p)
463 # { class_type_t*tmp = dynamic_cast<class_type_t*> ($2.type);
464 # if (tmp == 0) {
465 # yyerror(@2, "error: class declaration endlabel \"%s\" is not a class name\n", $2.text);
466 # $$ = 0;
467 # } else {
468 # $$ = strdupnew(tmp->name.str());
469 # }
470 # delete[]$2.text;
471 # }
472 ()
473 def p_class_declaration_endlabel_opt_2(p):
474 '''class_declaration_endlabel_opt : ':' IDENTIFIER '''
475 print(p)
476 # { $$ = $2; }
477 ()
478 def p_class_declaration_endlabel_opt_3(p):
479 '''class_declaration_endlabel_opt : '''
480 print(p)
481 # { $$ = 0; }
482 ()
483 def p_class_declaration_extends_opt_1(p):
484 '''class_declaration_extends_opt : K_extends TYPE_IDENTIFIER '''
485 print(p)
486 # { $$.type = $2.type;
487 # $$.exprs= 0;
488 # delete[]$2.text;
489 # }
490 ()
491 def p_class_declaration_extends_opt_2(p):
492 '''class_declaration_extends_opt : K_extends TYPE_IDENTIFIER '(' expression_list_with_nuls ')' '''
493 print(p)
494 # { $$.type = $2.type;
495 # $$.exprs = $4;
496 # delete[]$2.text;
497 # }
498 ()
499 def p_class_declaration_extends_opt_3(p):
500 '''class_declaration_extends_opt : '''
501 print(p)
502 # { $$.type = 0; $$.exprs = 0; }
503 ()
504 def p_class_items_opt_1(p):
505 '''class_items_opt : class_items '''
506 print(p)
507 ()
508 def p_class_items_opt_2(p):
509 '''class_items_opt : '''
510 print(p)
511 ()
512 def p_class_items_1(p):
513 '''class_items : class_items class_item '''
514 print(p)
515 ()
516 def p_class_items_2(p):
517 '''class_items : class_item '''
518 print(p)
519 ()
520 def p_class_item_1(p):
521 '''class_item : method_qualifier_opt K_function K_new _embed0_class_item '(' tf_port_list_opt ')' ';' function_item_list_opt statement_or_null_list_opt K_endfunction endnew_opt '''
522 print(p)
523 # { current_function->set_ports($6);
524 # pform_set_constructor_return(current_function);
525 # pform_set_this_class(@3, current_function);
526 # current_function_set_statement(@3, $10);
527 # pform_pop_scope();
528 # current_function = 0;
529 # }
530 ()
531 def p_class_item_2(p):
532 '''class_item : property_qualifier_opt data_type list_of_variable_decl_assignments ';' '''
533 print(p)
534 # { pform_class_property(@2, $1, $2, $3); }
535 ()
536 def p_class_item_3(p):
537 '''class_item : K_const class_item_qualifier_opt data_type list_of_variable_decl_assignments ';' '''
538 print(p)
539 # { pform_class_property(@1, $2 | property_qualifier_t::make_const(), $3, $4); }
540 ()
541 def p_class_item_4(p):
542 '''class_item : method_qualifier_opt task_declaration '''
543 print(p)
544 # { /* The task_declaration rule puts this into the class */ }
545 ()
546 def p_class_item_5(p):
547 '''class_item : method_qualifier_opt function_declaration '''
548 print(p)
549 # { /* The function_declaration rule puts this into the class */ }
550 ()
551 def p_class_item_6(p):
552 '''class_item : K_extern method_qualifier_opt K_function K_new ';' '''
553 print(p)
554 # { yyerror(@1, "sorry: External constructors are not yet supported."); }
555 ()
556 def p_class_item_7(p):
557 '''class_item : K_extern method_qualifier_opt K_function K_new '(' tf_port_list_opt ')' ';' '''
558 print(p)
559 # { yyerror(@1, "sorry: External constructors are not yet supported."); }
560 ()
561 def p_class_item_8(p):
562 '''class_item : K_extern method_qualifier_opt K_function data_type_or_implicit_or_void IDENTIFIER ';' '''
563 print(p)
564 # { yyerror(@1, "sorry: External methods are not yet supported.");
565 # delete[] $5;
566 # }
567 ()
568 def p_class_item_9(p):
569 '''class_item : K_extern method_qualifier_opt K_function data_type_or_implicit_or_void IDENTIFIER '(' tf_port_list_opt ')' ';' '''
570 print(p)
571 # { yyerror(@1, "sorry: External methods are not yet supported.");
572 # delete[] $5;
573 # }
574 ()
575 def p_class_item_10(p):
576 '''class_item : K_extern method_qualifier_opt K_task IDENTIFIER ';' '''
577 print(p)
578 # { yyerror(@1, "sorry: External methods are not yet supported.");
579 # delete[] $4;
580 # }
581 ()
582 def p_class_item_11(p):
583 '''class_item : K_extern method_qualifier_opt K_task IDENTIFIER '(' tf_port_list_opt ')' ';' '''
584 print(p)
585 # { yyerror(@1, "sorry: External methods are not yet supported.");
586 # delete[] $4;
587 # }
588 ()
589 def p_class_item_12(p):
590 '''class_item : class_constraint '''
591 print(p)
592 ()
593 def p_class_item_13(p):
594 '''class_item : property_qualifier_opt data_type error ';' '''
595 print(p)
596 # { yyerror(@3, "error: Errors in variable names after data type.");
597 # yyerrok;
598 # }
599 ()
600 def p_class_item_14(p):
601 '''class_item : property_qualifier_opt IDENTIFIER error ';' '''
602 print(p)
603 # { yyerror(@3, "error: %s doesn't name a type.", $2);
604 # yyerrok;
605 # }
606 ()
607 def p_class_item_15(p):
608 '''class_item : method_qualifier_opt K_function K_new error K_endfunction endnew_opt '''
609 print(p)
610 # { yyerror(@1, "error: I give up on this class constructor declaration.");
611 # yyerrok;
612 # }
613 ()
614 def p_class_item_16(p):
615 '''class_item : error ';' '''
616 print(p)
617 # { yyerror(@2, "error: invalid class item.");
618 # yyerrok;
619 # }
620 ()
621 def p__embed0_class_item(p):
622 '''_embed0_class_item : '''
623 # { assert(current_function==0);
624 # current_function = pform_push_constructor_scope(@3);
625 # }
626 ()
627 def p_class_item_qualifier_1(p):
628 '''class_item_qualifier : K_static '''
629 print(p)
630 # { $$ = property_qualifier_t::make_static(); }
631 ()
632 def p_class_item_qualifier_2(p):
633 '''class_item_qualifier : K_protected '''
634 print(p)
635 # { $$ = property_qualifier_t::make_protected(); }
636 ()
637 def p_class_item_qualifier_3(p):
638 '''class_item_qualifier : K_local '''
639 print(p)
640 # { $$ = property_qualifier_t::make_local(); }
641 ()
642 def p_class_item_qualifier_list_1(p):
643 '''class_item_qualifier_list : class_item_qualifier_list class_item_qualifier '''
644 print(p)
645 # { $$ = $1 | $2; }
646 ()
647 def p_class_item_qualifier_list_2(p):
648 '''class_item_qualifier_list : class_item_qualifier '''
649 print(p)
650 # { $$ = $1; }
651 ()
652 def p_class_item_qualifier_opt_1(p):
653 '''class_item_qualifier_opt : class_item_qualifier_list '''
654 print(p)
655 # { $$ = $1; }
656 ()
657 def p_class_item_qualifier_opt_2(p):
658 '''class_item_qualifier_opt : '''
659 print(p)
660 # { $$ = property_qualifier_t::make_none(); }
661 ()
662 def p_class_new_1(p):
663 '''class_new : K_new '(' expression_list_with_nuls ')' '''
664 print(p)
665 # { list<PExpr*>*expr_list = $3;
666 # strip_tail_items(expr_list);
667 # PENewClass*tmp = new PENewClass(*expr_list);
668 # FILE_NAME(tmp, @1);
669 # delete $3;
670 # $$ = tmp;
671 # }
672 ()
673 def p_class_new_2(p):
674 '''class_new : K_new hierarchy_identifier '''
675 print(p)
676 # { PEIdent*tmpi = new PEIdent(*$2);
677 # FILE_NAME(tmpi, @2);
678 # PENewCopy*tmp = new PENewCopy(tmpi);
679 # FILE_NAME(tmp, @1);
680 # delete $2;
681 # $$ = tmp;
682 # }
683 ()
684 def p_class_new_3(p):
685 '''class_new : K_new '''
686 print(p)
687 # { PENewClass*tmp = new PENewClass;
688 # FILE_NAME(tmp, @1);
689 # $$ = tmp;
690 # }
691 ()
692 def p_concurrent_assertion_item_1(p):
693 '''concurrent_assertion_item : block_identifier_opt K_assert K_property '(' property_spec ')' statement_or_null '''
694 print(p)
695 # { /* */
696 # if (gn_assertions_flag) {
697 # yyerror(@2, "sorry: concurrent_assertion_item not supported."
698 # " Try -gno-assertion to turn this message off.");
699 # }
700 # }
701 ()
702 def p_concurrent_assertion_item_2(p):
703 '''concurrent_assertion_item : block_identifier_opt K_assert K_property '(' error ')' statement_or_null '''
704 print(p)
705 # { yyerrok;
706 # yyerror(@2, "error: Error in property_spec of concurrent assertion item.");
707 # }
708 ()
709 def p_constraint_block_item_1(p):
710 '''constraint_block_item : constraint_expression '''
711 print(p)
712 ()
713 def p_constraint_block_item_list_1(p):
714 '''constraint_block_item_list : constraint_block_item_list constraint_block_item '''
715 print(p)
716 ()
717 def p_constraint_block_item_list_2(p):
718 '''constraint_block_item_list : constraint_block_item '''
719 print(p)
720 ()
721 def p_constraint_block_item_list_opt_1(p):
722 '''constraint_block_item_list_opt : '''
723 print(p)
724 ()
725 def p_constraint_block_item_list_opt_2(p):
726 '''constraint_block_item_list_opt : constraint_block_item_list '''
727 print(p)
728 ()
729 def p_constraint_declaration_1(p):
730 '''constraint_declaration : K_static_opt K_constraint IDENTIFIER '{' constraint_block_item_list_opt '}' '''
731 print(p)
732 # { yyerror(@2, "sorry: Constraint declarations not supported."); }
733 ()
734 def p_constraint_declaration_2(p):
735 '''constraint_declaration : K_static_opt K_constraint IDENTIFIER '{' error '}' '''
736 print(p)
737 # { yyerror(@4, "error: Errors in the constraint block item list."); }
738 ()
739 def p_constraint_expression_1(p):
740 '''constraint_expression : expression ';' '''
741 print(p)
742 ()
743 def p_constraint_expression_2(p):
744 '''constraint_expression : expression K_dist '{' '}' ';' '''
745 print(p)
746 ()
747 def p_constraint_expression_3(p):
748 '''constraint_expression : expression K_TRIGGER constraint_set '''
749 print(p)
750 ()
751 def p_constraint_expression_4(p):
752 '''constraint_expression : K_if '(' expression ')' constraint_set %prec less_than_K_else '''
753 print(p)
754 ()
755 def p_constraint_expression_5(p):
756 '''constraint_expression : K_if '(' expression ')' constraint_set K_else constraint_set '''
757 print(p)
758 ()
759 def p_constraint_expression_6(p):
760 '''constraint_expression : K_foreach '(' IDENTIFIER '[' loop_variables ']' ')' constraint_set '''
761 print(p)
762 ()
763 def p_constraint_expression_list_1(p):
764 '''constraint_expression_list : constraint_expression_list constraint_expression '''
765 print(p)
766 ()
767 def p_constraint_expression_list_2(p):
768 '''constraint_expression_list : constraint_expression '''
769 print(p)
770 ()
771 def p_constraint_prototype_1(p):
772 '''constraint_prototype : K_static_opt K_constraint IDENTIFIER ';' '''
773 print(p)
774 # { yyerror(@2, "sorry: Constraint prototypes not supported."); }
775 ()
776 def p_constraint_set_1(p):
777 '''constraint_set : constraint_expression '''
778 print(p)
779 ()
780 def p_constraint_set_2(p):
781 '''constraint_set : '{' constraint_expression_list '}' '''
782 print(p)
783 ()
784 def p_data_declaration_1(p):
785 '''data_declaration : attribute_list_opt data_type_or_implicit list_of_variable_decl_assignments ';' '''
786 print(p)
787 # { data_type_t*data_type = $2;
788 # if (data_type == 0) {
789 # data_type = new vector_type_t(IVL_VT_LOGIC, false, 0);
790 # FILE_NAME(data_type, @2);
791 # }
792 # pform_makewire(@2, 0, str_strength, $3, NetNet::IMPLICIT_REG, data_type);
793 # }
794 ()
795 def p_data_type_1(p):
796 '''data_type : integer_vector_type unsigned_signed_opt dimensions_opt '''
797 print(p)
798 # { ivl_variable_type_t use_vtype = $1;
799 # bool reg_flag = false;
800 # if (use_vtype == IVL_VT_NO_TYPE) {
801 # use_vtype = IVL_VT_LOGIC;
802 # reg_flag = true;
803 # }
804 # vector_type_t*tmp = new vector_type_t(use_vtype, $2, $3);
805 # tmp->reg_flag = reg_flag;
806 # FILE_NAME(tmp, @1);
807 # $$ = tmp;
808 # }
809 ()
810 def p_data_type_2(p):
811 '''data_type : non_integer_type '''
812 print(p)
813 # { real_type_t*tmp = new real_type_t($1);
814 # FILE_NAME(tmp, @1);
815 # $$ = tmp;
816 # }
817 ()
818 def p_data_type_3(p):
819 '''data_type : struct_data_type '''
820 print(p)
821 # { if (!$1->packed_flag) {
822 # yyerror(@1, "sorry: Unpacked structs not supported.");
823 # }
824 # $$ = $1;
825 # }
826 ()
827 def p_data_type_4(p):
828 '''data_type : enum_data_type '''
829 print(p)
830 # { $$ = $1; }
831 ()
832 def p_data_type_5(p):
833 '''data_type : atom2_type signed_unsigned_opt '''
834 print(p)
835 # { atom2_type_t*tmp = new atom2_type_t($1, $2);
836 # FILE_NAME(tmp, @1);
837 # $$ = tmp;
838 # }
839 ()
840 def p_data_type_6(p):
841 '''data_type : K_integer signed_unsigned_opt '''
842 print(p)
843 # { list<pform_range_t>*pd = make_range_from_width(integer_width);
844 # vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, $2, pd);
845 # tmp->reg_flag = true;
846 # tmp->integer_flag = true;
847 # $$ = tmp;
848 # }
849 ()
850 def p_data_type_7(p):
851 '''data_type : K_time '''
852 print(p)
853 # { list<pform_range_t>*pd = make_range_from_width(64);
854 # vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, pd);
855 # tmp->reg_flag = !gn_system_verilog();
856 # $$ = tmp;
857 # }
858 ()
859 def p_data_type_8(p):
860 '''data_type : TYPE_IDENTIFIER dimensions_opt '''
861 print(p)
862 # { if ($2) {
863 # parray_type_t*tmp = new parray_type_t($1.type, $2);
864 # FILE_NAME(tmp, @1);
865 # $$ = tmp;
866 # } else $$ = $1.type;
867 # delete[]$1.text;
868 # }
869 ()
870 def p_data_type_9(p):
871 '''data_type : PACKAGE_IDENTIFIER K_SCOPE_RES _embed0_data_type TYPE_IDENTIFIER '''
872 print(p)
873 # { lex_in_package_scope(0);
874 # $$ = $4.type;
875 # delete[]$4.text;
876 # }
877 ()
878 def p_data_type_10(p):
879 '''data_type : K_string '''
880 print(p)
881 # { string_type_t*tmp = new string_type_t;
882 # FILE_NAME(tmp, @1);
883 # $$ = tmp;
884 # }
885 ()
886 def p__embed0_data_type(p):
887 '''_embed0_data_type : '''
888 # { lex_in_package_scope($1); }
889 ()
890 def p_data_type_or_implicit_1(p):
891 '''data_type_or_implicit : data_type '''
892 print(p)
893 # { $$ = $1; }
894 ()
895 def p_data_type_or_implicit_2(p):
896 '''data_type_or_implicit : signing dimensions_opt '''
897 print(p)
898 # { vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, $1, $2);
899 # tmp->implicit_flag = true;
900 # FILE_NAME(tmp, @1);
901 # $$ = tmp;
902 # }
903 ()
904 def p_data_type_or_implicit_3(p):
905 '''data_type_or_implicit : dimensions '''
906 print(p)
907 # { vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, $1);
908 # tmp->implicit_flag = true;
909 # FILE_NAME(tmp, @1);
910 # $$ = tmp;
911 # }
912 ()
913 def p_data_type_or_implicit_4(p):
914 '''data_type_or_implicit : '''
915 print(p)
916 # { $$ = 0; }
917 ()
918 def p_data_type_or_implicit_or_void_1(p):
919 '''data_type_or_implicit_or_void : data_type_or_implicit '''
920 print(p)
921 # { $$ = $1; }
922 ()
923 def p_data_type_or_implicit_or_void_2(p):
924 '''data_type_or_implicit_or_void : K_void '''
925 print(p)
926 # { void_type_t*tmp = new void_type_t;
927 # FILE_NAME(tmp, @1);
928 # $$ = tmp;
929 # }
930 ()
931 def p_description_1(p):
932 '''description : module '''
933 print(p)
934 ()
935 def p_description_2(p):
936 '''description : udp_primitive '''
937 print(p)
938 ()
939 def p_description_3(p):
940 '''description : config_declaration '''
941 print(p)
942 ()
943 def p_description_4(p):
944 '''description : nature_declaration '''
945 print(p)
946 ()
947 def p_description_5(p):
948 '''description : package_declaration '''
949 print(p)
950 ()
951 def p_description_6(p):
952 '''description : discipline_declaration '''
953 print(p)
954 ()
955 def p_description_7(p):
956 '''description : package_item '''
957 print(p)
958 ()
959 def p_description_8(p):
960 '''description : KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' '''
961 print(p)
962 # { perm_string tmp3 = lex_strings.make($3);
963 # pform_set_type_attrib(tmp3, $5, $7);
964 # delete[] $3;
965 # delete[] $5;
966 # }
967 ()
968 def p_description_list_1(p):
969 '''description_list : description '''
970 print(p)
971 ()
972 def p_description_list_2(p):
973 '''description_list : description_list description '''
974 print(p)
975 ()
976 def p_endnew_opt_1(p):
977 '''endnew_opt : ':' K_new '''
978 print(p)
979 ()
980 def p_endnew_opt_2(p):
981 '''endnew_opt : '''
982 print(p)
983 ()
984 def p_dynamic_array_new_1(p):
985 '''dynamic_array_new : K_new '[' expression ']' '''
986 print(p)
987 # { $$ = new PENewArray($3, 0);
988 # FILE_NAME($$, @1);
989 # }
990 ()
991 def p_dynamic_array_new_2(p):
992 '''dynamic_array_new : K_new '[' expression ']' '(' expression ')' '''
993 print(p)
994 # { $$ = new PENewArray($3, $6);
995 # FILE_NAME($$, @1);
996 # }
997 ()
998 def p_for_step_1(p):
999 '''for_step : lpvalue '=' expression '''
1000 print(p)
1001 # { PAssign*tmp = new PAssign($1,$3);
1002 # FILE_NAME(tmp, @1);
1003 # $$ = tmp;
1004 # }
1005 ()
1006 def p_for_step_2(p):
1007 '''for_step : inc_or_dec_expression '''
1008 print(p)
1009 # { $$ = pform_compressed_assign_from_inc_dec(@1, $1); }
1010 ()
1011 def p_for_step_3(p):
1012 '''for_step : compressed_statement '''
1013 print(p)
1014 # { $$ = $1; }
1015 ()
1016 def p_function_declaration_1(p):
1017 '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER ';' _embed0_function_declaration function_item_list statement_or_null_list_opt K_endfunction _embed1_function_declaration endlabel_opt '''
1018 print(p)
1019 # { // Last step: check any closing name.
1020 # if ($11) {
1021 # if (strcmp($4,$11) != 0) {
1022 # yyerror(@11, "error: End label doesn't match "
1023 # "function name");
1024 # }
1025 # if (! gn_system_verilog()) {
1026 # yyerror(@11, "error: Function end labels require "
1027 # "SystemVerilog.");
1028 # }
1029 # delete[]$11;
1030 # }
1031 # delete[]$4;
1032 # }
1033 ()
1034 def p_function_declaration_2(p):
1035 '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER _embed2_function_declaration '(' tf_port_list_opt ')' ';' block_item_decls_opt statement_or_null_list_opt K_endfunction _embed3_function_declaration endlabel_opt '''
1036 print(p)
1037 # { // Last step: check any closing name.
1038 # if ($14) {
1039 # if (strcmp($4,$14) != 0) {
1040 # yyerror(@14, "error: End label doesn't match "
1041 # "function name");
1042 # }
1043 # if (! gn_system_verilog()) {
1044 # yyerror(@14, "error: Function end labels require "
1045 # "SystemVerilog.");
1046 # }
1047 # delete[]$14;
1048 # }
1049 # delete[]$4;
1050 # }
1051 ()
1052 def p_function_declaration_3(p):
1053 '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER error K_endfunction _embed4_function_declaration endlabel_opt '''
1054 print(p)
1055 # { // Last step: check any closing name.
1056 # if ($8) {
1057 # if (strcmp($4,$8) != 0) {
1058 # yyerror(@8, "error: End label doesn't match function name");
1059 # }
1060 # if (! gn_system_verilog()) {
1061 # yyerror(@8, "error: Function end labels require "
1062 # "SystemVerilog.");
1063 # }
1064 # delete[]$8;
1065 # }
1066 # delete[]$4;
1067 # }
1068 ()
1069 def p__embed0_function_declaration(p):
1070 '''_embed0_function_declaration : '''
1071 # { assert(current_function == 0);
1072 # current_function = pform_push_function_scope(@1, $4, $2);
1073 # }
1074 ()
1075 def p__embed1_function_declaration(p):
1076 '''_embed1_function_declaration : '''
1077 # { current_function->set_ports($7);
1078 # current_function->set_return($3);
1079 # current_function_set_statement($8? @8 : @4, $8);
1080 # pform_set_this_class(@4, current_function);
1081 # pform_pop_scope();
1082 # current_function = 0;
1083 # }
1084 ()
1085 def p__embed2_function_declaration(p):
1086 '''_embed2_function_declaration : '''
1087 # { assert(current_function == 0);
1088 # current_function = pform_push_function_scope(@1, $4, $2);
1089 # }
1090 ()
1091 def p__embed3_function_declaration(p):
1092 '''_embed3_function_declaration : '''
1093 # { current_function->set_ports($7);
1094 # current_function->set_return($3);
1095 # current_function_set_statement($11? @11 : @4, $11);
1096 # pform_set_this_class(@4, current_function);
1097 # pform_pop_scope();
1098 # current_function = 0;
1099 # if ($7==0 && !gn_system_verilog()) {
1100 # yyerror(@4, "error: Empty parenthesis syntax requires SystemVerilog.");
1101 # }
1102 # }
1103 ()
1104 def p__embed4_function_declaration(p):
1105 '''_embed4_function_declaration : '''
1106 # { /* */
1107 # if (current_function) {
1108 # pform_pop_scope();
1109 # current_function = 0;
1110 # }
1111 # assert(current_function == 0);
1112 # yyerror(@1, "error: Syntax error defining function.");
1113 # yyerrok;
1114 # }
1115 ()
1116 def p_import_export_1(p):
1117 '''import_export : K_import '''
1118 print(p)
1119 # { $$ = true; }
1120 ()
1121 def p_import_export_2(p):
1122 '''import_export : K_export '''
1123 print(p)
1124 # { $$ = false; }
1125 ()
1126 def p_implicit_class_handle_1(p):
1127 '''implicit_class_handle : K_this '''
1128 print(p)
1129 # { $$ = pform_create_this(); }
1130 ()
1131 def p_implicit_class_handle_2(p):
1132 '''implicit_class_handle : K_super '''
1133 print(p)
1134 # { $$ = pform_create_super(); }
1135 ()
1136 def p_inc_or_dec_expression_1(p):
1137 '''inc_or_dec_expression : K_INCR lpvalue %prec UNARY_PREC '''
1138 print(p)
1139 # { PEUnary*tmp = new PEUnary('I', $2);
1140 # FILE_NAME(tmp, @2);
1141 # $$ = tmp;
1142 # }
1143 ()
1144 def p_inc_or_dec_expression_2(p):
1145 '''inc_or_dec_expression : lpvalue K_INCR %prec UNARY_PREC '''
1146 print(p)
1147 # { PEUnary*tmp = new PEUnary('i', $1);
1148 # FILE_NAME(tmp, @1);
1149 # $$ = tmp;
1150 # }
1151 ()
1152 def p_inc_or_dec_expression_3(p):
1153 '''inc_or_dec_expression : K_DECR lpvalue %prec UNARY_PREC '''
1154 print(p)
1155 # { PEUnary*tmp = new PEUnary('D', $2);
1156 # FILE_NAME(tmp, @2);
1157 # $$ = tmp;
1158 # }
1159 ()
1160 def p_inc_or_dec_expression_4(p):
1161 '''inc_or_dec_expression : lpvalue K_DECR %prec UNARY_PREC '''
1162 print(p)
1163 # { PEUnary*tmp = new PEUnary('d', $1);
1164 # FILE_NAME(tmp, @1);
1165 # $$ = tmp;
1166 # }
1167 ()
1168 def p_inside_expression_1(p):
1169 '''inside_expression : expression K_inside '{' open_range_list '}' '''
1170 print(p)
1171 # { yyerror(@2, "sorry: \"inside\" expressions not supported yet.");
1172 # $$ = 0;
1173 # }
1174 ()
1175 def p_integer_vector_type_1(p):
1176 '''integer_vector_type : K_reg '''
1177 print(p)
1178 # { $$ = IVL_VT_NO_TYPE; }
1179 ()
1180 def p_integer_vector_type_2(p):
1181 '''integer_vector_type : K_bit '''
1182 print(p)
1183 # { $$ = IVL_VT_BOOL; }
1184 ()
1185 def p_integer_vector_type_3(p):
1186 '''integer_vector_type : K_logic '''
1187 print(p)
1188 # { $$ = IVL_VT_LOGIC; }
1189 ()
1190 def p_integer_vector_type_4(p):
1191 '''integer_vector_type : K_bool '''
1192 print(p)
1193 # { $$ = IVL_VT_BOOL; }
1194 ()
1195 def p_join_keyword_1(p):
1196 '''join_keyword : K_join '''
1197 print(p)
1198 # { $$ = PBlock::BL_PAR; }
1199 ()
1200 def p_join_keyword_2(p):
1201 '''join_keyword : K_join_none '''
1202 print(p)
1203 # { $$ = PBlock::BL_JOIN_NONE; }
1204 ()
1205 def p_join_keyword_3(p):
1206 '''join_keyword : K_join_any '''
1207 print(p)
1208 # { $$ = PBlock::BL_JOIN_ANY; }
1209 ()
1210 def p_jump_statement_1(p):
1211 '''jump_statement : K_break ';' '''
1212 print(p)
1213 # { yyerror(@1, "sorry: break statements not supported.");
1214 # $$ = 0;
1215 # }
1216 ()
1217 def p_jump_statement_2(p):
1218 '''jump_statement : K_return ';' '''
1219 print(p)
1220 # { PReturn*tmp = new PReturn(0);
1221 # FILE_NAME(tmp, @1);
1222 # $$ = tmp;
1223 # }
1224 ()
1225 def p_jump_statement_3(p):
1226 '''jump_statement : K_return expression ';' '''
1227 print(p)
1228 # { PReturn*tmp = new PReturn($2);
1229 # FILE_NAME(tmp, @1);
1230 # $$ = tmp;
1231 # }
1232 ()
1233 def p_lifetime_1(p):
1234 '''lifetime : K_automatic '''
1235 print(p)
1236 # { $$ = LexicalScope::AUTOMATIC; }
1237 ()
1238 def p_lifetime_2(p):
1239 '''lifetime : K_static '''
1240 print(p)
1241 # { $$ = LexicalScope::STATIC; }
1242 ()
1243 def p_lifetime_opt_1(p):
1244 '''lifetime_opt : lifetime '''
1245 print(p)
1246 # { $$ = $1; }
1247 ()
1248 def p_lifetime_opt_2(p):
1249 '''lifetime_opt : '''
1250 print(p)
1251 # { $$ = LexicalScope::INHERITED; }
1252 ()
1253 def p_loop_statement_1(p):
1254 '''loop_statement : K_for '(' lpvalue '=' expression ';' expression ';' for_step ')' statement_or_null '''
1255 print(p)
1256 # { PForStatement*tmp = new PForStatement($3, $5, $7, $9, $11);
1257 # FILE_NAME(tmp, @1);
1258 # $$ = tmp;
1259 # }
1260 ()
1261 def p_loop_statement_2(p):
1262 '''loop_statement : K_for '(' data_type IDENTIFIER '=' expression ';' expression ';' for_step ')' _embed0_loop_statement statement_or_null '''
1263 print(p)
1264 # { pform_name_t tmp_hident;
1265 # tmp_hident.push_back(name_component_t(lex_strings.make($4)));
1266 #
1267 # PEIdent*tmp_ident = pform_new_ident(tmp_hident);
1268 # FILE_NAME(tmp_ident, @4);
1269 #
1270 # PForStatement*tmp_for = new PForStatement(tmp_ident, $6, $8, $10, $13);
1271 # FILE_NAME(tmp_for, @1);
1272 #
1273 # pform_pop_scope();
1274 # vector<Statement*>tmp_for_list (1);
1275 # tmp_for_list[0] = tmp_for;
1276 # PBlock*tmp_blk = current_block_stack.top();
1277 # current_block_stack.pop();
1278 # tmp_blk->set_statement(tmp_for_list);
1279 # $$ = tmp_blk;
1280 # delete[]$4;
1281 # }
1282 ()
1283 def p_loop_statement_3(p):
1284 '''loop_statement : K_forever statement_or_null '''
1285 print(p)
1286 # { PForever*tmp = new PForever($2);
1287 # FILE_NAME(tmp, @1);
1288 # $$ = tmp;
1289 # }
1290 ()
1291 def p_loop_statement_4(p):
1292 '''loop_statement : K_repeat '(' expression ')' statement_or_null '''
1293 print(p)
1294 # { PRepeat*tmp = new PRepeat($3, $5);
1295 # FILE_NAME(tmp, @1);
1296 # $$ = tmp;
1297 # }
1298 ()
1299 def p_loop_statement_5(p):
1300 '''loop_statement : K_while '(' expression ')' statement_or_null '''
1301 print(p)
1302 # { PWhile*tmp = new PWhile($3, $5);
1303 # FILE_NAME(tmp, @1);
1304 # $$ = tmp;
1305 # }
1306 ()
1307 def p_loop_statement_6(p):
1308 '''loop_statement : K_do statement_or_null K_while '(' expression ')' ';' '''
1309 print(p)
1310 # { PDoWhile*tmp = new PDoWhile($5, $2);
1311 # FILE_NAME(tmp, @1);
1312 # $$ = tmp;
1313 # }
1314 ()
1315 def p_loop_statement_7(p):
1316 '''loop_statement : K_foreach '(' IDENTIFIER '[' loop_variables ']' ')' _embed1_loop_statement statement_or_null '''
1317 print(p)
1318 # { PForeach*tmp_for = pform_make_foreach(@1, $3, $5, $9);
1319 #
1320 # pform_pop_scope();
1321 # vector<Statement*>tmp_for_list(1);
1322 # tmp_for_list[0] = tmp_for;
1323 # PBlock*tmp_blk = current_block_stack.top();
1324 # current_block_stack.pop();
1325 # tmp_blk->set_statement(tmp_for_list);
1326 # $$ = tmp_blk;
1327 # }
1328 ()
1329 def p_loop_statement_8(p):
1330 '''loop_statement : K_for '(' lpvalue '=' expression ';' expression ';' error ')' statement_or_null '''
1331 print(p)
1332 # { $$ = 0;
1333 # yyerror(@1, "error: Error in for loop step assignment.");
1334 # }
1335 ()
1336 def p_loop_statement_9(p):
1337 '''loop_statement : K_for '(' lpvalue '=' expression ';' error ';' for_step ')' statement_or_null '''
1338 print(p)
1339 # { $$ = 0;
1340 # yyerror(@1, "error: Error in for loop condition expression.");
1341 # }
1342 ()
1343 def p_loop_statement_10(p):
1344 '''loop_statement : K_for '(' error ')' statement_or_null '''
1345 print(p)
1346 # { $$ = 0;
1347 # yyerror(@1, "error: Incomprehensible for loop.");
1348 # }
1349 ()
1350 def p_loop_statement_11(p):
1351 '''loop_statement : K_while '(' error ')' statement_or_null '''
1352 print(p)
1353 # { $$ = 0;
1354 # yyerror(@1, "error: Error in while loop condition.");
1355 # }
1356 ()
1357 def p_loop_statement_12(p):
1358 '''loop_statement : K_do statement_or_null K_while '(' error ')' ';' '''
1359 print(p)
1360 # { $$ = 0;
1361 # yyerror(@1, "error: Error in do/while loop condition.");
1362 # }
1363 ()
1364 def p_loop_statement_13(p):
1365 '''loop_statement : K_foreach '(' IDENTIFIER '[' error ']' ')' statement_or_null '''
1366 print(p)
1367 # { $$ = 0;
1368 # yyerror(@4, "error: Errors in foreach loop variables list.");
1369 # }
1370 ()
1371 def p__embed0_loop_statement(p):
1372 '''_embed0_loop_statement : '''
1373 # { static unsigned for_counter = 0;
1374 # char for_block_name [64];
1375 # snprintf(for_block_name, sizeof for_block_name, "$ivl_for_loop%u", for_counter);
1376 # for_counter += 1;
1377 # PBlock*tmp = pform_push_block_scope(for_block_name, PBlock::BL_SEQ);
1378 # FILE_NAME(tmp, @1);
1379 # current_block_stack.push(tmp);
1380 #
1381 # list<decl_assignment_t*>assign_list;
1382 # decl_assignment_t*tmp_assign = new decl_assignment_t;
1383 # tmp_assign->name = lex_strings.make($4);
1384 # assign_list.push_back(tmp_assign);
1385 # pform_makewire(@4, 0, str_strength, &assign_list, NetNet::REG, $3);
1386 # }
1387 ()
1388 def p__embed1_loop_statement(p):
1389 '''_embed1_loop_statement : '''
1390 # { static unsigned foreach_counter = 0;
1391 # char for_block_name[64];
1392 # snprintf(for_block_name, sizeof for_block_name, "$ivl_foreach%u", foreach_counter);
1393 # foreach_counter += 1;
1394 #
1395 # PBlock*tmp = pform_push_block_scope(for_block_name, PBlock::BL_SEQ);
1396 # FILE_NAME(tmp, @1);
1397 # current_block_stack.push(tmp);
1398 #
1399 # pform_make_foreach_declarations(@1, $5);
1400 # }
1401 ()
1402 def p_list_of_variable_decl_assignments_1(p):
1403 '''list_of_variable_decl_assignments : variable_decl_assignment '''
1404 print(p)
1405 # { list<decl_assignment_t*>*tmp = new list<decl_assignment_t*>;
1406 # tmp->push_back($1);
1407 # $$ = tmp;
1408 # }
1409 ()
1410 def p_list_of_variable_decl_assignments_2(p):
1411 '''list_of_variable_decl_assignments : list_of_variable_decl_assignments ',' variable_decl_assignment '''
1412 print(p)
1413 # { list<decl_assignment_t*>*tmp = $1;
1414 # tmp->push_back($3);
1415 # $$ = tmp;
1416 # }
1417 ()
1418 def p_variable_decl_assignment_1(p):
1419 '''variable_decl_assignment : IDENTIFIER dimensions_opt '''
1420 print(p)
1421 # { decl_assignment_t*tmp = new decl_assignment_t;
1422 # tmp->name = lex_strings.make($1);
1423 # if ($2) {
1424 # tmp->index = *$2;
1425 # delete $2;
1426 # }
1427 # delete[]$1;
1428 # $$ = tmp;
1429 # }
1430 ()
1431 def p_variable_decl_assignment_2(p):
1432 '''variable_decl_assignment : IDENTIFIER '=' expression '''
1433 print(p)
1434 # { decl_assignment_t*tmp = new decl_assignment_t;
1435 # tmp->name = lex_strings.make($1);
1436 # tmp->expr .reset($3);
1437 # delete[]$1;
1438 # $$ = tmp;
1439 # }
1440 ()
1441 def p_variable_decl_assignment_3(p):
1442 '''variable_decl_assignment : IDENTIFIER '=' K_new '(' ')' '''
1443 print(p)
1444 # { decl_assignment_t*tmp = new decl_assignment_t;
1445 # tmp->name = lex_strings.make($1);
1446 # PENewClass*expr = new PENewClass;
1447 # FILE_NAME(expr, @3);
1448 # tmp->expr .reset(expr);
1449 # delete[]$1;
1450 # $$ = tmp;
1451 # }
1452 ()
1453 def p_loop_variables_1(p):
1454 '''loop_variables : loop_variables ',' IDENTIFIER '''
1455 print(p)
1456 # { list<perm_string>*tmp = $1;
1457 # tmp->push_back(lex_strings.make($3));
1458 # delete[]$3;
1459 # $$ = tmp;
1460 # }
1461 ()
1462 def p_loop_variables_2(p):
1463 '''loop_variables : IDENTIFIER '''
1464 print(p)
1465 # { list<perm_string>*tmp = new list<perm_string>;
1466 # tmp->push_back(lex_strings.make($1));
1467 # delete[]$1;
1468 # $$ = tmp;
1469 # }
1470 ()
1471 def p_method_qualifier_1(p):
1472 '''method_qualifier : K_virtual '''
1473 print(p)
1474 ()
1475 def p_method_qualifier_2(p):
1476 '''method_qualifier : class_item_qualifier '''
1477 print(p)
1478 ()
1479 def p_method_qualifier_opt_1(p):
1480 '''method_qualifier_opt : method_qualifier '''
1481 print(p)
1482 ()
1483 def p_method_qualifier_opt_2(p):
1484 '''method_qualifier_opt : '''
1485 print(p)
1486 ()
1487
1488 if __name__ == '__main__':
1489 from ply import *
1490 yacc.yacc()
1491