diff --git a/mach/proto/mcg/map.c b/mach/proto/mcg/map.c deleted file mode 100644 index 228cf8bcc..000000000 --- a/mach/proto/mcg/map.c +++ /dev/null @@ -1,58 +0,0 @@ -#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 : */ diff --git a/mach/proto/mcg/map.h b/mach/proto/mcg/map.h deleted file mode 100644 index bf9d9e8e3..000000000 --- a/mach/proto/mcg/map.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MAP_H -#define MAP_H - -struct map_node -{ - void* left; - void* right; -}; - -#define _MAP(MODIFIER, NAME) \ - MODIFIER struct map_node* NAME; \ - MODIFIER int NAME##_count; \ - MODIFIER int NAME##_max - -#define MAP(NAME) _MAP(, NAME) -#define STATICMAP(NAME) _MAP(static, NAME) - -#define MAP_SET(MAP, LEFT, RIGHT) \ - map_set(&MAP, &MAP##_count, &MAP##_max, LEFT, RIGHT) - -extern void map_set(struct map_node** map, int* count, int* max, void* left, void* right); -extern void map_add(struct map_node** map, int* count, int* max, void* left, void* right); - -#endif - - diff --git a/mach/proto/mcg/pass_convertstackops.c b/mach/proto/mcg/pass_convertstackops.c index fd18ab67b..adbe25068 100644 --- a/mach/proto/mcg/pass_convertstackops.c +++ b/mach/proto/mcg/pass_convertstackops.c @@ -1,6 +1,6 @@ #include "mcg.h" -STATICMAP(graph); +static MAPOF(struct basicblock, struct basicblock) graph; static ARRAYOF(struct ir) pops; static ARRAYOF(struct ir) pushes; @@ -46,7 +46,7 @@ static bool collect_outputs_cb(struct ir* ir, void* user) struct basicblock* caller = user; if (ir->opcode == IR_BLOCK) - MAP_SET(graph, caller, ir->u.bvalue); + map_addp(&graph, caller, ir->u.bvalue); return false; } @@ -54,7 +54,7 @@ static void make_bb_graph(struct procedure* proc) { int i, j; - graph_count = 0; + graph.count = 0; for (i=0; iblocks.count; i++) { struct basicblock* bb = proc->blocks.item[i]; @@ -78,11 +78,11 @@ static void convert_block(struct procedure* proc, struct basicblock* bb) /* Abort unless *every* successor block of this one starts with a pop * of the same size... */ - for (i=0; isize != lastpush->size)) @@ -92,11 +92,11 @@ static void convert_block(struct procedure* proc, struct basicblock* bb) /* Also abort unless *every* predecessor block of the one we've * just found *also* ends in a push of the same size. */ - for (j=0; jsize != lastpush->size)) diff --git a/modules/src/data/build.lua b/modules/src/data/build.lua index 7250f4f72..f9af7c519 100644 --- a/modules/src/data/build.lua +++ b/modules/src/data/build.lua @@ -6,4 +6,3 @@ clibrary { }, } - diff --git a/modules/src/data/map.c b/modules/src/data/map.c new file mode 100644 index 000000000..d75284762 --- /dev/null +++ b/modules/src/data/map.c @@ -0,0 +1,58 @@ +#include +#include +#include "map.h" + +static void append(void* mapp, void* left, void* right) +{ + struct map* map = mapp; + struct map_node* node; + + if (map->count == map->max) + { + int newmax = (map->max == 0) ? 8 : (map->max * 2); + struct map_node* newarray = realloc(map->item, newmax * sizeof(*newarray)); + + map->max = newmax; + map->item = newarray; + } + + node = &map->item[map->count]; + map->count++; + + node->left = left; + node->right = right; +} + +void map_putp(void* mapp, void* left, void* right) +{ + struct map* map = mapp; + int i; + + for (i=0; icount; i++) + { + struct map_node* node = &map->item[i]; + if (node->left == left) + { + node->right = right; + return; + } + } + + append(map, left, right); +} + +void map_addp(void* mapp, void* left, void* right) +{ + struct map* map = mapp; + int i; + + for (i=0; icount; i++) + { + struct map_node* node = &map->item[i]; + if ((node->left == left) && (node->right == right)) + return; + } + + append(map, left, right); +} + diff --git a/modules/src/data/map.h b/modules/src/data/map.h new file mode 100644 index 000000000..859618bd7 --- /dev/null +++ b/modules/src/data/map.h @@ -0,0 +1,30 @@ +#ifndef MAP_H +#define MAP_H + +struct map_node +{ + void* left; + void* right; +}; + +/* Danger, Will Robinson! The type and the macro must be compatible. */ + +struct map +{ + struct map_node* item; + int count; + int max; +}; + +#define MAPOF(LEFT, RIGHT) \ + struct { \ + struct { LEFT* left; RIGHT* right; }* item; \ + int count; \ + int max; \ + } + +extern void map_putp(void* map, void* left, void* right); +extern void map_addp(void* map, void* left, void* right); + +#endif +