2011-04-28 02:08:42 +02:00
|
|
|
%option prefix="readmem"
|
2008-01-04 20:33:03 +01:00
|
|
|
%option nounput
|
2008-01-05 04:21:26 +01:00
|
|
|
%option noinput
|
2008-01-04 20:33:03 +01:00
|
|
|
|
1999-12-15 05:01:14 +01:00
|
|
|
%{
|
2000-02-23 03:56:53 +01:00
|
|
|
/*
|
2017-11-17 04:03:34 +01:00
|
|
|
* Copyright (c) 1999-2017 Stephen Williams (steve@icarus.com)
|
2000-02-23 03:56:53 +01:00
|
|
|
*
|
|
|
|
|
* 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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2000-02-23 03:56:53 +01:00
|
|
|
*/
|
2008-12-06 06:48:28 +01:00
|
|
|
|
1999-12-15 05:01:14 +01:00
|
|
|
# include "sys_readmem_lex.h"
|
|
|
|
|
# include <string.h>
|
2014-07-08 21:12:54 +02:00
|
|
|
static void make_addr(void);
|
|
|
|
|
static void make_hex_value(void);
|
|
|
|
|
static void make_bin_value(void);
|
2003-02-09 06:07:06 +01:00
|
|
|
|
|
|
|
|
static int save_state;
|
|
|
|
|
|
2009-02-25 01:47:46 +01:00
|
|
|
char *readmem_error_token = 0;
|
|
|
|
|
|
1999-12-15 05:01:14 +01:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%x BIN
|
|
|
|
|
%x HEX
|
2003-02-09 06:07:06 +01:00
|
|
|
%x CCOMMENT
|
1999-12-15 05:01:14 +01:00
|
|
|
|
|
|
|
|
%option noyywrap
|
|
|
|
|
%%
|
|
|
|
|
|
2003-02-09 06:07:06 +01:00
|
|
|
<HEX,BIN>"//".* { ; }
|
|
|
|
|
<HEX,BIN>[ \t\f\n\r] { ; }
|
1999-12-15 05:01:14 +01:00
|
|
|
|
2003-02-09 06:07:06 +01:00
|
|
|
<HEX,BIN>@[0-9a-fA-F]+ { make_addr(); return MEM_ADDRESS; }
|
1999-12-15 05:01:14 +01:00
|
|
|
<HEX>[0-9a-fA-FxXzZ_]+ { make_hex_value(); return MEM_WORD; }
|
2002-02-06 05:49:24 +01:00
|
|
|
<BIN>[01xXzZ_]+ { make_bin_value(); return MEM_WORD; }
|
1999-12-15 05:01:14 +01:00
|
|
|
|
2003-02-09 06:07:06 +01:00
|
|
|
<HEX,BIN>"/*" { save_state = YY_START; BEGIN(CCOMMENT); }
|
|
|
|
|
<CCOMMENT>[^*]* { ; }
|
|
|
|
|
<CCOMMENT>"*" { ; }
|
|
|
|
|
<CCOMMENT>"*"+"/" { BEGIN(save_state); }
|
|
|
|
|
|
2009-02-25 01:47:46 +01:00
|
|
|
/* Catch any invalid tokens and flagged them as an error. */
|
|
|
|
|
<HEX,BIN>. { readmem_error_token = yytext; return MEM_ERROR; }
|
|
|
|
|
|
1999-12-15 05:01:14 +01:00
|
|
|
%%
|
|
|
|
|
static unsigned word_width = 0;
|
|
|
|
|
static struct t_vpi_vecval*vecval = 0;
|
|
|
|
|
|
2014-07-08 21:12:54 +02:00
|
|
|
static void make_addr(void)
|
2001-12-01 03:40:10 +01:00
|
|
|
{
|
2009-12-10 21:49:39 +01:00
|
|
|
sscanf(yytext+1, "%x", (unsigned int*)&vecval->aval);
|
2001-12-01 03:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-08 21:12:54 +02:00
|
|
|
static void make_hex_value(void)
|
1999-12-15 05:01:14 +01:00
|
|
|
{
|
|
|
|
|
char*beg = yytext;
|
|
|
|
|
char*end = beg + strlen(beg);
|
|
|
|
|
struct t_vpi_vecval*cur;
|
|
|
|
|
int idx;
|
|
|
|
|
int width = 0, word_max = word_width;
|
|
|
|
|
|
|
|
|
|
for (idx = 0, cur = vecval ; idx < word_max ; idx += 32, cur += 1) {
|
|
|
|
|
cur->aval = 0;
|
|
|
|
|
cur->bval = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur = vecval;
|
|
|
|
|
while ((width < word_max) && (end > beg)) {
|
2001-07-25 05:10:48 +02:00
|
|
|
int aval = 0;
|
|
|
|
|
int bval = 0;
|
1999-12-15 05:01:14 +01:00
|
|
|
|
|
|
|
|
end -= 1;
|
|
|
|
|
if (*end == '_') continue;
|
|
|
|
|
switch (*end) {
|
|
|
|
|
case '0':
|
|
|
|
|
case '1':
|
|
|
|
|
case '2':
|
|
|
|
|
case '3':
|
|
|
|
|
case '4':
|
|
|
|
|
case '5':
|
|
|
|
|
case '6':
|
|
|
|
|
case '7':
|
|
|
|
|
case '8':
|
|
|
|
|
case '9':
|
|
|
|
|
aval = *end - '0';
|
|
|
|
|
break;
|
|
|
|
|
case 'a':
|
|
|
|
|
case 'b':
|
|
|
|
|
case 'c':
|
|
|
|
|
case 'd':
|
|
|
|
|
case 'e':
|
|
|
|
|
case 'f':
|
|
|
|
|
aval = *end - 'a' + 10;
|
|
|
|
|
break;
|
|
|
|
|
case 'A':
|
|
|
|
|
case 'B':
|
|
|
|
|
case 'C':
|
|
|
|
|
case 'D':
|
|
|
|
|
case 'E':
|
|
|
|
|
case 'F':
|
|
|
|
|
aval = *end - 'A' + 10;
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
case 'X':
|
|
|
|
|
aval = 15;
|
|
|
|
|
bval = 15;
|
|
|
|
|
break;
|
|
|
|
|
case 'z':
|
|
|
|
|
case 'Z':
|
|
|
|
|
bval = 15;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur->aval |= aval << width;
|
|
|
|
|
cur->bval |= bval << width;
|
|
|
|
|
width += 4;
|
|
|
|
|
if (width == 32) {
|
|
|
|
|
cur += 1;
|
|
|
|
|
width = 0;
|
|
|
|
|
word_max -= 32;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 21:12:54 +02:00
|
|
|
static void make_bin_value(void)
|
1999-12-15 05:01:14 +01:00
|
|
|
{
|
|
|
|
|
char*beg = yytext;
|
|
|
|
|
char*end = beg + strlen(beg);
|
|
|
|
|
struct t_vpi_vecval*cur;
|
|
|
|
|
int idx;
|
|
|
|
|
int width = 0, word_max = word_width;
|
|
|
|
|
|
|
|
|
|
for (idx = 0, cur = vecval ; idx < word_max ; idx += 32, cur += 1) {
|
|
|
|
|
cur->aval = 0;
|
|
|
|
|
cur->bval = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur = vecval;
|
|
|
|
|
while ((width < word_max) && (end > beg)) {
|
2001-07-25 05:10:48 +02:00
|
|
|
int aval = 0;
|
|
|
|
|
int bval = 0;
|
1999-12-15 05:01:14 +01:00
|
|
|
|
|
|
|
|
end -= 1;
|
|
|
|
|
if (*end == '_') continue;
|
|
|
|
|
switch (*end) {
|
|
|
|
|
case '0':
|
|
|
|
|
case '1':
|
|
|
|
|
aval = *end - '0';
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
case 'X':
|
|
|
|
|
aval = 1;
|
|
|
|
|
bval = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'z':
|
|
|
|
|
case 'Z':
|
|
|
|
|
bval = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur->aval |= aval << width;
|
|
|
|
|
cur->bval |= bval << width;
|
|
|
|
|
width += 1;
|
|
|
|
|
if (width == 32) {
|
|
|
|
|
cur += 1;
|
|
|
|
|
width = 0;
|
|
|
|
|
word_max -= 32;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sys_readmem_start_file(FILE*in, int bin_flag,
|
|
|
|
|
unsigned width, struct t_vpi_vecval *vv)
|
|
|
|
|
{
|
2000-03-05 21:01:19 +01:00
|
|
|
yyrestart(in);
|
1999-12-15 05:01:14 +01:00
|
|
|
BEGIN(bin_flag? BIN : HEX);
|
|
|
|
|
word_width = width;
|
|
|
|
|
vecval = vv;
|
|
|
|
|
}
|
2009-01-24 01:04:44 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Modern version of flex (>=2.5.9) can clean up the scanner data.
|
|
|
|
|
*/
|
2014-07-08 21:12:54 +02:00
|
|
|
void destroy_readmem_lexor(void)
|
2009-01-24 01:04:44 +01:00
|
|
|
{
|
|
|
|
|
# ifdef FLEX_SCANNER
|
|
|
|
|
# if YY_FLEX_MAJOR_VERSION >= 2 && YY_FLEX_MINOR_VERSION >= 5
|
2017-11-17 04:03:34 +01:00
|
|
|
# if YY_FLEX_MINOR_VERSION > 5 || defined(YY_FLEX_SUBMINOR_VERSION) && YY_FLEX_SUBMINOR_VERSION >= 9
|
2009-01-24 01:04:44 +01:00
|
|
|
yylex_destroy();
|
|
|
|
|
# endif
|
|
|
|
|
# endif
|
|
|
|
|
# endif
|
|
|
|
|
}
|