- add functions for global (ir_prog) resource management
[libfirm] / ir / ir / irprog.c
index 5ca65ce..22dff63 100644 (file)
@@ -24,9 +24,7 @@
  * @date     2000
  * @version  $Id$
  */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #ifdef HAVE_STRING_H
 # include <string.h>
@@ -51,11 +49,9 @@ ir_prog *get_irp(void) { return irp; }
 /**
  *  Create a new incomplete ir_prog.
  */
-static ir_prog *new_incomplete_ir_prog(void) {
-       ir_prog *res;
-
-       res = xmalloc(sizeof(*res));
-       memset(res, 0, sizeof(*res));
+static ir_prog *new_incomplete_ir_prog(void)
+{
+       ir_prog *res = XMALLOCZ(ir_prog);
 
        res->kind           = k_ir_prog;
        res->graphs         = NEW_ARR_F(ir_graph *, 0);
@@ -69,7 +65,10 @@ static ir_prog *new_incomplete_ir_prog(void) {
        res->max_irg_idx    = 0;
 
 #ifdef DEBUG_libfirm
-       res->max_node_nr = 0;
+       res->max_node_nr    = 0;
+#endif
+#ifndef NDEBUG
+       res->reserved_resources = 0;
 #endif
 
        return res;
@@ -434,3 +433,19 @@ ident *get_irp_asm(int pos) {
        assert(pos <= 0 && pos < get_irp_n_asms());
        return irp->global_asms[pos];
 }
+
+#ifndef NDEBUG
+void irp_reserve_resources(ir_prog *irp, ir_resources_t resources) {
+       assert((irp->reserved_resources & resources) == 0);
+       irp->reserved_resources |= resources;
+}
+
+void irp_free_resources(ir_prog *irp, ir_resources_t resources) {
+       assert((irp->reserved_resources & resources) == resources);
+       irp->reserved_resources &= ~resources;
+}
+
+ir_resources_t irp_resources_reserved(const ir_prog *irp) {
+       return irp->reserved_resources;
+}
+#endif