From f75f5e12420f0d182a65d7a56daf4418f29753ed Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Sun, 10 May 2015 17:51:32 +0200 Subject: [PATCH] Change delimiters of local symbol blocks to be more like page 3-10 of the manual. Also, to make Kermit sources work, only increase the local symbol block counter if there actually was a local symbol used in the block. This way, conditional inclusions (which include source text only in the first pass) will have less potential for de-synchronisation between the passes. After all, if the generated internal local symbol names do not match, phase errors will result (showing themselves as strange label redefinition problems). --- assemble.c | 38 +++++++++++++++++++++++++++++++++----- assemble.h | 2 ++ assemble_globals.c | 4 +++- assemble_globals.h | 4 +++- macro11.c | 8 ++++++-- macros.c | 4 ++-- parse.c | 6 ++++++ 7 files changed, 55 insertions(+), 11 deletions(-) diff --git a/assemble.c b/assemble.c index 72bb9ad..235e33d 100644 --- a/assemble.c +++ b/assemble.c @@ -126,8 +126,9 @@ static int assemble( free(label); /* See if local symbol block should be incremented */ - if (!enabl_lsb && !local) - lsb++; + if (!enabl_lsb && !local) { + lsb = get_next_lsb(); + } cp = skipwhite(ncp); opcp = cp; @@ -358,6 +359,9 @@ static int assemble( return 0; } else { go_section(tr, sect_stack[sect_sp]); + if (!enabl_lsb) { + lsb = get_next_lsb(); + } sect_sp--; } return 1; @@ -647,7 +651,7 @@ static int assemble( enabl_ama = 1; else if (strcmp(label, "LSB") == 0) { enabl_lsb = 1; - lsb++; + lsb = get_next_lsb(); } else if (strcmp(label, "GBL") == 0) enabl_gbl = 1; free(label); @@ -661,9 +665,10 @@ static int assemble( label = get_symbol(cp, &cp, NULL); if (strcmp(label, "AMA") == 0) enabl_ama = 0; - else if (strcmp(label, "LSB") == 0) + else if (strcmp(label, "LSB") == 0) { + lsb = get_next_lsb(); enabl_lsb = 0; - else if (strcmp(label, "GBL") == 0) + } else if (strcmp(label, "GBL") == 0) enabl_gbl = 0; free(label); cp = skipdelim(cp); @@ -882,6 +887,9 @@ static int assemble( return 1; case P_ASECT: + if (!enabl_lsb) { + lsb = get_next_lsb(); + } go_section(tr, &absolute_section); return 1; @@ -993,6 +1001,9 @@ static int assemble( } } + if (!enabl_lsb) { + lsb = get_next_lsb(); + } go_section(tr, sect); return 1; @@ -1534,6 +1545,23 @@ static int assemble( return do_word(stack, tr, cp, 2); } +int get_next_lsb( + void) +{ + if (lsb_used) { + lsb_used = 0; + if (enabl_debug && lstfile) { + fprintf(lstfile, "get_next_lsb: lsb: %d becomes %d (= next_lsb)\n", lsb, next_lsb); + } + return next_lsb++; + } else { + if (enabl_debug && lstfile) { + fprintf(lstfile, "get_next_lsb: lsb: stays %d\n", lsb); + } + return lsb; + } +} + /* assemble_stack assembles the input stack. It returns the error count. */ diff --git a/assemble.h b/assemble.h index fcde6e8..369a007 100644 --- a/assemble.h +++ b/assemble.h @@ -13,5 +13,7 @@ int assemble_stack( STACK *stack, TEXT_RLD *tr); +int get_next_lsb( + void); #endif diff --git a/assemble_globals.c b/assemble_globals.c index b1ea31a..e7c1b4a 100644 --- a/assemble_globals.c +++ b/assemble_globals.c @@ -14,7 +14,9 @@ int radix = 8; /* The current input conversion radix */ int lsb = 0; /* The current local symbol section identifier */ -int last_lsb = 0; /* The last block in which a macro +int lsb_used = 0; /* Whether there was a local symbol using this lsb */ +int next_lsb = 0; /* The number of the next local symbol block */ +int last_macro_lsb = 0; /* The last block in which a macro automatic label was created */ int last_locsym = 32768; /* The last local symbol number generated */ diff --git a/assemble_globals.h b/assemble_globals.h index 0cda4e6..63fc0c7 100644 --- a/assemble_globals.h +++ b/assemble_globals.h @@ -28,7 +28,9 @@ extern int pass; /* The current assembly pass. 0 = first pass */ extern int stmtno; /* The current source line number */ extern int radix; /* The current input conversion radix */ extern int lsb; /* The current local symbol section identifier */ -extern int last_lsb; /* The last block in which a macro +extern int lsb_used; /* Whether there was a local symbol using this lsb */ +extern int next_lsb; /* The number of the next local symbol block */ +extern int last_macro_lsb; /* The last block in which a macro automatic label was created */ extern int last_locsym; /* The last local symbol number generated */ diff --git a/macro11.c b/macro11.c index 2bb74d0..ae235ba 100644 --- a/macro11.c +++ b/macro11.c @@ -322,7 +322,9 @@ int main( pass = 0; stmtno = 0; lsb = 0; - last_lsb = -1; + next_lsb = 1; + lsb_used = 0; + last_macro_lsb = -1; last_locsym = 32767; last_cond = -1; sect_sp = -1; @@ -370,7 +372,9 @@ int main( pass = 1; stmtno = 0; lsb = 0; - last_lsb = -1; + next_lsb = 1; + lsb_used = 0; + last_macro_lsb = -1; last_locsym = 32767; pop_cond(-1); sect_sp = -1; diff --git a/macros.c b/macros.c index 0537050..62627dc 100644 --- a/macros.c +++ b/macros.c @@ -462,11 +462,11 @@ STREAM *expandmacro( /* Now go back and fill in defaults */ { int locsym; - if (last_lsb != lsb) + if (last_macro_lsb != lsb) locsym = last_locsym = 32768; else locsym = last_locsym; - last_lsb = lsb; + last_macro_lsb = lsb; for (macarg = mac->args; macarg != NULL; macarg = macarg->next) { arg = find_arg(args, macarg->label); diff --git a/parse.c b/parse.c index 2409ac4..cc44885 100644 --- a/parse.c +++ b/parse.c @@ -9,6 +9,7 @@ #include "util.h" #include "rad50.h" +#include "listing.h" #include "assemble_globals.h" @@ -510,10 +511,15 @@ char *get_symbol( char *newsym = memcheck(malloc(32)); /* Overkill */ sprintf(newsym, "%ld$%d", strtol(symcp, NULL, 10), lsb); + if (enabl_debug && lstfile) { + fprintf(lstfile, "lsb %d: %s -> %s\n", + lsb, symcp, newsym); + } free(symcp); symcp = newsym; if (islocal) *islocal = SYMBOLFLAG_LOCAL; + lsb_used++; } else { free(symcp); return NULL;