*/
#ifdef HAVE_CONFIG_H
-# include <config.h>
+# include "config.h"
#endif
+#ifdef HAVE_STRING_H
# include <string.h>
+#endif
# include "irprog_t.h"
# include "irgraph_t.h"
ir_prog *new_ir_prog (void) {
ir_prog *res;
- res = (ir_prog *) malloc (sizeof(ir_prog));
- memset(res, 0, sizeof(res));
+ res = xmalloc (sizeof(*res));
+ memset(res, 0, sizeof(*res));
irp = res;
- /* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
+ /* res->obst = xmalloc (sizeof(*res->obst)); */
res->graphs = NEW_ARR_F (ir_graph *, 0);
res->pseudo_graphs = NEW_ARR_F (ir_graph *, 0);
res->types = NEW_ARR_F (type *, 0);
}
/* Removes irg from the list or irgs, shrinks the list by one. */
-void remove_irp_irg(ir_graph *irg){
- int i;
+void remove_irp_irg_from_list(ir_graph *irg){
+ int i, found = false;
assert(irg);
- free_ir_graph(irg);
for (i = 0; i < (ARR_LEN (irp->graphs)); i++) {
if (irp->graphs[i] == irg) {
+ found = true;
for(; i < (ARR_LEN (irp->graphs)) - 1; i++) {
irp->graphs[i] = irp->graphs[i+1];
}
break;
}
}
+ if (!found) {
+ for (i = 0; i < (ARR_LEN (irp->pseudo_graphs)); i++) {
+ if (irp->pseudo_graphs[i] == irg) {
+ for(; i < (ARR_LEN (irp->pseudo_graphs)) - 1; i++) {
+ irp->pseudo_graphs[i] = irp->pseudo_graphs[i+1];
+ }
+ ARR_SETLEN(ir_graph*, irp->pseudo_graphs, (ARR_LEN(irp->pseudo_graphs)) - 1);
+ break;
+ }
+ }
+ }
+}
+
+/* Removes irg from the list or irgs, shrinks the list by one. */
+void remove_irp_irg(ir_graph *irg){
+ assert(irg);
+ free_ir_graph(irg);
+ remove_irp_irg_from_list(irg);
}
int (get_irp_n_irgs)(void) {
/* Returns the ir graph at position pos of all graphs (including
pseudo graphs). Visits first graphs, then pseudo graphs. */
ir_graph *get_irp_allirg(int pos) {
- int n_irgs = get_irp_n_irgs();
- if (pos < n_irgs)
+ int n_irgs = ARR_LEN((irp)->graphs);
+ assert(0 <= pos);
+ if (pos < n_irgs) {
return (irp)->graphs[pos];
- else
+ } else {
return get_irp_pseudo_irg(pos-n_irgs);
+ }
}