Skip to content
Browse files

Fix some -Wextra warnings and some other bug fixes/enhancements.

This patch covers more than it should. It removes many of the -Wextra
warnings in the main ivl directory. It also makes some minor code
improvements, adds support for constant logicals in eval_tree (&&/||),
adds support for correctly sign extending === and !==, it starts to
standardize the eval_tree debug messages and fixes a strength bug
in the target interface (found with -Wextra). The rest of the warnings
and eval_tree() rework will need to come as a second patch.
  • Loading branch information...
1 parent 57f9130 commit bb5ca97f2d3bb34540c605638cd3b858ced5412a @caryr caryr committed with
Showing with 574 additions and 461 deletions.
  1. +4 −2 Makefile.in
  2. +9 −8 PExpr.cc
  3. +3 −0 PGate.h
  4. +7 −7 cprop.cc
  5. +45 −32 elab_expr.cc
  6. +1 −3 elab_lval.cc
  7. +1 −1 elab_pexpr.cc
  8. +4 −6 elab_scope.cc
  9. +7 −4 elab_sig.cc
  10. +5 −1 elaborate.cc
  11. +3 −3 emit.cc
  12. +383 −283 eval_tree.cc
  13. +7 −8 expr_synth.cc
  14. +1 −1 functor.cc
  15. +2 −1 iverilog-vpi.sh
  16. +6 −0 lexor_keyword.gperf
  17. +12 −12 net_nex_input.cc
  18. +4 −4 net_nex_output.cc
  19. +3 −3 netlist.h
  20. +6 −6 netmisc.cc
  21. +4 −0 netmisc.h
  22. +2 −2 nodangle.cc
  23. +12 −25 set_width.cc
  24. +7 −8 syn-rules.y
  25. +24 −29 synth2.cc
  26. +2 −2 t-dll.cc
  27. +7 −7 target.cc
  28. +1 −1 verinum.cc
  29. +2 −2 verinum.h
