More unary operators.
This commit is contained in:
parent
6a823cde59
commit
0d210c90e5
94
lexor.lex
94
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.20 1999/06/12 23:16:08 steve Exp $"
|
||||
#ident "$Id: lexor.lex,v 1.21 1999/06/13 17:30:23 steve Exp $"
|
||||
#endif
|
||||
|
||||
//# define YYSTYPE lexval
|
||||
|
|
@ -81,6 +81,11 @@ static verinum*make_unsized_hex(const char*txt);
|
|||
"!==" { return K_CNE; }
|
||||
"||" { return K_LOR; }
|
||||
"&&" { return K_LAND; }
|
||||
"~|" { return K_NOR; }
|
||||
"~^" { return K_NXOR; }
|
||||
"^~" { return K_NXOR; }
|
||||
"~&" { return K_NAND; }
|
||||
|
||||
|
||||
[}{;:\[\],()#=.@&!?<>%|^~+*/-] { return yytext[0]; }
|
||||
|
||||
|
|
@ -453,7 +458,43 @@ static verinum*make_sized_octal(const char*txt)
|
|||
|
||||
static verinum*make_unsized_octal(const char*txt)
|
||||
{
|
||||
assert(0);
|
||||
const char*ptr = txt;
|
||||
assert(*ptr == '\'');
|
||||
ptr += 1;
|
||||
assert(tolower(*ptr) == 'o');
|
||||
ptr += 1;
|
||||
|
||||
unsigned size = 3 * strlen(ptr);
|
||||
verinum::V*bits = new verinum::V[size];
|
||||
|
||||
unsigned idx = size;
|
||||
while (*ptr) {
|
||||
unsigned val;
|
||||
switch (ptr[0]) {
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
val = *ptr - '0';
|
||||
bits[--idx] = (val&4) ? verinum::V1 : verinum::V0;
|
||||
bits[--idx] = (val&2) ? verinum::V1 : verinum::V0;
|
||||
bits[--idx] = (val&1) ? verinum::V1 : verinum::V0;
|
||||
break;
|
||||
case 'x':
|
||||
bits[--idx] = verinum::Vx;
|
||||
bits[--idx] = verinum::Vx;
|
||||
bits[--idx] = verinum::Vx;
|
||||
break;
|
||||
case 'z':
|
||||
bits[--idx] = verinum::Vz;
|
||||
bits[--idx] = verinum::Vz;
|
||||
bits[--idx] = verinum::Vz;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
ptr += 1;
|
||||
}
|
||||
|
||||
return new verinum(bits, size);
|
||||
}
|
||||
|
||||
static verinum*make_sized_hex(const char*txt)
|
||||
|
|
@ -527,7 +568,54 @@ static verinum*make_sized_hex(const char*txt)
|
|||
|
||||
static verinum*make_unsized_hex(const char*txt)
|
||||
{
|
||||
assert(0);
|
||||
const char*ptr = txt;
|
||||
assert(*ptr == '\'');
|
||||
ptr += 1;
|
||||
assert(tolower(*ptr) == 'h');
|
||||
ptr += 1;
|
||||
|
||||
unsigned size = 4 * strlen(ptr);
|
||||
verinum::V*bits = new verinum::V[size];
|
||||
|
||||
unsigned idx = size;
|
||||
while (*ptr) {
|
||||
unsigned val;
|
||||
switch (ptr[0]) {
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
val = *ptr - '0';
|
||||
bits[--idx] = (val&8) ? verinum::V1 : verinum::V0;
|
||||
bits[--idx] = (val&4) ? verinum::V1 : verinum::V0;
|
||||
bits[--idx] = (val&2) ? verinum::V1 : verinum::V0;
|
||||
bits[--idx] = (val&1) ? verinum::V1 : verinum::V0;
|
||||
break;
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
val = tolower(*ptr) - 'a' + 10;
|
||||
bits[--idx] = (val&8) ? verinum::V1 : verinum::V0;
|
||||
bits[--idx] = (val&4) ? verinum::V1 : verinum::V0;
|
||||
bits[--idx] = (val&2) ? verinum::V1 : verinum::V0;
|
||||
bits[--idx] = (val&1) ? verinum::V1 : verinum::V0;
|
||||
break;
|
||||
case 'x':
|
||||
bits[--idx] = verinum::Vx;
|
||||
bits[--idx] = verinum::Vx;
|
||||
bits[--idx] = verinum::Vx;
|
||||
bits[--idx] = verinum::Vx;
|
||||
break;
|
||||
case 'z':
|
||||
bits[--idx] = verinum::Vz;
|
||||
bits[--idx] = verinum::Vz;
|
||||
bits[--idx] = verinum::Vz;
|
||||
bits[--idx] = verinum::Vz;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
ptr += 1;
|
||||
}
|
||||
|
||||
return new verinum(bits, size);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
12
netlist.h
12
netlist.h
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: netlist.h,v 1.38 1999/06/13 16:30:06 steve Exp $"
|
||||
#ident "$Id: netlist.h,v 1.39 1999/06/13 17:30:23 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -993,6 +993,13 @@ class NetEConst : public NetExpr {
|
|||
* ~ -- Bit-wise negation
|
||||
* ! -- Logical negation
|
||||
* & -- Reduction AND
|
||||
* | -- Reduction OR
|
||||
* ^ -- Reduction XOR
|
||||
* + --
|
||||
* - --
|
||||
* A -- Reduciton NAND (~&)
|
||||
* N -- Reduciton NOR (~|)
|
||||
* X -- Reduciton NXOR (~^ or ^~)
|
||||
*/
|
||||
class NetEUnary : public NetExpr {
|
||||
|
||||
|
|
@ -1245,6 +1252,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
|
|||
|
||||
/*
|
||||
* $Log: netlist.h,v $
|
||||
* Revision 1.39 1999/06/13 17:30:23 steve
|
||||
* More unary operators.
|
||||
*
|
||||
* Revision 1.38 1999/06/13 16:30:06 steve
|
||||
* Unify the NetAssign constructors a bit.
|
||||
*
|
||||
|
|
|
|||
28
parse.y
28
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.39 1999/06/12 23:16:37 steve Exp $"
|
||||
#ident "$Id: parse.y,v 1.40 1999/06/13 17:30:23 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "parse_misc.h"
|
||||
|
|
@ -65,7 +65,7 @@ extern void lex_end_table();
|
|||
%token <text> IDENTIFIER PORTNAME SYSTEM_IDENTIFIER STRING
|
||||
%token <number> NUMBER
|
||||
%token K_LE K_GE K_EQ K_NE K_CEQ K_CNE K_LS K_RS
|
||||
%token K_LOR K_LAND
|
||||
%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
|
||||
%token K_casex K_casez K_cmos K_deassign K_default K_defparam K_disable
|
||||
%token K_edge K_else K_end K_endcase K_endfunction K_endmodule
|
||||
|
|
@ -297,11 +297,7 @@ expression
|
|||
: expr_primary
|
||||
{ $$ = $1; }
|
||||
| '+' expr_primary %prec UNARY_PREC
|
||||
{ PEUnary*tmp = new PEUnary('+', $2);
|
||||
tmp->set_file(@2.text);
|
||||
tmp->set_lineno(@2.first_line);
|
||||
$$ = tmp;
|
||||
}
|
||||
{ $$ = $2; }
|
||||
| '-' expr_primary %prec UNARY_PREC
|
||||
{ PEUnary*tmp = new PEUnary('-', $2);
|
||||
tmp->set_file(@2.text);
|
||||
|
|
@ -338,6 +334,24 @@ expression
|
|||
tmp->set_lineno(@2.first_line);
|
||||
$$ = tmp;
|
||||
}
|
||||
| K_NAND expr_primary %prec UNARY_PREC
|
||||
{ PEUnary*tmp = new PEUnary('A', $2);
|
||||
tmp->set_file(@2.text);
|
||||
tmp->set_lineno(@2.first_line);
|
||||
$$ = tmp;
|
||||
}
|
||||
| K_NOR expr_primary %prec UNARY_PREC
|
||||
{ PEUnary*tmp = new PEUnary('N', $2);
|
||||
tmp->set_file(@2.text);
|
||||
tmp->set_lineno(@2.first_line);
|
||||
$$ = tmp;
|
||||
}
|
||||
| K_NXOR expr_primary %prec UNARY_PREC
|
||||
{ PEUnary*tmp = new PEUnary('X', $2);
|
||||
tmp->set_file(@2.text);
|
||||
tmp->set_lineno(@2.first_line);
|
||||
$$ = tmp;
|
||||
}
|
||||
| expression '^' expression
|
||||
{ PEBinary*tmp = new PEBinary('^', $1, $3);
|
||||
tmp->set_file(@2.text);
|
||||
|
|
|
|||
Loading…
Reference in New Issue