diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-12-25 16:49:51 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-12-25 16:49:51 +0100 |
| commit | 238ac5ab6c47bfe0c9cda1490f97f2d7f5d3eaf6 (patch) | |
| tree | 8bc0450c20060c262743ee986854741531a19f68 /tpu.c | |
| parent | 8ec5b039472f9fbe24f2eb1c5d8e66a7551a33fd (diff) | |
| download | tis100-238ac5ab6c47bfe0c9cda1490f97f2d7f5d3eaf6.tar.gz tis100-238ac5ab6c47bfe0c9cda1490f97f2d7f5d3eaf6.zip | |
Add support for prefix labels
Diffstat (limited to 'tpu.c')
| -rw-r--r-- | tpu.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -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; |
