Convert real array index to integer.
This patch converts a constant real index to an integer value when defining an array. This can happen when using 2**8 which returns a real value since the operands are signed.
This commit is contained in:
parent
70c5c9fe14
commit
f8caebd076
45
elab_sig.cc
45
elab_sig.cc
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000-2007 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2000-2008 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
|
||||
|
|
@ -35,6 +35,32 @@
|
|||
# include "util.h"
|
||||
# include "ivl_assert.h"
|
||||
|
||||
static bool get_const_argument(NetExpr*exp, verinum&res)
|
||||
{
|
||||
switch (exp->expr_type()) {
|
||||
case IVL_VT_REAL: {
|
||||
NetECReal*cv = dynamic_cast<NetECReal*>(exp);
|
||||
if (cv == 0) return false;
|
||||
verireal tmp = cv->value();
|
||||
res = verinum(tmp.as_long());
|
||||
break;
|
||||
}
|
||||
|
||||
case IVL_VT_BOOL:
|
||||
case IVL_VT_LOGIC: {
|
||||
NetEConst*cv = dynamic_cast<NetEConst*>(exp);
|
||||
if (cv == 0) return false;
|
||||
res = cv->value();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
assert(0);;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Statement::elaborate_sig(Design*des, NetScope*scope) const
|
||||
{
|
||||
}
|
||||
|
|
@ -715,10 +741,14 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
NetEConst*lcon = dynamic_cast<NetEConst*> (lexp);
|
||||
NetEConst*rcon = dynamic_cast<NetEConst*> (rexp);
|
||||
bool const_flag = true;
|
||||
verinum lval, rval;
|
||||
const_flag &= get_const_argument(lexp, lval);
|
||||
const_flag &= get_const_argument(rexp, rval);
|
||||
delete rexp;
|
||||
delete lexp;
|
||||
|
||||
if ((lcon == 0) || (rcon == 0)) {
|
||||
if (!const_flag) {
|
||||
cerr << get_fileline() << ": internal error: The indices "
|
||||
<< "are not constant for array ``"
|
||||
<< name_ << "''." << endl;
|
||||
|
|
@ -726,12 +756,6 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
verinum lval = lcon->value();
|
||||
verinum rval = rcon->value();
|
||||
|
||||
delete lexp;
|
||||
delete rexp;
|
||||
|
||||
array_dimensions = 1;
|
||||
array_s0 = lval.as_long();
|
||||
array_e0 = rval.as_long();
|
||||
|
|
@ -807,4 +831,3 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
|
|||
|
||||
return sig;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue