diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-07-25 05:20:54 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-07-25 05:20:54 +0200 |
| commit | 41760436d528552d64122bb0c837f4d8274a0bdd (patch) | |
| tree | e8acbd7bb0663f1c76bb6a490c37c7e6338613ba | |
| parent | f621bed8f9bf20eca167d7cfa40840992c26da09 (diff) | |
| download | tis100-41760436d528552d64122bb0c837f4d8274a0bdd.tar.gz tis100-41760436d528552d64122bb0c837f4d8274a0bdd.zip | |
Fix label_map case insensitivity and allow numbers in label names
| -rw-r--r-- | asm.c | 10 | ||||
| -rw-r--r-- | test/test.asm | 2 | ||||
| -rw-r--r-- | tpu.c | 5 |
3 files changed, 10 insertions, 7 deletions
@@ -6,7 +6,9 @@ #include <string.h> #include <stdint.h> -#define NAMEALPH "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_" +#define TEXTALPH "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_" +#define NUMALPH "0123456789" +#define NAMEALPH TEXTALPH NUMALPH #define WHITESPACE " \t\v\r\n," enum asm_tok { @@ -178,14 +180,16 @@ tok_next(struct asm_tokenizer *tok) } else if (*s == '#') { tok->off += strlen(tok->linebuf + tok->off); return TOK_COMMENT; - } else if (len && strspn(s, NAMEALPH) == len-1 && s[len-1] == ':') { + } else if (len && strchr(TEXTALPH, *s) + && strspn(s, NAMEALPH) == len-1 && s[len-1] == ':') { s[len-1] = '\0'; return TOK_LABEL; } else if (*s == 'X' && atoi(s+1) > 0) { return TOK_XPOS; } else if (*s == 'Y' && atoi(s+1) > 0) { return TOK_YPOS; - } else if (strspn(s, NAMEALPH) == strlen(s)) { + } else if (strchr(TEXTALPH, *s) + && strspn(s, NAMEALPH) == strlen(s)) { return TOK_NAME; } else { die("load: line %lu, invalid token '%s'", tok->lineno, s); diff --git a/test/test.asm b/test/test.asm index 53340a4..d15a653 100644 --- a/test/test.asm +++ b/test/test.asm @@ -6,9 +6,11 @@ tpu X1 Y1 end tpu X2 Y1 +LABEL8: mov LEFT, ACC add 1 mov ACC, RIGHT + jmp LABEL8 end tpu X3 Y1 @@ -89,7 +89,7 @@ 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 && strcmp((*link)->label, name)) + while (*link && strcasecmp((*link)->label, name)) link = &(*link)->next; return link; @@ -99,7 +99,6 @@ bool label_map_add(struct label_map *map, const char *name, size_t pc) { struct label_map_link **pos, *link; - char *c; pos = label_map_link_pos(map, name); if (*pos) return false; @@ -110,8 +109,6 @@ label_map_add(struct label_map *map, const char *name, size_t pc) if (!link) die("malloc:"); link->label = strdup(name); if (!link->label) die("strdup:"); - for (c = link->label; *c; c++) - *c = (char) tolower(*c); link->pc = pc; link->next = NULL; |
