From: michaelh Date: Tue, 18 Apr 2000 05:02:11 +0000 (+0000) Subject: * Added sfr space X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=2fefb198f01957f9b60c8e206c2490a8fa14f3f3;p=fw%2Fsdcc * Added sfr space * Fixed many bugs as in the README git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@236 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCglue.c b/src/SDCCglue.c index cba43a44..8d7b1f9d 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -31,6 +31,7 @@ symbol *interrupts[256]; void printIval (symbol *, link *, initList *, FILE *); extern int noAlloc; set *publics = NULL; /* public variables */ +set *externs = NULL; /* Varibles that are declared as extern */ /* TODO: this should be configurable (DS803C90 uses more than 6) */ int maxInterrupts = 6; @@ -152,9 +153,11 @@ static void emitRegularMap (memmap * map, bool addPublics, bool arFlag) for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) { - /* if extern then do nothing */ - if (IS_EXTERN (sym->etype)) + /* if extern then add it into the extern list */ + if (IS_EXTERN (sym->etype)) { + addSetHead (&externs, sym); continue; + } /* if allocation required check is needed then check if the symbol really requires @@ -207,7 +210,10 @@ static void emitRegularMap (memmap * map, bool addPublics, bool arFlag) /* allocate space */ if ((options.debug || sym->level == 0) && !options.nodebug) fprintf(map->oFile,"==.\n"); - tfprintf(map->oFile, "!labeldef\n", sym->rname); + if (IS_STATIC(sym->etype)) + tfprintf(map->oFile, "!slabeldef\n", sym->rname); + else + tfprintf(map->oFile, "!labeldef\n", sym->rname); tfprintf(map->oFile, "\t!ds\n", (unsigned int)getSize (sym->type) & 0xffff); } @@ -845,7 +851,7 @@ void printPublics (FILE * afile) symbol *sym; fprintf (afile, "%s", iComments2); - fprintf (afile, "; publics variables in this module\n"); + fprintf (afile, "; Public variables in this module\n"); fprintf (afile, "%s", iComments2); for (sym = setFirstItem (publics); sym; @@ -853,6 +859,22 @@ void printPublics (FILE * afile) tfprintf(afile, "\t!global\n", sym->rname); } +/*-----------------------------------------------------------------*/ +/* printExterns - generates .global for externs */ +/*-----------------------------------------------------------------*/ +void printExterns (FILE * afile) +{ + symbol *sym; + + fprintf (afile, "%s", iComments2); + fprintf (afile, "; Externals used\n"); + fprintf (afile, "%s", iComments2); + + for (sym = setFirstItem (externs); sym; + sym = setNextItem (externs)) + tfprintf(afile, "\t!global\n", sym->rname); +} + /*-----------------------------------------------------------------*/ /* emitOverlay - will emit code for the overlay stuff */ /*-----------------------------------------------------------------*/ @@ -881,8 +903,8 @@ static void emitOverlay(FILE *afile) for (sym = setFirstItem(ovrset); sym; sym = setNextItem(ovrset)) { - - /* if extern then do nothing */ + + /* if extern then add it to the publics tabledo nothing */ if (IS_EXTERN (sym->etype)) continue; @@ -1006,7 +1028,8 @@ void glue () /* print the global variables in this module */ printPublics (asmFile); - + printExterns (asmFile); + /* copy the sfr segment */ fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; special function registers\n"); diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 1c8b6586..03a7c456 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1545,7 +1545,8 @@ operand *geniCodeSubtract (operand *left, operand *right) return geniCodePtrPtrSubtract (left,right); /* if they are both literal then we know the result */ - if (IS_LITERAL(letype) && IS_LITERAL(retype)) + if (IS_LITERAL(letype) && IS_LITERAL(retype) + && left->isLiteral && right->isLiteral) return operandFromValue (valMinus(left->operand.valOperand, right->operand.valOperand)); @@ -1585,18 +1586,18 @@ operand *geniCodeAdd (operand *left, operand *right ) operand *size ; int isarray = 0; LRTYPE ; - + /* if left is an array then array access */ if (IS_ARRAY(ltype)) return geniCodeArray (left,right); /* if the right side is LITERAL zero */ /* return the left side */ - if (IS_LITERAL(retype) && !floatFromVal(valFromType(retype))) + if (IS_LITERAL(retype) && right->isLiteral && !floatFromVal(valFromType(retype))) return left; /* if left is literal zero return right */ - if (IS_LITERAL(letype) && !floatFromVal(valFromType(letype))) + if (IS_LITERAL(letype) && left->isLiteral && !floatFromVal(valFromType(letype))) return right ; /* if left is an array or pointer then size */ @@ -1615,7 +1616,8 @@ operand *geniCodeAdd (operand *left, operand *right ) } /* if they are both literals then we know */ - if (IS_LITERAL(letype) && IS_LITERAL(retype)) + if (IS_LITERAL(letype) && IS_LITERAL(retype) + && left->isLiteral && right->isLiteral) return operandFromValue (valPlus(valFromType(letype), valFromType(retype))); diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 28eebe72..5438a081 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -1314,7 +1314,6 @@ int main ( int argc, char **argv , char **envp) printUsage(); exit(0); } - if (srcFileName) preProcess(envp) ; @@ -1332,7 +1331,7 @@ int main ( int argc, char **argv , char **envp) if (!options.c1mode) assemble(envp); } else { - exit(-1); + return 1; } } @@ -1354,6 +1353,7 @@ int main ( int argc, char **argv , char **envp) unlink(preOutName); free(preOutName); } + return 0; } diff --git a/src/SDCCmem.h b/src/SDCCmem.h index 6f10c4e1..54f5229a 100644 --- a/src/SDCCmem.h +++ b/src/SDCCmem.h @@ -63,6 +63,7 @@ extern struct set *ovrSetSets; #define IN_DIRSPACE(map) (map && map->direct) #define IN_PAGEDSPACE(map) (map && map->paged ) #define IN_CODESPACE(map) (map && map->codesp) +#define IN_REGSP(map) (map && map->regsp) #define PTR_TYPE(map) (map ? (map->ptrType ? map->ptrType : POINTER)\ : GPOINTER) diff --git a/src/asm.c b/src/asm.c index 0b954512..e1b3a0b1 100644 --- a/src/asm.c +++ b/src/asm.c @@ -20,6 +20,12 @@ static va_list _iprintf(char *pInto, const char *szFormat, va_list ap) case 'r': wassert(0); break; + /* Name of the code segment */ + case 'C': + strcpy(pInto, CODE_NAME); + pInto = pStart + strlen(pStart); + sz++; + break; default: { /* Scan out the arg and pass it on to sprintf */ @@ -129,6 +135,7 @@ void asm_addTree(const ASM_MAPPINGS *pMappings) static const ASM_MAPPING _asxxxx_mapping[] = { { "labeldef", "%s::" }, + { "slabeldef", "%s:" }, { "tlabeldef", "%05d$:" }, { "tlabel", "%05d$" }, { "immed", "#" }, diff --git a/src/z80/gen.c b/src/z80/gen.c index 0313979b..13a85e80 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -333,7 +333,7 @@ static asmop *newAsmop (short type) /*-----------------------------------------------------------------*/ /* aopForSym - for a true symbol */ /*-----------------------------------------------------------------*/ -static asmop *aopForSym (iCode *ic,symbol *sym,bool result) +static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool requires_a) { asmop *aop; memmap *space= SPEC_OCLS(sym->etype); @@ -359,18 +359,17 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result) return aop; } -#if 0 if (IS_GB) { /* if it is in direct space */ - if (IN_DIRSPACE(space)) { - sym->aop = aop = newAsmop (AOP_DIR); + printf("sname %s: regsp %u\n", space->sname, space->regsp); + if (IN_REGSP(space) && !requires_a) { + sym->aop = aop = newAsmop (AOP_SFR); aop->aopu.aop_dir = sym->rname ; aop->size = getSize(sym->type); - emitcode("", "; AOP_DIR for %s", sym->rname); + emitcode("", "; AOP_SFR for %s", sym->rname); return aop; } } -#endif /* only remaining is far space */ /* in which case DPTR gets the address */ @@ -506,12 +505,16 @@ bool sameRegs (asmop *aop1, asmop *aop2 ) { int i; - if (aop1 == aop2) - return TRUE ; + if (aop1->type == AOP_SFR || + aop2->type == AOP_SFR) + return FALSE; + + if (aop1 == aop2) + return TRUE; if (aop1->type != AOP_REG || aop2->type != AOP_REG ) - return FALSE ; + return FALSE; if (aop1->size != aop2->size) return FALSE ; @@ -527,7 +530,7 @@ bool sameRegs (asmop *aop1, asmop *aop2 ) /*-----------------------------------------------------------------*/ /* aopOp - allocates an asmop for an operand : */ /*-----------------------------------------------------------------*/ -static void aopOp (operand *op, iCode *ic, bool result) +static void aopOp (operand *op, iCode *ic, bool result, bool requires_a) { asmop *aop; symbol *sym; @@ -556,7 +559,7 @@ static void aopOp (operand *op, iCode *ic, bool result) /* if this is a true symbol */ if (IS_TRUE_SYMOP(op)) { - op->aop = aopForSym(ic,OP_SYMBOL(op),result); + op->aop = aopForSym(ic,OP_SYMBOL(op),result, requires_a); return ; } @@ -609,7 +612,7 @@ static void aopOp (operand *op, iCode *ic, bool result) /* else spill location */ sym->aop = op->aop = aop = - aopForSym(ic,sym->usl.spillLoc,result); + aopForSym(ic,sym->usl.spillLoc,result, requires_a); aop->size = getSize(sym->type); return; } @@ -859,6 +862,11 @@ static void setupPair(PAIR_ID pairId, asmop *aop, int offset) _G.pairs[pairId].last_type = aop->type; } +static void emitIntLabel(int key) +{ + emit2("!tlabeldef", key); +} + static void emitLabel(int key) { emit2("!tlabeldef", key); @@ -898,14 +906,20 @@ static char *aopGet(asmop *aop, int offset, bool bit16) case AOP_DIR: wassert(IS_GB); - /* PENDING: for re-target: currently unsupported. */ - wassert(0); emitcode("ld", "a,(%s+%d) ; x", aop->aopu.aop_dir, offset); sprintf(s, "a"); ALLOC_ATOMIC(rs,strlen(s)+1); strcpy(rs,s); return rs; + case AOP_SFR: + wassert(IS_GB); + emitcode("ldh", "a,(%s+%d) ; x", aop->aopu.aop_dir, offset); + sprintf(s, "a"); + ALLOC_ATOMIC(rs,strlen(s)+1); + strcpy(rs,s); + return rs; + case AOP_REG: return aop->aopu.aop_reg[offset]->name; @@ -1002,12 +1016,18 @@ static void aopPut (asmop *aop, char *s, int offset) case AOP_DIR: /* Direct. Hmmm. */ wassert(IS_GB); - /* Currently unsupported */ - wassert(0); - emitcode("ld", "a,%s", s); + if (strcmp(s, "a")) + emitcode("ld", "a,%s", s); emitcode("ld", "(%s+%d),a", aop->aopu.aop_dir, offset); break; + case AOP_SFR: + wassert(IS_GB); + if (strcmp(s, "a")) + emitcode("ld", "a,%s", s); + emitcode("ldh", "(%s+%d),a", aop->aopu.aop_dir, offset); + break; + case AOP_REG: emitcode("ld","%s,%s", aop->aopu.aop_reg[offset]->name,s); @@ -1201,8 +1221,8 @@ static void genNot (iCode *ic) link *optype = operandType(IC_LEFT(ic)); /* assign asmOps to operand & result */ - aopOp (IC_LEFT(ic),ic,FALSE); - aopOp (IC_RESULT(ic),ic,TRUE); + aopOp (IC_LEFT(ic),ic,FALSE, TRUE); + aopOp (IC_RESULT(ic),ic,TRUE, FALSE); /* if in bit space then a special case */ if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) { @@ -1238,8 +1258,8 @@ static void genCpl (iCode *ic) /* assign asmOps to operand & result */ - aopOp (IC_LEFT(ic),ic,FALSE); - aopOp (IC_RESULT(ic),ic,TRUE); + aopOp (IC_LEFT(ic),ic,FALSE, FALSE); + aopOp (IC_RESULT(ic),ic,TRUE, FALSE); /* if both are in bit space then a special case */ @@ -1270,8 +1290,8 @@ static void genUminus (iCode *ic) link *optype, *rtype; /* assign asmops */ - aopOp(IC_LEFT(ic),ic,FALSE); - aopOp(IC_RESULT(ic),ic,TRUE); + aopOp(IC_LEFT(ic),ic,FALSE, FALSE); + aopOp(IC_RESULT(ic),ic,TRUE, FALSE); /* if both in bit space then special case */ @@ -1363,7 +1383,7 @@ static void genIpush (iCode *ic) if (OP_SYMBOL(IC_LEFT(ic))->isspilt) return ; - aopOp(IC_LEFT(ic),ic,FALSE); + aopOp(IC_LEFT(ic),ic,FALSE, FALSE); size = AOP_SIZE(IC_LEFT(ic)); /* push it on the stack */ if (isPair(AOP(IC_LEFT(ic)))) { @@ -1388,7 +1408,7 @@ static void genIpush (iCode *ic) at this point? */ /* then do the push */ - aopOp(IC_LEFT(ic),ic,FALSE); + aopOp(IC_LEFT(ic),ic,FALSE, FALSE); size = AOP_SIZE(IC_LEFT(ic)); @@ -1429,7 +1449,7 @@ static void genIpop (iCode *ic) if (OP_SYMBOL(IC_LEFT(ic))->isspilt) return ; - aopOp(IC_LEFT(ic),ic,FALSE); + aopOp(IC_LEFT(ic),ic,FALSE, FALSE); size = AOP_SIZE(IC_LEFT(ic)); offset = (size-1); if (isPair(AOP(IC_LEFT(ic)))) { @@ -1462,7 +1482,7 @@ static void emitCall (iCode *ic, bool ispcall) for (sic = setFirstItem(sendSet) ; sic ; sic = setNextItem(sendSet)) { int size, offset = 0; - aopOp(IC_LEFT(sic),sic,FALSE); + aopOp(IC_LEFT(sic),sic,FALSE, FALSE); size = AOP_SIZE(IC_LEFT(sic)); while (size--) { char *l = aopGet(AOP(IC_LEFT(sic)),offset, @@ -1479,7 +1499,7 @@ static void emitCall (iCode *ic, bool ispcall) } if (ispcall) { - aopOp(IC_LEFT(ic),ic,FALSE); + aopOp(IC_LEFT(ic),ic,FALSE, FALSE); if (isLitWord(AOP(IC_LEFT(ic)))) { emitcode("", "; Special case where the pCall is to a constant"); @@ -1515,7 +1535,7 @@ static void emitCall (iCode *ic, bool ispcall) IS_TRUE_SYMOP(IC_RESULT(ic)) ) { accInUse++; - aopOp(IC_RESULT(ic),ic,FALSE); + aopOp(IC_RESULT(ic),ic,FALSE, FALSE); accInUse--; assignResultValue(IC_RESULT(ic)); @@ -1678,7 +1698,7 @@ static void genRet (iCode *ic) /* we have something to return then move the return value into place */ - aopOp(IC_LEFT(ic),ic,FALSE); + aopOp(IC_LEFT(ic),ic,FALSE, FALSE); size = AOP_SIZE(IC_LEFT(ic)); if ((size == 2) && ((l = aopGetWord(AOP(IC_LEFT(ic)), 0)))) { @@ -1793,7 +1813,7 @@ static bool genPlusIncr (iCode *ic) symbol *tlbl = NULL; while (size--) { if (offset) { - emitLabel(tlbl->key+100); + emitIntLabel(tlbl->key+100); } emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)), offset++, FALSE)); if (size) { @@ -1815,7 +1835,6 @@ static bool genPlusIncr (iCode *ic) if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) { while (icount--) emitcode ("inc","%s",aopGet(AOP(IC_LEFT(ic)),0, FALSE)); - return TRUE ; } @@ -1849,9 +1868,9 @@ static void genPlus (iCode *ic) /* special cases :- */ - aopOp (IC_LEFT(ic),ic,FALSE); - aopOp (IC_RIGHT(ic),ic,FALSE); - aopOp (IC_RESULT(ic),ic,TRUE); + aopOp (IC_LEFT(ic),ic,FALSE, FALSE); + aopOp (IC_RIGHT(ic),ic,FALSE, FALSE); + aopOp (IC_RESULT(ic),ic,TRUE, FALSE); /* Swap the left and right operands if: @@ -1923,13 +1942,13 @@ static void genPlus (iCode *ic) emitcode("adc","a,%s", aopGet(AOP(IC_RIGHT(ic)),offset,FALSE)); } else { - MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE)); + MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE)); if(offset == 0) emitcode("add","a,%s", - aopGet(AOP(IC_LEFT(ic)),offset,FALSE)); + aopGet(AOP(IC_RIGHT(ic)),offset,FALSE)); else emitcode("adc","a,%s", - aopGet(AOP(IC_LEFT(ic)),offset,FALSE)); + aopGet(AOP(IC_RIGHT(ic)),offset,FALSE)); } aopPut(AOP(IC_RESULT(ic)),"a",offset++); } @@ -2032,9 +2051,9 @@ static void genMinus (iCode *ic) int size, offset = 0; unsigned long lit = 0L; - aopOp (IC_LEFT(ic),ic,FALSE); - aopOp (IC_RIGHT(ic),ic,FALSE); - aopOp (IC_RESULT(ic),ic,TRUE); + aopOp (IC_LEFT(ic),ic,FALSE, FALSE); + aopOp (IC_RIGHT(ic),ic,FALSE, FALSE); + aopOp (IC_RESULT(ic),ic,TRUE, FALSE); /* special cases :- */ /* if both left & right are in bit space */ @@ -2303,9 +2322,9 @@ static void genCmpGt (iCode *ic, iCode *ifx) retype =getSpec(operandType(right)); sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype)); /* assign the amsops */ - aopOp (left,ic,FALSE); - aopOp (right,ic,FALSE); - aopOp (result,ic,TRUE); + aopOp (left,ic,FALSE, FALSE); + aopOp (right,ic,FALSE, FALSE); + aopOp (result,ic,TRUE, FALSE); genCmp(right, left, result, ifx, sign); @@ -2332,9 +2351,9 @@ static void genCmpLt (iCode *ic, iCode *ifx) sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype)); /* assign the amsops */ - aopOp (left,ic,FALSE); - aopOp (right,ic,FALSE); - aopOp (result,ic,TRUE); + aopOp (left,ic,FALSE, FALSE); + aopOp (right,ic,FALSE, FALSE); + aopOp (result,ic,TRUE, FALSE); genCmp(left, right, result, ifx, sign); @@ -2444,9 +2463,9 @@ static void genCmpEq (iCode *ic, iCode *ifx) { operand *left, *right, *result; - aopOp((left=IC_LEFT(ic)),ic,FALSE); - aopOp((right=IC_RIGHT(ic)),ic,FALSE); - aopOp((result=IC_RESULT(ic)),ic,TRUE); + aopOp((left=IC_LEFT(ic)),ic,FALSE, FALSE); + aopOp((right=IC_RIGHT(ic)),ic,FALSE, FALSE); + aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE); /* Swap operands if it makes the operation easier. ie if: 1. Left is a literal. @@ -2542,9 +2561,9 @@ static void genAndOp (iCode *ic) /* note here that && operations that are in an if statement are taken away by backPatchLabels only those used in arthmetic operations remain */ - aopOp((left=IC_LEFT(ic)),ic,FALSE); - aopOp((right=IC_RIGHT(ic)),ic,FALSE); - aopOp((result=IC_RESULT(ic)),ic,FALSE); + aopOp((left=IC_LEFT(ic)),ic,FALSE, TRUE); + aopOp((right=IC_RIGHT(ic)),ic,FALSE, TRUE); + aopOp((result=IC_RESULT(ic)),ic,FALSE, FALSE); /* if both are bit variables */ if (AOP_TYPE(left) == AOP_CRY && @@ -2575,9 +2594,9 @@ static void genOrOp (iCode *ic) /* note here that || operations that are in an if statement are taken away by backPatchLabels only those used in arthmetic operations remain */ - aopOp((left=IC_LEFT(ic)),ic,FALSE); - aopOp((right=IC_RIGHT(ic)),ic,FALSE); - aopOp((result=IC_RESULT(ic)),ic,FALSE); + aopOp((left=IC_LEFT(ic)),ic,FALSE, TRUE); + aopOp((right=IC_RIGHT(ic)),ic,FALSE, TRUE); + aopOp((result=IC_RESULT(ic)),ic,FALSE, FALSE); /* if both are bit variables */ if (AOP_TYPE(left) == AOP_CRY && @@ -2647,9 +2666,9 @@ static void genAnd (iCode *ic, iCode *ifx) unsigned long lit = 0L; int bytelit = 0; - aopOp((left = IC_LEFT(ic)),ic,FALSE); - aopOp((right= IC_RIGHT(ic)),ic,FALSE); - aopOp((result=IC_RESULT(ic)),ic,TRUE); + aopOp((left = IC_LEFT(ic)),ic,FALSE, FALSE); + aopOp((right= IC_RIGHT(ic)),ic,FALSE, FALSE); + aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE); #ifdef DEBUG_TYPE emitcode("","; Type res[%d] = l[%d]&r[%d]", @@ -2771,7 +2790,7 @@ static void genAnd (iCode *ic, iCode *ifx) MOVA(aopGet(AOP(left),offset,FALSE)); emitcode("and","a,%s", aopGet(AOP(right),offset,FALSE)); - emitcode("ld", "%s,a", aopGet(AOP(left),offset,FALSE)); + aopPut(AOP(left), "a", offset); } } @@ -2783,7 +2802,7 @@ static void genAnd (iCode *ic, iCode *ifx) MOVA(aopGet(AOP(left),offset,FALSE)); emitcode("and","a,%s", aopGet(AOP(right),offset,FALSE)); - emitcode("ld", "%s,a", aopGet(AOP(left),offset,FALSE)); + aopPut(AOP(left), "a", offset); } } } @@ -2836,9 +2855,9 @@ static void genOr (iCode *ic, iCode *ifx) int size, offset=0; unsigned long lit = 0L; - aopOp((left = IC_LEFT(ic)),ic,FALSE); - aopOp((right= IC_RIGHT(ic)),ic,FALSE); - aopOp((result=IC_RESULT(ic)),ic,TRUE); + aopOp((left = IC_LEFT(ic)),ic,FALSE, FALSE); + aopOp((right= IC_RIGHT(ic)),ic,FALSE, FALSE); + aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE); #if 1 emitcode("","; Type res[%d] = l[%d]&r[%d]", @@ -2895,19 +2914,19 @@ static void genOr (iCode *ic, iCode *ifx) if(((lit >> (offset*8)) & 0x0FFL) == 0x00L) continue; else { - MOVA(aopGet(AOP(right),offset,FALSE)); - emitcode("or","a,%s; 5", - aopGet(AOP(left),offset,FALSE)); - aopPut(AOP(result),"a ; 8", offset); + MOVA(aopGet(AOP(left),offset,FALSE)); + emitcode("or","a,%s", + aopGet(AOP(right),offset,FALSE)); + aopPut(AOP(result),"a", offset); } } else { if (AOP_TYPE(left) == AOP_ACC) - emitcode("or","a,%s ; 6",aopGet(AOP(right),offset,FALSE)); + emitcode("or","a,%s",aopGet(AOP(right),offset,FALSE)); else { - MOVA(aopGet(AOP(right),offset,FALSE)); - emitcode("or","a,%s ; 7", - aopGet(AOP(left),offset,FALSE)); - aopPut(AOP(result),"a ; 8", offset); + MOVA(aopGet(AOP(left),offset,FALSE)); + emitcode("or","a,%s", + aopGet(AOP(right),offset,FALSE)); + aopPut(AOP(result),"a", offset); } } } @@ -2957,9 +2976,9 @@ static void genXor (iCode *ic, iCode *ifx) int size, offset=0; unsigned long lit = 0L; - aopOp((left = IC_LEFT(ic)),ic,FALSE); - aopOp((right= IC_RIGHT(ic)),ic,FALSE); - aopOp((result=IC_RESULT(ic)),ic,TRUE); + aopOp((left = IC_LEFT(ic)),ic,FALSE, FALSE); + aopOp((right= IC_RIGHT(ic)),ic,FALSE, FALSE); + aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE); /* if left is a literal & right is not then exchange them */ if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) || @@ -3337,8 +3356,8 @@ static void genLeftShiftLiteral (operand *left, freeAsmop(right,NULL,ic); - aopOp(left,ic,FALSE); - aopOp(result,ic,FALSE); + aopOp(left,ic,FALSE, FALSE); + aopOp(result,ic,FALSE, FALSE); size = getSize(operandType(result)); @@ -3388,7 +3407,7 @@ static void genLeftShift (iCode *ic) left = IC_LEFT(ic); result = IC_RESULT(ic); - aopOp(right,ic,FALSE); + aopOp(right,ic,FALSE, FALSE); /* if the shift count is known then do it as efficiently as possible */ @@ -3404,8 +3423,8 @@ static void genLeftShift (iCode *ic) emitcode("ld","a,%s",aopGet(AOP(right),0,FALSE)); emitcode("inc","a"); freeAsmop (right,NULL,ic); - aopOp(left,ic,FALSE); - aopOp(result,ic,FALSE); + aopOp(left,ic,FALSE, FALSE); + aopOp(result,ic,FALSE, FALSE); /* now move the left to the result if they are not the same */ @@ -3553,8 +3572,8 @@ static void genRightShiftLiteral (operand *left, freeAsmop(right,NULL,ic); - aopOp(left,ic,FALSE); - aopOp(result,ic,FALSE); + aopOp(left,ic,FALSE, FALSE); + aopOp(result,ic,FALSE, FALSE); size = getSize(operandType(result)); @@ -3619,7 +3638,7 @@ static void genRightShift (iCode *ic) left = IC_LEFT(ic); result = IC_RESULT(ic); - aopOp(right,ic,FALSE); + aopOp(right,ic,FALSE, FALSE); /* if the shift count is known then do it as efficiently as possible */ @@ -3628,8 +3647,8 @@ static void genRightShift (iCode *ic) return; } - aopOp(left,ic,FALSE); - aopOp(result,ic,FALSE); + aopOp(left,ic,FALSE, FALSE); + aopOp(result,ic,FALSE, FALSE); /* now move the left to the result if they are not the same */ @@ -3689,8 +3708,8 @@ static void genGenPointerGet (operand *left, if (IS_GB) pair = PAIR_DE; - aopOp(left,ic,FALSE); - aopOp(result,ic,FALSE); + aopOp(left,ic,FALSE, FALSE); + aopOp(result,ic,FALSE, FALSE); if (isPair(AOP(left)) && AOP_SIZE(result)==1) { /* Just do it */ @@ -3777,8 +3796,8 @@ static void genGenPointerSet (operand *right, link *retype = getSpec(operandType(right)); PAIR_ID pairId = PAIR_HL; - aopOp(result,ic,FALSE); - aopOp(right,ic,FALSE); + aopOp(result,ic,FALSE, FALSE); + aopOp(right,ic,FALSE, FALSE); if (IS_GB) pairId = PAIR_DE; @@ -3860,7 +3879,7 @@ static void genIfx (iCode *ic, iCode *popIc) operand *cond = IC_COND(ic); int isbit =0; - aopOp(cond,ic,FALSE); + aopOp(cond,ic,FALSE, TRUE); /* get the value into acc */ if (AOP_TYPE(cond) != AOP_CRY) @@ -3894,7 +3913,7 @@ static void genAddrOf (iCode *ic) { symbol *sym = OP_SYMBOL(IC_LEFT(ic)); - aopOp(IC_RESULT(ic),ic,FALSE); + aopOp(IC_RESULT(ic),ic,FALSE, FALSE); /* if the operand is on the stack then we need to get the stack offset of this @@ -3948,8 +3967,8 @@ static void genAssign (iCode *ic) } #endif - aopOp(right,ic,FALSE); - aopOp(result,ic,TRUE); + aopOp(right,ic,FALSE, FALSE); + aopOp(result,ic,TRUE, FALSE); /* if they are the same registers */ if (sameRegs(AOP(right),AOP(result))) { @@ -4035,7 +4054,7 @@ static void genJumpTab (iCode *ic) symbol *jtab; char *l; - aopOp(IC_JTCOND(ic),ic,FALSE); + aopOp(IC_JTCOND(ic),ic,FALSE, FALSE); /* get the condition into accumulator */ l = aopGet(AOP(IC_JTCOND(ic)),0,FALSE); if (!IS_GB) @@ -4073,8 +4092,8 @@ static void genCast (iCode *ic) if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic))) return ; - aopOp(right,ic,FALSE) ; - aopOp(result,ic,FALSE); + aopOp(right,ic,FALSE, FALSE); + aopOp(result,ic,FALSE, FALSE); /* if the result is a bit */ if (AOP_TYPE(result) == AOP_CRY) { @@ -4154,7 +4173,7 @@ static void genReceive (iCode *ic) wassert(0); } else { accInUse++; - aopOp(IC_RESULT(ic),ic,FALSE); + aopOp(IC_RESULT(ic),ic,FALSE, FALSE); accInUse--; assignResultValue(IC_RESULT(ic)); } diff --git a/src/z80/gen.h b/src/z80/gen.h index 9eb59f04..b312bb4c 100644 --- a/src/z80/gen.h +++ b/src/z80/gen.h @@ -32,7 +32,9 @@ typedef enum { /* Is in a register */ AOP_REG, /* Is in direct space */ - AOP_DIR, + AOP_DIR, + /* SFR space ($FF00 and above) */ + AOP_SFR, /* Is on the stack */ AOP_STK , /* Is an immediate value */ diff --git a/src/z80/main.c b/src/z80/main.c index 58d346d7..b44921cb 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -18,7 +18,10 @@ static struct { bool fsetAsmType; } _G; -static char *_keywords[] = { NULL }; +static char *_keywords[] = { + "sfr", + NULL +}; extern PORT gbz80_port; extern PORT z80_port; @@ -55,9 +58,28 @@ static int _reg_parm(link *l) } +static bool _startsWith(const char *sz, const char *key) +{ + return !strncmp(sz, key, strlen(key)); +} + +static void _chomp(char *sz) +{ + char *nl; + while ((nl = strrchr(sz, '\n'))) + *nl = '\0'; +} + static int _process_pragma(const char *sz) { - printf("Got pragma \"%s\"\n", sz); + if (_startsWith(sz, "bank=")) { + char buffer[128]; + sprintf(buffer, "%s", sz+5); + _chomp(buffer); + gbz80_port.mem.code_name = gc_strdup(buffer); + code->sname = gbz80_port.mem.code_name; + return 0; + } return 1; } @@ -190,17 +212,17 @@ PORT z80_port = { 1, 1, 2, 4, 2, 2, 2, 1, 4, 4 }, { - "_XSEG", - "_STACK", - "_CODE", - "_DATA", - "_ISEG", - "_XSEG", - "_BSEG", - "_RSEG", - "_GSINIT", - "_OVERLAY", - "_GSFINAL", + "XSEG", + "STACK", + "CODE", + "DATA", + "ISEG", + "XSEG", + "BSEG", + "RSEG", + "GSINIT", + "OVERLAY", + "GSFINAL", NULL, NULL, 1 @@ -249,17 +271,17 @@ PORT gbz80_port = { 1, 1, 2, 4, 2, 2, 2, 1, 4, 4 }, { - "_XSEG", - "_STACK", - "_CODE", - "_DATA", - "_ISEG", - "_XSEG", - "_BSEG", - "_RSEG", - "_GSINIT", - "_OVERLAY", - "_GSFINAL", + "XSEG", + "STACK", + "CODE", + "DATA", + "ISEG", + "XSEG", + "BSEG", + "RSEG", + "GSINIT", + "OVERLAY", + "GSFINAL", NULL, NULL, 1 diff --git a/src/z80/mappings.i b/src/z80/mappings.i index 677e359c..1bc2d5fb 100644 --- a/src/z80/mappings.i +++ b/src/z80/mappings.i @@ -1,4 +1,8 @@ static const ASM_MAPPING _asxxxx_gb_mapping[] = { + /* We want to prepend the _ */ + { "area", ".area _%s" }, + { "areacode", ".area _%s" }, + { "areadata", ".area _%s" }, { "functionlabeldef", "%s:" }, { "*hl", "(hl)" }, { "di", "di" }, @@ -63,6 +67,7 @@ static const ASM_MAPPING _asxxxx_z80_mapping[] = { static const ASM_MAPPING _rgbds_mapping[] = { { "global", "GLOBAL %s" }, + { "slabeldef", "%s:" }, { "labeldef", "%s:" }, { "tlabeldef", ".l%05d:" }, { "tlabel", ".l%05d" }, @@ -90,8 +95,8 @@ static const ASM_MAPPING _rgbds_mapping[] = { { "functionlabeldef", "%s:" }, { "zero", "$00" }, { "one", "$01" }, - { "area", "SECTION \"%s\",CODE" }, - { "areacode", "SECTION \"CODE\",CODE" }, + { "area", "SECTION \"%s\",%C" }, + { "areacode", "SECTION \"CODE\",%C" }, { "areadata", "SECTION \"DATA\",BSS" }, { "ascii", "DB \"%s\"" }, { "ds", "DS %d" }, @@ -145,6 +150,7 @@ static const ASM_MAPPING _rgbds_gb_mapping[] = { static const ASM_MAPPING _isas_mapping[] = { { "global", "GLOBAL %s" }, + { "slabeldef", "%s:" }, { "labeldef", "%s:" }, { "tlabeldef", "?l%05d:" }, { "tlabel", "?l%05d" }, diff --git a/support/cpp/cpplib.c b/support/cpp/cpplib.c index 06d7e71f..0b3a28ae 100644 --- a/support/cpp/cpplib.c +++ b/support/cpp/cpplib.c @@ -1024,7 +1024,7 @@ copy_rest_of_line ( break; case '/': nextc = PEEKC(); - if (nextc == '*' || (opts->cplusplus_comments && nextc == '*')) + if (nextc == '*' || (opts->cplusplus_comments && nextc == '/')) goto scan_directive_token; break; case '\f': @@ -1397,6 +1397,11 @@ collect_expansion ( concat = p; #endif } + else if (*p == '/') { + /* A c++ comment. Discard to the end of line */ + exp_p--; + p = limit; + } break; } }