2001-03-11 01:29:38 +01:00
|
|
|
|
|
|
|
|
%{
|
2001-03-20 03:48:40 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2003-08-26 18:26:01 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2004-06-16 18:33:25 +02:00
|
|
|
#ident "$Id: lexor.lex,v 1.42 2004/06/16 16:33:26 steve Exp $"
|
2001-03-20 03:48:40 +01:00
|
|
|
#endif
|
|
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
# include "parse_misc.h"
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "parse.h"
|
|
|
|
|
# include <string.h>
|
2002-03-01 06:42:50 +01:00
|
|
|
# include <assert.h>
|
2001-03-11 01:29:38 +01:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
2001-03-23 03:40:22 +01:00
|
|
|
/* These are some special header keywords. */
|
|
|
|
|
^":vpi_module" { return K_vpi_module; }
|
2001-07-01 01:03:16 +02:00
|
|
|
^":vpi_time_precision" { return K_vpi_time_precision; }
|
2001-03-23 03:40:22 +01:00
|
|
|
|
|
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
/* A label is any non-blank text that appears left justified. */
|
2001-06-18 05:10:34 +02:00
|
|
|
^[.$_a-zA-Z\\][.$_a-zA-Z\\0-9<>/]* {
|
2001-03-11 01:29:38 +01:00
|
|
|
yylval.text = strdup(yytext);
|
2002-03-01 06:42:50 +01:00
|
|
|
assert(yylval.text);
|
2001-03-11 01:29:38 +01:00
|
|
|
return T_LABEL; }
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
/* String tokens are parsed here. Return as the token value the
|
|
|
|
|
contents of the string without the enclosing quotes. */
|
2001-06-18 05:10:34 +02:00
|
|
|
\"([^\"\\]|\\.)*\" {
|
2001-03-16 02:44:34 +01:00
|
|
|
yytext[strlen(yytext)-1] = 0;
|
|
|
|
|
yylval.text = strdup(yytext+1);
|
2002-03-01 06:42:50 +01:00
|
|
|
assert(yylval.text);
|
2001-03-16 02:44:34 +01:00
|
|
|
return T_STRING; }
|
|
|
|
|
|
2003-02-10 00:33:26 +01:00
|
|
|
/* Binary vector tokens are parsed here. The result of this is a
|
2002-04-14 05:53:20 +02:00
|
|
|
string of binary 4-values in the yylval.vect.text string. This is
|
2003-02-10 00:33:26 +01:00
|
|
|
preceded by an 's' if the vector is signed. */
|
2002-04-14 05:53:20 +02:00
|
|
|
[1-9][0-9]*("'b"|"'sb")[01xz]+ {
|
2001-04-04 06:33:08 +02:00
|
|
|
yylval.vect.idx = strtoul(yytext, 0, 10);
|
2002-04-14 05:53:20 +02:00
|
|
|
yylval.vect.text = (char*)malloc(yylval.vect.idx + 2);
|
2002-03-01 06:42:50 +01:00
|
|
|
assert(yylval.vect.text);
|
2002-04-14 05:53:20 +02:00
|
|
|
char*dest = yylval.vect.text;
|
2001-04-04 06:33:08 +02:00
|
|
|
|
2002-04-14 05:53:20 +02:00
|
|
|
const char*bits = strchr(yytext, '\'');
|
|
|
|
|
assert(bits);
|
|
|
|
|
bits += 1;
|
|
|
|
|
|
|
|
|
|
if (*bits == 's') {
|
|
|
|
|
*dest++ = 's';
|
|
|
|
|
bits += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(*bits == 'b');
|
2001-04-04 06:33:08 +02:00
|
|
|
bits += 1;
|
|
|
|
|
unsigned pad = 0;
|
|
|
|
|
if (strlen(bits) < yylval.vect.idx)
|
|
|
|
|
pad = yylval.vect.idx - strlen(bits);
|
|
|
|
|
|
2002-04-14 05:53:20 +02:00
|
|
|
memset(dest, '0', pad);
|
2001-04-04 06:33:08 +02:00
|
|
|
for (unsigned idx = pad ; idx < yylval.vect.idx ; idx += 1)
|
2002-04-14 05:53:20 +02:00
|
|
|
dest[idx] = bits[idx-pad];
|
2001-04-04 06:33:08 +02:00
|
|
|
|
2002-04-14 05:53:20 +02:00
|
|
|
dest[yylval.vect.idx] = 0;
|
2001-04-04 06:33:08 +02:00
|
|
|
return T_VECTOR; }
|
|
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
|
|
|
|
|
/* These are some keywords that are recognized. */
|
2001-10-16 04:47:37 +02:00
|
|
|
".arith/div" { return K_ARITH_DIV; }
|
2002-01-03 05:19:01 +01:00
|
|
|
".arith/mod" { return K_ARITH_MOD; }
|
2001-06-17 01:45:05 +02:00
|
|
|
".arith/mult" { return K_ARITH_MULT; }
|
|
|
|
|
".arith/sub" { return K_ARITH_SUB; }
|
|
|
|
|
".arith/sum" { return K_ARITH_SUM; }
|
2004-06-16 18:33:25 +02:00
|
|
|
".cmp/eq" { return K_CMP_EQ; }
|
|
|
|
|
".cmp/ne" { return K_CMP_NE; }
|
2001-06-15 06:07:57 +02:00
|
|
|
".cmp/ge" { return K_CMP_GE; }
|
2003-04-11 07:15:38 +02:00
|
|
|
".cmp/ge.s" { return K_CMP_GE_S; }
|
2001-06-15 06:07:57 +02:00
|
|
|
".cmp/gt" { return K_CMP_GT; }
|
2003-04-11 07:15:38 +02:00
|
|
|
".cmp/gt.s" { return K_CMP_GT_S; }
|
2001-04-14 07:10:56 +02:00
|
|
|
".event" { return K_EVENT; }
|
|
|
|
|
".event/or" { return K_EVENT_OR; }
|
|
|
|
|
".functor" { return K_FUNCTOR; }
|
|
|
|
|
".net" { return K_NET; }
|
|
|
|
|
".net/s" { return K_NET_S; }
|
2003-03-11 00:37:07 +01:00
|
|
|
".param" { return K_PARAM; }
|
2001-05-09 04:53:25 +02:00
|
|
|
".resolv" { return K_RESOLV; }
|
2001-04-14 07:10:56 +02:00
|
|
|
".scope" { return K_SCOPE; }
|
2001-07-06 06:46:44 +02:00
|
|
|
".shift/l" { return K_SHIFTL; }
|
2001-07-07 04:57:33 +02:00
|
|
|
".shift/r" { return K_SHIFTR; }
|
2001-04-14 07:10:56 +02:00
|
|
|
".thread" { return K_THREAD; }
|
2002-12-21 01:55:57 +01:00
|
|
|
".timescale" { return K_TIMESCALE; }
|
2002-03-18 01:19:34 +01:00
|
|
|
".ufunc" { return K_UFUNC; }
|
2001-04-14 07:10:56 +02:00
|
|
|
".var" { return K_VAR; }
|
|
|
|
|
".var/s" { return K_VAR_S; }
|
2002-06-21 06:58:55 +02:00
|
|
|
".var/i" { return K_VAR_I; /* integer */ }
|
2003-01-26 00:48:05 +01:00
|
|
|
".word" { return K_WORD; }
|
2001-04-24 04:23:58 +02:00
|
|
|
".udp" { return K_UDP; }
|
|
|
|
|
".udp/c"(omb)? { return K_UDP_C; }
|
|
|
|
|
".udp/s"(equ)? { return K_UDP_S; }
|
2001-05-01 03:09:39 +02:00
|
|
|
".mem" { return K_MEM; }
|
|
|
|
|
".mem/p"(ort)? { return K_MEM_P; }
|
|
|
|
|
".mem/i"(nit)? { return K_MEM_I; }
|
2001-11-01 04:00:19 +01:00
|
|
|
".force" { return K_FORCE; }
|
2001-03-11 01:29:38 +01:00
|
|
|
|
|
|
|
|
/* instructions start with a % character. The compiler decides what
|
2001-03-16 02:44:34 +01:00
|
|
|
kind of instruction this really is. The few exceptions (that have
|
|
|
|
|
exceptional parameter requirements) are listed first. */
|
|
|
|
|
|
2001-04-18 06:21:23 +02:00
|
|
|
"%vpi_call" { return K_vpi_call; }
|
2001-05-20 02:46:12 +02:00
|
|
|
"%vpi_func" { return K_vpi_func; }
|
2003-01-27 01:14:37 +01:00
|
|
|
"%vpi_func/r" { return K_vpi_func_r; }
|
2001-04-18 06:21:23 +02:00
|
|
|
"%disable" { return K_disable; }
|
|
|
|
|
"%fork" { return K_fork; }
|
2001-03-16 02:44:34 +01:00
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
"%"[.$_/a-zA-Z0-9]+ {
|
|
|
|
|
yylval.text = strdup(yytext);
|
2002-03-01 06:42:50 +01:00
|
|
|
assert(yylval.text);
|
2001-03-11 01:29:38 +01:00
|
|
|
return T_INSTR; }
|
|
|
|
|
|
|
|
|
|
[0-9][0-9]* {
|
2001-03-20 03:45:25 +01:00
|
|
|
yylval.numb = strtol(yytext, 0, 0);
|
2001-03-11 01:29:38 +01:00
|
|
|
return T_NUMBER; }
|
|
|
|
|
|
|
|
|
|
"0x"[0-9a-fA-F]+ {
|
2001-03-20 03:45:25 +01:00
|
|
|
yylval.numb = strtol(yytext, 0, 0);
|
2001-03-11 01:29:38 +01:00
|
|
|
return T_NUMBER; }
|
|
|
|
|
|
|
|
|
|
|
2001-04-04 06:33:08 +02:00
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
/* Symbols are pretty much what is left. They are used to refer to
|
|
|
|
|
labels so the rule must match a string that a label would match. */
|
2001-06-18 05:10:34 +02:00
|
|
|
[.$_a-zA-Z\\][.$_a-zA-Z\\0-9<>/]* {
|
2001-03-11 01:29:38 +01:00
|
|
|
yylval.text = strdup(yytext);
|
2002-03-01 06:42:50 +01:00
|
|
|
assert(yylval.text);
|
2001-03-11 01:29:38 +01:00
|
|
|
return T_SYMBOL; }
|
|
|
|
|
|
2001-05-10 02:26:53 +02:00
|
|
|
/* Symbols may include komma `,' in certain constructs */
|
|
|
|
|
|
|
|
|
|
[A-Z]"<"[.$_a-zA-Z0-9/,]*">" {
|
|
|
|
|
yylval.text = strdup(yytext);
|
2002-03-01 06:42:50 +01:00
|
|
|
assert(yylval.text);
|
2001-05-10 02:26:53 +02:00
|
|
|
return T_SYMBOL; }
|
|
|
|
|
|
2001-03-11 01:29:38 +01:00
|
|
|
|
|
|
|
|
/* Accept the common assembler style comments, treat them as white
|
|
|
|
|
space. Of course, also skip white space. The semi-colon is
|
|
|
|
|
special, though, in that it is also a statement terminator. */
|
|
|
|
|
";".* { return ';'; }
|
|
|
|
|
"#".* { ; }
|
|
|
|
|
|
2002-02-27 06:46:33 +01:00
|
|
|
[ \t\b\r] { ; }
|
2001-03-11 01:29:38 +01:00
|
|
|
|
|
|
|
|
\n { yyline += 1; }
|
|
|
|
|
|
|
|
|
|
. { return yytext[0]; }
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
int yywrap()
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2001-03-20 03:48:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: lexor.lex,v $
|
2004-06-16 18:33:25 +02:00
|
|
|
* Revision 1.42 2004/06/16 16:33:26 steve
|
|
|
|
|
* Add structural equality compare nodes.
|
|
|
|
|
*
|
2003-08-26 18:26:01 +02:00
|
|
|
* Revision 1.41 2003/08/26 16:26:02 steve
|
|
|
|
|
* ifdef idents correctly.
|
|
|
|
|
*
|
2003-04-11 07:15:38 +02:00
|
|
|
* Revision 1.40 2003/04/11 05:15:39 steve
|
|
|
|
|
* Add signed versions of .cmp/gt/ge
|
|
|
|
|
*
|
2003-03-11 00:37:07 +01:00
|
|
|
* Revision 1.39 2003/03/10 23:37:07 steve
|
|
|
|
|
* Direct support for string parameters.
|
|
|
|
|
*
|
2003-02-10 00:33:26 +01:00
|
|
|
* Revision 1.38 2003/02/09 23:33:26 steve
|
|
|
|
|
* Spelling fixes.
|
|
|
|
|
*
|
2003-01-27 01:14:37 +01:00
|
|
|
* Revision 1.37 2003/01/27 00:14:37 steve
|
|
|
|
|
* Support in various contexts the $realtime
|
|
|
|
|
* system task.
|
|
|
|
|
*
|
2003-01-26 00:48:05 +01:00
|
|
|
* Revision 1.36 2003/01/25 23:48:06 steve
|
|
|
|
|
* Add thread word array, and add the instructions,
|
|
|
|
|
* %add/wr, %cmp/wr, %load/wr, %mul/wr and %set/wr.
|
|
|
|
|
*
|
2002-12-21 01:55:57 +01:00
|
|
|
* Revision 1.35 2002/12/21 00:55:58 steve
|
|
|
|
|
* The $time system task returns the integer time
|
|
|
|
|
* scaled to the local units. Change the internal
|
|
|
|
|
* implementation of vpiSystemTime the $time functions
|
|
|
|
|
* to properly account for this. Also add $simtime
|
|
|
|
|
* to get the simulation time.
|
|
|
|
|
*
|
2002-06-21 06:58:55 +02:00
|
|
|
* Revision 1.34 2002/06/21 04:58:55 steve
|
|
|
|
|
* Add support for special integer vectors.
|
|
|
|
|
*
|
2002-04-14 05:53:20 +02:00
|
|
|
* Revision 1.33 2002/04/14 03:53:20 steve
|
|
|
|
|
* Allow signed constant vectors for call_vpi parameters.
|
|
|
|
|
*
|
2002-03-18 01:19:34 +01:00
|
|
|
* Revision 1.32 2002/03/18 00:19:34 steve
|
|
|
|
|
* Add the .ufunc statement.
|
|
|
|
|
*
|
2002-03-01 06:42:50 +01:00
|
|
|
* Revision 1.31 2002/03/01 05:42:50 steve
|
|
|
|
|
* out-of-memory asserts.
|
|
|
|
|
*
|
2002-02-27 06:46:33 +01:00
|
|
|
* Revision 1.30 2002/02/27 05:46:33 steve
|
|
|
|
|
* carriage return is white space.
|
|
|
|
|
*
|
2002-01-03 05:19:01 +01:00
|
|
|
* Revision 1.29 2002/01/03 04:19:02 steve
|
|
|
|
|
* Add structural modulus support down to vvp.
|
|
|
|
|
*
|
2001-11-01 04:00:19 +01:00
|
|
|
* Revision 1.28 2001/11/01 03:00:19 steve
|
|
|
|
|
* Add force/cassign/release/deassign support. (Stephan Boettcher)
|
|
|
|
|
*
|
2001-10-16 04:47:37 +02:00
|
|
|
* Revision 1.27 2001/10/16 02:47:37 steve
|
|
|
|
|
* Add arith/div object.
|
|
|
|
|
*
|
2001-07-07 04:57:33 +02:00
|
|
|
* Revision 1.26 2001/07/07 02:57:33 steve
|
|
|
|
|
* Add the .shift/r functor.
|
|
|
|
|
*
|
2001-07-06 06:46:44 +02:00
|
|
|
* Revision 1.25 2001/07/06 04:46:44 steve
|
|
|
|
|
* Add structural left shift (.shift/l)
|
|
|
|
|
*
|
2001-07-01 01:03:16 +02:00
|
|
|
* Revision 1.24 2001/06/30 23:03:17 steve
|
|
|
|
|
* support fast programming by only writing the bits
|
|
|
|
|
* that are listed in the input file.
|
|
|
|
|
*
|
2001-06-18 05:10:34 +02:00
|
|
|
* Revision 1.23 2001/06/18 03:10:34 steve
|
|
|
|
|
* 1. Logic with more than 4 inputs
|
|
|
|
|
* 2. Id and name mangling
|
|
|
|
|
* 3. A memory leak in draw_net_in_scope()
|
|
|
|
|
* (Stephan Boettcher)
|
|
|
|
|
*
|
2001-06-17 01:45:05 +02:00
|
|
|
* Revision 1.22 2001/06/16 23:45:05 steve
|
|
|
|
|
* Add support for structural multiply in t-dll.
|
|
|
|
|
* Add code generators and vvp support for both
|
|
|
|
|
* structural and behavioral multiply.
|
|
|
|
|
*
|
2001-06-15 06:07:57 +02:00
|
|
|
* Revision 1.21 2001/06/15 04:07:58 steve
|
|
|
|
|
* Add .cmp statements for structural comparison.
|
|
|
|
|
*
|
2001-06-07 05:09:03 +02:00
|
|
|
* Revision 1.20 2001/06/07 03:09:03 steve
|
|
|
|
|
* Implement .arith/sub subtraction.
|
|
|
|
|
*
|
2001-06-05 05:05:41 +02:00
|
|
|
* Revision 1.19 2001/06/05 03:05:41 steve
|
|
|
|
|
* Add structural addition.
|
|
|
|
|
*
|
2001-05-20 02:46:12 +02:00
|
|
|
* Revision 1.18 2001/05/20 00:46:12 steve
|
|
|
|
|
* Add support for system function calls.
|
|
|
|
|
*
|
2001-05-10 02:26:53 +02:00
|
|
|
* Revision 1.17 2001/05/10 00:26:53 steve
|
|
|
|
|
* VVP support for memories in expressions,
|
|
|
|
|
* including general support for thread bit
|
|
|
|
|
* vectors as system task parameters.
|
|
|
|
|
* (Stephan Boettcher)
|
|
|
|
|
*
|
2001-05-09 04:53:25 +02:00
|
|
|
* Revision 1.16 2001/05/09 02:53:25 steve
|
|
|
|
|
* Implement the .resolv syntax.
|
|
|
|
|
*
|
2001-05-01 03:09:39 +02:00
|
|
|
* Revision 1.15 2001/05/01 01:09:39 steve
|
|
|
|
|
* Add support for memory objects. (Stephan Boettcher)
|
|
|
|
|
*
|
2001-04-24 04:23:58 +02:00
|
|
|
* Revision 1.14 2001/04/24 02:23:59 steve
|
|
|
|
|
* Support for UDP devices in VVP (Stephen Boettcher)
|
|
|
|
|
*
|
2001-04-18 06:21:23 +02:00
|
|
|
* Revision 1.13 2001/04/18 04:21:23 steve
|
|
|
|
|
* Put threads into scopes.
|
|
|
|
|
*
|
2001-04-14 07:10:56 +02:00
|
|
|
* Revision 1.12 2001/04/14 05:10:56 steve
|
|
|
|
|
* support the .event/or statement.
|
|
|
|
|
*
|
2001-04-05 03:34:26 +02:00
|
|
|
* Revision 1.11 2001/04/05 01:34:26 steve
|
|
|
|
|
* Add the .var/s and .net/s statements for VPI support.
|
|
|
|
|
*
|
2001-04-04 06:33:08 +02:00
|
|
|
* Revision 1.10 2001/04/04 04:33:08 steve
|
|
|
|
|
* Take vector form as parameters to vpi_call.
|
|
|
|
|
*
|
2001-03-26 06:00:39 +02:00
|
|
|
* Revision 1.9 2001/03/26 04:00:39 steve
|
|
|
|
|
* Add the .event statement and the %wait instruction.
|
|
|
|
|
*
|
2001-03-25 21:36:45 +02:00
|
|
|
* Revision 1.8 2001/03/25 19:36:45 steve
|
|
|
|
|
* Accept <> characters in labels and symbols.
|
|
|
|
|
*
|
2001-03-25 01:35:35 +01:00
|
|
|
* Revision 1.7 2001/03/25 00:35:35 steve
|
|
|
|
|
* Add the .net statement.
|
|
|
|
|
*
|
2001-03-23 03:40:22 +01:00
|
|
|
* Revision 1.6 2001/03/23 02:40:22 steve
|
|
|
|
|
* Add the :module header statement.
|
|
|
|
|
*
|
2001-03-20 03:48:40 +01:00
|
|
|
* Revision 1.5 2001/03/20 02:48:40 steve
|
|
|
|
|
* Copyright notices.
|
|
|
|
|
*
|
|
|
|
|
*/
|