From d1e9cd803b2a34baddf8d9a8ae64c05b7cef6ff0 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 23 Jun 2018 23:29:13 +0200 Subject: [PATCH 01/17] Enable OSX builds on Travis again. --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 299ac5828..832335f7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,10 @@ matrix: sudo: false dist: trusty compiler: clang -# - -# os: osx -# env: HOMEBREW_NO_AUTO_UPDATE=1 -# compiler: clang + - + os: osx + env: HOMEBREW_NO_AUTO_UPDATE=1 + compiler: clang git: depth: 10 From 65e544c35a719e1b1845c8c57cfa9aa8b3ef296d Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 12:28:42 +0100 Subject: [PATCH 02/17] Don't prototype strcpy as it makes OSX sad. --- util/LLgen/src/tokens.g | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/LLgen/src/tokens.g b/util/LLgen/src/tokens.g index bc39d22ad..79ee579da 100644 --- a/util/LLgen/src/tokens.g +++ b/util/LLgen/src/tokens.g @@ -549,8 +549,6 @@ cpy(s,p,inserted) register string p; { return p; } -string strcpy(); - LLmessage(d) { /* * d is either 0, in which case the current token has been deleted, From dd35aa3eefac6769aff0f6775e7958e84afc54cb Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 12:35:18 +0100 Subject: [PATCH 03/17] We don't need depth 10 in the travis checkout. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 832335f7c..e43a00984 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: compiler: clang git: - depth: 10 + depth: 1 script: - make CC=$CC PREFIX=/tmp/acki +ack From 020e91056062a0a67cb9b1c62e5fbd6c484ef6ce Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 12:38:33 +0100 Subject: [PATCH 04/17] Remember that we need to update the generated file in LLgen, as it's not self-bootstrapping... --- util/LLgen/src/tokens.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/LLgen/src/tokens.c b/util/LLgen/src/tokens.c index 096c50951..9d94d8716 100644 --- a/util/LLgen/src/tokens.c +++ b/util/LLgen/src/tokens.c @@ -579,8 +579,6 @@ cpy(s,p,inserted) register string p; { return p; } -string strcpy(); - LLmessage(d) { /* * d is either 0, in which case the current token has been deleted, From 666d9a3edb3540fa1a29ea1ab78f5cff2a8de7f3 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 12:57:00 +0100 Subject: [PATCH 05/17] Add stray header. --- plat/cpm/emu/globals.h | 1 + 1 file changed, 1 insertion(+) diff --git a/plat/cpm/emu/globals.h b/plat/cpm/emu/globals.h index 6979f31aa..94e302330 100644 --- a/plat/cpm/emu/globals.h +++ b/plat/cpm/emu/globals.h @@ -2,6 +2,7 @@ #define GLOBALS_H #include +#include extern uint8_t ram[0x10000]; From 8a7077d5a97b1431b1b7be26b17e12f3d5d5c654 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 12:57:22 +0100 Subject: [PATCH 06/17] Change the way external symbols are defined to avoid COMMON symbols, which don't work on OSX very well. --- util/ack/data.c | 16 ++++++---------- util/ack/data.h | 5 ++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/util/ack/data.c b/util/ack/data.c index 181e034dc..2a6946597 100644 --- a/util/ack/data.c +++ b/util/ack/data.c @@ -6,15 +6,11 @@ #include "list.h" #include "trans.h" -#ifndef NORCSID -static char rcs_id[] = "$Id$" ; -#endif - -#undef EXTERN -#define EXTERN - +/* Include once without redefining EXTERN, to declare all the symbols as extern. */ #include "data.h" -#ifndef NORCSID -static char rcs_data[] = RCS_DATA ; -#endif +/* And again without EXTERN, to define them here. Without the extern versions above + * then these symbols will all end up as COMMON, which is poorly supported on OSX. */ +#undef EXTERN +#define EXTERN +#include "data.h" diff --git a/util/ack/data.h b/util/ack/data.h index ea845c4f7..faa094c0d 100644 --- a/util/ack/data.h +++ b/util/ack/data.h @@ -2,9 +2,8 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -#ifndef NORCSID -#define RCS_DATA "$Id$" -#endif + +/* WARNING: don't put guards around this file (there are reasons). See data.c. */ EXTERN char *stopsuffix; /* Suffix to stop at */ EXTERN char *machine; /* The machine id */ From c8c48221b3aa818c8f3e6e2136650073a56341df Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 13:11:03 +0100 Subject: [PATCH 07/17] Second try at removing common symbols. --- util/ack/ack.h | 111 ++++++++++++++++++++++++------------------------ util/ack/data.c | 50 +++++++++++++++++++--- util/ack/data.h | 67 +++++++++++++++-------------- 3 files changed, 133 insertions(+), 95 deletions(-) diff --git a/util/ack/ack.h b/util/ack/ack.h index 01eec8212..144fd5343 100644 --- a/util/ack/ack.h +++ b/util/ack/ack.h @@ -12,8 +12,8 @@ /* User settable options */ /****************************************************************************/ -#define FRONTENDS "fe" /* The front-end definitions */ -#define TMPNAME "Ack_%x" /* Naming of temp. files */ +#define FRONTENDS "fe" /* The front-end definitions */ +#define TMPNAME "Ack_%x" /* Naming of temp. files */ /****************************************************************************/ /* Internal mnemonics, should not be tinkered with */ @@ -21,77 +21,76 @@ /* The names of some string variables */ -#define HOME "EM" -#define RTS "RTS" -#define HEAD "HEAD" -#define TAIL "TAIL" -#define SRC "SOURCE" -#define LIBVAR "LNAME" -#define SUFFIX "SUFFIX" +#define HOME "EM" +#define RTS "RTS" +#define HEAD "HEAD" +#define TAIL "TAIL" +#define SRC "SOURCE" +#define LIBVAR "LNAME" +#define SUFFIX "SUFFIX" /* Intended for flags, possibly in bit fields */ -#define YES 1 -#define NO 0 -#define MAYBE 2 +#define YES 1 +#define NO 0 +#define MAYBE 2 -#define EXTERN extern +#define SUFCHAR '.' /* Start of SUFFIX in file name */ +#define SPACE ' ' +#define TAB '\t' +#define EQUAL '=' +#define S_VAR '{' /* Start of variable */ +#define C_VAR '}' /* End of variable */ +#define A_VAR '?' /* Variable alternative */ +#define BSLASH '\\' /* Backslash */ +#define STAR '*' /* STAR */ +#define C_IN '<' /* Token specifying input */ +#define C_OUT '>' /* Token specifying output */ +#define S_EXPR '(' /* Start of expression */ +#define C_EXPR ')' /* End of expression */ +#define M_EXPR ':' /* Middle of two suffix lists */ +#define T_EXPR '=' /* Start of tail */ -#define SUFCHAR '.' /* Start of SUFFIX in file name */ -#define SPACE ' ' -#define TAB '\t' -#define EQUAL '=' -#define S_VAR '{' /* Start of variable */ -#define C_VAR '}' /* End of variable */ -#define A_VAR '?' /* Variable alternative */ -#define BSLASH '\\' /* Backslash */ -#define STAR '*' /* STAR */ -#define C_IN '<' /* Token specifying input */ -#define C_OUT '>' /* Token specifying output */ -#define S_EXPR '(' /* Start of expression */ -#define C_EXPR ')' /* End of expression */ -#define M_EXPR ':' /* Middle of two suffix lists */ -#define T_EXPR '=' /* Start of tail */ +#define NO_SCAN 0200 /* Bit set in character to defeat recogn. */ -#define NO_SCAN 0200 /* Bit set in character to defeat recogn. */ +typedef struct +{ + char* p_path; /* points to the full pathname */ + int p_keeps : 1; /* The string should be thrown when unused */ + int p_keep : 1; /* The file should be thrown away after use */ +} path; -typedef struct { - char *p_path; /* points to the full pathname */ - int p_keeps:1; /* The string should be thrown when unused */ - int p_keep:1; /* The file should be thrown away after use */ -} path ; - -#define p_cont(elem) ((path *)l_content(elem)) +#define p_cont(elem) ((path*)l_content(elem)) /* Own routines */ /* rmach.c */ -void setlist(char *); +extern void setlist(char*); /* svars.c */ -void setsvar(char *, char *); -void setpvar(char *, char *(*)(void)); -char *getvar(const char *); +extern void setsvar(char*, char*); +extern void setpvar(char*, char* (*)(void)); +extern char* getvar(const char*); /* util.c */ -char *ack_basename(const char *); -char *skipblank(char *); -char *firstblank(char *); -void fatal(const char *, ...); -void vprint(const char *, ...); -void fuerror(const char *, ...); -void werror(const char *, ...); -void quit(int); -char *keeps(const char *); -#define throws(str) free(str) -void *getcore(size_t); -void *changecore(void *, size_t); -#define freecore(area) free(area) +extern char* ack_basename(const char*); +extern char* skipblank(char*); +extern char* firstblank(char*); +extern void fatal(const char*, ...); +extern void vprint(const char*, ...); +extern void fuerror(const char*, ...); +extern void werror(const char*, ...); +extern void quit(int); +extern char* keeps(const char*); +#define throws(str) free(str) +extern void* getcore(size_t); +extern void* changecore(void*, size_t); +#define freecore(area) free(area) -#define DEBUG 1 /* Allow debugging of Ack */ +#define DEBUG 1 /* Allow debugging of Ack */ #ifndef DEBUG -# define debug 0 /* To surprise all these 'if ( debug ) 's */ +#define debug 0 /* To surprise all these 'if ( debug ) 's */ #else -extern int debug ; +extern int debug; #endif diff --git a/util/ack/data.c b/util/ack/data.c index 2a6946597..168894dfd 100644 --- a/util/ack/data.c +++ b/util/ack/data.c @@ -5,12 +5,48 @@ #include "ack.h" #include "list.h" #include "trans.h" - -/* Include once without redefining EXTERN, to declare all the symbols as extern. */ #include "data.h" -/* And again without EXTERN, to define them here. Without the extern versions above - * then these symbols will all end up as COMMON, which is poorly supported on OSX. */ -#undef EXTERN -#define EXTERN -#include "data.h" +char* stopsuffix = NULL; /* Suffix to stop at */ +char* machine = NULL; /* The machine id */ +char* callname = NULL; /* argv[0] */ +char* rts = NULL; /* The runtime-system */ +char* rtsuf = NULL; /* The runtime-system module suffix */ +char* Optlist = NULL; /* Which optimizers */ + +list_head arguments = {}; /* List of arguments */ +list_head flags = {}; /* List of flags */ + +list_head tr_list = {}; /* List of transformations */ + +list_head R_list = {}; /* List of -R flags */ +list_head head_list = {}; /* List of suffices for headers */ +list_head tail_list = {}; /* List of suffices for tails */ + +int k_flag = 0; /* Like -k of lint */ +int t_flag = 0; /* Preserve intermediate files */ +int v_flag = 0; /* Verbose */ +int w_flag = 0; /* Don't print warnings */ +int nill_flag = 0; /* Don't print file names */ +int Optlevel = 0; /* Optimizing */ + +#ifdef DEBUG +int debug = 0; /* Debugging control */ +#endif + +int n_error = 0; /* Number of errors encountered */ + +char* progname = NULL; /* The program call name */ + +char* outfile = NULL; /* The result file e.g. a.out */ +char template[20] = {}; /* The template for temporary file + names */ + +trf* linker = NULL; /* Pointer to the Loader/Linker */ +trf* cpp_trafo = NULL; /* Pointer to C-preprocessor */ + +path in = {}; /* The current single input pathname */ +path out = {}; /* The current output pathname */ +path orig = {}; /* The original input path */ +char* p_basename = NULL; /* The current basename */ +const char* p_suffix = NULL; /* The current input suffix */ diff --git a/util/ack/data.h b/util/ack/data.h index faa094c0d..c775e82c0 100644 --- a/util/ack/data.h +++ b/util/ack/data.h @@ -3,48 +3,51 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* WARNING: don't put guards around this file (there are reasons). See data.c. */ +#ifndef DATA_H +#define DATA_H -EXTERN char *stopsuffix; /* Suffix to stop at */ -EXTERN char *machine; /* The machine id */ -EXTERN char *callname; /* argv[0] */ -EXTERN char *rts; /* The runtime-system */ -EXTERN char *rtsuf; /* The runtime-system module suffix */ -EXTERN char *Optlist; /* Which optimizers */ +extern char* stopsuffix; /* Suffix to stop at */ +extern char* machine; /* The machine id */ +extern char* callname; /* argv[0] */ +extern char* rts; /* The runtime-system */ +extern char* rtsuf; /* The runtime-system module suffix */ +extern char* Optlist; /* Which optimizers */ -EXTERN list_head arguments; /* List of arguments */ -EXTERN list_head flags; /* List of flags */ +extern list_head arguments; /* List of arguments */ +extern list_head flags; /* List of flags */ -EXTERN list_head tr_list; /* List of transformations */ +extern list_head tr_list; /* List of transformations */ -EXTERN list_head R_list; /* List of -R flags */ -EXTERN list_head head_list; /* List of suffices for headers */ -EXTERN list_head tail_list; /* List of suffices for tails */ +extern list_head R_list; /* List of -R flags */ +extern list_head head_list; /* List of suffices for headers */ +extern list_head tail_list; /* List of suffices for tails */ -EXTERN int k_flag; /* Like -k of lint */ -EXTERN int t_flag; /* Preserve intermediate files */ -EXTERN int v_flag; /* Verbose */ -EXTERN int w_flag; /* Don't print warnings */ -EXTERN int nill_flag; /* Don't print file names */ -EXTERN int Optlevel; /* Optimizing */ +extern int k_flag; /* Like -k of lint */ +extern int t_flag; /* Preserve intermediate files */ +extern int v_flag; /* Verbose */ +extern int w_flag; /* Don't print warnings */ +extern int nill_flag; /* Don't print file names */ +extern int Optlevel; /* Optimizing */ #ifdef DEBUG -EXTERN int debug; /* Debugging control */ +extern int debug; /* Debugging control */ #endif -EXTERN int n_error; /* Number of errors encountered */ +extern int n_error; /* Number of errors encountered */ -EXTERN char *progname; /* The program call name */ +extern char* progname; /* The program call name */ -EXTERN char *outfile; /* The result file e.g. a.out */ -EXTERN char template[20]; /* The template for temporary file - names */ +extern char* outfile; /* The result file e.g. a.out */ +extern char template[20]; /* The template for temporary file + names */ -EXTERN trf *linker; /* Pointer to the Loader/Linker */ -EXTERN trf *cpp_trafo; /* Pointer to C-preprocessor */ +extern trf* linker; /* Pointer to the Loader/Linker */ +extern trf* cpp_trafo; /* Pointer to C-preprocessor */ -EXTERN path in; /* The current single input pathname */ -EXTERN path out; /* The current output pathname */ -EXTERN path orig; /* The original input path */ -EXTERN char *p_basename; /* The current basename */ -EXTERN const char *p_suffix; /* The current input suffix */ +extern path in; /* The current single input pathname */ +extern path out; /* The current output pathname */ +extern path orig; /* The original input path */ +extern char* p_basename; /* The current basename */ +extern const char* p_suffix; /* The current input suffix */ + +#endif From 58698bed19ecc58d932dd1b74d35647ba6710109 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 13:20:04 +0100 Subject: [PATCH 08/17] Removed a whole bunch of old strcpy() prototypes in favour of . --- lang/cem/cpp.ansi/init.c | 1 - mach/proto/cg/compute.c | 2 +- modules/src/em_code/em.c | 1 - modules/src/em_opt/outputdfa.c | 2 +- util/byacc/defs.h | 16 ++-------------- util/cmisc/cclash.c | 3 +-- util/cmisc/cid.c | 3 +-- util/cmisc/mkdep.c | 2 +- util/cmisc/prid.c | 3 +-- util/cpp/LLlex.c | 2 +- util/cpp/init.c | 3 +-- util/cpp/replace.c | 1 - util/int/log.c | 4 +--- util/int/main.c | 6 ++---- 14 files changed, 13 insertions(+), 36 deletions(-) diff --git a/lang/cem/cpp.ansi/init.c b/lang/cem/cpp.ansi/init.c index 3953609b5..810b4204c 100644 --- a/lang/cem/cpp.ansi/init.c +++ b/lang/cem/cpp.ansi/init.c @@ -34,7 +34,6 @@ struct mkey { {0, K_UNKNOWN} }; -char *strcpy(); char *sprint(); init_pp() diff --git a/mach/proto/cg/compute.c b/mach/proto/cg/compute.c index 26570f49d..49d2381fa 100644 --- a/mach/proto/cg/compute.c +++ b/mach/proto/cg/compute.c @@ -73,7 +73,7 @@ char opdesc[] = { LLDEF, /* EX_REGVAR */ }; -string salloc(),strcpy(),strcat(); +string salloc(); string mycat(s1,s2) string s1,s2; { register string s; diff --git a/modules/src/em_code/em.c b/modules/src/em_code/em.c index f13ab28dc..cf6948bff 100644 --- a/modules/src/em_code/em.c +++ b/modules/src/em_code/em.c @@ -31,7 +31,6 @@ File *C_ofp; #ifndef INCORE File *C_tfr; char *C_tmpfile; -char *strcpy(), *strcat(); char *C_ibuf = 0; long C_current_out; #endif diff --git a/modules/src/em_opt/outputdfa.c b/modules/src/em_opt/outputdfa.c index cebdd958c..c58c966b9 100644 --- a/modules/src/em_opt/outputdfa.c +++ b/modules/src/em_opt/outputdfa.c @@ -2,6 +2,7 @@ static char rcsidp5[] = "$Id$"; #endif +#include #include "parser.h" #include "Lpars.h" @@ -40,7 +41,6 @@ PRIVATE openofile(filename) char *filename; { - char *strcpy(), *strcat(); strcpy(ofilename,filename); strcpy(ofiletemp,filename); strcat(ofiletemp,".new"); diff --git a/util/byacc/defs.h b/util/byacc/defs.h index 5eef5c55a..8be3d80db 100644 --- a/util/byacc/defs.h +++ b/util/byacc/defs.h @@ -1,6 +1,8 @@ #include #include #include +#include +#include /* machine dependent definitions */ /* the following definitions are for the VAX */ @@ -269,17 +271,3 @@ extern short final_state; extern char *allocate(); extern bucket *lookup(); extern bucket *make_bucket(); - - -/* system variables */ - -extern int errno; - - -/* system functions */ - -extern void free(); -extern char *calloc(); -extern char *malloc(); -extern char *realloc(); -extern char *strcpy(); diff --git a/util/cmisc/cclash.c b/util/cmisc/cclash.c index 44fa6cbe6..1bc8c68b3 100644 --- a/util/cmisc/cclash.c +++ b/util/cmisc/cclash.c @@ -30,6 +30,7 @@ */ #include +#include #define DEF_LENGTH 8 @@ -184,8 +185,6 @@ char * Salloc(str) char *str; { - char *strcpy(); - if (str == 0) str = ""; diff --git a/util/cmisc/cid.c b/util/cmisc/cid.c index a21a4d940..b09136e33 100644 --- a/util/cmisc/cid.c +++ b/util/cmisc/cid.c @@ -14,6 +14,7 @@ */ #include +#include #ifndef DEF_LENGTH #define DEF_LENGTH 8 @@ -159,8 +160,6 @@ char * Salloc(str) char *str; { - char *strcpy(); - if (str == 0) { str = ""; } diff --git a/util/cmisc/mkdep.c b/util/cmisc/mkdep.c index 8e14ae2dc..065678929 100644 --- a/util/cmisc/mkdep.c +++ b/util/cmisc/mkdep.c @@ -10,6 +10,7 @@ */ #include +#incoude #define BSIZ 1024 char *prog; @@ -64,7 +65,6 @@ add_name(nm) char *nm; { struct namelist *nlp = nl, *lnlp = 0, *nnlp; - char *strcpy(); while (nlp) { register i = strcmp(nm, nlp->name); diff --git a/util/cmisc/prid.c b/util/cmisc/prid.c index e81efe59e..79818bb27 100644 --- a/util/cmisc/prid.c +++ b/util/cmisc/prid.c @@ -14,6 +14,7 @@ */ #include +#include extern char *ProgName; @@ -101,8 +102,6 @@ char * Salloc(str) char *str; { - char *strcpy(); - if (str == 0) str = ""; diff --git a/util/cpp/LLlex.c b/util/cpp/LLlex.c index 93602e9d9..4bba8c0a2 100644 --- a/util/cpp/LLlex.c +++ b/util/cpp/LLlex.c @@ -5,6 +5,7 @@ /* $Id$ */ /* L E X I C A L A N A L Y Z E R */ +#include #include "idfsize.h" #include "numsize.h" #include "strsize.h" @@ -26,7 +27,6 @@ int AccDefined = 0; /* accept "defined(...)" */ int UnknownIdIsZero = 0; /* interpret unknown id as integer 0 */ char *string_token(); -char *strcpy(); PushLex() { diff --git a/util/cpp/init.c b/util/cpp/init.c index 61e2ac809..8a7273711 100644 --- a/util/cpp/init.c +++ b/util/cpp/init.c @@ -5,6 +5,7 @@ */ /* PREPROCESSOR: INITIALIZATION ROUTINES */ +#include #include #include #include "class.h" @@ -30,8 +31,6 @@ PRIVATE struct mkey { {0, K_UNKNOWN} }; -char *strcpy(); - EXPORT init_pp() { diff --git a/util/cpp/replace.c b/util/cpp/replace.c index 1951e1bda..2c3eec830 100644 --- a/util/cpp/replace.c +++ b/util/cpp/replace.c @@ -20,7 +20,6 @@ #include "class.h" #include "interface.h" -char *strcpy(), *strcat(); char *long2str(); extern int InputLevel; diff --git a/util/int/log.c b/util/int/log.c index 517d90a88..add9f356a 100644 --- a/util/int/log.c +++ b/util/int/log.c @@ -5,6 +5,7 @@ /* $Id$ */ #include +#include #if __STDC__ #include #else @@ -17,9 +18,6 @@ #ifdef LOGGING -extern int strlen(); -extern char *strcpy(); - extern long mess_id; /* from io.c */ extern FILE *fcreat_high(); /* from io.c */ diff --git a/util/int/main.c b/util/int/main.c index 3681d915f..a3fd17b4f 100644 --- a/util/int/main.c +++ b/util/int/main.c @@ -5,6 +5,8 @@ /* $Id$ */ #include +#include +#include #include #include @@ -20,10 +22,6 @@ #include "opcode.h" #include "rsb.h" -extern int atoi(); -extern long atol(); -extern char *strcpy(); - char mess_file[64] = "int.mess"; /* name of message file */ jmp_buf trapbuf; From d37749750d34658a3b90833f7382bf81d3d1a9b2 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 14:03:55 +0100 Subject: [PATCH 09/17] More common symbol fixing. --- util/ego/share/map.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/util/ego/share/map.c b/util/ego/share/map.c index 14353e800..d2724fe1d 100644 --- a/util/ego/share/map.c +++ b/util/ego/share/map.c @@ -5,22 +5,23 @@ */ /* M A P . C */ +#include #include "types.h" #include "map.h" -short plength; -short olength; -short llength; -short blength; -short lplength; -line_p *lmap; -bblock_p *lbmap; -proc_p *pmap ; /* dynamically allocated array that maps - * every proc_id to a proc_p. - */ -obj_p *omap; /* maps obj_id to obj_p */ -loop_p *lpmap; /* maps loop_id to loop_p */ -bblock_p *bmap; /* maps block_id to bblock_p */ +short plength = 0; +short olength = 0; +short llength = 0; +short blength = 0; +short lplength = 0; +line_p* lmap = NULL; +bblock_p* lbmap = NULL; +proc_p* pmap = NULL; /* dynamically allocated array that maps + * every proc_id to a proc_p. + */ +obj_p* omap = NULL; /* maps obj_id to obj_p */ +loop_p* lpmap = NULL; /* maps loop_id to loop_p */ +bblock_p* bmap = NULL; /* maps block_id to bblock_p */ -dblock_p fdblock; /* first dblock */ -proc_p fproc; /* first proc */ +dblock_p fdblock = NULL; /* first dblock */ +proc_p fproc = NULL; /* first proc */ From 813595358ce0c478e2845b43d38665cb257f19c7 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 14:09:52 +0100 Subject: [PATCH 10/17] More common symbol removal. --- util/int/global.c | 72 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/util/int/global.c b/util/int/global.c index d2087b5e6..9125baf42 100644 --- a/util/int/global.c +++ b/util/int/global.c @@ -10,61 +10,61 @@ /******** EM Machine capacity parameters ********/ -size wsize; -size dwsize; -size psize; -long i_minsw; -long i_maxsw; -unsigned long i_maxuw; -long min_off; -long max_off; -ptr max_addr; -size wsizem1; +size wsize = 0; +size dwsize = 0; +size psize = 0; +long i_minsw = 0; +long i_maxsw = 0; +unsigned long i_maxuw = 0; +long min_off = 0; +long max_off = 0; +ptr max_addr = 0; +size wsizem1 = 0; /******** EM program parameters ********/ -ptr ML; -ptr HB; -ptr DB; -long NProc; -long PreIgnMask; +ptr ML = 0; +ptr HB = 0; +ptr DB = 0; +long NProc = 0; +long PreIgnMask = 0; /******** EM machine registers ********/ -long PI; -ptr PC; +long PI = 0; +ptr PC = 0; -ptr HP; -ptr SP; -ptr LB; -ptr AB; +ptr HP = 0; +ptr SP = 0; +ptr LB = 0; +ptr AB = 0; -long ES; -int ES_def; +long ES = 0; +int ES_def = 0; -int OnTrap; -long IgnMask; -long TrapPI; +int OnTrap = 0; +long IgnMask = 0; +long TrapPI = 0; -char *FRA; -size FRALimit; -size FRASize; -int FRA_def; +char *FRA = NULL; +size FRALimit = 0; +size FRASize = 0; +int FRA_def = 0; /******** The EM Machine Memory ********/ -char *text; +char *text = NULL; -char *data; -ptr HL; +char *data = NULL; +ptr HL = 0; -char *stack; -char *stackML; -ptr SL; +char *stack = NULL; +char *stackML = NULL; +ptr SL = 0; From 1dfafe070cb9b7f424555a4f8a539c16be27a86e Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 14:19:18 +0100 Subject: [PATCH 11/17] Better error reporting. --- mach/proto/as/comm7.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mach/proto/as/comm7.c b/mach/proto/as/comm7.c index 02a7c1d58..c48de4d92 100644 --- a/mach/proto/as/comm7.c +++ b/mach/proto/as/comm7.c @@ -8,6 +8,7 @@ * miscellaneous */ +#include #include "comm0.h" #include "comm1.h" #include "y.tab.h" @@ -391,7 +392,7 @@ void emitf(int size, int negative) void ffreopen(char* s, FILE* f) { if (freopen(s, "r", f) == NULL) - fatal("can't reopen %s", s); + fatal("can't reopen %s: %s", s, strerror(errno)); } FILE* ffcreat(char* s) From 63fa647bc9cbc94373b2fb56a04fdeb0fd23ccbc Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 14:32:17 +0100 Subject: [PATCH 12/17] freopen() appears to be problematic on OSX; as it's only ever used to rewind files, replace with rewind(). --- mach/proto/as/comm1.h | 1 - mach/proto/as/comm4.c | 4 ++-- mach/proto/as/comm7.c | 8 +------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/mach/proto/as/comm1.h b/mach/proto/as/comm1.h index 206ae0b5d..660f41907 100644 --- a/mach/proto/as/comm1.h +++ b/mach/proto/as/comm1.h @@ -155,7 +155,6 @@ void emit4(long); void emitx(valu_t, int); void emitf(int size, int negative); void emitstr(int); -void ffreopen(char *, FILE *); FILE *ffcreat(char *); FILE *fftemp(char *, char *); void yyerror(const char *); diff --git a/mach/proto/as/comm4.c b/mach/proto/as/comm4.c index 3e88c41ed..9348b802a 100644 --- a/mach/proto/as/comm4.c +++ b/mach/proto/as/comm4.c @@ -399,7 +399,7 @@ pass_23(int n) #ifdef LISTING listmode >>= 3; if (listmode & 4) - ffreopen(listpath, listfile); + rewind(listfile); listeoln = 1; #endif #ifdef THREE_PASS @@ -438,7 +438,7 @@ pass_23(int n) #ifndef ASLD newmodule(modulename); #endif /* ASLD */ - ffreopen(temppath, tempfile); + rewind(tempfile); yyparse(); commfinish(); machfinish(n); diff --git a/mach/proto/as/comm7.c b/mach/proto/as/comm7.c index c48de4d92..debee0ca2 100644 --- a/mach/proto/as/comm7.c +++ b/mach/proto/as/comm7.c @@ -389,17 +389,11 @@ void emitf(int size, int negative) /* ---------- Error checked file I/O ---------- */ -void ffreopen(char* s, FILE* f) -{ - if (freopen(s, "r", f) == NULL) - fatal("can't reopen %s: %s", s, strerror(errno)); -} - FILE* ffcreat(char* s) { FILE* f; - if ((f = fopen(s, "w")) == NULL) + if ((f = fopen(s, "w+")) == NULL) fatal("can't create %s", s); return (f); } From c95d5db372f1d7ffc526debac99a586351482d59 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 14:36:15 +0100 Subject: [PATCH 13/17] Replace mkstemp() with the more modern and safer and simpler tmpfile(). --- mach/proto/as/comm1.h | 4 ---- mach/proto/as/comm4.c | 17 ++--------------- mach/proto/as/comm7.c | 27 --------------------------- 3 files changed, 2 insertions(+), 46 deletions(-) diff --git a/mach/proto/as/comm1.h b/mach/proto/as/comm1.h index 660f41907..391675a98 100644 --- a/mach/proto/as/comm1.h +++ b/mach/proto/as/comm1.h @@ -53,7 +53,6 @@ extern short bflag; /* -b option (no optimizations) */ #endif extern char *aoutpath INIT("a.out"); -extern char temppath[50]; extern FILE *input; extern FILE *tempfile; @@ -93,7 +92,6 @@ extern short listcolm; /* column on output */ extern short listeoln INIT(1); /* set by endline, tested by emit1 */ extern FILE *listfile; /* copy of source text */ -extern char listpath[50]; #endif #ifndef extern @@ -155,8 +153,6 @@ void emit4(long); void emitx(valu_t, int); void emitf(int size, int negative); void emitstr(int); -FILE *ffcreat(char *); -FILE *fftemp(char *, char *); void yyerror(const char *); void nosect(void); void fatal(const char *, ...); diff --git a/mach/proto/as/comm4.c b/mach/proto/as/comm4.c index 9348b802a..a47d1438d 100644 --- a/mach/proto/as/comm4.c +++ b/mach/proto/as/comm4.c @@ -32,12 +32,6 @@ static void commfinish(void); /* ========== Machine independent C routines ========== */ void stop(void) { -#if DEBUG < 2 - unlink(temppath); -#ifdef LISTING - unlink(listpath); -#endif -#endif exit(nerrors != 0); } @@ -78,13 +72,6 @@ main(int argc, char **argv) fatal("-o needs filename"); aoutpath = argv[i]; break; - case 'T': - if (*p != '\0') { - extern char *tmp_dir; - - tmp_dir = p; - } - break; case 'd': #ifdef LISTING dflag = 0; @@ -154,11 +141,11 @@ pass_1(int argc, char **argv) nbits = BITCHUNK; #endif - tempfile = fftemp(temppath, "asTXXXXXX"); + tempfile = tmpfile(); #ifdef LISTING listmode = dflag; if (listmode & 0440) - listfile = fftemp(listpath, "asLXXXXXX"); + listfile = tmpfile(); #endif for (ip = keytab; ip->i_type; ip++) item_insert(ip, H_KEY+hash(ip->i_name)); diff --git a/mach/proto/as/comm7.c b/mach/proto/as/comm7.c index debee0ca2..5611e8272 100644 --- a/mach/proto/as/comm7.c +++ b/mach/proto/as/comm7.c @@ -387,33 +387,6 @@ void emitf(int size, int negative) con_float(stringbuf, size); } -/* ---------- Error checked file I/O ---------- */ - -FILE* ffcreat(char* s) -{ - FILE* f; - - if ((f = fopen(s, "w+")) == NULL) - fatal("can't create %s", s); - return (f); -} - -#ifndef TMPDIR -#define TMPDIR "/tmp" -#endif -char* tmp_dir = TMPDIR; - -FILE* fftemp(char* path, char* tail) -{ - char* dir; - - if ((dir = getenv("TMPDIR")) == NULL) - dir = tmp_dir; - sprintf(path, "%s/%s", dir, tail); - close(mkstemp(path)); - return (ffcreat(path)); -} - /* ---------- Error handling ---------- */ /* ARGSUSED */ From b34ff2bdec05da58f1b7fa38ccb7f9d2dc34fd2d Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 18:44:47 +0100 Subject: [PATCH 14/17] Teach the i80 code generator how to do left shifts by using dad hl; prevents it from calling out to .sli2 for simple shifts. Shrinks Star Trek from 40055 bytes to 39976. --- mach/i80/ncg/table | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/mach/i80/ncg/table b/mach/i80/ncg/table index 046c99963..b0fcf3a6a 100644 --- a/mach/i80/ncg/table +++ b/mach/i80/ncg/table @@ -702,14 +702,33 @@ pat ngi $1==4 kills ALL gen Call {label,".ngi4"} -pat loc sli ($1 == 8) && ($2 == 2) -with hl_or_de -gen move %1.2, %1.1 - mvi %1.2, {const1,0} yields %1 +pat loc sli ($1==1) && ($2==2) + with hlreg + gen + dad hl + yields hl + +pat loc sli ($1>=2) && ($1<=7) && ($2==2) + with hlreg + gen + dad hl + yields hl + leaving + loc $1-1 + sli 2 + +pat loc sli ($1==8) && ($2==2) + with hl_or_de + gen + mov %1.1, %1.2 + mvi %1.2, {const1, 0} + yields %1 pat sli $1==2 -kills ALL -gen Call {label,".sli2"} yields de + kills ALL + gen + Call {label,".sli2"} + yields de pat sli $1==4 kills ALL @@ -761,7 +780,14 @@ kills ALL gen mvi a,{const1,0} Call {label,".dvi4"} -pat slu leaving sli $1 +pat loc slu ($2==2) + leaving + loc $1 + sli $2 + +pat slu + leaving + sli $1 pat loc sru ($1 == 8) && ($2 == 2) with hl_or_de From 35d1f36ca453733ba86a9321f338e43bb416bae6 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 18:57:20 +0100 Subject: [PATCH 15/17] Use pop rather than inx;inx to retract the stack; consumes a register but halves the number of calls. Reduces Star Trek from 39976 to 39771 bytes. --- mach/i80/ncg/table | 57 ++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/mach/i80/ncg/table b/mach/i80/ncg/table index b0fcf3a6a..720c1fa46 100644 --- a/mach/i80/ncg/table +++ b/mach/i80/ncg/table @@ -2053,46 +2053,29 @@ gen 1: /* Group 15: Miscellaneous */ /******************************************/ -pat asp $1<=0-6 -with STACK -uses hlreg={const2,$1} -gen dad sp - sphl. +pat asp ($1<=0-12) || ($1>=12) + with STACK + uses hlreg={const2,$1} + gen + dad sp + sphl. -pat asp $1==0-4 -with STACK -gen dcx sp - dcx sp - dcx sp - dcx sp +pat asp ($1<0) && ($1>0-12) + with STACK + gen + push hl + leaving + asp $1+2 -pat asp $1==0-2 -with STACK -gen dcx sp - dcx sp +pat asp $1==0 /* do nothing */ -pat asp $1==0 /* do nothing */ - -pat asp $1==2 -with exact src1or2 -with STACK - gen inx sp - inx sp - -pat asp $1==4 -with exact src1or2 leaving asp 2 -with STACK - gen inx sp - inx sp - inx sp - inx sp - -pat asp $1>=6 -with exact src1or2 leaving asp $1-2 -with STACK - uses hlreg={const2,$1} - gen dad sp - sphl. +pat asp ($1>0) && ($1<12) + with STACK + uses hlreg + gen + pop hl + leaving + asp $1-2 pat ass $1==2 with hlreg STACK From 7d34cd740786d9a4a87c42e0c434aa10bcb6bf8e Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 19:22:43 +0100 Subject: [PATCH 16/17] Simplify simple comparisons and use inlie constants where possible. Reduces Star Trek from 39771 to 39740 bytes. --- mach/i80/ncg/table | 168 ++++++++++++++++++++++++++++++--------------- mach/i80/top/table | 2 + 2 files changed, 114 insertions(+), 56 deletions(-) diff --git a/mach/i80/ncg/table b/mach/i80/ncg/table index 720c1fa46..67c8cb7e9 100644 --- a/mach/i80/ncg/table +++ b/mach/i80/ncg/table @@ -135,7 +135,7 @@ INSTRUCTIONS rst const1:ro cost(1,11). /* rz cost(1, 8). */ sbb reg1:ro kills a:cc cost(1, 4). -/* sbi const1:ro kills a:cc cost(2, 7). */ + sbi const1:ro kills a:cc cost(2, 7). shld label:ro cost(3,16). sphl cost(1, 5). sta label:ro cost(3,13). @@ -1817,65 +1817,121 @@ with yields {const2,$1} leaving bne $2 pat bra -with STACK -gen jmp {label,$1} + with STACK + gen + jmp {label,$1} pat blt -with hl_or_de hl_or_de STACK -uses areg -gen mov a,%2.2 - sub %1.2 - mov a,%2.1 - sbb %1.1 - jm {label,$1} - -pat ble -with hl_or_de hl_or_de STACK -uses areg -gen mov a,%1.2 - sub %2.2 - mov a,%1.1 - sbb %2.1 - jp {label,$1} - -pat beq -with hl_or_de hl_or_de STACK -uses areg -gen mov a,%2.2 - cmp %1.2 - jnz {label,1f} - mov a,%2.1 - cmp %1.1 - jz {label,$1} - 1: - -pat bne -with hl_or_de hl_or_de STACK -uses areg -gen mov a,%2.2 - cmp %1.2 - jnz {label,$1} - mov a,%2.1 - cmp %1.1 - jnz {label,$1} - -pat bge -with hl_or_de hl_or_de STACK -uses areg -gen mov a,%2.2 - sub %1.2 - mov a,%2.1 - sbb %1.1 - jp {label,$1} + with const2 hl_or_de STACK + uses areg + gen + mov a, %2.2 + sui {const1, %1.num & 0xff} + mov a, %2.1 + sbi {const1, %1.num >> 8} + jm {label, $1} + with hl_or_de const2 STACK + uses areg + gen + mvi a, {const1, %2.num & 0xff} + sub %1.2 + mvi a, {const1, %2.num >> 8} + sbb %1.1 + jm {label, $1} + with hl_or_de hl_or_de STACK + uses areg + gen + mov a,%2.2 + sub %1.2 + mov a,%2.1 + sbb %1.1 + jm {label,$1} pat bgt -with hl_or_de hl_or_de STACK -uses areg -gen mov a,%1.2 - sub %2.2 - mov a,%1.1 - sbb %2.1 - jm {label,$1} + leaving + exg 2 + blt $1 + +pat bge + with const2 hl_or_de STACK + uses areg + gen + mov a, %2.2 + sui {const1, %1.num & 0xff} + mov a, %2.1 + sbi {const1, %1.num >> 8} + jp {label, $1} + with hl_or_de const2 STACK + uses areg + gen + mvi a, {const1, %2.num & 0xff} + sub %1.2 + mvi a, {const1, %2.num >> 8} + sbb %1.1 + jp {label, $1} + with hl_or_de hl_or_de STACK + uses areg + gen + mov a,%2.2 + sub %1.2 + mov a,%2.1 + sbb %1.1 + jp {label,$1} + +pat ble + leaving + exg 2 + bge $1 + +pat beq + with const2 hl_or_de STACK + uses areg + gen + mov a, %2.2 + cpi {const1, %1.num & 0xff} + jnz {label, 1f} + mov a, %2.1 + cpi {const1, %1.num >> 8} + jz {label, $1} + 1: + with hl_or_de const2 STACK + leaving + exg 2 + beq $1 + with hl_or_de hl_or_de STACK + uses areg + gen + mov a,%2.2 + cmp %1.2 + jnz {label,1f} + mov a,%2.1 + cmp %1.1 + jz {label,$1} + 1: + +pat bne + with const2 hl_or_de STACK + uses areg + gen + mov a, %2.2 + cpi {const1, %1.num & 0xff} + jnz {label, $1} + mov a, %2.1 + cpi {const1, %1.num >> 8} + jnz {label, $1} + with hl_or_de const2 STACK + leaving + exg 2 + beq $1 + with hl_or_de hl_or_de STACK + uses areg + gen + mov a,%2.2 + cmp %1.2 + jnz {label,$1} + mov a,%2.1 + cmp %1.1 + jnz {label,$1} pat zlt with STACK diff --git a/mach/i80/top/table b/mach/i80/top/table index e6c4af727..e77100735 100644 --- a/mach/i80/top/table +++ b/mach/i80/top/table @@ -13,4 +13,6 @@ mvi X, Y : mov X, Z -> mov X, Z ; xchg : inx h : xchg -> inx d ; xchg : inx d : xchg -> inx h ; +cpi 0 -> ora a ; + %%; From fca54ccc1b743fcc92eae5f9b8436630b9874ce0 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 10 Feb 2019 19:40:48 +0100 Subject: [PATCH 17/17] Improve subtractions, using dad and inline constants where possible. Shrinks Star Trek from 39740 to 39656 bytes. --- mach/i80/ncg/table | 87 +++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 28 deletions(-) diff --git a/mach/i80/ncg/table b/mach/i80/ncg/table index 67c8cb7e9..00587bcbf 100644 --- a/mach/i80/ncg/table +++ b/mach/i80/ncg/table @@ -623,37 +623,68 @@ pat sde /****************************************/ pat adi $1==2 -with hlreg dereg - gen dad de yields hl -with dereg hlreg - gen dad de yields hl -with hlreg hlreg - gen dad hl yields hl -with dereg dereg - gen xchg. - dad hl yields hl + with hlreg dereg + gen + dad de + yields hl + with dereg hlreg + gen + dad de + yields hl + with hlreg hlreg + gen + dad hl + yields hl + with dereg dereg + gen + xchg. + dad hl + yields hl pat adi $1==4 -kills ALL -gen Call {label,".adi4"} + kills ALL + gen + Call {label,".adi4"} pat sbi $1==2 -with hl_or_de hl_or_de -uses areg -gen mov a,%2.2 - sub %1.2 - mov %1.2,a - mov a,%2.1 - sbb %1.1 - mov %1.1,a yields %1 -with hl_or_de hl_or_de -uses areg -gen mov a,%2.2 - sub %1.2 - mov %2.2,a - mov a,%2.1 - sbb %1.1 - mov %2.1,a yields %2 + with const2 hl_or_de + yields %2 {const2, 0-%1.num} + leaving + adi 2 + with smallconst2 hl_or_de + yields %2 {smallconst2, 0-%1.num} + leaving + adi 2 + with hl_or_de const2 + uses areg + gen + mvi a, {const1, %2.num & 0xff} + sub %1.2 + mov %1.2, a + mvi a, {const1, %2.num >> 8} + sbb %1.1 + mov %1.1, a + yields %1 + with hl_or_de hl_or_de + uses areg + gen + mov a,%2.2 + sub %1.2 + mov %1.2,a + mov a,%2.1 + sbb %1.1 + mov %1.1,a + yields %1 + with hl_or_de hl_or_de + uses areg + gen + mov a,%2.2 + sub %1.2 + mov %2.2,a + mov a,%2.1 + sbb %1.1 + mov %2.1,a + yields %2 pat sbi $1==4 kills ALL @@ -1851,7 +1882,7 @@ pat bgt leaving exg 2 blt $1 - + pat bge with const2 hl_or_de STACK uses areg