* as/as_gbz80.dsp, as/z80/as_gbz80.dsp,
[fw/sdcc] / as / mcs51 / asmain.c
index 79934663b7702ae7aeeff89cca18c99ac893c8f3..1a506fbf8ca84c0ba7e6df94e1478bab13c2b288 100644 (file)
  *             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
@@ -288,7 +288,7 @@ char *argv[];
                dot.s_area = &dca;
                symp = ˙
                minit();
-               while (getline()) {
+               while (as_getline()) {
                        cp = cb;
                        cpt = cbt;
                        ep = eb;
@@ -374,7 +374,7 @@ int i;
        if (i) {
          // remove output file
          printf ("removing %s\n", relFile);
-         unlink(relFile);
+         remove(relFile);
        }
        exit(i);
 }
@@ -482,6 +482,7 @@ asmbl()
        char fn[PATH_MAX];
        char *p;
        int d, n, uaf, uf;
+       static struct area *abs_ap; /* pointer to current absolute area structure */
 
        laddr = dot.s_addr;
        lmode = SLIST;
@@ -555,7 +556,7 @@ loop:
                goto loop;
        }
        /*
-        * If the first character is a letter then assume a lable,
+        * If the first character is a letter then assume a label,
         * symbol, assembler directive, or assembler mnemonic is
         * being processed.
         */
@@ -799,7 +800,7 @@ loop:
                break;
 
        case S_MODUL:
-               getst(id, -1);
+               getst(id, getnb()); // a module can start with a digit
                if (pass == 0) {
                        if (module[0]) {
                                err('m');
@@ -810,6 +811,20 @@ loop:
                lmode = SLIST;
                break;
 
+       case S_OPTSDCC:
+               p = optsdcc;
+               if ((c = getnb()) != 0) {
+                       do {
+                               if (p < &optsdcc[NINPUT-1])
+                                       *p++ = c;
+                       } while ((c = get()) != 0);
+               }
+               *p = 0;
+               unget(c);
+               lmode = SLIST;
+        /*if (pass == 0) printf("optsdcc=%s\n", optsdcc);*/
+        break;
+
        case S_GLOBL:
                do {
                        getid(id, -1);
@@ -821,7 +836,7 @@ loop:
                break;
 
        case S_DAREA:
-               getid(id, -1);
+               getid(id, -1);
                uaf = 0;
                uf  = A_CON|A_REL;
                if ((c = getnb()) == '(') {
@@ -855,17 +870,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:
@@ -914,7 +943,7 @@ loop:
                        }
                }
                *p = 0;
-               if (++incfil == MAXINC ||
+               if ((++incfil == MAXINC) ||
                   (ifp[incfil] = fopen(fn, "r")) == NULL) {
                        --incfil;
                        err('i');
@@ -931,7 +960,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.
@@ -949,7 +978,7 @@ loop:
                            flat24Mode = 1;
                        }
                    }
-                   else if (!strcmpi(id, "off"))
+                   else if (!as_strcmpi(id, "off"))
                    {
                        flat24Mode = 0;
                    }
@@ -1118,13 +1147,22 @@ register struct area *nap;
          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;