summaryrefslogtreecommitdiffstats
path: root/tpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'tpu.c')
-rw-r--r--tpu.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/tpu.c b/tpu.c
index 9fb87c3..caa6730 100644
--- a/tpu.c
+++ b/tpu.c
@@ -63,8 +63,7 @@ djb_hash(const char *str)
void
label_map_init(struct label_map *map)
{
- memset(map->labels, 0, sizeof(char *) * TPU_MAX_INST_CNT);
- memset(map->buckets, 0, sizeof(void *) * LABEL_MAP_BUCKETS);
+ memset(map, 0, sizeof(struct label_map));
}
void
@@ -77,11 +76,13 @@ label_map_deinit(struct label_map *map)
link = map->buckets[i];
while (link) {
next = link->next;
- free(link->label);
free(link);
link = next;
}
}
+
+ for (i = 0; i < TPU_MAX_INST_CNT; i++)
+ free(map->labels[i].str);
}
static struct label_map_link **
@@ -90,31 +91,30 @@ label_map_link_pos(struct label_map *map, const char *name)
struct label_map_link **link;
link = &map->buckets[djb_hash(name) % LABEL_MAP_BUCKETS];
- while (*link && strcasecmp((*link)->label, name))
+ while (*link && strcasecmp(map->labels[(*link)->pc].str, name))
link = &(*link)->next;
return link;
}
bool
-label_map_add(struct label_map *map, const char *name, int pc)
+label_map_add(struct label_map *map, const char *name, int pc, bool prefix)
{
struct label_map_link **pos, *link;
pos = label_map_link_pos(map, name);
if (*pos) return false;
- if (map->labels[pc]) return false;
+ if (map->labels[pc].str) return false;
+ map->labels[pc].str = strdup(name);
+ if (!map->labels[pc].str) die("strdup:");
+ map->labels[pc].prefix = prefix;
*pos = link = malloc(sizeof(struct label_map_link));
if (!link) die("malloc:");
- link->label = strdup(name);
- if (!link->label) die("strdup:");
link->pc = pc;
link->next = NULL;
- map->labels[pc] = link->label;
-
return true;
}
@@ -217,7 +217,7 @@ tpu_init(struct tpu *tpu)
tpu->acc = 0;
tpu->bak = 0;
tpu->inst_cnt = 0;
- tpu->label_cnt = 0;
+ tpu->rows = 0;
label_map_init(&tpu->label_map);
tpu->last = -1;