View
6 Makefile.in
@@ -83,7 +83,8 @@ INCLUDE_PATH = -I. -I$(srcdir)
endif
CPPFLAGS = @DEFS@ $(INCLUDE_PATH) @CPPFLAGS@
-CXXFLAGS = @WARNING_FLAGS@ @CXXFLAGS@
+CFLAGS = @WARNING_FLAGS@ @CFLAGS@
+CXXFLAGS = @WARNING_FLAGS@ @WARNING_FLAGS_CXX@ @CXXFLAGS@
PICFLAGS = @PICFLAG@
LDFLAGS = @rdynamic@ @LDFLAGS@
@@ -211,7 +212,8 @@ iverilog-vpi: $(srcdir)/iverilog-vpi.sh Makefile
-e 's;@SUFFIX@;$(suffix);' \
-e 's;@IVCC@;$(CC);' \
-e 's;@IVCXX@;$(CXX);' \
- -e 's;@IVCFLAGS@;$(CXXFLAGS);' \
+ -e 's;@IVCFLAGS@;$(CFLAGS);' \
+ -e 's;@IVCXXFLAGS@;$(CXXFLAGS);' \
-e 's;@INCLUDEDIR@;$(includedir);' \
-e 's;@LIBDIR@;@libdir@;' $< > $@
chmod +x $@
View
17 PExpr.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998-2008,2010 Stephen Williams <steve@icarus.com>
+ * Copyright (c) 1998-2010 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
@@ -38,7 +38,7 @@ PExpr::~PExpr()
{
}
-void PExpr::declare_implicit_nets(LexicalScope*scope, NetNet::Type type)
+void PExpr::declare_implicit_nets(LexicalScope*, NetNet::Type)
{
}
@@ -52,18 +52,19 @@ bool PExpr::is_the_same(const PExpr*that) const
return typeid(this) == typeid(that);
}
-NetNet* PExpr::elaborate_lnet(Design*des, NetScope*) const
+NetNet* PExpr::elaborate_lnet(Design*, NetScope*) const
{
- cerr << get_fileline() << ": error: expression not valid in assign l-value: "
- << *this << endl;
+ cerr << get_fileline() << ": error: "
+ << "expression not valid in assign l-value: "
+ << *this << endl;
return 0;
}
-NetNet* PExpr::elaborate_bi_net(Design*des, NetScope*) const
+NetNet* PExpr::elaborate_bi_net(Design*, NetScope*) const
{
cerr << get_fileline() << ": error: "
- << "expression not valid as argument to inout port: "
- << *this << endl;
+ << "expression not valid as argument to inout port: "
+ << *this << endl;
return 0;
}
View
3 PGate.h
@@ -237,7 +237,10 @@ class PGModule : public PGate {
void elaborate_scope_mod_(Design*des, Module*mod, NetScope*sc) const;
void elaborate_scope_mod_instances_(Design*des, Module*mod, NetScope*sc) const;
bool elaborate_sig_mod_(Design*des, NetScope*scope, Module*mod) const;
+ // Not currently used.
+#if 0
bool elaborate_sig_udp_(Design*des, NetScope*scope, PUdp*udp) const;
+#endif
NetNet*resize_net_to_port_(Design*des, NetScope*scope,
NetNet*sig, unsigned port_wid,
View
14 cprop.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998-2009 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 1998-2010 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
@@ -48,11 +48,11 @@ struct cprop_functor : public functor_t {
virtual void lpm_mux(Design*des, NetMux*obj);
};
-void cprop_functor::signal(Design*des, NetNet*obj)
+void cprop_functor::signal(Design*, NetNet*)
{
}
-void cprop_functor::lpm_add_sub(Design*des, NetAddSub*obj)
+void cprop_functor::lpm_add_sub(Design*, NetAddSub*)
{
}
@@ -70,11 +70,11 @@ void cprop_functor::lpm_compare(Design*des, NetCompare*obj)
}
}
-void cprop_functor::lpm_compare_eq_(Design*des, NetCompare*obj)
+void cprop_functor::lpm_compare_eq_(Design*, NetCompare*)
{
}
-void cprop_functor::lpm_ff(Design*des, NetFF*obj)
+void cprop_functor::lpm_ff(Design*, NetFF*obj)
{
// Look for and count unlinked FF outputs. Note that if the
// Data and Q pins are connected together, they can be removed
@@ -91,7 +91,7 @@ void cprop_functor::lpm_ff(Design*des, NetFF*obj)
}
}
-void cprop_functor::lpm_logic(Design*des, NetLogic*obj)
+void cprop_functor::lpm_logic(Design*, NetLogic*)
{
}
@@ -167,7 +167,7 @@ struct nexus_info_s {
unsigned out;
};
-void cprop_dc_functor::lpm_const(Design*des, NetConst*obj)
+void cprop_dc_functor::lpm_const(Design*, NetConst*obj)
{
// 'bz constant values drive high impedance to whatever is
// connected to it. In other words, it is a noop. But that is
View
77 elab_expr.cc
@@ -127,8 +127,8 @@ NetExpr* elaborate_rval_expr(Design*des, NetScope*scope,
* The default behavior for the test_width method is to just return the
* minimum width that is passed in.
*/
-unsigned PExpr::test_width(Design*des, NetScope*scope,
- unsigned min, unsigned lval,
+unsigned PExpr::test_width(Design*, NetScope*,
+ unsigned min, unsigned,
ivl_variable_type_t&, bool&)
{
if (debug_elaborate) {
@@ -226,9 +226,12 @@ unsigned PEBinary::test_width(Design*des, NetScope*scope,
break;
}
- if (type_is_vectorable(expr_type_))
+ if (type_is_vectorable(expr_type_)) {
+ // We don't use (need?) lval so make sure the minimum width
+ // is greater than or equal to the the L-value width.
+ assert(min >= lval);
expr_width_ = min;
- else
+ } else
expr_width_ = 1;
expr_type__ = expr_type_;
@@ -447,7 +450,7 @@ NetExpr* PEBinary::elaborate_expr_base_bits_(Design*des,
NetExpr* PEBinary::elaborate_expr_base_div_(Design*des,
NetExpr*lp, NetExpr*rp,
- int expr_wid, bool is_pexpr) const
+ int expr_wid, bool) const
{
/* The % operator does not support real arguments in
baseline Verilog. But we allow it in our extended
@@ -737,7 +740,7 @@ NetExpr* PEBinary::elaborate_expr_base_rshift_(Design*des,
return tmp;
}
-NetExpr* PEBinary::elaborate_expr_base_mult_(Design*des,
+NetExpr* PEBinary::elaborate_expr_base_mult_(Design*,
NetExpr*lp, NetExpr*rp,
int expr_wid, bool is_pexpr) const
{
@@ -800,7 +803,7 @@ NetExpr* PEBinary::elaborate_expr_base_mult_(Design*des,
return tmp;
}
-NetExpr* PEBinary::elaborate_expr_base_add_(Design*des,
+NetExpr* PEBinary::elaborate_expr_base_add_(Design*,
NetExpr*lp, NetExpr*rp,
int expr_wid, bool is_pexpr) const
{
@@ -888,7 +891,7 @@ unsigned PEBComp::test_width(Design*des, NetScope*scope, unsigned, unsigned,
}
NetExpr* PEBComp::elaborate_expr(Design*des, NetScope*scope,
- int expr_width_dummy, bool sys_task_arg) const
+ int, bool) const
{
assert(left_);
assert(right_);
@@ -943,10 +946,10 @@ NetExpr* PEBComp::elaborate_expr(Design*des, NetScope*scope,
return tmp;
}
-unsigned PEBLogic::test_width(Design*des, NetScope*scope,
- unsigned min, unsigned lval,
+unsigned PEBLogic::test_width(Design*, NetScope*,
+ unsigned, unsigned,
ivl_variable_type_t&expr_type_out,
- bool&unsized_flag)
+ bool&)
{
expr_type_ = IVL_VT_LOGIC;
expr_width_ = 1;
@@ -955,7 +958,7 @@ unsigned PEBLogic::test_width(Design*des, NetScope*scope,
}
NetExpr*PEBLogic::elaborate_expr(Design*des, NetScope*scope,
- int expr_width_dummp, bool sys_task_arg) const
+ int, bool) const
{
assert(left_);
assert(right_);
@@ -1038,7 +1041,7 @@ unsigned PEBLeftWidth::test_width(Design*des, NetScope*scope,
}
NetExpr*PEBLeftWidth::elaborate_expr(Design*des, NetScope*scope,
- int expr_wid, bool sys_task_arg) const
+ int expr_wid, bool) const
{
assert(left_);
assert(right_);
@@ -1065,7 +1068,7 @@ NetExpr*PEBLeftWidth::elaborate_expr(Design*des, NetScope*scope,
return elaborate_expr_leaf(des, lp, rp, expr_wid);
}
-NetExpr*PEBPower::elaborate_expr_leaf(Design*des, NetExpr*lp, NetExpr*rp,
+NetExpr*PEBPower::elaborate_expr_leaf(Design*, NetExpr*lp, NetExpr*rp,
int expr_wid) const
{
if (debug_elaborate) {
@@ -1129,6 +1132,9 @@ unsigned PECallFunction::test_width_sfunc_(Design*des, NetScope*scope,
<< " argument width = " << expr_width_
<< ", result width = " << min << "." << endl;
+ // We don't use (need?) lval so make sure the minimum width
+ // is greater than or equal to the the L-value width.
+ assert(min >= lval);
return min;
}
@@ -1610,7 +1616,7 @@ NetExpr* PECallFunction::elaborate_expr(Design*des, NetScope*scope,
}
unsigned PEConcat::test_width(Design*des, NetScope*scope,
- unsigned min, unsigned lval,
+ unsigned, unsigned,
ivl_variable_type_t&expr_type__,
bool&unsized_flag)
{
@@ -1807,8 +1813,8 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope,
*
* Absent any better idea, we call all real valued results a width of 1.
*/
-unsigned PEFNumber::test_width(Design*des, NetScope*scope,
- unsigned min, unsigned lval,
+unsigned PEFNumber::test_width(Design*, NetScope*,
+ unsigned, unsigned,
ivl_variable_type_t&expr_type__,
bool&unsized_flag)
{
@@ -1820,7 +1826,7 @@ unsigned PEFNumber::test_width(Design*des, NetScope*scope,
return 1;
}
-NetExpr* PEFNumber::elaborate_expr(Design*des, NetScope*scope, int, bool) const
+NetExpr* PEFNumber::elaborate_expr(Design*, NetScope*, int, bool) const
{
NetECReal*tmp = new NetECReal(*value_);
tmp->set_line(*this);
@@ -1953,7 +1959,7 @@ NetExpr* PEIdent::calculate_up_do_base_(Design*des, NetScope*scope) const
return tmp;
}
-bool PEIdent::calculate_param_range_(Design*des, NetScope*scope,
+bool PEIdent::calculate_param_range_(Design*, NetScope*,
const NetExpr*par_msb, long&par_msv,
const NetExpr*par_lsb, long&par_lsv,
long length) const
@@ -2092,7 +2098,7 @@ unsigned PEIdent::test_width(Design*des, NetScope*scope,
// This is a parameter. If it is sized (meaning it was
// declared with range expressions) then the range
// expressions would have been caught above. So if we
- // got there there we know this is an unsized constant.
+ // got here then we know this is an unsized constant.
expr_width_ = par->expr_width();
unsized_flag = true;
return expr_width_;
@@ -2103,6 +2109,10 @@ unsigned PEIdent::test_width(Design*des, NetScope*scope,
expr_type_ = IVL_VT_NO_TYPE;
expr_width_ = min;
+ // We don't use (need?) lval so make sure the minimum width
+ // is greater than or equal to the the L-value width.
+ assert(min >= lval);
+
expr_type__ = expr_type_;
return min;
}
@@ -2301,7 +2311,7 @@ static verinum param_part_select_bits(const verinum&par_val, long wid,
NetExpr* PEIdent::elaborate_expr_param_part_(Design*des, NetScope*scope,
const NetExpr*par,
- NetScope*found_in,
+ NetScope*,
const NetExpr*par_msb,
const NetExpr*par_lsb) const
{
@@ -2425,7 +2435,7 @@ static void warn_param_ob(long par_msv, long par_lsv, bool defined,
NetExpr* PEIdent::elaborate_expr_param_idx_up_(Design*des, NetScope*scope,
const NetExpr*par,
- NetScope*found_in,
+ NetScope*,
const NetExpr*par_msb,
const NetExpr*par_lsb) const
{
@@ -2504,7 +2514,7 @@ NetExpr* PEIdent::elaborate_expr_param_idx_up_(Design*des, NetScope*scope,
NetExpr* PEIdent::elaborate_expr_param_idx_do_(Design*des, NetScope*scope,
const NetExpr*par,
- NetScope*found_in,
+ NetScope*,
const NetExpr*par_msb,
const NetExpr*par_lsb) const
{
@@ -2900,7 +2910,7 @@ NetExpr* PEIdent::elaborate_expr_net_word_(Design*des, NetScope*scope,
* Handle part selects of NetNet identifiers.
*/
NetExpr* PEIdent::elaborate_expr_net_part_(Design*des, NetScope*scope,
- NetESignal*net, NetScope*found_in) const
+ NetESignal*net, NetScope*) const
{
long msv, lsv;
bool parts_defined_flag;
@@ -3005,7 +3015,7 @@ NetExpr* PEIdent::elaborate_expr_net_part_(Design*des, NetScope*scope,
* Part select indexed up, i.e. net[<m> +: <l>]
*/
NetExpr* PEIdent::elaborate_expr_net_idx_up_(Design*des, NetScope*scope,
- NetESignal*net, NetScope*found_in) const
+ NetESignal*net, NetScope*) const
{
NetExpr*base = calculate_up_do_base_(des, scope);
@@ -3093,7 +3103,7 @@ NetExpr* PEIdent::elaborate_expr_net_idx_up_(Design*des, NetScope*scope,
* Part select indexed down, i.e. net[<m> -: <l>]
*/
NetExpr* PEIdent::elaborate_expr_net_idx_do_(Design*des, NetScope*scope,
- NetESignal*net, NetScope*found_in)const
+ NetESignal*net, NetScope*)const
{
NetExpr*base = calculate_up_do_base_(des, scope);
@@ -3177,7 +3187,7 @@ NetExpr* PEIdent::elaborate_expr_net_idx_do_(Design*des, NetScope*scope,
}
NetExpr* PEIdent::elaborate_expr_net_bit_(Design*des, NetScope*scope,
- NetESignal*net, NetScope*found_in) const
+ NetESignal*net, NetScope*) const
{
const name_component_t&name_tail = path_.back();
ivl_assert(*this, !name_tail.index.empty());
@@ -3345,7 +3355,7 @@ unsigned PENumber::test_width(Design*, NetScope*,
return use_wid;
}
-NetEConst* PENumber::elaborate_expr(Design*des, NetScope*,
+NetEConst* PENumber::elaborate_expr(Design*, NetScope*,
int expr_width__, bool) const
{
assert(value_);
@@ -3369,10 +3379,10 @@ NetEConst* PENumber::elaborate_expr(Design*des, NetScope*,
return tmp;
}
-unsigned PEString::test_width(Design*des, NetScope*scope,
+unsigned PEString::test_width(Design*, NetScope*,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type__,
- bool&unsized_flag)
+ bool&)
{
expr_type_ = IVL_VT_BOOL;
expr_width_ = text_? 8*strlen(text_) : 0;
@@ -3380,11 +3390,14 @@ unsigned PEString::test_width(Design*des, NetScope*scope,
expr_width_ = min;
expr_type__ = expr_type_;
+ // We don't use (need?) lval so make sure the minimum width
+ // is greater than or equal to the the L-value width.
+ assert(expr_width_ >= lval);
return expr_width_;
}
-NetEConst* PEString::elaborate_expr(Design*des, NetScope*,
- int expr_width_dummy, bool) const
+NetEConst* PEString::elaborate_expr(Design*, NetScope*,
+ int, bool) const
{
NetEConst*tmp = new NetEConst(value());
tmp->set_line(*this);
View
4 elab_lval.cc
@@ -66,9 +66,7 @@
* is to try to make a net elaboration, and see if the result is
* suitable for assignment.
*/
-NetAssign_* PExpr::elaborate_lval(Design*des,
- NetScope*scope,
- bool is_force) const
+NetAssign_* PExpr::elaborate_lval(Design*, NetScope*, bool) const
{
NetNet*ll = 0;
if (ll == 0) {
View
2 elab_pexpr.cc
@@ -28,7 +28,7 @@
# include <iostream>
# include "ivl_assert.h"
-NetExpr*PExpr::elaborate_pexpr(Design*des, NetScope*sc) const
+NetExpr*PExpr::elaborate_pexpr(Design*des, NetScope*) const
{
cerr << get_fileline() << ": error: invalid parameter expression: "
<< *this << endl;
View
10 elab_scope.cc
@@ -247,7 +247,6 @@ static void elaborate_scope_events_(Design*des, NetScope*scope,
}
static void elaborate_scope_tasks(Design*des, NetScope*scope,
- const LineInfo&loc,
const map<perm_string,PTask*>&tasks)
{
typedef map<perm_string,PTask*>::const_iterator tasks_it_t;
@@ -302,7 +301,6 @@ static void elaborate_scope_tasks(Design*des, NetScope*scope,
}
static void elaborate_scope_funcs(Design*des, NetScope*scope,
- const LineInfo&loc,
const map<perm_string,PFunction*>&funcs)
{
typedef map<perm_string,PFunction*>::const_iterator funcs_it_t;
@@ -482,14 +480,14 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,
// elaborate_scope method of the PTask for detailed
// processing.
- elaborate_scope_tasks(des, scope, *this, tasks);
+ elaborate_scope_tasks(des, scope, tasks);
// Functions are very similar to tasks, at least from the
// perspective of scopes. So handle them exactly the same
// way.
- elaborate_scope_funcs(des, scope, *this, funcs);
+ elaborate_scope_funcs(des, scope, funcs);
// Gates include modules, which might introduce new scopes, so
// scan all of them to create those scopes.
@@ -1050,8 +1048,8 @@ void PGenerate::elaborate_subscope_(Design*des, NetScope*scope)
// Scan through all the task and function declarations in this
// scope.
- elaborate_scope_tasks(des, scope, *this, tasks);
- elaborate_scope_funcs(des, scope, *this, funcs);
+ elaborate_scope_tasks(des, scope, tasks);
+ elaborate_scope_funcs(des, scope, funcs);
// Scan the generated scope for gates that may create
// their own scopes.
View
11 elab_sig.cc
@@ -78,7 +78,7 @@ static bool get_const_argument(NetExpr*exp, long&res)
return true;
}
-void Statement::elaborate_sig(Design*des, NetScope*scope) const
+void Statement::elaborate_sig(Design*, NetScope*) const
{
}
@@ -268,17 +268,17 @@ bool Module::elaborate_sig(Design*des, NetScope*scope) const
return flag;
}
-bool PGate::elaborate_sig(Design*des, NetScope*scope) const
+bool PGate::elaborate_sig(Design*, NetScope*) const
{
return true;
}
-bool PGBuiltin::elaborate_sig(Design*des, NetScope*scope) const
+bool PGBuiltin::elaborate_sig(Design*, NetScope*) const
{
return true;
}
-bool PGAssign::elaborate_sig(Design*des, NetScope*scope) const
+bool PGAssign::elaborate_sig(Design*, NetScope*) const
{
return true;
}
@@ -313,10 +313,13 @@ bool PGModule::elaborate_sig_mod_(Design*des, NetScope*scope,
return flag;
}
+ // Not currently used.
+#if 0
bool PGModule::elaborate_sig_udp_(Design*des, NetScope*scope, PUdp*udp) const
{
return true;
}
+#endif
bool PGenerate::elaborate_sig(Design*des, NetScope*container) const
{
View
6 elaborate.cc
@@ -42,7 +42,7 @@
# include "ivl_assert.h"
-void PGate::elaborate(Design*des, NetScope*scope) const
+void PGate::elaborate(Design*, NetScope*) const
{
cerr << "internal error: what kind of gate? " <<
typeid(*this).name() << endl;
@@ -1903,9 +1903,13 @@ bool PGModule::elaborate_sig(Design*des, NetScope*scope) const
if (mod != pform_modules.end())
return elaborate_sig_mod_(des, scope, (*mod).second);
+ // elaborate_sig_udp_ currently always returns true so skip all this
+ // for now.
+#if 0
map<perm_string,PUdp*>::const_iterator udp = pform_primitives.find(type_);
if (udp != pform_primitives.end())
return elaborate_sig_udp_(des, scope, (*udp).second);
+#endif
return true;
}
View
6 emit.cc
@@ -31,7 +31,7 @@
# include <cassert>
# include <cstring>
-bool NetNode::emit_node(struct target_t*tgt) const
+bool NetNode::emit_node(struct target_t*) const
{
cerr << "EMIT: Gate type? " << typeid(*this).name() << endl;
return false;
@@ -200,7 +200,7 @@ bool NetAnalogTop::emit(struct target_t*tgt) const
return tgt->process(this);
}
-bool NetProc::emit_proc(struct target_t*tgt) const
+bool NetProc::emit_proc(struct target_t*) const
{
cerr << "EMIT: Proc type? " << typeid(*this).name() << endl;
return false;
@@ -531,7 +531,7 @@ void NetECRealParam::expr_scan(struct expr_scan_t*tgt) const
tgt->expr_rparam(this);
}
-void NetEParam::expr_scan(struct expr_scan_t*tgt) const
+void NetEParam::expr_scan(struct expr_scan_t*) const
{
cerr << get_fileline() << ":internal error: unexpected NetEParam."
<< endl;
View
666 eval_tree.cc
@@ -29,7 +29,7 @@
# include "ivl_assert.h"
# include "netmisc.h"
-NetExpr* NetExpr::eval_tree(int prune_to_width)
+NetExpr* NetExpr::eval_tree(int)
{
return 0;
}
@@ -60,6 +60,20 @@ static bool get_real_arg_(NetExpr*expr, verireal&val)
return true;
}
+static bool get_real_arguments(NetExpr*le, NetExpr*re,
+ double&lval, double&rval)
+{
+ verireal val;
+
+ if (!get_real_arg_(le, val)) return false;
+ lval = val.as_double();
+
+ if (!get_real_arg_(re, val)) return false;
+ rval = val.as_double();
+
+ return true;
+}
+
bool NetEBinary::get_real_arguments_(verireal&lval, verireal&rval)
{
if (!get_real_arg_(left_, lval)) return false;
@@ -68,6 +82,38 @@ bool NetEBinary::get_real_arguments_(verireal&lval, verireal&rval)
return true;
}
+NetECReal* NetEBAdd::eval_tree_real_()
+{
+ verireal lval;
+ verireal rval;
+
+ bool flag = get_real_arguments_(lval, rval);
+ if (!flag) return 0;
+
+ verireal res_val;
+
+ switch (op()) {
+ case '+':
+ res_val = lval + rval;
+ break;
+ case '-':
+ res_val = lval - rval;
+ break;
+ default:
+ ivl_assert(*this, 0);
+ }
+
+ NetECReal*res = new NetECReal( res_val );
+ ivl_assert(*this, res);
+ res->set_line(*this);
+
+ if (debug_eval_tree)
+ cerr << get_fileline() << ": debug: Evaluated (real): " << *this
+ << " --> " << *res << endl;
+
+ return res;
+}
+
NetExpr* NetEBAdd::eval_tree(int prune_to_width)
{
eval_expr(left_, prune_to_width);
@@ -97,12 +143,6 @@ NetExpr* NetEBAdd::eval_tree(int prune_to_width)
return 0;
}
- if (debug_eval_tree) {
- cerr << get_fileline() << ": debug: Evaluate expr=" << *this
- << " --- prune=" << prune_to_width
- << " has_width=" << (has_width()? "true" : "false") << endl;
- }
-
/* Result might have known width. */
if (has_width()) {
unsigned lwid = lc->expr_width();
@@ -118,7 +158,15 @@ NetExpr* NetEBAdd::eval_tree(int prune_to_width)
val = val2;
}
- return new NetEConst(val);
+ NetEConst *res = new NetEConst(val);
+ ivl_assert(*this, res);
+ res->set_line(*this);
+
+ if (debug_eval_tree)
+ cerr << get_fileline() << ": debug: Evaluated: " << *this
+ << " --> " << *res << endl;
+
+ return res;
}
/* Try to combine a right constant value with the right
@@ -188,35 +236,15 @@ NetExpr* NetEBAdd::eval_tree(int prune_to_width)
return 0;
}
-NetECReal* NetEBAdd::eval_tree_real_()
+NetEConst* NetEBBits::eval_tree(int prune_to_width)
{
- verireal lval;
- verireal rval;
- bool flag = get_real_arguments_(lval, rval);
- if (!flag) return 0;
-
- verireal res_val;
-
- switch (op()) {
- case '+':
- res_val = lval + rval;
- break;
- case '-':
- res_val = lval - rval;
- break;
- default:
- ivl_assert(*this, 0);
+ if (debug_eval_tree) {
+ cerr << get_fileline() << ": debug: Evaluating expression:"
+ << *this << ", prune_to_width=" << prune_to_width << endl;
}
- NetECReal*res = new NetECReal( res_val );
- res->set_line(*this);
- return res;
-}
-
-NetEConst* NetEBBits::eval_tree(int prune_to_width)
-{
- eval_expr(left_);
- eval_expr(right_);
+ eval_expr(left_, prune_to_width);
+ eval_expr(right_, prune_to_width);
NetEConst*lc = dynamic_cast<NetEConst*>(left_);
NetEConst*rc = dynamic_cast<NetEConst*>(right_);
@@ -321,21 +349,20 @@ NetEConst* NetEBBits::eval_tree(int prune_to_width)
return new NetEConst(res);
}
-
NetEConst* NetEBComp::eval_less_()
{
- if (right_->expr_type() == IVL_VT_REAL)
- return eval_leeq_real_(left_, right_, false);
- if (left_->expr_type() == IVL_VT_REAL)
+ if (right_->expr_type() == IVL_VT_REAL ||
+ left_->expr_type() == IVL_VT_REAL)
return eval_leeq_real_(left_, right_, false);
- NetEConst*r = dynamic_cast<NetEConst*>(right_);
- if (r == 0) return 0;
+ NetEConst*rc = dynamic_cast<NetEConst*>(right_);
+ if (rc == 0) return 0;
- verinum rv = r->value();
+ verinum rv = rc->value();
if (! rv.is_defined()) {
- verinum result(verinum::Vx, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::Vx, 1));
+ ivl_assert(*this, res);
+ return res;
}
if (NetEConst*tmp = must_be_leeq_(left_, rv, false)) {
@@ -343,80 +370,25 @@ NetEConst* NetEBComp::eval_less_()
}
/* Now go on to the normal test of the values. */
- NetEConst*l = dynamic_cast<NetEConst*>(left_);
- if (l == 0) return 0;
- verinum lv = l->value();
+ NetEConst*lc = dynamic_cast<NetEConst*>(left_);
+ if (lc == 0) return 0;
+
+ verinum lv = lc->value();
if (! lv.is_defined()) {
- verinum result(verinum::Vx, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::Vx, 1));
+ ivl_assert(*this, res);
+ return res;
}
if (lv < rv) {
- verinum result(verinum::V1, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::V1, 1));
+ ivl_assert(*this, res);
+ return res;
} else {
- verinum result(verinum::V0, 1);
- return new NetEConst(result);
- }
-}
-
-NetEConst* NetEBComp::eval_leeq_real_(NetExpr*le, NetExpr*ri, bool eq_flag)
-{
- NetEConst*vtmp;
- NetECReal*rtmp;
- double lv, rv;
-
- switch (le->expr_type()) {
- case IVL_VT_REAL:
- rtmp = dynamic_cast<NetECReal*> (le);
- if (rtmp == 0) return 0;
- lv = rtmp->value().as_double();
- break;
-
- case IVL_VT_LOGIC:
- case IVL_VT_BOOL:
- vtmp = dynamic_cast<NetEConst*> (le);
- if (vtmp == 0) return 0;
- lv = vtmp->value().as_double();
- break;
-
- default:
- lv = 0.0;
- cerr << get_fileline() << ": internal error: "
- << "Unexpected expression type? " << le->expr_type() << endl;
- assert(0);
- }
-
- switch (ri->expr_type()) {
- case IVL_VT_REAL:
- rtmp = dynamic_cast<NetECReal*> (ri);
- if (rtmp == 0) return 0;
- rv = rtmp->value().as_double();
- break;
-
- case IVL_VT_LOGIC:
- case IVL_VT_BOOL:
- vtmp = dynamic_cast<NetEConst*> (ri);
- if (vtmp == 0) return 0;
- rv = vtmp->value().as_double();
- break;
-
- default:
- rv = 0.0;
- cerr << get_fileline() << ": internal error: "
- << "Unexpected expression type? " << ri->expr_type() << endl;
- assert(0);
+ NetEConst*res = new NetEConst(verinum(verinum::V0, 1));
+ ivl_assert(*this, res);
+ return res;
}
-
- bool test = false;
- if (lv < rv) test = true;
- if (test == false && eq_flag && lv == rv) test = true;
-
- verinum result(test? verinum::V1 : verinum::V0, 1);
- vtmp = new NetEConst(result);
- vtmp->set_line(*this);
-
- return vtmp;
}
NetEConst* NetEBComp::must_be_leeq_(NetExpr*le, const verinum&rv, bool eq_flag)
@@ -432,27 +404,49 @@ NetEConst* NetEBComp::must_be_leeq_(NetExpr*le, const verinum&rv, bool eq_flag)
}
if (lv < rv || (eq_flag && (lv == rv))) {
- verinum result(verinum::V1, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::V1, 1));
+ ivl_assert(*this, res);
+ return res;
}
return 0;
}
+NetEConst* NetEBComp::eval_leeq_real_(NetExpr*le, NetExpr*re, bool eq_flag)
+{
+ double lval;
+ double rval;
+
+ bool flag = get_real_arguments(le, re, lval, rval);
+ if (! flag) return 0;
+
+ bool tmp = false;
+ if (lval < rval) tmp = true;
+ if (tmp == false && eq_flag && lval == rval) tmp = true;
+
+ verinum result(tmp ? verinum::V1 : verinum::V0, 1);
+ NetEConst*res = new NetEConst(result);
+ ivl_assert(*this, res);
+
+ return res;
+}
+
NetEConst* NetEBComp::eval_leeq_()
{
- if (right_->expr_type() == IVL_VT_REAL)
- return eval_leeq_real_(left_, right_, true);
- if (left_->expr_type() == IVL_VT_REAL)
+ if (right_->expr_type() == IVL_VT_REAL ||
+ left_->expr_type() == IVL_VT_REAL)
return eval_leeq_real_(left_, right_, true);
+// assert(expr_type() == IVL_VT_LOGIC);
+// HERE
NetEConst*r = dynamic_cast<NetEConst*>(right_);
if (r == 0) return 0;
verinum rv = r->value();
if (! rv.is_defined()) {
- verinum result(verinum::Vx, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::Vx, 1));
+ ivl_assert(*this, res);
+ return res;
}
if (left_->expr_width() == 0) {
@@ -468,26 +462,29 @@ NetEConst* NetEBComp::eval_leeq_()
/* Now go on to the normal test of the values. */
NetEConst*l = dynamic_cast<NetEConst*>(left_);
if (l == 0) return 0;
+
verinum lv = l->value();
if (! lv.is_defined()) {
- verinum result(verinum::Vx, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::Vx, 1));
+ ivl_assert(*this, res);
+ return res;
}
if (lv <= rv) {
- verinum result(verinum::V1, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::V1, 1));
+ ivl_assert(*this, res);
+ return res;
} else {
- verinum result(verinum::V0, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::V0, 1));
+ ivl_assert(*this, res);
+ return res;
}
}
NetEConst* NetEBComp::eval_gt_()
{
- if (right_->expr_type() == IVL_VT_REAL)
- return eval_leeq_real_(right_, left_, false);
- if (left_->expr_type() == IVL_VT_REAL)
+ if (right_->expr_type() == IVL_VT_REAL ||
+ left_->expr_type() == IVL_VT_REAL)
return eval_leeq_real_(right_, left_, false);
NetEConst*l = dynamic_cast<NetEConst*>(left_);
@@ -495,8 +492,9 @@ NetEConst* NetEBComp::eval_gt_()
verinum lv = l->value();
if (! lv.is_defined()) {
- verinum result(verinum::Vx, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::Vx, 1));
+ ivl_assert(*this, res);
+ return res;
}
if (NetEConst*tmp = must_be_leeq_(right_, lv, false)) {
@@ -506,26 +504,29 @@ NetEConst* NetEBComp::eval_gt_()
/* Now go on to the normal test of the values. */
NetEConst*r = dynamic_cast<NetEConst*>(right_);
if (r == 0) return 0;
+
verinum rv = r->value();
if (! rv.is_defined()) {
- verinum result(verinum::Vx, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::Vx, 1));
+ ivl_assert(*this, res);
+ return res;
}
if (lv > rv) {
- verinum result(verinum::V1, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::V1, 1));
+ ivl_assert(*this, res);
+ return res;
} else {
- verinum result(verinum::V0, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::V0, 1));
+ ivl_assert(*this, res);
+ return res;
}
}
NetEConst* NetEBComp::eval_gteq_()
{
- if (right_->expr_type() == IVL_VT_REAL)
- return eval_leeq_real_(right_, left_, true);
- if (left_->expr_type() == IVL_VT_REAL)
+ if (right_->expr_type() == IVL_VT_REAL ||
+ left_->expr_type() == IVL_VT_REAL)
return eval_leeq_real_(right_, left_, true);
NetEConst*l = dynamic_cast<NetEConst*>(left_);
@@ -533,8 +534,9 @@ NetEConst* NetEBComp::eval_gteq_()
verinum lv = l->value();
if (! lv.is_defined()) {
- verinum result(verinum::Vx, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::Vx, 1));
+ ivl_assert(*this, res);
+ return res;
}
if (NetEConst*tmp = must_be_leeq_(right_, lv, true)) {
@@ -544,18 +546,22 @@ NetEConst* NetEBComp::eval_gteq_()
/* Now go on to the normal test of the values. */
NetEConst*r = dynamic_cast<NetEConst*>(right_);
if (r == 0) return 0;
+
verinum rv = r->value();
if (! rv.is_defined()) {
- verinum result(verinum::Vx, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::Vx, 1));
+ ivl_assert(*this, res);
+ return res;
}
if (lv >= rv) {
- verinum result(verinum::V1, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::V1, 1));
+ ivl_assert(*this, res);
+ return res;
} else {
- verinum result(verinum::V0, 1);
- return new NetEConst(result);
+ NetEConst*res = new NetEConst(verinum(verinum::V0, 1));
+ ivl_assert(*this, res);
+ return res;
}
}
@@ -566,75 +572,34 @@ NetEConst* NetEBComp::eval_gteq_()
* are equal, but there are are x/z bits, then the situation is
* ambiguous so the result is x.
*/
-NetEConst* NetEBComp::eval_eqeq_real_(NetExpr*le, NetExpr*ri, bool ne_flag)
+NetEConst* NetEBComp::eval_eqeq_real_(bool ne_flag)
{
- NetEConst*vtmp;
- NetECReal*rtmp;
- double lv, rv;
-
- switch (le->expr_type()) {
- case IVL_VT_REAL:
- rtmp = dynamic_cast<NetECReal*> (le);
- if (rtmp == 0) return 0;
- lv = rtmp->value().as_double();
- break;
-
- case IVL_VT_LOGIC:
- case IVL_VT_BOOL:
- vtmp = dynamic_cast<NetEConst*> (le);
- if (vtmp == 0) return 0;
- lv = vtmp->value().as_double();
- break;
-
- default:
- lv = 0.0;
- cerr << get_fileline() << ": internal error: "
- << "Unexpected expression type? " << le->expr_type() << endl;
- assert(0);
- }
-
- switch (ri->expr_type()) {
- case IVL_VT_REAL:
- rtmp = dynamic_cast<NetECReal*> (ri);
- if (rtmp == 0) return 0;
- rv = rtmp->value().as_double();
- break;
-
- case IVL_VT_LOGIC:
- case IVL_VT_BOOL:
- vtmp = dynamic_cast<NetEConst*> (ri);
- if (vtmp == 0) return 0;
- rv = vtmp->value().as_double();
- break;
+ verireal lval;
+ verireal rval;
- default:
- rv = 0.0;
- cerr << get_fileline() << ": internal error: "
- << "Unexpected expression type? " << ri->expr_type() << endl;
- assert(0);
- }
+ bool flag = get_real_arguments_(lval, rval);
+ if (! flag) return 0;
- verinum result(((lv == rv) ^ ne_flag) ? verinum::V1 : verinum::V0, 1);
- vtmp = new NetEConst(result);
- vtmp->set_line(*this);
+ verinum result(((lval.as_double() == rval.as_double()) ^ ne_flag) ?
+ verinum::V1 : verinum::V0, 1);
+ NetEConst*res = new NetEConst(result);
+ ivl_assert(*this, res);
- return vtmp;
+ return res;
}
NetEConst* NetEBComp::eval_eqeq_(bool ne_flag)
{
- if (right_->expr_type() == IVL_VT_REAL)
- return eval_eqeq_real_(right_, left_, ne_flag);
- if (left_->expr_type() == IVL_VT_REAL)
- return eval_eqeq_real_(right_, left_, ne_flag);
+ if (left_->expr_type() == IVL_VT_REAL ||
+ right_->expr_type() == IVL_VT_REAL)
+ return eval_eqeq_real_(ne_flag);
- NetEConst*l = dynamic_cast<NetEConst*>(left_);
- if (l == 0) return 0;
- NetEConst*r = dynamic_cast<NetEConst*>(right_);
- if (r == 0) return 0;
+ NetEConst*lc = dynamic_cast<NetEConst*>(left_);
+ NetEConst*rc = dynamic_cast<NetEConst*>(right_);
+ if (lc == 0 || rc == 0) return 0;
- const verinum&lv = l->value();
- const verinum&rv = r->value();
+ const verinum&lv = lc->value();
+ const verinum&rv = rc->value();
const verinum::V eq_res = ne_flag? verinum::V0 : verinum::V1;
const verinum::V ne_res = ne_flag? verinum::V1 : verinum::V0;
@@ -735,91 +700,119 @@ NetEConst* NetEBComp::eval_eqeq_(bool ne_flag)
}
}
- return new NetEConst(verinum(res));
+ NetEConst*result = new NetEConst(verinum(res, 1));
+ ivl_assert(*this, result);
+ return result;
}
-NetEConst* NetEBComp::eval_eqeqeq_()
+NetEConst* NetEBComp::eval_eqeqeq_(bool ne_flag)
{
- NetEConst*l = dynamic_cast<NetEConst*>(left_);
- if (l == 0) return 0;
- NetEConst*r = dynamic_cast<NetEConst*>(right_);
- if (r == 0) return 0;
+ NetEConst*lc = dynamic_cast<NetEConst*>(left_);
+ NetEConst*rc = dynamic_cast<NetEConst*>(right_);
+ if (lc == 0 || rc == 0) return 0;
- const verinum&lv = l->value();
- const verinum&rv = r->value();
+ const verinum&lv = lc->value();
+ const verinum&rv = rc->value();
verinum::V res = verinum::V1;
+ // Find the smallest argument length.
unsigned cnt = lv.len();
- if (cnt > rv.len())
- cnt = rv.len();
+ if (cnt > rv.len()) cnt = rv.len();
+ // Check the common bits.
for (unsigned idx = 0 ; idx < cnt ; idx += 1)
- if (lv.get(idx) != rv.get(idx))
- res = verinum::V0;
-
- for (unsigned idx = cnt ; idx < lv.len() ; idx += 1)
- if (lv.get(idx) != verinum::V0)
- res = verinum::V0;
-
- for (unsigned idx = cnt ; idx < rv.len() ; idx += 1)
- if (rv.get(idx) != verinum::V0)
+ if (lv.get(idx) != rv.get(idx)) {
res = verinum::V0;
+ break;
+ }
- return new NetEConst(verinum(res, 1));
-}
+ bool is_signed = lv.has_sign() && rv.has_sign();
-NetEConst* NetEBComp::eval_neeqeq_()
-{
- NetEConst*tmp = eval_eqeqeq_();
- if (tmp == 0)
- return 0;
+ // If the left value is longer check it against the pad bit.
+ if (res == verinum::V1) {
+ verinum::V pad = verinum::V0;
+ if (is_signed) pad = rv.get(rv.len()-1);
+ for (unsigned idx = cnt ; idx < lv.len() ; idx += 1)
+ if (lv.get(idx) != pad) {
+ res = verinum::V0;
+ break;
+ }
+ }
- NetEConst*res;
+ // If the right value is longer check it against the pad bit.
+ if (res == verinum::V1) {
+ verinum::V pad = verinum::V0;
+ if (is_signed) pad = lv.get(lv.len()-1);
+ for (unsigned idx = cnt ; idx < rv.len() ; idx += 1) {
+ if (rv.get(idx) != pad)
+ res = verinum::V0;
+ break;
+ }
+ }
- if (tmp->value().get(0) == verinum::V0)
- res = new NetEConst(verinum(verinum::V1,1));
- else
- res = new NetEConst(verinum(verinum::V0,1));
+ if (ne_flag) {
+ if (res == verinum::V0) res = verinum::V1;
+ else res = verinum::V0;
+ }
- delete tmp;
- res->set_line(*this);
- return res;
+ NetEConst*result = new NetEConst(verinum(res, 1));
+ ivl_assert(*this, result);
+ return result;
}
-NetEConst* NetEBComp::eval_tree(int prune_to_width)
+NetEConst* NetEBComp::eval_tree(int)
{
eval_expr(left_);
eval_expr(right_);
+ NetEConst*res = 0;
+
switch (op_) {
case 'E': // Case equality (===)
- return eval_eqeqeq_();
+ res = eval_eqeqeq_(false);
+ break;
case 'e': // Equality (==)
- return eval_eqeq_(false);
+ res = eval_eqeq_(false);
+ break;
case 'G': // >=
- return eval_gteq_();
+ res = eval_gteq_();
+ break;
case 'L': // <=
- return eval_leeq_();
+ res = eval_leeq_();
+ break;
case 'N': // Case inequality (!==)
- return eval_neeqeq_();
+ res = eval_eqeqeq_(true);
+ break;
case 'n': // not-equal (!=)
- return eval_eqeq_(true);
+ res = eval_eqeq_(true);
+ break;
case '<': // Less than
- return eval_less_();
+ res = eval_less_();
+ break;
case '>': // Greater than
- return eval_gt_();
+ res = eval_gt_();
+ break;
- default:
- return 0;
}
+ if (res == 0) return 0;
+ res->set_line(*this);
+
+ if (debug_eval_tree) {
+ cerr << get_fileline() << ": debug: Evaluated";
+ if (left_->expr_type() == IVL_VT_REAL ||
+ right_->expr_type() == IVL_VT_REAL)
+ cerr << " (real)";
+ cerr << ": " << *this << " --> " << *res << endl;
+ }
+ return res;
}
NetExpr* NetEBDiv::eval_tree_real_()
@@ -845,6 +838,11 @@ NetExpr* NetEBDiv::eval_tree_real_()
}
ivl_assert(*this, res);
res->set_line(*this);
+
+ if (debug_eval_tree)
+ cerr << get_fileline() << ": debug: Evaluated (real): " << *this
+ << " --> " << *res << endl;
+
return res;
}
@@ -854,11 +852,13 @@ NetExpr* NetEBDiv::eval_tree_real_()
*/
NetExpr* NetEBDiv::eval_tree(int prune_to_width)
{
+// assert(prune_to_width <= 0);
+// HERE
+
eval_expr(left_);
eval_expr(right_);
if (expr_type() == IVL_VT_REAL) return eval_tree_real_();
-
assert(expr_type() == IVL_VT_LOGIC);
NetEConst*lc = dynamic_cast<NetEConst*>(left_);
@@ -881,14 +881,65 @@ NetExpr* NetEBDiv::eval_tree(int prune_to_width)
}
ivl_assert(*this, tmp);
tmp->set_line(*this);
+
+ if (debug_eval_tree)
+ cerr << get_fileline() << ": debug: Evaluated: " << *this
+ << " --> " << *tmp << endl;
+
return tmp;
}
-NetEConst* NetEBLogic::eval_tree(int prune_to_width)
+NetEConst* NetEBLogic::eval_tree_real_()
+{
+ verireal lval;
+ verireal rval;
+
+ bool flag = get_real_arguments_(lval, rval);
+ if (! flag) return 0;
+
+ verinum::V res;
+ switch (op_) {
+ case 'a': { // Logical AND (&&)
+ if ((lval.as_double() != 0.0) && (rval.as_double() != 0.0))
+ res = verinum::V1;
+ else
+ res = verinum::V0;
+ break;
+ }
+
+ case 'o': { // Logical OR (||)
+ if ((lval.as_double() != 0.0) || (rval.as_double() != 0.0))
+ res = verinum::V1;
+ else
+ res = verinum::V0;
+ break;
+ }
+
+ default:
+ return 0;
+ }
+
+ NetEConst*tmp = new NetEConst(verinum(res, 1));
+ ivl_assert(*this, tmp);
+ tmp->set_line(*this);
+
+ if (debug_eval_tree)
+ cerr << get_fileline() << ": debug: Evaluated (real): " << *this
+ << " --> " << *tmp << endl;
+
+ return tmp;
+}
+
+NetEConst* NetEBLogic::eval_tree(int)
{
eval_expr(left_);
eval_expr(right_);
+ if (left_->expr_type() == IVL_VT_REAL ||
+ right_->expr_type() == IVL_VT_REAL)
+ return eval_tree_real_();
+ assert(expr_type() == IVL_VT_LOGIC);
+
NetEConst*lc = dynamic_cast<NetEConst*>(left_);
NetEConst*rc = dynamic_cast<NetEConst*>(right_);
if (lc == 0 || rc == 0) return 0;
@@ -898,23 +949,21 @@ NetEConst* NetEBLogic::eval_tree(int prune_to_width)
verinum v = lc->value();
for (unsigned idx = 0 ; idx < v.len() ; idx += 1)
- if (v.get(idx) == verinum::V1)
+ if (v.get(idx) == verinum::V1) {
lv = verinum::V1;
+ break;
+ }
- if (lv == verinum::V0)
- for (unsigned idx = 0 ; idx < v.len() ; idx += 1)
- if (v.get(idx) != verinum::V0)
- lv = verinum::Vx;
+ if (lv == verinum::V0 && ! v.is_defined()) lv = verinum::Vx;
v = rc->value();
for (unsigned idx = 0 ; idx < v.len() ; idx += 1)
- if (v.get(idx) == verinum::V1)
+ if (v.get(idx) == verinum::V1) {
rv = verinum::V1;
+ break;
+ }
- if (rv == verinum::V0)
- for (unsigned idx = 0 ; idx < v.len() ; idx += 1)
- if (v.get(idx) != verinum::V0)
- rv = verinum::Vx;
+ if (rv == verinum::V0 && ! v.is_defined()) rv = verinum::Vx;
verinum::V res;
switch (op_) {
@@ -948,7 +997,15 @@ NetEConst* NetEBLogic::eval_tree(int prune_to_width)
return 0;
}
- return new NetEConst(verinum(res, 1));
+ NetEConst*tmp = new NetEConst(verinum(res, 1));
+ ivl_assert(*this, tmp);
+ tmp->set_line(*this);
+
+ if (debug_eval_tree)
+ cerr << get_fileline() << ": debug: Evaluated: " << *this
+ << " --> " << *tmp << endl;
+
+ return tmp;
}
@@ -961,17 +1018,25 @@ NetExpr* NetEBMult::eval_tree_real_()
if (! flag) return 0;
NetECReal*res = new NetECReal(lval * rval);
+ ivl_assert(*this, res);
res->set_line(*this);
+
+ if (debug_eval_tree)
+ cerr << get_fileline() << ": debug: Evaluated (real): " << *this
+ << " --> " << *res << endl;
+
return res;
}
NetExpr* NetEBMult::eval_tree(int prune_to_width)
{
+// assert(prune_to_width <= 0);
+// HERE
+
eval_expr(left_);
eval_expr(right_);
if (expr_type() == IVL_VT_REAL) return eval_tree_real_();
-
assert(expr_type() == IVL_VT_LOGIC);
NetEConst*lc = dynamic_cast<NetEConst*>(left_);
@@ -982,10 +1047,12 @@ NetExpr* NetEBMult::eval_tree(int prune_to_width)
verinum rval = rc->value();
NetEConst*tmp = new NetEConst(lval * rval);
+ ivl_assert(*this, tmp);
+ tmp->set_line(*this);
if (debug_eval_tree)
- cerr << get_fileline() << ": debug: Evaluate "
- << lval << " * " << rval << " --> " << *tmp << endl;
+ cerr << get_fileline() << ": debug: Evaluated: " << *this
+ << " --> " << *tmp << endl;
return tmp;
}
@@ -999,23 +1066,25 @@ NetExpr* NetEBPow::eval_tree_real_()
if (! flag) return 0;
NetECReal*res = new NetECReal( pow(lval,rval) );
+ ivl_assert(*this, res);
res->set_line(*this);
if (debug_eval_tree)
- cerr << get_fileline() << ": debug: Evaluate (real) "
- << lval << " ** " << rval << " --> " << *res << endl;
+ cerr << get_fileline() << ": debug: Evaluated (real): " << *this
+ << " --> " << *res << endl;
return res;
}
NetExpr* NetEBPow::eval_tree(int prune_to_width)
{
+// assert(prune_to_width <= 0);
+// HERE
+
eval_expr(left_);
eval_expr(right_);
- if (expr_type() == IVL_VT_REAL)
- return eval_tree_real_();
-
+ if (expr_type() == IVL_VT_REAL) return eval_tree_real_();
assert(expr_type() == IVL_VT_LOGIC);
NetEConst*lc = dynamic_cast<NetEConst*>(left_);
@@ -1026,11 +1095,12 @@ NetExpr* NetEBPow::eval_tree(int prune_to_width)
verinum rval = rc->value();
NetEConst*res = new NetEConst( pow(lval,rval) );
+ ivl_assert(*this, res);
res->set_line(*this);
if (debug_eval_tree)
- cerr << get_fileline() << ": debug: Evaluate "
- << lval << " ** " << rval << " --> " << *res << endl;
+ cerr << get_fileline() << ": debug: Evaluated: " << *this
+ << " --> " << *res << endl;
return res;
}
@@ -1081,7 +1151,7 @@ NetEConst* NetEBShift::eval_tree(int prune_to_width)
if (prune_to_width > 0 && wid > (unsigned)prune_to_width)
wid = prune_to_width;
- assert(wid);
+ assert(wid > 0);
verinum::V pad = verinum::V0;
if (op() == 'R' && has_sign()) {
pad = lv[lv.len()-1];
@@ -1117,21 +1187,28 @@ NetEConst* NetEBShift::eval_tree(int prune_to_width)
} else {
if (wid == 0) wid = left_->expr_width();
+ if (prune_to_width > 0 && wid > (unsigned)prune_to_width)
+ wid = prune_to_width;
+
+ assert(wid > 0);
verinum nv (verinum::Vx, wid);
res = new NetEConst(nv);
}
+ res->set_line(*this);
+
return res;
}
NetEConst* NetEConcat::eval_tree(int prune_to_width)
{
+// HERE
unsigned repeat_val = repeat();
unsigned local_errors = 0;
if (debug_eval_tree) {
- cerr << get_fileline() << ": debug: Evaluate expr=" << *this
- << ", prune_to_width=" << prune_to_width << endl;
+ cerr << get_fileline() << ": debug: Evaluating expression:"
+ << *this << ", prune_to_width=" << prune_to_width << endl;
}
unsigned gap = 0;
@@ -1218,16 +1295,18 @@ NetEConst* NetEConcat::eval_tree(int prune_to_width)
NetExpr* NetEParam::eval_tree(int prune_to_width)
{
+// HERE
if (des_ == 0) {
assert(scope_ == 0);
return 0;
}
if (debug_eval_tree) {
- cerr << get_fileline() << ": debug: evaluating expression: "
- << *this << endl;
+ cerr << get_fileline() << ": debug: Evaluating expression:"
+ << *this << ", prune_to_width=" << prune_to_width << endl;
}
+
if (solving()) {
cerr << get_fileline() << ": warning: Recursive parameter "
"reference found involving " << *this << "." << endl;
@@ -1336,6 +1415,12 @@ NetExpr* NetEParam::eval_tree(int prune_to_width)
NetEConst* NetESelect::eval_tree(int prune_to_width)
{
+// HERE
+ if (debug_eval_tree) {
+ cerr << get_fileline() << ": debug: Evaluating expression:"
+ << *this << ", prune_to_width=" << prune_to_width << endl;
+ }
+
eval_expr(expr_);
NetEConst*expr = dynamic_cast<NetEConst*>(expr_);
@@ -1409,7 +1494,7 @@ NetExpr* NetETernary::eval_tree(int prune_to_width)
eval_expr(cond_);
switch (const_logical(cond_)) {
case C_0:
- eval_expr(false_val_);
+ eval_expr(false_val_, prune_to_width);
if (debug_eval_tree) {
cerr << get_fileline() << ": debug: Evaluate ternary with "
@@ -1432,7 +1517,7 @@ NetExpr* NetETernary::eval_tree(int prune_to_width)
return false_val_->dup_expr();
case C_1:
- eval_expr(true_val_);
+ eval_expr(true_val_, prune_to_width);
if (debug_eval_tree) {
cerr << get_fileline() << ": debug: Evaluate ternary with "
<< "constant condition value: ";
@@ -1464,8 +1549,8 @@ NetExpr* NetETernary::eval_tree(int prune_to_width)
expressions down to constants then compare the values to
build up a constant result. */
- eval_expr(true_val_);
- eval_expr(false_val_);
+ eval_expr(true_val_, prune_to_width);
+ eval_expr(false_val_, prune_to_width);
NetEConst*t = dynamic_cast<NetEConst*>(true_val_);
NetEConst*f = dynamic_cast<NetEConst*>(false_val_);
@@ -1542,6 +1627,11 @@ NetExpr* NetEUnary::eval_tree_real_()
NetExpr* NetEUnary::eval_tree(int prune_to_width)
{
+ if (debug_eval_tree) {
+ cerr << get_fileline() << ": debug: Evaluating expression:"
+ << *this << ", prune_to_width=" << prune_to_width << endl;
+ }
+
eval_expr(expr_);
if (expr_type() == IVL_VT_REAL) return eval_tree_real_();
@@ -1605,6 +1695,11 @@ NetExpr* NetEUBits::eval_tree(int prune_to_width)
NetEConst* NetEUReduce::eval_tree(int prune_to_width)
{
+ if (debug_eval_tree) {
+ cerr << get_fileline() << ": debug: Evaluating expression:"
+ << *this << ", prune_to_width=" << prune_to_width << endl;
+ }
+
eval_expr(expr_);
NetEConst*rval = dynamic_cast<NetEConst*>(expr_);
if (rval == 0) return 0;
@@ -1892,6 +1987,11 @@ NetExpr* evaluate_min_max(NetExpr*&arg0_, NetExpr*&arg1_, const char*name)
NetExpr* NetESFunc::eval_tree(int prune_to_width)
{
+ if (debug_eval_tree) {
+ cerr << get_fileline() << ": debug: Evaluating expression:"
+ << *this << ", prune_to_width=" << prune_to_width << endl;
+ }
+
/* If we are not targeting at least Verilog-2005, Verilog-AMS
* or using the Icarus misc flag then we do not support these
* functions as constant. */
@@ -1989,7 +2089,7 @@ NetExpr* NetESFunc::eval_tree(int prune_to_width)
return rtn;
}
-NetExpr* NetEUFunc::eval_tree(int prune_to_width)
+NetExpr* NetEUFunc::eval_tree(int)
{
if (need_constant_expr) {
cerr << get_fileline() << ": sorry: constant user "
View
15 expr_synth.cc
@@ -39,8 +39,7 @@ static NetNet* convert_to_real_const(Design*des, NetScope*scope, NetEConst*expr)
/* Note that lsig, rsig and real_args are references. */
static bool process_binary_args(Design*des, NetScope*scope, NetExpr*root,
NetExpr*left, NetExpr*right,
- NetNet*&lsig, NetNet*&rsig, bool&real_args,
- NetExpr*obj)
+ NetNet*&lsig, NetNet*&rsig, bool&real_args)
{
if (left->expr_type() == IVL_VT_REAL ||
right->expr_type() == IVL_VT_REAL) {
@@ -77,7 +76,7 @@ static bool process_binary_args(Design*des, NetScope*scope, NetExpr*root,
else return false;
}
-NetNet* NetExpr::synthesize(Design*des, NetScope*scope, NetExpr*root)
+NetNet* NetExpr::synthesize(Design*des, NetScope*, NetExpr*)
{
cerr << get_fileline() << ": internal error: cannot synthesize expression: "
<< *this << endl;
@@ -95,7 +94,7 @@ NetNet* NetEBAdd::synthesize(Design*des, NetScope*scope, NetExpr*root)
NetNet *lsig=0, *rsig=0;
bool real_args=false;
if (process_binary_args(des, scope, root, left_, right_, lsig, rsig,
- real_args, this)) {
+ real_args)) {
return 0;
}
@@ -221,7 +220,7 @@ NetNet* NetEBComp::synthesize(Design*des, NetScope*scope, NetExpr*root)
unsigned width;
bool real_args=false;
if (process_binary_args(des, scope, root, left_, right_, lsig, rsig,
- real_args, this)) {
+ real_args)) {
return 0;
}
@@ -370,7 +369,7 @@ NetNet* NetEBPow::synthesize(Design*des, NetScope*scope, NetExpr*root)
unsigned width;
bool real_args=false;
if (process_binary_args(des, scope, root, left_, right_, lsig, rsig,
- real_args, this)) {
+ real_args)) {
return 0;
}
@@ -406,7 +405,7 @@ NetNet* NetEBMult::synthesize(Design*des, NetScope*scope, NetExpr*root)
unsigned width;
bool real_args=false;
if (process_binary_args(des, scope, root, left_, right_, lsig, rsig,
- real_args, this)) {
+ real_args)) {
return 0;
}
@@ -443,7 +442,7 @@ NetNet* NetEBDiv::synthesize(Design*des, NetScope*scope, NetExpr*root)
unsigned width;
bool real_args=false;
if (process_binary_args(des, scope, root, left_, right_, lsig, rsig,
- real_args, this)) {
+ real_args)) {
return 0;
}
View
2 functor.cc
@@ -244,7 +244,7 @@ proc_match_t::~proc_match_t()
{
}
-int NetProc::match_proc(proc_match_t*that)
+int NetProc::match_proc(proc_match_t*)
{
return 0;
}
View
3 iverilog-vpi.sh
@@ -22,6 +22,7 @@
CC="@IVCC@"
CXX=@IVCXX@
CFLAGS="@PIC@ @IVCFLAGS@ -I@INCLUDEDIR@"
+CXXFLAGS="@PIC@ @IVCXXFLAGS@ -I@INCLUDEDIR@"
SUFFIX=@SUFFIX@
@@ -136,7 +137,7 @@ do
obj=$base".o"
echo "Compiling $src..."
- $CXX -c -o $obj $DEFS $CFLAGS $INCOPT $src || compile_errors=`expr $compile_errors + 1`
+ $CXX -c -o $obj $DEFS $CXXFLAGS $INCOPT $src || compile_errors=`expr $compile_errors + 1`
OBJ="$OBJ $obj"
done
View
6 lexor_keyword.gperf
@@ -1,3 +1,9 @@
+/*
+ * We need this to prevent -Wextra (-W) from complaining that the mask and
+ * tokenType values are not initialized for the empty table entries.
+ */
+%define initializer-suffix ,0,0
+
%{
/* Command-line: gperf -o -i 1 -C -k 1-3,$ -L C -H keyword_hash -N check_identifier -tT lexor_keyword.gperf */
View
24 net_nex_input.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2008 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2002-2010 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
@@ -27,7 +27,7 @@
# include "netlist.h"
# include "netmisc.h"
-NexusSet* NetExpr::nex_input(bool rem_out)
+NexusSet* NetExpr::nex_input(bool)
{
cerr << get_fileline()
<< ": internal error: nex_input not implemented: "
@@ -35,7 +35,7 @@ NexusSet* NetExpr::nex_input(bool rem_out)
return 0;
}
-NexusSet* NetProc::nex_input(bool rem_out)
+NexusSet* NetProc::nex_input(bool)
{
cerr << get_fileline()
<< ": internal error: NetProc::nex_input not implemented"
@@ -68,7 +68,7 @@ NexusSet* NetEConcat::nex_input(bool rem_out)
return result;
}
-NexusSet* NetEAccess::nex_input(bool rem_out)
+NexusSet* NetEAccess::nex_input(bool)
{
return new NexusSet;
}
@@ -76,12 +76,12 @@ NexusSet* NetEAccess::nex_input(bool rem_out)
/*
* A constant has not inputs, so always return an empty set.
*/
-NexusSet* NetEConst::nex_input(bool rem_out)
+NexusSet* NetEConst::nex_input(bool)
{
return new NexusSet;
}
-NexusSet* NetECReal::nex_input(bool rem_out)
+NexusSet* NetECReal::nex_input(bool)
{
return new NexusSet;
}
@@ -90,17 +90,17 @@ NexusSet* NetECReal::nex_input(bool rem_out)
* A parameter by definition has no inputs. It represents a constant
* value, even if that value is a constant expression.
*/
-NexusSet* NetEParam::nex_input(bool rem_out)
+NexusSet* NetEParam::nex_input(bool)
{
return new NexusSet;
}
-NexusSet* NetEEvent::nex_input(bool rem_out)
+NexusSet* NetEEvent::nex_input(bool)
{
return new NexusSet;
}
-NexusSet* NetEScope::nex_input(bool rem_out)
+NexusSet* NetEScope::nex_input(bool)
{
return new NexusSet;
}
@@ -324,7 +324,7 @@ NexusSet* NetCase::nex_input(bool rem_out)
return result;
}
-NexusSet* NetCAssign::nex_input(bool rem_out)
+NexusSet* NetCAssign::nex_input(bool)
{
cerr << get_fileline() << ": internal warning: NetCAssign::nex_input()"
<< " not implemented." << endl;
@@ -349,7 +349,7 @@ NexusSet* NetCondit::nex_input(bool rem_out)
return result;
}
-NexusSet* NetForce::nex_input(bool rem_out)
+NexusSet* NetForce::nex_input(bool)
{
cerr << get_fileline() << ": internal warning: NetForce::nex_input()"
<< " not implemented." << endl;
@@ -407,7 +407,7 @@ NexusSet* NetSTask::nex_input(bool rem_out)
* parameters to consider, because the compiler already removed them
* and converted them to blocking assignments.
*/
-NexusSet* NetUTask::nex_input(bool rem_out)
+NexusSet* NetUTask::nex_input(bool)
{
return new NexusSet;
}
View
8 net_nex_output.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2007 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2002-2010 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
@@ -26,7 +26,7 @@
# include "netlist.h"
# include "netmisc.h"
-void NetProc::nex_output(NexusSet&out)
+void NetProc::nex_output(NexusSet&)
{
cerr << get_fileline()
<< ": internal error: NetProc::nex_output not implemented"
@@ -108,7 +108,7 @@ void NetPDelay::nex_output(NexusSet&out)
* all. This is OK because most system tasks are not synthesizable in
* the first place.
*/
-void NetSTask::nex_output(NexusSet&out)
+void NetSTask::nex_output(NexusSet&)
{
}
@@ -117,7 +117,7 @@ void NetSTask::nex_output(NexusSet&out)
* right, we should be listing as outputs all the output ports, but for
* the purposes that this method is used, this will do for now.
*/
-void NetUTask::nex_output(NexusSet&out)
+void NetUTask::nex_output(NexusSet&)
{
}
View
6 netlist.h
@@ -3405,14 +3405,13 @@ class NetEBComp : public NetEBinary {
NetEConst* must_be_leeq_(NetExpr*le, const verinum&rv, bool eq_flag);
NetEConst*eval_eqeq_(bool ne_flag);
- NetEConst*eval_eqeq_real_(NetExpr*le, NetExpr*ri, bool ne_flag);
+ NetEConst*eval_eqeq_real_(bool ne_flag);
NetEConst*eval_less_();
NetEConst*eval_leeq_();
NetEConst*eval_leeq_real_(NetExpr*le, NetExpr*ri, bool eq_flag);
NetEConst*eval_gt_();
NetEConst*eval_gteq_();
- NetEConst*eval_eqeqeq_();
- NetEConst*eval_neeqeq_();
+ NetEConst*eval_eqeqeq_(bool ne_flag);
};
/*
@@ -3434,6 +3433,7 @@ class NetEBLogic : public NetEBinary {
virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);
private:
+ NetEConst* eval_tree_real_();
};
/*
View
12 netmisc.cc
@@ -26,11 +26,14 @@
# include "pform_types.h"
# include "ivl_assert.h"
+// This routines is not currently used!
+#if 0
NetNet* add_to_net(Design*des, NetNet*sig, long val)
{
if (val == 0)
return sig;
-#if 0
+ cerr << sig->get_fileline() << ": XXXX: Forgot how to implement add_to_net" << endl;
+ return 0;
NetScope*scope = sig->scope();
unsigned long abs_val = (val >= 0)? val : (-val);
unsigned width = sig->pin_count();
@@ -70,11 +73,8 @@ NetNet* add_to_net(Design*des, NetNet*sig, long val)
des->add_node(val_c);
return res;
-#else
- cerr << sig->get_fileline() << ": XXXX: Forgot how to implement add_to_net" << endl;
- return 0;
-#endif
}
+#endif
NetNet* sub_net_from(Design*des, NetScope*scope, long val, NetNet*sig)
{
@@ -657,7 +657,7 @@ const_bool const_logical(const NetExpr*expr)
for (unsigned idx = 0; idx < cval.len(); idx += 1) {
switch (cval.get(idx)) {
case verinum::V1:
- res = C_1;
+ return C_1;
break;
case verinum::V0:
View
4 netmisc.h
@@ -107,8 +107,12 @@ extern NetExpr*normalize_variable_array_base(NetExpr *base, long offset,
* This function takes as input a NetNet signal and adds a constant
* value to it. If the val is 0, then simply return sig. Otherwise,
* return a new NetNet value that is the output of an addition.
+ *
+ * Not currently used.
*/
+#if 0
extern NetNet*add_to_net(Design*des, NetNet*sig, long val);
+#endif
extern NetNet*sub_net_from(Design*des, NetScope*scope, long val, NetNet*sig);
/*
View
4 <