Skip to content

Commit

Permalink
array in struct
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanohar committed Apr 26, 2023
1 parent ce888ad commit 227f528
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 62 deletions.
21 changes: 21 additions & 0 deletions actsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,13 @@ class ActSimCore {
}

int useOrAllocTrIndex (const char *s) {
/* have we loaded this format already? */
int i = trIndex (s);
if (i != -1) {
return i;
}

/* is there an open slot to load the format? */
for (i=0; i < TRACE_NUM_FORMATS; i++) {
if (!_trname[i]) {
_trfn[i] = act_trace_load_format (s, NULL);
Expand All @@ -532,6 +535,24 @@ class ActSimCore {
return i;
}
}

/* can we free an earlier loaded format and replace it with this
one? */
for (i=0; i < TRACE_NUM_FORMATS; i++) {
if (!_tr[i]) {
act_extern_trace_func_t *tmp = act_trace_load_format (s, NULL);
if (!tmp) {
return -1;
}
FREE (_trname[i]);
act_trace_close_format (_trfn[i]);
_trfn[i] = tmp;
_trname[i] = Strdup (s);
return i;
}
}

/* all attempts failed */
return -1;
}

Expand Down
211 changes: 149 additions & 62 deletions chpsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3469,9 +3469,26 @@ static void _mark_vars_used (ActSimCore *_sc, ActId *id, struct iHashtable *H)
}

