2 %option never-interactive
6 * Copyright (c) 2001-2005 Stephen Williams (steve@icarus.com)
8 * This source code is free software; you can redistribute it
9 * and/or modify it in source code form under the terms of the GNU
10 * General Public License as published by the Free Software
11 * Foundation; either version 2 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 #ident "$Id: lexor.lex,v 1.66 2007/04/10 01:26:16 steve Exp $"
27 # include "parse_misc.h"
36 /* These are some special header keywords. */
37 ^":vpi_module" { return K_vpi_module; }
38 ^":vpi_time_precision" { return K_vpi_time_precision; }
41 /* A label is any non-blank text that appears left justified. */
42 ^[.$_a-zA-Z\\][.$_a-zA-Z\\0-9<>/]* {
43 yylval.text = strdup(yytext);
47 /* String tokens are parsed here. Return as the token value the
48 contents of the string without the enclosing quotes. */
50 yytext[strlen(yytext)-1] = 0;
51 yylval.text = strdup(yytext+1);
55 /* Binary vector tokens are parsed here. The result of this is a
56 string of binary 4-values in the yylval.vect.text string. This is
57 preceded by an 's' if the vector is signed. */
58 [1-9][0-9]*("'b"|"'sb")[01xz]+ {
59 yylval.vect.idx = strtoul(yytext, 0, 10);
60 yylval.vect.text = (char*)malloc(yylval.vect.idx + 2);
61 assert(yylval.vect.text);
62 char*dest = yylval.vect.text;
64 const char*bits = strchr(yytext, '\'');
76 if (strlen(bits) < yylval.vect.idx)
77 pad = yylval.vect.idx - strlen(bits);
79 memset(dest, '0', pad);
80 for (unsigned idx = pad ; idx < yylval.vect.idx ; idx += 1)
81 dest[idx] = bits[idx-pad];
83 dest[yylval.vect.idx] = 0;
87 /* These are some keywords that are recognized. */
88 ".alias" { return K_ALIAS; }
89 ".alias/real" { return K_ALIAS_R; }
90 ".alias/s" { return K_ALIAS_S; }
91 ".arith/div" { return K_ARITH_DIV; }
92 ".arith/div.r" { return K_ARITH_DIV_R; }
93 ".arith/div.s" { return K_ARITH_DIV_S; }
94 ".arith/mod" { return K_ARITH_MOD; }
95 ".arith/mult" { return K_ARITH_MULT; }
96 ".arith/sub" { return K_ARITH_SUB; }
97 ".arith/sub.r" { return K_ARITH_SUB_R; }
98 ".arith/sum" { return K_ARITH_SUM; }
99 ".array" { return K_ARRAY; }
100 ".array/i" { return K_ARRAY_I; }
101 ".array/real" { return K_ARRAY_R; }
102 ".array/s" { return K_ARRAY_S; }
103 ".array/port" { return K_ARRAY_PORT; }
104 ".cmp/eeq" { return K_CMP_EEQ; }
105 ".cmp/eq" { return K_CMP_EQ; }
106 ".cmp/nee" { return K_CMP_NEE; }
107 ".cmp/ne" { return K_CMP_NE; }
108 ".cmp/ge" { return K_CMP_GE; }
109 ".cmp/ge.s" { return K_CMP_GE_S; }
110 ".cmp/gt" { return K_CMP_GT; }
111 ".cmp/gt.s" { return K_CMP_GT_S; }
112 ".concat" { return K_CONCAT; }
113 ".delay" { return K_DELAY; }
114 ".dff" { return K_DFF; }
115 ".event" { return K_EVENT; }
116 ".event/or" { return K_EVENT_OR; }
117 ".extend/s" { return K_EXTEND_S; }
118 ".functor" { return K_FUNCTOR; }
119 ".modpath" { return K_MODPATH; }
120 ".net" { return K_NET; }
121 ".net8" { return K_NET8; }
122 ".net8/s" { return K_NET8_S; }
123 ".net/real" { return K_NET_R; }
124 ".net/s" { return K_NET_S; }
125 ".param/l" { return K_PARAM_L; }
126 ".param/str" { return K_PARAM_STR; }
127 ".part" { return K_PART; }
128 ".part/pv" { return K_PART_PV; }
129 ".part/v" { return K_PART_V; }
130 ".reduce/and" { return K_REDUCE_AND; }
131 ".reduce/or" { return K_REDUCE_OR; }
132 ".reduce/xor" { return K_REDUCE_XOR; }
133 ".reduce/nand" { return K_REDUCE_NAND; }
134 ".reduce/nor" { return K_REDUCE_NOR; }
135 ".reduce/xnor" { return K_REDUCE_XNOR; }
136 ".repeat" { return K_REPEAT; }
137 ".resolv" { return K_RESOLV; }
138 ".scope" { return K_SCOPE; }
139 ".sfunc" { return K_SFUNC; }
140 ".shift/l" { return K_SHIFTL; }
141 ".shift/r" { return K_SHIFTR; }
142 ".shift/rs" { return K_SHIFTRS; }
143 ".thread" { return K_THREAD; }
144 ".timescale" { return K_TIMESCALE; }
145 ".ufunc" { return K_UFUNC; }
146 ".var" { return K_VAR; }
147 ".var/real" { return K_VAR_R; }
148 ".var/s" { return K_VAR_S; }
149 ".var/i" { return K_VAR_I; /* integer */ }
150 ".udp" { return K_UDP; }
151 ".udp/c"(omb)? { return K_UDP_C; }
152 ".udp/s"(equ)? { return K_UDP_S; }
153 ".mem" { return K_MEM; }
154 ".mem/p"(ort)? { return K_MEM_P; }
155 ".mem/i"(nit)? { return K_MEM_I; }
156 "-debug" { return K_DEBUG; }
158 /* instructions start with a % character. The compiler decides what
159 kind of instruction this really is. The few exceptions (that have
160 exceptional parameter requirements) are listed first. */
162 "%vpi_call" { return K_vpi_call; }
163 "%vpi_func" { return K_vpi_func; }
164 "%vpi_func/r" { return K_vpi_func_r; }
165 "%disable" { return K_disable; }
166 "%fork" { return K_fork; }
168 "%"[.$_/a-zA-Z0-9]+ {
169 yylval.text = strdup(yytext);
174 yylval.numb = strtol(yytext, 0, 0);
178 yylval.numb = strtol(yytext, 0, 0);
183 /* Symbols are pretty much what is left. They are used to refer to
184 labels so the rule must match a string that a label would match. */
185 [.$_a-zA-Z\\][.$_a-zA-Z\\0-9<>/]* {
186 yylval.text = strdup(yytext);
190 /* Symbols may include komma `,' in certain constructs */
192 [A-Z]"<"[.$_a-zA-Z0-9/,]*">" {
193 yylval.text = strdup(yytext);
198 /* Accept the common assembler style comments, treat them as white
199 space. Of course, also skip white space. The semi-colon is
200 special, though, in that it is also a statement terminator. */
201 ";".* { return ';'; }
208 . { return yytext[0]; }
219 * $Log: lexor.lex,v $
220 * Revision 1.66 2007/04/10 01:26:16 steve
221 * variable arrays generated without writing a record for each word.
223 * Revision 1.65 2007/01/16 05:44:16 steve
224 * Major rework of array handling. Memories are replaced with the
225 * more general concept of arrays. The NetMemory and NetEMemory
226 * classes are removed from the ivl core program, and the IVL_LPM_RAM
227 * lpm type is removed from the ivl_target API.
229 * Revision 1.64 2006/11/22 06:10:05 steve
230 * Fix spurious event from net8 that is forced.
232 * Revision 1.63 2006/09/23 04:57:20 steve
233 * Basic support for specify timing.
235 * Revision 1.62 2006/07/30 02:51:36 steve
236 * Fix/implement signed right shift.
238 * Revision 1.61 2006/06/18 04:15:50 steve
239 * Add support for system functions in continuous assignments.
241 * Revision 1.60 2006/05/17 04:15:25 steve
242 * Lexor os never interactive.
244 * Revision 1.59 2006/03/08 05:29:42 steve
245 * Add support for logic parameters.
247 * Revision 1.58 2006/01/02 05:32:07 steve
248 * Require explicit delay node from source.
250 * Revision 1.57 2005/11/25 17:55:26 steve
251 * Put vec8 and vec4 nets into seperate net classes.
253 * Revision 1.56 2005/10/12 17:23:15 steve
256 * Revision 1.55 2005/07/06 04:29:25 steve
257 * Implement real valued signals and arith nodes.
259 * Revision 1.54 2005/05/24 01:43:27 steve
260 * Add a sign-extension node.
262 * Revision 1.53 2005/05/08 23:40:14 steve
263 * Add support for variable part select.
265 * Revision 1.52 2005/04/28 04:59:53 steve
266 * Remove dead functor code.
268 * Revision 1.51 2005/04/24 20:07:26 steve
271 * Revision 1.50 2005/03/09 05:52:04 steve
272 * Handle case inequality in netlists.
274 * Revision 1.49 2005/02/07 22:42:42 steve
275 * Add .repeat functor and BIFIF functors.
277 * Revision 1.48 2005/02/03 04:55:13 steve
278 * Add support for reduction logic gates.
280 * Revision 1.47 2005/01/22 01:06:20 steve
281 * Implement the .cmp/eeq LPM node.
283 * Revision 1.46 2005/01/09 20:11:15 steve
284 * Add the .part/pv node and related functionality.
286 * Revision 1.45 2004/12/29 23:45:13 steve
287 * Add the part concatenation node (.concat).
289 * Add a vvp_event_anyedge class to handle the special
290 * case of .event statements of edge type. This also
291 * frees the posedge/negedge types to handle all 4 inputs.
293 * Implement table functor recv_vec4 method to receive
294 * and process vectors.
296 * Revision 1.44 2004/12/11 02:31:29 steve
297 * Rework of internals to carry vectors through nexus instead
298 * of single bits. Make the ivl, tgt-vvp and vvp initial changes
301 * Revision 1.43 2004/06/30 02:15:57 steve
302 * Add signed LPM divide.
304 * Revision 1.42 2004/06/16 16:33:26 steve
305 * Add structural equality compare nodes.
307 * Revision 1.41 2003/08/26 16:26:02 steve
308 * ifdef idents correctly.
310 * Revision 1.40 2003/04/11 05:15:39 steve
311 * Add signed versions of .cmp/gt/ge
313 * Revision 1.39 2003/03/10 23:37:07 steve
314 * Direct support for string parameters.
316 * Revision 1.38 2003/02/09 23:33:26 steve
319 * Revision 1.37 2003/01/27 00:14:37 steve
320 * Support in various contexts the $realtime
323 * Revision 1.36 2003/01/25 23:48:06 steve
324 * Add thread word array, and add the instructions,
325 * %add/wr, %cmp/wr, %load/wr, %mul/wr and %set/wr.
327 * Revision 1.35 2002/12/21 00:55:58 steve
328 * The $time system task returns the integer time
329 * scaled to the local units. Change the internal
330 * implementation of vpiSystemTime the $time functions
331 * to properly account for this. Also add $simtime
332 * to get the simulation time.
334 * Revision 1.34 2002/06/21 04:58:55 steve
335 * Add support for special integer vectors.
337 * Revision 1.33 2002/04/14 03:53:20 steve
338 * Allow signed constant vectors for call_vpi parameters.
340 * Revision 1.32 2002/03/18 00:19:34 steve
341 * Add the .ufunc statement.
343 * Revision 1.31 2002/03/01 05:42:50 steve
344 * out-of-memory asserts.
346 * Revision 1.30 2002/02/27 05:46:33 steve
347 * carriage return is white space.
349 * Revision 1.29 2002/01/03 04:19:02 steve
350 * Add structural modulus support down to vvp.
352 * Revision 1.28 2001/11/01 03:00:19 steve
353 * Add force/cassign/release/deassign support. (Stephan Boettcher)
355 * Revision 1.27 2001/10/16 02:47:37 steve
356 * Add arith/div object.
358 * Revision 1.26 2001/07/07 02:57:33 steve
359 * Add the .shift/r functor.
361 * Revision 1.25 2001/07/06 04:46:44 steve
362 * Add structural left shift (.shift/l)
364 * Revision 1.24 2001/06/30 23:03:17 steve
365 * support fast programming by only writing the bits
366 * that are listed in the input file.
368 * Revision 1.23 2001/06/18 03:10:34 steve
369 * 1. Logic with more than 4 inputs
370 * 2. Id and name mangling
371 * 3. A memory leak in draw_net_in_scope()
372 * (Stephan Boettcher)
374 * Revision 1.22 2001/06/16 23:45:05 steve
375 * Add support for structural multiply in t-dll.
376 * Add code generators and vvp support for both
377 * structural and behavioral multiply.
379 * Revision 1.21 2001/06/15 04:07:58 steve
380 * Add .cmp statements for structural comparison.
382 * Revision 1.20 2001/06/07 03:09:03 steve
383 * Implement .arith/sub subtraction.
385 * Revision 1.19 2001/06/05 03:05:41 steve
386 * Add structural addition.
388 * Revision 1.18 2001/05/20 00:46:12 steve
389 * Add support for system function calls.
391 * Revision 1.17 2001/05/10 00:26:53 steve
392 * VVP support for memories in expressions,
393 * including general support for thread bit
394 * vectors as system task parameters.
395 * (Stephan Boettcher)
397 * Revision 1.16 2001/05/09 02:53:25 steve
398 * Implement the .resolv syntax.
400 * Revision 1.15 2001/05/01 01:09:39 steve
401 * Add support for memory objects. (Stephan Boettcher)
403 * Revision 1.14 2001/04/24 02:23:59 steve
404 * Support for UDP devices in VVP (Stephen Boettcher)
406 * Revision 1.13 2001/04/18 04:21:23 steve
407 * Put threads into scopes.
409 * Revision 1.12 2001/04/14 05:10:56 steve
410 * support the .event/or statement.
412 * Revision 1.11 2001/04/05 01:34:26 steve
413 * Add the .var/s and .net/s statements for VPI support.
415 * Revision 1.10 2001/04/04 04:33:08 steve
416 * Take vector form as parameters to vpi_call.
418 * Revision 1.9 2001/03/26 04:00:39 steve
419 * Add the .event statement and the %wait instruction.
421 * Revision 1.8 2001/03/25 19:36:45 steve
422 * Accept <> characters in labels and symbols.
424 * Revision 1.7 2001/03/25 00:35:35 steve
425 * Add the .net statement.
427 * Revision 1.6 2001/03/23 02:40:22 steve
428 * Add the :module header statement.
430 * Revision 1.5 2001/03/20 02:48:40 steve