From d17eb092f620d217f08ae7fb27122bb30799eaf4 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Tue, 11 Aug 2020 12:13:21 -0400 Subject: - Changed the spacing format to now store the number of spaces, and tabs before the current token. Along with also now storing a sub-token count which is used in case the token's secondary id is meant to be treated as a sub-token. - Added suppor for saving the number of blank lines before the current tokenized line. --- asmmon.c | 178 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 98 insertions(+), 80 deletions(-) (limited to 'asmmon.c') diff --git a/asmmon.c b/asmmon.c index 79a9862..6b71ac3 100644 --- a/asmmon.c +++ b/asmmon.c @@ -112,19 +112,31 @@ char *showbits(uint64_t value, uint8_t bitnum, uint8_t dbg) { } +static inline uint8_t isopdone(token *t) { + switch (t->id) { + case TOK_OF : + case TOK_HEX : + case TOK_BIN : + case TOK_DEC : + case TOK_CHAR: + case TOK_EXPR: return 0; + default : return 1; + } +} + void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, uint64_t address, uint8_t dbg) { - line *s = (!all) ? find_line(start, dbg) : lines ; - line *e = (!all) ? find_line( end, dbg) : last_line; + line *s = (!all) ? find_line(start, dbg) : lines; + line *e = (!all) ? find_line( end, dbg) : NULL; uint8_t j = 0; uint8_t flags = 0; uint8_t isstr; uint8_t iscom; uint8_t iscm = 0; - uint8_t fall = 0; uint8_t bitnum; uint8_t opsize = 0; uint8_t spaces; uint8_t tabs; + char mne_lower[4]; char ch[6]; do { @@ -132,29 +144,48 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u token *t = s->tok; uint8_t am = 0xFF; uint8_t rs = 0xFF; + uint8_t am_done = 1; + uint8_t op_done = 1; + uint16_t bline = s->bline; + for (; bline; bline--) { + putchar('\n'); + } if (dbg) { printf("list(): "); } if (ln) { - printf("%u\t\t", s->linenum); + printf("%5u\t\t", s->linenum); } else if (addr) { printf("$%"PRIX64":\t\t", s->addr); } - spaces = s->sspace; - tabs = s->stab; - while (spaces || tabs) { - if (spaces) { - putchar(' '); - spaces--; + while (t) { + if (am != 0xFF && op_done && t->id != TOK_RS) { + switch (am) { + case IMM : putchar('#'); am_done = 1; break; + case IND : + case INDX: + case INDY: putchar('('); am_done = 0; break; + case ZMY : + case ZMX : am_done = 0; break; + case BREG: putchar('b'); am_done = 1; break; + } + am = (am_done) ? 0xFF : am; } - if (tabs) { - putchar('\t'); - tabs--; + spaces = t->space; + tabs = t->tab; + while (spaces || tabs) { + if (spaces) { + putchar(' '); + spaces--; + } + if (tabs) { + putchar('\t'); + tabs--; + } } - } - while (t && t->id != TOK_COMMENT) { switch (t->id) { - case TOK_DIR : printf(".%s ", dir_t[t->type] ); break; + case TOK_DIR : printf(".%s", dir_t[t->type]); break; + case TOK_RS : printf("%s", rs_t[t->type]); break; case TOK_OPCODE: for (; j < 3; j++) { mne_lower[j] = tolower(mne[t->byte][j]); @@ -163,19 +194,6 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u j = 0; printf("%s", mne_lower); am = t->type; - if (t->next && t->next->id == TOK_RS) { - t = t->next; - rs = t->type; - printf("%s", rs_t[t->type]); - } - putchar(' '); - switch (am) { - case IMM : putchar('#'); break; - case IND : - case INDX: - case INDY: putchar('('); break; - case BREG: putchar('b'); break; - } break; case TOK_OF: switch (t->type) { @@ -191,18 +209,16 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u printf("%s", (t->sym) ? t->sym->name : "unknown"); if (t->id == TOK_LABEL) { putchar(':'); - } else if (t == s->tok && t->id == TOK_SYM) { - printf(" = "); } break; case TOK_HEX: if (t->id == TOK_HEX) { - printf("$%02"PRIX64, t->qword); + printf("$%0*"PRIX64, t->digits, t->qword); } else if (t->id == TOK_DEC) { - case TOK_DEC: printf( "%"PRIu64, t->qword); + case TOK_DEC: printf( "%0*"PRIu64, t->digits, t->qword); } else if (t->id == TOK_BIN) { - case TOK_BIN: if (rs != 0xFF) { - bitnum = (rs << 3); + case TOK_BIN: if (t->digits) { + bitnum = t->digits; } else { opsize = 1; opsize = (t->qword > 0x000000FF) ? 2 : opsize; @@ -238,15 +254,14 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u if (t->next) { switch (t->next->id) { case TOK_STRING: - case TOK_HEX: - case TOK_BIN: - case TOK_DEC: - case TOK_CHAR: - printf(", "); - break; + case TOK_HEX : + case TOK_BIN : + case TOK_DEC : + case TOK_CHAR : putchar(','); break; } } break; + case TOK_COMMENT: printf(";%s", (t->str) ? t->str : ""); break; case TOK_EXPR: switch (t->type) { case EXPR_PLUS : putchar('+'); break; @@ -258,50 +273,49 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u case EXPR_OR : putchar('|'); break; } break; + } - t = t->next; - } - if (am != 0xFF) { - if (fall) { - fall = 0; - } - switch (am) { - case INDX: - case ZMX: - printf(", x"); - if (am == ZMX) { - break; + if (t->subspace || t->subtab) { + spaces = t->subspace; + tabs = t->subtab; + while (spaces || tabs) { + if (spaces) { + putchar(' '); + spaces--; } - fall = 1; - /* Falls Through. */ - case INDY: - fall = !fall; - /* Falls Through. */ - case IND: - putchar(')'); - if (!fall) { - break; + if (tabs) { + putchar('\t'); + tabs--; } - /* Falls Through. */ - case ZMY: - printf(", y"); - break; + } } - } - spaces = s->espace; - tabs = s->etab; - while (spaces || tabs) { - if (spaces) { - putchar(' '); - spaces--; + if (t->next && !isopdone(t)) { + op_done = isopdone(t->next); } - if (tabs) { - putchar('\t'); - tabs--; + if (am != 0xFF && !am_done && op_done) { + switch (am) { + case INDX: + case ZMX : + printf(", x"); + if (am == ZMX) { + break; + } + /* Falls Through. */ + case INDY: + case IND : + putchar(')'); + if (am == IND) { + break; + } + case ZMY : printf(", y"); break; + } + am = 0xFF; + am_done = 1; } - } - if (t && t->id == TOK_COMMENT) { - printf(";%s", (t->str) ? t->str : ""); + if (t == s->tok && t->id == TOK_SYM) { + putchar('='); + } + t = t->next; } puts(""); s = s->next; @@ -339,6 +353,7 @@ int asmmon(const char *fn) { uint8_t dbg = 0; uint8_t isinclude = 0; uint16_t tmp_lineidx = 0; + uint16_t bline = 0; while (!done) { char *cmd; char *arg = malloc(sizeof(char *)*128); @@ -534,9 +549,12 @@ int asmmon(const char *fn) { case 0xFF: break; default: - address = lex(lex_line, address, dbg); + address = lex(lex_line, address, bline, dbg); + bline = 0; break; } + } else if (lex_line[0] == '\n') { + bline++; } } free(path); -- cgit v1.2.3-13-gbd6f