1999-12-15 05:01:14 +01:00
|
|
|
|
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
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1999 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
|
|
|
|
|
#ident "$Id: sys_readmem_lex.lex,v 1.8 2003/08/26 16:26:02 steve Exp $"
|
2000-02-23 03:56:53 +01:00
|
|
|
#endif
|
1999-12-15 05:01:14 +01:00
|
|
|
# include "sys_readmem_lex.h"
|
|
|
|
|
# include <string.h>
|
2001-12-01 03:40:10 +01:00
|
|
|
static void make_addr();
|
1999-12-15 05:01:14 +01:00
|
|
|
static void make_hex_value();
|
|
|
|
|
static void make_bin_value();
|
2003-02-09 06:07:06 +01:00
|
|
|
|
|
|
|
|
static int save_state;
|
|
|
|
|
|
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); }
|
|
|
|
|
|
1999-12-15 05:01:14 +01:00
|
|
|
%%
|
|
|
|
|
static unsigned word_width = 0;
|
|
|
|
|
static struct t_vpi_vecval*vecval = 0;
|
|
|
|
|
|
2001-12-01 03:40:10 +01:00
|
|
|
static void make_addr()
|
|
|
|
|
{
|
|
|
|
|
sscanf(yytext+1, "%x", &vecval->aval);
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-15 05:01:14 +01:00
|
|
|
static void make_hex_value()
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void make_bin_value()
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|