From d935ec1dfcf761b5f0790fce80953d7b80d99252 Mon Sep 17 00:00:00 2001 From: michaelh Date: Tue, 22 Feb 2000 04:02:54 +0000 Subject: [PATCH] Lots. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@115 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- as/z80/Makefile | 3 +- as/z80/asmain.c | 3 +- link/z80/Makefile | 3 +- link/z80/lkmain.c | 2 +- src/SDCCast.c | 2 +- src/SDCCglobl.h | 4 +- src/SDCCglue.c | 21 +++-- src/SDCCicode.c | 4 +- src/SDCCmain.c | 122 +++++++++++++++---------- src/SDCCopt.c | 93 +++++++++---------- src/SDCCsymt.c | 147 +++++++++++++++---------------- src/SDCCsymt.h | 41 +++------ src/mcs51/main.c | 3 + src/port.h | 11 ++- src/z80/Makefile | 2 +- src/z80/gbz80.c | 3 + src/z80/gen.c | 28 ++++-- src/z80/main.c | 3 + support/tests/dhrystone/Makefile | 23 +++-- support/tests/dhrystone/dhry.c | 25 ++---- 20 files changed, 293 insertions(+), 250 deletions(-) diff --git a/as/z80/Makefile b/as/z80/Makefile index 25fce800..17520bca 100644 --- a/as/z80/Makefile +++ b/as/z80/Makefile @@ -5,8 +5,9 @@ include $(TOPDIR)/Makefile.common SRC = . OBJS = asdata.o asexpr.o aslex.o aslist.o asmain.o asout.o \ assubr.o assym.o z80adr.o z80ext.o z80mch.o z80pst.o -BINS = as$E +BINS = $(TOPDIR)/bin/as-gbz80$E +CFLAGS += -DINDEXLIB -DMLH_MAP -DGAMEBOY -DUNIX -DSDK CFLAGS += -funsigned-char -ggdb LDFLAGS += -lm diff --git a/as/z80/asmain.c b/as/z80/asmain.c index d407b3eb..6e1aec7c 100644 --- a/as/z80/asmain.c +++ b/as/z80/asmain.c @@ -153,8 +153,7 @@ */ VOID -main(argc, argv) -char *argv[]; +main(int argc, char **argv) { register char *p; register c, i; diff --git a/link/z80/Makefile b/link/z80/Makefile index 3848c519..1ec1dbfd 100644 --- a/link/z80/Makefile +++ b/link/z80/Makefile @@ -5,8 +5,9 @@ include $(TOPDIR)/Makefile.common OBJS = lkarea.o lkdata.o lkeval.o lkhead.o lkihx.o lklex.o \ lklibr.o lklist.o lkmain.o lkrloc.o lks19.o lksym.o \ lkgb.o lkgg.o -BINS = link$E +BINS = $(TOPDIR)/bin/link-gbz80$E +CFLAGS += -DINDEXLIB -DMLH_MAP -DGAMEBOY -DUNIX -DSDK -DSDK_VERSION_STRING="\"3.0.0\"" -DTARGET_STRING="\"gbz80\"" CFLAGS += -funsigned-char -DUNIX all: $(BINS) diff --git a/link/z80/lkmain.c b/link/z80/lkmain.c index c2d8936e..1d59a2a7 100644 --- a/link/z80/lkmain.c +++ b/link/z80/lkmain.c @@ -135,7 +135,7 @@ int binary = 0; #ifdef GAMEBOY char *default_basep[] = { "_CODE=0x0200", - "_BSS=0xC0A0", + "_DATA=0xC0A0", NULL }; diff --git a/src/SDCCast.c b/src/SDCCast.c index 772fadb7..660db8da 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -1517,7 +1517,7 @@ ast *decorateType (ast *tree) TTYPE(tree) = TETYPE(tree) = tree->opval.val->type = tree->opval.val->sym->type = tree->opval.val->etype = tree->opval.val->sym->etype = - copyLinkChain(intType); + copyLinkChain(INTTYPE); } else { diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index 3f0c4bdd..bb71339c 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -194,7 +194,9 @@ struct options { int debug : 1 ; /* generate extra debug info */ int stackOnData:1 ; /* stack after data segment */ int noregparms: 1 ; /* do not pass parameters in registers */ - char *peep_file ; /* additional rules for peep hole */ + int c1mode : 1 ; /* Act like c1 - no pre-proc, asm or link */ + char *peep_file ; /* additional rules for peep hole */ + char *out_name ; /* Asm output name for c1 mode */ char *calleeSaves[128]; /* list of functions using callee save */ char *excludeRegs[32] ; /* registers excluded from saving */ diff --git a/src/SDCCglue.c b/src/SDCCglue.c index f80af473..047074b9 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -892,8 +892,13 @@ void glue () if (options.debug) cdbStructBlock (0,cdbFile); - /* create the interrupt vector table */ - createInterruptVect ((vFile = tmpfile ())); + vFile = tmpfile(); + /* PENDING: this isnt the best place but it will do */ + if (port->general.glue_up_main) { + /* create the interrupt vector table */ + createInterruptVect (vFile); + } + addSetHead(&tmpfileSet,vFile); /* emit code for the all the variables declared */ @@ -903,8 +908,15 @@ void glue () /* now put it all together into the assembler file */ /* create the assembler file name */ - sprintf (buffer, srcFileName); - strcat (buffer, ".asm"); + + if (!options.c1mode) { + sprintf (buffer, srcFileName); + strcat (buffer, ".asm"); + } + else { + strcpy(buffer, options.out_name); + } + if (!(asmFile = fopen (buffer, "w"))) { werror (E_FILE_OPEN_ERR, buffer); exit (1); @@ -924,7 +936,6 @@ void glue () /* print the global variables in this module */ printPublics (asmFile); - /* copy the sfr segment */ fprintf (asmFile, "%s", iComments2); diff --git a/src/SDCCicode.c b/src/SDCCicode.c index f42e063e..b633ce4d 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2674,7 +2674,7 @@ int geniCodeJumpTable (operand *cond, value *caseVals, ast *tree) /* if the min is not zero then we no make it zero */ if (min) { cond = geniCodeSubtract(cond,operandFromLit(min)); - setOperandType(cond,ucharType); + setOperandType(cond, UCHARTYPE); } /* now create the jumptable */ @@ -2903,7 +2903,7 @@ operand *ast2iCode (ast *tree) case GETHBIT: { operand *op = geniCodeUnary (geniCodeRValue(left,FALSE),tree->opval.op); - setOperandType(op,ucharType); + setOperandType(op, UCHARTYPE); return op; } case '>' : diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 2ad90c4c..6a9126d4 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -112,6 +112,7 @@ char *preOutName; #define OPTION_VERSION "-version" #define OPTION_STKAFTRDATA "-stack-after-data" #define OPTION_PREPROC_ONLY "-preprocessonly" +#define OPTION_C1_MODE "-c1mode" #define OPTION_HELP "-help" #define OPTION_CALLEE_SAVES "-callee-saves" #define OPTION_NOREGPARMS "-noregparms" @@ -345,7 +346,7 @@ static void processFile (char *s) } /* otherwise depending on the file type */ - if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0) { + if (strcmp(fext,".c") == 0 || strcmp(fext,".C") == 0 || options.c1mode) { /* source file name : not if we already have a source file */ if (srcFileName) { @@ -402,6 +403,20 @@ static void processFile (char *s) } +static void _processC1Arg(char *s) +{ + if (srcFileName) { + if (options.out_name) { + werror(W_TOO_MANY_SRC,s); + return; + } + options.out_name = strdup(s); + } + else { + processFile(s); + } +} + static void _addToList(const char **list, const char *str) { /* This is the bad way to do things :) */ @@ -536,6 +551,11 @@ int parseCmdLine ( int argc, char **argv ) continue; } + if (strcmp(&argv[i][1],OPTION_C1_MODE) == 0) { + options.c1mode = 1; + continue; + } + if (strcmp(&argv[i][1],OPTION_DUMP_ALL) == 0) { options.dump_rassgn = @@ -737,8 +757,10 @@ int parseCmdLine ( int argc, char **argv ) /* these are undocumented options */ /* if preceded by '/' then turn off certain optmizations, used for debugging only these are also the legacy options from - version 1.xx will be removed gradually */ - if ( *argv[i] == '/') { + version 1.xx will be removed gradually. + It may be an absolute filename. + */ + if ( *argv[i] == '/' && strlen(argv[i]) < 3) { switch (argv[i][1]) { case 'p': @@ -926,7 +948,10 @@ int parseCmdLine ( int argc, char **argv ) if (!port->parseOption(&argc, argv, &i)) { /* no option must be a filename */ - processFile(argv[i]); + if (options.c1mode) + _processC1Arg(argv[i]); + else + processFile(argv[i]); } } @@ -1128,52 +1153,57 @@ static int preProcess (char **envp) preOutName = NULL; - /* if using external stack define the macro */ - if ( options.useXstack ) - _addToList(preArgv, "-DSDCC_USE_XSTACK"); - - /* set the macro for stack autos */ - if ( options.stackAuto ) - _addToList(preArgv, "-DSDCC_STACK_AUTO"); + if (!options.c1mode) { + /* if using external stack define the macro */ + if ( options.useXstack ) + _addToList(preArgv, "-DSDCC_USE_XSTACK"); + + /* set the macro for stack autos */ + if ( options.stackAuto ) + _addToList(preArgv, "-DSDCC_STACK_AUTO"); - /* set the macro for large model */ - switch(options.model) - { - case MODEL_LARGE: - _addToList(preArgv, "-DSDCC_MODEL_LARGE"); - break; - case MODEL_SMALL: - _addToList(preArgv, "-DSDCC_MODEL_SMALL"); - break; - case MODEL_FLAT24: - _addToList(preArgv, "-DSDCC_MODEL_FLAT24"); - break; - default: - werror(W_UNKNOWN_MODEL, __FILE__, __LINE__); - break; - } + /* set the macro for large model */ + switch(options.model) + { + case MODEL_LARGE: + _addToList(preArgv, "-DSDCC_MODEL_LARGE"); + break; + case MODEL_SMALL: + _addToList(preArgv, "-DSDCC_MODEL_SMALL"); + break; + case MODEL_FLAT24: + _addToList(preArgv, "-DSDCC_MODEL_FLAT24"); + break; + default: + werror(W_UNKNOWN_MODEL, __FILE__, __LINE__); + break; + } - /* add port (processor information to processor */ - sprintf(procDef,"-DSDCC_%s",port->target); - _addToList(preArgv,procDef); + /* add port (processor information to processor */ + sprintf(procDef,"-DSDCC_%s",port->target); + _addToList(preArgv,procDef); - if (!preProcOnly) - preOutName = strdup(tmpnam(NULL)); + if (!preProcOnly) + preOutName = strdup(tmpnam(NULL)); - _buildCmdLine(buffer, argv, _preCmd, fullSrcFileName, - preOutName, srcFileName, preArgv); + _buildCmdLine(buffer, argv, _preCmd, fullSrcFileName, + preOutName, srcFileName, preArgv); - if (my_system(argv[0], argv)) { - unlink (preOutName); - perror("Cannot exec Preprocessor"); - exit(1); - } + if (my_system(argv[0], argv)) { + unlink (preOutName); + perror("Cannot exec Preprocessor"); + exit(1); + } - if (preProcOnly) - exit(0); + if (preProcOnly) + exit(0); + } + else { + preOutName = fullSrcFileName; + } - yyin = fopen(preOutName,"r"); + yyin = fopen(preOutName, "r"); if (yyin == NULL) { perror("Preproc file not found\n"); exit(1); @@ -1218,7 +1248,7 @@ int main ( int argc, char **argv , char **envp) parseCmdLine(argc,argv); /* if no input then printUsage & exit */ - if (!srcFileName && !nrelFiles) { + if ((!options.c1mode && !srcFileName && !nrelFiles) || (options.c1mode && !srcFileName && !options.out_name)) { printUsage(); exit(0); } @@ -1238,7 +1268,8 @@ int main ( int argc, char **argv , char **envp) if (!fatalError) { glue(); - assemble(envp); + if (!options.c1mode) + assemble(envp); } } @@ -1249,13 +1280,14 @@ int main ( int argc, char **argv , char **envp) if (!options.cc_only && !fatalError && !noAssemble && + !options.c1mode && (srcFileName || nrelFiles)) linkEdit (envp); if (yyin && yyin != stdin) fclose(yyin); - if (preOutName) { + if (preOutName && !options.c1mode) { unlink(preOutName); free(preOutName); } diff --git a/src/SDCCopt.c b/src/SDCCopt.c index 25b44b9b..642bff15 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -160,27 +160,22 @@ static void cnvToFloatCast (iCode *ic, eBBlock *ebp) symbol *func; link *type = operandType(IC_RIGHT(ic)); int linenno = ic->lineno; + int bwd, su; ip = ic->next ; /* remove it from the iCode */ remiCodeFromeBBlock (ebp,ic); /* depending on the type */ - if (checkType(type,charType) == 1) - func = __char2fs ; - else - if (checkType(type,ucharType) == 1) - func = __uchar2fs; - else - if (checkType(type,intType) == 1) - func = __int2fs; - else - if (checkType(type,uintType) == 1) - func = __uint2fs ; - else - if (checkType(type,longType) == 1) - func = __long2fs; - else - func = __ulong2fs ; + for (bwd = 0; bwd < 3; bwd++) { + for (su = 0; su < 2; su++) { + if (checkType(type, __multypes[bwd][su]) == 1) { + func = __conv[0][bwd][su]; + goto found; + } + } + } + assert(0); + found: /* if float support routines NOT compiled as reentrant */ if (! options.float_rent) { @@ -224,28 +219,23 @@ static void cnvFromFloatCast (iCode *ic, eBBlock *ebp) symbol *func; link *type = operandType(IC_LEFT(ic)); int lineno = ic->lineno ; + int bwd, su; ip = ic->next ; /* remove it from the iCode */ remiCodeFromeBBlock (ebp,ic); /* depending on the type */ - if (checkType(type,charType) == 1) - func = __fs2char ; - else - if (checkType(type,ucharType) == 1) - func = __fs2uchar; - else - if (checkType(type,intType) == 1) - func = __fs2int; - else - if (checkType(type,uintType) == 1) - func = __fs2uint ; - else - if (checkType(type,longType) == 1) - func = __fs2long; - else - func = __fs2ulong ; + for (bwd = 0; bwd < 3; bwd++) { + for (su = 0; su < 2; su++) { + if (checkType(type, __multypes[bwd][su]) == 1) { + func = __conv[1][bwd][su]; + goto found; + } + } + } + assert(0); + found: /* if float support routines NOT compiled as reentrant */ if (! options.float_rent) { @@ -286,29 +276,32 @@ static void cnvFromFloatCast (iCode *ic, eBBlock *ebp) /*-----------------------------------------------------------------*/ static void convilong (iCode *ic, eBBlock *ebp, link *type, int op) { - symbol *func; + symbol *func = NULL; iCode *ip = ic->next; iCode *newic ; int lineno = ic->lineno; - + int bwd; + int su; remiCodeFromeBBlock (ebp,ic); /* depending on the type */ - if (checkType(type,intType) == 1) - func = (op == '*' ? __mulsint : - (op == '%' ? __modsint :__divsint)); - else - if (checkType(type,uintType) == 1) - func = (op == '*' ? __muluint : - (op == '%' ? __moduint : __divuint)); - else - if (checkType(type,longType) == 1) - func = (op == '*' ? __mulslong : - (op == '%' ? __modslong : __divslong)); - else - func = (op == '*'? __mululong : - (op == '%' ? __modulong : __divulong)); - + for (bwd = 0; bwd < 3; bwd++) { + for (su = 0; su < 2; su++) { + if (checkType(type, __multypes[bwd][su]) == 1) { + if (op == '*') + func = __muldiv[0][bwd][su]; + else if (op == '/') + func = __muldiv[1][bwd][su]; + else if (op == '%') + func = __muldiv[2][bwd][su]; + else + assert(0); + goto found; + } + } + } + assert(0); + found: /* if int & long support routines NOT compiled as reentrant */ if (! options.intlong_rent) { /* first one */ @@ -401,7 +394,7 @@ static void convertToFcall (eBBlock **ebbs, int count) if (ic->op == '*' || ic->op == '/' || ic->op == '%' ) { link *type = operandType(IC_LEFT(ic)); - if (IS_INTEGRAL(type) && getSize(type) > 1) + if (IS_INTEGRAL(type) && getSize(type) > port->muldiv.native_below) convilong (ic,ebbs[i],type,ic->op); } } diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 2a956ab5..688e8966 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -1842,93 +1842,90 @@ symbol *__fslt ; symbol *__fslteq; symbol *__fsgt ; symbol *__fsgteq; -symbol *__fs2uchar; -symbol *__fs2uint ; -symbol *__fs2ulong; -symbol *__fs2char; -symbol *__fs2int ; -symbol *__fs2long; -symbol *__long2fs; -symbol *__ulong2fs; -symbol *__int2fs; -symbol *__uint2fs; -symbol *__char2fs; -symbol *__uchar2fs; -symbol *__muluint; -symbol *__mulsint; -symbol *__divuint; -symbol *__divsint; -symbol *__mululong; -symbol *__mulslong; -symbol *__divulong; -symbol *__divslong; -symbol *__moduint; -symbol *__modsint; -symbol *__modulong; -symbol *__modslong; - -link *charType ; -link *intType ; + +/* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */ +symbol *__muldiv[3][3][2]; +/* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */ +link *__multypes[3][2]; +/* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */ +symbol *__conv[2][3][2]; + link *floatType; -link *longType ; -link *ucharType ; -link *uintType ; -link *ulongType ; /*-----------------------------------------------------------------*/ /* initCSupport - create functions for C support routines */ /*-----------------------------------------------------------------*/ void initCSupport () { - charType = newCharLink(); - intType = newIntLink(); + const char *smuldivmod[] = { + "mul", "div", "mod" + }; + const char *sbwd[] = { + "char", "int", "long" + }; + const char *ssu[] = { + "s", "u" + }; + + int bwd, su, muldivmod, tofrom; + floatType= newFloatLink(); - longType = newLongLink(); - ucharType = copyLinkChain(charType); - SPEC_USIGN(ucharType) = 1; - ulongType = copyLinkChain(longType); - SPEC_USIGN(ulongType) = 1; - uintType = copyLinkChain(intType); - SPEC_USIGN(uintType) = 1; + for (bwd = 0; bwd < 3; bwd++) { + link *l; + switch (bwd) { + case 0: + l = newCharLink(); + break; + case 1: + l = newIntLink(); + break; + case 2: + l = newLongLink(); + break; + default: + assert(0); + } + __multypes[bwd][0] = l; + __multypes[bwd][1] = copyLinkChain(l); + SPEC_USIGN(__multypes[bwd][1]) = 1; + } __fsadd = funcOfType ("__fsadd", floatType, floatType, 2, options.float_rent); __fssub = funcOfType ("__fssub", floatType, floatType, 2, options.float_rent); __fsmul = funcOfType ("__fsmul", floatType, floatType, 2, options.float_rent); __fsdiv = funcOfType ("__fsdiv", floatType, floatType, 2, options.float_rent); - __fseq = funcOfType ("__fseq", charType, floatType, 2, options.float_rent); - __fsneq = funcOfType ("__fsneq", charType, floatType, 2, options.float_rent); - __fslt = funcOfType ("__fslt", charType, floatType, 2, options.float_rent); - __fslteq= funcOfType ("__fslteq", charType, floatType, 2, options.float_rent); - __fsgt = funcOfType ("__fsgt", charType, floatType, 2, options.float_rent); - __fsgteq= funcOfType ("__fsgteq", charType, floatType, 2, options.float_rent); - - __fs2uchar = funcOfType ("__fs2uchar",ucharType,floatType,1, options.float_rent); - __fs2uint = funcOfType ("__fs2uint",uintType,floatType,1, options.float_rent); - __fs2ulong = funcOfType ("__fs2ulong",ulongType,floatType,1, options.float_rent); - __fs2char = funcOfType ("__fs2char",charType,floatType,1, options.float_rent); - __fs2int = funcOfType ("__fs2int",intType,floatType,1, options.float_rent); - __fs2long = funcOfType ("__fs2long",longType,floatType,1, options.float_rent); - - __long2fs = funcOfType ("__long2fs",floatType,longType,1, options.float_rent); - __ulong2fs = funcOfType ("__ulong2fs",floatType,ulongType,1, options.float_rent); - __int2fs = funcOfType ("__int2fs",floatType,intType,1, options.float_rent); - __uint2fs = funcOfType ("__uint2fs",floatType,uintType,1, options.float_rent); - __char2fs = funcOfType ("__char2fs",floatType,charType,1, options.float_rent); - __uchar2fs = funcOfType ("__uchar2fs",floatType,ucharType,1, options.float_rent); - - __muluint = funcOfType ("_muluint",uintType,uintType,2,options.intlong_rent); - __mulsint = funcOfType ("_mulsint",intType,intType,2,options.intlong_rent); - __divuint = funcOfType ("_divuint",uintType,uintType,2,options.intlong_rent); - __divsint = funcOfType ("_divsint",intType,intType,2,options.intlong_rent); - __moduint = funcOfType ("_moduint",uintType,uintType,2,options.intlong_rent); - __modsint = funcOfType ("_modsint",intType,intType,2,options.intlong_rent); - - __mululong = funcOfType ("_mululong",ulongType,ulongType,2,options.intlong_rent); - __mulslong = funcOfType ("_mulslong",longType,longType,2,options.intlong_rent); - __divulong = funcOfType ("_divulong",ulongType,ulongType,2,options.intlong_rent); - __divslong = funcOfType ("_divslong",longType,longType,2,options.intlong_rent); - __modulong = funcOfType ("_modulong",ulongType,ulongType,2,options.intlong_rent); - __modslong = funcOfType ("_modslong",longType,longType,2,options.intlong_rent); - + __fseq = funcOfType ("__fseq", CHARTYPE, floatType, 2, options.float_rent); + __fsneq = funcOfType ("__fsneq", CHARTYPE, floatType, 2, options.float_rent); + __fslt = funcOfType ("__fslt", CHARTYPE, floatType, 2, options.float_rent); + __fslteq= funcOfType ("__fslteq", CHARTYPE, floatType, 2, options.float_rent); + __fsgt = funcOfType ("__fsgt", CHARTYPE, floatType, 2, options.float_rent); + __fsgteq= funcOfType ("__fsgteq", CHARTYPE, floatType, 2, options.float_rent); + + for (tofrom = 0; tofrom < 2; tofrom++) { + for (bwd = 0; bwd < 3; bwd++) { + for (su = 0; su < 2; su++) { + if (tofrom) { + sprintf(buffer, "__fs2%s%s", ssu[su], sbwd[bwd]); + __conv[tofrom][bwd][su] = funcOfType(buffer, __multypes[bwd][su], floatType, 2, options.float_rent); + } + else { + sprintf(buffer, "__%s%s2fs", ssu[su], sbwd[bwd]); + __conv[tofrom][bwd][su] = funcOfType(buffer, floatType, __multypes[bwd][su], 2, options.float_rent); + } + } + } + } + + for (muldivmod = 0; muldivmod < 3; muldivmod++) { + for (bwd = 0; bwd < 3; bwd++) { + for (su = 0; su < 2; su++) { + sprintf(buffer, "_%s%s%s", + smuldivmod[muldivmod], + ssu[su], + sbwd[bwd]); + __muldiv[muldivmod][bwd][su] = funcOfType(buffer, __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent); + } + } + } } diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 6f7ee262..73346afd 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -330,38 +330,19 @@ extern symbol *__fslt ; extern symbol *__fslteq; extern symbol *__fsgt ; extern symbol *__fsgteq; -extern symbol *__fs2uchar; -extern symbol *__fs2uint ; -extern symbol *__fs2ulong; -extern symbol *__fs2char; -extern symbol *__fs2int ; -extern symbol *__fs2long; -extern symbol *__long2fs; -extern symbol *__ulong2fs; -extern symbol *__int2fs; -extern symbol *__uint2fs; -extern symbol *__char2fs; -extern symbol *__uchar2fs; -extern symbol *__muluint; -extern symbol *__mulsint; -extern symbol *__divuint; -extern symbol *__divsint; -extern symbol *__mululong; -extern symbol *__mulslong; -extern symbol *__divulong; -extern symbol *__divslong; -extern symbol *__moduint; -extern symbol *__modsint; -extern symbol *__modulong; -extern symbol *__modslong; -extern link *charType ; -extern link *intType ; +/* Dims: mul/div/mod, BYTE/WORD/DWORD, SIGNED/UNSIGNED */ +extern symbol *__muldiv[3][3][2]; +/* Dims: BYTE/WORD/DWORD SIGNED/UNSIGNED */ +extern link *__multypes[3][2]; +/* Dims: to/from float, BYTE/WORD/DWORD, SIGNED/USIGNED */ +extern symbol *__conv[2][3][2]; + +#define CHARTYPE __multypes[0][0] +#define INTTYPE __multypes[1][0] +#define UCHARTYPE __multypes[0][1] + extern link *floatType; -extern link *longType ; -extern link *ucharType ; -extern link *uintType ; -extern link *ulongType ; #include "SDCCval.h" diff --git a/src/mcs51/main.c b/src/mcs51/main.c index e4732ad9..62881b54 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -142,6 +142,9 @@ static const char *_asmCmd[] = { PORT mcs51_port = { "mcs51", "MCU 8051", /* Target name */ + { + TRUE, /* Emit glue around main */ + }, { _asmCmd, "-plosgffc", /* Options with debug */ diff --git a/src/port.h b/src/port.h index 76ebfbd6..b8639fb1 100644 --- a/src/port.h +++ b/src/port.h @@ -13,6 +13,15 @@ typedef struct { /** Target name string, used for --help */ const char *target_name; + struct { + /** TRUE if all types of glue functions should be inseted into + the file that also defines main. + We dont want this in cases like the z80 where the startup + code is provided by a seperate module. + */ + bool glue_up_main; + } general; + /* assembler related information */ struct { /** Command to run and arguments (eg as-z80) */ @@ -80,7 +89,7 @@ typedef struct { /** One more than the smallest mul/div operation the processor can do nativley Eg if the processor has an 8 bit mul, nativebelow is 2 */ - int nativebelow; + int native_below; } muldiv; /** Called once the processor target has been selected. diff --git a/src/z80/Makefile b/src/z80/Makefile index f3b71b32..e71232b6 100644 --- a/src/z80/Makefile +++ b/src/z80/Makefile @@ -22,6 +22,6 @@ peeph-gbz80.rul: peeph-gbz80.def $(AWK) -f ../SDCCpeeph.awk peeph-gbz80.def > peeph-gbz80.rul main.o: main.c peeph.rul -gbz80.o: gbz80.o peeph-gbz80.rul +gbz80.o: gbz80.c peeph-gbz80.rul include clean.mk diff --git a/src/z80/gbz80.c b/src/z80/gbz80.c index d0b2f88a..84946032 100644 --- a/src/z80/gbz80.c +++ b/src/z80/gbz80.c @@ -73,6 +73,9 @@ static const char *_asmCmd[] = { PORT gbz80_port = { "gbz80", "Gameboy Z80-like", /* Target name */ + { + FALSE, + }, { _asmCmd, "-plosgff", /* Options with debug */ diff --git a/src/z80/gen.c b/src/z80/gen.c index 029cbfad..a46c959d 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -2343,7 +2343,7 @@ static void genOrOp (iCode *ic) toBoolean(left); emitcode(_shortJP, "nz," LABEL_STR,tlbl->key+100); toBoolean(right); - emitcode("", LABEL_STR,tlbl->key+100); + emitcode("", LABEL_STR ":",tlbl->key+100); outBitAcc(result); } @@ -2372,6 +2372,26 @@ int isLiteralBit(unsigned long lit) return 0; } +/*-----------------------------------------------------------------*/ +/* jmpTrueOrFalse - */ +/*-----------------------------------------------------------------*/ +static void jmpTrueOrFalse (iCode *ic, symbol *tlbl) +{ + // ugly but optimized by peephole + if(IC_TRUE(ic)){ + symbol *nlbl = newiTempLabel(NULL); + emitcode("jp", LABEL_STR, nlbl->key+100); + emitcode("", LABEL_STR ":",tlbl->key+100); + emitcode("jp",LABEL_STR,IC_TRUE(ic)->key+100); + emitcode("", LABEL_STR ":",nlbl->key+100); + } + else{ + emitcode("jp", LABEL_STR, IC_FALSE(ic)->key+100); + emitcode("", LABEL_STR ":",tlbl->key+100); + } + ic->generated = 1; +} + /*-----------------------------------------------------------------*/ /* genAnd - code for and */ /*-----------------------------------------------------------------*/ @@ -2485,11 +2505,7 @@ static void genAnd (iCode *ic, iCode *ifx) // if(left & literal) else{ if(ifx) -#if 0 jmpTrueOrFalse(ifx, tlbl); -#else - assert(0); -#endif goto release ; } } @@ -3499,7 +3515,7 @@ static void genGenPointerSet (operand *right, while (size--) { char *l = aopGet(AOP(right),offset,FALSE); if (isRegOrLit(AOP(right)) && !IS_GB) { - emitcode("ld", "(%s),%s", l); + emitcode("ld", "(%s),%s", ptr, l); } else { MOVA(l); diff --git a/src/z80/main.c b/src/z80/main.c index f59edf61..f19ad5d8 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -68,6 +68,9 @@ static const char *_asmCmd[] = { PORT z80_port = { "z80", "Zilog Z80", /* Target name */ + { + FALSE, + }, { _asmCmd, "-plosgff", /* Options with debug */ diff --git a/support/tests/dhrystone/Makefile b/support/tests/dhrystone/Makefile index b0b93904..824fac0f 100644 --- a/support/tests/dhrystone/Makefile +++ b/support/tests/dhrystone/Makefile @@ -1,28 +1,27 @@ # Simple Makefile for dhrystone and sdcc -CC = /home/michaelh/projects/sdcc/bin/sdcc +PROC = gbz80 +PORT = gb + +CC = /home/michaelh/projects/gbdk-support/lcc/lcc # -DNOENUM is here to make the results more predictable -CFLAGS = -mgbz80 -v --dumpall -CFLAGS += -DREG= -DNOSTRUCTASSIGN -DNOENUM -DBROKEN_SDCC=0 -DHZ=100 -LIBDIR = /home/michaelh/projects/sdcc/device/lib/gbz80/ -LD = link-gb -AS = as-gb +CFLAGS = +CFLAGS += -DREG= -DNOSTRUCTASSIGN -DNOENUM +LIBDIR = /home/michaelh/projects/gbdk-lib/build/ +LD = link-$(PROC) +LDFLAGS = -v +AS = as-$(PROC) OBJ = dhry.o all: dhry dhry: $(OBJ) - $(LD) -n -- -z -m -k$(LIBDIR) -lz80.lib \ - -b_CODE=0x200 dhry.gb $(LIBDIR)crt0.o $(OBJ) -# cat dhry.ihx | ../../makebin/makebin > dhry.rom + $(CC) -o dhry.gb dhry.o native: gcc -g -O2 -DREG= -DNOSTRUCTASSIGN -DNOENUM -o dhry dhry.c -.c.o: - $(CC) $(CFLAGS) $< - dhry.c: clean: diff --git a/support/tests/dhrystone/dhry.c b/support/tests/dhrystone/dhry.c index a893a202..27d53aad 100644 --- a/support/tests/dhrystone/dhry.c +++ b/support/tests/dhrystone/dhry.c @@ -43,11 +43,8 @@ #include /** For printf */ #include - -/** Returns the current device time in ticks. Check HZ in the Makefile - as well - HZ ticks = 1 second. -*/ -unsigned _clock(void); +/** For clock() */ +#include /** Print the number of t-states this program has been executing for. Optional :) @@ -89,11 +86,7 @@ Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val); Boolean Func_2 (char *Str_1_Par_Ref, char *Str_2_Par_Ref); Boolean Func_3 (Enumeration Enum_Par_Val); -#if SDCC -int _main(void) -#else int main(void) -#endif { One_Fifty Int_1_Loc; REG One_Fifty Int_2_Loc; @@ -106,7 +99,7 @@ int main(void) REG int Number_Of_Runs; unsigned runTime; - // printf("[dhry]\n"); + printf("[dhry]\n"); Next_Ptr_Glob = &_r[0]; Ptr_Glob = &_r[1]; @@ -131,7 +124,7 @@ int main(void) /* 32766 is the highest value for a 16 bitter */ Number_Of_Runs = 32766; - runTime = _clock(); + runTime = clock(); /* Main test loop */ for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) { @@ -205,7 +198,7 @@ int main(void) printf("Run_Index = %d\n", Run_Index); - runTime = _clock() - runTime; + runTime = clock() - runTime; printf ("Execution ends\n"); printf ("\n"); @@ -261,7 +254,7 @@ int main(void) printf ("\n"); printf("Time: %u ticks\n", runTime); - printf("Dhrystones/s = %u\n", Number_Of_Runs / (runTime/HZ)); + printf("Dhrystones/s = %u\n", Number_Of_Runs / (runTime/CLOCKS_PER_SEC)); printf("MIPS = d/s/1757 = (sigh, need floats...)\n"); _printTStates(); } @@ -309,17 +302,17 @@ void Proc_2 (One_Fifty *Int_Par_Ref) Int_Loc = *Int_Par_Ref + 10; do { - DPRINTF(("1\n")); + DPRINTF(("1")); /* executed once */ if (Ch_1_Glob == 'A') /* then, executed */ { - DPRINTF(("2\n")); + DPRINTF(("2")); Int_Loc -= 1; *Int_Par_Ref = Int_Loc - Int_Glob; Enum_Loc = Ident_1; } /* if */ - DPRINTF(("3\n")); + DPRINTF(("3")); } while (Enum_Loc != Ident_1); /* true */ DPRINTF(("Proc_2 done.\n")); } /* Proc_2 */ -- 2.47.2