minor xa51 improvements
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 22 Jan 2002 18:16:59 +0000 (18:16 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 22 Jan 2002 18:16:59 +0000 (18:16 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1835 4a8a32a2-be11-0410-ad9d-d568d2c75423

as/xa51/Makefile
as/xa51/xa_asm.l
as/xa51/xa_asm.y
as/xa51/xa_main.c
as/xa51/xa_main.h
device/lib/Makefile.in
src/asm.c
src/xa51/gen.c
src/xa51/gen.h
src/xa51/main.c
src/xa51/ralloc.c

index 6edcc239a1f50158ba3a31383b2af9d94225a369..0ed11c76f6493ce84fa94619fc2b981870af93c7 100644 (file)
@@ -1,12 +1,12 @@
 CC = gcc
-CFLAGS = -O2
+CFLAGS = -ggdb -O2
 YACC = bison -y -d
 LEX = flex -i
 LEXLIB = 
 
 xa_asm: xa_main.o xa_asm.tab.o xa_asm.lex.o xa_dasm.o
        $(CC) -o xa_asm xa_main.o xa_asm.tab.o xa_asm.lex.o xa_dasm.o $(LEXLIB)
-       strip xa_asm
+       #strip xa_asm
 
 xa_asm.lex.o: xa_asm.lex.c xa_asm.tab.h xa_main.h
        $(CC) $(CFLAGS) -c xa_asm.lex.c
index 61fdaf63d32ab454da0abeddd4aa3d7b8a704045..b47736bbe5842b53f4df5274895d650532ecab4d 100644 (file)
@@ -252,7 +252,7 @@ R[0-7]H             {LIST; yylval = (yytext[1] - '0') * 2 + 1 + BYTE_REG; return REG;}
                        }
 [0-9]+\$               {
                                LIST;
-                               /* should print error is base_symbol_name */
+                               /* should print error if base_symbol_name */
                                /* is not defined */
                                sprintf(lex_sym_name, "%s:%s",
                                        base_symbol_name, yytext);
index 4567d7e33ca9c36fd0f48d6b43191bc9714dcfb2..8ef50d5e21eb4860dd051264da9a2cf4338e1c7a 100644 (file)
@@ -40,7 +40,6 @@ extern void yyrestart(FILE *new_file);
 extern char * disasm(int byte, int memory_location);
 extern void hexout(int byte, int memory_location, int end);
 void error(char *s);
-void fatal_error(char *s);
 
 static int bitmask[]={1, 2, 4, 8, 16, 32, 64, 128};
 
@@ -166,8 +165,6 @@ directive:     '.' ORG expr {
                }
             | '.' MODULE WORD {
                        /* ignore module definition */
-                       build_sym_list(lex_sym_name);
-                       assign_value(lex_sym_name, 0);
                        $$ = 0;
                }
             | '.' GLOBL WORD {
@@ -1305,11 +1302,6 @@ int yyerror(char *s)
 }
 
 void error(char *s)
-{
-       yyerror(s);
-}
-
-void fatal_error(char *s)
 {
        yyerror(s);
        exit(1);
index b01f829485860a575c2e7566dbce560449b6d09a..1736650b6a6cff228bc42b22575578918b4fde32 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
 
 #define printf(x...) fprintf(stderr,x)
 
@@ -33,7 +34,7 @@ extern int yyparse();
 
 /* global variables */
 
-FILE *fhex, *fmem, *list_fp;
+FILE *fhex, *fmem, *list_fp, *sym_fp;
 extern FILE *yyin;
 extern char *yytext;
 extern char last_line_text[];
@@ -201,12 +202,12 @@ void print_symbol_table()
   struct symbol *p;
   p = sym_list;
   while (p != NULL) {
-    printf("Sym in %-5s: %s\n", areaToString(p->area), p->name);
-    printf("  at: 0x%04X (%5d)", p->value, p->value);
-    printf(" Def:%s", p->isdef ? "Yes" : "No ");
-    printf(" Bit:%s", p->isbit ? "Yes" : "No ");
-    printf(" Target:%s", p->istarget ? "Yes" : "No ");
-    printf(" Line %d\n", p->line_def);
+    fprintf(sym_fp, "Sym in %-5s: %s\n", areaToString(p->area), p->name);
+    fprintf(sym_fp, "  at: 0x%04X (%5d)", p->value, p->value);
+    fprintf(sym_fp, " Def:%s", p->isdef ? "Yes" : "No ");
+    fprintf(sym_fp, " Bit:%s", p->isbit ? "Yes" : "No ");
+    fprintf(sym_fp, " Target:%s", p->istarget ? "Yes" : "No ");
+    fprintf(sym_fp, " Line %d\n", p->line_def);
     p = p->next;
   }
 }
@@ -368,7 +369,7 @@ int binary2int(char *str)
        return (sum);
 }
 
-void print_usage();
+void print_usage(int);
 
 
 /* todo: someday this will allow the user to control where the */
@@ -379,18 +380,87 @@ void print_usage();
 
 void init_areas(void)
 {
-       area[AREA_CSEG].alloc_position = 0;
-       area[AREA_DSEG].alloc_position = 0x30;
-       area[AREA_OSEG].alloc_position = 0x80;
-       area[AREA_ISEG].alloc_position = 0;
-       area[AREA_BSEG].alloc_position = 0;
-       area[AREA_XSEG].alloc_position = 0;
-       area[AREA_XISEG].alloc_position = 0;
-       area[AREA_GSINIT].alloc_position = 0;
-       area[AREA_GSFINAL].alloc_position = 0;
-       area[AREA_HOME].alloc_position = 0;
+  area[AREA_CSEG].start=area[AREA_CSEG].alloc_position = 0;
+  area[AREA_DSEG].start=area[AREA_DSEG].alloc_position = 0x30;
+  area[AREA_OSEG].start=area[AREA_OSEG].alloc_position = 0x80;
+  area[AREA_ISEG].start=area[AREA_ISEG].alloc_position = 0;
+  area[AREA_BSEG].start=area[AREA_BSEG].alloc_position = 0;
+  area[AREA_XSEG].start=area[AREA_XSEG].alloc_position = 0;
+  area[AREA_XISEG].start=area[AREA_XISEG].alloc_position = 0;
+  area[AREA_XINIT].start=area[AREA_XINIT].alloc_position = 0;
+  area[AREA_GSINIT].start=area[AREA_GSINIT].alloc_position = 0;
+  area[AREA_GSFINAL].start=area[AREA_GSFINAL].alloc_position = 0;
+  area[AREA_HOME].alloc_position = 0;
 }
 
+void printVersion() {
+  printf("\nPaul's XA51 Assembler\n");
+  printf("Copyright 1997,2002 Paul Stoffregen\n\n");
+  printf("This program is free software; you can redistribute it\n");
+  printf("and/or modify it under the terms of the GNU General Public\n");
+  printf("License, Version 2, published by the Free Software Foundation\n\n");
+  printf("This program is distributed in the hope that it will be useful,\n");
+  printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+  printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
+}
+
+char infilename[PATH_MAX];
+char outfilename[PATH_MAX];
+char listfilename[PATH_MAX];
+char symfilename[PATH_MAX];
+//char mapfilename[PATH_MAX];
+
+int verbose=0, createSymbolFile=0;
+
+void process_args(int argc, char **argv) 
+{
+  int i=0;
+
+  if (argc < 2) print_usage(1);
+  
+  while (++i<argc && *argv[i]=='-') {
+    if (strcmp(argv[i], "--version")==0) {
+      printVersion();
+      exit (0);
+    }
+    if (strcmp(argv[i], "--help")==0) {
+      print_usage(0);
+    }
+    if (strcmp(argv[i], "-v")==0) {
+      verbose++;
+      continue;
+    }
+    if (strcmp(argv[i], "-s")==0) {
+      createSymbolFile++;
+      continue;
+    }
+    print_usage(1);
+  }
+
+  if (i!=argc-1) {
+    // only 1 source file for now
+    print_usage(1);
+  }
+
+  strcpy(infilename, argv[i]);
+
+  if (strncasecmp(infilename+strlen(infilename)-3, ".xa", 3)) {
+    fprintf (stderr, "unrecognized input file: \"%s\"\n", argv[i]);
+    print_usage(1);
+  }
+
+  strcpy(outfilename, infilename);
+  outfilename[strlen(outfilename)-3] = '\0';
+  strcpy(listfilename, outfilename);
+  if (createSymbolFile) {
+    strcpy(symfilename, outfilename);
+    strcat(symfilename, ".sym");
+  }
+  //strcpy(mapfilename, outfilename);
+  strcat(outfilename, ".hex");
+  strcat(listfilename, ".lst");
+  //strcat(mapfilename, ".map");
+}
 
 /* pass #1 (p1=1) find all symbol defs and branch target names */
 /* pass #2 (p2=1) align branch targets, evaluate all symbols */
@@ -398,19 +468,8 @@ void init_areas(void)
 
 int main(int argc, char **argv)
 {
-       char infilename[200], outfilename[200], listfilename[200];
-
-       if (argc < 2) print_usage();
-       strcpy(infilename, argv[1]);
-       if(strlen(infilename) > 3) {
-               if (strncasecmp(infilename+strlen(infilename)-3, ".xa", 3))
-                       strcat(infilename, ".xa");
-       } else strcat(infilename, ".xa");
-       strcpy(outfilename, infilename);
-       outfilename[strlen(outfilename)-3] = '\0';
-       strcpy(listfilename, outfilename);
-       strcat(outfilename, ".hex");
-       strcat(listfilename, ".lst");
+       process_args (argc, argv);
+
        yyin = fopen(infilename, "r");
        if (yyin == NULL) {
                fprintf(stderr, "Can't open file '%s'.\n", infilename);
@@ -426,56 +485,65 @@ int main(int argc, char **argv)
                fprintf(stderr, "Can't write file '%s'.\n", listfilename);
                exit(1);
        }
+       if (createSymbolFile) {
+         sym_fp = fopen(symfilename, "w");
+         if (sym_fp == NULL) {
+           fprintf(stderr, "Can't write file '%s'.\n", symfilename);
+           exit(1);
+         }
+       }
 
-       /* todo: add a command line option to supress verbose messages */
-       printf("\nPaul's XA51 Assembler\n");
-       printf("Copyright 1997,2002 Paul Stoffregen\n\n");
-       printf("This program is free software; you can redistribute it\n");
-       printf("and/or modify it under the terms of the GNU General Public\n");
-       printf("License, Version 2, published by the Free Software Foundation\n\n");
-       printf("This program is distributed in the hope that it will be useful,\n");
-       printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
-       printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
-
-
-
-       printf("    Building Symbol Table:\n");
+       if (verbose) printf("Pass 1: Building Symbol Table:\n");
        p1 = 1;
-       //mem = 0;
        init_areas();
        yyparse();
        flag_targets();
-       print_symbol_table();
+       if (createSymbolFile) print_symbol_table();
        check_redefine();
+
+       if (verbose) printf("Pass 2: Aligning Branch Targets:\n");
        p1 = 0;
        p2 = 1;
        rewind(yyin);
        yyrestart(yyin);
        lineno = 1;
-       printf("    Aligning Branch Targets:\n");
-       //mem = 0;
        init_areas();
        yyparse();
-       // print_symbol_table();
+
+       if (verbose) printf("Pass 3: Generating Object Code:\n");
        p2 = 0;
        p3 = 1;
        rewind(yyin);
        yyrestart(yyin);
        lineno = 1;
-       printf("    Generating Object Code:\n");
-       //mem = 0;
        init_areas();
        yyparse();
+
        fclose(yyin);
        hexout(0, 0, 1);  /* flush and close intel hex file output */
        return 0;
 }
 
 
-void print_usage()
+void print_usage(int fatal)
 {
-       fprintf(stderr, "Usage: xa_asm file\n");
-       fprintf(stderr, "   or  xa_asm file.asm\n");
-       exit(1);
+  FILE *out = fatal ? stderr : stdout;
+
+  fprintf (out, "Usage: xa_asm [-s] [-v] file.xa\n");
+  fprintf (out, "  -v            verbose: show progress\n");
+  fprintf (out, "  -s            create symbol file\n");
+  fprintf (out, "  --version     show version/copyright info and exit\n");
+  fprintf (out, "  --help        show this and exit\n");
+#if 0
+  // some usefull options I can think of.
+  fprintf (out, "  -m            create map file\n");
+  fprintf (out, "  -ss           create symbol file sorted by symbol\n");
+  fprintf (out, "  -sa           create symbol file sorted by segment/address\n");
+  fprintf (out, "  --no-temps    supress temp symbols in map and sym file\n");
+  fprintf (out, "  --code-loc=#  sets the start address of the code\n");
+  fprintf (out, "  --xdata-loc=# sets the start address of the external data\n");
+  fprintf (out, "  --stack-loc=# sets the start address of the stack\n");
+#endif
+  exit(fatal);
 }
 
index e3bf912bda8589b9c577d1527a3f07aac3945884..b31227ab8135891ec84fc5502c625970d8071f4f 100644 (file)
@@ -44,6 +44,7 @@ struct target {
         struct target *next; };
 
 struct area_struct {
+        int start;
        int alloc_position;
 };
 
index 7c28242bdceab319260914a0e00410576f0c2ec3..4b97353a51ebec26d73d987a301ffc663017f35a 100644 (file)
@@ -90,6 +90,30 @@ Z80SOURCES      = _atoi.c \
 
 Z80OBJECTS      = $(Z80SOURCES:%.c=$(PORTDIR)/%.o)
 
+XA51SOURCES      = _atoi.c _atol.c _schar2fs.c \
+                 _divsint.c _divslong.c _divuint.c \
+                 _divulong.c _fs2schar.c _fs2sint.c _fs2slong.c \
+                 _fs2uchar.c _fs2uint.c _fs2ulong.c _fsadd.c \
+                 _fsdiv.c _fseq.c _fsgt.c _fslt.c _fsmul.c \
+                 _fsneq.c _fssub.c \
+                 _sint2fs.c _iscntrl.c _isdigit.c _isgraph.c \
+                 _islower.c _isprint.c _ispunct.c _isspace.c \
+                 _isupper.c _isxdigit.c _slong2fs.c _memcmp.c \
+                 _memcpy.c _memset.c _modsint.c _modslong.c \
+                 _moduint.c _modulong.c _mulint.c _mullong.c \
+                 _strchr.c _strcmp.c _strcpy.c \
+                 _strcspn.c _strlen.c _strncat.c _strncmp.c \
+                 _strncpy.c _strpbrk.c _strrchr.c _strspn.c \
+                 _strstr.c _strtok.c _uchar2fs.c _uint2fs.c \
+                 _ulong2fs.c malloc.c puts.c gets.c \
+                 assert.c _strcat.c time.c \
+                 fabsf.c frexpf.c ldexpf.c expf.c powf.c sincosf.c sinf.c \
+                 cosf.c logf.c log10f.c sqrtf.c tancotf.c tanf.c cotf.c \
+                 asincosf.c asinf.c acosf.c atanf.c atan2f.c sincoshf.c \
+                 sinhf.c coshf.c tanhf.c floorf.c ceilf.c modff.c
+
+XA51OBJECTS      = $(XA51SOURCES:%.c=$(PORTDIR)/%.xa)
+
 OEXT            = .rel
 
 include incl.mk
@@ -112,6 +136,14 @@ model-ds390:
          $(MAKE) MODELFLAGS="-mds390" PORT=ds390 objects; \
        fi
 
+model-xa51:
+       if [ "`grep xa51 ../../ports.build`" = xa51 ]; then \
+         $(MAKE) MODELFLAGS="-mxa51" PORT=xa51 objects-xa51 OEXT=.xa; \
+       fi
+
+objects-xa51: build-dir $(XA51OBJECTS) port-specific-objects
+       cd $(PORTDIR); ls *$(OEXT) > $(PORT).lib
+
 model-z80:
        if [ "`grep z80 ../../ports.build`" = z80 ]; then \
          $(MAKE) MODELFLAGS="-mz80" PORT=z80 objects-z80 OEXT=.o; \
@@ -201,7 +233,7 @@ include clean.mk
 $(PORTDIR)/%$(OEXT): %.c
        $(CC) $(CPPFLAGS) $(CFLAGS) -c $<
        mv -f `basename $@` $@
-       mv -f `basename $@ $(OEXT)`.asm $(PORTDIR)
+       -mv -f `basename $@ $(OEXT)`.asm $(PORTDIR)
 
 # Remaking configuration
 # ----------------------
index 66e8d20195a34280569778f7b7d277b99ef9379f..325b28a9f60c7c434e27f0d912e71249645cc10b 100644 (file)
--- a/src/asm.c
+++ b/src/asm.c
@@ -409,7 +409,7 @@ static const ASM_MAPPING _xa_asm_mapping[] =
   {"hashedstr", "#%s"},
   {"lsbimmeds", "#<%s"},
   {"msbimmeds", "#>%s"},
-  {"module", ".module %s"},
+  {"module", ".module %s"},
   {"global", ".globl %s"},
   {"fileprelude", ""},
   {"functionheader",
index 8653e54a282f65dbdf2818d965450b95d9093c2a..bbe49199c34ed364aae25676df0cd8ccf89cf8d4 100755 (executable)
@@ -1,11 +1,3 @@
-/* The only ops for now are:
-   genAssign
-   genIfx
-   genAddrOf
-   genPointerSet
-   genPointerGet
-*/
-
 /*-------------------------------------------------------------------------
   SDCCgen51.c - source file for code generation for 8051
 
@@ -104,8 +96,8 @@ static lineNode *lineCurr = NULL;
 
 static char *MOVB="mov.b";
 static char *MOVW="mov.w";
-static char *MOVCB="movc.b";
-static char *MOVCW="movc.w";
+//static char *MOVCB="movc.b";
+//static char *MOVCW="movc.w";
 
 void bailOut (char *mesg) {
   fprintf (stderr, "%s: bailing out\n", mesg);
@@ -147,7 +139,7 @@ static void emitcode (char *inst, char *fmt,...) {
 
 char *getStackOffset(int stack) {
   static char gsoBuf[1024];
-  // dit slaat natuurlijk nergens op
+  // dit slaat natuurlijk nergens op, maar ja voor nou
   sprintf (gsoBuf, "r7+(%+d+0%+d%+d)", stack,
           FUNC_ISISR(currFunc->type) ? 
             port->stack.isr_overhead : port->stack.call_overhead,
@@ -176,9 +168,10 @@ char *aopTypeName(asmop *aop) {
     case AOP_DIR: return "dir";
     case AOP_FAR: return "far";
     case AOP_CODE: return "code";
+    case AOP_GPTR: return "gptr";
     case AOP_STK: return "stack";
     case AOP_IMMD: return "imm";
-    case AOP_CRY: return "bit";
+    case AOP_BIT: return "bit";
     }
   return "unknown";
 }
@@ -186,7 +179,7 @@ char *aopTypeName(asmop *aop) {
 /*-----------------------------------------------------------------*/
 /* aopForSym - for a true symbol                                   */
 /*-----------------------------------------------------------------*/
-static asmop *aopForSym(symbol *sym, bool result) {
+static asmop *aopForSym(symbol *sym, bool result, bool cantUsePointer) {
   int size;
   asmop *aop;
 
@@ -197,7 +190,7 @@ static asmop *aopForSym(symbol *sym, bool result) {
   if (sym->nRegs && sym->regs[0]) {
     aop->type=AOP_REG;
     sprintf (aop->name[0], sym->regs[0]->name);
-    if (size>2) {
+    if (size > 2) {
       sprintf (aop->name[1], sym->regs[1]->name);
     }
     return aop;
@@ -205,6 +198,33 @@ static asmop *aopForSym(symbol *sym, bool result) {
 
   // if it is on stack
   if (sym->onStack) {
+    if (cantUsePointer) {
+      aop->type=AOP_REG;
+      switch (size) 
+       {
+       case 1:
+         emitcode ("mov.b", "r0l,[%s]", getStackOffset(sym->stack));
+         sprintf (aop->name[0], "r0l");
+         return aop;
+       case 2:
+         emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+         sprintf (aop->name[0], "r0");
+         return aop;
+       case 3:
+         emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+         sprintf (aop->name[0], "r0");
+         emitcode ("mov.b", "r1l,[%s]", getStackOffset(sym->stack+2));
+         sprintf (aop->name[1], "r1l");
+         return aop;
+       case 4:
+         emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+         sprintf (aop->name[0], "r0");
+         emitcode ("mov.w", "r1,[%s]", getStackOffset(sym->stack+2));
+         sprintf (aop->name[1], "r1");
+         return aop;
+       }
+      bailOut("aopForSym: onStack CantUsePointer unknown size");
+    }
     aop->type=AOP_STK;
     sprintf (aop->name[0], "[%s]", getStackOffset(sym->stack));
     if (size > 2) {
@@ -215,12 +235,12 @@ static asmop *aopForSym(symbol *sym, bool result) {
 
   // if it has a spillLoc
   if (sym->usl.spillLoc) {
-    return aopForSym (sym->usl.spillLoc, result);
+    return aopForSym (sym->usl.spillLoc, result, cantUsePointer);
   }
 
   // if in bit space
   if (IN_BITSPACE(SPEC_OCLS(sym->etype))) {
-    aop->type=AOP_CRY;
+    aop->type=AOP_BIT;
     sprintf (aop->name[0], sym->rname);
     return aop;
   }
@@ -230,7 +250,7 @@ static asmop *aopForSym(symbol *sym, bool result) {
     aop->type=AOP_DIR;
     sprintf (aop->name[0], sym->rname);
     if (size>2) {
-      sprintf (aop->name[0], "%s+2", sym->rname);
+      sprintf (aop->name[1], "%s+2", sym->rname);
     }
     return aop;
   }
@@ -241,10 +261,10 @@ static asmop *aopForSym(symbol *sym, bool result) {
       bailOut("aopForSym: result can not be in code space");
     }
     aop->type=AOP_CODE;
-    emitcode ("mov", "r0,#%s", sym->rname);
+    emitcode ("mov", "r0,#%s ; aopForSym:code", sym->rname);
     sprintf (aop->name[0], "[r0]");
     if (size>2) {
-      sprintf (aop->name[1], "[r0+1]");
+      sprintf (aop->name[1], "[r0+2]");
     }
     return aop;
   }
@@ -252,10 +272,10 @@ static asmop *aopForSym(symbol *sym, bool result) {
   // if in far space
   if (IN_FARSPACE(SPEC_OCLS(sym->etype))) {
     aop->type=AOP_FAR;
-    emitcode ("mov", "r0,#%s", sym->rname);
+    emitcode ("mov", "r0,#%s ; aopForSym:far", sym->rname);
     sprintf (aop->name[0], "[r0]");
     if (size>2) {
-      sprintf (aop->name[1], "[r0+1]");
+      sprintf (aop->name[1], "[r0+2]");
     }
     return aop;
   }
@@ -269,21 +289,33 @@ static asmop *aopForSym(symbol *sym, bool result) {
 /*-----------------------------------------------------------------*/
 static asmop *aopForVal(operand *op) {
   asmop *aop;
-  long v=(long long)floatFromVal(OP_VALUE(op));
 
   if (IS_OP_LITERAL(op)) {
     op->aop = aop = newAsmop (AOP_LIT);
     switch ((aop->size=getSize(operandType(op))))
       {
       case 1:
-       sprintf (aop->name[0], "#0x%02lx", v);
+       sprintf (aop->name[0], "#0x%02x", 
+                SPEC_CVAL(operandType(op)).v_int & 0xff);
+       sprintf (aop->name[1], "#0");
        break;
       case 2:
-       sprintf (aop->name[0], "#0x%04lx", v);
+       sprintf (aop->name[0], "#0x%04x", 
+                SPEC_CVAL(operandType(op)).v_int & 0xffff);
+       sprintf (aop->name[1], "#0");
+       break;
+      case 3:
+       // must be a generic pointer, can only be zero
+       // ?? if (v!=0) fprintf (stderr, "invalid val op for gptr\n"); exit(1);
+       sprintf (aop->name[0], "#0x%04x", 
+                SPEC_CVAL(operandType(op)).v_uint & 0xffff);
+       sprintf (aop->name[1], "#0");
        break;
       case 4:
-       sprintf (aop->name[0], "#(0x%08lx >> 16)", v);
-       sprintf (aop->name[1], "#(0x%08lx & 0xffff)", v);
+       sprintf (aop->name[0], "#0x%04lx",
+                SPEC_CVAL(operandType(op)).v_ulong >> 16);
+       sprintf (aop->name[1], "#0x%04x", 
+                SPEC_CVAL(operandType(op)).v_ulong && 0xffff);
        break;
       default:
        bailOut("aopForVal");
@@ -306,27 +338,38 @@ static asmop *aopForVal(operand *op) {
        return aop;
       }
   }
+
   bailOut ("aopForVal: unknown type");
   return NULL;
 }
 
-static void aopOp(operand *op, bool result) {
+static void aopOp(operand *op, bool result, bool cantUsePointer) {
 
   if (IS_SYMOP(op)) {
-    op->aop=aopForSym (OP_SYMBOL(op), result);
+    op->aop=aopForSym (OP_SYMBOL(op), result, cantUsePointer);
     return;
   }
   if (IS_VALOP(op)) {
     if (result) {
       bailOut("aopOp: result can not be a value");
     }
-    aopForVal (op);
+    op->aop=aopForVal (op);
     return;
   }
 
   bailOut("aopOp: unexpected operand");
 }
 
+bool aopIsPtr(operand *op) {
+  if (AOP_TYPE(op)==AOP_STK ||
+      AOP_TYPE(op)==AOP_CODE ||
+      AOP_TYPE(op)==AOP_FAR) {
+    return TRUE;
+  } else {
+    return FALSE;
+  }
+}
+      
 char *opRegName(operand *op, int offset, char *opName) {
 
   if (IS_SYMOP(op)) {
@@ -415,6 +458,10 @@ char * printOp (operand *op) {
       sprintf (line+strlen(line), "stack%+d", sym->stack);
       return line;
     }
+    if (IN_CODESPACE(SPEC_OCLS(sym->etype))) {
+      strcat (line, "code");
+      return line;
+    }
     if (IN_FARSPACE(SPEC_OCLS(sym->etype))) {
       strcat (line, "far");
       return line;
@@ -646,7 +693,7 @@ static void genRet (iCode * ic) {
 
   printIc ("genRet", ic, 0,1,0);
 
-  aopOp(IC_LEFT(ic),FALSE);
+  aopOp(IC_LEFT(ic),FALSE, FALSE);
 
   switch (AOP_SIZE(IC_LEFT(ic)))
     {
@@ -896,11 +943,10 @@ static void genRightShift (iCode * ic) {
 /* genPointerGet - generate code for pointer get                   */
 /*-----------------------------------------------------------------*/
 static void genPointerGet (iCode * ic, iCode *pi) {
-  char *instr;
-
-  operand *result=IC_RESULT(ic), *left=IC_LEFT(ic);
-
   printIc ("genPointerGet", ic, 1,1,0);
+#if 0
+  char *instr, *scratchReg;
+  operand *result=IC_RESULT(ic), *left=IC_LEFT(ic);
 
   if (!IS_PTR(operandType(left))) {
     bailOut ("genPointerGet: pointer required");
@@ -969,13 +1015,15 @@ static void genPointerGet (iCode * ic, iCode *pi) {
     case AOP_REG:
       if (AOP_SIZE(result)==1) {
        instr=MOVB;
+       scratchReg=R0L;
       } else {
        instr=MOVW;
+       scratchReg=R0;
       }
       // if result=onstack
       if (AOP_TYPE(result)==AOP_STK) {
-       emitcode (instr, "r0,[%s]", AOP_NAME(left)[0]);
-       emitcode (instr, "%s,r0", AOP_NAME(result)[0]);
+       emitcode (instr, "%s,[%s]", scratchReg, AOP_NAME(left)[0]);
+       emitcode (instr, "%s,%s", AOP_NAME(result)[0], scratchReg);
       } else {
        emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]);
       }
@@ -984,10 +1032,10 @@ static void genPointerGet (iCode * ic, iCode *pi) {
        sym_link *optype=operandType(left);
        sym_link *opetype=getSpec(optype);
        if (IS_PTR(optype) && !IS_GENPTR(optype)) {
-         emitcode ("mov.b", "%s,#0x%02x", AOP_NAME(result)[1], 
+         emitcode (MOVB, "%s,#0x%02x", AOP_NAME(result)[1], 
                    PTR_TYPE(SPEC_OCLS(opetype)));
        } else {
-         emitcode ("mov.b", "%s,[%s]", AOP_NAME(result)[1], AOP_NAME(left)[1]);
+         emitcode (MOVB, "%s,[%s]", AOP_NAME(result)[1], AOP_NAME(left)[1]);
        }
       }
       return;
@@ -1024,55 +1072,14 @@ static void genPointerGet (iCode * ic, iCode *pi) {
       return;
     }
   bailOut ("genPointerGet: unknown pointer");
+#endif
 }
 
 /*-----------------------------------------------------------------*/
 /* genPointerSet - stores the value into a pointer location        */
 /*-----------------------------------------------------------------*/
 static void genPointerSet (iCode * ic, iCode *pi) {
-  char *instr;
-
-  operand *result=IC_RESULT(ic), *right=IC_RIGHT(ic);
-
   printIc ("genPointerSet", ic, 1,0,1);
-
-  if (!IS_PTR(operandType(result))) {
-    bailOut ("genPointerSet: pointer required");
-  }
-
-  aopOp(right,FALSE);
-  aopOp(result,TRUE);
-
-  if (IS_GENPTR(operandType(result))) {
-    emitcode (";", "INLINE _gptrset ; [%s %s]=  %s %s", 
-             AOP_NAME(result)[0], AOP_NAME(result)[1],
-             AOP_NAME(right)[0], AOP_NAME(right)[1]);
-    return;
-  }
-
-  switch (AOP_TYPE(result)) 
-    {
-    case AOP_REG:
-    case AOP_DIR:
-    case AOP_FAR:
-    case AOP_STK:
-      if (AOP_SIZE(result)==1) {
-       instr=MOVB;
-      } else {
-       instr=MOVW;
-      }
-      emitcode (instr, "[%s],%s", AOP_NAME(result)[0], AOP_NAME(right)[0]);
-      if (AOP_SIZE(result) > 2) {
-       if (AOP_SIZE(result)==3) {
-         instr=MOVB;
-       } else {
-         instr=MOVW;
-       }
-       emitcode (instr, "[%s],%s", AOP_NAME(result)[1], AOP_NAME(right)[1]);
-      }
-      return;
-    }
-  bailOut ("genPointerSet: unknown pointer");
 }
 
 /*-----------------------------------------------------------------*/
@@ -1089,7 +1096,7 @@ static void genIfx (iCode * ic, iCode * popIc) {
            IC_TRUE(ic) ? IC_TRUE(ic)->name : "NULL",
            IC_FALSE(ic) ? IC_FALSE(ic)->name : "NULL");
 
-  aopOp(cond,FALSE);
+  aopOp(cond,FALSE,FALSE);
 
   if (IC_TRUE(ic)) {
     trueOrFalse=TRUE;
@@ -1101,7 +1108,7 @@ static void genIfx (iCode * ic, iCode * popIc) {
 
   switch (AOP_TYPE(cond) )
     {
-    case AOP_CRY:
+    case AOP_BIT:
       emitcode (trueOrFalse ? "jb" : "jbc", "%s,%05d$", 
                AOP_NAME(cond)[0], jlbl->key+100);
       return;
@@ -1141,14 +1148,14 @@ static void genAddrOf (iCode * ic) {
 
   printIc ("genAddrOf", ic, 1,1,0);
 
-  aopOp (IC_RESULT(ic),TRUE);
+  aopOp (IC_RESULT(ic),TRUE, FALSE);
 
   if (isOperandOnStack(left)) {
     emitcode ("lea", "%s,%s", AOP_NAME(IC_RESULT(ic))[0],
              getStackOffset(OP_SYMBOL(left)->stack));
     if (AOP_SIZE(IC_RESULT(ic)) > 2) {
       // this must be a generic pointer
-      emitcode ("mov", "%s,#0x01", AOP_NAME(IC_RESULT(ic))[1]);
+      emitcode ("mov", "%s,#0x%02x", AOP_NAME(IC_RESULT(ic))[1], FPOINTER);
     }
     return;
   }
@@ -1156,8 +1163,8 @@ static void genAddrOf (iCode * ic) {
   if (isOperandInDirSpace(left) ||
       isOperandInFarSpace(left) ||
       isOperandInCodeSpace(left)) {
-    emitcode ("mov", "%s,#%s", AOP_NAME(IC_RESULT(ic))[0],
-             OP_SYMBOL(left));
+    emitcode ("mov.w", "%s,#%s", AOP_NAME(IC_RESULT(ic))[0],
+             OP_SYMBOL(left)->rname);
     if (AOP_SIZE(IC_RESULT(ic)) > 2) {
       // this must be a generic pointer
       int space=0; // dir space
@@ -1166,7 +1173,7 @@ static void genAddrOf (iCode * ic) {
       } else if (isOperandInCodeSpace(left)) {
        space=2;
       }
-      emitcode ("mov", "%s,#0x%02x", AOP_NAME(IC_RESULT(ic))[1], space);
+      emitcode ("mov.b", "%s,#0x%02x", AOP_NAME(IC_RESULT(ic))[1], space);
     }
     return;
   }
@@ -1188,27 +1195,12 @@ static void genAssign (iCode * ic) {
     bailOut("genAssign: result is not a symbol");
   }
   
-  aopOp(right, FALSE);
-  aopOp(result, TRUE);
+  aopOp(result, TRUE, FALSE);
+  aopOp(right, FALSE, aopIsPtr(result));
   size=AOP_SIZE(result);
 
-  if (result->aop->type==AOP_REG || 
-      right->aop->type==AOP_REG ||
-      right->aop->type==AOP_LIT ||
-      right->aop->type==AOP_STK ||
-      right->aop->type==AOP_IMMD) {
-    // everything will do
-  } else {
-    // they have to match
-    if (result->aop->type != right->aop->type) {
-      fprintf (stderr, "genAssign: types don't match (%s!=%s)\n",
-              aopTypeName(result->aop), aopTypeName(right->aop));
-      exit (1);
-    }
-  }
-
   /* if result is a bit */
-  if (AOP_TYPE(result) == AOP_CRY) {
+  if (AOP_TYPE(result) == AOP_BIT) {
     /* if right is literal, we know what the value is */
     if (AOP_TYPE(right) == AOP_LIT) {
       if (operandLitValue(right)) {
@@ -1219,7 +1211,7 @@ static void genAssign (iCode * ic) {
       return;
     }
     /* if right is also a bit */
-    if (AOP_TYPE(right) == AOP_CRY) {
+    if (AOP_TYPE(right) == AOP_BIT) {
       emitcode ("mov", "c,%s", AOP_NAME(right));
       emitcode ("mov", "%s,c", AOP_NAME(result));
       return;
@@ -1235,31 +1227,16 @@ static void genAssign (iCode * ic) {
   } else {
     instr=MOVW;
   }
-  if (AOP_TYPE(right)==AOP_STK && AOP_TYPE(result)==AOP_STK) {
-    emitcode (instr, "%s,%s", size==1 ? "r0l":"r0", right->aop->name[0]);
-    emitcode (instr, "%s,%s", AOP_NAME(result)[0], size==1 ? "r0l":"r0");
-  } else {
-    emitcode (instr, "%s,%s",
-             result->aop->name[0], right->aop->name[0]);
-  }
+  emitcode (instr, "%s,%s", AOP_NAME(result)[0], AOP_NAME(right)[0]);
+
   if (AOP_SIZE(result) > 2) {
-    if (AOP_TYPE(right)==AOP_LIT) {
-      emitcode (instr, "%s,%s", result->aop->name[1], 
-               *AOP_NAME(right)[1] ? AOP_NAME(right)[1] : "#0x00");
-      return;
-    }
     if (size==3) {
+      // generic pointer
       instr=MOVB;
     } else {
       instr=MOVW;
     }
-    if (AOP_TYPE(right)==AOP_STK && AOP_TYPE(result)==AOP_STK) {
-      emitcode (instr, "%s,%s", size==1 ? "r0l":"r0", right->aop->name[1]);
-      emitcode (instr, "%s,%s", AOP_NAME(result)[1], size==1 ? "r0l":"r0");
-    } else {
-      emitcode (instr, "%s,%s",
-               result->aop->name[1], right->aop->name[1]);
-    }
+    emitcode (instr, "%s,%s", AOP_NAME(result)[1], AOP_NAME(right)[1]);
     return;
   }
 }
@@ -1312,18 +1289,19 @@ static bool genDjnz (iCode * ic, iCode * ifx) {
   lbl = newiTempLabel (NULL);
   lbl1 = newiTempLabel (NULL);
 
-  aopOp (IC_RESULT (ic), TRUE);
+  aopOp (IC_RESULT (ic), TRUE, FALSE);
 
   if (AOP_TYPE(IC_RESULT(ic))==AOP_REG || AOP_TYPE(IC_RESULT(ic))==AOP_DIR) {
     emitcode ("djnz", "%s,%05d$", AOP_NAME(IC_RESULT(ic)), lbl->key+100);
-    emitcode ("bra", "%05d$", lbl1->key + 100);
+    emitcode ("br", "%05d$", lbl1->key + 100);
     emitcode ("", "%05d$:", lbl->key + 100);
     emitcode ("jmp", "%05d$", IC_TRUE (ifx)->key + 100);
     emitcode ("", "%05d$:", lbl1->key + 100);
     return TRUE;
   }
-    bailOut("genDjnz: aop type");
-    return FALSE;
+
+  bailOut("genDjnz: aop type");
+  return FALSE;
 }
 
 /*-----------------------------------------------------------------*/
@@ -1340,7 +1318,6 @@ void genXA51Code (iCode * lic) {
   iCode *ic;
   int cln = 0;
   
-  fprintf (stderr, "genXA51Code\n");
   lineHead = lineCurr = NULL;
   
   /* print the allocation information */
index 9719e76a983480812256e2b49d0afc3f3c2c4110..85f6e6bfb20e419758ddda70faafa1e16775f04c 100755 (executable)
@@ -33,9 +33,9 @@ enum
     AOP_FAR,
     AOP_CODE,
     AOP_GPTR,
-    AOP_STK, 
+    AOP_STK,
     AOP_IMMD, 
-    AOP_CRY
+    AOP_BIT
   };
 
 /* type asmop : a homogenised type for 
index f7bb02d4f891130f04fe19f1d3b318ab0f98c694..b92ae24c744ef20932871785d01d1cb97541be14 100755 (executable)
@@ -46,8 +46,8 @@ static char *_xa51_keywords[] =
 
 extern int rewinds;
 void   _xa51_genAssemblerEnd () {
-  fprintf (stderr, "Did %d rewind%c for c-line in asm comments\n", rewinds,
-          rewinds==1 ? '\0' : 's');
+  //fprintf (stderr, "Did %d rewind%c for c-line in asm comments\n", rewinds,
+  //rewinds==1 ? '\0' : 's');
 }
 
 void xa51_assignRegisters (eBBlock ** ebbs, int count);
index 94d2048608cf8321c92daed618de381cb1e60fe1..66cdeb4fed0ae56e001aafdaa083c1959f9bddb7 100755 (executable)
@@ -37,6 +37,7 @@
 /*-----------------------------------------------------------------*/
 
 extern void genXA51Code (iCode *);
+
 #define D(x)
 
 /* Global data */
@@ -166,8 +167,8 @@ static void freeReg (regs * reg, bool silent) {
   }
   
   if (!silent) {
-    fprintf (stderr, "freeReg: (%08x) %s (%s) ", xa51RegsInUse, 
-            reg->name, reg->sym->name);
+    D(fprintf (stderr, "freeReg: (%08x) %s (%s) ", xa51RegsInUse, 
+            reg->name, reg->sym->name));
   }
 
   if (reg->isFree || ((xa51RegsInUse&reg->regMask)!=reg->regMask)) {
@@ -178,7 +179,7 @@ static void freeReg (regs * reg, bool silent) {
   xa51RegsInUse &= ~reg->regMask;
   reg->isFree = 1;
   reg->sym = NULL;
-  if (!silent) fprintf (stderr, "(%08x)\n", xa51RegsInUse);
+  if (!silent) D(fprintf (stderr, "(%08x)\n", xa51RegsInUse));
 
   checkRegMask(__FUNCTION__);
 }
@@ -194,10 +195,10 @@ static bool allocReg (short size, short type, symbol *sym,
   checkRegMask(__FUNCTION__);
 
   if (!silent) {
-    fprintf (stderr, "allocReg (%08x) for %s size:%d, type:%s ", 
+    D(fprintf (stderr, "allocReg (%08x) for %s size:%d, type:%s ", 
             xa51RegsInUse,
             sym->name,
-            size, regTypeToStr(type));
+            size, regTypeToStr(type)));
   }
 
   switch (size) 
@@ -216,7 +217,7 @@ static bool allocReg (short size, short type, symbol *sym,
            reg->isFree=0; // redundant
            reg->sym = sym;
            if (!silent) {
-             fprintf (stderr, "(using gap) %s\n", reg->name);
+             D(fprintf (stderr, "(using gap) %s\n", reg->name));
            }
            checkRegMask(__FUNCTION__);
            return TRUE;
@@ -233,7 +234,7 @@ static bool allocReg (short size, short type, symbol *sym,
          regsXA51[i].isFree = 0; // redundant
          regsXA51[i].sym = sym;
          if (!silent) {
-           fprintf (stderr, "%s\n", regsXA51[i].name);
+           D(fprintf (stderr, "%s\n", regsXA51[i].name));
          }
          sym->regs[offset]=&regsXA51[i];
          checkRegMask(__FUNCTION__);
@@ -241,7 +242,7 @@ static bool allocReg (short size, short type, symbol *sym,
        }
       }
       if (!silent) {
-       fprintf (stderr, "failed (%08x)\n", xa51RegsInUse);
+       D(fprintf (stderr, "failed (%08x)\n", xa51RegsInUse));
       }
       checkRegMask(__FUNCTION__);
       return FALSE;
@@ -249,25 +250,25 @@ static bool allocReg (short size, short type, symbol *sym,
     case 3:
       // this must be a generic pointer
       if (!silent) {
-       fprintf (stderr, "trying 2+1\n");
+       D(fprintf (stderr, "trying 1+2\n"));
       }
-      // get the pointer part
-      if (allocReg (2, REG_PTR, sym, offset, silent)) {
-       // get the generic part
-       if ((xa51HasGprRegs && allocReg (1, REG_GPR, sym, offset+1, silent)) ||
-           allocReg (1, REG_PTR, sym, offset+1, silent)) {
+      // get the generic part
+      if ((xa51HasGprRegs && allocReg (1, REG_GPR, sym, offset+1, silent)) ||
+         allocReg (1, REG_PTR, sym, offset+1, silent)) {
+       // get the pointer part
+       if (allocReg (2, REG_PTR, sym, offset, silent)) {
          checkRegMask(__FUNCTION__);
          return TRUE;
        }
-       freeReg(sym->regs[offset], silent);
-       sym->regs[offset]=NULL;
+       freeReg(sym->regs[offset+1], silent);
+       sym->regs[offset+1]=NULL;
       }
       checkRegMask(__FUNCTION__);
       return FALSE;
       break;
     case 4: // this is a dword
       if (!silent) {
-       fprintf (stderr, "trying 2+2\n");
+       D(fprintf (stderr, "trying 2+2\n"));
       }
       if ((xa51HasGprRegs && allocReg (2, REG_GPR, sym, offset, silent)) ||
          allocReg (2, REG_PTR, sym, offset, silent)) {
@@ -560,7 +561,7 @@ createStackSpil (symbol * sym)
 
   char slocBuffer[30];
 
-  fprintf (stderr, "  createStackSpil: %s\n", sym->name);
+  D(fprintf (stderr, "  createStackSpil: %s\n", sym->name));
 
   /* first go try and find a free one that is already 
      existing on the stack */
@@ -644,7 +645,7 @@ spillThis (symbol * sym)
 {
   int i;
   
-  fprintf (stderr, "  spillThis: %s\n", sym->name);
+  D(fprintf (stderr, "  spillThis: %s\n", sym->name));
 
   /* if this is rematerializable or has a spillLocation
      we are okay, else we need to create a spillLocation
@@ -776,7 +777,7 @@ spillSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
   /* get something we can spil */
   ssym = selectSpil (ic, ebp, forSym);
 
-  fprintf (stderr, "  spillSomething: spilling %s\n", ssym->name);
+  D(fprintf (stderr, "  spillSomething: spilling %s\n", ssym->name));
 
   /* mark it as spilt */
   ssym->isspilt = ssym->spillA = 1;
@@ -834,9 +835,9 @@ spillSomething (iCode * ic, eBBlock * ebp, symbol * forSym)
 /*-----------------------------------------------------------------*/
 static bool getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym, short offset) {
 
-  fprintf (stderr, "getRegPtr: %s ", sym->name);
-  printTypeChain(sym->type, stderr);
-  fprintf (stderr, "\n");
+  D(fprintf (stderr, "getRegPtr: %s ", sym->name));
+  D(printTypeChain(sym->type, stderr));
+  D(fprintf (stderr, "\n"));
 
 tryAgain:
   /* try for a ptr type */
@@ -862,9 +863,9 @@ tryAgain:
 /*-----------------------------------------------------------------*/
 static bool getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym, short offset) {
 
-  fprintf (stderr, "getRegGpr: %s ", sym->name);
-  printTypeChain(sym->type, stderr);
-  fprintf (stderr, "\n");
+  D(fprintf (stderr, "getRegGpr: %s ", sym->name));
+  D(printTypeChain(sym->type, stderr));
+  D(fprintf (stderr, "\n"));
 
 tryAgain:
   /* try for gpr type */
@@ -945,7 +946,7 @@ static bool willCauseSpill (symbol *sym) {
     }
     return FALSE;
   }
-  fprintf (stderr, "  %s will cause a spill\n", sym->name);
+  D(fprintf (stderr, "  %s will cause a spill\n", sym->name));
   return TRUE;
 }
 
@@ -1405,6 +1406,7 @@ regTypeNum (eBBlock *ebbs)
              fprintf (stderr, "allocated more than 4 or 0 registers for type ");
              printTypeChain (sym->type, stderr);
              fprintf (stderr, "\n");
+             exit (1);
            }
 
          /* determine the type of register required */