From b1f9b010e519cb7319310c975755d3014534254f Mon Sep 17 00:00:00 2001 From: johanknol Date: Tue, 22 Jan 2002 18:16:59 +0000 Subject: [PATCH] minor xa51 improvements git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1835 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- as/xa51/Makefile | 4 +- as/xa51/xa_asm.l | 2 +- as/xa51/xa_asm.y | 8 -- as/xa51/xa_main.c | 178 +++++++++++++++++++++---------- as/xa51/xa_main.h | 1 + device/lib/Makefile.in | 34 +++++- src/asm.c | 2 +- src/xa51/gen.c | 237 +++++++++++++++++++---------------------- src/xa51/gen.h | 4 +- src/xa51/main.c | 4 +- src/xa51/ralloc.c | 56 +++++----- 11 files changed, 301 insertions(+), 229 deletions(-) diff --git a/as/xa51/Makefile b/as/xa51/Makefile index 6edcc239..0ed11c76 100644 --- a/as/xa51/Makefile +++ b/as/xa51/Makefile @@ -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 diff --git a/as/xa51/xa_asm.l b/as/xa51/xa_asm.l index 61fdaf63..b47736bb 100644 --- a/as/xa51/xa_asm.l +++ b/as/xa51/xa_asm.l @@ -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); diff --git a/as/xa51/xa_asm.y b/as/xa51/xa_asm.y index 4567d7e3..8ef50d5e 100644 --- a/as/xa51/xa_asm.y +++ b/as/xa51/xa_asm.y @@ -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); diff --git a/as/xa51/xa_main.c b/as/xa51/xa_main.c index b01f8294..1736650b 100644 --- a/as/xa51/xa_main.c +++ b/as/xa51/xa_main.c @@ -21,6 +21,7 @@ #include #include #include +#include #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 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); } diff --git a/as/xa51/xa_main.h b/as/xa51/xa_main.h index e3bf912b..b31227ab 100644 --- a/as/xa51/xa_main.h +++ b/as/xa51/xa_main.h @@ -44,6 +44,7 @@ struct target { struct target *next; }; struct area_struct { + int start; int alloc_position; }; diff --git a/device/lib/Makefile.in b/device/lib/Makefile.in index 7c28242b..4b97353a 100644 --- a/device/lib/Makefile.in +++ b/device/lib/Makefile.in @@ -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 # ---------------------- diff --git a/src/asm.c b/src/asm.c index 66e8d201..325b28a9 100644 --- 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", diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 8653e54a..bbe49199 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -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 */ diff --git a/src/xa51/gen.h b/src/xa51/gen.h index 9719e76a..85f6e6bf 100755 --- a/src/xa51/gen.h +++ b/src/xa51/gen.h @@ -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 diff --git a/src/xa51/main.c b/src/xa51/main.c index f7bb02d4..b92ae24c 100755 --- a/src/xa51/main.c +++ b/src/xa51/main.c @@ -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); diff --git a/src/xa51/ralloc.c b/src/xa51/ralloc.c index 94d20486..66cdeb4f 100755 --- a/src/xa51/ralloc.c +++ b/src/xa51/ralloc.c @@ -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®->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]=®sXA51[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 */ -- 2.30.2