void copy_gtrans(GTrans *from, GTrans *to) /* copies a transition */ { to->to = from->to; copy_set(from->pos, to->pos, 1); copy_set(from->neg, to->neg, 1); copy_set(from->final, to->final, 0); }
int simplify_gtrans() /* simplifies the transitions */ { int changed = 0; GState *s; GTrans *t, *t1; if(tl_stats) getrusage(RUSAGE_SELF, &tr_debut); for(s = gstates->nxt; s != gstates; s = s->nxt) { t = s->trans->nxt; while(t != s->trans) { /* tries to remove t */ copy_gtrans(t, s->trans); t1 = s->trans->nxt; while ( !((t != t1) && (t1->to == t->to) && included_set(t1->pos, t->pos, 1) && included_set(t1->neg, t->neg, 1) && (included_set(t->final, t1->final, 0) /* acceptance conditions of t are also in t1 or may be ignored */ || (tl_simp_scc && ((s->incoming != t->to->incoming) || in_set(bad_scc, s->incoming))))) ) t1 = t1->nxt; if(t1 != s->trans) { /* remove transition t */ GTrans *free = t->nxt; t->to = free->to; copy_set(free->pos, t->pos, 1); copy_set(free->neg, t->neg, 1); copy_set(free->final, t->final, 0); t->nxt = free->nxt; if(free == s->trans) s->trans = t; free_gtrans(free, 0, 0); changed++; } else t = t->nxt; }
ATrans *dup_trans(ATrans *trans) /* returns the copy of a transition */ { ATrans *result; if(!trans) return trans; result = emalloc_atrans(); copy_set(trans->to, result->to, 0); copy_set(trans->pos, result->pos, 1); copy_set(trans->neg, result->neg, 1); return result; }
/** * Find in/out */ void find_inout() { struct block *b = first_block; struct block *tmpb = (struct block *) malloc(sizeof(struct block)); int i; int change = 1; int oldlen; calc_pred(); DEBUG(print_pred()); while(b) { b->defin.ini = 0; copy_set(b, OUT_SET, b, GEN_SET); b = b->next; } while(change) { change = 0; b = first_block; while(b) { for(i = 0; i < b->predi; i++) union_set(b, IN_SET, b->pred[i], OUT_SET); copy_set(tmpb, IN_SET, b, IN_SET); sub_set(tmpb, IN_SET, b, KILL_SET); union_set(tmpb, IN_SET, b, GEN_SET); oldlen = b->defin.outi; // According to algorithm I should do what is commented belove /* copy_set(oldb, OUT_SET, b, OUT_SET); copy_set(b, OUT_SET, tmpb, IN_SET); if(!equal_set(oldb, OUT_SET, b, OUT_SET)) change = 1; */ // but since out[b] = gen[b] we can do // 1. union agains copy // 2. compare set's length to see if it's changed union_set(b, OUT_SET, tmpb, IN_SET); if(oldlen != b->defin.outi) change = 1; b = b -> next; } } }