diff options
author | Robert de Bath <rdebath@poboxes.com> | 1997-02-25 20:42:19 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:38:07 +0200 |
commit | 4c36e9a0c125ccfff37aa440dab2cf58c4152fff (patch) | |
tree | a5d9c84ba2661029ddb2223dacd50529a361c3d5 /bcc | |
parent | f8de35da65c5d93bb733073cf40da154bc1c0748 (diff) | |
parent | 9696d7b0e1f3a1b0f5fd4a0428eb75afe8ad4ed6 (diff) | |
download | dev86-4c36e9a0c125ccfff37aa440dab2cf58c4152fff.tar.gz |
Import Dev86src-0.0.11.tar.gzv0.0.11
Diffstat (limited to 'bcc')
-rw-r--r-- | bcc/Makefile | 20 | ||||
-rw-r--r-- | bcc/bcc.c | 235 | ||||
-rw-r--r-- | bcc/bcc.exe | bin | 13949 -> 0 bytes | |||
-rw-r--r-- | bcc/const.h | 6 | ||||
-rw-r--r-- | bcc/input.c | 23 | ||||
-rw-r--r-- | bcc/preproc.c | 2 | ||||
-rw-r--r-- | bcc/proto.h | 1 |
7 files changed, 237 insertions, 50 deletions
diff --git a/bcc/Makefile b/bcc/Makefile index a95c5bc..512c013 100644 --- a/bcc/Makefile +++ b/bcc/Makefile @@ -3,20 +3,13 @@ # $Id$ # -ifneq ($(TOPDIR),) -include $(TOPDIR)/Make.defs -BCCDEFS =-DLOCALPREFIX="\"$(BCCROOT)\"" -DDEFARCH=0 -else +PREFIX=/usr + CFLAGS =-O LDFLAGS =-s BINDIR =/usr/bin LIBDIR =/usr/lib/bcc -BCCDEFS =-DLOCALPREFIX="\"/usr\"" -DDEFARCH=0 -endif - -ifeq ($(CC),bcc) -CFLAGS=-Mf -endif +BCCDEFS =-DLOCALPREFIX=$(PREFIX) -DDEFARCH=0 OBJS = bcc-cc1.o codefrag.o debug.o declare.o express.o exptree.o floatop.o \ function.o gencode.o genloads.o glogcode.o hardop.o input.o label.o \ @@ -34,6 +27,9 @@ install: all bcc: bcc.c $(CC) -ansi $(CFLAGS) $(BCCDEFS) $(LDFLAGS) bcc.c -o $@ +ncc: bcc.c + $(CC) -ansi $(CFLAGS) -DL_TREE -DDEFARCH=0 $(LDFLAGS) bcc.c -o $@ + bcc09: bcc.c $(CC) -ansi $(CFLAGS) -DMC6809 $(BCCDEFS) $(LDFLAGS) bcc.c -o $@ @@ -43,8 +39,8 @@ ccc: bcc.c bcc-cc1: $(OBJS) $(CC) $(LDFLAGS) $(OBJS) -o bcc-cc1 -clean: - rm -f bcc bcc-cc1 bcc09 ccc bcc.o $(OBJS) +clean realclean: + rm -f bcc bcc-cc1 ncc bcc09 ccc bcc.o $(OBJS) $(OBJS): align.h byteord.h condcode.h const.h gencode.h input.h label.h os.h \ @@ -24,21 +24,31 @@ #ifdef __STDC__ #define P(x) x +#define HASHIT(x) #x +#define QUOT(x) HASHIT(x) #else #define P(x) () +/* Well you find something that works! */ +#define QUOT(x) "x" #endif #ifdef MSDOS -#define LOCALPREFIX "/linux86" +#define LOCALPREFIX /linux86 #define EXESUF ".exe" #define R_OK 4 /* Test for read permission. */ #define W_OK 2 /* Test for write permission. */ #define X_OK 1 /* Test for execute permission. */ #define F_OK 0 /* Test for existence. */ +#define L_TREE 1 /* Use different tree style */ +#define DEFARCH 0 /* Default to 8086 code */ #else #define EXESUF #endif +#ifdef __minix +#define realpath(x,y) 0 +#endif + #define BAS86 #define BCC86 @@ -51,8 +61,9 @@ #define GCC "gcc" #define LD "ld86" EXESUF #define UNPROTO "unproto" EXESUF +#define OPTIM "copt" EXESUF -#ifdef MSDOS +#ifdef L_TREE #define STANDARD_CRT0_0_PREFIX "~/lib/" #define STANDARD_CRT0_3_PREFIX "~/lib/i386/" #define STANDARD_EXEC_PREFIX "~/lib/" @@ -60,6 +71,7 @@ #define DEFAULT_INCLUDE "-I~/include" #define DEFAULT_LIBDIR0 "-L~/lib/" #define DEFAULT_LIBDIR3 "-L~/lib/i386/" +#define OPTIM_RULES "-d~/lib" #else #define STANDARD_CRT0_0_PREFIX "~/lib/bcc/i86/" #define STANDARD_CRT0_3_PREFIX "~/lib/bcc/i386/" @@ -68,6 +80,7 @@ #define DEFAULT_INCLUDE "-I~/include" #define DEFAULT_LIBDIR0 "-L~/lib/bcc/i86/" #define DEFAULT_LIBDIR3 "-L~/lib/bcc/i386/" +#define OPTIM_RULES "-d~/lib/bcc/i86" #endif #ifdef CCC @@ -117,6 +130,7 @@ PRIVATE struct arg_s asargs = { AS, }; PRIVATE struct arg_s ccargs = { CC1, CC1_MINUS_O_BROKEN, }; PRIVATE struct arg_s cppargs = { CPP, }; PRIVATE struct arg_s unprotoargs = { UNPROTO, TRUE }; +PRIVATE struct arg_s optargs = { OPTIM }; #ifdef STANDARD_CRT0_PREFIX PRIVATE struct prefix_s crt0_prefix = { STANDARD_CRT0_PREFIX, }; #endif @@ -137,7 +151,7 @@ PRIVATE struct arg_s tmpargs; /* = empty */ PRIVATE char *tmpdir; PRIVATE unsigned verbosity; /* = 0 */ -PRIVATE char * localprefix = LOCALPREFIX; +PRIVATE char * localprefix = QUOT(LOCALPREFIX); #ifdef REDECLARE_STDC_FUNCTIONS void exit P((int status)); @@ -173,7 +187,7 @@ FORWARD char *my_mktemp P((void)); FORWARD void my_unlink P((char *name)); FORWARD void outofmemory P((char *where)); FORWARD int run P((char *in_name, char *out_name, struct arg_s *argp)); -#ifdef MSDOS +#ifdef L_TREE FORWARD void reset_localprefix P((void)); #endif FORWARD void set_trap P((void)); @@ -218,6 +232,11 @@ char **argv; char *crt0; #endif char *libc = "-lc"; +#ifdef MSDOS + char major_mode = 'd'; +#else + char major_mode = 0; +#endif bool_T debug = FALSE; bool_T echo = FALSE; unsigned errcount = 0; @@ -234,13 +253,14 @@ char **argv; unsigned nifiles = 0; unsigned npass_specs; bool_T optimize = FALSE; + char *optflags = 0; char *out_name; bool_T profile = FALSE; bool_T prep_only = FALSE; bool_T prep_line_numbers = FALSE; int status; char *temp; - bool_T patch_exe = FALSE; + bool_T patch_exe = FALSE; /* Hackish patch to convert minix i386->OMAGIC */ progname = argv[0]; addarg(&cppargs, CPPFLAGS); @@ -252,9 +272,11 @@ char **argv; addarg(&ldrargs, "-r"); addarg(&ldrargs, "-N"); /* GCC uses native objects */ /* GCC also uses 386 how to add -3 too ? */ + addarg(&optargs, "-c!"); + optflags = stralloc("start"); #endif -#ifdef MSDOS +#ifdef L_TREE reset_localprefix(); #endif /* Pass 1 over argv to gather compile options. */ @@ -287,7 +309,10 @@ char **argv; prep_line_numbers = FALSE; break; case 'O': - optimize = TRUE; /* unsupported( arg, "optimize" ); */ + optimize = TRUE; + temp = optflags; + optflags=stralloc2(optflags,",86"); + free(temp); break; case 'S': cc_only = TRUE; @@ -390,31 +415,19 @@ char **argv; addarg(&ldargs, arg); break; case 'M': - switch(arg[2]) + major_mode=arg[2]; + break; + + case 'O': + optimize = TRUE; + temp=optflags; optflags=stralloc2(optflags,","); free(temp); + temp=optflags; optflags=stralloc2(optflags,arg+2); free(temp); + if( arg[3] == 0 && ( arg[2] >= '1' && arg[2] <= '3' )) { - case 'd': /* DOS compile */ -#ifndef CCC - addarg(&ccargs, "-D__MSDOS__"); -#endif - addarg(&cppargs, "-D__MSDOS__"); - addarg(&ldargs, "-d"); - addarg(&ldargs, "-s"); - addarg(&ldargs, "-T100"); - libc= "-ldos"; - break; - case 'f': /* Caller saves+ax is first arg */ - libc= "-lc_f"; - addarg(&ccargs, "-f"); - addarg(&ccargs, "-c"); - break; - case 's': /* Standalone executable */ -#ifndef CCC - addarg(&ccargs, "-D__STANDALONE__"); -#endif - addarg(&cppargs, "-D__STANDALONE__"); - addarg(&ldargs, "-s"); - libc= "-lc_s"; - break; + temp=optflags; + optflags=stralloc2(optflags,"86,86"); + free(temp); + addarg(&optargs, "-huse16 386"); } break; case 'P': @@ -467,7 +480,61 @@ char **argv; if (errcount != 0) exit(1); - if( !aswarn ) +#ifdef BCC86 + switch(major_mode) + { + case 'd': /* DOS compile */ + bits32 = FALSE; + libc= "-ldos"; +#ifndef CCC + addarg(&ccargs, "-D__MSDOS__"); +#endif + addarg(&cppargs, "-D__MSDOS__"); + addarg(&ldargs, "-d"); + addarg(&ldargs, "-s"); + addarg(&ldargs, "-T100"); + break; + + case 'n': /* Normal Linux-86 */ + bits32 = FALSE; + libc= "-lc"; + break; + + case 'f': /* Caller saves+ax is first arg */ + bits32 = FALSE; + libc= "-lc_f"; + addarg(&ccargs, "-f"); + addarg(&ccargs, "-c"); + break; + + case 'c': /* Just caller saves, normal C-lib is ok */ + bits32 = FALSE; + libc= "-lc"; + addarg(&ccargs, "-c"); + break; + + case 's': /* Standalone executable */ + bits32 = FALSE; + libc= "-lc_s"; +#ifndef CCC + addarg(&ccargs, "-D__STANDALONE__"); +#endif + addarg(&cppargs, "-D__STANDALONE__"); + break; + + case 'l': /* Large Linux compile */ + bits32 = TRUE; + libc= "-lc"; +#ifndef CCC + addarg(&ccargs, "-D__linux__"); +#endif + addarg(&cppargs, "-D__linux__"); + addarg(&ldargs, "-N"); /* Make OMAGIC */ + break; + } +#endif + +if( !aswarn ) addarg(&asargs, "-w"); if( patch_exe ) addarg(&ldargs, "-s"); @@ -500,6 +567,14 @@ char **argv; #endif addarg(&ldargs, DEFAULT_LIBDIR0); } + + addarg(&optargs, OPTIM_RULES); + temp=optflags; optflags=stralloc2(optflags,",end"); free(temp); + for(temp=strtok(optflags,","); temp; temp=strtok((char*)0,",")) + { + temp = stralloc2("rules.", temp); + addarg(&optargs, temp); + } addprefix(&exec_prefix, STANDARD_EXEC_PREFIX); addprefix(&exec_prefix, STANDARD_EXEC_PREFIX_2); cppargs.prog = fixpath(cppargs.prog, &exec_prefix, X_OK); @@ -510,6 +585,7 @@ char **argv; ldrargs.prog = fixpath(ldrargs.prog, &exec_prefix, X_OK); #endif unprotoargs.prog=fixpath(unprotoargs.prog, &exec_prefix, X_OK); + optargs.prog = fixpath(optargs.prog, &exec_prefix, X_OK); if (tmpdir == NUL_PTR && (tmpdir = getenv("TMPDIR")) == NUL_PTR) #ifdef MSDOS tmpdir = "."; @@ -603,7 +679,7 @@ char **argv; { if (prep_only) continue; - if (cc_only) + if (cc_only && !optimize) { if (f_out != NUL_PTR) out_name = f_out; @@ -618,6 +694,25 @@ char **argv; if (run(in_name, out_name, &ccargs) != 0) continue; in_name = out_name; + if( optimize ) + { + if (cc_only) + { + if (f_out != NUL_PTR) + out_name = f_out; + else + { + out_name = stralloc(basename); + out_name[strlen(out_name) - 1] = 's'; + } + } + else + out_name = my_mktemp(); + + if (run(in_name, out_name, &optargs) != 0) + continue; + in_name = out_name; + } ext = 's'; } if (ext == 'S') @@ -826,6 +921,7 @@ static struct aout_exec { close(fd); } +#ifdef L_TREE #ifdef MSDOS PRIVATE void reset_localprefix() { @@ -846,6 +942,68 @@ PRIVATE void reset_localprefix() else free(temp); } +#else + +PRIVATE void reset_localprefix() +{ + char *ptr, *temp; + + if( *progname == '/' ) + temp = stralloc(progname); + else + { + char * s, * d; + ptr = getenv("PATH"); + if( ptr==0 || *ptr == 0 ) return; + ptr = stralloc(ptr); + temp = stralloc(""); + + for(d=s=ptr; d && *s; s=d) + { +#ifdef MAXPATHLEN + char buf[MAXPATHLEN]; +#else + char buf[1024]; +#endif + + free(temp); + d=strchr(s, ':'); + if( d ) *d='\0'; + temp = my_malloc(strlen(progname)+strlen(s)+2, "prefixing"); + strcpy(temp, s); + strcat(temp, "/"); + strcat(temp, progname); + if( realpath(temp, buf) != 0 ) + { + free(temp); + temp = stralloc(buf); + } + if( access(temp, X_OK) == 0 ) break; + d++; + } + if( s == 0 ) + { + free(temp); + temp = stralloc(progname); + } + free(ptr); + } + + if( (ptr = strrchr(temp, '/')) != 0 + && temp<ptr-4 && strncmp(ptr-4, "/bin", 4) == 0 ) + { + ptr[-4] = 0; + localprefix = temp; + if (verbosity > 2) + { + show_who("localprefix is now "); + writesn(localprefix); + } + } + else + free(temp); +} +#endif #endif PRIVATE char * expand_tilde(str, canfree) @@ -966,13 +1124,14 @@ PRIVATE char *my_mktemp() static unsigned tmpnum; #ifdef MSDOS - p = template = stralloc2(tmpdir, "/$$YYYXXX"); + digits = 42; + p = template = stralloc2(tmpdir, "/$$YYYYXX"); #else + digits = getpid(); p = template = stralloc2(tmpdir, "/bccYYYYXXXX"); #endif p += strlen(p); - digits = getpid(); while (*--p == 'X') { if ((digit = digits % 16) > 9) @@ -1060,6 +1219,12 @@ struct arg_s *argp; if (verbosity > 4 ) return 0; #ifdef MSDOS status = spawnv(0, argp->prog, argp->argv+arg0); + if( status<0 ) + { + show_who("spawn of "); + writes(argp->prog); + writesn(" failed"); + } #else switch (fork()) { diff --git a/bcc/bcc.exe b/bcc/bcc.exe Binary files differdeleted file mode 100644 index db47d08..0000000 --- a/bcc/bcc.exe +++ /dev/null diff --git a/bcc/const.h b/bcc/const.h index 20608c2..f8fd692 100644 --- a/bcc/const.h +++ b/bcc/const.h @@ -2,6 +2,12 @@ /* Copyright (C) 1992 Bruce Evans */ +#ifdef __STDC__ +#include <stdlib.h> +#else +#include <malloc.h> +#endif + /* switches for code generation */ #if !defined(I8088) && !defined(MC6809) diff --git a/bcc/input.c b/bcc/input.c index f32fd9e..f905416 100644 --- a/bcc/input.c +++ b/bcc/input.c @@ -433,7 +433,10 @@ ts_s_pathname_tot -= strlen(inputbuf->fname) + 1; ts_s_inputbuf_tot -= sizeof *inputbuf; #endif ourfree((char *) inputbuf); - close(input.fd); +#ifndef NO_EOFHACK + if(input.fd>=0) +#endif + close(input.fd); #ifdef FAKE_INBUFSIZE_1 fclose(input.fp); #endif @@ -675,7 +678,23 @@ case0: #endif *lineptr = ich; #else - nread = read(input.fd, lineptr = inputbuf->fbuf, INBUFSIZE); +#ifndef NO_EOFHACK + if(input.fd<0) + nread=0; + else + { +#endif + nread = read(input.fd, lineptr = inputbuf->fbuf, INBUFSIZE); +#ifndef NO_EOFHACK + if( nread == 0 && inclevel > 0 ) + { + close(input.fd); + input.fd = -1; + memcpy(inputbuf->fbuf, "\n", 1); + nread = 1; + } + } +#endif #endif if (nread < 0) fatalerror("input error"); diff --git a/bcc/preproc.c b/bcc/preproc.c index 030214b..b9aed0e 100644 --- a/bcc/preproc.c +++ b/bcc/preproc.c @@ -64,7 +64,9 @@ FORWARD void undef P((void)); PRIVATE void asmcontrol() { +#ifdef ASM_BARE char treasure; /* to save at least one leading blank */ +#endif asmmode = TRUE; if (orig_cppmode) diff --git a/bcc/proto.h b/bcc/proto.h index cd26e0c..e45cf0e 100644 --- a/bcc/proto.h +++ b/bcc/proto.h @@ -7,7 +7,6 @@ #else #define P(x) () #endif -#include <malloc.h> /* assign.c */ void assign P((struct symstruct *source, struct symstruct *target)); |