/* replace oldinst with newinst, remove oldinst from ilist, and return oldinst (newinst can be a chain of insts) */ instr_t * instrlist_replace(instrlist_t *ilist, instr_t *oldinst, instr_t *newinst) { instr_t *where; CLIENT_ASSERT(oldinst != NULL, "instrlist_replace: oldinst cannot be NULL"); CLIENT_ASSERT(instr_get_prev(newinst) == NULL, "instrlist_replace: cannot add middle of list"); where = instr_get_prev(oldinst); instrlist_remove(ilist, oldinst); if (where) instrlist_postinsert(ilist, where, newinst); else instrlist_prepend(ilist, newinst); return oldinst; }
/* Inserts inst as a non-application instruction into ilist after "where" */ void instrlist_meta_postinsert(instrlist_t *ilist, instr_t *where, instr_t *inst) { instr_set_ok_to_mangle(inst, false); instrlist_postinsert(ilist, where, inst); }