diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-07-25 02:52:33 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-07-25 02:52:33 +0200 |
| commit | c1e767700fc14fbe385a9a8d9ad0cfa4d5315c35 (patch) | |
| tree | 41a8b648e48ca58f9edb67ebeda5cd82a0519f6a /tpu.c | |
| parent | d07257c9e92e8697915aaf40070c6228a5855104 (diff) | |
| download | tis100-c1e767700fc14fbe385a9a8d9ad0cfa4d5315c35.tar.gz tis100-c1e767700fc14fbe385a9a8d9ad0cfa4d5315c35.zip | |
Add label support to curses source view
Diffstat (limited to 'tpu.c')
| -rw-r--r-- | tpu.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -62,6 +62,7 @@ djb_hash(const char *str) void label_map_init(struct label_map *map) { + memset(map->labels, 0, sizeof(char *) * TPU_MAX_INST); memset(map->buckets, 0, sizeof(void *) * LABEL_MAP_BUCKETS); } @@ -103,6 +104,8 @@ label_map_add(struct label_map *map, const char *name, size_t pc) pos = label_map_link_pos(map, name); if (*pos) return false; + if (map->labels[pc]) return false; + *pos = link = malloc(sizeof(struct label_map_link)); if (!link) die("malloc:"); link->label = strdup(name); @@ -112,6 +115,8 @@ label_map_add(struct label_map *map, const char *name, size_t pc) link->pc = pc; link->next = NULL; + map->labels[pc] = link->label; + return true; } @@ -163,7 +168,7 @@ tpu_init(struct tpu *tpu) tpu->acc = 0; tpu->bak = 0; tpu->inst_cnt = 0; - label_map_init(&tpu->labels); + label_map_init(&tpu->label_map); tpu->last = -1; tpu->io_port = -1; @@ -176,7 +181,7 @@ tpu_deinit(struct tpu *tpu) { int i; - label_map_deinit(&tpu->labels); + label_map_deinit(&tpu->label_map); for (i = 0; i < TPU_MAX_INST; i++) { if (tpu->insts[i].ops[0].type == OP_LABEL) free(tpu->insts[i].ops[0].val.label); @@ -353,7 +358,7 @@ tpu_jmp_label(struct tpu *tpu, const char *label) { size_t pc; - pc = label_map_get(&tpu->labels, label); + pc = label_map_get(&tpu->label_map, label); if (pc >= TPU_MAX_INST) abort(); tpu->pc = (uint8_t) pc; } |
