X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=as%2Fmcs51%2Fasmain.c;h=a333cceae75c6568295119f5308125a712a600c6;hb=d7b30120ae115e8929d57e25038ca76dde13974e;hp=8c3d68dc3686c0441f4717a3122e9c4c52e002ff;hpb=28ddfae037e9fdfd03615953bdf9f5f0811fc393;p=fw%2Fsdcc diff --git a/as/mcs51/asmain.c b/as/mcs51/asmain.c index 8c3d68dc..a333ccea 100644 --- a/as/mcs51/asmain.c +++ b/as/mcs51/asmain.c @@ -11,15 +11,14 @@ * 29-Oct-97 JLH pass ";!" comments to output file */ +#include #include #include #include -#if !defined(_MSC_VER) -#include -#endif + #include "asm.h" +#include "strcmpi.h" -extern VOID machine(struct mne *); /*)Module asmain.c * * The module asmain.c includes the command argument parser, @@ -131,7 +130,7 @@ extern VOID machine(struct mne *); * VOID diag() assubr.c * VOID err() assubr.c * int fprintf() c-library - * int getline() aslex.c + * int as_getline() aslex.c * VOID list() aslist.c * VOID lstsym() aslist.c * VOID minit() ___mch.c @@ -149,6 +148,9 @@ extern VOID machine(struct mne *); * REL, LST, and/or SYM files may be generated. */ +int fatalErrors=0; +char relFile[128]; + int main(argc, argv) char *argv[]; @@ -243,8 +245,11 @@ char *argv[]; if (inpfil == 0) { if (lflag) lfp = afile(p, "lst", 1); - if (oflag) - ofp = afile(p, "rel", 1); + if (oflag) { + ofp = afile(p, "rel", 1); + // save the file name if we have to delete it on error + strcpy(relFile,afn); + } if (sflag) tfp = afile(p, "sym", 1); } @@ -284,7 +289,7 @@ char *argv[]; dot.s_area = &dca; symp = ˙ minit(); - while (getline()) { + while (as_getline()) { cp = cb; cpt = cbt; ep = eb; @@ -319,8 +324,10 @@ char *argv[]; if (lflag) { lstsym(lfp); } - asexit(aserr != 0); - return 0; + //printf ("aserr: %d\n", aserr); + //printf ("fatalErrors: %d\n", fatalErrors); + asexit(fatalErrors); + return 0; // hush the compiler } /*)Function VOID asexit(i) @@ -365,7 +372,11 @@ int i; /*for (j=0; ja_flag) err('m'); - if (ap->a_flag & A_OVR) { - ap->a_size = 0; - ap->a_fuzz=0; - } } else { ap = (struct area *) new (sizeof(struct area)); ap->a_ap = areap; @@ -849,17 +871,31 @@ loop: } newdot(ap); lmode = SLIST; + if (dot.s_area->a_flag & A_ABS) + abs_ap = ap; break; case S_ORG: if (dot.s_area->a_flag & A_ABS) { - outall(); - laddr = dot.s_addr = absexpr(); + char buf[NCPS]; + laddr = absexpr(); + sprintf(buf, "%s%x", abs_ap->a_id, laddr); + if ((ap = alookup(buf)) == NULL) { + ap = (struct area *) new (sizeof(struct area)); + *ap = *areap; + ap->a_ap = areap; + strncpy(ap->a_id, buf, NCPS); + ap->a_ref = areap->a_ref + 1; + ap->a_size = 0; + ap->a_fuzz = 0; + areap = ap; + } + newdot(ap); + lmode = ALIST; + dot.s_addr = dot.s_org = laddr; } else { err('o'); } - outall(); - lmode = ALIST; break; case S_RADIX: @@ -901,7 +937,7 @@ loop: d = getnb(); p = fn; while ((c = get()) != d) { - if (p < &fn[FILSPC-1]) { + if (p < &fn[PATH_MAX-1]) { *p++ = c; } else { break; @@ -925,7 +961,7 @@ loop: { getst(id, -1); - if (!strcmpi(id, "on")) + if (!as_strcmpi(id, "on")) { /* Quick sanity check: size of * Addr_T must be at least 24 bits. @@ -943,7 +979,7 @@ loop: flat24Mode = 1; } } - else if (!strcmpi(id, "off")) + else if (!as_strcmpi(id, "off")) { flat24Mode = 0; } @@ -1032,30 +1068,36 @@ char *fn; char *ft; int wf; { - register char *p1, *p2, *p3; + register char *p2, *p3; register int c; FILE *fp; - p1 = fn; p2 = afn; p3 = ft; - while ((c = *p1++) != 0 && c != FSEPX) { - if (p2 < &afn[FILSPC-4]) - *p2++ = c; - } + + strcpy (afn, fn); + p2 = strrchr (afn, FSEPX); // search last '.' + if (!p2) + p2 = afn + strlen (afn); + if (p2 > &afn[PATH_MAX-4]) // truncate filename, if it's too long + p2 = &afn[PATH_MAX-4]; *p2++ = FSEPX; - if (*p3 == 0) { - if (c == FSEPX) { - p3 = p1; - } else { - p3 = dsft; - } + + // choose a file-extension + if (*p3 == 0) { // extension supplied? + p3 = strrchr (fn, FSEPX); // no: extension in fn? + if (p3) + ++p3; + else + p3 = dsft; // no: default extension } - while ((c = *p3++) != 0) { - if (p2 < &afn[FILSPC-1]) + + while ((c = *p3++) != 0) { // strncpy + if (p2 < &afn[PATH_MAX-1]) *p2++ = c; } *p2++ = 0; + if ((fp = fopen(afn, wf?"w":"r")) == NULL) { fprintf(stderr, "%s: cannot %s.\n", afn, wf?"create":"open"); asexit(1); @@ -1098,11 +1140,35 @@ register struct area *nap; register struct area *oap; oap = dot.s_area; + /* fprintf (stderr, "%s dot.s_area->a_size: %d dot.s_addr: %d\n", + oap->a_id, dot.s_area->a_size, dot.s_addr); */ oap->a_fuzz = fuzz; - oap->a_size = dot.s_addr; - fuzz = nap->a_fuzz; + if (oap->a_flag & A_OVR) { + // the size of an overlay is the biggest size encountered + if (oap->a_size < dot.s_addr) { + oap->a_size = dot.s_addr; + } + } else if (oap->a_flag & A_ABS) { + oap->a_addr = dot.s_org; + oap->a_size += dot.s_addr - dot.s_org; + dot.s_addr = dot.s_org = 0; + } else { + oap->a_addr = 0; + oap->a_size = dot.s_addr; + } + if (nap->a_flag & A_OVR) { + // a new overlay starts at 0, no fuzz + dot.s_addr = 0; + fuzz = 0; + } else if (nap->a_flag & A_ABS) { + // a new absolute starts at org, no fuzz + dot.s_addr = dot.s_org; + fuzz = 0; + } else { + dot.s_addr = nap->a_size; + fuzz = nap->a_fuzz; + } dot.s_area = nap; - dot.s_addr = nap->a_size; outall(); }