ack/mach/proto/mcg/map.c
David Given ed67d427c9 Replaced the block splicer with a trivial block eliminator (which rewrites
jumps to blocks which contain only a jump). Don't bother storing the bb graph
in the ir nodes; we can find it on demand by walking the tree instead ---
slower, but much easier to understand and more robust. Added a terrible map
library.
2016-09-23 23:59:15 +02:00

59 lines
1 KiB
C

#include "mcg.h"
static void extend(struct map_node** map, int* count, int* max)
{
if (*count == *max)
{
int newmax = (*max == 0) ? 8 : (*max * 2);
struct map_node* newmap = realloc(*map, newmax * sizeof(struct map_node));
if (!newmap)
fatal("memory allocation failure");
*max = newmax;
*map = newmap;
}
}
void map_set(struct map_node** map, int* count, int* max, void* left, void* right)
{
int i;
struct map_node* node;
for (i=0; i<*count; i++)
{
node = &(*map)[i];
if (node->left == left)
{
node->right = right;
return;
}
}
extend(map, count, max);
node = &(*map)[*count];
node->left = left;
node->right = right;
(*count)++;
}
void map_add(struct map_node** map, int* count, int* max, void* left, void* right)
{
int i;
struct map_node* node;
for (i=0; i<*count; i++)
{
node = &(*map)[i];
if ((node->left == left) && (node->right == right))
return;
}
extend(map, count, max);
node = &(*map)[*count];
node->left = left;
node->right = right;
(*count)++;
}
/* vim: set sw=4 ts=4 expandtab : */