generator uses this to put all temporary data onto the procedure heap.
struct valueusage
{
- struct vreg* vreg;
bool input : 1;
bool output : 1;
bool through : 1;
PMAPOF(struct value, struct value) equals_constraint;
struct hashtable* valueusage;
-
struct hashtable* vregmapping; /* value -> vreg */
PMAPOF(struct vreg, struct vreg) copies;
};
extern uint32_t value_hash_function(void* key);
extern bool value_comparison_function(void* key1, void* key2);
#define HASHTABLE_OF_VALUES \
- { value_hash_function, value_comparison_function }
+ { value_hash_function, value_comparison_function, \
+ proc_alloc, proc_free }
extern const struct hashtable empty_hashtable_of_values;
struct ir
struct procedure* current_proc;
struct heap proc_heap;
+void* proc_alloc(size_t nmemb, size_t size)
+{
+ return heap_alloc(&proc_heap, nmemb, size);
+}
+
+void proc_free(void* ptr)
+{
+ /* do nothing; objects will leak until the heap is freed */
+}
+
static void print_blocks(char k)
{
int i;
emit_procedure(proc);
- heap_free(&proc_heap);
#endif
+ heap_free(&proc_heap);
}
/* vim: set sw=4 ts=4 expandtab : */
ARRAYOF(struct hreg) usedregs;
};
+extern struct heap proc_heap;
+extern void* proc_alloc(size_t nmemb, size_t size);
+extern void proc_free(void* ptr);
+
extern void procedure_compile(struct procedure* proc);
extern void procedure_update_bb_graph(struct procedure* proc);
extern struct procedure* current_proc;
-extern struct heap proc_heap;
#endif
if (!ht->cmpfunction)
ht->cmpfunction = standard_pointer_comparison_function;
+ if (!ht->allocfunction)
+ ht->allocfunction = calloc;
+
+ if (!ht->freefunction)
+ ht->freefunction = free;
+
if (!ht->buckets)
- ht->buckets = calloc(ht->num_buckets, sizeof(struct hashnode*));
+ ht->buckets = ht->allocfunction(ht->num_buckets, sizeof(struct hashnode*));
}
void hashtable_empty(struct hashtable* ht)
void hashtable_reset(struct hashtable* ht)
{
+ lazy_init(ht);
hashtable_empty(ht);
- free(ht->buckets);
+ ht->freefunction(ht->buckets);
ht->buckets = NULL;
}
int i;
ht->num_buckets = num_buckets;
- ht->buckets = calloc(num_buckets, sizeof(struct hashnode*));
+ ht->buckets = ht->allocfunction(num_buckets, sizeof(struct hashnode*));
for (i=0; i<old_num_buckets; i++)
{
}
}
- free(old_buckets);
+ ht->freefunction(old_buckets);
}
static struct hashnode** findnodep(struct hashtable* ht, void* key)
return hashtable_put(ht, key, value);
}
- *hnp = calloc(1, sizeof(struct hashnode));
+ *hnp = ht->allocfunction(1, sizeof(struct hashnode));
ht->size++;
}
struct hashnode* hn = *hnp;
void* value = hn->value;
*hnp = hn->next;
- free(hn);
+ ht->freefunction(hn);
ht->size--;
return value;
}
struct hashnode* hn = *hnp;
void* value = hn->value;
*hnp = hn->next;
- free(hn);
+ ht->freefunction(hn);
ht->size--;
return value;
}
typedef uint32_t hashfunction_t(void* key);
typedef bool cmpfunction_t(void* key1, void* key2);
+typedef void* allocfunction_t(size_t nmemb, size_t size);
+typedef void freefunction_t(void* ptr);
extern uint32_t standard_pointer_hash_function(void* key);
extern bool standard_pointer_comparison_function(void* key1, void* key2);
{
hashfunction_t* hashfunction;
cmpfunction_t* cmpfunction;
+ allocfunction_t* allocfunction;
+ freefunction_t* freefunction;
unsigned int num_buckets; /* power of 2 */
struct hashnode** buckets;
int size;
heap->next = old->next;
free(old);
}
-}
\ No newline at end of file
+}