for (int i=0; i < d->getNumPorts(); i++) {
InstType *xit;
tmp = new ActId (d->getPortName(i));
tail->Append (tmp);
_mark_vars_used (_sc, id, H);
xit = d->getPortType (i);

if (xit->arrayInfo()) {
Arraystep *as = xit->arrayInfo()->stepper();
while (!as->isend()) {
Array *a = as->toArray();
tmp->setArray (a);
_mark_vars_used (_sc, id, H);
delete a;
as->step();
}
tmp->setArray (NULL);
delete as;
}
else {
_mark_vars_used (_sc, id, H);
}
tail->prune();
delete tmp;
}
Expand Down Expand Up @@ -3805,20 +3822,49 @@ static void _add_deref_struct (ActSimCore *sc,
InstType *it = d->getPortType (i);
tmp = new ActId (d->getPortName(i));
tail->Append (tmp);
if (TypeFactory::isStructure (it)) {
Data *x = dynamic_cast<Data *> (it->BaseType());
Assert (x, "What?");
_add_deref_struct (sc, id, x, ds);

if (it->arrayInfo()) {
Arraystep *as = it->arrayInfo()->stepper();
while (!as->isend()) {
Array *a = as->toArray();
tmp->setArray (a);

if (TypeFactory::isStructure (it)) {
Data *x = dynamic_cast<Data *> (it->BaseType());
Assert (x, "What?");
_add_deref_struct (sc, id, x, ds);
}
else {
ds->idx[ds->offset] = sc->getLocalOffset (id, sc->cursi(),
&ds->idx[ds->offset+1],
&ds->idx[ds->offset+2]);
if (TypeFactory::isEnum (it)) {
ds->idx[ds->offset+1] = 2;
ds->idx[ds->offset+2] = TypeFactory::enumNum (it);
}
ds->offset += 3;
}
delete a;
as->step();
}
tmp->setArray (NULL);
}
else {
ds->idx[ds->offset] = sc->getLocalOffset (id, sc->cursi(),
&ds->idx[ds->offset+1],
&ds->idx[ds->offset+2]);
if (TypeFactory::isEnum (it)) {
ds->idx[ds->offset+1] = 2;
ds->idx[ds->offset+2] = TypeFactory::enumNum (it);
if (TypeFactory::isStructure (it)) {
Data *x = dynamic_cast<Data *> (it->BaseType());
Assert (x, "What?");
_add_deref_struct (sc, id, x, ds);
}
else {
ds->idx[ds->offset] = sc->getLocalOffset (id, sc->cursi(),
&ds->idx[ds->offset+1],
&ds->idx[ds->offset+2]);
if (TypeFactory::isEnum (it)) {
ds->idx[ds->offset+1] = 2;
ds->idx[ds->offset+2] = TypeFactory::enumNum (it);
}
ds->offset += 3;
}
ds->offset += 3;
}
tail->prune ();
delete tmp;
Expand All @@ -3833,31 +3879,39 @@ static void _add_deref_struct2 (Data *d,
{
for (int i=0; i < d->getNumPorts(); i++) {
InstType *it = d->getPortType (i);
if (TypeFactory::isStructure (it)) {
Data *x = dynamic_cast<Data *> (it->BaseType());
Assert (x, "What?");
_add_deref_struct2 (x, idx, off_i, off_b, off);
int sz = 1;

if (it->arrayInfo()) {
sz = it->arrayInfo()->size();
}
else if (TypeFactory::isIntType (it)) {
idx[*off] = *off_i;
idx[*off+1] = 1;
idx[*off+2] = TypeFactory::bitWidth (it);

if (TypeFactory::isEnum (it)) {
idx[*off+1] = 2;
idx[*off+2] = TypeFactory::enumNum (it);
while (sz > 0) {
if (TypeFactory::isStructure (it)) {
Data *x = dynamic_cast<Data *> (it->BaseType());
Assert (x, "What?");
_add_deref_struct2 (x, idx, off_i, off_b, off);
}
else if (TypeFactory::isIntType (it)) {
idx[*off] = *off_i;
idx[*off+1] = 1;
idx[*off+2] = TypeFactory::bitWidth (it);

if (TypeFactory::isEnum (it)) {
idx[*off+1] = 2;
idx[*off+2] = TypeFactory::enumNum (it);
}

*off_i = *off_i + 1;
*off += 3;
}
else {
Assert (TypeFactory::isBoolType (it), "Hmm");
idx[*off] = *off_b;
idx[*off+1] = 0;
idx[*off+2] = 1;
*off_b = *off_b + 1;
*off += 3;
*off_i = *off_i + 1;
*off += 3;
}
else {
Assert (TypeFactory::isBoolType (it), "Hmm");
idx[*off] = *off_b;
idx[*off+1] = 0;
idx[*off+2] = 1;
*off_b = *off_b + 1;
*off += 3;
}
sz--;
}
}
}
Expand Down Expand Up @@ -5323,11 +5377,16 @@ int expr_multires::_count (Data *d)
int n = 0;
Assert (d, "What?");
for (int i=0; i < d->getNumPorts(); i++) {
if (TypeFactory::isStructure (d->getPortType(i))) {
n += _count (dynamic_cast<Data *>(d->getPortType(i)->BaseType()));
int sz = 1;
InstType *it = d->getPortType (i);
if (it->arrayInfo()) {
sz = it->arrayInfo()->size();
}
if (TypeFactory::isStructure (it)) {
n += _count (dynamic_cast<Data *>(d->getPortType(i)->BaseType()))*sz;
}
else {
n++;
n += sz;
}
}
return n;
Expand All @@ -5337,19 +5396,33 @@ void expr_multires::_init_helper (Data *d, int *pos)
{
Assert (d, "What?");
for (int i=0; i < d->getNumPorts(); i++) {
if (TypeFactory::isStructure (d->getPortType(i))) {
_init_helper (dynamic_cast<Data *>(d->getPortType(i)->BaseType()), pos);
int sz = 1;
InstType *it = d->getPortType (i);
if (it->arrayInfo()) {
sz = it->arrayInfo()->size();
}
else if (TypeFactory::isBoolType (d->getPortType(i))) {
v[*pos].setWidth (1);
v[*pos].setVal (0, 0);
*pos = (*pos) + 1;
if (TypeFactory::isStructure (it)) {
while (sz > 0) {
_init_helper (dynamic_cast<Data *>(it->BaseType()), pos);
sz--;
}
}
else if (TypeFactory::isIntType (d->getPortType(i))) {
v[*pos].setWidth (1);
v[*pos].setVal (0, 0);
v[*pos].setWidth (TypeFactory::bitWidth (d->getPortType(i)));
*pos = *pos + 1;
else if (TypeFactory::isBoolType (it)) {
while (sz > 0) {
v[*pos].setWidth (1);
v[*pos].setVal (0, 0);
*pos = (*pos) + 1;
sz--;
}
}
else if (TypeFactory::isIntType (it)) {
while (sz > 0) {
v[*pos].setWidth (1);
v[*pos].setVal (0, 0);
v[*pos].setWidth (TypeFactory::bitWidth (it));
*pos = *pos + 1;
sz--;
}
}
}
}
Expand All @@ -5372,24 +5445,38 @@ void expr_multires::_fill_helper (Data *d, ActSimCore *sc, int *pos, int *oi, in
{
Assert (d, "Hmm");
for (int i=0; i < d->getNumPorts(); i++) {
if (TypeFactory::isStructure (d->getPortType(i))) {
_fill_helper (dynamic_cast<Data *>(d->getPortType(i)->BaseType()),
sc, pos, oi, ob);
int sz = 1;
InstType *it = d->getPortType (i);
if (it->arrayInfo()) {
sz = it->arrayInfo()->size();
}
else if (TypeFactory::isBoolType (d->getPortType(i))) {
if (sc->getBool (*ob)) {
v[*pos].setVal (0, 1);
if (TypeFactory::isStructure (it)) {
while (sz > 0) {
_fill_helper (dynamic_cast<Data *>(it->BaseType()),
sc, pos, oi, ob);
sz--;
}
else {
v[*pos].setVal (0, 0);
}
else if (TypeFactory::isBoolType (it)) {
while (sz > 0) {
if (sc->getBool (*ob)) {
v[*pos].setVal (0, 1);
}
else {
v[*pos].setVal (0, 0);
}
*ob = *ob + 1;
*pos = (*pos) + 1;
sz--;
}
*ob = *ob + 1;
*pos = (*pos) + 1;
}
else if (TypeFactory::isIntType (d->getPortType(i))) {
v[*pos] = *(sc->getInt (*oi));
*oi = *oi + 1;
*pos = *pos + 1;
else if (TypeFactory::isIntType (it)) {
while (sz > 0) {
v[*pos] = *(sc->getInt (*oi));
*oi = *oi + 1;
*pos = *pos + 1;
sz--;
}
}
}
}
Expand Down

0 comments on commit 227f528

Please sign in to comment.