Skip to content

Commit 154d2de

Browse files
committed
fragmented channel may not be fully utilized; more user input validation
1 parent 9cd5057 commit 154d2de

File tree

4 files changed

+80
-42
lines changed

4 files changed

+80
-42
lines changed

channel.cc

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static void _hse_record_ids (act_channel_state *ch,
4040
if (!b) {
4141
int off;
4242
int type;
43+
bool found;
4344

4445
b = ihash_add (ch->fH, (long)ac);
4546

@@ -73,18 +74,29 @@ static void _hse_record_ids (act_channel_state *ch,
7374
ntmp = newtmp;
7475
}
7576

76-
off = sc->getLocalOffset (ntmp, mysi, &type);
77-
Assert (type == 0, "HSE in channel has non-boolean ops?");
78-
if (myc != c && (off < 0 && ((-off) & 1))) {
77+
if (sc->hasLocalOffset (ntmp, mysi)) {
78+
off = sc->getLocalOffset (ntmp, mysi, &type);
79+
found = true;
80+
}
81+
else {
82+
found = false;
83+
}
84+
Assert (!found || type == 0, "HSE in channel has non-boolean ops?");
85+
if (found && (myc != c && (off < 0 && ((-off) & 1)))) {
7986
stateinfo_t *saved = sc->cursi();
8087
sc->setsi (mysi);
8188
off = myc->getGlobalOffset (off, 0);
8289
b->i = off;
8390
sc->setsi (saved);
8491
}
8592
else {
86-
off = myc->getGlobalOffset (off, 0);
87-
b->i = off;
93+
if (found) {
94+
off = myc->getGlobalOffset (off, 0);
95+
b->i = off;
96+
}
97+
else {
98+
b->i = -1;
99+
}
88100
}
89101

90102
if (ntmp != ch_name) {
@@ -448,36 +460,38 @@ int ChanMethods::runMethod (ActSimCore *sim,
448460
fatal_error ("%s: Internal error running method %d", ch->ct->getName(),
449461
idx);
450462
}
451-
v = ch->_dummy->getBool (b->i);
452-
if (_ops[idx].op[from].type == CHAN_OP_BOOL_T) {
453-
if (v != 1) {
463+
if (b->i != -1) {
464+
v = ch->_dummy->getBool (b->i);
465+
if (_ops[idx].op[from].type == CHAN_OP_BOOL_T) {
466+
if (v != 1) {
454467
#ifdef DUMP_ALL
455-
printf ("nm:g#%d := 1\n", b->i);
456-
#endif
457-
ch->_dummy->setBool (b->i, 1);
458-
v = -1;
468+
printf ("nm:g#%d := 1\n", b->i);
469+
#endif
470+
ch->_dummy->setBool (b->i, 1);
471+
v = -1;
472+
}
459473
}
460-
}
461-
else {
462-
if (v != 0) {
463-
ch->_dummy->setBool (b->i, 0);
474+
else {
475+
if (v != 0) {
476+
ch->_dummy->setBool (b->i, 0);
464477
#ifdef DUMP_ALL
465-
printf ("nm:g#%d := 0\n", b->i);
478+
printf ("nm:g#%d := 0\n", b->i);
466479
#endif
467-
v = -1;
480+
v = -1;
481+
}
468482
}
469-
}
470-
if (v == -1) {
471-
const ActSim::watchpt_bucket *nm;
472-
if ((nm = sim->chkWatchPt (0, b->i))) {
473-
BigInt tmpv;
474-
ch->_dummy->msgPrefix ();
475-
printf (" %s := %c\n", nm->s, _ops[idx].op[from].type == CHAN_OP_BOOL_T ?
476-
'1' : '0');
477-
tmpv = (_ops[idx].op[from].type == CHAN_OP_BOOL_T ? 1 : 0);
478-
sim->recordTrace (nm, 0, ACT_CHAN_IDLE, tmpv);
483+
if (v == -1) {
484+
const ActSim::watchpt_bucket *nm;
485+
if ((nm = sim->chkWatchPt (0, b->i))) {
486+
BigInt tmpv;
487+
ch->_dummy->msgPrefix ();
488+
printf (" %s := %c\n", nm->s, _ops[idx].op[from].type == CHAN_OP_BOOL_T ?
489+
'1' : '0');
490+
tmpv = (_ops[idx].op[from].type == CHAN_OP_BOOL_T ? 1 : 0);
491+
sim->recordTrace (nm, 0, ACT_CHAN_IDLE, tmpv);
492+
}
493+
ch->_dummy->boolProp (b->i);
479494
}
480-
ch->_dummy->boolProp (b->i);
481495
}
482496
from++;
483497
break;

chpsim.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,16 +2960,26 @@ BigInt ChpSim::exprEval (Expr *e)
29602960
c = xid->Canonical (_frag_ch->ct->CurScope());
29612961
b = ihash_lookup (_frag_ch->fH, (long)c);
29622962
Assert (b, "Error during channel registration");
2963-
l.setWidth (1);
2964-
l.setVal (0, _sc->getBool (b->i));
2965-
if (_sc->getBool (b->i) == 2) {
2966-
ActId *tid;
2967-
msgPrefix ();
2963+
if (b->i < 0) {
2964+
msgPrefix();
29682965
printf ("CHP model: Boolean variable `");
2969-
tid = c->toid();
2970-
tid->Print (stdout);
2971-
delete tid;
2972-
printf ("' is X\n");
2966+
xid->Print (stdout);
2967+
printf ("' was optimized out; treating as 0.\n");
2968+
l.setWidth (1);
2969+
l.setVal (0, 0);
2970+
}
2971+
else {
2972+
l.setWidth (1);
2973+
l.setVal (0, _sc->getBool (b->i));
2974+
if (_sc->getBool (b->i) == 2) {
2975+
ActId *tid;
2976+
msgPrefix ();
2977+
printf ("CHP model: Boolean variable `");
2978+
tid = c->toid();
2979+
tid->Print (stdout);
2980+
delete tid;
2981+
printf ("' is X\n");
2982+
}
29732983
}
29742984
}
29752985
}

core.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,8 @@ int ActSimCore::getLocalOffset (act_connection *c, stateinfo_t *si, int *type,
18251825

18261826
int ActSimCore::hasLocalOffset (ActId *id, stateinfo_t *si)
18271827
{
1828-
act_connection *c = id->Canonical (si->bnl->cur);
1828+
act_connection *c = id->Canonical (si->bnl->cur, true);
1829+
if (!c) return 0;
18291830
return hasLocalOffset (c, si);
18301831
}
18311832

@@ -1882,7 +1883,14 @@ int ActSimCore::getLocalOffset (ActId *id, stateinfo_t *si, int *type, int *widt
18821883
act_connection *c;
18831884
Scope *sc = si->bnl->cur;
18841885

1885-
c = id->Canonical (sc);
1886+
c = id->Canonical (sc, true);
1887+
if (!c) {
1888+
act_error_ctxt (stderr);
1889+
fprintf (stderr, "Identifier `");
1890+
id->Print (stderr);
1891+
fprintf (stderr, "' used, but not used in the design hierarchy selected.\n");
1892+
fatal_error ("Error in initializer block?");
1893+
}
18861894
return getLocalOffset (c, si, type, width);
18871895
}
18881896

main.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,14 @@ static int id_obj_to_siminfo (ActSimObj *obj,
625625
return 0;
626626
}
627627

628-
c = id->Canonical (si->bnl->cur);
628+
// validate the ID first, then call canonical pointer
629+
c = id->Canonical (si->bnl->cur, true);
630+
if (!c) {
631+
fprintf (stderr, "Identifier `");
632+
id->Print (stderr);
633+
fprintf (stderr, "' not found in the design.\n");
634+
return 0;
635+
}
629636
Assert (c, "What?");
630637

631638
int type, offset;
@@ -814,7 +821,6 @@ int process_set (int argc, char **argv)
814821
fprintf (stderr, "Integers are unsigned.\n");
815822
return LISP_RET_ERROR;
816823
}
817-
818824
BigInt before = rd;
819825
rd.setWidth (otmp->getWidth());
820826
if (before != rd) {

0 commit comments

Comments
 (0)