From 07ab4971778cfe20f0e962d6dacb7aa14e529e5a Mon Sep 17 00:00:00 2001 From: Andre Fachat Date: Mon, 16 Oct 2023 12:56:57 +0200 Subject: [PATCH] start working on lint output --- xa/src/xa.c | 2 +- xa/src/xalisting.c | 115 +++++++++++++++++++++++++++------------------ xa/src/xalisting.h | 5 +- xa/src/xat.c | 3 -- 4 files changed, 74 insertions(+), 51 deletions(-) diff --git a/xa/src/xa.c b/xa/src/xa.c index 7b521b0..ff4c29b 100644 --- a/xa/src/xa.c +++ b/xa/src/xa.c @@ -945,7 +945,7 @@ static void usage(int default816, FILE *fp) " -l filename sets labellist filename, default is none\n" " -P filename sets filename for listing, default is none, '-' is stdout\n" " -F format sets format for listing, default is plain, 'html' is current only other\n" - " supported format\n" + " supported format. Use 'lint' resp. 'linthtml' for linted source output\n" " -r adds crossreference list to labellist (if `-l' given)\n" " -M allow ``:'' to appear in comments for MASM compatibility\n" " -Xcompatset set compatibility flags for other assemblers, known values are:\n" diff --git a/xa/src/xalisting.c b/xa/src/xalisting.c index 85440c9..952bf99 100644 --- a/xa/src/xalisting.c +++ b/xa/src/xalisting.c @@ -31,6 +31,8 @@ #include "xal.h" #include "xat.h" +#include "xalisting.h" + /*********************************************************************************************/ /* this is the listing code @@ -46,6 +48,7 @@ static int list_last_lineno = 0; /* current line number */ static char *list_filenamep = NULL; /* current file name pointer */ static int list_numbytes = 8; +static int list_lint = 0; static int list_string(char *buf, char *string); static int list_tokens(char *buf, signed char *input, int len); @@ -175,8 +178,17 @@ void list_flush() { void list_start(const char *formatname) { formatp = &def_format; - if (formatname != NULL && strcmp("html", formatname) == 0) { - formatp = &html_format; + if (formatname != NULL) { + if (strcmp("linthtml", formatname) == 0) { + formatp = &html_format; + list_setlint(); + } else + if (strcmp("html", formatname) == 0) { + formatp = &html_format; + } else + if (strcmp("lint", formatname) == 0) { + list_setlint(); + } } if (listfp != NULL) { @@ -195,6 +207,11 @@ void list_setbytes(int number_of_bytes_per_line) { list_numbytes = number_of_bytes_per_line; } +// set to lint mode +void list_setlint() { + list_lint = 1; +} + /* set line number for the coming listing output */ void list_line(int l) { list_lineno = l; @@ -208,7 +225,7 @@ void list_filename(char *fname) { list_last_lineno = 0; /* Hack */ - if (listfp != NULL) { + if (listfp != NULL && !list_lint) { fprintf(listfp, "\n%s\n\n", fname); } } @@ -284,8 +301,6 @@ void do_listing(signed char *listing, int listing_len, signed char *bincode, int // could be extended to include the preamble... if (formatp->start_line != NULL) formatp->start_line(); - buf = list_preamble(buf, list_lineno, lst_seg, lst_pc); - // check if we have labels, so we can adjust the max printable number of // bytes in the last line int num_last_line = 11; @@ -294,54 +309,62 @@ void do_listing(signed char *listing, int listing_len, signed char *bincode, int // we have label definition num_last_line = 8; } - int overflow = 0; - /* binary output (up to 8 byte. If more than 8 byte, print 7 plus "..." */ - n_hexb = bincode_len; - if (list_numbytes != 0 && n_hexb >= list_numbytes) { - n_hexb = list_numbytes-1; - overflow = 1; - } - for (i = 0; i < n_hexb; i++) { - buf = buf + list_byte(buf, bincode[i]); - buf = buf + list_sp(buf); - if ( (i%16) == 15) { - // make a break + if (list_lint) { + buf = buf + list_nchar(buf, ' ', (num_last_line - 8) * 3); + } else { + buf = list_preamble(buf, list_lineno, lst_seg, lst_pc); + + int overflow = 0; + + /* binary output (up to 8 byte. If more than 8 byte, print 7 plus "..." */ + n_hexb = bincode_len; + if (list_numbytes != 0 && n_hexb >= list_numbytes) { + n_hexb = list_numbytes-1; + overflow = 1; + } + for (i = 0; i < n_hexb; i++) { + buf = buf + list_byte(buf, bincode[i]); + buf = buf + list_sp(buf); + if ( (i%16) == 15) { + // make a break + buf[0] = 0; + fprintf(listfp, "%s\n", outline); + if (formatp->end_line != NULL) formatp->end_line(); + if (formatp->start_line != NULL) formatp->start_line(); + buf = outline; + buf = list_preamble(buf, list_lineno, lst_seg, lst_pc + i + 1); + } + } + if (overflow) { + // are we at the last byte? + if (n_hexb + 1 == bincode_len) { + // just print the last byte + buf = buf + list_byte(buf, bincode[i]); + buf = buf + list_sp(buf); + } else { + // display "..." + buf = buf + list_nchar(buf, '.', 3); + } + n_hexb++; + } + i = n_hexb % 16; + if (i > num_last_line) { + // make a break (Note: with original PC, as now the assembler text follows buf[0] = 0; fprintf(listfp, "%s\n", outline); if (formatp->end_line != NULL) formatp->end_line(); if (formatp->start_line != NULL) formatp->start_line(); buf = outline; - buf = list_preamble(buf, list_lineno, lst_seg, lst_pc + i + 1); - } - } - if (overflow) { - // are we at the last byte? - if (n_hexb + 1 == bincode_len) { - // just print the last byte - buf = buf + list_byte(buf, bincode[i]); - buf = buf + list_sp(buf); - } else { - // display "..." - buf = buf + list_nchar(buf, '.', 3); - } - n_hexb++; - } - i = n_hexb % 16; - if (i > num_last_line) { - // make a break (Note: with original PC, as now the assembler text follows - buf[0] = 0; - fprintf(listfp, "%s\n", outline); - if (formatp->end_line != NULL) formatp->end_line(); - if (formatp->start_line != NULL) formatp->start_line(); - buf = outline; - buf = list_preamble(buf, list_lineno, lst_seg, lst_pc); - i = 0; - } - i = num_last_line - i; - buf = buf + list_nchar(buf, ' ', i * 3); + buf = list_preamble(buf, list_lineno, lst_seg, lst_pc); + i = 0; + } + i = num_last_line - i; + buf = buf + list_nchar(buf, ' ', i * 3); - buf = buf + list_sp(buf); + buf = buf + list_sp(buf); + + } // end list_lint buf += list_tokens(buf, listing + 3, listing_len - 3); diff --git a/xa/src/xalisting.h b/xa/src/xalisting.h index 8505047..990f468 100644 --- a/xa/src/xalisting.h +++ b/xa/src/xalisting.h @@ -19,7 +19,7 @@ #ifndef __XA65_XALISTING_H__ #define __XA65_XALISTING_H__ -void list_start(char *formatname); //either NULL or "html" +void list_start(const char *formatname); //either NULL or "html" void list_end(); void list_flush(); // debug helper @@ -31,4 +31,7 @@ void list_filename(char *fname);/* set file name for the coming listing output * // list a single line/token set void do_listing(signed char *listing, int listing_len, signed char *bincode, int bincode_len); +void list_setbytes(int number_of_bytes_per_line); +void list_setlint(); + #endif /* __XA65_XALISTING_H__ */ diff --git a/xa/src/xat.c b/xa/src/xat.c index 9c9c4ad..8a4aeab 100644 --- a/xa/src/xat.c +++ b/xa/src/xat.c @@ -56,9 +56,6 @@ static void tg_hex(signed char*,int*,int*); static void tg_oct(signed char*,int*,int*); static void tg_bin(signed char*,int*,int*); static int t_p2(signed char *t, int *ll, int fl, int *al); -//static void do_listing(signed char *listing, int listing_len, signed char *bincode, int bincode_len); - -void list_setbytes(int number_of_bytes_per_line); /* assembly mnemonics and pseudo-op tokens */ /* ina and dea don't work yet */