diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-05-08 12:22:25 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-05-08 12:22:25 -0400 |
commit | 9cb8e4f83b49355610134b152df129b2f68ce9fe (patch) | |
tree | 31972078120b6cae8950f6acb67e4f758df738ce | |
parent | 04cc80c19d763f6de4ef5c3baac5026e5e6969b3 (diff) |
Start implementing whole file lexing.
This will eventually replace the per-line lexer.
-rw-r--r-- | asmmon.c | 32 | ||||
-rw-r--r-- | asmmon.h | 12 | ||||
-rw-r--r-- | assemble.c | 25 |
3 files changed, 67 insertions, 2 deletions
@@ -23,6 +23,9 @@ symbol *last_sym = 0; fixup *fixups = 0; fixup *last_fix = 0; +strln *first_strln = 0; +strln *last_strln = 0; + static char tstr[2048]; void viewmem(uint64_t address) { @@ -347,6 +350,30 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u } while (s != e && s); } +strln *make_strln(char *str, int blanks) { + strln *new_strln = malloc(sizeof(strln)); + + if (new_strln == NULL) { + return NULL; + } + + new_strln->next = NULL; + new_strln->prev = NULL; + new_strln->str = str; + new_strln->blanks = blanks; + + if (last_strln == NULL) { + first_strln = new_strln; + } else { + new_strln->prev = last_strln; + last_strln->next = new_strln; + } + + last_strln = new_strln; + + return new_strln; +} + int asmmon(const char *fn) { FILE *fp = NULL; FILE *fp2 = NULL; @@ -616,6 +643,11 @@ int asmmon(const char *fn) { default : break; } if (!is_valid) { + size_t len = strlen(lex_line); + char *tmp = malloc(len+1); + memcpy(tmp, lex_line, len); + tmp[len] = '\0'; + strln *dummy = make_strln(tmp, bline); address = lex(lex_line, address, bline, dbg); bline = 0; } @@ -10,6 +10,7 @@ typedef struct sym symbol; typedef struct fix fixup; typedef struct inst instruction; typedef struct expr expr; +typedef struct strln strln; struct tok { @@ -47,8 +48,6 @@ struct ln { uint64_t addr; /* The address of this line. */ }; - - struct fix { fixup *next; symbol *s; @@ -89,6 +88,12 @@ struct expr { } value; }; +struct strln { + strln *next; + strln *prev; + char *str; + int blanks; +}; extern char lexeme[]; extern char *string[]; @@ -105,6 +110,9 @@ extern symbol *last_loc; extern fixup *fixups; extern fixup *last_fix; +extern strln *first_strln; +extern strln *last_strln; + extern uint8_t lex_type; enum dir { @@ -1304,6 +1304,23 @@ static void free_fixups(fixup *f) { } } +void free_strlns(strln *root) { + strln *line; + if (root != NULL) { + line = root; + root = root->next; + if (line->str != NULL) { + free(line->str); + } + line->blanks = 0; + line->prev = NULL; + line->next = NULL; + free(line); + line = NULL; + free_strlns(root); + } +} + uint64_t get_tokmem(token *t) { uint64_t i = 0; for (; t; t = t->next, i++); @@ -1324,15 +1341,23 @@ void cleanup() { /*fix_symtree(lines);*/ free_lines(lines); lines = NULL; + last_line = NULL; } if (symbols) { /*print_symtree(symbols, 0);*/ free_symbols(symbols); symbols = NULL; + last_sym = NULL; } if (fixups) { free_fixups(fixups); fixups = NULL; + last_fix = NULL; + } + if (first_strln) { + free_strlns(first_strln); + first_strln = NULL; + last_strln = NULL; } while (i < stridx || i < comidx) { if (i < stridx && string[i]) { |