Skip to content

Commit d7bc142

Browse files
committed
fully propagate refines
1 parent 4dee705 commit d7bc142

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

act/body.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ ActBody *ActBody_Print::Clone(ActNamespace *replace, ActNamespace *newns)
18811881
}
18821882

18831883

1884-
void ActBody::updateInstType (list_t *namelist, InstType *it)
1884+
void ActBody::updateInstType (list_t *namelist, InstType *it, bool handle_subref)
18851885
{
18861886
ActBody *b = this;
18871887
listitem_t *li;
@@ -1908,7 +1908,7 @@ void ActBody::updateInstType (list_t *namelist, InstType *it)
19081908
else if (dynamic_cast<ActBody_Loop *> (b)) {
19091909
ActBody_Loop *bl = dynamic_cast<ActBody_Loop *> (b);
19101910
if (bl->getBody()) {
1911-
bl->getBody()->updateInstType (namelist, it);
1911+
bl->getBody()->updateInstType (namelist, it, handle_subref);
19121912
}
19131913
}
19141914
else {
@@ -1919,12 +1919,24 @@ void ActBody::updateInstType (list_t *namelist, InstType *it)
19191919
else if (dynamic_cast<ActBody_Genloop *> (b)) {
19201920
sel = dynamic_cast<ActBody_Genloop *> (b)->getGC();
19211921
}
1922+
else if (dynamic_cast<ActBody_Lang *> (b) && handle_subref) {
1923+
ActBody_Lang *l = dynamic_cast<ActBody_Lang *> (b);
1924+
if (l->gettype() == ActBody_Lang::LANG_REFINE) {
1925+
act_refine *r = (act_refine *) l->getlang();
1926+
if (r->b && r->nsteps <= ActNamespace::Act()->getRefSteps ()) {
1927+
ActNamespace::Act()->decRefSteps (r->nsteps);
1928+
r->b->updateInstType (namelist, it, true);
1929+
ActNamespace::Act()->incRefSteps (r->nsteps);
1930+
}
1931+
}
1932+
sel = NULL;
1933+
}
19221934
else {
19231935
sel = NULL;
19241936
}
19251937
while (sel) {
19261938
if (sel->getBody()) {
1927-
sel->getBody()->updateInstType (namelist, it);
1939+
sel->getBody()->updateInstType (namelist, it, handle_subref);
19281940
}
19291941
sel = sel->getNext();
19301942
}

act/body.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,13 @@ class ActBody {
119119
* instance type to the new one specified. This is used to support
120120
* overrides.
121121
* @param namelist is a list of names (char * list)
122-
* @param it is the updated instance type for the specified identifiers
122+
* @param it is the updated instance type for the specified
123+
* identifiers
124+
* @param handle_subref is a flag. If it is true, then the update
125+
* method also handles a nested refine within the body; otherwise
126+
* those are ignored.
123127
*/
124-
void updateInstType (list_t *namelist, InstType *it);
128+
void updateInstType (list_t *namelist, InstType *it, bool handle_subref);
125129

126130
/**
127131
* @return the saved away line number associated with a body

act/defs.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ override_one_spec: user_type [ "+" ] bare_id_list ";"
648648
}
649649
/* walk through the body, editing instances */
650650
if (b) {
651-
b->updateInstType ($3, $1);
651+
b->updateInstType ($3, $1, false);
652652
if (port_override_asserts) {
653653
b->Tail()->Append (port_override_asserts);
654654
}

act/types.cc

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,17 +2827,19 @@ void Data::synthStructMacro ()
28272827
void UserDef::_apply_ref_overrides (ActBody *b, ActBody *srch)
28282828
{
28292829
list_t *ol = NULL;
2830+
28302831
while (srch) {
28312832
ActBody_Lang *l = dynamic_cast<ActBody_Lang *> (srch);
28322833
if (l) {
28332834
if (l->gettype() == ActBody_Lang::LANG_REFINE) {
28342835
act_refine *r = (act_refine *) l->getlang();
2835-
if (acceptRefine (ActNamespace::Act()->getRefSteps(), r->nsteps) &&
2836-
r->overrides) {
2836+
if (acceptRefine (ActNamespace::Act()->getRefSteps(), r->nsteps)) {
28372837
listitem_t *oi, *oprev;
28382838
if (!ol) {
28392839
ol = list_new ();
28402840
}
2841+
2842+
/* insert the override into a sorted list of refinement levels */
28412843
oi = list_first (ol);
28422844
oprev = NULL;
28432845
while (oi) {
@@ -2870,14 +2872,33 @@ void UserDef::_apply_ref_overrides (ActBody *b, ActBody *srch)
28702872
}
28712873
/* apply overrides in refinement order */
28722874
if (ol) {
2873-
for (listitem_t *oi = list_first (ol); oi; oi = list_next (oi)) {
2874-
act_refine *ri = (act_refine *) list_value (oi);
2875-
refine_override *rl = ri->overrides;
2875+
for (listitem_t *oi = list_first (ol); oi; oi = list_next (oi)) {
2876+
act_refine *ri = (act_refine *) list_value (oi);
2877+
refine_override *rl = ri->overrides;
2878+
28762879
while (rl) {
2877-
b->updateInstType (rl->ids, rl->it);
2878-
rl = rl->next;
2879-
}
2880-
}
2880+
b->updateInstType (rl->ids, rl->it, false);
2881+
rl = rl->next;
2882+
}
2883+
2884+
/* also propagate the refinement to the bodies of the earlier
2885+
refinement bodies! */
2886+
2887+
/** XXX: this doesn't correctly handle nested refinement blocks **/
2888+
if (ri->overrides) {
2889+
for (listitem_t *op = list_first (ol); op != oi; op = list_next (op)) {
2890+
act_refine *rp = (act_refine *) list_value (op);
2891+
rl = ri->overrides;
2892+
Assert (rp->nsteps <= ActNamespace::Act()->getRefSteps(), "What?");
2893+
ActNamespace::Act()->decRefSteps (rp->nsteps);
2894+
while (rl) {
2895+
rp->b->updateInstType (rl->ids, rl->it, true);
2896+
rl = rl->next;
2897+
}
2898+
ActNamespace::Act()->incRefSteps (rp->nsteps);
2899+
}
2900+
}
2901+
}
28812902
}
28822903
}
28832904

0 commit comments

Comments
 (0)