Skip to content

Commit

Permalink
initialize entire dynamic array
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanohar committed Oct 30, 2024
1 parent 55e2ad2 commit 9b54697
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 46 deletions.
85 changes: 39 additions & 46 deletions chpsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4215,69 +4215,62 @@ void ChpSim::_zeroStructure (struct chpsimderef *d)
Assert (d, "Hmm");
int *struct_info;
int struct_len;
int sz = 1;

state_counts ts;
ActStatePass::getStructCount (d->d, &ts);

if (d->range) {
/* array deref */
for (int i=0; i < d->range->nDims(); i++) {
BigInt res = exprEval (d->chp_idx[i]);
d->idx[i] = res.getVal (0);
}
int x = d->range->Offset (d->idx);
if (x == -1) {
fprintf (stderr, "In: ");
if (getName()) {
getName()->Print (stderr);
}
else {
fprintf (stderr, "<>");
}
fprintf (stderr, " [ %s ]\n", _proc ? _proc->getName() : "-global-");
fprintf (stderr, "\tAccessing index ");
for (int i=0; i < d->range->nDims(); i++) {
fprintf (stderr, "[%d]", d->idx[i]);
}
fprintf (stderr, " from ");
d->cx->toid()->Print (stderr);
fprintf (stderr, "\n");
fatal_error ("Array out of bounds!");
}
int off_i, off_b, off;
// doesn't matter, we need to actually zero everything out!
MALLOC (struct_info, int, 3*(ts.numInts() + ts.numBools()));
off_i = d->offset + x*ts.numInts();
off_b = d->width + x*ts.numBools();
off_i = d->offset;
off_b = d->width;
off = 0;
sz = d->range->size();
_add_deref_struct2 (d->d, struct_info, &off_i, &off_b, &off);
}
else {
struct_info = d->idx;
}
struct_len = 3*(ts.numInts() + ts.numBools());
for (int i=0; i < struct_len/3; i++) {
int off = getGlobalOffset (struct_info[3*i],
struct_info[3*i+1] == 2 ?
1 : struct_info[3*i+1]);
if (struct_info[3*i+1] == 1) {
BigInt tmp;
tmp.setWidth (struct_info[3*i+2]);
tmp.toStatic ();
_sc->setInt (off, tmp);
}
else if (struct_info[3*i+1] == 2) {
/* enum */
BigInt tmpv (64, 0, 0);
tmpv.setVal (0, struct_info[3*i+2]);
tmpv.setWidth (_ceil_log2 (struct_info[3*i+2]));
tmpv.toStatic ();
_sc->setInt (off, tmpv);

while (sz > 0) {
for (int i=0; i < struct_len/3; i++) {
int off = getGlobalOffset (struct_info[3*i],
struct_info[3*i+1] == 2 ?
1 : struct_info[3*i+1]);
if (struct_info[3*i+1] == 1) {
BigInt tmp;
tmp.setWidth (struct_info[3*i+2]);
tmp.toStatic ();
_sc->setInt (off, tmp);
}
else if (struct_info[3*i+1] == 2) {
/* enum */
BigInt tmpv (64, 0, 0);
tmpv.setVal (0, struct_info[3*i+2]);
tmpv.setWidth (_ceil_log2 (struct_info[3*i+2]));
tmpv.toStatic ();
_sc->setInt (off, tmpv);
}
else {
Assert (struct_info[3*i+1] == 0, "What?");
}
}
else {
Assert (struct_info[3*i+1] == 0, "What?");
sz--;
if (sz > 0) {
for (int i=0; i < struct_len/3; i++) {
if (struct_info[3*i+1] == 1 || struct_info[3*i+1] == 2) {
// int or enum
struct_info[3*i] += ts.numInts();
}
else {
struct_info[3*i] += ts.numBools();
}
}
}
}

if (struct_info != d->idx) {
FREE (struct_info);
}
Expand Down
17 changes: 17 additions & 0 deletions test/116.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
deftype foo
(
int x;
int y;
int z
){}

defproc test ()
{
foo f1[20], f2[20];
int i;

chp {
i := 10;
*[ i > 0 -> f1[i] := f2[i]; log ("works now!"); i := i - 1 ]
}
}
1 change: 1 addition & 0 deletions test/runs/116.act.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WARNING: test<>: substituting chp model (requested prs, not found)
10 changes: 10 additions & 0 deletions test/runs/116.act.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ 20] <> works now!
[ 40] <> works now!
[ 60] <> works now!
[ 80] <> works now!
[ 100] <> works now!
[ 120] <> works now!
[ 140] <> works now!
[ 160] <> works now!
[ 180] <> works now!
[ 200] <> works now!

0 comments on commit 9b54697

Please sign in to comment.