Skip to content

Commit

Permalink
Merge test_width rework
Browse files Browse the repository at this point in the history
This collection of patches fixes a variety of bugs with the handling
of signed-ness in exprsesions.
  • Loading branch information
steveicarus committed Oct 14, 2008
2 parents 3adcbb5 + 25f6282 commit 1a3e655
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 167 deletions.
1 change: 1 addition & 0 deletions PExpr.cc
Expand Up @@ -28,6 +28,7 @@

PExpr::PExpr()
{
expr_type_ = IVL_VT_NO_TYPE;
}

PExpr::~PExpr()
Expand Down
41 changes: 27 additions & 14 deletions PExpr.h
Expand Up @@ -73,7 +73,12 @@ class PExpr : public LineInfo {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);

// After the test_width method is complete, these methods
// return valid results.
ivl_variable_type_t expr_type() const { return expr_type_; }
unsigned expr_width() const { return expr_width_; }

// During the elaborate_sig phase, we may need to scan
// expressions to find implicit net declarations.
Expand Down Expand Up @@ -128,6 +133,13 @@ class PExpr : public LineInfo {
// expressions that must be structurally "identical".
virtual bool is_the_same(const PExpr*that) const;

protected:
// The derived class test_width methods should fill these in.
ivl_variable_type_t expr_type_;
unsigned expr_width_;

static void suppress_binary_operand_sign_if_needed_(NetExpr*lp, NetExpr*rp);

private: // not implemented
PExpr(const PExpr&);
PExpr& operator= (const PExpr&);
Expand Down Expand Up @@ -207,7 +219,7 @@ class PEFNumber : public PExpr {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);
virtual NetExpr*elaborate_expr(Design*des, NetScope*,
int expr_width, bool sys_task_arg) const;
virtual NetExpr*elaborate_pexpr(Design*des, NetScope*sc) const;
Expand All @@ -233,7 +245,7 @@ class PEIdent : public PExpr {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);

virtual bool elaborate_sig(Design*des, NetScope*scope) const;

Expand Down Expand Up @@ -348,7 +360,7 @@ class PENumber : public PExpr {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);

virtual NetEConst*elaborate_expr(Design*des, NetScope*,
int expr_width, bool) const;
Expand Down Expand Up @@ -384,7 +396,7 @@ class PEString : public PExpr {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);

virtual NetEConst*elaborate_expr(Design*des, NetScope*,
int expr_width, bool) const;
Expand All @@ -406,7 +418,7 @@ class PEUnary : public PExpr {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);

virtual bool elaborate_sig(Design*des, NetScope*scope) const;

Expand All @@ -415,6 +427,9 @@ class PEUnary : public PExpr {
virtual NetExpr*elaborate_pexpr(Design*des, NetScope*sc) const;
virtual verinum* eval_const(Design*des, NetScope*sc) const;

private:
NetExpr* elaborate_expr_bits_(NetExpr*operand, int expr_wid) const;

private:
char op_;
PExpr*expr_;
Expand All @@ -431,7 +446,7 @@ class PEBinary : public PExpr {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);

virtual bool elaborate_sig(Design*des, NetScope*scope) const;

Expand All @@ -455,8 +470,6 @@ class PEBinary : public PExpr {
NetExpr*elaborate_expr_base_mult_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const;
NetExpr*elaborate_expr_base_add_(Design*, NetExpr*lp, NetExpr*rp, int use_wid) const;

static void suppress_operand_sign_if_needed_(NetExpr*lp, NetExpr*rp);

};

/*
Expand All @@ -472,7 +485,7 @@ class PEBComp : public PEBinary {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&flag) const;
bool&flag);

NetExpr* elaborate_expr(Design*des, NetScope*scope,
int expr_width, bool sys_task_arg) const;
Expand All @@ -487,7 +500,7 @@ class PEBShift : public PEBinary {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&flag) const;
bool&flag);
virtual NetExpr*elaborate_expr(Design*des, NetScope*,
int expr_width, bool sys_task_arg) const;
};
Expand All @@ -506,7 +519,7 @@ class PETernary : public PExpr {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);

virtual bool elaborate_sig(Design*des, NetScope*scope) const;

Expand Down Expand Up @@ -548,7 +561,7 @@ class PECallFunction : public PExpr {
virtual unsigned test_width(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);

private:
pform_name_t path_;
Expand All @@ -561,7 +574,7 @@ class PECallFunction : public PExpr {
unsigned test_width_sfunc_(Design*des, NetScope*scope,
unsigned min, unsigned lval,
ivl_variable_type_t&expr_type,
bool&unsized_flag) const;
bool&unsized_flag);
};

#endif
2 changes: 1 addition & 1 deletion PGate.h
Expand Up @@ -80,7 +80,7 @@ class PGate : public LineInfo {
bool as_net_flag =false) const;

unsigned pin_count() const { return pins_? pins_->count() : 0; }
const PExpr*pin(unsigned idx) const { return (*pins_)[idx]; }
PExpr*pin(unsigned idx) const { return (*pins_)[idx]; }

strength_t strength0() const;
strength_t strength1() const;
Expand Down
2 changes: 1 addition & 1 deletion Statement.h
Expand Up @@ -99,7 +99,7 @@ class PAssign_ : public Statement {
virtual ~PAssign_() =0;

const PExpr* lval() const { return lval_; }
const PExpr* rval() const { return rval_; }
PExpr* rval() const { return rval_; }

protected:
NetAssign_* elaborate_lval(Design*, NetScope*scope) const;
Expand Down
4 changes: 3 additions & 1 deletion design_dump.cc
Expand Up @@ -343,7 +343,9 @@ void NetCLShift::dump_node(ostream&o, unsigned ind) const

void NetCompare::dump_node(ostream&o, unsigned ind) const
{
o << setw(ind) << "" << "LPM_COMPARE (NetCompare): " << name() << endl;
o << setw(ind) << "" << "LPM_COMPARE (NetCompare "
<< (get_signed()? "signed" : "unsigned") << "): "
<< name() << endl;
dump_node_pins(o, ind+4);
dump_obj_attr(o, ind+4);
}
Expand Down

0 comments on commit 1a3e655

Please sign in to comment.