From cea246282ef02e72548408c02833d6efe2ea0786 Mon Sep 17 00:00:00 2001 From: kvigor Date: Sun, 27 Feb 2000 06:03:18 +0000 Subject: [PATCH] Get compiling with Borland C++ for Windows git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@131 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/Makefile.bcc | 69 ++++++++++++++++++++++++++++++++++++++++++ src/SDCCcse.c | 4 ++- src/SDCCicode.c | 10 ++++-- src/SDCCmain.c | 50 ++++++++++++++++++++++++------ src/mcs51/Makefile.bcc | 24 +++++++++++++++ src/mcs51/gen.c | 12 ++++++-- src/mcs51/ralloc.c | 12 ++++++-- src/z80/Makefile.bcc | 28 +++++++++++++++++ 8 files changed, 192 insertions(+), 17 deletions(-) create mode 100644 src/Makefile.bcc create mode 100644 src/mcs51/Makefile.bcc create mode 100644 src/z80/Makefile.bcc diff --git a/src/Makefile.bcc b/src/Makefile.bcc new file mode 100644 index 00000000..d788d391 --- /dev/null +++ b/src/Makefile.bcc @@ -0,0 +1,69 @@ +# Generated automatically from Makefile.in by configure. +# +# +# + +PRJDIR = .. + +# !include $(PRJDIR)/Makefile.common + +PORTS = mcs51 z80 +PORT_LIBS = mcs51/port.lib z80/port.lib + +LIBS = -lgc +LIBDIRS = -L$(PRJDIR)/support/gc +LIBGC = $(PRJDIR)/support/gc/gc.lib + +OBJECTS = SDCCy.obj SDCClex.obj SDCCerr.obj SDCChasht.obj SDCCmain.obj \ + SDCCsymt.obj SDCCopt.obj SDCCast.obj SDCCmem.obj SDCCval.obj \ + SDCCicode.obj SDCCbitv.obj SDCCset.obj SDCClabel.obj \ + SDCCBBlock.obj SDCCloop.obj SDCCcse.obj SDCCcflow.obj SDCCdflow.obj \ + SDCClrange.obj SDCCptropt.obj SDCCpeeph.obj SDCCglue.obj + +TARGET = $(PRJDIR)/bin/sdcc.exe + +# Compiling entire program or any subproject +# ------------------------------------------ +all: $(LIBGC) $(TARGET) + +ports: +# for i in $(PORTS); do $(MAKE) -C $$i; done + +#$(PRJDIR)/support/gc/libgc.a: +# cd $(PRJDIR)/support/gc && $(MAKE) + + +!include Makefile.dep +#!include clean.mk + + +# My rules +# -------- +$(TARGET): $(OBJECTS) $(PORT_LIBS) + bcc32 -e$(TARGET) $(OBJECTS) $(PORT_LIBS) $(LIBGC) + +CFLAGS = -6 -O -g0 -I. -I.. -I..\support + +.c.obj: + BCC32 -c $(CFLAGS) $(CPPFLAGS) $< + +SDCCy.h: SDCCy.c + +SDCCy.c: SDCC.y + $(YACC) -d -v -o $@ $< + +SDCClex.c: SDCC.lex SDCCy.h + $(LEX) -t $< >$@ + +.y.c: + rm -f $*.cc $*.h + $(YACC) -d $< + mv y.tab.c $*.cc + mv y.tab.h $*.h + +.l.c: + rm -f $*.cc + $(LEX) -t $< >$*.cc + + + diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 04e6337f..00cda0b8 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -67,6 +67,8 @@ int pcseDef (void *item, va_list ap) cseDef *cdp = item; iCodeTable *icTab ; + (void)ap; + if (!cdp->sym) fprintf(stdout,"**null op**"); printOperand(cdp->sym,stdout); @@ -854,7 +856,7 @@ void ifxOptimize (iCode *ic, set *cseSet, /* if the conditional is a literal then */ if (IS_OP_LITERAL(IC_COND(ic))) { - if ( operandLitValue(IC_COND(ic)) && IC_TRUE(ic)) { + if ( (operandLitValue(IC_COND(ic)) != 0.0) && IC_TRUE(ic)) { /* change to a goto */ ic->op = GOTO ; diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 3a2799d4..7213568f 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2140,6 +2140,12 @@ operand *geniCodeRightShift (operand *left, operand *right) return IC_RESULT(ic) ; } +#ifdef __BORLANDC__ +#define LONG_LONG __int64 +#else +#define LONG_LONG long long +#endif + /*-----------------------------------------------------------------*/ /* geniCodeLogic- logic code */ /*-----------------------------------------------------------------*/ @@ -2156,7 +2162,7 @@ operand *geniCodeLogic (operand *left, operand *right, int op ) int nbits = bitsForType(ltype); long v = operandLitValue(right); - if (v > ((long long) 1 << nbits) && v > 0) + if (v > ((LONG_LONG) 1 << nbits) && v > 0) werror(W_CONST_RANGE," compare operation "); } @@ -2249,7 +2255,7 @@ operand *geniCodeAssign (operand *left, operand *right, int nosupdate) int nbits = bitsForType(ltype); long v = operandLitValue(right); - if (v > ((long long)1 << nbits) && v > 0) + if (v > ((LONG_LONG)1 << nbits) && v > 0) werror(W_CONST_RANGE," = operation"); } /* if the left & right type don't exactly match */ diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 6a9126d4..2a5064a4 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -24,7 +24,12 @@ #include "common.h" #include + +#ifdef __BORLANDC__ +#include +#else #include "spawn.h" +#endif /* This is a bit messy. We cant include unistd.h as it defines 'link' which we also use. @@ -979,15 +984,40 @@ int parseCmdLine ( int argc, char **argv ) char *try_dir[]= {SRCDIR "/bin",PREFIX "/bin", NULL}; int my_system (const char *cmd, char **cmd_argv) { - char *dir, *got= NULL; int i= 0; - while (!got && try_dir[i]) { - dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10); - strcpy(dir, try_dir[i]); strcat(dir, "/"); strcat(dir, cmd); - if (access(dir, X_OK) == 0) - got= strdup(dir); - free(dir); - i++; + #ifdef __BORLANDC__ + char *r; + #endif + + while (!got && try_dir[i]) + { + dir= (char*)malloc(strlen(try_dir[i])+strlen(cmd)+10); + strcpy(dir, try_dir[i]); + strcat(dir, "/"); + strcat(dir, cmd); + + #ifdef __BORLANDC__ + strcat(dir, ".exe"); + + /* Mung slashes into backslashes to keep WIndoze happy. */ + r = dir; + + while (*r) + { + if (*r == '/') + { + *r = '\\'; + } + r++; + } + #endif + + if (access(dir, X_OK) == 0) + { + got= strdup(dir); + } + free(dir); + i++; } #if FEATURE_VERBOSE_EXEC if (verboseExec) { @@ -1288,8 +1318,8 @@ int main ( int argc, char **argv , char **envp) fclose(yyin); if (preOutName && !options.c1mode) { - unlink(preOutName); - free(preOutName); + unlink(preOutName); + free(preOutName); } return 0; diff --git a/src/mcs51/Makefile.bcc b/src/mcs51/Makefile.bcc new file mode 100644 index 00000000..bc0ae897 --- /dev/null +++ b/src/mcs51/Makefile.bcc @@ -0,0 +1,24 @@ +PRJDIR = ../.. + +# !include $(PRJDIR)/Makefile.common + +OBJ = gen.obj ralloc.obj main.obj +LIB = port.lib + +CFLAGS = -6 -O -g0 -I.. -I. -I..\.. -I..\..\support + +.c.obj: + BCC32 -c $(CFLAGS) $(CPPFLAGS) $< + +all: $(LIB) + +main.obj: main.c peeph.rul + +$(LIB): peeph.rul $(OBJ) + del $(LIB) + tlib /a $(LIB) +gen.obj +ralloc.obj +main.obj + +peeph.rul: peeph.def + gawk -f ../SDCCpeeph.awk peeph.def > peeph.rul + +# include clean.mk diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 416fa2bc..a182bc99 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -40,10 +40,12 @@ #ifdef HAVE_ENDIAN_H #include #else +#ifndef __BORLANDC__ #warning "Cannot determine ENDIANESS of this machine assuming LITTLE_ENDIAN" #warning "If you running sdcc on an INTEL 80x86 Platform you are okay" #endif #endif +#endif #include "common.h" #include "SDCCpeeph.h" @@ -1872,6 +1874,12 @@ static int resultRemat (iCode *ic) return 0; } +#ifdef __BORLANDC__ +#define STRCASECMP stricmp +#else +#define STRCASECMP strcasecmp +#endif + /*-----------------------------------------------------------------*/ /* inExcludeList - return 1 if the string is in exclude Reg list */ /*-----------------------------------------------------------------*/ @@ -1880,12 +1888,12 @@ static bool inExcludeList(char *s) int i =0; if (options.excludeRegs[i] && - strcasecmp(options.excludeRegs[i],"none") == 0) + STRCASECMP(options.excludeRegs[i],"none") == 0) return FALSE ; for ( i = 0 ; options.excludeRegs[i]; i++) { if (options.excludeRegs[i] && - strcasecmp(s,options.excludeRegs[i]) == 0) + STRCASECMP(s,options.excludeRegs[i]) == 0) return TRUE; } return FALSE ; diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 45c9e18d..80573d3a 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -443,6 +443,8 @@ static symbol *createStackSpil (symbol *sym) int useXstack, model, noOverlay; int stackAuto; + char slocBuffer[30]; + /* first go try and find a free one that is already existing on the stack */ if (applyToSet(_G.stackSpil,isFree,&sloc, sym)) { @@ -458,8 +460,14 @@ static symbol *createStackSpil (symbol *sym) we need to allocate this on the stack : this is really a hack!! but cannot think of anything better at this time */ - sprintf(buffer,"sloc%d",_G.slocNum++); - sloc = newiTemp(buffer); + if (sprintf(slocBuffer,"sloc%d",_G.slocNum++) >= sizeof(slocBuffer)) + { + fprintf(stderr, "***Internal error: slocBuffer overflowed: %s:%d\n", + __FILE__, __LINE__); + exit(1); + } + + sloc = newiTemp(slocBuffer); /* set the type to the spilling symbol */ sloc->type = copyLinkChain(sym->type); diff --git a/src/z80/Makefile.bcc b/src/z80/Makefile.bcc new file mode 100644 index 00000000..1b2c4688 --- /dev/null +++ b/src/z80/Makefile.bcc @@ -0,0 +1,28 @@ +PRJDIR = ../.. + +# !include $(PRJDIR)/Makefile.common + +OBJ = gen.obj ralloc.obj main.obj gbz80.obj +LIB = port.lib + +CFLAGS = -6 -O -g0 -I.. -I. -I..\.. -I..\..\support + +.c.obj: + BCC32 -c $(CFLAGS) $(CPPFLAGS) $< + +all: $(LIB) + +main.obj: main.c peeph.rul +gbz80.obj: gbz80.c peeph-gbz80.rul + +$(LIB): peeph.rul $(OBJ) + del $(LIB) + tlib /a $(LIB) +gen.obj +ralloc.obj +main.obj +gbz80.obj + +peeph.rul: peeph.def + gawk -f ../SDCCpeeph.awk peeph.def > peeph.rul + +peeph-gbz80.rul: peeph-gbz80.def + gawk -f ../SDCCpeeph.awk peeph-gbz80.def > peeph-gbz80.rul + +# include clean.mk -- 2.30.2