Handle null objects in general.

This commit is contained in:
Stephen Williams 2012-11-21 17:48:46 -08:00
parent e7c6829512
commit 79903ecadd
9 changed files with 50 additions and 3 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@ tags
TAGS
cscope.*
*.patch
*.orig
# Object files and libraries
*.[oa]

View File

@ -494,6 +494,8 @@ class PENull : public PExpr {
virtual void dump(ostream&) const;
virtual unsigned test_width(Design*des, NetScope*scope,
width_mode_t&mode);
virtual NetExpr*elaborate_expr(Design*des, NetScope*scope,
ivl_type_t type, unsigned flags) const;
virtual NetExpr*elaborate_expr(Design*des, NetScope*,
unsigned expr_wid,
unsigned flags) const;

View File

@ -4015,8 +4015,7 @@ NetExpr* PENew::elaborate_expr(Design*des, NetScope*scope,
/*
* This method should never actually be called.
*/
NetExpr* PENew::elaborate_expr(Design*des, NetScope*scope,
unsigned, unsigned flags) const
NetExpr* PENew::elaborate_expr(Design*, NetScope*, unsigned, unsigned) const
{
ivl_assert(*this, 0);
return 0;
@ -4053,6 +4052,13 @@ unsigned PENull::test_width(Design*, NetScope*, width_mode_t&)
return expr_width_;
}
NetExpr* PENull::elaborate_expr(Design*, NetScope*, ivl_type_t, unsigned) const
{
NetENull*tmp = new NetENull;
tmp->set_line(*this);
return tmp;
}
NetExpr* PENull::elaborate_expr(Design*, NetScope*, unsigned, unsigned) const
{
NetENull*tmp = new NetENull;

View File

@ -2385,6 +2385,9 @@ NetProc* PAssign::elaborate(Design*des, NetScope*scope) const
handle it with this code instead. */
rv = elaborate_rval_(des, scope, lv->sig()->net_type());
} else if (lv->more==0 && dynamic_cast<const PENull*> (rval())) {
rv = elaborate_rval_(des, scope, lv->sig()->net_type());
} else if (lv->more==0 && dynamic_cast<const PENewClass*> (rval())) {
rv = elaborate_rval_(des, scope, lv->sig()->net_type());

View File

@ -73,6 +73,12 @@ static int eval_class_new(ivl_expr_t ex)
return 0;
}
static int eval_object_null(ivl_expr_t ex)
{
fprintf(vvp_out, " %%null;\n");
return 0;
}
int draw_eval_object(ivl_expr_t ex)
{
switch (ivl_expr_type(ex)) {
@ -88,6 +94,10 @@ int draw_eval_object(ivl_expr_t ex)
ivl_expr_value(ex));
return 0;
}
case IVL_EX_NULL:
return eval_object_null(ex);
default:
fprintf(vvp_out, "; ERROR: Invalid expression type %u\n", ivl_expr_type(ex));
return 1;

View File

@ -153,6 +153,7 @@ extern bool of_NEW_DARRAY(vthread_t thr, vvp_code_t code);
extern bool of_NOOP(vthread_t thr, vvp_code_t code);
extern bool of_NOR(vthread_t thr, vvp_code_t code);
extern bool of_NORR(vthread_t thr, vvp_code_t code);
extern bool of_NULL(vthread_t thr, vvp_code_t code);
extern bool of_OR(vthread_t thr, vvp_code_t code);
extern bool of_ORR(vthread_t thr, vvp_code_t code);
extern bool of_PAD(vthread_t thr, vvp_code_t code);

View File

@ -201,6 +201,7 @@ static const struct opcode_table_s opcode_table[] = {
{ "%noop", of_NOOP, 0, {OA_NONE, OA_NONE, OA_NONE} },
{ "%nor", of_NOR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%nor/r", of_NORR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%null", of_NULL, 0, {OA_NONE, OA_NONE, OA_NONE} },
{ "%or", of_OR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%or/r", of_ORR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%pad", of_PAD, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },

View File

@ -386,7 +386,14 @@ supports run-time calculated delays.
* %delete/obj <var-label>
Arrange for the dynamic object at the target label to be deleted.
This has no effect on the object or string stack.
This has no effect on the object or string stack. Note that this is
the same as:
%null ;
%store/obj <var-label>
but that idiom is expected to be common enough that it warrants an
optimized shorthand.
* %disable <scope-label>
@ -802,6 +809,11 @@ The actual operation performed is the inverted or of all the bits in
the vector.
* %null
Push a null object and push it to the object stack. The null object
can be used with any class or darray object, so it is not typed.
* %or <dst>, <src>, <wid>
Perform the bitwise or of the vectors. Each bit in the <dst> is

View File

@ -4146,6 +4146,17 @@ bool of_NORR(vthread_t thr, vvp_code_t cp)
return true;
}
/*
* Push a null to the object stack.
*/
bool of_NULL(vthread_t thr, vvp_code_t cp)
{
vvp_object_t tmp;
thr->push_object(tmp);
return true;
}
bool of_ANDR(vthread_t thr, vvp_code_t cp)
{
assert(cp->bit_idx[0] >= 4);