Add lexical support for real numbers.
This commit is contained in:
parent
bcbd2abb8d
commit
430d7b22e4
|
|
@ -18,7 +18,7 @@
|
|||
# 59 Temple Place - Suite 330
|
||||
# Boston, MA 02111-1307, USA
|
||||
#
|
||||
#ident "$Id: Makefile.in,v 1.3 1999/05/08 20:37:59 steve Exp $"
|
||||
#ident "$Id: Makefile.in,v 1.4 1999/06/15 02:50:02 steve Exp $"
|
||||
#
|
||||
#
|
||||
SHELL = /bin/sh
|
||||
|
|
@ -54,8 +54,8 @@ TT = t-null.o t-verilog.o t-vvm.o t-xnf.o
|
|||
FF = nobufz.o propinit.o sigfold.o stupid.o xnfio.o
|
||||
|
||||
O = main.o cprop.o design_dump.o elaborate.o emit.o eval.o lexor.o mangle.o \
|
||||
netlist.o parse.o parse_misc.o pform.o pform_dump.o verinum.o target.o \
|
||||
targets.o Module.o PExpr.o PGate.o Statement.o $(FF) $(TT)
|
||||
netlist.o parse.o parse_misc.o pform.o pform_dump.o verinum.o verireal.o \
|
||||
target.o targets.o Module.o PExpr.o PGate.o Statement.o $(FF) $(TT)
|
||||
|
||||
Makefile: Makefile.in config.status
|
||||
./config.status
|
||||
|
|
@ -71,6 +71,8 @@ ivl: $O
|
|||
|
||||
lexor.o dep/lexor.d: lexor.cc parse.h
|
||||
|
||||
parse.o dep/parse.d: parse.cc
|
||||
|
||||
parse.h parse.cc: parse.y
|
||||
bison --verbose -t -p VL -d parse.y -o parse.cc
|
||||
mv parse.cc.h parse.h
|
||||
|
|
|
|||
6
PExpr.h
6
PExpr.h
|
|
@ -19,12 +19,13 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: PExpr.h,v 1.11 1999/06/10 04:03:52 steve Exp $"
|
||||
#ident "$Id: PExpr.h,v 1.12 1999/06/15 02:50:02 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <string>
|
||||
# include "netlist.h"
|
||||
# include "verinum.h"
|
||||
# include "verireal.h"
|
||||
# include "LineInfo.h"
|
||||
|
||||
class Design;
|
||||
|
|
@ -217,6 +218,9 @@ class PETernary : public PExpr {
|
|||
|
||||
/*
|
||||
* $Log: PExpr.h,v $
|
||||
* Revision 1.12 1999/06/15 02:50:02 steve
|
||||
* Add lexical support for real numbers.
|
||||
*
|
||||
* Revision 1.11 1999/06/10 04:03:52 steve
|
||||
* Add support for the Ternary operator,
|
||||
* Add support for repeat concatenation,
|
||||
|
|
|
|||
14
lexor.lex
14
lexor.lex
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: lexor.lex,v 1.22 1999/06/14 03:15:14 steve Exp $"
|
||||
#ident "$Id: lexor.lex,v 1.23 1999/06/15 02:50:02 steve Exp $"
|
||||
#endif
|
||||
|
||||
//# define YYSTYPE lexval
|
||||
|
|
@ -181,6 +181,17 @@ static verinum*make_unsized_hex(const char*txt);
|
|||
delete[]bits;
|
||||
return NUMBER; }
|
||||
|
||||
[0-9][0-9_]*\.[0-9][0-9_]*([Ee][+-]?[0-9][0-9_]*)? {
|
||||
yylval.realtime = new verireal(yytext);
|
||||
return REALTIME; }
|
||||
|
||||
[0-9][0-9_]*[Ee][+-]?[0-9][0-9_]* {
|
||||
yylval.realtime = new verireal(yytext);
|
||||
return REALTIME; }
|
||||
|
||||
`celldefine[ \t]*\n { yylloc.first_line += 1; }
|
||||
`endcelldefine[ \t]*\n { yylloc.first_line += 1; }
|
||||
|
||||
`timescale { BEGIN(PPTIMESCALE); }
|
||||
<PPTIMESCALE>. { ; }
|
||||
<PPTIMESCALE>\n {
|
||||
|
|
@ -317,6 +328,7 @@ static const struct { const char*name; int code; } key_table[] = {
|
|||
{ "tri1", K_tri1 },
|
||||
{ "triand", K_triand },
|
||||
{ "trior", K_trior },
|
||||
{ "trireg", K_trireg },
|
||||
{ "vectored", K_vectored },
|
||||
{ "wait", K_wait },
|
||||
{ "wand", K_wand },
|
||||
|
|
|
|||
42
parse.y
42
parse.y
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: parse.y,v 1.40 1999/06/13 17:30:23 steve Exp $"
|
||||
#ident "$Id: parse.y,v 1.41 1999/06/15 02:50:02 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "parse_misc.h"
|
||||
|
|
@ -60,10 +60,13 @@ extern void lex_end_table();
|
|||
list<Statement*>*statement_list;
|
||||
|
||||
verinum* number;
|
||||
|
||||
verireal* realtime;
|
||||
};
|
||||
|
||||
%token <text> IDENTIFIER PORTNAME SYSTEM_IDENTIFIER STRING
|
||||
%token <number> NUMBER
|
||||
%token <realtime> REALTIME
|
||||
%token K_LE K_GE K_EQ K_NE K_CEQ K_CNE K_LS K_RS
|
||||
%token K_LOR K_LAND K_NAND K_NOR K_NXOR
|
||||
%token K_always K_and K_assign K_begin K_buf K_bufif0 K_bufif1 K_case
|
||||
|
|
@ -80,7 +83,8 @@ extern void lex_end_table();
|
|||
%token K_small K_specify
|
||||
%token K_specparam K_strong0 K_strong1 K_supply0 K_supply1 K_table K_task
|
||||
%token K_time K_tran K_tranif0 K_tranif1 K_tri K_tri0 K_tri1 K_triand
|
||||
%token K_trior K_vectored K_wait K_wand K_weak0 K_weak1 K_while K_wire
|
||||
%token K_trior K_trireg K_vectored K_wait K_wand K_weak0 K_weak1
|
||||
%token K_while K_wire
|
||||
%token K_wor K_xnor K_xor
|
||||
|
||||
%token KK_attribute
|
||||
|
|
@ -188,6 +192,17 @@ case_items
|
|||
}
|
||||
;
|
||||
|
||||
charge_strength
|
||||
: '(' K_small ')'
|
||||
| '(' K_medium ')'
|
||||
| '(' K_large ')'
|
||||
;
|
||||
|
||||
charge_strength_opt
|
||||
: charge_strength
|
||||
|
|
||||
;
|
||||
|
||||
delay
|
||||
: '#' delay_value
|
||||
{ $$ = $2;
|
||||
|
|
@ -507,15 +522,16 @@ expression_list
|
|||
|
||||
expr_primary
|
||||
: NUMBER
|
||||
{ if ($1 == 0) {
|
||||
yyerror(@1, "XXXX No number value in primary?");
|
||||
$$ = 0;
|
||||
} else {
|
||||
PENumber*tmp = new PENumber($1);
|
||||
tmp->set_file(@1.text);
|
||||
tmp->set_lineno(@1.first_line);
|
||||
$$ = tmp;
|
||||
}
|
||||
{ assert($1);
|
||||
PENumber*tmp = new PENumber($1);
|
||||
tmp->set_file(@1.text);
|
||||
tmp->set_lineno(@1.first_line);
|
||||
$$ = tmp;
|
||||
}
|
||||
| REALTIME
|
||||
{ yyerror(@1, "Sorry, real constants not supported.");
|
||||
delete $1;
|
||||
$$ = 0;
|
||||
}
|
||||
| STRING
|
||||
{ PEString*tmp = new PEString(*$1);
|
||||
|
|
@ -853,6 +869,10 @@ module_item
|
|||
}
|
||||
delete $3;
|
||||
}
|
||||
| K_trireg charge_strength_opt range_opt delay_opt list_of_variables ';'
|
||||
{ yyerror(@1, "Sorry, trireg nets not supported.");
|
||||
delete $3;
|
||||
}
|
||||
| port_type range_opt list_of_variables ';'
|
||||
{ pform_set_port_type($3, $1);
|
||||
if ($2) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: verireal.cc,v 1.1 1999/06/15 02:50:02 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "verireal.h"
|
||||
# include <ctype.h>
|
||||
# include <assert.h>
|
||||
|
||||
verireal::verireal()
|
||||
{
|
||||
sign_ = false;
|
||||
mant_ = 0;
|
||||
exp10_ = 0;
|
||||
}
|
||||
|
||||
verireal::verireal(const char*txt)
|
||||
{
|
||||
mant_ = 0;
|
||||
sign_ = false;
|
||||
exp10_ = 0;
|
||||
|
||||
const char*ptr = txt;
|
||||
for ( ; *ptr ; ptr += 1) {
|
||||
if (*ptr == '.') break;
|
||||
if (*ptr == 'e') break;
|
||||
if (*ptr == 'E') break;
|
||||
if (*ptr == '_') continue;
|
||||
|
||||
assert(isdigit(*ptr));
|
||||
|
||||
mant_ *= 10;
|
||||
mant_ += *ptr - '0';
|
||||
}
|
||||
|
||||
if (*ptr == '.') {
|
||||
ptr += 1;
|
||||
for ( ; *ptr ; ptr += 1) {
|
||||
if (*ptr == 'e') break;
|
||||
if (*ptr == 'E') break;
|
||||
if (*ptr == '_') continue;
|
||||
|
||||
assert(isdigit(*ptr));
|
||||
|
||||
mant_ *= 10;
|
||||
mant_ += *ptr - '0';
|
||||
exp10_ -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*ptr == 'e') || (*ptr == 'E')) {
|
||||
ptr += 1;
|
||||
long tmp = 0;
|
||||
bool sflag = false;
|
||||
if (*ptr == '+') {ptr += 1; sflag = false;}
|
||||
if (*ptr == '-') {ptr += 1; sflag = true;}
|
||||
|
||||
for ( ; *ptr ; ptr += 1) {
|
||||
if (*ptr == '_') continue;
|
||||
assert(isdigit(*ptr));
|
||||
tmp *= 10;
|
||||
tmp += *ptr - '0';
|
||||
}
|
||||
|
||||
exp10_ += sflag? -tmp : +tmp;
|
||||
}
|
||||
|
||||
assert(*ptr == 0);
|
||||
}
|
||||
|
||||
|
||||
verireal::~verireal()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* $Log: verireal.cc,v $
|
||||
* Revision 1.1 1999/06/15 02:50:02 steve
|
||||
* Add lexical support for real numbers.
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef __verireal_H
|
||||
#define __verireal_H
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: verireal.h,v 1.1 1999/06/15 02:50:02 steve Exp $"
|
||||
#endif
|
||||
|
||||
class verireal {
|
||||
|
||||
public:
|
||||
explicit verireal();
|
||||
explicit verireal(const char*text);
|
||||
~verireal();
|
||||
|
||||
private:
|
||||
bool sign_;
|
||||
unsigned long mant_;
|
||||
signed int exp10_;
|
||||
};
|
||||
|
||||
/*
|
||||
* $Log: verireal.h,v $
|
||||
* Revision 1.1 1999/06/15 02:50:02 steve
|
||||
* Add lexical support for real numbers.
|
||||
*
|
||||
*/
|
||||
#endif
|
||||
Loading…
Reference in New Issue