From c5f5bace63c03b0eeb51cc35bd26c1dc38f135f9 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 17:08:45 +0800 Subject: [PATCH 01/84] Add additional defines for compilation. --- util/led/archive.c | 21 ++++++--- util/led/build.lua | 6 ++- util/led/const.h | 5 +++ util/led/debug.h | 6 +++ util/led/defs.h | 6 +++ util/led/error.c | 20 ++++----- util/led/extract.c | 43 ++++++++----------- util/led/finish.c | 56 +++++++++++------------- util/led/mach.h | 7 ++- util/led/main.c | 102 +++++++++++++++++--------------------------- util/led/memory.c | 5 ++- util/led/memory.h | 8 ++++ util/led/orig.h | 4 ++ util/led/output.c | 16 ++++--- util/led/read.c | 3 +- util/led/relocate.c | 9 ++-- util/led/save.c | 32 +++++++------- util/led/scan.c | 49 +++++++-------------- util/led/scan.h | 14 ++++++ util/led/sym.c | 20 +++------ util/led/sym.h | 26 +++++++++-- util/led/write.c | 29 ++++++------- 22 files changed, 250 insertions(+), 237 deletions(-) diff --git a/util/led/archive.c b/util/led/archive.c index 1b48dc087..e170c2dee 100644 --- a/util/led/archive.c +++ b/util/led/archive.c @@ -13,15 +13,24 @@ static char rcsid[] = "$Id$"; #include "arch.h" #include "out.h" #include "ranlib.h" +#include "object.h" #include "const.h" #include "debug.h" +#include "finish.h" +#include "extract.h" #include "defs.h" #include "memory.h" +#include "scan.h" +#include "error.h" +#include "save.h" #define ENDLIB ((long)0) static struct ar_hdr arhdr; + +void notelib(long pos); + /* * First read a long telling how many ranlib structs there are, then * the structs themselves. Second read a long telling how many chars there are @@ -29,15 +38,14 @@ static struct ar_hdr arhdr; * We keep only one ranlib table in core, so this table always starts at offset * (ind_t)0 from its base. */ -static long -getsymdeftable() +static long getsymdeftable(void) { register ind_t off; register struct ranlib *ran; register long count; register long nran, nchar; extern long rd_long(); - extern int infile; + extern FILE* infile; count = nran = rd_long(infile); debug("%ld ranlib structs, ", nran, 0, 0, 0); @@ -81,7 +89,7 @@ extern char *modulname; * scan the table again. We perform these actions as long as new symbols * are defined. */ -arch() +void arch(void) { long nran; bool resolved; @@ -143,8 +151,7 @@ arch() * An archive member that will be loaded is remembered by storing its position * in the archive into the table of positions. */ -notelib(pos) - long pos; +void notelib(long pos) { register ind_t off; @@ -165,7 +172,7 @@ static ind_t posindex = (ind_t)0; * that we've processed all needed modules in this archive. Each group of * positions of an archive is terminated with ENDLIB. */ -arch2() +void arch2(void) { register long *pos; register ind_t localpos; diff --git a/util/led/build.lua b/util/led/build.lua index 58b4be5a5..02db10c89 100644 --- a/util/led/build.lua +++ b/util/led/build.lua @@ -2,8 +2,10 @@ cprogram { name = "led", srcs = { "./*.c" }, deps = { - "./const.h", "./debug.h", "./defs.h", "./mach.h", - "./memory.h", "./orig.h", "./scan.h", + "./archive.h", "./const.h", "./debug.h", "./defs.h", + "./error.h", "./extract.h", "./finish.h", "./mach.h", + "./memory.h", "./orig.h", "./output.h", "./relocate.h", + "./save.h", "./scan.h", "./sym.h", "./write.h", "modules/src/string+lib", "modules/src/object+lib", "h+emheaders", diff --git a/util/led/const.h b/util/led/const.h index d2d27f51a..f1e2d77c1 100644 --- a/util/led/const.h +++ b/util/led/const.h @@ -4,6 +4,9 @@ */ /* $Id$ */ +#ifndef __CONST_H_INCLUDED__ +#define __CONST_H_INCLUDED__ + #define FALSE 0 #define TRUE 1 @@ -22,3 +25,5 @@ #define SECOND 2 /* Idem. */ #define BADOFF ((ind_t)-1) + +#endif /* __CONST_H_INCLUDED__ */ diff --git a/util/led/debug.h b/util/led/debug.h index 715409d25..979e0cec8 100644 --- a/util/led/debug.h +++ b/util/led/debug.h @@ -4,6 +4,10 @@ */ /* $Id$ */ +#ifndef __DEBUG_H_INCLUDED__ +#define __DEBUG_H_INCLUDED__ + + #ifdef NDEBUG #define debug(s, a1, a2, a3, a4) @@ -19,3 +23,5 @@ extern int Verbose; #define verbose(s, a1, a2, a3, a4) (Verbose && do_verbose(s, a1, a2, a3, a4)) extern void fatal(char* format, ...); + +#endif /* __DEBUG_H_INCLUDED__ */ diff --git a/util/led/defs.h b/util/led/defs.h index 0bac963ce..222be2707 100644 --- a/util/led/defs.h +++ b/util/led/defs.h @@ -3,6 +3,9 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* $Id$ */ +#ifndef __DEFS_H_INCLUDED__ +#define __DEFS_H_INCLUDED__ + /* * We need the S_EXT because we leave locals alone. @@ -12,3 +15,6 @@ #define ISCOMMON(n) (((n)->on_type & (S_COM | S_EXT)) == (S_COM | S_EXT)) #define mustsavelocal(name) (!((name)->on_type & S_SCT)) + + +#endif /* __DEFS_H_INCLUDED__ */ diff --git a/util/led/error.c b/util/led/error.c index 61dc7983e..bcaa4c329 100644 --- a/util/led/error.c +++ b/util/led/error.c @@ -17,13 +17,13 @@ static char rcsid[] = "$Id$"; static short nerrors = 0; static void diag(char *, char *, va_list); -stop() +void stop(void) { extern char *outputname; extern int exitstatus; if (nerrors) { - unlink(outputname); + remove(outputname); exit(nerrors); } @@ -31,8 +31,7 @@ stop() } /* VARARGS1 */ -void -fatal(char *format, ...) +void fatal(char *format, ...) { va_list ap; va_start(ap, format); @@ -42,8 +41,7 @@ fatal(char *format, ...) } /* VARARGS1 */ -void -warning(char *format, ...) +void warning(char *format, ...) { va_list ap; va_start(ap, format); @@ -52,8 +50,7 @@ warning(char *format, ...) } /* VARARGS1 */ -void -error(char *format, ...) +void error(char *format, ...) { va_list ap; va_start(ap, format); @@ -63,17 +60,16 @@ error(char *format, ...) } /* VARARGS1 */ -void -do_verbose(char *format, ...) +int do_verbose(char *format, ...) { va_list ap; va_start(ap, format); diag((char *) 0, format, ap); va_end(ap); + return 1; } -static void -diag(char *tail, char *format, va_list ap) +static void diag(char *tail, char *format, va_list ap) { extern char *progname, *archname, *modulname; diff --git a/util/led/extract.c b/util/led/extract.c index d979c1982..acfb49a03 100644 --- a/util/led/extract.c +++ b/util/led/extract.c @@ -17,22 +17,27 @@ static char rcsid[] = "$Id$"; #include "memory.h" #include "orig.h" #include "scan.h" +#include "save.h" #include "sym.h" +#include "error.h" + +static void getexternal(register struct outname *); +static void get_names(register struct outhead *); +static void process(register struct outhead *); +static void redefine(register struct outname *, register struct outname *); +static void transfer(register struct outname *, register struct outname *); +static void process(register struct outhead *); -static get_names(); -static process(); -static getexternal(); -static redefine(); -static transfer(); extern ind_t savechar(); +extern struct orig relorig[]; void namerelocate(); /* * Get section sizes and symboltable information from present module. */ -extract() +void extract(void) { struct outhead head; @@ -52,9 +57,7 @@ extract() * appear in the final output file if this module is linked. * That number will be returned. */ -static -get_names(head) - register struct outhead *head; +static void get_names(register struct outhead *head) { register int nnames; register ind_t nameindex, charindex; @@ -106,11 +109,9 @@ get_names(head) } } -extern struct orig relorig[]; -static -process(head) - register struct outhead *head; + +static void process(register struct outhead *head) { register struct outsect *sects; register struct outsect *outsp; @@ -152,9 +153,7 @@ process(head) * Otherwise we just add the accumulated size of all normal parts in preceding * sections with the same size. */ -void -namerelocate(name) - register struct outname *name; +void namerelocate(register struct outname *name) { register int type = name->on_type; register int sct = type & S_TYP; @@ -174,9 +173,7 @@ namerelocate(name) * we might need it later on. Otherwise it must confirm to what we already * know about it, and eventually add to that knowledge. */ -static -getexternal(name) - register struct outname *name; +static void getexternal(register struct outname *name) { register char *string; register int h; @@ -216,9 +213,7 @@ getexternal(name) * greatest value so that the common declared name always has enough space. * If a common is defined as a not-common, the old definition is ignored. */ -static -redefine(new, old) - register struct outname *new, *old; +static void redefine(register struct outname *new, register struct outname *old) { if (!ISCOMMON(old)) { if (!ISCOMMON(new)) @@ -244,9 +239,7 @@ redefine(new, old) /* * Transfer things we want to know from `src' to `dst'. */ -static -transfer(src, dst) - register struct outname *src, *dst; +static void transfer(register struct outname *src, register struct outname *dst) { debug("%s defined here\n", src->on_mptr, 0, 0, 0); dst->on_valu = src->on_valu; diff --git a/util/led/finish.c b/util/led/finish.c index 9735ae440..229d6095c 100644 --- a/util/led/finish.c +++ b/util/led/finish.c @@ -10,21 +10,30 @@ static char rcsid[] = "$Id$"; #include #include #include -#include +#include "out.h" +#include "arch.h" #include "const.h" #include "defs.h" #include "memory.h" #include "orig.h" #include "scan.h" +#include "sym.h" +#include "object.h" +#include "write.h" +#include "relocate.h" +#include "extract.h" +#include "finish.h" +extern bool incore; extern unsigned short NLocals; extern int flagword; extern struct outname *searchname(); +extern void addbase(struct outname *name); -static adjust_names(); -static handle_relos(); -static put_locals(); -static compute_origins(); +static void adjust_names(register struct outname *, struct outhead *, register char *); +static void handle_relos(struct outhead *, struct outsect *, struct outname *); +static void put_locals(struct outname *, register unsigned int); +static void compute_origins(register struct outsect *, register unsigned int); /* * We know all there is to know about the current module. @@ -32,7 +41,7 @@ static compute_origins(); * those to the final output file. Then we compute the relative origins * for the next module. */ -finish() +void finish(void) { struct outhead *head; struct outsect *sects; @@ -59,11 +68,8 @@ finish() /* * Adjust all local names for the move into core. */ -static -adjust_names(name, head, chars) - register struct outname *name; - struct outhead *head; - register char *chars; +static void adjust_names(register struct outname *name, struct outhead *head, register char *chars) + { register int cnt; register long charoff; @@ -81,9 +87,7 @@ adjust_names(name, head, chars) } } -do_crs(base, count) - struct outname *base; - unsigned count; +void do_crs(struct outname *base, unsigned int count) { register struct outname *name = base; @@ -116,16 +120,14 @@ do_crs(base, count) * the relocation table again, because the relocation entries of one section * need not be consecutive. */ -static -handle_relos(head, sects, names) - struct outhead *head; - struct outsect *sects; - struct outname *names; +static void handle_relos(struct outhead *head, struct outsect *sects, struct outname *names) { register struct outrelo *relo; register int sectindex; register int nrelo; register char *emit; + extern char *getemit(); + extern struct outrelo *nextrelo(); static long zeros[MAXSECT]; if (incore) { @@ -166,6 +168,7 @@ handle_relos(head, sects, names) long sz = sects[sectindex].os_flen; long sf = 0; long blksz; + char *getblk(); emit = getblk(sz, &blksz, sectindex); while (sz) { @@ -206,10 +209,8 @@ handle_relos(head, sects, names) /* * Write out the local names that must be saved. */ -static -put_locals(name, nnames) - struct outname *name; - register unsigned nnames; +static void put_locals(struct outname *name, register unsigned int nnames) + { register struct outname *oname = name; register struct outname *iname = oname; @@ -230,10 +231,7 @@ put_locals(name, nnames) * Add all flen's and all (size - flen == zero)'s of preceding sections * with the same number. */ -static -compute_origins(sect, nsect) - register struct outsect *sect; - register unsigned nsect; +static void compute_origins(register struct outsect *sect, register unsigned int nsect) { extern struct orig relorig[]; register struct orig *orig = relorig; @@ -250,9 +248,7 @@ compute_origins(sect, nsect) * Write out what is after the string area. This is likely to be * debugging information. */ -static -put_dbug(offdbug) - long offdbug; +static void put_dbug(long offdbug) { char buf[512]; register int nbytes; diff --git a/util/led/mach.h b/util/led/mach.h index ce914c4f2..e64b79b2a 100644 --- a/util/led/mach.h +++ b/util/led/mach.h @@ -9,8 +9,11 @@ * Values depend on the machine on which this program should run. * Now for Vax 11/750. */ +#ifndef __MACH_H_INCLUDED__ +#define __MACH_H_INCLUDED__ -#include + +#include "local.h" #define K 1024L @@ -49,3 +52,5 @@ mems[ALLOMODL].mem_left = 12 * K; mems[ALLORANL].mem_left = 4 * K; #endif + +#endif /* __MACH_H_INCLUDED__ */ diff --git a/util/led/main.c b/util/led/main.c index 24bff403f..4fcb42900 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -22,8 +22,15 @@ static char rcsid[] = "$Id$"; #include "defs.h" #include "memory.h" #include "orig.h" +#include "scan.h" #include "sym.h" +#include "extract.h" +#include "error.h" +#include "output.h" +#include "finish.h" +#include "archive.h" +extern bool incore; #ifndef NOSTATISTICS int statistics; #endif @@ -32,30 +39,29 @@ int DEB = 0; #endif int Verbose = 0; -static initializations(); -static first_pass(); -static uint32_t number(const char *); +static void initializations(int, char*[]); +static void first_pass(char**); +static uint32_t number(const char *); static void setlign(int, uint32_t); static void setbase(int, uint32_t); -static void enterundef(const char *, int); -static pass1(); -static evaluate(); +static struct outname *makename(char*); +static void pass1(char*); +static void evaluate(void); static void norm_commons(); -static complete_sections(); -static void change_names(); -static bool setbit(); -static bool tstbit(); -static second_pass(); -static pass2(); +static void complete_sections(void); +static void change_names(void); +static void enterundef(const char *, int); +static bool setbit(int, char[]); +static bool tstbit(int, char[]); +static void second_pass(char**); +static void pass2(char*); #ifndef NOSTATISTICS -static do_statistics(); +static void do_statistics(void); #endif -void addbase(); +void addbase(struct outname *); -main(argc, argv) - int argc; - char **argv; +int main(int argc, char **argv) { initializations(argc, argv); first_pass(argv); @@ -71,8 +77,7 @@ main(argc, argv) } #ifndef NOSTATISTICS -static -do_statistics() +static void do_statistics(void) { register struct memory *m = mems; @@ -92,10 +97,7 @@ struct outhead outhead; /* Header of final output file. */ struct outsect outsect[MAXSECT];/* Its section table. */ /* ARGSUSED */ -static -initializations(argc, argv) - int argc; - char *argv[]; +static void initializations(int argc, char *argv[]) { /* * Avoid malloc()s. @@ -123,9 +125,7 @@ int exitstatus = 0; * If the argument starts with a '-', it's a flag, else it is either * a plain file to be loaded, or an archive. */ -static -first_pass(argv) - register char **argv; +static void first_pass(register char **argv) { register char *argp; int sectno; @@ -255,8 +255,7 @@ first_pass(argv) * else if it starts with 0, it's octal, * else it's decimal. */ -static uint32_t -number(const char *s) +static uint32_t number(const char *s) { register int digit; register uint32_t value = 0; @@ -273,7 +272,7 @@ number(const char *s) s++; } } - while (digit = *s++) { + while ((digit = *s++)) { if (digit >= 'A' && digit <= 'F') digit = digit - 'A' + 10; else if (digit >= 'a' && digit <= 'f') @@ -298,13 +297,11 @@ static uint32_t sect_base[MAXSECT]; static char lignmap[MAXSECT / WIDTH]; static uint32_t sect_lign[MAXSECT]; -/* /* * Set the alignment of section `sectno' to `lign', if this doesn't * conflict with earlier alignment. */ -static void -setlign(int sectno, uint32_t lign) +static void setlign(int sectno, uint32_t lign) { extern bool setbit(); @@ -332,8 +329,7 @@ setbase(int sectno, uint32_t base) /* * Do -u name by entering the undefined name in the symbol table. */ -static void -enterundef(const char *string, int hashval) +static void enterundef(const char *string, int hashval) { struct outname namebuf; size_t len; @@ -364,9 +360,7 @@ enterundef(const char *string, int hashval) * extracted. If it is an archive it is examined to see if it defines any * undefined symbols. */ -static -pass1(file) - char *file; +static void pass1(char* file) { if (getfile(file) == PLAIN) { debug("%s: plain file\n", file, 0, 0, 0); @@ -388,8 +382,7 @@ pass1(file) * sections. We then add the section bases to the values of names in * corresponding sections. */ -static -evaluate() +static void evaluate(void) { norm_commons(); complete_sections(); @@ -411,8 +404,7 @@ long sect_comm[MAXSECT]; * just like "normal" names. We also count the total size of common names * within each section to be able to compute the final size in the machine. */ -static void -norm_commons() +static void norm_commons(void) { register struct outname *name; register int cnt; @@ -470,8 +462,7 @@ struct orig relorig[MAXSECT]; * Compute the offsets in file and machine that the sections will have. * Also set the origins to 0. */ -static -complete_sections() +static void complete_sections(void) { register uint32_t base = 0; register uint32_t foff; @@ -508,8 +499,7 @@ complete_sections() * For each name we add the base of its section to its value, unless * the output has to be able to be linked again, as indicated by RFLAG. */ -static void -change_names() +static void change_names(void) { register int cnt; register struct outname *name; @@ -539,10 +529,7 @@ change_names() * This function sets a bit with index `indx' in string. * It returns whether it was already set. */ -bool -setbit(indx, string) - int indx; - char string[]; +bool setbit(int indx, char string[]) { register int byte_index, bit_index; register int byte; @@ -562,10 +549,7 @@ setbit(indx, string) /* * This function returns whether the bit given by `indx' is set in `string'. */ -static bool -tstbit(indx, string) - int indx; - char string[]; +static bool tstbit(int indx, char string[]) { register int byte_index, bit_index; register int byte; @@ -581,9 +565,7 @@ tstbit(indx, string) /* * Add the base of the section of a name to its value. */ -void -addbase(name) - struct outname *name; +void addbase(struct outname *name) { register int type = name->on_type & S_TYP; register int sectindex = type - S_MIN; @@ -607,9 +589,7 @@ addbase(name) /* * Flags have already been processed, so we ignore them here. */ -static -second_pass(argv) - char **argv; +static void second_pass(char **argv) { passnumber = SECOND; while (*++argv) { @@ -628,9 +608,7 @@ second_pass(argv) } } -static -pass2(file) - char *file; +static void pass2(char* file) { if (getfile(file) == PLAIN) { debug("%s: plain file\n", file, 0, 0, 0); diff --git a/util/led/memory.c b/util/led/memory.c index a6dad9608..5e0f53c8d 100644 --- a/util/led/memory.c +++ b/util/led/memory.c @@ -40,6 +40,8 @@ static char rcsid[] = "$Id$"; #include "memory.h" #include "object.h" #include "sym.h" +#include "finish.h" +#include "write.h" #ifndef USEMALLOC static void copy_down(struct memory* mem, ind_t dist); @@ -655,8 +657,7 @@ void core_free(int piece, char* p) * Reset index into piece of memory for modules and * take care that the allocated pieces will not be moved. */ -void -freeze_core() +void freeze_core(void) { register int i; diff --git a/util/led/memory.h b/util/led/memory.h index 95426137f..e887db467 100644 --- a/util/led/memory.h +++ b/util/led/memory.h @@ -4,6 +4,9 @@ */ /* $Id$ */ +#ifndef __MEMORY_H_INCLUDED__ +#define __MEMORY_H_INCLUDED__ + #include #include @@ -35,6 +38,8 @@ struct memory { }; extern struct memory mems[]; +struct outname; + #define address(piece,offset) (mems[(piece)].mem_base+(offset)) #define modulptr(offset) (mems[ALLOMODL].mem_base+core_position+(offset)) @@ -49,4 +54,7 @@ extern void dealloc(int piece); extern char *core_alloc(int piece, size_t size); extern void core_free(int piece, char* p); extern void write_bytes(void); +extern void freeze_core(void); extern void namecpy(struct outname* name, unsigned nname, long offchar); + +#endif /* #ifndef __MEMORY_H_INCLUDED__ */ diff --git a/util/led/orig.h b/util/led/orig.h index 019c419e9..46cfd8d43 100644 --- a/util/led/orig.h +++ b/util/led/orig.h @@ -3,7 +3,11 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* $Id$ */ +#ifndef __ORIG_H_INCLUDED__ +#define __ORIG_H_INCLUDED__ struct orig { long org_size; /* Accumulated length of preceding sections. */ }; + +#endif /* __ORIG_H_INCLUDED__ */ diff --git a/util/led/output.c b/util/led/output.c index b303b24b2..d89743381 100644 --- a/util/led/output.c +++ b/util/led/output.c @@ -10,14 +10,19 @@ static char rcsid[] = "$Id$"; #include #include #include -#include +#include "out.h" +#include "object.h" #include "const.h" +#include "output.h" #include "memory.h" +#include "error.h" +#include "write.h" #include "sym.h" -static void generate_section_names(); +static void generate_section_names(void); extern struct outhead outhead; +extern bool incore; extern int flagword; /* @@ -26,7 +31,7 @@ extern int flagword; * flag was given. * If this flag is given we don't need the string table either. */ -beginoutput() +void beginoutput(void) { extern long NLChars, NGChars; extern char *outputname; @@ -54,8 +59,7 @@ beginoutput() * Generate names for all sections and put them after the global names. * Section names are used for relocation. */ -static void -generate_section_names() +static void generate_section_names(void) { register struct outname *name; register int sectindex; @@ -80,7 +84,7 @@ generate_section_names() * written out, and we just finish that. * If we did, we write out our pieces of core. */ -endoutput() +void endoutput(void) { if (!incore) { if (!(flagword & SFLAG)) diff --git a/util/led/read.c b/util/led/read.c index 3ea15925c..3beda14a4 100644 --- a/util/led/read.c +++ b/util/led/read.c @@ -10,10 +10,11 @@ static char rcsid[] = "$Id$"; #include #include #include +#include "error.h" int infile; /* The current input file. */ -rd_fatal() +void rd_fatal(void) { fatal("read error"); } diff --git a/util/led/relocate.c b/util/led/relocate.c index 9fac60e52..9f7df829d 100644 --- a/util/led/relocate.c +++ b/util/led/relocate.c @@ -17,6 +17,7 @@ static char rcsid[] = "$Id$"; #include "defs.h" #include "orig.h" #include "sym.h" +#include "relocate.h" #define UBYTE(x) ((x)&BYTEMASK) @@ -443,7 +444,7 @@ static void put_mips_valu(char* addr, uint32_t value) * significance should be attributed to each byte. * We do not check for overflow. */ -static putvalu(uint32_t valu, char* addr, uint16_t type) +static void putvalu(uint32_t valu, char* addr, uint16_t type) { switch (type & RELSZ) @@ -547,11 +548,7 @@ long* valu_out; /* Out variable. */ * which the header is pointed to by `head'. Relocation is relative to the * names in `names'; `relo' tells how to relocate. */ -relocate(head, emit, names, relo, off) struct outhead* head; -char* emit; -struct outname names[]; -struct outrelo* relo; -long off; +void relocate(struct outhead *head, char* emit, struct outname names[], struct outrelo *relo, long off) { long valu; int sectindex = relo->or_sect - S_MIN; diff --git a/util/led/save.c b/util/led/save.c index 9f8df53ec..160866b67 100644 --- a/util/led/save.c +++ b/util/led/save.c @@ -17,51 +17,51 @@ static char rcsid[] = "$Id$"; #include #include #include "arch.h" +#include "save.h" #include "out.h" #include "const.h" #include "memory.h" -void -savemagic() +extern bool incore; +extern char *core_alloc(); + +long NLChars = 0; /* Size of string area for local names. */ +long NGChars = 0; /* Idem for global names. */ + +void savemagic(void) { register char *p; if (!incore) return; - if ((p = core_alloc(ALLOMODL, sizeof(int))) != (char *)0) { + if ((p = core_alloc(ALLOMODL, (long)sizeof(int))) != (char *)0) { *(unsigned short *)p = AALMAG; core_position += sizeof(int); } } -void -savehdr(hdr) - struct ar_hdr *hdr; +void savehdr(struct ar_hdr *hdr) { register char *p; if (!incore) return; - if ((p=core_alloc(ALLOMODL, sizeof(struct ar_hdr)))!=(char *)0) { + if ((p=core_alloc(ALLOMODL,(long)sizeof(struct ar_hdr)))!=(char *)0) { *(struct ar_hdr *)p = *hdr; core_position += int_align(sizeof(struct ar_hdr)); } } -long NLChars = 0; /* Size of string area for local names. */ -long NGChars = 0; /* Idem for global names. */ + /* * Put the string in cp into the block allocated for the string area. * Return its offset in this area. We don't use the first char of the string * area, so that empty strings can be distinguished from the first string. */ -ind_t -savechar(piece, off) - register int piece; - register ind_t off; +ind_t savechar(register int piece, register ind_t off) { register size_t len; register ind_t newoff; @@ -90,9 +90,7 @@ savechar(piece, off) * allocation, but the string of which name->on_foff is the offset may be * destroyed, so we save that first. */ -void -savelocal(name) - struct outname *name; +void savelocal(struct outname *name) { ind_t savindex; struct outname *new; @@ -101,7 +99,7 @@ savelocal(name) return; new = (struct outname *) - core_alloc(ALLOLOCL, sizeof(struct outname)); + core_alloc(ALLOLOCL, (long)sizeof(struct outname)); if (new != (struct outname *)0) { *new = *name; new->on_foff = savindex; diff --git a/util/led/scan.c b/util/led/scan.c index db641feb6..dc828fd53 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -35,7 +35,7 @@ static char rcsid[] = "$Id$"; #define IND_DBUG(x) (IND_RELO(x) + sizeof(ind_t)) #endif /* SYMDBUG */ -extern int infile; +extern FILE* infile; extern int passnumber; char *archname; /* Name of archive, if reading from archive. */ @@ -66,9 +66,7 @@ static void scan_modul(void); * In case of a plain file, the file pointer is repositioned after the * examination. Otherwise it is at the beginning of the table of contents. */ -int -getfile(filename) - char *filename; +int getfile(char* filename) { unsigned int rd_unsigned2(); struct ar_hdr archive_header; @@ -81,7 +79,7 @@ getfile(filename) modulname = (char *)0; if (passnumber == FIRST || !incore) { - if ((infile = open(filename, READ)) < 0) + if ((infile = fopen(filename, "rb")) == NULL) fatal("can't read %s", filename); magic_number = rd_unsigned2(infile); } else { @@ -122,7 +120,7 @@ getfile(filename) void closefile(char* filename) { if (passnumber == FIRST || !incore) - close(infile); + fclose(infile); } void get_archive_header(struct ar_hdr* archive_header) @@ -156,8 +154,7 @@ void get_modul(void) * to keep everything in core is abandoned, but we will always put the header, * the section table, and the name and string table into core. */ -static void -scan_modul(void) +static void scan_modul(void) { bool space; struct outhead *head; @@ -188,8 +185,7 @@ scan_modul(void) * If possible, allocate space for the rest of the module. Return whether * this was possible. */ -static bool -all_alloc(void) +static bool all_alloc(void) { struct outhead head; @@ -208,9 +204,7 @@ all_alloc(void) * First allocate the section table and read it in, then allocate the rest * and return whether this succeeded. */ -static bool -direct_alloc(head) - struct outhead *head; +static bool direct_alloc(struct outhead *head) { ind_t sectindex = IND_SECT(*head); register struct outsect *sects; @@ -245,9 +239,7 @@ direct_alloc(head) * Allocate space for the indirectly accessed pieces: the section contents and * the relocation table, and put their indices in the right place. */ -static bool -indirect_alloc(head) - struct outhead *head; +static bool indirect_alloc(struct outhead *head) { register int allopiece; unsigned short nsect = head->oh_nsect; @@ -283,8 +275,7 @@ indirect_alloc(head) * at offset `sectindex'. Put the offset of the allocated piece at offset * `emitoff'. */ -static bool -putemitindex(ind_t sectindex, ind_t emitoff, int allopiece) +static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece) { long flen; ind_t emitindex; @@ -358,8 +349,7 @@ putdbugindex(ind_t dbugoff, size_t ndbugbytes) * Compute addresses and read in. Remember that the contents of the sections * and also the relocation table are accessed indirectly. */ -static void -get_indirect(struct outhead* head, struct outsect* sect) +static void get_indirect(struct outhead* head, struct outsect* sect) { register ind_t *emitindex; register int nsect; @@ -385,7 +375,7 @@ get_indirect(struct outhead* head, struct outsect* sect) void seek(long pos) { if (passnumber == FIRST || !incore) - lseek(infile, pos, 0); + fseek(infile, pos, SEEK_SET); } /* @@ -410,8 +400,7 @@ void skip_modul(struct outhead* head) /* * Read in what we need in pass 2, because we couldn't keep it in core. */ -static void -read_modul(void) +static void read_modul(void) { struct outhead *head; register struct outsect *sects; @@ -544,11 +533,7 @@ struct outrelo* nextrelo(void) * Get the section contents in core of which the describing struct has index * `sectindex'. `Head' points to the header of the module. */ -char * -getemit(head, sects, sectindex) - struct outhead *head; - struct outsect *sects; - int sectindex; +char *getemit(struct outhead *head, struct outsect *sects, int sectindex) { char *ret; ind_t off; @@ -573,11 +558,7 @@ getemit(head, sects, sectindex) return address(ALLOEMIT + sectindex, off); } -char * -getblk(totalsz, pblksz, sectindex) - long totalsz; - long *pblksz; - int sectindex; +char *getblk(long totalsz, long *pblksz, int sectindex) { char *ret; long sz = (1L << 30); @@ -596,7 +577,7 @@ getblk(totalsz, pblksz, sectindex) sz >>= 1; } fatal("no space for section contents"); - return (char *) 0; + return (char *) NULL; } void endemit(char* emit) diff --git a/util/led/scan.h b/util/led/scan.h index 0d8435ff9..e1669991f 100644 --- a/util/led/scan.h +++ b/util/led/scan.h @@ -4,6 +4,11 @@ */ /* $Id$ */ +#ifndef __SCAN_H_INCLUDED__ +#define __SCAN_H_INCLUDED__ + +#include "arch.h" + /* * Offsets of the pieces of the input module in core. */ @@ -26,3 +31,12 @@ extern struct outrelo* nextrelo(void); extern char* getemit(struct outhead* head, struct outsect* sects, int sectindex); extern char* getblk(long totalsz, long* pblksz, int sectindex); extern void endemit(char* emit); +/* + * Open the file with name `filename' (if necessary) and examine the first + * few bytes to see if it's a plain file or an archive. + * In case of a plain file, the file pointer is repositioned after the + * examination. Otherwise it is at the beginning of the table of contents. + */ +int getfile(char* filename); + +#endif /* __SCAN_H_INCLUDED__ */ diff --git a/util/led/sym.c b/util/led/sym.c index 71ca6ee5c..e946a5a17 100644 --- a/util/led/sym.c +++ b/util/led/sym.c @@ -16,6 +16,7 @@ static char rcsid[] = "$Id$"; #include #include "out.h" #include "const.h" +#include "error.h" #include "memory.h" #include "debug.h" #include "sym.h" @@ -41,7 +42,7 @@ unsigned short NGlobals = 0; /* Number of global names. */ /* * Initialize the symbol table. All indices should be noticeably invalid. */ -init_symboltable() +void init_symboltable(void) { register ind_t *rap; @@ -56,10 +57,7 @@ init_symboltable() * in this element of the list is returned. When a match cannot be found, * NIL is returned. */ -struct outname * -searchname(string, hashval) - char *string; - int hashval; +struct outname *searchname(char *string, int hashval) { register char *rcp; register char *namestring; @@ -105,9 +103,9 @@ void entername(struct outname* name, int hashval) debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc); savindex = savechar(ALLOGCHR, (ind_t)name->on_foff); - symindex = hard_alloc(ALLOSYMB, sizeof(struct symbol)); + symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol)); debug("; %ld\n", symindex, 0, 0, 0); - namindex = hard_alloc(ALLOGLOB, sizeof(struct outname)); + namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname)); if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF) fatal("symbol table overflow"); sym = (struct symbol *)address(ALLOSYMB, symindex); @@ -124,9 +122,7 @@ void entername(struct outname* name, int hashval) * Return the index of `name' in the symbol table in the order in which * it was entered. We need a REAL index, not a byte offset. */ -unsigned -indexof(name) - struct outname *name; +unsigned int indexof(struct outname *name) { return name - (struct outname *)address(ALLOGLOB, (ind_t)0); } @@ -136,9 +132,7 @@ indexof(name) * 0 <= hash(p) < NHASH, so it can - and will - be used * as index in a hash table. */ -int -hash(p) - register char *p; +int hash(register char* p) { register unsigned short h = 0; register int c; diff --git a/util/led/sym.h b/util/led/sym.h index 60004c1c3..e65bc6d14 100644 --- a/util/led/sym.h +++ b/util/led/sym.h @@ -1,9 +1,27 @@ -#ifndef SYM_H -#define SYM_H + +#ifndef __SYM_H_INCLUDED__ +#define __SYM_H_INCLUDED__ extern unsigned short NLocals; /* Number of local names to be saved. */ extern unsigned short NGlobals; /* Number of global names. */ -extern void entername(struct outname* name, int hashval); +/** Enter a new name in the symbol table.*/ +void entername(struct outname* name, int hashval); +/** Initialize the symbol table. All indices should be noticeably invalid. */ +void init_symboltable(void); +/** Return the hash value of the string represented in p. */ +int hash(register char* p); +/** Return the index of `name' in the symbol table. */ +unsigned int indexof(struct outname *name); +/* + * Search for `string' in the symboltable. The hash value of `string' is in + * `hashval'. The linked list belonging to the entry of hashval + * in the hash table is followed. If the names match, a pointer to the outname + * in this element of the list is returned. When a match cannot be found, + * NIL is returned. + */ +struct outname *searchname(char *string, int hashval); -#endif + + +#endif /* __SYM_H_INCLUDED__ */ diff --git a/util/led/write.c b/util/led/write.c index cf161b61f..79d8ea508 100644 --- a/util/led/write.c +++ b/util/led/write.c @@ -13,26 +13,32 @@ static char rcsid[] = "$Id$"; #include #include #include "out.h" +#include "object.h" #include "const.h" #include "memory.h" #include "sym.h" +#include "error.h" +#include "write.h" extern struct outhead outhead; extern struct outsect outsect[]; extern int flagword; +extern bool incore; -wr_fatal() +static long off_char; + +void wr_fatal(void) { fatal("write error"); } -static long off_char; + /* * Open the output file according to the chosen strategy. * Write away the header and section table: they will not change anymore. */ -begin_write() +void begin_write(void) { register struct outhead *hd = &outhead; @@ -42,9 +48,7 @@ begin_write() off_char = OFF_CHAR(*hd); } -static struct outname * -sectname(sectindex) - int sectindex; +static struct outname *sectname(int sectindex) { static struct outname namebuf; @@ -59,7 +63,7 @@ sectname(sectindex) /* * Write out the symbol table and the section names. */ -end_write() +void end_write(void) { register struct outname *name; register int sectindex; @@ -77,18 +81,14 @@ end_write() wrt_name(sectname(sectindex), 1); } -wrt_emit(emit, sectindex, cnt) - char *emit; - int sectindex; - long cnt; +void wrt_emit(char *emit, int sectindex, long cnt) { wr_outsect(sectindex); wr_emit(emit, cnt); } -wrt_nulls(sectindex, cnt) - register long cnt; +void wrt_nulls(int sectindex, register long cnt) { static char nullbuf[BUFSIZ]; @@ -100,8 +100,7 @@ wrt_nulls(sectindex, cnt) } } -wrt_name(name, writename) - register struct outname *name; +void wrt_name(register struct outname *name, int writename) { assert(!incore); assert(!(flagword & SFLAG)); From 086a2ac9abc9f55314027b39a2d4523922a99bd0 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 17:09:12 +0800 Subject: [PATCH 02/84] Add additional defines for compilation. --- util/led/error.h | 19 +++++++++++++++++++ util/led/extract.h | 23 +++++++++++++++++++++++ util/led/finish.h | 14 ++++++++++++++ util/led/output.h | 27 +++++++++++++++++++++++++++ util/led/relocate.h | 21 +++++++++++++++++++++ util/led/save.h | 14 ++++++++++++++ util/led/write.h | 21 +++++++++++++++++++++ 7 files changed, 139 insertions(+) create mode 100644 util/led/error.h create mode 100644 util/led/extract.h create mode 100644 util/led/finish.h create mode 100644 util/led/output.h create mode 100644 util/led/relocate.h create mode 100644 util/led/save.h create mode 100644 util/led/write.h diff --git a/util/led/error.h b/util/led/error.h new file mode 100644 index 000000000..8071a9f06 --- /dev/null +++ b/util/led/error.h @@ -0,0 +1,19 @@ +/* + * error.h + * + * Created on: 2018-11-17 + * Author: carl + */ + + +#ifndef __ERROR_H_INCLUDED__ +#define __ERROR_H_INCLUDED__ + +void stop(void); +void fatal(char *format, ...); +void warning(char *format, ...); +void error(char *format, ...); +int do_verbose(char *format, ...); + + +#endif /* __ERROR_H_INCLUDED__ */ diff --git a/util/led/extract.h b/util/led/extract.h new file mode 100644 index 000000000..48c817190 --- /dev/null +++ b/util/led/extract.h @@ -0,0 +1,23 @@ +/* + * extract.h + * + * Created on: 2018-11-17 + * Author: carl + */ + +#ifndef __EXTRACT_H_INCLUDED__ +#define __EXTRACT_H_INCLUDED__ + +#include "out.h" + +void extract(void); +/* + * Add relocation constant for names in user defined sections. + * The value of a common name indicates a size instead of an offset, + * and hence shouldn't be relocated. + * Otherwise we just add the accumulated size of all normal parts in preceding + * sections with the same size. + */ +void namerelocate(register struct outname *name); + +#endif /* __EXTRACT_H_INCLUDED___ */ diff --git a/util/led/finish.h b/util/led/finish.h new file mode 100644 index 000000000..51159fabd --- /dev/null +++ b/util/led/finish.h @@ -0,0 +1,14 @@ +/* + * finish.h + * + * Created on: 2018-11-17 + * Author: Carl Eric Codere + */ + +#ifndef __FINISH_H_INCLUDED__ +#define __FINISH_H_INCLUDED__ + +void finish(void); +void do_crs(struct outname *base, unsigned int count); + +#endif /* __FINISH_H_INCLUDED__ */ diff --git a/util/led/output.h b/util/led/output.h new file mode 100644 index 000000000..19c9a1b3a --- /dev/null +++ b/util/led/output.h @@ -0,0 +1,27 @@ +/* + * output.h + * + * Created on: 2018-11-18 + * Author: carl + */ + +#ifndef __OUTPUT_H_INCLUDED__ +#define __OUTPUT_H_INCLUDED__ + +/* + * We have counted all relocation structs but we know only now if + * these must be emitted.We add all names here,unless the -s(trip) + * flag was given. + * If this flag is given we don't need the string table either. + */ +void beginoutput(void); + +/* + * If we didn't keep the whole output file in core, most of it has been + * written out, and we just finish that. + * If we did, we write out our pieces of core. + */ +void endoutput(void); + + +#endif /* __OUTPUT_H_INCLUDED__ */ diff --git a/util/led/relocate.h b/util/led/relocate.h new file mode 100644 index 000000000..0c76729ac --- /dev/null +++ b/util/led/relocate.h @@ -0,0 +1,21 @@ +/* + * relocate.h + * + * Created on: 2018-11-18 + * Author: carl + */ + +#ifndef __RELOCATE_H_INCLUDED__ +#define __RELOCATE_H_INCLUDED__ + +#include "out.h" + +/* + * This routine relocates a value in a section pointed to by `emit', of + * which the header is pointed to by `head'. Relocation is relative to the + * names in `names'; `relo' tells how to relocate. + */ +void relocate(struct outhead *head, char* emit, struct outname names[], struct outrelo *relo, long off); + + +#endif /* __RELOCATE_H_INCLUDED__ */ diff --git a/util/led/save.h b/util/led/save.h new file mode 100644 index 000000000..54a51715e --- /dev/null +++ b/util/led/save.h @@ -0,0 +1,14 @@ +#ifndef __SAVE_H_INCLUDED__ +#define __SAVE_H_INCLUDED__ + +#include "memory.h" + +struct ar_hdr; +struct outname; + +void savemagic(void); +void savehdr(struct ar_hdr *hdr); +ind_t savechar(int piece, ind_t off); +void savelocal(struct outname *name); + +#endif /* __SAVE_H_INCLUDED__ */ diff --git a/util/led/write.h b/util/led/write.h new file mode 100644 index 000000000..07b337ae6 --- /dev/null +++ b/util/led/write.h @@ -0,0 +1,21 @@ +/* + * write.h + * + * Created on: 2018-11-17 + * Author: carl + */ + +#ifndef __WRITE_H_INCLUDED__ +#define __WRITE_H_INCLUDED__ + +#include "out.h" + +void wr_fatal(void); +void begin_write(void); +void end_write(void); +void wrt_emit(char *emit, int sectindex, long cnt); +void wrt_nulls(int sectindex, long cnt); +void wrt_name(struct outname *name, int writename); + + +#endif /* __WRITE_H_INCLUDED__ */ From 7063301f8cd555bb0fe8fa3e5b1e3323be5e6ccf Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 17:09:29 +0800 Subject: [PATCH 03/84] Add additional defines for compilation. --- util/led/archive.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 util/led/archive.h diff --git a/util/led/archive.h b/util/led/archive.h new file mode 100644 index 000000000..a6e12d265 --- /dev/null +++ b/util/led/archive.h @@ -0,0 +1,37 @@ +/* + * archive.h + * + * Created on: 2018-11-18 + * Author: carl + */ + +#ifndef __ARCHIVE_H_INCLUDED__ +#define __ARCHIVE_H_INCLUDED__ + +/* + * Process archive with table of contents. The table of contents tells + * of symbols in which module they are defined. We scan the table for + * symbols that are known but not yet defined. Then we extract all necessary + * information from the corresponding module. This module may need symbols that + * were defined in modules located before this one in the archive, so we + * scan the table again. We perform these actions as long as new symbols + * are defined. + */ +void arch(void); + +/* + * An archive member that will be loaded is remembered by storing its position + * in the archive into the table of positions. + */ +void notelib(long pos); + +/* + * Process the archive in pass 2. + * We walk through the table of positions telling at what byte offset the + * archive header + module is located, until this position is ENDLIB, meaning + * that we've processed all needed modules in this archive. Each group of + * positions of an archive is terminated with ENDLIB. + */ +void arch2(void); + +#endif /* __ARCHIVE_H_INCLUDED__ */ From 9b6e1774ea0ed8000e94b0ad02d33d289ced4d94 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 17:37:49 +0800 Subject: [PATCH 04/84] ANSI C version More portability fixes. --- util/arch/archiver.c | 1094 ++++++++++++++++++++++++------------------ 1 file changed, 615 insertions(+), 479 deletions(-) diff --git a/util/arch/archiver.c b/util/arch/archiver.c index 2be5fd3ad..73ea4e606 100644 --- a/util/arch/archiver.c +++ b/util/arch/archiver.c @@ -2,91 +2,96 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* ar - archiver Author: Michiel Huisjes */ +/* ar - archiver Author: Michiel Huisjes */ /* Made into arch/aal by Ceriel Jacobs */ -static char RcsId[] = "$Id$"; + /* * Usage: [arch|aal] [qdprtx][vlcu] archive [file] ... - * v: verbose - * x: extract - * q: append - * r: replace (append when not in archive) - * d: delete - * t: print contents of archive - * p: print named files - * l: temporaries in current directory instead of /tmp - * c: don't give "create" message - * u: replace only if dated later than member in archive -#ifdef DISTRIBUTION - * D: make distribution: use distr_time, uid=2, gid=2, mode=0644 -#endif + * possible key + * d: delete + * p: print named files + * q: append + * r: replace (append when not in archive) + * t: print contents of archive + * x: extract + * possible args + * c: don't give "create" message + * u: replace only if dated later than member in archive + * v: verbose + #ifdef DISTRIBUTION + * D: make distribution: use distr_time, uid=2, gid=2, mode=0644 + #endif */ #include +#include #include #include #include #include #include -#include -#include +#include "print.h" +#include "system.h" +#include "object.h" +#include "arch.h" +#include "ranlib.h" + +/* UNIX specific */ +#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) +#ifndef unix +#define unix +#endif +#endif + +#ifdef unix #include +#else +#define getuid() 0 +#define getgid() 0 +#endif + #ifdef AAL -#include -#define MAGIC_NUMBER AALMAG -long offset; +#include "out.h" +#define MAGIC_NUMBER AALMAG +long offset; struct ranlib *tab; -unsigned int tnum = 0; -char *tstrtab; -unsigned int tssiz = 0; +unsigned int tnum = 0; +char *tstrtab; +unsigned int tssiz = 0; unsigned int tabsz, strtabsz; #else -#define MAGIC_NUMBER ARMAG +#define MAGIC_NUMBER ARMAG #endif -#define odd(nr) (nr & 01) -#define even(nr) (odd(nr) ? nr + 1 : nr) +#define odd(nr) (nr & 01) +#define even(nr) (odd(nr) ? nr + 1 : nr) typedef char BOOL; -#define FALSE 0 -#define TRUE 1 +#define FALSE 0 +#define TRUE 1 -#define READ 0 -#define APPEND 2 -#define CREATE 1 +#define READ 0 +#define APPEND 2 +#define CREATE 1 -#define MEMBER struct ar_hdr +#define MEMBER struct ar_hdr -#define NIL_PTR ((char *) 0) -#define NIL_MEM ((MEMBER *) 0) -#define NIL_LONG ((long *) 0) +#define NIL_PTR ((char *) 0) +#define NIL_MEM ((MEMBER *) 0) +#define NIL_LONG ((long *) 0) -#define IO_SIZE (10 * 1024) +#define IO_SIZE (10 * 1024) -#define equal(str1, str2) (!strncmp((str1), (str2), 14)) -#ifndef S_ISDIR -#define S_ISDIR(m) (m & S_IFDIR) /* is a directory */ -#endif - -/* Use Posix names if old-fashioned names are not defined. */ - -#ifndef S_IREAD -#define S_IREAD S_IRUSR -#endif -#ifndef S_IWRITE -#define S_IWRITE S_IWUSR -#endif -#ifndef S_IEXEC -#define S_IEXEC S_IXUSR -#endif +#define equal(str1, str2) (!strncmp((str1), (str2), AR_NAME_MAX)) BOOL verbose; BOOL app_fl; BOOL ex_fl; BOOL show_fl; +/* print files found in archive. */ BOOL pr_fl; BOOL u_fl; BOOL rep_fl; @@ -95,536 +100,658 @@ BOOL nocr_fl; BOOL local_fl; #ifdef DISTRIBUTION BOOL distr_fl; -long distr_time; +time_t distr_time; #endif -int ar_fd; +#ifndef S_ISUID +#define S_ISUID 0 +#endif +#ifndef S_ISGID +#define S_ISGID 0 +#endif + +#define MODE_COUNT 11 char io_buffer[IO_SIZE]; char *progname; -char temp_buf[32]; +char temp_buf[L_tmpnam]; char *temp_arch = &temp_buf[0]; -extern char *ctime(); -void do_object(int f, long size); -void write_symdef(); -void add(); +void do_object(FILE* f, long size); +void do_names(struct outhead *headp); +void enter_name(struct outname *namep); +void write_symdef(FILE *ar); -usage() +void error(BOOL quit, char *str1, char *str2); +FILE* open_archive(char *name, int mode); +void +catch(int param); +MEMBER *get_member(FILE*); +void get(int argc, char *argv[]); +void add(char *name, FILE* ar, FILE* dst, char *mess); +void extract(FILE* ar, MEMBER *member); +void copy_member(MEMBER *member, FILE* from, FILE* to, BOOL extracting); +char *get_mode(int mode); +void wr_fatal(void); +void rd_fatal(void); +void mwrite(FILE* f, void* address, size_t bytes); +void show(char *s, char *name); + +/* Conversion utilities. */ +static mode_t ar2mode(short mode); +static short mode2ar(mode_t mode); + +/** Maps an AR mode to the current system mode. */ +struct modemap { - error(TRUE, "usage: %s [qdprtxl][vlc] archive [file] ...\n", - progname - ); + short ar_mode; + mode_t mode; +}; + +/** Mapping table to map an AR mode to a system mode. */ +static const struct modemap armodes[MODE_COUNT] = +{ +{ AR_IRUSR, S_IRUSR }, +{ AR_IWUSR, S_IWUSR }, +{ AR_IXUSR, S_IXUSR }, + +{ AR_IRGRP, S_IRGRP }, +{ AR_IWGRP, S_IWGRP }, +{ AR_IXGRP, S_IXGRP }, + +{ AR_IROTH, S_IROTH }, +{ AR_IWOTH, S_IWOTH }, +{ AR_IXOTH, S_IXOTH }, + +{ AR_ISUID, S_ISUID }, +{ AR_ISGID, S_ISGID } }; + +/** Convert an "ar" mode to a system specific + * mode. + */ +static mode_t ar2mode(short mode) +{ + int i; + mode_t result = 0; + for (i = 0; i < MODE_COUNT; i++) + { + if (mode & armodes[i].ar_mode) + { + result = result | armodes[i].mode; + } + } + return result; +} + +/** Convert a system specified mode to + * an ar compatible mode. + */ +static short mode2ar(mode_t mode) +{ + int i; + short result = 0; + for (i = 0; i < MODE_COUNT; i++) + { + if (mode & armodes[i].mode) + { + result = result | armodes[i].ar_mode; + } + } + return result; +} + +static void usage(void) +{ + error(TRUE, "usage: %s [qdprtxl][vc] archive [file] ...\n", progname); } /*VARARGS2*/ -error(quit, str1, str2, str3, str4) -BOOL quit; -char *str1, *str2, *str3, *str4; +void error(BOOL quit, char *str1, char *str2) { char errbuf[256]; - sprint(errbuf, str1, str2, str3, str4); - write(2, errbuf, strlen(errbuf)); - if (quit) { - unlink(temp_arch); - _exit(1); - } -} - -char *basename(path) -char *path; -{ - register char *ptr = path; - register char *last = NIL_PTR; - - while (*ptr != '\0') { - if (*ptr == '/') - last = ptr; - ptr++; - } - if (last == NIL_PTR) - return path; - if (*(last + 1) == '\0') { - *last = '\0'; - return basename(path); - } - return last + 1; -} - -extern unsigned int rd_unsigned2(); - -open_archive(name, mode) -register char *name; -register int mode; -{ - unsigned short magic = 0; - int fd; - - if (mode == CREATE) { - if ((fd = creat(name, 0666)) < 0) - error(TRUE, "cannot creat %s\n", name); - magic = MAGIC_NUMBER; - wr_int2(fd, magic); - return fd; - } - - if ((fd = open(name, mode)) < 0) { - if (mode == APPEND) { - close(open_archive(name, CREATE)); - if (!nocr_fl) error(FALSE, "%s: creating %s\n", progname, name); - return open_archive(name, APPEND); + sprint(errbuf, str1, str2); + fwrite(errbuf, strlen(errbuf), 1, stderr); + if (quit) + { + remove(temp_arch); + exit(1); } - error(TRUE, "cannot open %s\n", name); - } - lseek(fd, 0L, 0); - magic = rd_unsigned2(fd); - if (magic != AALMAG && magic != ARMAG) - error(TRUE, "%s is not in ar format\n", name); +} - return fd; +/** Opens the specified archive. */ +FILE* open_archive(char *name, int mode) +{ + unsigned short magic = 0; + FILE* file = NULL; + + if (mode == CREATE) + { + file = fopen(name, "wb+"); + if (file == NULL) + error(TRUE, "cannot create %s\n", name); + magic = MAGIC_NUMBER; + wr_int2(file, magic); + return file; + } + + file = fopen(name, "rb"); + if (file == NULL) + { + /* mode APPEND and files does not exist. */ + if (mode == APPEND) + { + fclose(open_archive(name, CREATE)); + if (!nocr_fl) + error(FALSE, "creating %s\n", name); + return open_archive(name, APPEND); + } + error(TRUE, "cannot open %s\n", name); + } + else + /* file already exists, simply open it for appending */ + { + if (mode == APPEND) + { + fclose(file); + file = fopen(name, "a+b"); + } + } + fseek(file, 0, SEEK_SET); + magic = rd_unsigned2(file); + if (magic != AALMAG && magic != ARMAG) + error(TRUE, "%s is not in ar format\n", name); + + return file; } void -catch() +catch(int param) { - unlink(temp_arch); - _exit (2); + remove(temp_arch); + exit(2); } -main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { - register char *ptr; - int needs_arg = 0; + register char *ptr; + int needs_arg = 0; - progname = argv[0]; + progname = argv[0]; - if (argc < 3) - usage(); + if (argc < 3) + usage(); - for (ptr = argv[1]; *ptr; ptr++) { - switch (*ptr) { - case 't' : + for (ptr = argv[1]; *ptr; ptr++) + { + switch (*ptr) + { + case 't': show_fl = TRUE; break; - case 'v' : + case 'v': verbose = TRUE; break; - case 'x' : + case 'x': ex_fl = TRUE; break; - case 'q' : + case 'q': needs_arg = 1; app_fl = TRUE; break; - case 'c' : + case 'c': nocr_fl = TRUE; break; case 'u': u_fl = TRUE; break; - case 'p' : + case 'p': needs_arg = 1; pr_fl = TRUE; break; - case 'd' : + case 'd': needs_arg = 1; del_fl = TRUE; break; - case 'r' : + case 'r': needs_arg = 1; rep_fl = TRUE; break; - case 'l' : - local_fl = TRUE; - break; #ifdef DISTRIBUTION - case 'D' : + case 'D' : distr_fl = TRUE; break; #endif - default : + default: usage(); + } } - } - if (needs_arg && argc <= 3) - usage(); + if (needs_arg && argc <= 3) + usage(); #ifdef DISTRIBUTION - if (distr_fl) { - static struct stat statbuf; + if (distr_fl) + { + static struct stat statbuf; - stat(progname, &statbuf); - distr_time = statbuf.st_mtime; - } + stat(progname, &statbuf); + distr_time = statbuf.st_mtime; + } #endif - if (local_fl) strcpy(temp_arch, "ar.XXXXXX"); - else strcpy(temp_arch, "/tmp/ar.XXXXXX"); + if (sys_tmpnam(temp_arch) == NULL) + { + error(TRUE, "Cannot create a temporary filename\n", NULL); + } - if (app_fl + ex_fl + del_fl + rep_fl + show_fl + pr_fl != 1) - usage(); + if (app_fl + ex_fl + del_fl + rep_fl + show_fl + pr_fl != 1) + usage(); - if (u_fl && ! rep_fl) - usage(); + if (u_fl && !rep_fl) + usage(); - if (rep_fl || del_fl + if (rep_fl || del_fl #ifdef AAL - || app_fl + || app_fl #endif - ) { - close(mkstemp(temp_arch)); - } + ) + { + /*fclose(mkstemp(temp_arch));*/ + } #ifdef AAL - tab = (struct ranlib *) malloc(512 * sizeof(struct ranlib)); - tstrtab = malloc(4096); - if (!tab || !tstrtab) error(TRUE,"Out of core\n"); - tabsz = 512; - strtabsz = 4096; + tab = (struct ranlib *) malloc(512 * sizeof(struct ranlib)); + tstrtab = malloc(4096); + if (!tab || !tstrtab) + error(TRUE, "Out of core\n", NULL); + tabsz = 512; + strtabsz = 4096; #endif - signal(SIGINT, catch); - get(argc, argv); + signal(SIGINT, + catch); + get(argc, argv); - return 0; + return 0; } -MEMBER * -get_member() +/* Read next member of in the archive file "f". */ +MEMBER *get_member(FILE *f) { - static MEMBER member; + static MEMBER member; -again: - if (rd_arhdr(ar_fd, &member) == 0) + again: + if (rd_arhdr(f, &member) == 0) return NIL_MEM; - if (member.ar_size < 0) { - error(TRUE, "archive has member with negative size\n"); - } - if (equal(SYMDEF, member.ar_name)) { - lseek(ar_fd, member.ar_size, 1); - goto again; - } - return &member; + if (member.ar_size < 0) + { + error(TRUE, "archive has member with negative size\n",NULL); + } + if (equal(SYMDEF, member.ar_name)) + { + fseek(f, member.ar_size, SEEK_CUR); + goto again; + } + return &member; } -char *get_mode(); - -get(argc, argv) -int argc; -register char *argv[]; +void get(int argc, char *argv[]) { - register MEMBER *member; - int i = 0; - int temp_fd, read_chars; + register MEMBER *member; + FILE *ar_f; + int i = 0; + char buffer[FILENAME_MAX]; + size_t read_chars; + FILE* temp_fd; - ar_fd = open_archive(argv[2], (show_fl || pr_fl || ex_fl) ? READ : APPEND); - if (rep_fl || del_fl + ar_f = open_archive(argv[2], (show_fl || pr_fl || ex_fl) ? READ : APPEND); + if (rep_fl || del_fl #ifdef AAL - || app_fl + || app_fl #endif - ) + ) temp_fd = open_archive(temp_arch, CREATE); - while ((member = get_member()) != NIL_MEM) { - if (argc > 3) { - for (i = 3; i < argc; i++) { - if (equal(basename(argv[i]), member->ar_name)) + while ((member = get_member(ar_f)) != NIL_MEM) + { + if (argc > 3) + { + for (i = 3; i < argc; i++) + { + sys_basename(argv[i],buffer); + if (equal(buffer, member->ar_name)) break; - } - if (i == argc || app_fl) { - if (rep_fl || del_fl -#ifdef AAL - || app_fl -#endif - ) { -#ifdef AAL - if (i != argc) { - print("%s: already in archive\n", argv[i]); - argv[i] = ""; - } -#endif - wr_arhdr(temp_fd, member); - copy_member(member, ar_fd, temp_fd, 0); } - else { + if (i == argc || app_fl) + { + if (rep_fl || del_fl +#ifdef AAL + || app_fl +#endif + ) + { +#ifdef AAL + if (i != argc) + { + print("%s: already in archive\n", argv[i]); + argv[i] = ""; + } +#endif + wr_arhdr(temp_fd, member); + copy_member(member, ar_f, temp_fd, FALSE); + } + else + { #ifndef AAL - if (app_fl && i != argc) { - print("%s: already in archive\n", argv[i]); - argv[i] = ""; - } + if (app_fl && i != argc) + { + print("%s: already in archive\n", argv[i]); + argv[i] = ""; + } #endif - lseek(ar_fd, even(member->ar_size),1); + fseek(ar_f, even(member->ar_size),SEEK_CUR); + } + continue; } - continue; } - } - if (ex_fl || pr_fl) - extract(member); - else { - if (rep_fl) - add(argv[i], temp_fd, "r - %s\n"); - else if (show_fl) { - char buf[sizeof(member->ar_name) + 2]; - register char *p = buf, *q = member->ar_name; + if (ex_fl || pr_fl) + extract(ar_f,member); + else + { + if (rep_fl) + add(argv[i], ar_f, temp_fd, "r - %s\n"); + else if (show_fl) + { + char buf[sizeof(member->ar_name) + 2]; + register char *p = buf, *q = member->ar_name; - while (q <= &member->ar_name[sizeof(member->ar_name)-1] && *q) { - *p++ = *q++; + while (q <= &member->ar_name[sizeof(member->ar_name)-1] && *q) + { + *p++ = *q++; + } + *p++ = '\n'; + *p = '\0'; + if (verbose) + { + char *mode = get_mode(member->ar_mode); + char *date = ctime(&(member->ar_date)); + + *(date + 16) = '\0'; + *(date + 24) = '\0'; + + print("%s%3u/%u%7ld %s %s %s", + mode, + (unsigned) (member->ar_uid & 0377), + (unsigned) (member->ar_gid & 0377), + member->ar_size, + date+4, + date+20, + buf); + } + else print(buf); } - *p++ = '\n'; - *p = '\0'; - if (verbose) { - char *mode = get_mode(member->ar_mode); - char *date = ctime(&(member->ar_date)); - - *(date + 16) = '\0'; - *(date + 24) = '\0'; - - print("%s%3u/%u%7ld %s %s %s", - mode, - (unsigned) (member->ar_uid & 0377), - (unsigned) (member->ar_gid & 0377), - member->ar_size, - date+4, - date+20, - buf); + else if (del_fl) + { + show("d - %s\n", member->ar_name); } - else print(buf); + fseek(ar_f, even(member->ar_size), SEEK_CUR); } - else if (del_fl) - show("d - %s\n", member->ar_name); - lseek(ar_fd, even(member->ar_size), 1); + argv[i] = ""; } - argv[i] = ""; - } - if (argc > 3) { - for (i = 3; i < argc; i++) - if (argv[i][0] != '\0') { + if (argc > 3) + { + for (i = 3; i < argc; i++) + if (argv[i][0] != '\0') + { #ifndef AAL if (app_fl) - add(argv[i], ar_fd, "a - %s\n"); + add(argv[i], ar_f, "a - %s\n"); else #endif if (rep_fl #ifdef AAL - || app_fl + || app_fl #endif ) - add(argv[i], temp_fd, "a - %s\n"); - else { + add(argv[i], ar_f, temp_fd, "a - %s\n"); + else + { print("%s: not found\n", argv[i]); } } - } + } - if (rep_fl || del_fl + if (rep_fl || del_fl #ifdef AAL - || app_fl + || app_fl #endif - ) { - signal(SIGINT, SIG_IGN); - close(ar_fd); - close(temp_fd); - ar_fd = open_archive(argv[2], CREATE); - temp_fd = open_archive(temp_arch, APPEND); + ) + { + signal(SIGINT, SIG_IGN); + fclose(ar_f); + fclose(temp_fd); + ar_f = open_archive(argv[2], CREATE); + temp_fd = open_archive(temp_arch, APPEND); #ifdef AAL - write_symdef(); + write_symdef(ar_f); #endif - while ((read_chars = read(temp_fd, io_buffer, IO_SIZE)) > 0) - mwrite(ar_fd, io_buffer, read_chars); - close(temp_fd); - unlink(temp_arch); - } - close(ar_fd); + while ((read_chars = fread(io_buffer, 1, IO_SIZE, temp_fd)) > 0) + mwrite(ar_f, io_buffer, read_chars); + fclose(temp_fd); + remove(temp_arch); + } + fclose(ar_f); } -void -add(name, fd, mess) -char *name; -int fd; -char *mess; +/** Add an entry into the archive. + * + * @param[in] name path specification of the file to add. + * @param[in] ar Original ar file for update. + * @param[in] dst Archive name that will have its file added. + * + */ +void add(char *name, FILE* ar, FILE* dst, char *mess) { - static MEMBER member; - register int read_chars; - struct stat status; - int src_fd; + static MEMBER member; + size_t read_chars; + struct stat status; + char buffer[FILENAME_MAX]; + FILE* src_fd = NULL; - if (stat(name, &status) < 0) { - error(FALSE, "cannot find %s\n", name); - return; - } - else if (S_ISDIR(status.st_mode)) { - error(FALSE, "%s is a directory (ignored)\n", name); - return; - } - else if (u_fl && status.st_mtime <= member.ar_date) { - wr_arhdr(fd, member); - copy_member(member, ar_fd, fd, 0); - return; - } - else if ((src_fd = open(name, 0)) < 0) { - error(FALSE, "cannot open %s\n", name); - return; - } + if (stat(name, &status) < 0) + { + error(FALSE, "cannot find %s\n", name); + return; + } + else if (S_ISDIR(status.st_mode)) + { + error(FALSE, "%s is a directory (ignored)\n", name); + return; + } + else if (u_fl && status.st_mtime <= member.ar_date) + { + wr_arhdr(dst, &member); + copy_member(&member, ar, dst, FALSE); + return; + } + else if ((src_fd = fopen(name, "rb")) == NULL) + { + error(FALSE, "cannot open %s\n", name); + return; + } - strncpy (member.ar_name, basename (name), sizeof(member.ar_name)); - member.ar_uid = status.st_uid; - member.ar_gid = status.st_gid; - member.ar_mode = status.st_mode; - member.ar_date = status.st_mtime; - member.ar_size = status.st_size; + sys_basename(name, buffer); + strncpy (member.ar_name, buffer, sizeof(member.ar_name)); + member.ar_uid = status.st_uid; + member.ar_gid = status.st_gid; + member.ar_mode = mode2ar(status.st_mode); + member.ar_date = status.st_mtime; + member.ar_size = status.st_size; #ifdef DISTRIBUTION - if (distr_fl) { - member.ar_uid = 2; - member.ar_gid = 2; - member.ar_mode = 0644; - member.ar_date = distr_time; - } + if (distr_fl) + { + member.ar_uid = 2; + member.ar_gid = 2; + member.ar_mode = AR_IUSR | AR_IWUSR | AR_IRGRP | AR_IROTH; + member.ar_date = distr_time; + } #endif - wr_arhdr(fd, &member); + wr_arhdr(dst, &member); #ifdef AAL - do_object(src_fd, member.ar_size); - lseek(src_fd, 0L, 0); - offset += AR_TOTAL + even(member.ar_size); + do_object(src_fd, member.ar_size); + fseek(src_fd, 0L, SEEK_SET); + offset += AR_TOTAL + even(member.ar_size); #endif - while (status.st_size > 0) { - int x = IO_SIZE; + while (status.st_size > 0) + { + size_t x = IO_SIZE; - read_chars = x; - if (status.st_size < x) { - x = status.st_size; read_chars = x; - status.st_size = 0; - x = even(x); + if (status.st_size < x) + { + x = status.st_size; + read_chars = x; + status.st_size = 0; + x = even(x); + } + else status.st_size -= x; + if (fread(io_buffer, 1, read_chars, src_fd) != read_chars) + { + error(FALSE,"%s seems to shrink\n", name); + break; + } + mwrite(dst, io_buffer, x); } - else status.st_size -= x; - if (read(src_fd, io_buffer, read_chars) != read_chars) { - error(FALSE,"%s seems to shrink\n", name); - break; - } - mwrite(fd, io_buffer, x); - } - if (verbose) - show(mess, member.ar_name); - close(src_fd); + if (verbose) + show(mess, member.ar_name); + fclose(src_fd); } -extract(member) -register MEMBER *member; +/** Extract an archive entry pointed to by member to + * either standard output or to a file. + * + */ +void extract(FILE* ar, MEMBER *member) { - int fd = 1; - char buf[sizeof(member->ar_name) + 1]; + FILE* file = stdout; + char buf[sizeof(member->ar_name) + 1]; - strncpy(buf, member->ar_name, sizeof(member->ar_name)); - buf[sizeof(member->ar_name)] = 0; - if (pr_fl == FALSE && (fd = creat(buf, 0666)) < 0) { - error(FALSE, "cannot create %s\n", buf); - fd = -1; - } + strncpy(buf, member->ar_name, sizeof(member->ar_name)); + buf[sizeof(member->ar_name)] = 0; + if (pr_fl == FALSE) + { + file = fopen(buf, "wb"); + if (file == NULL) + { + error(FALSE, "cannot create %s\n", buf); + file = NULL; + } + }; - if (verbose) { - if (pr_fl == FALSE) show("x - %s\n", buf); - else show("\n<%s>\n\n", buf); - } + if (verbose) + { + if (pr_fl == FALSE) + show("x - %s\n", buf); + else + show("\n<%s>\n\n", buf); + } - copy_member(member, ar_fd, fd, 1); + copy_member(member, ar, file, TRUE); - if (fd >= 0 && fd != 1) - close(fd); - if (pr_fl == FALSE) chmod(buf, member->ar_mode); + if (file != NULL) + fclose(file); + if (pr_fl == FALSE) + chmod(buf, ar2mode(member->ar_mode)); } -copy_member(member, from, to, extracting) -register MEMBER *member; -int from, to; +void copy_member(MEMBER *member, FILE* from, FILE* to, BOOL extracting) { - register int rest; - long mem_size = member->ar_size; - BOOL is_odd = odd(mem_size) ? TRUE : FALSE; + size_t rest; + long mem_size = member->ar_size; + BOOL is_odd = odd(mem_size) ? TRUE : FALSE; #ifdef AAL - if (! extracting) { - long pos = lseek(from, 0L, 1); + if (!extracting) + { + long pos = ftell(from); - do_object(from, mem_size); - offset += AR_TOTAL + even(mem_size); - lseek(from, pos, 0); - } -#endif - do { - rest = mem_size > (long) IO_SIZE ? IO_SIZE : (int) mem_size; - if (read(from, io_buffer, rest) != rest) { - char buf[sizeof(member->ar_name) + 1]; - - strncpy(buf, member->ar_name, sizeof(member->ar_name)); - buf[sizeof(member->ar_name)] = 0; - error(TRUE, "read error on %s\n", buf); + do_object(from, mem_size); + offset += AR_TOTAL + even(mem_size); + fseek(from, pos, SEEK_SET); } - if (to >= 0) mwrite(to, io_buffer, rest); - mem_size -= (long) rest; - } while (mem_size > 0L); +#endif + do + { + rest = mem_size > (size_t) IO_SIZE ? IO_SIZE : (size_t) mem_size; + if (fread(io_buffer, 1, rest, from) != rest) + { + char buf[sizeof(member->ar_name) + 1]; - if (is_odd) { - lseek(from, 1L, 1); - if (to >= 0 && ! extracting) - lseek(to, 1L, 1); - } + strncpy(buf, member->ar_name, sizeof(member->ar_name)); + buf[sizeof(member->ar_name)] = 0; + error(TRUE, "read error on %s\n", buf); + } + if (to != NULL) + mwrite(to, io_buffer, rest); + mem_size -= (long) rest; + } while (mem_size > 0L); + + if (is_odd) + { + fseek(from, 1L, SEEK_CUR); + if ((to != NULL) && (extracting == FALSE)) + fseek(to, 1L, SEEK_CUR); + } } -char * -get_mode(mode) -register int mode; +char *get_mode(int mode) { - static char mode_buf[11]; - register int tmp = mode; - int i; + static char mode_buf[11]; + register int tmp = mode; + int i; - mode_buf[9] = ' '; - for (i = 0; i < 3; i++) { - mode_buf[i * 3] = (tmp & S_IREAD) ? 'r' : '-'; - mode_buf[i * 3 + 1] = (tmp & S_IWRITE) ? 'w' : '-'; - mode_buf[i * 3 + 2] = (tmp & S_IEXEC) ? 'x' : '-'; - tmp <<= 3; - } - if (mode & S_ISUID) - mode_buf[2] = 's'; - if (mode & S_ISGID) - mode_buf[5] = 's'; - return mode_buf; + mode_buf[9] = ' '; + for (i = 0; i < 3; i++) + { + mode_buf[i * 3] = (tmp & AR_IRUSR) ? 'r' : '-'; + mode_buf[i * 3 + 1] = (tmp & AR_IWUSR) ? 'w' : '-'; + mode_buf[i * 3 + 2] = (tmp & AR_IXUSR) ? 'x' : '-'; + tmp <<= 3; + } + if (mode & AR_ISUID) + mode_buf[2] = 's'; + if (mode & AR_ISGID) + mode_buf[5] = 's'; + return mode_buf; } -wr_fatal() +void wr_fatal(void) { - error(TRUE, "write error\n"); + error(TRUE, "write error\n", NULL); } -rd_fatal() +void rd_fatal(void) { - error(TRUE, "read error\n"); + error(TRUE, "read error\n", NULL); } -mwrite(fd, address, bytes) -int fd; -register char *address; -register int bytes; +void mwrite(FILE* f, void* address, size_t bytes) { - if (write(fd, address, bytes) != bytes) - error(TRUE, "write error\n"); + if (fwrite(address, 1, bytes, f) != bytes) + error(TRUE, "write error\n", NULL); } -show(s, name) -char *s, *name; +void show(char *s, char *name) { - MEMBER x; - char buf[sizeof(x.ar_name)+1]; - register char *p = buf, *q = name; + MEMBER x; + char buf[sizeof(x.ar_name) + 1]; + register char *p = buf, *q = name; - while (q <= &name[sizeof(x.ar_name)-1] && *q) *p++ = *q++; - *p++ = '\0'; - print(s, buf); + while (q <= &name[sizeof(x.ar_name) - 1] && *q) + *p++ = *q++; + *p++ = '\0'; + print(s, buf); } #ifdef AAL @@ -634,76 +761,80 @@ char *s, *name; * then 4 bytes giving the size of the string table, followed by the string * table itself. */ -void -write_symdef() +void write_symdef(FILE *ar) { - register struct ranlib *ran; - register int i; - register long delta; - MEMBER arbuf; + register struct ranlib *ran; + register int i; + register long delta; + time_t time_value; + MEMBER arbuf; - if (! tnum) return; + if (!tnum) + return; if (odd(tssiz)) tstrtab[tssiz++] = '\0'; for (i = 0; i < sizeof(arbuf.ar_name); i++) arbuf.ar_name[i] = '\0'; strcpy(arbuf.ar_name, SYMDEF); - arbuf.ar_size = 4 + 2 * 4 * (long)tnum + 4 + (long)tssiz; - time(&arbuf.ar_date); + arbuf.ar_size = 4 + 2 * 4 * (long) tnum + 4 + (long) tssiz; + time(&time_value); + arbuf.ar_date = (long) time_value; arbuf.ar_uid = getuid(); arbuf.ar_gid = getgid(); - arbuf.ar_mode = 0444; + arbuf.ar_mode = AR_IRUSR | AR_IRGRP | AR_IROTH; #ifdef DISTRIBUTION - if (distr_fl) { + if (distr_fl) + { arbuf.ar_uid = 2; arbuf.ar_gid = 2; arbuf.ar_date = distr_time; } #endif - wr_arhdr(ar_fd,&arbuf); - wr_long(ar_fd, (long) tnum); + wr_arhdr(ar, &arbuf); + wr_long(ar, (long) tnum); /* * Account for the space occupied by the magic number * and the ranlib table. */ delta = 2 + AR_TOTAL + arbuf.ar_size; - for (ran = tab; ran < &tab[tnum]; ran++) { + for (ran = tab; ran < &tab[tnum]; ran++) + { ran->ran_pos += delta; } - wr_ranlib(ar_fd, tab, (long) tnum); - wr_long(ar_fd, (long) tssiz); - wr_bytes(ar_fd, tstrtab, (long) tssiz); + wr_ranlib(ar, tab, (long) tnum); + wr_long(ar, (long) tssiz); + wr_bytes(ar, tstrtab, (long) tssiz); } /* * Return whether the bytes in `buf' form a good object header. * The header is put in `headp'. */ -int -is_outhead(headp) - register struct outhead *headp; +int is_outhead(struct outhead *headp) { - return !BADMAGIC(*headp) && headp->oh_nname != 0; } -void do_object(int f, long size) +void do_object(FILE* f, long size) { - struct outhead headbuf; + struct outhead headbuf; - if (size < SZ_HEAD) { + if (size < SZ_HEAD) + { /* It can't be an object file. */ return; } /* * Read a header to see if it is an object file. */ - if (! rd_fdopen(f)) { + if (!rd_fdopen(f)) + { rd_fatal(); } rd_ohead(&headbuf); - if (!is_outhead(&headbuf)) { + if (!is_outhead(&headbuf)) + { return; } do_names(&headbuf); @@ -714,30 +845,32 @@ void do_object(int f, long size) * name table and read and write the names one by one. Update the ranlib table * accordingly. */ -do_names(headp) - struct outhead *headp; +void do_names(struct outhead *headp) { - register char *strings; - register int nnames = headp->oh_nname; + register char *strings = NULL; + register int nnames = headp->oh_nname; #define NNAMES 100 - struct outname namebuf[NNAMES]; + struct outname namebuf[NNAMES]; long xxx = OFF_CHAR(*headp); - if ( headp->oh_nchar != (unsigned int)headp->oh_nchar || - (strings = malloc((unsigned int)headp->oh_nchar)) == (char *)0 - ) { - error(TRUE, "string table too big\n"); + if ( (headp->oh_nchar != (unsigned int) headp->oh_nchar) + || ((strings = malloc((unsigned int) headp->oh_nchar))) == NULL) + { + error(TRUE, "string table too big\n", NULL); } rd_string(strings, headp->oh_nchar); - while (nnames) { + while (nnames) + { int i = nnames >= NNAMES ? NNAMES : nnames; register struct outname *p = namebuf; nnames -= i; rd_name(namebuf, i); - while (i--) { + while (i--) + { long off = p->on_foff - xxx; - if (p->on_foff == (long)0) { + if (p->on_foff == (long) 0) + { p++; continue; /* An unrecognizable name. */ } @@ -750,9 +883,7 @@ do_names(headp) * However, this problem also exists on the Unix * ranlib archives. */ - if ( (p->on_type & S_EXT) && - (p->on_type & S_TYP) != S_UND - ) + if ((p->on_type & S_EXT) && (p->on_type & S_TYP) != S_UND) enter_name(p); p++; } @@ -760,26 +891,31 @@ do_names(headp) free(strings); } -enter_name(namep) - struct outname *namep; +void enter_name(struct outname *namep) { - register char *cp; + register char *cp; - if (tnum >= tabsz) { - tab = (struct ranlib *) - realloc((char *) tab, (tabsz += 512) * sizeof(struct ranlib)); - if (! tab) error(TRUE, "Out of core\n"); + if (tnum >= tabsz) + { + tab = (struct ranlib *) realloc((char *) tab, + (tabsz += 512) * sizeof(struct ranlib)); + if (!tab) + error(TRUE, "Out of core\n", NULL); } tab[tnum].ran_off = tssiz; tab[tnum].ran_pos = offset; - for (cp = namep->on_mptr;; cp++) { - if (tssiz >= strtabsz) { + for (cp = namep->on_mptr;; cp++) + { + if (tssiz >= strtabsz) + { tstrtab = realloc(tstrtab, (strtabsz += 4096)); - if (! tstrtab) error(TRUE, "string table overflow\n"); + if (!tstrtab) + error(TRUE, "string table overflow\n", NULL); } - tstrtab[tssiz++] = *cp; - if (!*cp) break; + tstrtab[tssiz++] = *cp; + if (!*cp) + break; } tnum++; } From 75394c93e122c7e9fcb8c7d114acc6365a8315dd Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 17:40:27 +0800 Subject: [PATCH 05/84] Better ANSI C portability. --- modules/src/object/object.h | 41 ++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/modules/src/object/object.h b/modules/src/object/object.h index cf6ac476a..a7a44c648 100644 --- a/modules/src/object/object.h +++ b/modules/src/object/object.h @@ -7,11 +7,14 @@ #ifndef __OBJECT_INCLUDED__ #define __OBJECT_INCLUDED__ +#include + struct ar_hdr; struct outhead; struct outrelo; struct outsect; struct ranlib; +struct outname; int wr_open(const char *f); void wr_close(void); @@ -23,13 +26,17 @@ void wr_putc(int c); void wr_relo(const struct outrelo *r, unsigned int c); void wr_name(const struct outname *n, unsigned int c); void wr_string(const char *s, long c); -void wr_arhdr(int fd, struct ar_hdr *a); -void wr_ranlib(int fd, struct ranlib *r, long cnt); -void wr_int2(int fd, int i); -void wr_long(int fd, long l); -void wr_bytes(int fd, const char *buf, long l); + + +void wr_arhdr(FILE* fd, struct ar_hdr *a); +void wr_ranlib(FILE* fd, struct ranlib *r, long cnt); +void wr_int2(FILE* fd, int i); +void wr_long(FILE* fd, long l); +void wr_bytes(FILE* fd, const char *buf, long l); + + int rd_open(const char *f); -int rd_fdopen(int f); +int rd_fdopen(FILE* fd); void rd_close(void); void rd_ohead(struct outhead *h); void rd_sect(struct outsect *s, unsigned int c); @@ -39,11 +46,21 @@ void rd_relo(struct outrelo *r, unsigned int c); void rd_rew_relos(struct outhead *head); void rd_name(struct outname *n, unsigned int c); void rd_string(char *s, long c); -int rd_arhdr(int fd, struct ar_hdr *a); -void rd_ranlib(int fd, struct ranlib *r, long cnt); -int rd_int2(int fd); -long rd_long(int fd); -void rd_bytes(int fd, char *buf, long l); -int rd_fd(void); + +/** Reads an archive header and returns the filled + * up archive header structure. Returns 0 if failure + * otherwise returns 1. + * + * @param[in] fd Opened file descriptor to read from. + * @param[out] a Archive header structure. + * + */ +int rd_arhdr(FILE* fd, struct ar_hdr *a); +void rd_ranlib(FILE* fd, struct ranlib *r, long cnt); +int rd_int2(FILE* fd); +long rd_long(FILE* fd); +unsigned int rd_unsigned2(FILE* fd); +void rd_bytes(FILE* fd, char *buf, long l); +FILE* rd_fd(void); #endif /* __OBJECT_INCLUDED__ */ From da0e0ac257c0ca2e6a29f19d57c6a51315d036cb Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 23:35:59 +0800 Subject: [PATCH 06/84] * Adapt to more ANSI C --- util/amisc/CMakeLists.txt | 36 ++++++++++++++++++++++ util/amisc/abmodules.c | 22 +++++--------- util/amisc/aelflod.c | 8 ++++- util/amisc/anm.c | 35 +++++++++------------ util/amisc/ashow.c | 64 ++++++++++++++++++++++----------------- util/amisc/asize.c | 7 ++--- util/amisc/aslod.c | 6 ++-- util/amisc/astrip.c | 62 +++++++++++++++++++------------------ 8 files changed, 141 insertions(+), 99 deletions(-) create mode 100644 util/amisc/CMakeLists.txt diff --git a/util/amisc/CMakeLists.txt b/util/amisc/CMakeLists.txt new file mode 100644 index 000000000..340e2925b --- /dev/null +++ b/util/amisc/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required (VERSION 2.9) +project (ack-misc) + +set(SRC_MODULES abmodules.c) +set(SRC_ELFLOD aelflod.c) +set(SRC_ANM anm.c) +set(SRC_ASHOW ashow.c) +set(SRC_ASIZE asize.c) +set(SRC_ASLOD aslod.c) +set(SRC_ASTRIP astrip.c) + + + + +add_executable(anm ${SRC_ANM}) +add_executable(ashow ${SRC_ASHOW}) +add_executable(asize ${SRC_ASIZE}) +add_executable(astrip ${SRC_ASTRIP}) +add_executable(aslod ${SRC_ASLOD}) + + +include_directories(${INCLUDE_DIRS}) + +# Set linking options +#target_link_libraries(ack-modules emheaders object) +target_link_libraries(anm emheaders object) +target_link_libraries(ashow emheaders object) +target_link_libraries(asize emheaders object) +target_link_libraries(astrip emheaders object system) +target_link_libraries(aslod emheaders object) + +install(TARGETS anm DESTINATION bin) +install(TARGETS ashow DESTINATION bin) +install(TARGETS asize DESTINATION bin) +install(TARGETS astrip DESTINATION bin) +install(TARGETS aslod DESTINATION bin) \ No newline at end of file diff --git a/util/amisc/abmodules.c b/util/amisc/abmodules.c index e1190c207..b77c7e96b 100644 --- a/util/amisc/abmodules.c +++ b/util/amisc/abmodules.c @@ -32,22 +32,18 @@ long s_base[S_MAX]; /* for specially encoded bases */ char *filename; int narg; -extern int rd_unsigned2(); static const char prefix[] = "_bmodule_"; static struct stringlist modules; -static void do_file(int fd) +static void do_file(FILE *fd) { struct outhead hbuf; - struct outname *nbufp = NULL; char *cbufp; long fi_to_co; long n; unsigned readcount; - int i,j; - int compare(); read_error = 0; rd_fdopen(fd); @@ -75,7 +71,6 @@ static void do_file(int fd) while (--n >= 0) { struct outname nbuf; - struct stringfragment* f; rd_name(&nbuf, 1); if (read_error) @@ -107,12 +102,12 @@ corrupt: fatal("%s --- corrupt", filename); } -static void process(int fd) +static void process(FILE* fd) { uint16_t magic = rd_unsigned2(fd); switch(magic) { case O_MAGIC: - lseek(fd, 0L, 0); + fseek(fd, 0L, SEEK_SET); do_file(fd); break; @@ -124,7 +119,7 @@ static void process(int fd) while (rd_arhdr(fd, &archive_header)) { - long nextpos = lseek(fd, 0L, SEEK_CUR) + archive_header.ar_size; + long nextpos = ftell(fd) + archive_header.ar_size; if (nextpos & 1) nextpos++; @@ -132,7 +127,7 @@ static void process(int fd) filename = buf; if (strcmp(filename, SYMDEF) != 0) do_file(fd); - lseek(fd, nextpos, 0); + fseek(fd, nextpos, SEEK_SET); } break; } @@ -144,7 +139,6 @@ static void process(int fd) int main(int argc, char* const argv[]) { - int opt; FILE* outputfp = NULL; program_name = argv[0]; @@ -169,15 +163,15 @@ int main(int argc, char* const argv[]) for (;;) { - int fd; + FILE *fd; filename = argv[optind++]; if (!filename) break; - if ((fd = open(filename, 0)) < 0) + if ((fd = fopen(filename, "rb")) == NULL) fatal("cannot open %s: %s", filename, strerror(errno)); process(fd); - close(fd); + fclose(fd); } if (outputfp) diff --git a/util/amisc/aelflod.c b/util/amisc/aelflod.c index 4ad77adbc..98ef2a44a 100644 --- a/util/amisc/aelflod.c +++ b/util/amisc/aelflod.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "out.h" #define ASSERT(x) switch (2) { case 0: case (x): ; } @@ -859,7 +860,12 @@ int main(int argc, char* argv[]) if (ferror(output)) fatal("output write error"); if (outputfile) - chmod(outputfile, 0755); + { + /* mode = 0755 in standard UNIX */ + chmod(outputfile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + /* Summarise what we've done. */ diff --git a/util/amisc/anm.c b/util/amisc/anm.c index 076c1424a..d149d64a2 100644 --- a/util/amisc/anm.c +++ b/util/amisc/anm.c @@ -10,12 +10,10 @@ ** anm [-gopruns] [name ...] */ -#include #include #include #include #include -#include #include "object.h" #include "out.h" @@ -38,10 +36,10 @@ long s_base[S_MAX]; /* for specially encoded bases */ char *filename; int narg; -void do_file(); +static void process(FILE *); +static void do_file(FILE *); -main(argc, argv) -char **argv; +int main(int argc, char **argv) { if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) { @@ -88,23 +86,21 @@ char **argv; narg = argc; while(argc--) { - int fd; + FILE *fd; filename = *++argv; - if ((fd = open(filename, 0)) < 0) { + if ((fd = fopen(filename, "rb")) == NULL) { fprintf(stderr, "anm: cannot open %s\n", filename); continue; } process(fd); - close(fd); + fclose(fd); } - exit(0); + exit(EXIT_SUCCESS); } -extern int rd_unsigned2(); -process(fd) - int fd; +static void process(FILE *fd) { unsigned int magic; long nextpos; @@ -116,13 +112,13 @@ process(fd) magic = rd_unsigned2(fd); switch(magic) { case O_MAGIC: - lseek(fd, 0L, 0); + fseek(fd, 0L, SEEK_SET); do_file(fd); break; case ARMAG: case AALMAG: while (rd_arhdr(fd, &archive_header)) { - nextpos = lseek(fd, 0L, 1) + archive_header.ar_size; + nextpos = ftell(fd) + archive_header.ar_size; if (nextpos & 1) nextpos++; strncpy(buf,archive_header.ar_name,sizeof(archive_header.ar_name)); filename = buf; @@ -130,7 +126,7 @@ process(fd) printf("\n%s:\n", filename); do_file(fd); } - lseek(fd, nextpos, 0); + fseek(fd, nextpos, SEEK_SET); } break; default: @@ -139,9 +135,7 @@ process(fd) } } -void -do_file(fd) - int fd; +static void do_file(FILE *fd) { struct outname *nbufp = NULL; struct outname nbuf; @@ -301,8 +295,7 @@ do_file(fd) free((char *)cbufp); } -compare(p1, p2) -struct outname *p1, *p2; +int compare(struct outname *p1, struct outname *p2) { int i; @@ -336,7 +329,7 @@ struct outname *p1, *p2; return(0); } -rd_fatal() +void rd_fatal(void) { fprintf(stderr,"read error on %s\n", filename); read_error = 1; diff --git a/util/amisc/ashow.c b/util/amisc/ashow.c index a1dbacf2f..015cd7bf7 100644 --- a/util/amisc/ashow.c +++ b/util/amisc/ashow.c @@ -5,18 +5,25 @@ static char rcsid[] = "$Id$"; #include #include -#include -#include -#include -#include +#include +#include "object.h" +#include "out.h" #define OK 0 /* Return value of gethead if Orl Korekt. */ #define BMASK 0xFF /* To extract least significant 8 bits from an int. */ +/* Forward declarations */ +static void show(register struct outhead *); +static void showflags(unsigned int); +static void showsect(void); +static void showrelo(void); +static void showname(struct outname *); +static char *myalloc(unsigned int); +static void error(char *, ...); + + /* ARGSUSED */ -main(argc, argv) - int argc; - char *argv[]; +int main(int argc, char **argv) # define prog argv[0] { register char **arg = argv; @@ -36,6 +43,7 @@ main(argc, argv) } rd_close(); } + return EXIT_SUCCESS; } /* @@ -43,14 +51,12 @@ main(argc, argv) * NB. The header has already been read and is in the struct outhead `headp' * points to. */ -show(headp) - register struct outhead *headp; +static void show(register struct outhead *headp) { register int i; register struct outname *np; register struct outname *name; /* Dynamically allocated name-array. */ register char *string;/* Base of string area. */ - extern char *myalloc(); printf("Version %d\n", headp->oh_stamp); showflags((unsigned) headp->oh_flags); @@ -90,8 +96,12 @@ show(headp) /* * Now we can show all names. */ - for (np = &name[0]; np < &name[headp->oh_nname]; np++) { - printf("Name %d:\n", np - name); + for (np = &name[0]; np < &name[headp->oh_nname]; np++) + { + /* In C99 this should be "%td" but we are in ANSI C89, + * so we typecast explicitly to int here. + */ + printf("Name %d:\n", (int)(np - name)); showname(np); } } @@ -99,8 +109,7 @@ show(headp) /* * Show flags from header. */ -showflags(flagword) - unsigned flagword; +static void showflags(unsigned int flagword) { if (flagword & HF_LINK) printf("unresolved references left\n"); } @@ -108,7 +117,7 @@ showflags(flagword) /* * Show a section. */ -showsect() +static void showsect(void) { struct outsect section; @@ -123,7 +132,7 @@ showsect() /* * Show a relocation record. */ -showrelo() +static void showrelo(void) { struct outrelo relrec; @@ -171,8 +180,7 @@ showrelo() /* * Show the name in the struct `namep' points to. */ -showname(namep) - struct outname *namep; +static void showname(struct outname *namep) { if (namep->on_mptr) printf("\t%s\n", namep->on_mptr); @@ -219,29 +227,29 @@ showname(namep) /* * Core allocation via malloc() but fatal if no core. */ -char * -myalloc(u) - unsigned int u; +static char *myalloc(unsigned int u) { register char *rcp; rcp = malloc(u); - if (rcp == (char *) 0) { + if (rcp == (char *) NULL) { error("Out of core\n"); - exit(1); + exit(EXIT_FAILURE); } return rcp; } -/* VARARGS1 */ -error(s, a1, a2, a3, a4) - char *s; +static void error(char *fmt, ...) { fflush(stdout); - fprintf(stderr, s, a1, a2, a3, a4); + /* Diagnostic print, no auto NL */ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); } -rd_fatal() +void rd_fatal(void) { error("Error in reading the object file\n"); exit(1); diff --git a/util/amisc/asize.c b/util/amisc/asize.c index 9b7bd7868..6ee79ba14 100644 --- a/util/amisc/asize.c +++ b/util/amisc/asize.c @@ -14,8 +14,7 @@ */ -main(argc, argv) -char **argv; +int main(int argc, char **argv) { struct outhead buf; struct outsect sbuf; @@ -60,10 +59,10 @@ char **argv; printf(" = %ld = 0x%lx\n", sum, sum); rd_close(); } - exit(0); + exit(EXIT_SUCCESS); } -rd_fatal() +void rd_fatal(void) { fprintf(stderr, "read error\n"); exit(2); diff --git a/util/amisc/aslod.c b/util/amisc/aslod.c index 72fbc8ce4..1d0e09c8a 100644 --- a/util/amisc/aslod.c +++ b/util/amisc/aslod.c @@ -287,8 +287,10 @@ int main(int argc, char* argv[]) if (ferror(output)) fatal("output write error"); if (outputfile) - chmod(outputfile, 0755); - + { + /* mode = 0755 in standard UNIX */ + chmod(outputfile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } /* Summarise what we've done. */ if (verbose) diff --git a/util/amisc/astrip.c b/util/amisc/astrip.c index 51342be4e..fcccb3474 100644 --- a/util/amisc/astrip.c +++ b/util/amisc/astrip.c @@ -4,11 +4,11 @@ */ /* $Id$ */ -#include #include #include #include -#include +#include +#include "system.h" #include "object.h" #include "out.h" @@ -18,34 +18,40 @@ */ -char temp_name[] = "/tmp/sXXXXXX"; -char *tname; +char tname[L_tmpnam]; FILE *tf; struct outhead buf; int readerror, writeerror; -main(argc, argv) -char **argv; + +static int copy(char *, char *, long, FILE *, FILE *); +static int strip(char *); + +int main(int argc, char **argv) { int status; signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); - close(mkstemp(temp_name)); + if (sys_tmpnam(tname)==NULL) + { + fprintf(stderr, "astrip: cannot create temporary filename\n"); + return(1); + } + fclose(fopen(tname,"wb")); while(--argc) { if ((status = strip(argv[argc])) > 1) break; } - unlink(temp_name); - exit(status); + remove(tname); + return status; } -strip(name) -char *name; +int strip(char *name) { long size; - int fw; + FILE *fw; if (! rd_open(name)) { fprintf(stderr, "astrip: cannot open %s\n", name); @@ -78,48 +84,46 @@ char *name; rd_close(); return(1); } - fw = open(tname, 2); - if (fw < 0 || lseek(fw, (long)SZ_HEAD, 0) < 0) { + fw = fopen(tname, "ab"); + if ((fw == NULL) || (fseek(fw, (long)SZ_HEAD, SEEK_SET)!=0)) { fprintf(stderr, "astrip: cannot create temp file %s\n", tname); rd_close(); - close(fw); + fclose(fw); return(2); } if(copy(name, tname, size, rd_fd(), fw)) { rd_close(); - close(fw); + fclose(fw); return(1); } rd_close(); - close(fw); + fclose(fw); size += SZ_HEAD; if (! rd_open(tname)) { fprintf(stderr, "astrip: cannot read temp file %s\n", tname); return(2); } - fw = creat(name, 0777); - if (fw < 0) { + fw = fopen(name, "wb"); + if (fw == NULL) { fprintf(stderr, "astrip: cannot write %s\n", name); rd_close(); return(1); } if(copy(tname, name, size, rd_fd(), fw)) { - close(fw); + fclose(fw); rd_close(); return(2); } - - close(fw); + fclose(fw); rd_close(); + /* Change the mode to everything. */ + chmod(name,S_IRWXU | S_IRWXG | S_IRWXO); return(0); } -copy(fnam, tnam, size, fr, fw) -char *fnam; -char *tnam; -long size; +static int copy(char *fnam, char *tnam, long size, FILE *fr, FILE *fw) { - register s, n; + register int s; char lbuf[512]; while(size != (long)0) { @@ -141,12 +145,12 @@ long size; return(0); } -rd_fatal() +void rd_fatal(void) { readerror = 1; } -wr_fatal() +void wr_fatal(void) { writeerror = 1; } From a58ad2bc31f5c902b11c49dbc4b3e30aaeb465c2 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 23:36:52 +0800 Subject: [PATCH 07/84] * Adapt to more ANSI C --- util/arch/archiver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/util/arch/archiver.c b/util/arch/archiver.c index f216262fb..1353fa1be 100644 --- a/util/arch/archiver.c +++ b/util/arch/archiver.c @@ -553,7 +553,6 @@ void get(int argc, char *argv[]) */ void add(char *name, FILE* ar, FILE* dst, char *mess) { -<<<<<<< HEAD static MEMBER member; size_t read_chars; struct stat status; From f7e4fac687e56a8346d960665a5d34ec6984c759 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 23:39:04 +0800 Subject: [PATCH 08/84] Revert "* Adapt to more ANSI C" This reverts commit da0e0ac257c0ca2e6a29f19d57c6a51315d036cb. --- util/amisc/CMakeLists.txt | 36 ---------------------- util/amisc/abmodules.c | 22 +++++++++----- util/amisc/aelflod.c | 8 +---- util/amisc/anm.c | 35 ++++++++++++--------- util/amisc/ashow.c | 64 +++++++++++++++++---------------------- util/amisc/asize.c | 7 +++-- util/amisc/aslod.c | 6 ++-- util/amisc/astrip.c | 62 ++++++++++++++++++------------------- 8 files changed, 99 insertions(+), 141 deletions(-) delete mode 100644 util/amisc/CMakeLists.txt diff --git a/util/amisc/CMakeLists.txt b/util/amisc/CMakeLists.txt deleted file mode 100644 index 340e2925b..000000000 --- a/util/amisc/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required (VERSION 2.9) -project (ack-misc) - -set(SRC_MODULES abmodules.c) -set(SRC_ELFLOD aelflod.c) -set(SRC_ANM anm.c) -set(SRC_ASHOW ashow.c) -set(SRC_ASIZE asize.c) -set(SRC_ASLOD aslod.c) -set(SRC_ASTRIP astrip.c) - - - - -add_executable(anm ${SRC_ANM}) -add_executable(ashow ${SRC_ASHOW}) -add_executable(asize ${SRC_ASIZE}) -add_executable(astrip ${SRC_ASTRIP}) -add_executable(aslod ${SRC_ASLOD}) - - -include_directories(${INCLUDE_DIRS}) - -# Set linking options -#target_link_libraries(ack-modules emheaders object) -target_link_libraries(anm emheaders object) -target_link_libraries(ashow emheaders object) -target_link_libraries(asize emheaders object) -target_link_libraries(astrip emheaders object system) -target_link_libraries(aslod emheaders object) - -install(TARGETS anm DESTINATION bin) -install(TARGETS ashow DESTINATION bin) -install(TARGETS asize DESTINATION bin) -install(TARGETS astrip DESTINATION bin) -install(TARGETS aslod DESTINATION bin) \ No newline at end of file diff --git a/util/amisc/abmodules.c b/util/amisc/abmodules.c index b77c7e96b..e1190c207 100644 --- a/util/amisc/abmodules.c +++ b/util/amisc/abmodules.c @@ -32,18 +32,22 @@ long s_base[S_MAX]; /* for specially encoded bases */ char *filename; int narg; +extern int rd_unsigned2(); static const char prefix[] = "_bmodule_"; static struct stringlist modules; -static void do_file(FILE *fd) +static void do_file(int fd) { struct outhead hbuf; + struct outname *nbufp = NULL; char *cbufp; long fi_to_co; long n; unsigned readcount; + int i,j; + int compare(); read_error = 0; rd_fdopen(fd); @@ -71,6 +75,7 @@ static void do_file(FILE *fd) while (--n >= 0) { struct outname nbuf; + struct stringfragment* f; rd_name(&nbuf, 1); if (read_error) @@ -102,12 +107,12 @@ corrupt: fatal("%s --- corrupt", filename); } -static void process(FILE* fd) +static void process(int fd) { uint16_t magic = rd_unsigned2(fd); switch(magic) { case O_MAGIC: - fseek(fd, 0L, SEEK_SET); + lseek(fd, 0L, 0); do_file(fd); break; @@ -119,7 +124,7 @@ static void process(FILE* fd) while (rd_arhdr(fd, &archive_header)) { - long nextpos = ftell(fd) + archive_header.ar_size; + long nextpos = lseek(fd, 0L, SEEK_CUR) + archive_header.ar_size; if (nextpos & 1) nextpos++; @@ -127,7 +132,7 @@ static void process(FILE* fd) filename = buf; if (strcmp(filename, SYMDEF) != 0) do_file(fd); - fseek(fd, nextpos, SEEK_SET); + lseek(fd, nextpos, 0); } break; } @@ -139,6 +144,7 @@ static void process(FILE* fd) int main(int argc, char* const argv[]) { + int opt; FILE* outputfp = NULL; program_name = argv[0]; @@ -163,15 +169,15 @@ int main(int argc, char* const argv[]) for (;;) { - FILE *fd; + int fd; filename = argv[optind++]; if (!filename) break; - if ((fd = fopen(filename, "rb")) == NULL) + if ((fd = open(filename, 0)) < 0) fatal("cannot open %s: %s", filename, strerror(errno)); process(fd); - fclose(fd); + close(fd); } if (outputfp) diff --git a/util/amisc/aelflod.c b/util/amisc/aelflod.c index 98ef2a44a..4ad77adbc 100644 --- a/util/amisc/aelflod.c +++ b/util/amisc/aelflod.c @@ -25,7 +25,6 @@ #include #include #include -#include #include "out.h" #define ASSERT(x) switch (2) { case 0: case (x): ; } @@ -860,12 +859,7 @@ int main(int argc, char* argv[]) if (ferror(output)) fatal("output write error"); if (outputfile) - { - /* mode = 0755 in standard UNIX */ - chmod(outputfile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - } - - + chmod(outputfile, 0755); /* Summarise what we've done. */ diff --git a/util/amisc/anm.c b/util/amisc/anm.c index d149d64a2..076c1424a 100644 --- a/util/amisc/anm.c +++ b/util/amisc/anm.c @@ -10,10 +10,12 @@ ** anm [-gopruns] [name ...] */ +#include #include #include #include #include +#include #include "object.h" #include "out.h" @@ -36,10 +38,10 @@ long s_base[S_MAX]; /* for specially encoded bases */ char *filename; int narg; -static void process(FILE *); -static void do_file(FILE *); +void do_file(); -int main(int argc, char **argv) +main(argc, argv) +char **argv; { if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) { @@ -86,21 +88,23 @@ int main(int argc, char **argv) narg = argc; while(argc--) { - FILE *fd; + int fd; filename = *++argv; - if ((fd = fopen(filename, "rb")) == NULL) { + if ((fd = open(filename, 0)) < 0) { fprintf(stderr, "anm: cannot open %s\n", filename); continue; } process(fd); - fclose(fd); + close(fd); } - exit(EXIT_SUCCESS); + exit(0); } +extern int rd_unsigned2(); -static void process(FILE *fd) +process(fd) + int fd; { unsigned int magic; long nextpos; @@ -112,13 +116,13 @@ static void process(FILE *fd) magic = rd_unsigned2(fd); switch(magic) { case O_MAGIC: - fseek(fd, 0L, SEEK_SET); + lseek(fd, 0L, 0); do_file(fd); break; case ARMAG: case AALMAG: while (rd_arhdr(fd, &archive_header)) { - nextpos = ftell(fd) + archive_header.ar_size; + nextpos = lseek(fd, 0L, 1) + archive_header.ar_size; if (nextpos & 1) nextpos++; strncpy(buf,archive_header.ar_name,sizeof(archive_header.ar_name)); filename = buf; @@ -126,7 +130,7 @@ static void process(FILE *fd) printf("\n%s:\n", filename); do_file(fd); } - fseek(fd, nextpos, SEEK_SET); + lseek(fd, nextpos, 0); } break; default: @@ -135,7 +139,9 @@ static void process(FILE *fd) } } -static void do_file(FILE *fd) +void +do_file(fd) + int fd; { struct outname *nbufp = NULL; struct outname nbuf; @@ -295,7 +301,8 @@ static void do_file(FILE *fd) free((char *)cbufp); } -int compare(struct outname *p1, struct outname *p2) +compare(p1, p2) +struct outname *p1, *p2; { int i; @@ -329,7 +336,7 @@ int compare(struct outname *p1, struct outname *p2) return(0); } -void rd_fatal(void) +rd_fatal() { fprintf(stderr,"read error on %s\n", filename); read_error = 1; diff --git a/util/amisc/ashow.c b/util/amisc/ashow.c index 015cd7bf7..a1dbacf2f 100644 --- a/util/amisc/ashow.c +++ b/util/amisc/ashow.c @@ -5,25 +5,18 @@ static char rcsid[] = "$Id$"; #include #include -#include -#include "object.h" -#include "out.h" +#include +#include +#include +#include #define OK 0 /* Return value of gethead if Orl Korekt. */ #define BMASK 0xFF /* To extract least significant 8 bits from an int. */ -/* Forward declarations */ -static void show(register struct outhead *); -static void showflags(unsigned int); -static void showsect(void); -static void showrelo(void); -static void showname(struct outname *); -static char *myalloc(unsigned int); -static void error(char *, ...); - - /* ARGSUSED */ -int main(int argc, char **argv) +main(argc, argv) + int argc; + char *argv[]; # define prog argv[0] { register char **arg = argv; @@ -43,7 +36,6 @@ int main(int argc, char **argv) } rd_close(); } - return EXIT_SUCCESS; } /* @@ -51,12 +43,14 @@ int main(int argc, char **argv) * NB. The header has already been read and is in the struct outhead `headp' * points to. */ -static void show(register struct outhead *headp) +show(headp) + register struct outhead *headp; { register int i; register struct outname *np; register struct outname *name; /* Dynamically allocated name-array. */ register char *string;/* Base of string area. */ + extern char *myalloc(); printf("Version %d\n", headp->oh_stamp); showflags((unsigned) headp->oh_flags); @@ -96,12 +90,8 @@ static void show(register struct outhead *headp) /* * Now we can show all names. */ - for (np = &name[0]; np < &name[headp->oh_nname]; np++) - { - /* In C99 this should be "%td" but we are in ANSI C89, - * so we typecast explicitly to int here. - */ - printf("Name %d:\n", (int)(np - name)); + for (np = &name[0]; np < &name[headp->oh_nname]; np++) { + printf("Name %d:\n", np - name); showname(np); } } @@ -109,7 +99,8 @@ static void show(register struct outhead *headp) /* * Show flags from header. */ -static void showflags(unsigned int flagword) +showflags(flagword) + unsigned flagword; { if (flagword & HF_LINK) printf("unresolved references left\n"); } @@ -117,7 +108,7 @@ static void showflags(unsigned int flagword) /* * Show a section. */ -static void showsect(void) +showsect() { struct outsect section; @@ -132,7 +123,7 @@ static void showsect(void) /* * Show a relocation record. */ -static void showrelo(void) +showrelo() { struct outrelo relrec; @@ -180,7 +171,8 @@ static void showrelo(void) /* * Show the name in the struct `namep' points to. */ -static void showname(struct outname *namep) +showname(namep) + struct outname *namep; { if (namep->on_mptr) printf("\t%s\n", namep->on_mptr); @@ -227,29 +219,29 @@ static void showname(struct outname *namep) /* * Core allocation via malloc() but fatal if no core. */ -static char *myalloc(unsigned int u) +char * +myalloc(u) + unsigned int u; { register char *rcp; rcp = malloc(u); - if (rcp == (char *) NULL) { + if (rcp == (char *) 0) { error("Out of core\n"); - exit(EXIT_FAILURE); + exit(1); } return rcp; } -static void error(char *fmt, ...) +/* VARARGS1 */ +error(s, a1, a2, a3, a4) + char *s; { fflush(stdout); - /* Diagnostic print, no auto NL */ - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); + fprintf(stderr, s, a1, a2, a3, a4); } -void rd_fatal(void) +rd_fatal() { error("Error in reading the object file\n"); exit(1); diff --git a/util/amisc/asize.c b/util/amisc/asize.c index 6ee79ba14..9b7bd7868 100644 --- a/util/amisc/asize.c +++ b/util/amisc/asize.c @@ -14,7 +14,8 @@ */ -int main(int argc, char **argv) +main(argc, argv) +char **argv; { struct outhead buf; struct outsect sbuf; @@ -59,10 +60,10 @@ int main(int argc, char **argv) printf(" = %ld = 0x%lx\n", sum, sum); rd_close(); } - exit(EXIT_SUCCESS); + exit(0); } -void rd_fatal(void) +rd_fatal() { fprintf(stderr, "read error\n"); exit(2); diff --git a/util/amisc/aslod.c b/util/amisc/aslod.c index 1d0e09c8a..72fbc8ce4 100644 --- a/util/amisc/aslod.c +++ b/util/amisc/aslod.c @@ -287,10 +287,8 @@ int main(int argc, char* argv[]) if (ferror(output)) fatal("output write error"); if (outputfile) - { - /* mode = 0755 in standard UNIX */ - chmod(outputfile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - } + chmod(outputfile, 0755); + /* Summarise what we've done. */ if (verbose) diff --git a/util/amisc/astrip.c b/util/amisc/astrip.c index fcccb3474..51342be4e 100644 --- a/util/amisc/astrip.c +++ b/util/amisc/astrip.c @@ -4,11 +4,11 @@ */ /* $Id$ */ +#include #include #include #include -#include -#include "system.h" +#include #include "object.h" #include "out.h" @@ -18,40 +18,34 @@ */ -char tname[L_tmpnam]; +char temp_name[] = "/tmp/sXXXXXX"; +char *tname; FILE *tf; struct outhead buf; int readerror, writeerror; - -static int copy(char *, char *, long, FILE *, FILE *); -static int strip(char *); - -int main(int argc, char **argv) +main(argc, argv) +char **argv; { int status; signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); - if (sys_tmpnam(tname)==NULL) - { - fprintf(stderr, "astrip: cannot create temporary filename\n"); - return(1); - } - fclose(fopen(tname,"wb")); + close(mkstemp(temp_name)); while(--argc) { if ((status = strip(argv[argc])) > 1) break; } - remove(tname); - return status; + unlink(temp_name); + exit(status); } -int strip(char *name) +strip(name) +char *name; { long size; - FILE *fw; + int fw; if (! rd_open(name)) { fprintf(stderr, "astrip: cannot open %s\n", name); @@ -84,46 +78,48 @@ int strip(char *name) rd_close(); return(1); } - fw = fopen(tname, "ab"); - if ((fw == NULL) || (fseek(fw, (long)SZ_HEAD, SEEK_SET)!=0)) { + fw = open(tname, 2); + if (fw < 0 || lseek(fw, (long)SZ_HEAD, 0) < 0) { fprintf(stderr, "astrip: cannot create temp file %s\n", tname); rd_close(); - fclose(fw); + close(fw); return(2); } if(copy(name, tname, size, rd_fd(), fw)) { rd_close(); - fclose(fw); + close(fw); return(1); } rd_close(); - fclose(fw); + close(fw); size += SZ_HEAD; if (! rd_open(tname)) { fprintf(stderr, "astrip: cannot read temp file %s\n", tname); return(2); } - fw = fopen(name, "wb"); - if (fw == NULL) { + fw = creat(name, 0777); + if (fw < 0) { fprintf(stderr, "astrip: cannot write %s\n", name); rd_close(); return(1); } if(copy(tname, name, size, rd_fd(), fw)) { - fclose(fw); + close(fw); rd_close(); return(2); } - fclose(fw); + + close(fw); rd_close(); - /* Change the mode to everything. */ - chmod(name,S_IRWXU | S_IRWXG | S_IRWXO); return(0); } -static int copy(char *fnam, char *tnam, long size, FILE *fr, FILE *fw) +copy(fnam, tnam, size, fr, fw) +char *fnam; +char *tnam; +long size; { - register int s; + register s, n; char lbuf[512]; while(size != (long)0) { @@ -145,12 +141,12 @@ static int copy(char *fnam, char *tnam, long size, FILE *fr, FILE *fw) return(0); } -void rd_fatal(void) +rd_fatal() { readerror = 1; } -void wr_fatal(void) +wr_fatal() { writeerror = 1; } From 5ec9de401db406ebd4f5817508d337da4bc945ba Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 24 Mar 2019 23:53:13 +0800 Subject: [PATCH 09/84] * More ANSI C portability fixes. --- util/amisc/abmodules.c | 22 ++++++--------- util/amisc/aelflod.c | 8 +++++- util/amisc/anm.c | 35 +++++++++-------------- util/amisc/ashow.c | 64 ++++++++++++++++++++++++------------------ util/amisc/asize.c | 7 ++--- util/amisc/aslod.c | 6 ++-- util/amisc/astrip.c | 62 +++++++++++++++++++++------------------- 7 files changed, 105 insertions(+), 99 deletions(-) diff --git a/util/amisc/abmodules.c b/util/amisc/abmodules.c index e1190c207..b77c7e96b 100644 --- a/util/amisc/abmodules.c +++ b/util/amisc/abmodules.c @@ -32,22 +32,18 @@ long s_base[S_MAX]; /* for specially encoded bases */ char *filename; int narg; -extern int rd_unsigned2(); static const char prefix[] = "_bmodule_"; static struct stringlist modules; -static void do_file(int fd) +static void do_file(FILE *fd) { struct outhead hbuf; - struct outname *nbufp = NULL; char *cbufp; long fi_to_co; long n; unsigned readcount; - int i,j; - int compare(); read_error = 0; rd_fdopen(fd); @@ -75,7 +71,6 @@ static void do_file(int fd) while (--n >= 0) { struct outname nbuf; - struct stringfragment* f; rd_name(&nbuf, 1); if (read_error) @@ -107,12 +102,12 @@ corrupt: fatal("%s --- corrupt", filename); } -static void process(int fd) +static void process(FILE* fd) { uint16_t magic = rd_unsigned2(fd); switch(magic) { case O_MAGIC: - lseek(fd, 0L, 0); + fseek(fd, 0L, SEEK_SET); do_file(fd); break; @@ -124,7 +119,7 @@ static void process(int fd) while (rd_arhdr(fd, &archive_header)) { - long nextpos = lseek(fd, 0L, SEEK_CUR) + archive_header.ar_size; + long nextpos = ftell(fd) + archive_header.ar_size; if (nextpos & 1) nextpos++; @@ -132,7 +127,7 @@ static void process(int fd) filename = buf; if (strcmp(filename, SYMDEF) != 0) do_file(fd); - lseek(fd, nextpos, 0); + fseek(fd, nextpos, SEEK_SET); } break; } @@ -144,7 +139,6 @@ static void process(int fd) int main(int argc, char* const argv[]) { - int opt; FILE* outputfp = NULL; program_name = argv[0]; @@ -169,15 +163,15 @@ int main(int argc, char* const argv[]) for (;;) { - int fd; + FILE *fd; filename = argv[optind++]; if (!filename) break; - if ((fd = open(filename, 0)) < 0) + if ((fd = fopen(filename, "rb")) == NULL) fatal("cannot open %s: %s", filename, strerror(errno)); process(fd); - close(fd); + fclose(fd); } if (outputfp) diff --git a/util/amisc/aelflod.c b/util/amisc/aelflod.c index 4ad77adbc..98ef2a44a 100644 --- a/util/amisc/aelflod.c +++ b/util/amisc/aelflod.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "out.h" #define ASSERT(x) switch (2) { case 0: case (x): ; } @@ -859,7 +860,12 @@ int main(int argc, char* argv[]) if (ferror(output)) fatal("output write error"); if (outputfile) - chmod(outputfile, 0755); + { + /* mode = 0755 in standard UNIX */ + chmod(outputfile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + /* Summarise what we've done. */ diff --git a/util/amisc/anm.c b/util/amisc/anm.c index 076c1424a..d149d64a2 100644 --- a/util/amisc/anm.c +++ b/util/amisc/anm.c @@ -10,12 +10,10 @@ ** anm [-gopruns] [name ...] */ -#include #include #include #include #include -#include #include "object.h" #include "out.h" @@ -38,10 +36,10 @@ long s_base[S_MAX]; /* for specially encoded bases */ char *filename; int narg; -void do_file(); +static void process(FILE *); +static void do_file(FILE *); -main(argc, argv) -char **argv; +int main(int argc, char **argv) { if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) { @@ -88,23 +86,21 @@ char **argv; narg = argc; while(argc--) { - int fd; + FILE *fd; filename = *++argv; - if ((fd = open(filename, 0)) < 0) { + if ((fd = fopen(filename, "rb")) == NULL) { fprintf(stderr, "anm: cannot open %s\n", filename); continue; } process(fd); - close(fd); + fclose(fd); } - exit(0); + exit(EXIT_SUCCESS); } -extern int rd_unsigned2(); -process(fd) - int fd; +static void process(FILE *fd) { unsigned int magic; long nextpos; @@ -116,13 +112,13 @@ process(fd) magic = rd_unsigned2(fd); switch(magic) { case O_MAGIC: - lseek(fd, 0L, 0); + fseek(fd, 0L, SEEK_SET); do_file(fd); break; case ARMAG: case AALMAG: while (rd_arhdr(fd, &archive_header)) { - nextpos = lseek(fd, 0L, 1) + archive_header.ar_size; + nextpos = ftell(fd) + archive_header.ar_size; if (nextpos & 1) nextpos++; strncpy(buf,archive_header.ar_name,sizeof(archive_header.ar_name)); filename = buf; @@ -130,7 +126,7 @@ process(fd) printf("\n%s:\n", filename); do_file(fd); } - lseek(fd, nextpos, 0); + fseek(fd, nextpos, SEEK_SET); } break; default: @@ -139,9 +135,7 @@ process(fd) } } -void -do_file(fd) - int fd; +static void do_file(FILE *fd) { struct outname *nbufp = NULL; struct outname nbuf; @@ -301,8 +295,7 @@ do_file(fd) free((char *)cbufp); } -compare(p1, p2) -struct outname *p1, *p2; +int compare(struct outname *p1, struct outname *p2) { int i; @@ -336,7 +329,7 @@ struct outname *p1, *p2; return(0); } -rd_fatal() +void rd_fatal(void) { fprintf(stderr,"read error on %s\n", filename); read_error = 1; diff --git a/util/amisc/ashow.c b/util/amisc/ashow.c index a1dbacf2f..015cd7bf7 100644 --- a/util/amisc/ashow.c +++ b/util/amisc/ashow.c @@ -5,18 +5,25 @@ static char rcsid[] = "$Id$"; #include #include -#include -#include -#include -#include +#include +#include "object.h" +#include "out.h" #define OK 0 /* Return value of gethead if Orl Korekt. */ #define BMASK 0xFF /* To extract least significant 8 bits from an int. */ +/* Forward declarations */ +static void show(register struct outhead *); +static void showflags(unsigned int); +static void showsect(void); +static void showrelo(void); +static void showname(struct outname *); +static char *myalloc(unsigned int); +static void error(char *, ...); + + /* ARGSUSED */ -main(argc, argv) - int argc; - char *argv[]; +int main(int argc, char **argv) # define prog argv[0] { register char **arg = argv; @@ -36,6 +43,7 @@ main(argc, argv) } rd_close(); } + return EXIT_SUCCESS; } /* @@ -43,14 +51,12 @@ main(argc, argv) * NB. The header has already been read and is in the struct outhead `headp' * points to. */ -show(headp) - register struct outhead *headp; +static void show(register struct outhead *headp) { register int i; register struct outname *np; register struct outname *name; /* Dynamically allocated name-array. */ register char *string;/* Base of string area. */ - extern char *myalloc(); printf("Version %d\n", headp->oh_stamp); showflags((unsigned) headp->oh_flags); @@ -90,8 +96,12 @@ show(headp) /* * Now we can show all names. */ - for (np = &name[0]; np < &name[headp->oh_nname]; np++) { - printf("Name %d:\n", np - name); + for (np = &name[0]; np < &name[headp->oh_nname]; np++) + { + /* In C99 this should be "%td" but we are in ANSI C89, + * so we typecast explicitly to int here. + */ + printf("Name %d:\n", (int)(np - name)); showname(np); } } @@ -99,8 +109,7 @@ show(headp) /* * Show flags from header. */ -showflags(flagword) - unsigned flagword; +static void showflags(unsigned int flagword) { if (flagword & HF_LINK) printf("unresolved references left\n"); } @@ -108,7 +117,7 @@ showflags(flagword) /* * Show a section. */ -showsect() +static void showsect(void) { struct outsect section; @@ -123,7 +132,7 @@ showsect() /* * Show a relocation record. */ -showrelo() +static void showrelo(void) { struct outrelo relrec; @@ -171,8 +180,7 @@ showrelo() /* * Show the name in the struct `namep' points to. */ -showname(namep) - struct outname *namep; +static void showname(struct outname *namep) { if (namep->on_mptr) printf("\t%s\n", namep->on_mptr); @@ -219,29 +227,29 @@ showname(namep) /* * Core allocation via malloc() but fatal if no core. */ -char * -myalloc(u) - unsigned int u; +static char *myalloc(unsigned int u) { register char *rcp; rcp = malloc(u); - if (rcp == (char *) 0) { + if (rcp == (char *) NULL) { error("Out of core\n"); - exit(1); + exit(EXIT_FAILURE); } return rcp; } -/* VARARGS1 */ -error(s, a1, a2, a3, a4) - char *s; +static void error(char *fmt, ...) { fflush(stdout); - fprintf(stderr, s, a1, a2, a3, a4); + /* Diagnostic print, no auto NL */ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); } -rd_fatal() +void rd_fatal(void) { error("Error in reading the object file\n"); exit(1); diff --git a/util/amisc/asize.c b/util/amisc/asize.c index 9b7bd7868..6ee79ba14 100644 --- a/util/amisc/asize.c +++ b/util/amisc/asize.c @@ -14,8 +14,7 @@ */ -main(argc, argv) -char **argv; +int main(int argc, char **argv) { struct outhead buf; struct outsect sbuf; @@ -60,10 +59,10 @@ char **argv; printf(" = %ld = 0x%lx\n", sum, sum); rd_close(); } - exit(0); + exit(EXIT_SUCCESS); } -rd_fatal() +void rd_fatal(void) { fprintf(stderr, "read error\n"); exit(2); diff --git a/util/amisc/aslod.c b/util/amisc/aslod.c index 72fbc8ce4..1d0e09c8a 100644 --- a/util/amisc/aslod.c +++ b/util/amisc/aslod.c @@ -287,8 +287,10 @@ int main(int argc, char* argv[]) if (ferror(output)) fatal("output write error"); if (outputfile) - chmod(outputfile, 0755); - + { + /* mode = 0755 in standard UNIX */ + chmod(outputfile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } /* Summarise what we've done. */ if (verbose) diff --git a/util/amisc/astrip.c b/util/amisc/astrip.c index 51342be4e..fcccb3474 100644 --- a/util/amisc/astrip.c +++ b/util/amisc/astrip.c @@ -4,11 +4,11 @@ */ /* $Id$ */ -#include #include #include #include -#include +#include +#include "system.h" #include "object.h" #include "out.h" @@ -18,34 +18,40 @@ */ -char temp_name[] = "/tmp/sXXXXXX"; -char *tname; +char tname[L_tmpnam]; FILE *tf; struct outhead buf; int readerror, writeerror; -main(argc, argv) -char **argv; + +static int copy(char *, char *, long, FILE *, FILE *); +static int strip(char *); + +int main(int argc, char **argv) { int status; signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); - close(mkstemp(temp_name)); + if (sys_tmpnam(tname)==NULL) + { + fprintf(stderr, "astrip: cannot create temporary filename\n"); + return(1); + } + fclose(fopen(tname,"wb")); while(--argc) { if ((status = strip(argv[argc])) > 1) break; } - unlink(temp_name); - exit(status); + remove(tname); + return status; } -strip(name) -char *name; +int strip(char *name) { long size; - int fw; + FILE *fw; if (! rd_open(name)) { fprintf(stderr, "astrip: cannot open %s\n", name); @@ -78,48 +84,46 @@ char *name; rd_close(); return(1); } - fw = open(tname, 2); - if (fw < 0 || lseek(fw, (long)SZ_HEAD, 0) < 0) { + fw = fopen(tname, "ab"); + if ((fw == NULL) || (fseek(fw, (long)SZ_HEAD, SEEK_SET)!=0)) { fprintf(stderr, "astrip: cannot create temp file %s\n", tname); rd_close(); - close(fw); + fclose(fw); return(2); } if(copy(name, tname, size, rd_fd(), fw)) { rd_close(); - close(fw); + fclose(fw); return(1); } rd_close(); - close(fw); + fclose(fw); size += SZ_HEAD; if (! rd_open(tname)) { fprintf(stderr, "astrip: cannot read temp file %s\n", tname); return(2); } - fw = creat(name, 0777); - if (fw < 0) { + fw = fopen(name, "wb"); + if (fw == NULL) { fprintf(stderr, "astrip: cannot write %s\n", name); rd_close(); return(1); } if(copy(tname, name, size, rd_fd(), fw)) { - close(fw); + fclose(fw); rd_close(); return(2); } - - close(fw); + fclose(fw); rd_close(); + /* Change the mode to everything. */ + chmod(name,S_IRWXU | S_IRWXG | S_IRWXO); return(0); } -copy(fnam, tnam, size, fr, fw) -char *fnam; -char *tnam; -long size; +static int copy(char *fnam, char *tnam, long size, FILE *fr, FILE *fw) { - register s, n; + register int s; char lbuf[512]; while(size != (long)0) { @@ -141,12 +145,12 @@ long size; return(0); } -rd_fatal() +void rd_fatal(void) { readerror = 1; } -wr_fatal() +void wr_fatal(void) { writeerror = 1; } From 8457ec6791bb50dca249e2186a773da2186117ab Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:07:12 +0800 Subject: [PATCH 10/84] Object module now uses ANSI C I/O --- modules/src/object/obj.h | 43 +++++----- modules/src/object/object.3 | 138 ++++++++------------------------- modules/src/object/rd.c | 34 ++++---- modules/src/object/rd_arhdr.c | 56 +++++++------ modules/src/object/rd_bytes.c | 31 ++++---- modules/src/object/rd_int2.c | 8 +- modules/src/object/rd_long.c | 9 ++- modules/src/object/rd_ranlib.c | 12 ++- modules/src/object/rd_unsig2.c | 8 +- modules/src/object/wr.c | 37 ++++----- modules/src/object/wr_arhdr.c | 14 +++- modules/src/object/wr_bytes.c | 31 +++++--- modules/src/object/wr_int2.c | 8 +- modules/src/object/wr_long.c | 9 ++- modules/src/object/wr_putc.c | 8 +- modules/src/object/wr_ranlib.c | 14 ++-- 16 files changed, 219 insertions(+), 241 deletions(-) diff --git a/modules/src/object/obj.h b/modules/src/object/obj.h index 9000b32ce..02a283fd4 100644 --- a/modules/src/object/obj.h +++ b/modules/src/object/obj.h @@ -3,21 +3,14 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -#include -#include + #include -#include -#include -#include -#include -#include -#include "object.h" #if ! defined(CHAR_UNSIGNED) #define CHAR_UNSIGNED 0 #endif -#define Xchar(ch) (uint32_t)(uint8_t)(ch) +#define Xchar(ch) (uint32_t)(uint8_t)(ch) #define uget2(c) (Xchar((c)[0]) | (Xchar((c)[1])<<8)) @@ -28,33 +21,33 @@ #define get4(c) ((int32_t) uget4(c)) #define put4(i, c) (put2(i, c), put2((i)>>16, (c)+2)) -#define SECTCNT 3 /* number of sections with own output buffer */ +#define SECTCNT 3 /* number of sections with own output buffer */ #if BIGMACHINE -#define WBUFSIZ (8*BUFSIZ) +#define WBUFSIZ (8*BUFSIZ) #else -#define WBUFSIZ BUFSIZ +#define WBUFSIZ BUFSIZ #endif struct fil { - int cnt; - char *pnow; - char *pbegin; - long currpos; - int fd; - char pbuf[WBUFSIZ]; + int cnt; + char *pnow; + char *pbegin; + long currpos; + FILE* fd; + char pbuf[WBUFSIZ]; }; extern struct fil __parts[]; -#define PARTEMIT 0 -#define PARTRELO (PARTEMIT+SECTCNT) -#define PARTNAME (PARTRELO+1) -#define PARTCHAR (PARTNAME+1) +#define PARTEMIT 0 +#define PARTRELO (PARTEMIT+SECTCNT) +#define PARTNAME (PARTRELO+1) +#define PARTCHAR (PARTNAME+1) #ifdef SYMDBUG -#define PARTDBUG (PARTCHAR+1) +#define PARTDBUG (PARTCHAR+1) #else -#define PARTDBUG (PARTCHAR+0) +#define PARTDBUG (PARTCHAR+0) #endif -#define NPARTS (PARTDBUG + 1) +#define NPARTS (PARTDBUG + 1) #define getsect(s) (PARTEMIT+((s)>=(SECTCNT-1)?(SECTCNT-1):(s))) diff --git a/modules/src/object/object.3 b/modules/src/object/object.3 index 6ab5cf785..70a62ce8e 100644 --- a/modules/src/object/object.3 +++ b/modules/src/object/object.3 @@ -16,147 +16,71 @@ and write ACK-object files and libraries .br .B #include .PP -.B int wr_open(filename) -.br -.B char *filename; +.B FILE* wr_open(const char *filename) .PP .B void wr_close() .PP -.B void wr_ohead(head) -.br -.B struct outhead *head; +.B void wr_ohead(struct outhead *head) .PP -.B void wr_sect(sect, cnt) -.br -.B struct outsect *sect; -.br -.B unsigned int cnt; +.B void wr_sect(struct outsect *sect, unsigned int cnt) .PP -.B void wr_outsect(sectionnr) -.br -.B int sectionnr; +.B void wr_outsect(int sectionnr) .PP -.B void wr_emit(emit, cnt) -.br -.B char *emit; -.br -.B long cnt; +.B void wr_emit(const char *emit, long cnt) .PP -.B void wr_putc(ch) +.B void wr_putc(int ch) .PP -.B void wr_relo(relo, cnt) -.br -.B struct outrelo *relo; -.br -.B unsigned int cnt; +.B void wr_relo(const struct outrelo *relo, unsigned int cnt) .PP -.B void wr_name(name, cnt) -.br -.B struct outname *name; -.br -.B unsigned int cnt; +.B void wr_name(struct outname *name, unsigned int cnt) .PP -.B void wr_string(stringaddr, cnt) -.br -.B char *stringaddr; -.br -.B long cnt; +.B void wr_string(const char *stringaddr, long cnt) .PP -.B void wr_arhdr(fd, arhdr) -.br -.B struct ar_hdr *arhdr; +.B void wr_arhdr(FILE* fd, struct ar_hdr *arhdr) .PP -.B void wr_ranlib(fd, ran, cnt) -.br -.B struct ranlib *ran; -.br -.B long cnt; +.B void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt) .PP -.B void wr_int2(fd, i) +.B void wr_int2(FILE* fd, int i) .PP -.B void wr_long(fd, l) -.br -.B long l; +.B void wr_long(FILE* fd, long l) .PP -.B void wr_bytes(fd, buf, l) -.br -.B char *buf; -.br -.B long l; +.B void wr_bytes(FILE* fd, const char* buf, long l) .PP -.B int rd_open(filename) -.br -.B char *filename; +.B int rd_open(const char *filename) .PP -.B int rd_fdopen(fd) +.B int rd_fdopen(FILE* fd) .PP .B void rd_close() .PP -.B void rd_ohead(head) -.br -.B struct outhead *head; +.B void rd_ohead(struct outhead *head) .PP -.B void rd_sect(sect, cnt) -.br -.B struct outsect *sect; -.br -.B unsigned int cnt; +.B void rd_sect(struct outsect *sect, unsigned int cnt) .PP -.B void rd_outsect(sectionnr) -.br -.B int sectionnr; +.B void rd_outsect(int sectionnr) .PP -.B void rd_emit(emit, cnt) -.br -.B char *emit; -.br -.B long cnt; +.B void rd_emit(char *emit, long cnt) .PP -.B void rd_relo(relo, cnt) -.br -.B struct outrelo *relo; -.br -.B unsigned int cnt; +.B void rd_relo(struct outrelo *relo, unsigned int cnt) .PP -.B void rd_rew_relo(head) -.br -.B struct outhead *head; +.B void rd_rew_relo(struct outhead *head) .PP -.B void rd_name(name, cnt) -.br -.B struct outname *name; -.br -.B unsigned int cnt; +.B void rd_name(struct outname *name, unsigned int cnt) .PP -.B void rd_string(stringaddr, cnt) -.br -.B char *stringaddr; -.br -.B long cnt; +.B void rd_string(char *stringaddr, long cnt) .PP -.B int rd_arhdr(fd, arhdr) -.br -.B struct ar_hdr *arhdr; +.B int rd_arhdr(FILE* fd, struct ar_hdr *arhdr) .PP -.B void rd_ranlib(fd, ran, cnt) -.br -.B struct ranlib *ran; -.br -.B long cnt; +.B void rd_ranlib(FILE* fd, struct ranlib *ran, long cnt) .PP -.B int rd_int2(fd) +.B int rd_int2(FILE* fd) .PP -.B unsigned int rd_unsigned2(fd) +.B unsigned int rd_unsigned2(FILE* fd) .PP -.B long rd_long(fd) +.B long rd_long(FILE* fd) .PP -.B void rd_bytes(fd, buf, l) -.br -.B char *buf; -.br -.B long l; +.B void rd_bytes(FILE* fd, char *buf, long l) .PP -.B int rd_fd() +.B FILE* rd_fd() .SH DESCRIPTION These routines come in handy when reading or writing ACK-object files or libraries. No checking is performed. diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c index bad012844..01da90dbc 100644 --- a/modules/src/object/rd.c +++ b/modules/src/object/rd.c @@ -1,9 +1,13 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ -#include +#include +#include +#include "out.h" +#include "object.h" #include "obj.h" /* @@ -29,7 +33,7 @@ static long offset[MAXSECT]; -static int outfile; +static FILE* outfile; static long outseek[NPARTS]; static long currpos; static long rd_base; @@ -46,7 +50,7 @@ OUTREAD(int p, char* b, long n) register long l = outseek[p]; if (currpos != l) { - lseek(outfile, l, 0); + fseek(outfile, l, SEEK_SET); } rd_bytes(outfile, b, n); l += n; @@ -57,25 +61,23 @@ OUTREAD(int p, char* b, long n) /* * Open the output file according to the chosen strategy. */ -int -rd_open(const char* f) +int rd_open(const char* f) { - if ((outfile = open(f, 0)) < 0) + if ((outfile = fopen(f, "rb")) == NULL) return 0; return rd_fdopen(outfile); } static int offcnt; -int -rd_fdopen(int fd) +int rd_fdopen(FILE* fd) { register int i; for (i = 0; i < NPARTS; i++) outseek[i] = 0; offcnt = 0; - rd_base = lseek(fd, 0L, 1); + rd_base = fseek(fd, 0L, SEEK_CUR); if (rd_base < 0) { return 0; } @@ -86,16 +88,14 @@ rd_fdopen(int fd) return 1; } -void -rd_close(void) +void rd_close(void) { - close(outfile); - outfile = -1; + fclose(outfile); + outfile = NULL; } -int -rd_fd(void) +FILE* rd_fd(void) { return outfile; } @@ -221,6 +221,10 @@ rd_string(char* addr, long len) OUTREAD(PARTCHAR, addr, len); } + + + + #ifdef SYMDBUG void rd_dbug(char* buf, long size) diff --git a/modules/src/object/rd_arhdr.c b/modules/src/object/rd_arhdr.c index a2807dbe8..98138b9ee 100644 --- a/modules/src/object/rd_arhdr.c +++ b/modules/src/object/rd_arhdr.c @@ -1,34 +1,40 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "arch.h" +#include "object.h" #include "obj.h" -int -rd_arhdr(fd, arhdr) - register struct ar_hdr *arhdr; -{ - char buf[AR_TOTAL]; - register char *c = buf; - register char *p = arhdr->ar_name; - register int i; +extern void rd_fatal(void); - i = read(fd, c, AR_TOTAL); - if (i == 0) return 0; - if (i != AR_TOTAL) { - rd_fatal(); - } - i = 14; - while (i--) { - *p++ = *c++; - } - arhdr->ar_date = ((long) get2(c)) << 16; c += 2; - arhdr->ar_date |= ((long) get2(c)) & 0xffff; c += 2; - arhdr->ar_uid = *c++; - arhdr->ar_gid = *c++; - arhdr->ar_mode = get2(c); c += 2; - arhdr->ar_size = (long) get2(c) << 16; c += 2; - arhdr->ar_size |= (long) get2(c) & 0xffff; - return 1; +int rd_arhdr(FILE* fd, register struct ar_hdr *arhdr) +{ + char buf[AR_TOTAL]; + register char *c = buf; + register char *p = arhdr->ar_name; + register size_t i; + + i = fread(c, 1, AR_TOTAL, fd); + if (i == 0) return 0; + if (i != AR_TOTAL) { + rd_fatal(); + } + i = AR_NAME_MAX; + while (i--) { + *p++ = *c++; + } + arhdr->ar_date = ((long) get2(c)) << 16; c += 2; + arhdr->ar_date |= ((long) get2(c)) & 0xffff; c += 2; + arhdr->ar_uid = *c++; + arhdr->ar_gid = *c++; + arhdr->ar_mode = get2(c); c += 2; + arhdr->ar_size = (long) get2(c) << 16; c += 2; + arhdr->ar_size |= (long) get2(c) & 0xffff; + return 1; } diff --git a/modules/src/object/rd_bytes.c b/modules/src/object/rd_bytes.c index d3554a392..099f408b1 100644 --- a/modules/src/object/rd_bytes.c +++ b/modules/src/object/rd_bytes.c @@ -4,32 +4,35 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include #include "obj.h" -#define MININT (1 << (sizeof(int) * 8 - 1)) -#define MAXCHUNK (~MININT) /* Highest count we read(2). */ +#define MININT (1 << (sizeof(int) * 8 - 1)) +#define MAXCHUNK (~MININT) /* Highest count we read(2). */ /* Unfortunately, MAXCHUNK is too large with some compilers. Put it in an int! */ static int maxchunk = MAXCHUNK; +extern void rd_fatal(void); + /* * We don't have to worry about byte order here. * Just read "cnt" bytes from file-descriptor "fd". */ -void -rd_bytes(fd, string, cnt) - register char *string; - register long cnt; +void +rd_bytes(FILE* fd, register char *string, register long cnt) { + size_t read_bytes; + while (cnt) { + register size_t n = cnt >= maxchunk ? maxchunk : cnt; - while (cnt) { - register int n = cnt >= maxchunk ? maxchunk : cnt; - - if (read(fd, string, n) != n) - rd_fatal(); - string += n; - cnt -= n; - } + read_bytes = fread(string, 1, n, fd); + if (read_bytes != n) + rd_fatal(); + string += n; + cnt -= n; + } } diff --git a/modules/src/object/rd_int2.c b/modules/src/object/rd_int2.c index 54ec352b5..cf781c831 100644 --- a/modules/src/object/rd_int2.c +++ b/modules/src/object/rd_int2.c @@ -1,12 +1,16 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "object.h" #include "obj.h" -int -rd_int2(fd) +int rd_int2(FILE* fd) { char buf[2]; diff --git a/modules/src/object/rd_long.c b/modules/src/object/rd_long.c index c05534475..a4495d4cd 100644 --- a/modules/src/object/rd_long.c +++ b/modules/src/object/rd_long.c @@ -1,12 +1,17 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "object.h" #include "obj.h" -long -rd_long(fd) + +long rd_long(FILE* fd) { char buf[4]; diff --git a/modules/src/object/rd_ranlib.c b/modules/src/object/rd_ranlib.c index 0a3d4d760..84c17b170 100644 --- a/modules/src/object/rd_ranlib.c +++ b/modules/src/object/rd_ranlib.c @@ -1,14 +1,18 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "arch.h" +#include "ranlib.h" +#include "object.h" #include "obj.h" -void -rd_ranlib(fd, ran, cnt) - register struct ranlib *ran; - register long cnt; +void rd_ranlib(FILE* fd, register struct ranlib *ran, register long cnt) { rd_bytes(fd, (char *) ran, cnt * SZ_RAN); { diff --git a/modules/src/object/rd_unsig2.c b/modules/src/object/rd_unsig2.c index 4e4ad7485..f711dd01e 100644 --- a/modules/src/object/rd_unsig2.c +++ b/modules/src/object/rd_unsig2.c @@ -1,12 +1,16 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "object.h" #include "obj.h" -unsigned int -rd_unsigned2(fd) +unsigned int rd_unsigned2(FILE* fd) { char buf[2]; diff --git a/modules/src/object/wr.c b/modules/src/object/wr.c index 7b382c0c6..d5f77e30f 100644 --- a/modules/src/object/wr.c +++ b/modules/src/object/wr.c @@ -11,8 +11,12 @@ * part. In this case #define OUTSEEK. */ -#include +#include +#include +#include "out.h" +#include "object.h" #include "obj.h" +#include "ranlib.h" /* * Parts of the output file. @@ -21,7 +25,7 @@ static long offset[MAXSECT]; struct fil __parts[NPARTS]; #ifdef OUTSEEK -static int outfile; +static FILE* outfile; static long currpos; #endif int __sectionnr; @@ -34,7 +38,7 @@ __wr_flush(struct fil *ptr) #ifdef OUTSEEK /* seek to correct position even if we aren't going to write now */ if (currpos != ptr->currpos) { - currpos = lseek(ptr->fd, ptr->currpos, 0); + currpos = fseek(ptr->fd, ptr->currpos, SEEK_SET); } #endif if (ptr->pnow > ptr->pbegin) { @@ -116,8 +120,7 @@ OUTWRITE(int p, const char *b, long n) } } -static void -BEGINSEEK(int p, long o) +static void BEGINSEEK(int p, long o) /* p = part number, o = offset in file */ { struct fil *ptr = &__parts[p]; @@ -126,7 +129,7 @@ BEGINSEEK(int p, long o) ptr->fd = outfile; ptr->currpos = o; #else - ptr->currpos = lseek(ptr->fd, o, 0); + ptr->currpos = fseek(ptr->fd, o, SEEK_SET); #endif if (p >= PARTRELO) o = 0; /* no attempt to align writes for the time being */ @@ -139,39 +142,37 @@ BEGINSEEK(int p, long o) /* * Open the output file according to the chosen strategy. */ -int -wr_open(const char *f) +int wr_open(const char *f) { struct fil *fdp; - close(creat(f, 0666)); + fclose(fopen(f,"wb")); #ifdef OUTSEEK - if ((outfile = open(f, 1)) < 0) + if ((outfile = fopen(f, "ab+")) == NULL) return 0; currpos = 0; #else /* not OUTSEEK */ for (fdp = &__parts[PARTEMIT]; fdp < &__parts[NPARTS]; fdp++) - if ((fdp->fd = open(f, 1)) < 0) + if ((fdp->fd = fopen(f, "wb+")) == NULL) return 0; #endif /* not OUTSEEK */ offcnt = 0; return 1; } -void -wr_close() +void wr_close(void) { struct fil *ptr; for (ptr = &__parts[PARTEMIT]; ptr < &__parts[NPARTS]; ptr++) { __wr_flush(ptr); #ifndef OUTSEEK - close(ptr->fd); + fclose(ptr->fd); #endif /* not OUTSEEK */ - ptr->fd = -1; + ptr->fd = NULL; } #ifdef OUTSEEK - close(outfile); + fclose(outfile); outfile = -1; #endif /* OUTSEEK */ } @@ -259,7 +260,7 @@ wr_outsect(int s) if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) { #ifdef OUTSEEK if (currpos != ptr->currpos) - currpos = lseek(ptr->fd, ptr->currpos, 0); + currpos = fseek(ptr->fd, ptr->currpos, SEEK_SET); #endif wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin)); ptr->currpos += ptr->pnow - ptr->pbegin; @@ -268,7 +269,7 @@ wr_outsect(int s) #endif offset[sectionnr] = ptr->currpos; if (offset[s] != ptr->currpos) { - ptr->currpos = lseek(ptr->fd, offset[s], 0); + ptr->currpos = fseek(ptr->fd, offset[s], SEEK_SET); #ifdef OUTSEEK currpos = ptr->currpos; #endif diff --git a/modules/src/object/wr_arhdr.c b/modules/src/object/wr_arhdr.c index ac5f2811b..e574f059b 100644 --- a/modules/src/object/wr_arhdr.c +++ b/modules/src/object/wr_arhdr.c @@ -1,18 +1,24 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "arch.h" +#include "object.h" #include "obj.h" -void -wr_arhdr(fd, arhdr) - register struct ar_hdr *arhdr; + +void wr_arhdr(FILE* fd, register struct ar_hdr *arhdr) { char buf[AR_TOTAL]; register char *c = buf; register char *p = arhdr->ar_name; - register int i = 14; + register int i = AR_NAME_MAX; while (i--) { *c++ = *p++; diff --git a/modules/src/object/wr_bytes.c b/modules/src/object/wr_bytes.c index 278d1d369..a115660a2 100644 --- a/modules/src/object/wr_bytes.c +++ b/modules/src/object/wr_bytes.c @@ -4,29 +4,38 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include #include "obj.h" -#define MININT (1 << (sizeof(int) * 8 - 1)) -#define MAXCHUNK (~MININT) /* Highest count we write(2). */ +#define MININT (1 << (sizeof(int) * 8 - 1)) +#define MAXCHUNK (~MININT) /* Highest count we write(2). */ /* Notice that MAXCHUNK itself might be too large with some compilers. You have to put it in an int! */ static const int maxchunk = MAXCHUNK; +extern void wr_fatal(void); + + /* * Just write "cnt" bytes to file-descriptor "fd". */ -void -wr_bytes(int fd, const char *string, long cnt) +void wr_bytes(FILE* fd, const char *string, long cnt) { - while (cnt) { - int n = cnt >= maxchunk ? maxchunk : cnt; + size_t written_bytes; + while (cnt) + { + int n = cnt >= maxchunk ? maxchunk : cnt; - if (write(fd, string, n) != n) - wr_fatal(); - string += n; - cnt -= n; - } + written_bytes = fwrite(string, 1, n, fd); + if (written_bytes != (size_t)n) + { + wr_fatal(); + } + string += n; + cnt -= n; + } } diff --git a/modules/src/object/wr_int2.c b/modules/src/object/wr_int2.c index 9c63ca5c8..560d3d706 100644 --- a/modules/src/object/wr_int2.c +++ b/modules/src/object/wr_int2.c @@ -1,12 +1,16 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "object.h" #include "obj.h" -void -wr_int2(fd, i) +void wr_int2(FILE* fd, int i) { char buf[2]; diff --git a/modules/src/object/wr_long.c b/modules/src/object/wr_long.c index 3900f61c3..da4cb524f 100644 --- a/modules/src/object/wr_long.c +++ b/modules/src/object/wr_long.c @@ -1,13 +1,16 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "object.h" #include "obj.h" -void -wr_long(fd, l) - long l; +void wr_long(FILE* fd, long l) { char buf[4]; diff --git a/modules/src/object/wr_putc.c b/modules/src/object/wr_putc.c index f28f2ea04..68d3dd759 100644 --- a/modules/src/object/wr_putc.c +++ b/modules/src/object/wr_putc.c @@ -1,15 +1,19 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include +#include +#include "out.h" +#include "object.h" #include "obj.h" extern int __sectionnr; void __wr_flush(struct fil *); -void -wr_putc(int ch) +void wr_putc(int ch) { struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)]; diff --git a/modules/src/object/wr_ranlib.c b/modules/src/object/wr_ranlib.c index b515ffb3b..31cc96899 100644 --- a/modules/src/object/wr_ranlib.c +++ b/modules/src/object/wr_ranlib.c @@ -1,14 +1,18 @@ /* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". */ -#include "obj.h" -void -wr_ranlib(fd, ran, cnt1) - struct ranlib *ran; - long cnt1; +#include +#include +#include "out.h" +#include "object.h" +#include "obj.h" +#include "ranlib.h" + +void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt1) { struct ranlib *r; long cnt, val; From 98d8505c6e797d649220d1fe0593ff023be87ea5 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:07:43 +0800 Subject: [PATCH 11/84] arch.h flag fixing --- h/arch.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/h/arch.h b/h/arch.h index 9d6e99cd8..fc003de41 100644 --- a/h/arch.h +++ b/h/arch.h @@ -9,9 +9,12 @@ #define ARMAG 0177545 #define AALMAG 0177454 +#define AR_NAME_MAX 14 struct ar_hdr { - char ar_name[14]; + /** null terminated filename. */ + char ar_name[AR_NAME_MAX]; + /** last modification time, defined as seconds since epoch. */ long ar_date; char ar_uid; char ar_gid; @@ -22,4 +25,33 @@ struct ar_hdr { #define AR_TOTAL 26 #define AR_SIZE 22 + +/** ar_mode Read permission bit for the owner of the file. */ +#define AR_IRUSR 0400 +/** ar_mode Write permission bit for the owner of the file. */ +#define AR_IWUSR 0200 +/** ar_mode Execute (for ordinary files) or search (for directories) + * permission bit for the owner of the file. + */ +#define AR_IXUSR 0100 +/** ar_mode Read permission bit for the group owner of the file. */ +#define AR_IRGRP 040 +/** ar_mode Write permission bit for the group owner of the file. */ +#define AR_IWGRP 020 +/** ar_mode Execute or search permission bit for the group owner of the file. */ +#define AR_IXGRP 010 +/** ar_mode Read permission bit for other users. */ +#define AR_IROTH 04 +/** ar_mode Write permission for other users. */ +#define AR_IWOTH 02 +/** ar_mode Execute or search permission bit for other users. */ +#define AR_IXOTH 01 + +/* This is the set-user-ID on execute bit. */ +#define AR_ISUID 04000 +/* This is the set-group-ID on execute bit. */ +#define AR_ISGID 02000 + + + #endif /* __ARCH_H_INCLUDED */ From a915b76300f621b10dde5fd6f33dfcdc52c92fa4 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:09:42 +0800 Subject: [PATCH 12/84] Fix crash upon error. --- fast/driver/driver.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fast/driver/driver.c b/fast/driver/driver.c index 6499683f7..4ff6358b4 100644 --- a/fast/driver/driver.c +++ b/fast/driver/driver.c @@ -355,13 +355,13 @@ char* stringdup(const char* s) char* getackhome(void) { - char *value = stringdup(getenv("ACK_HOME")); + char *value = getenv("ACK_HOME"); if (value == NULL) { #ifndef EM_DIR panic("ACK_HOME must be set."); #else - return stringdup(EM_DIR); + return EM_DIR; #endif } return value; @@ -383,12 +383,12 @@ int main(int argc, char *argv[]) char *INCLUDE = NULL; int compile_cnt = 0; - ackhome = getackhome(); + ackhome = stringdup(getackhome()); if (ackhome == NULL) { panic("ACK_HOME Environment variable is not set."); } - tmpdir = sys_gettmpdir(); + tmpdir = stringdup(sys_gettmpdir()); if (tmpdir == NULL) { panic("TMPDIR Environment variable is not set."); @@ -478,6 +478,9 @@ int main(int argc, char *argv[]) case 'M': /* use other compiler (for testing) */ strcpy(COMP, str + 2); break; + case 'P': /* use other cpp (for testing) */ + strcpy(CPP, str + 2); + break; case 's': /* strip */ if (str[2] == '\0') { @@ -663,6 +666,10 @@ int main(int argc, char *argv[]) runvec(call, (char *) 0);*/ cleanup(tmp_file); } + if ((LDFILES.al_argc == 0) && (SRCFILES.al_argc==0)) + { + panic("No input source files or input object files specified."); + } exit(RET_CODE); } From dac3d0b10c2b9ef9394524b691704dc85e4cdae8 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:10:10 +0800 Subject: [PATCH 13/84] Add function prototypes. --- mach/6500/as/mach1.c | 3 +++ mach/6500/as/mach5.c | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mach/6500/as/mach1.c b/mach/6500/as/mach1.c index 2243d1f8e..cef0ab8d2 100644 --- a/mach/6500/as/mach1.c +++ b/mach/6500/as/mach1.c @@ -9,3 +9,6 @@ */ #define fits_zeropage(x) (lowb(x) == (int)(x)) + +void branch(register int opc, expr_t exp); +void code(expr_t exp, register int opc1, register int opc2); diff --git a/mach/6500/as/mach5.c b/mach/6500/as/mach5.c index 2e073d709..53e121214 100644 --- a/mach/6500/as/mach5.c +++ b/mach/6500/as/mach5.c @@ -8,9 +8,7 @@ * Mostek 6500 special routines. */ -branch(opc, exp) -register int opc; -expr_t exp; +void branch(register int opc, expr_t exp) { register int dist; @@ -29,9 +27,7 @@ expr_t exp; } } -code(exp, opc1, opc2) -expr_t exp; -register int opc1, opc2; +void code(expr_t exp, register int opc1, register int opc2) { if (small((exp.typ & S_TYP) == S_ABS && fits_zeropage(exp.val), 1)) { emit1(opc1); emit1(exp.val); From 143da61d136bd5af412958f513e52cbcf6acd5ce Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:10:20 +0800 Subject: [PATCH 14/84] Add function prototypes. --- mach/6800/as/mach1.c | 3 +++ mach/6800/as/mach5.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mach/6800/as/mach1.c b/mach/6800/as/mach1.c index b23265cf2..90e90b031 100644 --- a/mach/6800/as/mach1.c +++ b/mach/6800/as/mach1.c @@ -7,3 +7,6 @@ /* * Motorola 6800 C declarations */ + +void branch(register int opc, expr_t exp); + diff --git a/mach/6800/as/mach5.c b/mach/6800/as/mach5.c index 50a8b2233..e14f7d098 100644 --- a/mach/6800/as/mach5.c +++ b/mach/6800/as/mach5.c @@ -8,8 +8,9 @@ * Motorola 6800 special routines */ -branch(opc,exp) register opc; expr_t exp; { - register sm, dist; +void branch(register int opc,expr_t exp) +{ + register int sm, dist; int saving; dist = exp.val - (DOTVAL + 2); From 2dd0d0f81b58cd0e8be298f343b5229a649e3ffc Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:10:32 +0800 Subject: [PATCH 15/84] Add function prototypes. --- mach/6805/as/mach1.c | 2 ++ mach/6805/as/mach4.c | 5 ++++- mach/6805/as/mach5.c | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mach/6805/as/mach1.c b/mach/6805/as/mach1.c index 59e4829ed..2a5893ea8 100644 --- a/mach/6805/as/mach1.c +++ b/mach/6805/as/mach1.c @@ -11,3 +11,5 @@ extern int opt_cmos; #define fitj(z) ((unsigned)z + 0x80 <= 0xFF) + +void branch(register int opc,expr_t exp,expr_t cell); diff --git a/mach/6805/as/mach4.c b/mach/6805/as/mach4.c index c4019440b..0e906bb2a 100644 --- a/mach/6805/as/mach4.c +++ b/mach/6805/as/mach4.c @@ -31,7 +31,10 @@ operation { emit1($1);} | BRANCH expr - { branch($1,$2);} + { + /* Empty expression */ + struct expr_t expr = {0,0}; + branch($1,$2,expr);} | BBRANCH bitexp ',' expr8 ',' expr { diff --git a/mach/6805/as/mach5.c b/mach/6805/as/mach5.c index 630d25aab..223bdbf3d 100644 --- a/mach/6805/as/mach5.c +++ b/mach/6805/as/mach5.c @@ -9,8 +9,9 @@ */ /* VARARGS2 */ -branch(opc,exp,cell) register opc; expr_t cell; expr_t exp; { - register sm, dist; +void branch(register int opc,expr_t exp,expr_t cell) +{ + register int sm, dist; int saving; dist = exp.val - (DOTVAL + 2); From 2f84fc92cfdc53234fdc2161e204de7acf999e31 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:10:45 +0800 Subject: [PATCH 16/84] Add function prototypes. --- mach/6809/as/mach1.c | 7 +++++++ mach/6809/as/mach4.c | 2 +- mach/6809/as/mach5.c | 14 ++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mach/6809/as/mach1.c b/mach/6809/as/mach1.c index 21ce06cf3..12200b55a 100644 --- a/mach/6809/as/mach1.c +++ b/mach/6809/as/mach1.c @@ -42,3 +42,10 @@ int regbit[] = { /* push-pull coding */ #define B 9 #define CC 10 #define DP 11 + + +/* Motorola 6809 specific routines */ +void branch(register int opc, expr_t exp); +int regno(register int r); +void emit1or2(int n); +void offset(register int reg, expr_t exp, register int ind); diff --git a/mach/6809/as/mach4.c b/mach/6809/as/mach4.c index 16853aedc..81979b44d 100644 --- a/mach/6809/as/mach4.c +++ b/mach/6809/as/mach4.c @@ -167,7 +167,7 @@ reglist : ALL { if (($$ = regbit[$1]) < 0) serror("register error");} | reglist ',' REG - { register i; + { register int i; if ((i = regbit[$3]) < 0 || ($1 & i) != 0) serror("register error"); $$ = $1 | i; diff --git a/mach/6809/as/mach5.c b/mach/6809/as/mach5.c index 75e0d5c10..58d80a6de 100644 --- a/mach/6809/as/mach5.c +++ b/mach/6809/as/mach5.c @@ -8,9 +8,7 @@ * Motorola 6809 special routines */ -branch(opc, exp) -register int opc; -expr_t exp; +void branch(register int opc, expr_t exp) { register int sm, dist; int saving; @@ -47,7 +45,8 @@ expr_t exp; emit1(lowb(dist)); } -regno(r) register r; { +int regno(register int r) +{ switch (r) { case X: return 0; case Y: return 0x20; @@ -57,15 +56,14 @@ regno(r) register r; { return -1; } -emit1or2(n) { +void emit1or2(int n) +{ if (n & ~0xFF) emit1(n >> 8); emit1(n); } -offset(reg, exp, ind) -register int reg, ind; -expr_t exp; +void offset(register int reg, expr_t exp, register int ind) { if (reg == PC) { int sm, dist; From 053c509fc9a17bce8459ab2aa38b53c9bebdae60 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:10:58 +0800 Subject: [PATCH 17/84] Add function prototypes. --- mach/arm/as/mach1.c | 13 ++++++++++++ mach/arm/as/mach5.c | 48 +++++++++++++-------------------------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/mach/arm/as/mach1.c b/mach/arm/as/mach1.c index 69ad511e2..6f209ab4a 100644 --- a/mach/arm/as/mach1.c +++ b/mach/arm/as/mach1.c @@ -1,3 +1,16 @@ /* $Header; mach1.c, v1.1 06-Mar-89 AJM */ extern word_t opcode; extern int success; /* LDR/STR address failure flag */ + + +/* ARM32 Specific routines */ +void branch(word_t brtyp, word_t link, valu_t val); +void data(long opc, long ins, valu_t val, short typ); +int calcimm(word_t *opc, valu_t *val,short typ); +word_t calcoffset(valu_t val); +void strldr(long opc, long ins, valu_t val); +void calcadr(word_t ins, word_t reg, valu_t val, short typ); +word_t calcshft(valu_t val, short typ, word_t styp); +void rotateleft2(long *x); +void putaddr(long opc, long ins, long val, int count); +int oursmall(int fitsmall, int gain); diff --git a/mach/arm/as/mach5.c b/mach/arm/as/mach5.c index 1eedbaf8d..8c38dee72 100644 --- a/mach/arm/as/mach5.c +++ b/mach/arm/as/mach5.c @@ -1,9 +1,6 @@ /* $Id: mach5.c, v3.3 25-Apr-89 AJM */ -branch(brtyp, link, val) -word_t brtyp; -word_t link; -valu_t val; +void branch(word_t brtyp, word_t link, valu_t val) { valu_t offset; @@ -16,10 +13,7 @@ valu_t val; return; } -data(opc, ins, val, typ) -long opc, ins; -valu_t val; -short typ; +void data(long opc, long ins, valu_t val, short typ) { valu_t tmpval; int adrflag = 0; @@ -92,10 +86,7 @@ short typ; 12-bit field. Unfortunately this means that some numbers may not fit at all. */ -calcimm(opc,val,typ) -word_t *opc; -valu_t *val; -short typ; +int calcimm(word_t *opc, valu_t *val,short typ) { int i = 0; @@ -176,9 +167,7 @@ short typ; /* Calculate an offset in an address */ -word_t -calcoffset(val) -valu_t val; +word_t calcoffset(valu_t val) { if((val & 0xFFFFF000) == 0) return(val|0x00800000); @@ -192,9 +181,7 @@ valu_t val; /* This routine deals with STR and LDR instructions */ -strldr(opc, ins, val) -long opc, ins; -valu_t val; +void strldr(long opc, long ins, valu_t val) { long reg, reg2; /* The registers we are using */ @@ -310,10 +297,7 @@ valu_t val; optimisation problem with mobile addresses ! */ -calcadr(ins, reg, val, typ) -word_t ins, reg; -valu_t val; -short typ; +void calcadr(word_t ins, word_t reg, valu_t val, short typ) { valu_t tmpval = val; word_t opc = 0xff; /* Dummy opc used as a flag for data() */ @@ -336,11 +320,7 @@ short typ; } -word_t -calcshft(val, typ, styp) -valu_t val; -short typ; -word_t styp; +word_t calcshft(valu_t val, short typ, word_t styp) { if (typ == S_UND) return(0); @@ -354,8 +334,7 @@ word_t styp; return((val & 0x1F)<<7); } -rotateleft2(x) -long *x; +void rotateleft2(long *x) { unsigned long bits; @@ -380,9 +359,7 @@ long *x; less instruction, because that will upset other addresses. */ -putaddr(opc, ins, val, count) -long opc, ins, val; -int count; +void putaddr(long opc, long ins, long val, int count) { long tmpval = val; long reg = ins & 0x0000F000; @@ -448,9 +425,9 @@ int count; #define PBITTABSZ 128 static char *pbittab[PBITTABSZ]; -oursmall(fitsmall, gain) +int oursmall(int fitsmall, int gain) { - register bit; + register int bit; register char *p; if (DOTSCT == NULL) @@ -505,6 +482,9 @@ oursmall(fitsmall, gain) serror("This one is fatal!"); } return(*p & bit); + default: + assert(0); + } /*NOTREACHED*/ } From ef3a6b3cc4c962df1c1e978f95786ae79683c85e Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:11:19 +0800 Subject: [PATCH 18/84] Add function prototypes. --- mach/i86/as/mach1.c | 18 +++++++++++++ mach/i86/as/mach5.c | 61 ++++++++++++++++++++++++++------------------- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/mach/i86/as/mach1.c b/mach/i86/as/mach1.c index b36ed5601..93ec0cbd5 100644 --- a/mach/i86/as/mach1.c +++ b/mach/i86/as/mach1.c @@ -42,3 +42,21 @@ char dr_m[8][8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; #endif + +/* 8086 specific routines */ +void ea_1(int param); +void ea_2(int param); +void reverse(void); +void badsyntax(void); +void regsize(register int sz); +void indexed(void); +void branch(register int opc,expr_t exp); +void pushop(register int opc); +void addop(register int opc); +void rolop(register int opc); +void incop(register int opc); +void callop(register int opc); +void xchg(register int opc); +void test(register int opc); +void mov(register int opc); +void imul(int opc); diff --git a/mach/i86/as/mach5.c b/mach/i86/as/mach5.c index f8805c064..097c8cd43 100644 --- a/mach/i86/as/mach5.c +++ b/mach/i86/as/mach5.c @@ -8,7 +8,8 @@ * INTEL 8086 special routines */ -ea_1(param) { +void ea_1(int param) +{ if ((mrg_1 & 070) || (param & ~070)) { serror("bad operand"); @@ -41,7 +42,7 @@ ea_1(param) { } } -ea_2(param) { +void ea_2(int param) { mrg_1 = mrg_2; exp_1 = exp_2; @@ -49,8 +50,10 @@ ea_2(param) { ea_1(param); } -reverse() { - register m, r; expr_t e; +void reverse(void) +{ + register int m, r; + expr_t e; m = mrg_1; mrg_1 = mrg_2; mrg_2 = m; e = exp_1; exp_1 = exp_2; exp_2 = e; @@ -59,13 +62,15 @@ reverse() { #endif } -badsyntax() { +void badsyntax(void) +{ serror("bad operands"); } -regsize(sz) register sz; { - register bit; +void regsize(register int sz) +{ + register int bit; sz <<= 3; bit = 010; @@ -77,7 +82,8 @@ regsize(sz) register sz; { mrg_2 &= ~bit; } -indexed() { +void indexed(void) +{ int sm1, sm2; if (mrg_2 & ~7) @@ -98,8 +104,9 @@ indexed() { } } -branch(opc,exp) register opc; expr_t exp; { - register sm,dist; +void branch(register int opc,expr_t exp) +{ + register int sm,dist; int saving = opc == 0353 ? 1 : 3; dist = exp.val - (DOTVAL + 2); @@ -132,7 +139,8 @@ branch(opc,exp) register opc; expr_t exp; { emit1(dist); } -pushop(opc) register opc; { +void pushop(register int opc) +{ regsize(1); if (mrg_1 & 020) { @@ -161,8 +169,8 @@ pushop(opc) register opc; { } } -addop(opc) register opc; { - +void addop(register int opc) +{ regsize(opc); if (mrg_2 >= 0300) { emit1(opc); ea_1((mrg_2&7)<<3); @@ -197,8 +205,9 @@ addop(opc) register opc; { badsyntax(); } -rolop(opc) register opc; { - register cmrg; +void rolop(register int opc) +{ + register int cmrg; cmrg = mrg_2; mrg_2 = mrg_1; @@ -217,7 +226,8 @@ rolop(opc) register opc; { badsyntax(); } -incop(opc) register opc; { +void incop(register int opc) +{ regsize(opc); if ((opc&1) && mrg_1>=0300) { @@ -228,8 +238,8 @@ incop(opc) register opc; { } } -callop(opc) register opc; { - +void callop(register int opc) +{ regsize(1); if (mrg_1 & 040) { if (opc == (040+(0351<<8))) { @@ -249,8 +259,8 @@ callop(opc) register opc; { } } -xchg(opc) register opc; { - +void xchg(register int opc) +{ regsize(opc); if (mrg_2 == 0300 || mrg_1 < 0300) reverse(); @@ -262,8 +272,8 @@ xchg(opc) register opc; { badsyntax(); } -test(opc) register opc; { - +void test(register int opc) +{ regsize(opc); if ((mrg_1 & 040) || mrg_2 >= 0300) reverse(); @@ -288,8 +298,8 @@ test(opc) register opc; { badsyntax(); } -mov(opc) register opc; { - +void mov(register int opc) +{ regsize(opc); if (mrg_1 & 020) { emit1(0216); ea_2((mrg_1&3)<<3); @@ -334,8 +344,7 @@ mov(opc) register opc; { } } -imul(opc) - int opc; +void imul(int opc) { regsize(opc); if (exp_2.typ != S_ABS || ((mrg_2 & 040) == 0)) { From 98c5d1f0ee7eca5a4a6039ee1c3a53fa0aa4813b Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:11:31 +0800 Subject: [PATCH 19/84] Add function prototypes. --- mach/i386/as/mach1.c | 25 ++++++++++++++++ mach/i386/as/mach5.c | 69 +++++++++++++++----------------------------- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/mach/i386/as/mach1.c b/mach/i386/as/mach1.c index 3538958bb..f6c51264c 100644 --- a/mach/i386/as/mach1.c +++ b/mach/i386/as/mach1.c @@ -100,3 +100,28 @@ char dr_m[8][8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; #endif + +/* 80386 specific routines */ +void ea_1_16(int param); +void ea_1(int param); +void ea_2(int param); +int checkscale(valu_t val); +void reverse(void); +void badsyntax(void); +void regsize(int sz); +void indexed(void); +void ebranch(register int opc,expr_t exp); +void branch(register int opc,expr_t exp); +void pushop(register int opc); +void opsize_exp(expr_t exp, int nobyte); +void adsize_exp(expr_t exp, int relpc); +void addop(register int opc); +void rolop(register int opc); +void incop(register int opc); +void callop(register int opc); +void xchg(register int opc); +void test(register int opc); +void mov(register int opc); +void extshft(int opc, int reg); +void bittestop(int opc); +void imul(int reg); diff --git a/mach/i386/as/mach5.c b/mach/i386/as/mach5.c index 8d638c922..4c07402fb 100644 --- a/mach/i386/as/mach5.c +++ b/mach/i386/as/mach5.c @@ -8,7 +8,7 @@ * INTEL 80386 special routines */ -ea_1_16(param) +void ea_1_16(int param) { reg_1 &= 0377; if ((reg_1 & 070) || (param & ~070)) { @@ -38,8 +38,7 @@ ea_1_16(param) } } -void -ea_1(param) { +void ea_1(int param) { if (! address_long) { ea_1_16(param); return; @@ -71,16 +70,14 @@ ea_1(param) { } } -ea_2(param) { +void ea_2(int param) { op_1 = op_2; RELOMOVE(rel_1, rel_2); ea_1(param); } -int -checkscale(val) - valu_t val; +int checkscale(valu_t val) { int v = val; @@ -105,7 +102,7 @@ checkscale(val) /*NOTREACHED*/ } -reverse() { +void reverse(void) { struct operand op; #ifdef RELOCATION int r = rel_1; @@ -115,13 +112,13 @@ reverse() { op = op_1; op_1 = op_2; op_2 = op; } -badsyntax() { +void badsyntax(void) +{ serror("bad operands"); } -regsize(sz) - int sz; +void regsize(int sz) { register int bit; @@ -135,8 +132,7 @@ regsize(sz) } } -void -indexed() { +void indexed(void) { if (address_long) { mod_2 = 0; if (sib_2 == -1) @@ -175,9 +171,7 @@ indexed() { } } -ebranch(opc,exp) - register int opc; - expr_t exp; +void ebranch(register int opc,expr_t exp) { /* Conditional branching; Full displacements are available on the 80386, so the welknown trick with the reverse branch @@ -220,9 +214,7 @@ ebranch(opc,exp) } } -branch(opc,exp) - register int opc; - expr_t exp; +void branch(register int opc,expr_t exp) { /* LOOP, JCXZ, etc. branch instructions. Here, the offset just must fit in a byte. @@ -237,8 +229,7 @@ branch(opc,exp) emit1((int)dist); } -pushop(opc) - register int opc; +void pushop(register int opc) { regsize(1); @@ -274,8 +265,7 @@ pushop(opc) } } -opsize_exp(exp, nobyte) - expr_t exp; +void opsize_exp(expr_t exp, int nobyte) { if (! nobyte) { #ifdef RELOCATION @@ -297,8 +287,7 @@ opsize_exp(exp, nobyte) } } -adsize_exp(exp, relpc) - expr_t exp; +void adsize_exp(expr_t exp, int relpc) { if (address_long) { #ifdef RELOCATION @@ -314,8 +303,7 @@ adsize_exp(exp, relpc) } } -addop(opc) - register int opc; +void addop(register int opc) { regsize(opc); @@ -348,8 +336,7 @@ addop(opc) badsyntax(); } -rolop(opc) - register int opc; +void rolop(register int opc) { register int oreg; @@ -378,8 +365,7 @@ rolop(opc) badsyntax(); } -incop(opc) - register int opc; +void incop(register int opc) { regsize(opc); @@ -392,8 +378,7 @@ incop(opc) } } -callop(opc) - register int opc; +void callop(register int opc) { regsize(1); @@ -412,8 +397,7 @@ callop(opc) } } -xchg(opc) - register int opc; +void xchg(register int opc) { regsize(opc); @@ -428,8 +412,7 @@ xchg(opc) badsyntax(); } -test(opc) - register int opc; +void test(register int opc) { regsize(opc); @@ -453,8 +436,7 @@ test(opc) badsyntax(); } -mov(opc) - register int opc; +void mov(register int opc) { regsize(opc); @@ -495,8 +477,7 @@ mov(opc) badsyntax(); } -extshft(opc, reg) - int opc; +void extshft(int opc, int reg) { int oreg2 = reg_2; @@ -521,8 +502,7 @@ extshft(opc, reg) else badsyntax(); } -bittestop(opc) - int opc; +void bittestop(int opc) { regsize(1); emit1(0xF); @@ -542,8 +522,7 @@ bittestop(opc) else badsyntax(); } -imul(reg) - int reg; +void imul(int reg) { /* This instruction is more elaborate on the 80386. Its most general form is: From 180d3388d6563509b80b5eff26aabd273e3189ee Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:11:43 +0800 Subject: [PATCH 20/84] Add function prototypes. --- mach/m68k2/as/mach1.c | 30 ++++++++++++++++ mach/m68k2/as/mach5.c | 79 ++++++++++++++++++++----------------------- 2 files changed, 67 insertions(+), 42 deletions(-) diff --git a/mach/m68k2/as/mach1.c b/mach/m68k2/as/mach1.c index 173556b5c..adbd5cb2e 100644 --- a/mach/m68k2/as/mach1.c +++ b/mach/m68k2/as/mach1.c @@ -76,3 +76,33 @@ short eamode[] = { /* 074L */ DTA|MEM |PUTL | (RELO4 )<<8, }; #endif + +/* 680x0 specific instructions */ +void ea_1(int sz, int bits); +void ea_2(int sz, int bits); +void indexmode(int hibyte); +void checksize(int sz, int bits); +void test68010(void); +void badoperand(void); +void shift_op(int opc, int sz); +void bitop(int opc); +void add(int opc, int sz); +void and(int opc, int sz); +int to_dreg(int opc, int sz, int bits); +int from_dreg(int opc, int sz, int bits); +void cmp(int sz); +void move(int sz); +void move_special(int sz); +int reverse(register int regs, int max); +void movem(int dr, int sz, int regs); +void movep(int sz); +void branch(int opc, expr_t exp); +void ea5x73(int rg, int sz); +void ea707172(int sz); +void ea6x(int rg, int ir, int sz); +void ea72(void); +void ea73(int ri, int sz); +void Xnofit(void); +void fbranch(int opc, expr_t exp); +void ch_sz_dreg(int size, int mode); +void check_fsize(int sz, int size); diff --git a/mach/m68k2/as/mach5.c b/mach/m68k2/as/mach5.c index bde0f6580..9e121f4e4 100644 --- a/mach/m68k2/as/mach5.c +++ b/mach/m68k2/as/mach5.c @@ -8,8 +8,7 @@ * Motorola 68000/68010 auxiliary functions */ -static int -extension_offset() +static int extension_offset(void) { switch(curr_instr) { case MOVEM: @@ -25,9 +24,9 @@ extension_offset() return 2; } -ea_1(sz, bits) +void ea_1(int sz, int bits) { - register flag; + register int flag; if (mrg_1 > 074) serror("no specials"); @@ -61,7 +60,7 @@ ea_1(sz, bits) emit2(loww(exp_1.val)); } -ea_2(sz, bits) +void ea_2(int sz, int bits) { mrg_1 = mrg_2; exp_1 = exp_2; @@ -69,30 +68,30 @@ ea_2(sz, bits) ea_1(sz, bits); } -indexmode(hibyte) +void indexmode(int hibyte) { Xfit(fitb(exp_2.val)); exp_2.val = hibyte | lowb(exp_2.val); } -checksize(sz, bits) +void checksize(int sz, int bits) { if ((bits & (1 << (sz>>6))) == 0) serror("bad size"); } -test68010() +void test68010(void) { if (model != 1 && pass == PASS_3) warning("68010 instruction"); } -badoperand() +void badoperand(void) { serror("bad operands"); } -shift_op(opc, sz) +void shift_op(int opc, int sz) { if (mrg_1 < 010 && mrg_2 < 010) { emit2((opc&0170470) | sz | mrg_1<<9 | mrg_2); @@ -113,9 +112,9 @@ shift_op(opc, sz) ea_2(SIZE_W, MEM|ALT); } -bitop(opc) +void bitop(int opc) { - register bits; + register int bits; bits = DTA|ALT; if (opc == 0 && (mrg_1 < 010 || mrg_2 != 074)) @@ -134,7 +133,7 @@ bitop(opc) badoperand(); } -add(opc, sz) +void add(int opc, int sz) { if ((mrg_2 & 070) == 010) checksize(sz, 2|4); @@ -168,7 +167,7 @@ add(opc, sz) badoperand(); } -and(opc, sz) +void and(int opc, int sz) { if (mrg_1 == 074 && mrg_2 >= 076) { /* ccr or sr */ if (sz != SIZE_NON) @@ -194,7 +193,7 @@ and(opc, sz) badoperand(); } -to_dreg(opc, sz, bits) +int to_dreg(int opc, int sz, int bits) { if ((mrg_2 & 070) != 000) return(0); @@ -203,7 +202,7 @@ to_dreg(opc, sz, bits) return(1); } -from_dreg(opc, sz, bits) +int from_dreg(int opc, int sz, int bits) { if ((mrg_1 & 070) != 000) return(0); @@ -212,9 +211,9 @@ from_dreg(opc, sz, bits) return(1); } -cmp(sz) +void cmp(int sz) { - register opc; + register int opc; if ((mrg_1&070) == 030 && (mrg_2&070) == 030) { emit2(0130410 | sz | (mrg_1&7) | (mrg_2&7)<<9); @@ -259,9 +258,9 @@ cmp(sz) badoperand(); } -move(sz) +void move(int sz) { - register opc; + register int opc; if (mrg_1 > 074 || mrg_2 > 074) { move_special(sz); @@ -291,7 +290,7 @@ move(sz) ea_2(sz, ALT); } -move_special(sz) +void move_special(int sz) { if (mrg_2 >= 076) { if (sz != SIZE_NON) @@ -322,9 +321,7 @@ move_special(sz) badoperand(); } -int -reverse(regs, max) - register int regs; +int reverse(register int regs, int max) { register int r, i; @@ -337,9 +334,9 @@ reverse(regs, max) return regs; } -movem(dr, sz, regs) +void movem(int dr, int sz, int regs) { - register i; + register int i; if ((mrg_2>>3) == 04) { regs = reverse(regs, 16); @@ -359,7 +356,7 @@ movem(dr, sz, regs) ea_2(sz, i); } -movep(sz) +void movep(int sz) { checksize(sz, 2|4); if (mrg_1<010 && (mrg_2&070)==050) { @@ -375,10 +372,9 @@ movep(sz) badoperand(); } -branch(opc, exp) -expr_t exp; +void branch(int opc, expr_t exp) { - register sm; + register int sm; exp.val -= (DOTVAL + 2); if ((pass == PASS_2) @@ -406,7 +402,7 @@ expr_t exp; } } -ea5x73(rg, sz) +void ea5x73(int rg, int sz) { if ((exp_2.typ & ~S_DOT) == DOTTYP) { /* pc relative with index */ @@ -426,9 +422,9 @@ ea5x73(rg, sz) badoperand(); } -ea707172(sz) +void ea707172(int sz) { - register sm; + register int sm; mrg_2 = 071; switch (sz) { @@ -474,20 +470,20 @@ ea707172(sz) } } -ea6x(rg, ir, sz) +void ea6x(int rg, int ir, int sz) { mrg_2 = 060 | rg; checksize(sz, 2|4); indexmode(ir<<12 | (sz&0200)<<4); } -ea72() +void ea72(void) { mrg_2 = 072; exp_2.val -= (DOTVAL + extension_offset()); } -ea73(ri, sz) +void ea73(int ri, int sz) { mrg_2 = 073; exp_2.val -= (DOTVAL + extension_offset()); @@ -495,15 +491,14 @@ ea73(ri, sz) indexmode(ri<<12 | (sz&0200)<<4); } -Xnofit() +void Xnofit(void) { if (pass == PASS_3) serror("too big"); } -fbranch(opc, exp) -expr_t exp; +void fbranch(int opc, expr_t exp) { - register sm; + register int sm; exp.val -= (DOTVAL + 2); if ((pass == PASS_2) @@ -528,14 +523,14 @@ expr_t exp; emit4(exp.val); } -ch_sz_dreg(size, mode) +void ch_sz_dreg(int size, int mode) { if (mode == 0 && (size == FSIZE_X || size == FSIZE_P || size == FSIZE_D)) serror("illegal size for data register"); } -check_fsize(sz, size) +void check_fsize(int sz, int size) { if (sz != size) serror("bad size"); } From 1636b9b52dde86a065f6a2f4dd689e3b6de4c39b Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:11:55 +0800 Subject: [PATCH 21/84] Add function prototypes. --- mach/m68020/as/mach1.c | 41 ++++++++++++++++ mach/m68020/as/mach5.c | 108 ++++++++++++++++------------------------- 2 files changed, 82 insertions(+), 67 deletions(-) diff --git a/mach/m68020/as/mach1.c b/mach/m68020/as/mach1.c index fa620c8cb..0e0ac10c0 100644 --- a/mach/m68020/as/mach1.c +++ b/mach/m68020/as/mach1.c @@ -119,3 +119,44 @@ short eamode[] = { * '(expression).w', which still have to be relocatable. */ #endif + +/* 680x0 specific routines */ +void emit_instr(void); + +#ifdef RELOCATION +void t_emit2(short word, short relotype, int reloinfo, valu_t relnm); +#else +void t_emit2(short word); +#endif + +#ifdef RELOCATION +void t_emit4(long words, short relotype, int reloinfo, valu_t relnm); +#else +void t_emit4(long words); +#endif + +void ea_1(int sz, int bits); +void ea_2(int sz, int bits); +void checksize(int sz, int bits); +void check_fsize(int sz, int size); +void ch_sz_dreg(int size, int mode); +int checkscale(valu_t val); +void badoperand(void); +void shift_op(int opc, int sz); +void bitop(int opc); +void bitfield(int opc, int extension); +void add(int opc, int sz); +void and(int opc, int sz); +int to_dreg(int opc, int sz, int bits); +int from_dreg(int opc, int sz, int bits); +void cmp(int sz); +void link_instr(int sz, int areg); +void move(int sz); +void move_special(int sz); +void movem(int dr, int sz, int regs); +int reverse(register int regs, int max); +void movep(int sz); +void branch(int opc, expr_t exp); +void cpbcc(int opc, expr_t exp); +void ea7071(int sz); +void fbranch(int opc, expr_t exp); diff --git a/mach/m68020/as/mach5.c b/mach/m68020/as/mach5.c index e623bd01f..8a82b6313 100644 --- a/mach/m68020/as/mach5.c +++ b/mach/m68020/as/mach5.c @@ -21,9 +21,9 @@ * then emitted in one go, by emit_instr(). */ -void move_special(); -emit_instr() + +void emit_instr(void) { register instr_t *ip; @@ -38,17 +38,13 @@ emit_instr() #ifdef RELOCATION -t_emit2(word, relotype, reloinfo, relnm) -short word; -short relotype; -valu_t relnm; +void t_emit2(short word, short relotype, int reloinfo, valu_t relnm) #else -t_emit2(word) -short word; +void t_emit2(short word) #endif { #ifdef RELOCATION - if (instrp->i_reloinfo = reloinfo) { + if ((instrp->i_reloinfo = reloinfo)) { RELOMOVE(instrp->i_relonami, relnm); instrp->i_relotype = relotype; } @@ -59,21 +55,16 @@ short word; } #ifdef RELOCATION -t_emit4(words, relotype, reloinfo, relnm) -long words; -short relotype; -valu_t relnm; +void t_emit4(long words, short relotype, int reloinfo, valu_t relnm) #else -t_emit4(words) -long words; +void t_emit4(long words) #endif { T_EMIT2((short)(words>>16), relotype, reloinfo, relnm); T_EMIT2((short)(words), 0, 0, 0); } -void -ea_1(sz, bits) +void ea_1(int sz, int bits) { /* Because displacements come in three sizes (null displacement, * word and long displacement), each displacement requires @@ -81,8 +72,8 @@ ea_1(sz, bits) * one of these calls is a dummy call. */ - register flag; - register sm, sm1, sm2; + register int flag; + register int sm, sm1, sm2; if (mrg_1 > 074) serror("no specials"); @@ -195,7 +186,7 @@ ea_1(sz, bits) T_EMIT2(loww(bd_1.val), bd_1.typ, (flag>>8), bd_rel1); } -ea_2(sz, bits) +void ea_2(int sz, int bits) { mrg_1 = mrg_2; bd_1 = bd_2; @@ -206,27 +197,26 @@ ea_2(sz, bits) ea_1(sz, bits); } -checksize(sz, bits) +void checksize(int sz, int bits) { if ((bits & (1 << (sz>>6))) == 0) serror("bad size"); } -check_fsize(sz, size) +void check_fsize(int sz, int size) { if (sz != size) serror("bad size"); } -ch_sz_dreg(size, mode) +void ch_sz_dreg(int size, int mode) { if (mode == 0 && (size == FSIZE_X || size == FSIZE_P || size == FSIZE_D)) serror("illegal size for data register"); } -checkscale(val) -valu_t val; +int checkscale(valu_t val) { int v = val; @@ -240,13 +230,12 @@ valu_t val; } } -badoperand() +void badoperand(void) { serror("bad operand(s)"); } -void -shift_op(opc, sz) +void shift_op(int opc, int sz) { if (mrg_1 < 010 && mrg_2 < 010) { T_EMIT2((opc & 0170470) | sz | mrg_1<<9 | mrg_2, 0, 0, 0); @@ -267,10 +256,9 @@ shift_op(opc, sz) ea_2(SIZE_W, MEM|ALT); } -void -bitop(opc) +void bitop(int opc) { - register bits; + register int bits; bits = DTA|ALT; if (opc == 0 && (mrg_1 < 010 || mrg_2 != 074)) @@ -289,15 +277,14 @@ bitop(opc) badoperand(); } -bitfield(opc, extension) +void bitfield(int opc, int extension) { T_EMIT2(opc | mrg_2, 0, 0, 0); T_EMIT2(extension, 0, 0, 0); ea_2(SIZE_L, (mrg_2 < 010) ? 0 : (CTR | ALT)); } -void -add(opc, sz) +void add(int opc, int sz) { if ((mrg_2 & 070) == 010) checksize(sz, 2|4); @@ -332,8 +319,7 @@ add(opc, sz) badoperand(); } -void -and(opc, sz) +void and(int opc, int sz) { if (mrg_1 == 074 && mrg_2 >= 076) { /* ccr or sr */ if (sz != SIZE_NON) @@ -359,7 +345,7 @@ and(opc, sz) badoperand(); } -to_dreg(opc, sz, bits) +int to_dreg(int opc, int sz, int bits) { if ((mrg_2 & 070) != 000) return(0); @@ -368,7 +354,7 @@ to_dreg(opc, sz, bits) return(1); } -from_dreg(opc, sz, bits) +int from_dreg(int opc, int sz, int bits) { if ((mrg_1 & 070) != 000) return(0); @@ -377,10 +363,9 @@ from_dreg(opc, sz, bits) return(1); } -void -cmp(sz) +void cmp(int sz) { - register opc; + register int opc; if ((mrg_1&070) == 030 && (mrg_2&070) == 030) { T_EMIT2(0130410 | sz | (mrg_1&7) | (mrg_2&7)<<9, 0, 0, 0); @@ -408,7 +393,7 @@ cmp(sz) badoperand(); } -link_instr(sz, areg) +void link_instr(int sz, int areg) { if (sz == SIZE_NON) { if (bd_2.typ == S_ABS && fitw(bd_2.val)) @@ -424,10 +409,9 @@ link_instr(sz, areg) ea_2(sz, 0); } -void -move(sz) +void move(int sz) { - register opc; + register int opc; if (mrg_1 > 074 || mrg_2 > 074) { move_special(sz); @@ -457,8 +441,7 @@ move(sz) ea_2(sz, ALT); } -void -move_special(sz) +void move_special(int sz) { if (mrg_2 >= 076) { if (sz != SIZE_NON) @@ -487,9 +470,9 @@ move_special(sz) badoperand(); } -movem(dr, sz, regs) +void movem(int dr, int sz, int regs) { - register i; + register int i; if ((mrg_2>>3) == 04) { regs = reverse(regs, 16); @@ -509,8 +492,7 @@ movem(dr, sz, regs) ea_2(sz, i); } -reverse(regs, max) - register int regs; +int reverse(register int regs, int max) { register int r, i; @@ -524,8 +506,7 @@ reverse(regs, max) return regs; } -void -movep(sz) +void movep(int sz) { checksize(sz, 2|4); if (mrg_1<010 && (mrg_2&070)==050) { @@ -541,11 +522,9 @@ movep(sz) badoperand(); } -void -branch(opc, exp) -expr_t exp; +void branch(int opc, expr_t exp) { - register sm; + register int sm; exp.val -= (DOTVAL + 2); if ((pass == PASS_2) @@ -578,11 +557,9 @@ expr_t exp; T_EMIT4(exp.val, exp.typ, RELPC|RELO4, relonami); } -void -cpbcc(opc, exp) -expr_t exp; +void cpbcc(int opc, expr_t exp) { - register sm; + register int sm; exp.val -= (DOTVAL + 2); if ((pass == PASS_2) @@ -606,8 +583,7 @@ expr_t exp; T_EMIT4(exp.val, exp.typ, RELPC|RELO4, relonami); } -void -ea7071(sz) +void ea7071(int sz) { mrg_2 = 071; switch (sz) { @@ -685,11 +661,9 @@ ea7071(sz) mrg_2 = 070; } -void -fbranch(opc, exp) -expr_t exp; +void fbranch(int opc, expr_t exp) { - register sm; + register int sm; exp.val -= (DOTVAL + 2); if ((pass == PASS_2) From 5295049b16120c8a48d639d9224e94f50bd1cec7 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:12:07 +0800 Subject: [PATCH 22/84] Add function prototypes. --- mach/ns/as/mach1.c | 29 +++++++++++++++++++++ mach/ns/as/mach5.c | 63 +++++++++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/mach/ns/as/mach1.c b/mach/ns/as/mach1.c index a7e018e6a..736e40de1 100644 --- a/mach/ns/as/mach1.c +++ b/mach/ns/as/mach1.c @@ -115,3 +115,32 @@ extern struct { } mode1, mode2, *mode_ptr ; #define not_imm(mode_ptr) if ( (mode_ptr)->m_mode==0x14 ) ill_imm() ; + + +/* NS Specific routines */ +void clrmode(void); +int ind_mode(int type); +void badsyntax(void); +void ill_imm(void); +void form2(int id, int sval); +void form3(int id); +void form4(int id); +void form5(int id, int sval); +void form7x(int id,int i_type); +void form8(int id,int reg); +void form9(int id,int i_type,int f_type); +void form11(int id); +void form14(int id,int reg); +void frm15_0(int id,int reg); +void frm15_1(int id,int i_type,int s_type); +void frm15_5(int id); +void gen1(int id); +void gengen(int id); +void disp(register expr_t *expr, int relpc); +void putdisp(valu_t val,int size); +void dot_adjust(register expr_t *expr); +int testsize(int type,int val); +void imm(int i_type,register expr_t *expr); +int reg_list(int list,int reverse); +int cpu_opt(int indic); +int string_opt(int indic); diff --git a/mach/ns/as/mach5.c b/mach/ns/as/mach5.c index 8fa832394..30bb2c149 100644 --- a/mach/ns/as/mach5.c +++ b/mach/ns/as/mach5.c @@ -8,11 +8,11 @@ * NS 16032 special routines */ -clrmode() { /* clear the current mode */ +void clrmode(void) { /* clear the current mode */ mode_ptr->m_ndisp = 0 ; } -int ind_mode(type) { +int ind_mode(int type) { switch ( type ) { case 'b' : return 0x1C ; case 'w' : return 0x1D ; @@ -24,95 +24,95 @@ int ind_mode(type) { } } -badsyntax() { +void badsyntax(void) { serror("bad operands"); } -ill_imm() { +void ill_imm(void) { serror("immediate operand not allowed") ; } /* Create the output formats */ -form2(id,sval) { +void form2(int id, int sval) { assert ( id_t1(id)==T_INT ) ; emit1( id_g1(id) | 0xC | (id_op(id)<<4) | ((sval&1)<<7 ) ) ; emit1( (sval>>1) | (mode1.m_mode<<3) ) ; } -form3(id) { +void form3(int id) { assert ( id_t1(id)==T_INT ) ; emit1( id_g1(id) | 0x7C | ((id_op(id)&1)<<7) ) ; emit1( (id_op(id)>>1) | (mode1.m_mode<<3) ) ; } -form4(id) { +void form4(int id) { assert ( id_t1(id)==T_INT && id_t2(id)==T_INT ); emit1( id_g2(id) | (id_op(id)<<2) | ((mode2.m_mode&3)<<6) ) ; emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; } -form5(id,sval) { +void form5(int id, int sval) { assert ( id_t1(id)==T_INT ) ; emit1(0xE) ; emit1( id_g1(id) | (id_op(id)<<2) | ((sval&1)<<7 ) ) ; emit1( (sval>>1) ) ; } -form7x(id,i_type) { +void form7x(int id,int i_type) { assert ( id_t1(id)==T_INT && id_t2(id)==T_INT ); emit1(0xCE) ; emit1( i_type | (id_op(id)<<2) | ((mode2.m_mode&3)<<6) ) ; emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; } -form8(id,reg) { +void form8(int id,int reg) { assert ( id_t1(id)==T_INT ) ; emit1( 0x2E | ((id_op(id)&3)<<6) ) ; emit1( id_g1(id) | (id_op(id)&04) | (reg<<3) | ((mode2.m_mode&03)<<6) ) ; emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; } -form9(id,i_type,f_type) { +void form9(int id,int i_type,int f_type) { emit1(0x3E) ; emit1( i_type | (f_type<<2) | (id_op(id)<<3) | ((mode2.m_mode&03)<<6) ) ; emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; } -form11(id) { +void form11(int id) { assert ( id_t1(id)==T_FL && id_t2(id)==T_FL && id_g1(id)==id_g2(id) ); emit1(0xBE) ; emit1( id_g1(id) | (id_op(id)<<2) | ((mode2.m_mode&3)<<6) ) ; emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; } -form14(id,reg) { +void form14(int id,int reg) { assert ( id_t1(id)==T_INT ) ; emit1(0x1E) ; emit1( id_g1(id) | (id_op(id)<<2) | ((reg&1)<<7 ) ) ; emit1( (reg>>1) | (mode1.m_mode<<3) ) ; } -frm15_0(id,reg) { +void frm15_0(int id,int reg) { assert ( id_t1(id)==T_INT ) ; emit1(0x16 /* + slave<<5 */ ) ; emit1( id_g1(id) | (id_op(id)<<2) | ((reg&1)<<7 ) ) ; emit1( (reg>>1) | (mode1.m_mode<<3) ) ; } -frm15_1(id,i_type,s_type) { +void frm15_1(int id,int i_type,int s_type) { emit1(0x16 /* + slave<<5 */ ) ; emit1( i_type | (s_type<<2) | (id_op(id)<<3) | ((mode2.m_mode&03)<<6) ) ; emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; } -frm15_5(id) { +void frm15_5(int id) { assert(id_t1(id)==T_SLAVE&& id_t2(id)==T_SLAVE&& id_g1(id)==id_g2(id) ); emit1(0x16 /* + slave<<5 */ ) ; emit1( id_g1(id) | (id_op(id)<<2) | ((mode2.m_mode&3)<<6) ) ; emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; } -gen1(id) { +void gen1(int id) { if ( (mode1.m_mode&0x1C)==0x1C ) { emit1(mode1.m_index) ; } @@ -130,7 +130,7 @@ gen1(id) { } } -gengen(id) { +void gengen(int id) { if ( (mode1.m_mode&0x1C)==0x1C ) { emit1(mode1.m_index) ; } @@ -163,8 +163,8 @@ gengen(id) { } } -disp(expr, relpc) register expr_t *expr ; { - register sm1, sm2 ; +void disp(register expr_t *expr, int relpc) { + register int sm1, sm2 ; sm1=0 ; sm2=0 ; if (DOTTYP >= 0x2 && DOTTYP<=0x7F && @@ -202,7 +202,8 @@ disp(expr, relpc) register expr_t *expr ; { else putdisp(expr->val,4) ; } -putdisp(val,size) valu_t val ; { +void putdisp(valu_t val,int size) +{ switch ( size ) { case 1 : emit1( ((int)val)&0x7F ) ; @@ -220,7 +221,8 @@ putdisp(val,size) valu_t val ; { } } -dot_adjust(expr) register expr_t *expr ; { +void dot_adjust(register expr_t *expr) +{ expr->val -= DOTVAL ; if ( pass==PASS_2 ) { if ( (expr->typ&S_DOT) == 0 && expr->val>0 ) { @@ -239,7 +241,8 @@ dot_adjust(expr) register expr_t *expr ; { * an immediate value in a field which is too small to fit in. */ -testsize(type,val) { +int testsize(int type,int val) +{ /* check if value fits in type */ switch( type ) { case I_DOUBLE : return fit32(val); @@ -248,7 +251,8 @@ testsize(type,val) { } } -imm(i_type,expr) register expr_t *expr ; { +void imm(int i_type,register expr_t *expr) +{ /* emit value of immediate expression , after check on FIT */ if (!testsize(i_type,(int)expr->val)) warning("immediate operand too large"); @@ -278,8 +282,9 @@ imm(i_type,expr) register expr_t *expr ; { } -reg_list(list,reverse) { - register rev_list, i ; +int reg_list(int list,int reverse) +{ + register int rev_list, i ; if ( !reverse ) { return list ; } @@ -291,7 +296,9 @@ reg_list(list,reverse) { } return rev_list ; } -cpu_opt(indic) { + +int cpu_opt(int indic) +{ switch( indic ) { case 'i' : return 1 ; case 'f' : return 2 ; @@ -303,7 +310,7 @@ cpu_opt(indic) { } } -string_opt(indic) { +int string_opt(int indic) { switch( indic ) { case 'b' : return SO_BACKW ; case 'u' : return SO_UNTIL ; From dcc2be5e8cfc7b6985b2f413329b5410de123a17 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:12:21 +0800 Subject: [PATCH 23/84] Add function prototypes. --- mach/pdp/as/mach1.c | 9 ++++++++- mach/pdp/as/mach5.c | 32 ++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/mach/pdp/as/mach1.c b/mach/pdp/as/mach1.c index 5b92041df..ac5646edf 100644 --- a/mach/pdp/as/mach1.c +++ b/mach/pdp/as/mach1.c @@ -36,4 +36,11 @@ extern expr_t exp_1, exp_2; extern int rel_1, rel_2; extern int im1flag INIT(0); extern int im2flag INIT(0); -extern valu_t adjust(); + +void op1(int mode); +void op2(int mode); +void branch(int opc,expr_t exp); +void ejump(int opc, expr_t exp); +void sob(int reg, expr_t exp); +int jump(int opc,int opr); +valu_t adjust(expr_t exp); diff --git a/mach/pdp/as/mach5.c b/mach/pdp/as/mach5.c index b8a3bc1f9..ec15b077b 100644 --- a/mach/pdp/as/mach5.c +++ b/mach/pdp/as/mach5.c @@ -6,7 +6,8 @@ * */ -op1(mode) { +void op1(int mode) +{ int relpc = 0; if (im1flag) { if (mode == 067 || mode == 077) { @@ -23,7 +24,8 @@ op1(mode) { } } -op2(mode) { +void op2(int mode) +{ int relpc = 0; if (im2flag) { if (mode == 067 || mode == 077) { @@ -40,9 +42,10 @@ op2(mode) { } } -branch(opc,exp) expr_t exp; { - register eval; - register sm; +void branch(int opc,expr_t exp) +{ + register int eval; + register int sm; eval = adjust(exp) >> 1; sm = fitb(eval); @@ -53,8 +56,9 @@ branch(opc,exp) expr_t exp; { emit2(opc | lowb(eval)); } -ejump(opc, exp) expr_t exp; { - register sm,eval; +void ejump(int opc, expr_t exp) +{ + register int sm,eval; int gain; # ifdef THREE_PASS @@ -82,7 +86,8 @@ ejump(opc, exp) expr_t exp; { # endif } -sob(reg, exp) expr_t exp; { +void sob(int reg, expr_t exp) +{ if ((exp.typ & ~S_DOT) != DOTTYP) { serror("error in sob-label"); } @@ -91,12 +96,13 @@ sob(reg, exp) expr_t exp; { emit2( OPSOB | (reg << 6) | exp.val); } -jump(opc,opr) { - register val; +int jump(int opc,int opr) +{ + register int val; # ifdef THREE_PASS if (opr==067) { - register sm = 0; + register int sm = 0; val = adjust(exp_1) >> 1; if ( fitb(val) && (exp_1.typ & ~S_DOT) == DOTTYP) { @@ -111,9 +117,11 @@ jump(opc,opr) { # endif emit2(opc | opr); op1(opr); + return(0); } -valu_t adjust(exp) expr_t exp; { +valu_t adjust(expr_t exp) +{ valu_t val; val = exp.val - DOTVAL - 2; From a6120c220e13209e5ddc4dc004b1cf7959722932 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:13:42 +0800 Subject: [PATCH 24/84] Fix buffer overflow issue. --- mach/proto/as/comm4.c | 7 ++++--- mach/proto/as/comm5.c | 10 ++++++++-- mach/proto/as/comm6.c | 10 ++++++++-- mach/proto/as/comm7.c | 10 ++++++---- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/mach/proto/as/comm4.c b/mach/proto/as/comm4.c index a47d1438d..05255ba22 100644 --- a/mach/proto/as/comm4.c +++ b/mach/proto/as/comm4.c @@ -15,7 +15,7 @@ #include "comm0.h" #include "comm1.h" #include "y.tab.h" -#include +#include "object.h" extern YYSTYPE yylval; @@ -243,7 +243,8 @@ archive(void) { if (needed()) { fseek(input,offset,0); archsize = header.ar_size; - header.ar_name[14] = '\0'; + // TODO: To check if this is correct. + header.ar_name[AR_NAME_MAX-1] = '\0'; parse(remember(header.ar_name)); } offset += header.ar_size; @@ -330,7 +331,7 @@ parse(char *s) */ #ifdef ASLD for (i = 0; i < H_SIZE; i++) { - while (ip = hashtab[H_LOCAL+i]) { + while ((ip = hashtab[H_LOCAL+i])) { /* * cleanup local queue */ diff --git a/mach/proto/as/comm5.c b/mach/proto/as/comm5.c index 0b448ef0e..e8718bc46 100644 --- a/mach/proto/as/comm5.c +++ b/mach/proto/as/comm5.c @@ -439,7 +439,7 @@ static int innumber(int c) if (radix != 16 && (c == 'f' || c == 'b')) return (infbsym(num)); yylval.y_valu = 0; - while (c = *p++) + while ((c = *p++)) { if (c > '9') c -= ('a' - '9' - 1); @@ -593,7 +593,7 @@ int hash(const char* p) int c; h = 0; - while (c = *p++) + while ((c = *p++)) { h <<= 2; h += c; @@ -668,10 +668,16 @@ item_t* fb_shift(int lab) ip = fb_ptr[FB_FORW + lab]; if (ip == 0) + { if (pass == PASS_1) + { ip = fb_alloc(lab); + } else + { ip = fb_ptr[FB_HEAD + lab]; + } + } fb_ptr[FB_BACK + lab] = ip; fb_ptr[FB_FORW + lab] = ip->i_next; return (ip); diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index 8aca81e8a..404e08742 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -11,7 +11,7 @@ #include "comm0.h" #include "comm1.h" #include "y.tab.h" -#include +#include "object.h" static void new_common(item_t *); @@ -187,7 +187,7 @@ switchsect(int newtyp) { sect_t *sp; - if (sp = DOTSCT) + if ((sp = DOTSCT)) sp->s_size = DOTVAL - sp->s_base; if (newtyp == S_UND) { DOTSCT = NULL; @@ -212,10 +212,16 @@ align(valu_t bytes) if (bytes == 0) bytes = ALIGNWORD; if (sp->s_lign % bytes) + { if (bytes % sp->s_lign) + { serror("illegal alignment"); + } else + { sp->s_lign = bytes; + } + } if (pass == PASS_1) /* * be pessimistic: biggest gap possible diff --git a/mach/proto/as/comm7.c b/mach/proto/as/comm7.c index 5611e8272..418bf363c 100644 --- a/mach/proto/as/comm7.c +++ b/mach/proto/as/comm7.c @@ -13,7 +13,7 @@ #include "comm1.h" #include "y.tab.h" #include -#include +#include "object.h" valu_t load(const item_t* ip) { @@ -77,7 +77,7 @@ char* remember(char* s) assert(nleft >= 0); } p = next; - while (*p++ = *s++) + while ((*p++ = *s++)) ; s = next; next = p; @@ -133,7 +133,7 @@ int printx(int ndig, valu_t val) } while (--n); do { - c = "0123456789ABCDEF"[*--p]; + c = "0123456789ABCDEF"[(unsigned char)*--p]; putchar(c); } while (p > buf); return (ndig); @@ -232,6 +232,8 @@ int small(int fitsmall, int gain) case PASS_3: assert(fitsmall || (*p & bit) == 0); return (*p & bit); + default: + assert(0); } /*NOTREACHED*/ } @@ -368,7 +370,7 @@ void emitstr(int zero) #endif #define gen1 emit1 -#include +#include "con_float" void emitf(int size, int negative) { From f161a5867dbc4058181d597e2019f03625945e14 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:13:56 +0800 Subject: [PATCH 25/84] Add function prototypes. --- mach/s2650/as/mach1.c | 6 ++++++ mach/s2650/as/mach5.c | 31 ++++++++++++------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/mach/s2650/as/mach1.c b/mach/s2650/as/mach1.c index 45b838ab2..f6667aed3 100644 --- a/mach/s2650/as/mach1.c +++ b/mach/s2650/as/mach1.c @@ -22,3 +22,9 @@ extern expr_t par_exp; extern unsigned p_indirect; extern int p_indexed; + +void page(void); +void pag2(void); +void rela(expr_t exp,int ind); +void absoa(expr_t exp, int ix, unsigned int ind); +void absob(expr_t exp, unsigned int ind); diff --git a/mach/s2650/as/mach5.c b/mach/s2650/as/mach5.c index d77662555..8a74101e6 100644 --- a/mach/s2650/as/mach5.c +++ b/mach/s2650/as/mach5.c @@ -12,22 +12,20 @@ #define MASK1 0x1FFF #define MASK2 0x1FFE -page() - { +void page(void) +{ if(((DOTVAL - 1) & MASK1) == MASK1) serror("page violation"); - } +} -pag2() - { +void pag2(void) +{ if(((DOTVAL - 1) & MASK1) >= MASK2) serror("page violation"); - } +} -rela(exp,ind) -expr_t exp; -int ind; - { +void rela(expr_t exp,int ind) +{ int c, d; page(); if(pass == PASS_3){ @@ -58,11 +56,8 @@ int ind; emit1(low7(c) | ind); } -absoa(exp, ix, ind) -expr_t exp; -int ix; -unsigned ind; - { +void absoa(expr_t exp, int ix, unsigned int ind) +{ pag2(); #ifdef ASLD if(pass == PASS_3 && (exp.val & MASK) != (DOTVAL & MASK)) @@ -74,10 +69,8 @@ unsigned ind; emit2(low13(exp.val) | ind | ix); } -absob(exp, ind) -expr_t exp; -unsigned ind; - { +void absob(expr_t exp, unsigned int ind) +{ pag2(); #ifdef ASLD if (exp.val < 0) From 82cdc096b0362e44caedd104a6c0b249ee745fcf Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:14:08 +0800 Subject: [PATCH 26/84] Add function prototypes. --- mach/vax4/as/mach1.c | 6 ++++++ mach/vax4/as/mach5.c | 15 +++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mach/vax4/as/mach1.c b/mach/vax4/as/mach1.c index b88eb847f..fdd023a51 100644 --- a/mach/vax4/as/mach1.c +++ b/mach/vax4/as/mach1.c @@ -66,3 +66,9 @@ extern struct operand opnd[6]; /* maximum number of operands of a VAX instruction is 6 */ extern int op_ind; /* index in opng array */ + +/* VAX4 Specific instructions */ +void branch(int opc, expr_t exp); +void ext_branch(int opc, expr_t exp); +void operands(void); + diff --git a/mach/vax4/as/mach5.c b/mach/vax4/as/mach5.c index d1f736d36..73658ef6c 100644 --- a/mach/vax4/as/mach5.c +++ b/mach/vax4/as/mach5.c @@ -12,9 +12,7 @@ #define rev_cond_branch(opc) ((opc) ^ 1) /* Process one operand. */ -static -oprnd(p) - register struct operand *p; +static void oprnd(register struct operand *p) { int sm; @@ -203,8 +201,7 @@ oprnd(p) } /* Give an upper bound on the size of the operands */ -static int -size_ops() +static int size_ops(void) { register struct operand *p = &opnd[0]; register int i; @@ -241,8 +238,7 @@ size_ops() } /* Branch with byte or word offset */ -branch(opc, exp) - expr_t exp; +void branch(int opc, expr_t exp) { exp.val -= (DOTVAL + 2); if ((pass == PASS_2) && @@ -272,8 +268,7 @@ branch(opc, exp) they are replaced by a reversed conditional branch over a word-branch or jump. */ -ext_branch(opc, exp) - expr_t exp; +void ext_branch(int opc, expr_t exp) { int sm; int gain = opc == BRB ? 1 : 3; @@ -340,7 +335,7 @@ ext_branch(opc, exp) } /* Generate code for the operands */ -operands() +void operands(void) { register int i; From 9979fb37d2f3e327cf66c29bc25e512ef7c013c0 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:14:27 +0800 Subject: [PATCH 27/84] Add function prototypes. --- mach/z80/as/mach1.c | 7 +++++++ mach/z80/as/mach5.c | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mach/z80/as/mach1.c b/mach/z80/as/mach1.c index 3d02072ee..c201dca2c 100644 --- a/mach/z80/as/mach1.c +++ b/mach/z80/as/mach1.c @@ -34,3 +34,10 @@ extern expr_t exp_ind; #ifndef ASLD extern int rel_ind; #endif + +/* + * Zilog Z80 special routines + */ +void xyreg(int r,int byte); +void xymem(int r,int byte); +void branch(register int opc,expr_t exp); diff --git a/mach/z80/as/mach5.c b/mach/z80/as/mach5.c index 0808665c0..64da16087 100644 --- a/mach/z80/as/mach5.c +++ b/mach/z80/as/mach5.c @@ -8,7 +8,8 @@ * Zilog Z80 special routines */ -xyreg(r,byte) { +void xyreg(int r,int byte) +{ if (r==IX) emit1(0335); @@ -19,7 +20,8 @@ xyreg(r,byte) { emit1(byte); } -xymem(r,byte) { +void xymem(int r,int byte) +{ xyreg(r,byte); if (r != HL) { @@ -31,8 +33,9 @@ xymem(r,byte) { } } -branch(opc,exp) register opc; expr_t exp; { - register sm,dist; +void branch(register int opc,expr_t exp) +{ + register int sm,dist; dist = exp.val - (DOTVAL + 2); if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT)) From efecff78b98be66011a8b252ec13706b4b6f7d6b Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 00:14:38 +0800 Subject: [PATCH 28/84] Add function prototypes. --- mach/z8000/as/mach1.c | 15 ++++++++++++++ mach/z8000/as/mach4.c | 10 ++++----- mach/z8000/as/mach5.c | 47 ++++++++++++++++--------------------------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/mach/z8000/as/mach1.c b/mach/z8000/as/mach1.c index 0e48130e1..9e2a0b966 100644 --- a/mach/z8000/as/mach1.c +++ b/mach/z8000/as/mach1.c @@ -80,3 +80,18 @@ extern expr_t addr_inf; /* .val (address) up to 23 bits! */ extern expr_t immed; #define regerr() serror("register error") + +/* Z8000 specific routines */ +void settype( int type ); +int twolog(int s); +void setmod(int opr); +void chtype(int opr, int typerange ); +void chreg(int opc, int reg); +ATYPE checkaddr(valu_t addr ); +void emit_ad(expr_t ad_inf); +void ldmcode(int wrd1,int wrd2, int num); +valu_t adjust(valu_t absval); +void branch(int opc,expr_t exp); +void ldrel(int opc,expr_t exp); +void shiftcode(int w1, int w2); +void argerr(void); diff --git a/mach/z8000/as/mach4.c b/mach/z8000/as/mach4.c index fd01c1ac5..4fc5cc3c6 100644 --- a/mach/z8000/as/mach4.c +++ b/mach/z8000/as/mach4.c @@ -91,7 +91,7 @@ f2 : F2_1 reg ',' src if ( oprtype[ SRC ] == IM && ( $1 == 0x0B00 || $1 == 0x0A00 ) ) /* cp or cpb */ - { setmode( DST ); + { setmod( DST ); emit2( mode | $1 + 0x201 | $2<<4 ); break; } @@ -182,7 +182,7 @@ f2 : F2_1 reg ',' src } break; case REG: case IR: case DA: case X: - setmode( SRC ); + setmod( SRC ); emit2( mode | 0x2000 | $1 | $4<<4 | $2 ); if ( mode>>12 == 4 ) emit_ad( addr_inf ); break; @@ -202,7 +202,7 @@ f2 : F2_1 reg ',' src if ( oprtype[ SRC ] == REG ) { switch( oprtype[ DST ] ) { case IR: case DA: case X: - setmode( DST ); + setmod( DST ); emit2( mode | 0x2E00 | $1 | $2<<4 | $4 ); if ( mode>>12 == 4 ) emit_ad( addr_inf ); break; @@ -252,7 +252,7 @@ f2 : F2_1 reg ',' src emit4( immed.val ); break; case REG: case IR: case DA: case X: - setmode( SRC ); + setmod( SRC ); emit2( mode | 0x1400 | $4<<4 | $2 ); if ( mode>>12 == 4 ) emit_ad( addr_inf ); break; @@ -272,7 +272,7 @@ f2 : F2_1 reg ',' src if ( oprtype[ SRC ] == REG ) { switch( oprtype[ DST ] ) { case IR: case DA: case X: - setmode( DST ); + setmod( DST ); emit2( mode | 0x1D00 | $2<<4 | $4 ); if ( mode>>12 == 4 ) emit_ad( addr_inf ); break; diff --git a/mach/z8000/as/mach5.c b/mach/z8000/as/mach5.c index c3be42010..80e313c0b 100644 --- a/mach/z8000/as/mach5.c +++ b/mach/z8000/as/mach5.c @@ -4,37 +4,33 @@ */ #define RCSID5 "$Id$" -settype( type ) -int type; +void settype( int type ) { oprtype[ operand ] = type; } -int twolog( s ) -int s; +int twolog(int s) { int twopower = 0; while ( (s>>=1) != 0 ) twopower++; return( twopower ); } -setmode( opr ) -int opr; -{ mode = modetbl[ twolog( oprtype[opr] ) ] << 12; } +void setmod(int opr) +{ + mode = modetbl[ twolog( oprtype[opr] ) ] << 12; +} -chtype( opr, typerange ) -int opr, - typerange; +void chtype(int opr, int typerange ) /* Check type of 'opr' with given 'typerange' and ** set the global var 'mode'. */ { if ( (oprtype[opr] & typerange) != oprtype[opr] ) argerr(); - else /* We have a permitted type for 'opr'. */ setmode( opr ); + else /* We have a permitted type for 'opr'. */ setmod( opr ); } -chreg( opc, reg ) -int opc, reg; +void chreg(int opc, int reg) { switch( opc ) { case 0xB10A: case 0x1B00: case 0x1900: /* R32 expected */ if (reg & 1) regerr(); break; @@ -43,8 +39,7 @@ int opc, reg; } } -ATYPE checkaddr( addr ) -valu_t addr; +ATYPE checkaddr( valu_t addr ) /* Called by functions emit_ad() and branch(). */ { ATYPE addr_struct; @@ -57,8 +52,7 @@ valu_t addr; return( addr_struct ); } -emit_ad( ad_inf ) -expr_t ad_inf; +void emit_ad(expr_t ad_inf) /* When the type of an operand is 'da' or 'x' this function ** emits the address. */ @@ -75,8 +69,7 @@ expr_t ad_inf; } -ldmcode( wrd1, wrd2, num ) -int wrd1, wrd2, num; +void ldmcode(int wrd1,int wrd2, int num) { fit(fit4(num-1)); emit2( mode | wrd1 ); emit2( wrd2<<8 | num-1 ); @@ -84,8 +77,7 @@ int wrd1, wrd2, num; } -valu_t adjust( absval ) -valu_t absval; +valu_t adjust(valu_t absval) { valu_t val = absval - DOTVAL - 2; if ( pass == PASS_2 && val > 0 ) val -= DOTGAIN; @@ -93,9 +85,7 @@ valu_t absval; } -branch( opc, exp ) -int opc; -expr_t exp; +void branch(int opc,expr_t exp) /* This routine determines for the F3 format instructions whether the ** relative address is small enough to fit in normal code; If this is ** so normal code is emitted otherwise 'long' code is emitted contai- @@ -145,9 +135,7 @@ expr_t exp; } -ldrel( opc, exp ) -int opc; -expr_t exp; +void ldrel(int opc,expr_t exp) /* This routine determines for the F4 format instructions whether the ** address is within the same segment (meaning a relative address of ** less than 16 bits); If this is so normal code is emitted otherwise @@ -160,8 +148,7 @@ expr_t exp; } -shiftcode( w1, w2 ) -int w1, w2; +void shiftcode(int w1, int w2) { switch( w1 & 0x0F04 ) { /* Remember: w2 negative means right shift ! */ case 0x200: /*byte*/ fit( w2>=-8 && w2<=8 ); break; @@ -173,5 +160,5 @@ int w1, w2; } -argerr() +void argerr(void) { serror( "illegal operand" ); } From 41fd51eeeaa21448b7c93168d3359feab3232ba7 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 01:41:04 +0800 Subject: [PATCH 29/84] Revert change. --- mach/proto/as/comm4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/as/comm4.c b/mach/proto/as/comm4.c index 05255ba22..c7435f38b 100644 --- a/mach/proto/as/comm4.c +++ b/mach/proto/as/comm4.c @@ -244,7 +244,7 @@ archive(void) { fseek(input,offset,0); archsize = header.ar_size; // TODO: To check if this is correct. - header.ar_name[AR_NAME_MAX-1] = '\0'; + header.ar_name[AR_NAME_MAX] = '\0'; parse(remember(header.ar_name)); } offset += header.ar_size; From 78899705d57f4e0f4c8146fdc4136b7b615f19a3 Mon Sep 17 00:00:00 2001 From: carl Date: Mon, 25 Mar 2019 02:20:50 +0800 Subject: [PATCH 30/84] Bug of fseek and wrong setting of position. --- modules/src/object/rd.c | 2 +- modules/src/object/wr.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c index 01da90dbc..26c9f224c 100644 --- a/modules/src/object/rd.c +++ b/modules/src/object/rd.c @@ -77,7 +77,7 @@ int rd_fdopen(FILE* fd) for (i = 0; i < NPARTS; i++) outseek[i] = 0; offcnt = 0; - rd_base = fseek(fd, 0L, SEEK_CUR); + rd_base = ftell(fd); if (rd_base < 0) { return 0; } diff --git a/modules/src/object/wr.c b/modules/src/object/wr.c index d5f77e30f..e4f304bca 100644 --- a/modules/src/object/wr.c +++ b/modules/src/object/wr.c @@ -38,7 +38,8 @@ __wr_flush(struct fil *ptr) #ifdef OUTSEEK /* seek to correct position even if we aren't going to write now */ if (currpos != ptr->currpos) { - currpos = fseek(ptr->fd, ptr->currpos, SEEK_SET); + fseek(ptr->fd, ptr->currpos, SEEK_SET); + currpos = ptr->currpos; } #endif if (ptr->pnow > ptr->pbegin) { @@ -129,7 +130,8 @@ static void BEGINSEEK(int p, long o) ptr->fd = outfile; ptr->currpos = o; #else - ptr->currpos = fseek(ptr->fd, o, SEEK_SET); + fseek(ptr->fd, o, SEEK_SET); + ptr->currpos = o; #endif if (p >= PARTRELO) o = 0; /* no attempt to align writes for the time being */ @@ -259,8 +261,11 @@ wr_outsect(int s) if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) { #ifdef OUTSEEK - if (currpos != ptr->currpos) - currpos = fseek(ptr->fd, ptr->currpos, SEEK_SET); + if (currpos != ptr->currpos) + { + fseek(ptr->fd, ptr->currpos, SEEK_SET); + currpos -> ptr->currpos; + } #endif wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin)); ptr->currpos += ptr->pnow - ptr->pbegin; @@ -269,7 +274,8 @@ wr_outsect(int s) #endif offset[sectionnr] = ptr->currpos; if (offset[s] != ptr->currpos) { - ptr->currpos = fseek(ptr->fd, offset[s], SEEK_SET); + fseek(ptr->fd, offset[s], SEEK_SET); + ptr->currpos = offset[s]; #ifdef OUTSEEK currpos = ptr->currpos; #endif From 7973e87b2f2eb778667c24b674e7f7f7ffec5fd1 Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 26 Mar 2019 00:58:14 +0800 Subject: [PATCH 31/84] Additional check with NULL or empty string (now same behaviour as POSIX version) --- modules/src/system/basename.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/src/system/basename.c b/modules/src/system/basename.c index 21736bbce..04322085e 100644 --- a/modules/src/system/basename.c +++ b/modules/src/system/basename.c @@ -12,12 +12,22 @@ void sys_basename(char *str, register char *dst) register char *p2 = p1; register char *end; register char *start; + int len; - int len = strlen(str); + if ((str == NULL) || (*str == '\0')) + { + dst[0] = '.'; + dst[1] = '\0'; + return; + } + + len = strlen(str); /* Point to the end of the string. */ p1 = p1 + len - 1; end = p1; + + while ((*p1 == '/') || (*p1 == '\\')) { if (p1 == str) From 415ec163a7993ab808fe2ecd0cddd715d1cb6259 Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 26 Mar 2019 00:58:36 +0800 Subject: [PATCH 32/84] Fix tabs. --- util/arch/archiver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/arch/archiver.c b/util/arch/archiver.c index 1353fa1be..3d6d30a0f 100644 --- a/util/arch/archiver.c +++ b/util/arch/archiver.c @@ -420,7 +420,7 @@ void get(int argc, char *argv[]) { sys_basename(argv[i],buffer); if (equal(buffer, member->ar_name)) - break; + break; } if (i == argc || app_fl) { @@ -459,7 +459,7 @@ void get(int argc, char *argv[]) else { if (rep_fl) - add(argv[i], ar_f, temp_fd, "r - %s\n"); + add(argv[i], ar_f, temp_fd, "r - %s\n"); else if (show_fl) { char buf[sizeof(member->ar_name) + 2]; @@ -497,7 +497,7 @@ void get(int argc, char *argv[]) fseek(ar_f, even(member->ar_size), SEEK_CUR); } argv[i] = ""; - } + } /* end while */ if (argc > 3) { From a09e40cba39a63b85626a46b238ec38c603a8d69 Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 26 Mar 2019 00:58:56 +0800 Subject: [PATCH 33/84] Fix memory overflow error. --- fast/driver/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fast/driver/driver.c b/fast/driver/driver.c index 4ff6358b4..f78a1d002 100644 --- a/fast/driver/driver.c +++ b/fast/driver/driver.c @@ -865,7 +865,8 @@ static int runvec(struct arglist *vec, char *outp) } if(outp != NULL) { - redirect = alloc(strlen(outp)+sizeof(char)*2); + /* Don't forget the null character. */ + redirect = alloc(strlen(outp)+sizeof(char)*3); strcpy(redirect,"1>"); strcat(redirect,outp); append(vec,redirect); From 496795f0cfac0b8a5112092298a7816006887773 Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 26 Mar 2019 00:59:16 +0800 Subject: [PATCH 34/84] Fix memory overflow error. --- util/ass/maktab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ass/maktab.c b/util/ass/maktab.c index 81874f5e0..122a7acb1 100644 --- a/util/ass/maktab.c +++ b/util/ass/maktab.c @@ -380,7 +380,7 @@ static void writeout(void) } elem[sp_lmnem - sp_fmnem + 1] = nch; printf("0 } ;\n\nchar *opindex[] = {\n"); - for (i = 0; i <= sp_lmnem - sp_fmnem + 1; i++) + for (i = 0; i < sp_lmnem - sp_fmnem + 1; i++) { printf(" &opchoice[%d], /* %d = %s */\n", elem[i], i, em_mnem[i]); } From 9bc3ffe6ec2bec8a7fcddeeda273337035e6b956 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 31 Mar 2019 00:52:27 +0800 Subject: [PATCH 35/84] Buffer overflow memory errors. --- fast/driver/driver.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fast/driver/driver.c b/fast/driver/driver.c index f78a1d002..48aed8cc9 100644 --- a/fast/driver/driver.c +++ b/fast/driver/driver.c @@ -476,9 +476,13 @@ int main(int argc, char *argv[]) append(&SRCFILES, str); break; case 'M': /* use other compiler (for testing) */ + free(COMP); + COMP = alloc(strlen(str)+2-1); strcpy(COMP, str + 2); break; case 'P': /* use other cpp (for testing) */ + free(CPP); + CPP = alloc(strlen(str)+2-1); strcpy(CPP, str + 2); break; case 's': /* strip */ @@ -742,6 +746,7 @@ static char * expand_string(char *s) if (!expanded) return s; *q++ = '\0'; + /* Do not forget the missing null character. */ p = alloc((unsigned int) (q - buf)); return strcpy(p, buf); } From 4f2c48241691d2317da1ae8497a603096f772372 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 31 Mar 2019 00:52:37 +0800 Subject: [PATCH 36/84] Buffer overflow memory errors. --- mach/proto/as/comm5.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/mach/proto/as/comm5.c b/mach/proto/as/comm5.c index e8718bc46..2b301a2e3 100644 --- a/mach/proto/as/comm5.c +++ b/mach/proto/as/comm5.c @@ -395,6 +395,18 @@ char* readident(int c) } #endif +static void need_stringbuf() +{ + if (!maxstring) + { + maxstring = STRINGMAX; + if ((stringbuf = malloc(maxstring)) == 0) + { + fatal("out of memory"); + } + } +} + static int innumber(int c) { char* p; @@ -464,11 +476,8 @@ floatconstant: *p = '\0'; stringlen = p - num; - if (stringlen > maxstring) - { - maxstring = stringlen; - stringbuf = realloc(stringbuf, maxstring); - } + need_stringbuf(); + assert(stringlen < maxstring); strcpy(stringbuf, num); return NUMBERF; } @@ -478,14 +487,7 @@ static int instring(int termc) char* p; int c; - if (!maxstring) - { - maxstring = STRINGMAX; - if ((stringbuf = malloc(maxstring)) == 0) - { - fatal("out of memory"); - } - } + need_stringbuf(); p = stringbuf; for (;;) { From 715717a4f63806fcaaf72233dbe58efcbca5f9e6 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 31 Mar 2019 00:53:09 +0800 Subject: [PATCH 37/84] Read beyond buffer bugfix. --- util/ass/maktab.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/ass/maktab.c b/util/ass/maktab.c index 122a7acb1..39cd33328 100644 --- a/util/ass/maktab.c +++ b/util/ass/maktab.c @@ -384,6 +384,8 @@ static void writeout(void) { printf(" &opchoice[%d], /* %d = %s */\n", elem[i], i, em_mnem[i]); } + printf(" &opchoice[%d], /* %d = %s */\n", elem[sp_lmnem - sp_fmnem + 1], + sp_lmnem - sp_fmnem + 1, ""); printf("} ;\n"); } From 8d6cfa770138070c10b99813aa17867fbab98b04 Mon Sep 17 00:00:00 2001 From: carl Date: Sun, 31 Mar 2019 01:14:49 +0800 Subject: [PATCH 38/84] Fix possible buffer writer overflow --- mach/proto/as/comm4.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mach/proto/as/comm4.c b/mach/proto/as/comm4.c index c7435f38b..08c053ed0 100644 --- a/mach/proto/as/comm4.c +++ b/mach/proto/as/comm4.c @@ -223,6 +223,7 @@ static void archive(void) { long offset; struct ar_hdr header; + char ar_name[AR_NAME_MAX+1]; char getsize[AR_TOTAL]; archmode++; @@ -234,7 +235,7 @@ archive(void) { if (fread(getsize,AR_TOTAL,1,input) != 1) break; offset += AR_TOTAL; - strncpy(header.ar_name,getsize,sizeof header.ar_name) ; + strncpy(ar_name,getsize,sizeof(header.ar_name)) ; header.ar_size= (((((long) (getsize[AR_SIZE+1]&0377))<<8)+ ((long) (getsize[AR_SIZE ]&0377))<<8)+ ((long) (getsize[AR_SIZE+3]&0377))<<8)+ @@ -243,9 +244,8 @@ archive(void) { if (needed()) { fseek(input,offset,0); archsize = header.ar_size; - // TODO: To check if this is correct. - header.ar_name[AR_NAME_MAX] = '\0'; - parse(remember(header.ar_name)); + ar_name[AR_NAME_MAX] = '\0'; + parse(remember(ar_name)); } offset += header.ar_size; while (offset % 2) From 2330d35ade6e0a8d862cc5c7657953b70ae80608 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 00:49:10 +0800 Subject: [PATCH 39/84] * Fix compilation warning. --- util/make/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/make/main.c b/util/make/main.c index a2ce602f7..88a1dcfa2 100644 --- a/util/make/main.c +++ b/util/make/main.c @@ -196,7 +196,7 @@ void fatal(char *msg, char* value) } else { fprintf(stderr, "%s: ", myname); - fprintf(stderr, msg); + fprintf(stderr, "%s",msg); } fputc('\n', stderr); exit(1); From 7cb2b3de7f1c30ef659b33ae10caf64bbc4aae49 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 00:51:42 +0800 Subject: [PATCH 40/84] Fix syntax mistake in man page. --- modules/src/alloc/alloc.3 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/src/alloc/alloc.3 b/modules/src/alloc/alloc.3 index cd7bfbf5e..5db5745d8 100644 --- a/modules/src/alloc/alloc.3 +++ b/modules/src/alloc/alloc.3 @@ -56,14 +56,12 @@ containing the head of the free list, and \fIsize\fR again contains the size of the structures. These last two routines are best used in a macro. .PP -\fIClear\fR clears \fIsize\fR bytes, starting at \fIptr\fR. +\fIclear\fR clears \fIsize\fR bytes, starting at \fIptr\fR. .SH FILES .nf ~em/modules/h/alloc.h ~em/modules/lib/liballoc.a .fi -.SH "MODULES USED" -system(3) .SH "SEE ALSO" malloc(3) .SH DIAGNOSTICS From 5bb20bdb9e4a1079b4fa45e1e78ccb985efda130 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 00:52:40 +0800 Subject: [PATCH 41/84] Add init/free functions and rename parameters. --- modules/src/data/smap.c | 55 ++++++++++++++++++++++++++--------- modules/src/data/smap.h | 37 +++++++++++++++++++---- modules/src/data/stringlist.c | 50 ++++++++++++++++++++++++++++++- modules/src/data/stringlist.h | 6 +++- 4 files changed, 128 insertions(+), 20 deletions(-) diff --git a/modules/src/data/smap.c b/modules/src/data/smap.c index 312241a20..45e25ebbf 100644 --- a/modules/src/data/smap.c +++ b/modules/src/data/smap.c @@ -3,14 +3,15 @@ #include #include "smap.h" -static void append(void* mapp, const char* left, void* right) +#define INCR_SIZE 8 + +static void append(void* mapp, char* key, void* value) { struct smap* map = mapp; struct smap_node* node; - if (map->count == map->max) { - int newmax = (map->max == 0) ? 8 : (map->max * 2); + int newmax = (map->max == 0) ? INCR_SIZE : (map->max * 2); struct smap_node* newarray = realloc(map->item, newmax * sizeof(*newarray)); map->max = newmax; @@ -20,11 +21,12 @@ static void append(void* mapp, const char* left, void* right) node = &map->item[map->count]; map->count++; - node->left = left; - node->right = right; + node->left = key; + node->right = value; } -void smap_put(void* mapp, const char* left, void* right) + +void smap_put(struct smap *mapp, char* key, void* value) { struct smap* map = mapp; int i; @@ -32,17 +34,44 @@ void smap_put(void* mapp, const char* left, void* right) for (i=0; icount; i++) { struct smap_node* node = &map->item[i]; - if (strcmp(node->left, left) == 0) + if (strcmp(node->left, key) == 0) { - node->right = right; + node->right = value; return; } } - append(map, left, right); + append(map, key, value); } -void smap_add(void* mapp, const char* left, void* right) +void smap_init(struct smap *mapp) +{ + mapp->count = 0; + mapp->item = NULL; + mapp->max = 0; +} + + +void smap_free(struct smap *mapp, int free_key, int free_value) +{ + int i; + for (i=0; icount; i++) + { + struct smap_node* node = &mapp->item[i]; + if (free_key) + { + free(node->left); + } + if (free_value) + { + free(node->right); + } + } + mapp->count = 0; + free(mapp->item); +} + +void smap_add(struct smap *mapp, char* key, void* value) { struct smap* map = mapp; int i; @@ -50,14 +79,14 @@ void smap_add(void* mapp, const char* left, void* right) for (i=0; icount; i++) { struct smap_node* node = &map->item[i]; - if ((strcmp(node->left, left) == 0) && (node->right == right)) + if ((strcmp(node->left, key) == 0) && (node->right == value)) return; } - append(map, left, right); + append(map, key, value); } -void* smap_get(void* mapp, const char* left) +void* smap_get(struct smap *mapp, const char* left) { struct smap* map = mapp; int i; diff --git a/modules/src/data/smap.h b/modules/src/data/smap.h index 7ccdb51de..f01b38010 100644 --- a/modules/src/data/smap.h +++ b/modules/src/data/smap.h @@ -1,9 +1,14 @@ +/** @file + * String map implementation. + * + */ + #ifndef SMAP_H #define SMAP_H struct smap_node { - const char* left; + char* left; void* right; }; @@ -18,14 +23,36 @@ struct smap #define SMAPOF(RIGHT) \ struct { \ - struct { const char* left; RIGHT* right; }* item; \ + struct { char* left; RIGHT* right; }* item; \ int count; \ int max; \ } -extern void smap_put(void* map, const char* left, void* right); -extern void smap_add(void* map, const char* left, void* right); -extern void* smap_get(void* map, const char* left); +/** Initializes a string map and returns the initialized + * handle in `mapp`. + */ +extern void smap_init(struct smap *mapp); +/** Adds a new item with name `key` in the string map if + * it does not already exist, otherwise replaces the + * value `value` associated with the existing `key`. + */ +extern void smap_put(struct smap *mapp, char* key, void* value); +/** Adds a new item in a string map only if `key` does + * not already exist in the string map. + */ +extern void smap_add(struct smap *mapp, char* key, void* value); +/** Returns the value associated with the specified `key`, returns + * NULL if `key` is not present in the string map. + * + */ +extern void* smap_get(struct smap* mapp, const char* key); +/** Frees the data structure associated with the string map. + * Also frees the memory associated with the key if + * `free_key` is non-zero, and free the memory associated + * with the value if `free_value` is non-zero. + * + */ +extern void smap_free(struct smap *mapp, int free_key, int free_value); #endif diff --git a/modules/src/data/stringlist.c b/modules/src/data/stringlist.c index 28322bf98..74d73b331 100644 --- a/modules/src/data/stringlist.c +++ b/modules/src/data/stringlist.c @@ -1,3 +1,7 @@ +/** @file + * String list implementation. + * + */ #include #include "stringlist.h" @@ -26,18 +30,62 @@ void stringlist_addall(struct stringlist* list, struct stringlist* src) } } -void stringlist_free(struct stringlist* list) +void stringlist_free(struct stringlist* list, int freedata) { struct stringfragment* f = list->first; while (f) { struct stringfragment* next = f->next; + if (freedata) + { + free(f->data); + f->data = NULL; + } free(f); f = next; } } +void stringlist_init(struct stringlist* list) +{ + list->first = NULL; + list->last = NULL; +} + + +char* stringlist_get(struct stringlist *list, int index) +{ + struct stringfragment* f = list->first; + int i = 0; + + while (f) + { + if (i == index) + { + return f->data; + } + f = f->next; + i++; + + } + return i; + +} + +int stringlist_count(struct stringlist *list) +{ + struct stringfragment* f = list->first; + int i = 0; + + while (f) + { + f = f->next; + i++; + } + return i; +} + /* vim: set sw=4 ts=4 expandtab : */ diff --git a/modules/src/data/stringlist.h b/modules/src/data/stringlist.h index 493d7ff1e..3d9b0c4c1 100644 --- a/modules/src/data/stringlist.h +++ b/modules/src/data/stringlist.h @@ -15,7 +15,11 @@ struct stringlist extern void stringlist_add(struct stringlist* list, const char* data); extern void stringlist_addall(struct stringlist* list, struct stringlist* src); -extern void stringlist_free(struct stringlist* list); +extern void stringlist_free(struct stringlist* list, int freedata); +extern void stringlist_init(struct stringlist* list); +extern int stringlist_count(struct stringlist *list); +extern char* stringlist_get(struct stringlist *list, int index); + #endif From dc269e57d815b7fd88a45f840cf8dcf748160f22 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 00:53:52 +0800 Subject: [PATCH 42/84] ANSI C conversion of code and adapt man page accordingly. --- modules/src/em_mes/C_ms_stb.c | 26 +++----------- modules/src/em_mes/em_mes.3 | 65 ++++++++++------------------------- 2 files changed, 22 insertions(+), 69 deletions(-) diff --git a/modules/src/em_mes/C_ms_stb.c b/modules/src/em_mes/C_ms_stb.c index 600b747dc..6dc88957f 100644 --- a/modules/src/em_mes/C_ms_stb.c +++ b/modules/src/em_mes/C_ms_stb.c @@ -19,12 +19,7 @@ void C_ms_stb_cst(char* s, int e1, int e2, arith e3) C_mes_end(); } -void -C_ms_stb_dlb(s, e1, e2, l, off) - char *s; - int e1, e2; - label l; - arith off; +void C_ms_stb_dlb(char *s, int e1, int e2, label l, arith off) { C_mes_begin(ms_stb); if (s) C_scon(s, (arith) (strlen(s)+1)); @@ -34,12 +29,7 @@ C_ms_stb_dlb(s, e1, e2, l, off) C_mes_end(); } -void -C_ms_stb_dnam(s, e1, e2, l, off) - char *s; - int e1, e2; - char *l; - arith off; +void C_ms_stb_dnam(char *s, int e1, int e2, char *l, arith off) { C_mes_begin(ms_stb); if (s) C_scon(s, (arith) (strlen(s)+1)); @@ -49,11 +39,7 @@ C_ms_stb_dnam(s, e1, e2, l, off) C_mes_end(); } -void -C_ms_stb_ilb(s, e1, e2, l) - char *s; - int e1, e2; - label l; +void C_ms_stb_ilb(char *s, int e1, int e2, label l) { C_mes_begin(ms_stb); if (s) C_scon(s, (arith) (strlen(s)+1)); @@ -63,11 +49,7 @@ C_ms_stb_ilb(s, e1, e2, l) C_mes_end(); } -void -C_ms_stb_pnam(s, e1, e2, p) - char *s; - int e1, e2; - char *p; +void C_ms_stb_pnam(char *s, int e1, int e2, char *p) { C_mes_begin(ms_stb); if (s) C_scon(s, (arith) (strlen(s)+1)); diff --git a/modules/src/em_mes/em_mes.3 b/modules/src/em_mes/em_mes.3 index 84b4a7890..3ba4beb8d 100644 --- a/modules/src/em_mes/em_mes.3 +++ b/modules/src/em_mes/em_mes.3 @@ -6,68 +6,39 @@ em_mes \- EM-message generating routines .nf .B #include .PP -.B void C_ms_err() +.B void C_ms_err(void) .PP -.B void C_ms_opt() +.B void C_ms_opt(void) .PP -.B void C_ms_emx(wsiz, psiz) -.B arith wsiz, psiz; +.B void C_ms_emx(arith wsiz, arith psiz) .PP .B #include -.B void C_ms_reg(offs, siz, class, prior) -.B arith offs, siz; -.B int class, prior; +.B void C_ms_reg(arith offs, arith siz, int class, int prior) .PP -.B void C_ms_src(nlines, filnam) -.B int nlines; -.B char *filnam; +.B void C_ms_src(int nlines, char *filnam) .PP -.B void C_ms_flt() +.B void C_ms_flt(void) .PP -.B void C_ms_com(str) -.B char *str; +.B void C_ms_com(char *str) .PP -.B void C_ms_par(nparams) -.B arith nparams; +.B void C_ms_par(arith nparams) .PP .B #include -.B void C_ms_ego(hint, offs, siz, regno) -.B int hint, regno; -.B arith offs, siz; +.B void C_ms_ego(int hint, arith offs, arith siz, int regno) .PP -.B void C_ms_gto() +.B void C_ms_gto(void) .PP -.B void C_ms_stb_cst(s, e1, e2, e3) -.B char *s; -.B int e1, e2; -.B arith e3; +.B void C_ms_stb_cst(char *s, int e1, int e2, arith e3) .PP -.B void C_ms_stb_dlb(s, e1, e2, l, off) -.B char *s; -.B int e1, e2; -.B label l; -.B arith off; +.B void C_ms_stb_dlb(char *s, int e1, int e2, label l, arith off) .PP -.B void C_ms_stb_dnam(s, e1, e2, l, off) -.B char *s; -.B int e1, e2; -.B char *l; -.B arith off; +.B void C_ms_stb_dnam(char *s, int e1, int e2, char *l, arith off) .PP -.B void C_ms_stb_ilb(s, e1, e2, l) -.B char *s; -.B int e1, e2; -.B label l; +.B void C_ms_stb_ilb(char *s, int e1, int e2, label l) .PP -.B void C_ms_stb_pnam(s, e1, e2, p) -.B char *s; -.B int e1, e2; -.B char *p; +.B void C_ms_stb_pnam(char *s, int e1, int e2, char *p) .PP -.B void C_ms_std(s, e1, l) -.B char *s; -.B int e1; -.B int l; +.B void C_ms_std(char* s, int e1, int l) .fi .SH DESCRIPTION This set of routines forms a front end for the @@ -108,7 +79,7 @@ can be used to indicate that a local variable, having offset and size (in bytes) .IR siz , may be stored in a register. -.I Class +.I class indicates the use of the variable. The following classes are allowed (the names are defined in em_reg.h): .RS @@ -122,7 +93,7 @@ pointer variable floating point variable .LP .RE -.I Prior +.I prior is taken to be the priority of the variable; higher numbers indicate better candidates. .PP From add131b6f972b6913db69283d8716bc64f609c94 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 00:56:13 +0800 Subject: [PATCH 43/84] ANSI C conversion of code, rename some parameters to better names and adapt man page accordingly. --- modules/src/flt_arith/b64_sft.c | 7 +- modules/src/flt_arith/flt_add.c | 35 ++--- modules/src/flt_arith/flt_ar2flt.c | 5 +- modules/src/flt_arith/flt_arith.3 | 61 +++------ modules/src/flt_arith/flt_arith.h | 104 +++++++++++--- modules/src/flt_arith/flt_cmp.c | 4 +- modules/src/flt_arith/flt_div.c | 28 ++-- modules/src/flt_arith/flt_flt2ar.c | 4 +- modules/src/flt_arith/flt_modf.c | 4 +- modules/src/flt_arith/flt_mul.c | 29 ++-- modules/src/flt_arith/flt_str2fl.c | 213 ++++++++++++++--------------- modules/src/flt_arith/flt_umin.c | 4 +- modules/src/flt_arith/test.c | 6 +- 13 files changed, 256 insertions(+), 248 deletions(-) diff --git a/modules/src/flt_arith/b64_sft.c b/modules/src/flt_arith/b64_sft.c index ef6d74a9e..cf774accc 100644 --- a/modules/src/flt_arith/b64_sft.c +++ b/modules/src/flt_arith/b64_sft.c @@ -7,10 +7,9 @@ #include "flt_misc.h" -void -flt_b64_sft(e,n) - register struct flt_mantissa *e; - register int n; +void flt_b64_sft( + register struct flt_mantissa *e, + register int n) { if (n > 63 || n < -63) { e->flt_l_32 = 0; diff --git a/modules/src/flt_arith/flt_add.c b/modules/src/flt_arith/flt_add.c index ca9830ec3..21be5c2ed 100644 --- a/modules/src/flt_arith/flt_add.c +++ b/modules/src/flt_arith/flt_add.c @@ -7,23 +7,18 @@ #include "flt_misc.h" -void -flt_add(e1,e2,e3) - register flt_arith *e1,*e2,*e3; +void flt_add(flt_arith *e1, flt_arith *e2,flt_arith *res) { - /* Add two extended numbers e1 and e2, and put the result - in e3 - */ flt_arith ce1, ce2; int diff; flt_status = 0; if ((e2->m1 | e2->m2) == 0L) { - *e3 = *e1; + *res = *e1; return; } if ((e1->m1 | e1->m2) == 0L) { - *e3 = *e2; + *res = *e2; return; } ce2 = *e2; @@ -52,33 +47,31 @@ flt_add(e1,e2,e3) } e1->m1 -= e2->m1; e1->m2 -= e2->m2; - *e3 = *e1; + *res = *e1; } else { if (e1->m2 > e2->m2) e2->m1 -= 1; /* carry in */ e2->m1 -= e1->m1; e2->m2 -= e1->m2; - *e3 = *e2; + *res = *e2; } } else { - *e3 = *e2; - if (flt_b64_add(&e3->flt_mantissa,&e1->flt_mantissa)) {/* addition carry */ - flt_b64_sft(&e3->flt_mantissa, 1); - e3->m1 |= 0x80000000L; /* set max bit */ - e3->flt_exp++; /* increase the exponent */ + *res = *e2; + if (flt_b64_add(&res->flt_mantissa,&e1->flt_mantissa)) {/* addition carry */ + flt_b64_sft(&res->flt_mantissa, 1); + res->m1 |= 0x80000000L; /* set max bit */ + res->flt_exp++; /* increase the exponent */ } } - flt_nrm(e3); - flt_chk(e3); + flt_nrm(res); + flt_chk(res); } -void -flt_sub(e1,e2,e3) - flt_arith *e1,*e2,*e3; +void flt_sub(flt_arith *e1, flt_arith *e2, flt_arith *res) { e2->flt_sign = ! e2->flt_sign; - flt_add(e1,e2,e3); + flt_add(e1,e2,res); e2->flt_sign = ! e2->flt_sign; } diff --git a/modules/src/flt_arith/flt_ar2flt.c b/modules/src/flt_arith/flt_ar2flt.c index 6dac35883..69ddca337 100644 --- a/modules/src/flt_arith/flt_ar2flt.c +++ b/modules/src/flt_arith/flt_ar2flt.c @@ -8,10 +8,7 @@ #include "flt_misc.h" #include -void -flt_arith2flt(n, e, uns) - register arith n; - register flt_arith *e; +void flt_arith2flt(arith n, flt_arith *e, int uns) { /* Convert the arith "n" to a flt_arith "e". */ diff --git a/modules/src/flt_arith/flt_arith.3 b/modules/src/flt_arith/flt_arith.3 index 91bce44ea..8d09c656e 100644 --- a/modules/src/flt_arith/flt_arith.3 +++ b/modules/src/flt_arith/flt_arith.3 @@ -28,51 +28,32 @@ extern int flt_status; #define FLT_STRLEN 32 .PP -.B void flt_add(e1, e2, e3) -.B flt_arith *e1, *e2, *e3; +.B void flt_add(flt_arith *e1, flt_arith *e2,flt_arith *res) .PP -.B void flt_mul(e1, e2, e3) -.B flt_arith *e1, *e2, *e3; +.B void flt_mul(flt_arith *e1, flt_arith *e2, flt_arith *res) .PP -.B void flt_sub(e1, e2, e3) -.B flt_arith *e1, *e2, *e3; +.B void flt_sub(flt_arith *e1, flt_arith *e2, flt_arith *res) .PP -.B void flt_div(e1, e2, e3) -.B flt_arith *e1, *e2, *e3; +.B void flt_div(flt_arith *e1, flt_arith *e2, flt_arith *res) .PP -.B void flt_umin(e) -.B flt_arith *e; +.B void flt_umin(flt_arith *e) .PP -.B void flt_modf(e1, intpart, fractpart) -.B flt_arith *e1, *intpart, *fractpart; +.B void flt_modf(flt_arith *e, flt_arith *ipart, flt_arith *fpart) .PP -.B int flt_cmp(e1, e2) -.B flt_arith *e1, *e2; +.B int flt_cmp(flt_arith *e1, flt_arith *e2) .PP -.B void flt_str2flt(s, e) -.B char *s; -.B flt_arith *e; +.B void flt_str2flt(char *s, flt_arith *e) .PP -.B void flt_flt2str(e, buf, bufsize) -.B flt_arith *e; -.B char *buf; -.B int bufsize; +.B void flt_flt2str(flt_arith *e, char *buf, int bufsize) .PP .B int flt_status; .PP .B #include -.B void flt_arith2flt(n, e, uns) -.B arith n; -.B flt_arith *e; -.B int uns; +.B void flt_arith2flt(arith n, flt_arith *e, int uns) .PP -.B arith flt_flt2arith(e, uns) -.B flt_arith *e; -.B int uns; +.B arith flt_flt2arith(register flt_arith *e, int uns) .PP -.B void flt_b64_sft(m, n) -.B struct flt_mantissa *m; -.B int n; +.B void flt_b64_sft(register struct flt_mantissa *e, register int n) .SH DESCRIPTION This set of routines emulates floating point arithmetic, in a high precision. It is intended primarily for compilers that need to evaluate @@ -86,7 +67,7 @@ adds the numbers indicated by and .I e2 and stores the result indirectly through -.IR e3 . +.IR res. .PP .B flt_mul multiplies the numbers indicated by @@ -94,7 +75,7 @@ multiplies the numbers indicated by and .I e2 and stores the result indirectly through -.IR e3 . +.IR res. .PP .B flt_sub subtracts the number indicated by @@ -102,7 +83,7 @@ subtracts the number indicated by from the one indicated by .I e1 and stores the result indirectly through -.IR e3 . +.IR res . .PP .B flt_div divides the number indicated by @@ -110,7 +91,7 @@ divides the number indicated by by the one indicated by .I e2 and stores the result indirectly through -.IR e3 . +.IR res. .PP .B flt_umin negates the number indicated by @@ -124,20 +105,20 @@ splits the number indicated by in an integer and a fraction part, and stores the integer part through .I intpart and the fraction part through -.IR fractpart . +.IR fpart . So, adding the numbers indicated by -.I intpart +.I ipart and -.I fractpart +.I fpart results (in the absence of rounding error) in the number indicated by .IR e . Also, the absolute value of the number indicated by -.I intpart +.I ipart is less than or equal to the absolute value of the number indicated by .IR e . The absolute value of the number indicated by -.I fractpart +.I fpart is less than 1. .PP .B flt_cmp diff --git a/modules/src/flt_arith/flt_arith.h b/modules/src/flt_arith/flt_arith.h index 9a21e5135..b1c0a9893 100644 --- a/modules/src/flt_arith/flt_arith.h +++ b/modules/src/flt_arith/flt_arith.h @@ -2,8 +2,13 @@ * (c) copyright 1989 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ - +/** @file + * High precision floating point arithmetic module. + * + * Before each operation, the `#flt_status` variable is reset to 0. + * + * + */ #ifndef __FLT_INCLUDED__ #define __FLT_INCLUDED__ @@ -14,36 +19,95 @@ #endif struct flt_mantissa { - uint32_t flt_h_32; /* high order 32 bits of mantissa */ - uint32_t flt_l_32; /* low order 32 bits of mantissa */ + uint32_t flt_h_32; /**< high order 32 bits of mantissa */ + uint32_t flt_l_32; /**< low order 32 bits of mantissa */ }; typedef struct flt_arith { - short flt_sign; /* 0 for positive, 1 for negative */ - short flt_exp; /* between -16384 and 16384 */ - struct flt_mantissa flt_mantissa; /* normalized, in [1,2). */ + short flt_sign; /**< 0 for positive, 1 for negative */ + short flt_exp; /**< between -16384 and 16384 */ + struct flt_mantissa flt_mantissa; /**< mantissa normalized, in [1,2). */ } flt_arith; +/** Status of last floating point operation. */ extern int flt_status; +/** An overflow occurred. */ #define FLT_OVFL 001 +/** An underflow occurred. The result is 0. */ #define FLT_UNFL 002 +/** Divide by 0. */ #define FLT_DIV0 004 +/** String cannot be represented into a real number. */ #define FLT_NOFLT 010 +/** Buffer is too small. */ #define FLT_BTSM 020 -#define FLT_STRLEN 32 /* max length of result of flt_flt2str() */ +#define FLT_STRLEN 32 /**< max length of result of flt_flt2str() */ + +/** Adds the numbers indicated by `e1` and `e2` and stores the result + * in `res`. */ +void flt_add(flt_arith *e1, flt_arith *e2, flt_arith *res); +/** Subtracts the number indicated by `e2` from the one indicated by + * `e1` and stores the result in `res`. */ +void flt_sub(flt_arith *e1, flt_arith *e2, flt_arith *res); +/** Multiplies the numbers indicated by `e1` and `e2` and stores the + * result in `res`. */ +void flt_mul(flt_arith *e1, flt_arith *e2, flt_arith *res); +/** Divides the number indicated by `e1` by the one indicated by `e2` + * and stores the result in `res`. + */ +void flt_div(flt_arith *e1, flt_arith *e2, flt_arith *res); +/** Splits the number indicated by `e` in an integer and a fraction + * part, and stores the integer part through `ipart` and the fraction part + * through `fpart`. Also, the absolute value of the number indicated by + * `ipart` is less than or equal to the absolute value of the number + * indicated by `e`. The absolute value of the number indicated by + * `fpart` is less than 1. + */ +void flt_modf(flt_arith *e, flt_arith *ipart, flt_arith *fpart); +/** Compares the numbers indicated by `e1` and `e2` and returns -1 if + * `e1` < `e2`, 0 if `e1` = `e2`, and 1 if `e1` > `e2`. + */ +int flt_cmp(flt_arith *e1, flt_arith *e2); + +/** Converts the string indicated by `s` to a floating point number, + * and stores this number through `e`. The string should contain a + * floating point constant, which consists of an integer part, a decimal + * point, a fraction part, an e or an E, and an optionally signed integer + * exponent. The integer and fraction parts both consist of a sequence of + * digits. They may not both be missing. The decimal point, the e and the + * exponent may be missing. + */ +void flt_str2flt(char *s, flt_arith *e); +/** Converts the number indicated by `e` into a string, in a scientific + * notation acceptable for EM. The result is stored in `buf`. At most + * `bufsize` characters are stored. The maximum length needed is + * available in the constant `#FLT_STRLEN`. + */ +void flt_flt2str(flt_arith *e, char *buf, int bufsize); +/** Converts the number `n` to the floating point format used + * in this package and returns the result in `e`. If the `uns` + * flag is set, the number n is regarded as an unsigned. + */ +void flt_arith2flt(arith n, flt_arith *e, int uns); +/** Truncates the number indicated by `e` to the largest integer + * value smaller than or equal to the number indicated by `e`. It + * returns this value. If the uns flag is set, the result is to be + * regarded as unsigned. + */ +arith flt_flt2arith(register flt_arith *e, int uns); +/** Negates the number indicated by `e` and stores the result + * in `e`. */ +void flt_umin(flt_arith *e); +/** Shifts the mantissa m |n| bits left or right, depending on the sign + * of n. If n is negative, it is a left-shift; If n is positive, + * it is a right shift. + */ +void flt_b64_sft( + register struct flt_mantissa *e, + register int n); + + -void flt_add(flt_arith *, flt_arith *, flt_arith *); -void flt_sub(flt_arith *, flt_arith *, flt_arith *); -void flt_mul(flt_arith *, flt_arith *, flt_arith *); -void flt_div(flt_arith *, flt_arith *, flt_arith *); -void flt_modf(flt_arith *, flt_arith *, flt_arith *); -int flt_cmp(flt_arith *, flt_arith *); -void flt_str2flt(char *, flt_arith *); -void flt_flt2str(flt_arith *, char *, int); -void flt_arith2flt(arith, flt_arith *, int); -arith flt_flt2arith(flt_arith *, int); -void flt_b64_sft(struct flt_mantissa *, int); -void flt_umin(flt_arith *); #endif /* __FLT_INCLUDED__ */ diff --git a/modules/src/flt_arith/flt_cmp.c b/modules/src/flt_arith/flt_cmp.c index 20150ab36..390bb305c 100644 --- a/modules/src/flt_arith/flt_cmp.c +++ b/modules/src/flt_arith/flt_cmp.c @@ -7,9 +7,7 @@ #include "flt_misc.h" -int -flt_cmp(e1, e2) - register flt_arith *e1, *e2; +int flt_cmp(flt_arith *e1, flt_arith *e2) { flt_arith x; diff --git a/modules/src/flt_arith/flt_div.c b/modules/src/flt_arith/flt_div.c index 3295fe63b..42bae252d 100644 --- a/modules/src/flt_arith/flt_div.c +++ b/modules/src/flt_arith/flt_div.c @@ -8,9 +8,7 @@ #include #include "flt_misc.h" -void -flt_div(e1,e2,e3) - register flt_arith *e1,*e2,*e3; +void flt_div(flt_arith *e1,flt_arith *e2,flt_arith *res) { uint32_t result[2]; register uint32_t *rp; @@ -21,21 +19,21 @@ flt_div(e1,e2,e3) flt_arith cpe1 = *e1; flt_status = 0; - e3->flt_sign = e1->flt_sign ^ e2->flt_sign; + res->flt_sign = e1->flt_sign ^ e2->flt_sign; if ((e2->m1 | e2->m2) == 0) { flt_status = FLT_DIV0; - e3->flt_exp = EXT_MAX; - e3->m1 = 0x80000000; - e3->m2 = 0L; + res->flt_exp = EXT_MAX; + res->m1 = 0x80000000; + res->m2 = 0L; return; } if ((e1->m1 | e1->m2) == 0) { /* 0 / anything == 0 */ - e3->flt_exp = 0; /* make sure */ - e3->m1 = e3->m2 = 0L; - e3->flt_sign = 0; + res->flt_exp = 0; /* make sure */ + res->m1 = res->m2 = 0L; + res->flt_sign = 0; return; } - e3->flt_exp = e1->flt_exp - e2->flt_exp; + res->flt_exp = e1->flt_exp - e2->flt_exp; u[4] = (e1->m2 & 1) << 15; flt_b64_sft(&(cpe1.flt_mantissa),1); @@ -112,9 +110,9 @@ flt_div(e1,e2,e3) *rp |= (j & 1) ? q_est : (q_est<<16); } } - e3->m1 = result[0]; - e3->m2 = result[1]; + res->m1 = result[0]; + res->m2 = result[1]; - flt_nrm(e3); - flt_chk(e3); + flt_nrm(res); + flt_chk(res); } diff --git a/modules/src/flt_arith/flt_flt2ar.c b/modules/src/flt_arith/flt_flt2ar.c index d2a2ac384..7815d9bfd 100644 --- a/modules/src/flt_arith/flt_flt2ar.c +++ b/modules/src/flt_arith/flt_flt2ar.c @@ -8,9 +8,7 @@ #include "flt_misc.h" #include -arith -flt_flt2arith(e, uns) - register flt_arith *e; +arith flt_flt2arith(register flt_arith *e, int uns) { /* Convert the flt_arith "n" to an arith. */ diff --git a/modules/src/flt_arith/flt_modf.c b/modules/src/flt_arith/flt_modf.c index 7f885785a..21553783f 100644 --- a/modules/src/flt_arith/flt_modf.c +++ b/modules/src/flt_arith/flt_modf.c @@ -7,9 +7,7 @@ #include "flt_misc.h" -void -flt_modf(e, ipart, fpart) - register flt_arith *e, *ipart, *fpart; +void flt_modf(flt_arith *e, flt_arith *ipart, flt_arith *fpart) { if (e->flt_exp < 0) { *fpart = *e; diff --git a/modules/src/flt_arith/flt_mul.c b/modules/src/flt_arith/flt_mul.c index 4d989382b..70bb538bc 100644 --- a/modules/src/flt_arith/flt_mul.c +++ b/modules/src/flt_arith/flt_mul.c @@ -8,13 +8,8 @@ #include #include "flt_misc.h" -void -flt_mul(e1,e2,e3) - register flt_arith *e1,*e2,*e3; +void flt_mul(flt_arith *e1, flt_arith *e2, flt_arith *res) { - /* Multiply the extended numbers e1 and e2, and put the - result in e3. - */ register int i,j; /* loop control */ unsigned short mp[4]; unsigned short mc[4]; @@ -25,10 +20,10 @@ flt_mul(e1,e2,e3) flt_status = 0; /* first save the sign (XOR) */ - e3->flt_sign = e1->flt_sign ^ e2->flt_sign; + res->flt_sign = e1->flt_sign ^ e2->flt_sign; /* compute new exponent */ - e3->flt_exp = e1->flt_exp + e2->flt_exp + 1; + res->flt_exp = e1->flt_exp + e2->flt_exp + 1; /* 128 bit multiply of mantissas */ @@ -55,7 +50,7 @@ flt_mul(e1,e2,e3) } if (! (result[0] & 0x8000)) { - e3->flt_exp--; + res->flt_exp--; for (i = 0; i <= 3; i++) { result[i] <<= 1; if (result[i+1]&0x8000) result[i] |= 1; @@ -65,16 +60,16 @@ flt_mul(e1,e2,e3) /* * combine the registers to a total */ - e3->m1 = ((uint32_t)result[0] << 16) + result[1]; - e3->m2 = ((uint32_t)result[2] << 16) + result[3]; + res->m1 = ((uint32_t)result[0] << 16) + result[1]; + res->m2 = ((uint32_t)result[2] << 16) + result[3]; if (result[4] & 0x8000) { - if (++e3->m2 == 0) { - e3->m2 = 0; - if (++e3->m1 == 0) { - e3->m1 = 0x80000000; - e3->flt_exp++; + if (++res->m2 == 0) { + res->m2 = 0; + if (++res->m1 == 0) { + res->m1 = 0x80000000; + res->flt_exp++; } } } - flt_chk(e3); + flt_chk(res); } diff --git a/modules/src/flt_arith/flt_str2fl.c b/modules/src/flt_arith/flt_str2fl.c index 9e49b1453..03c510ae3 100644 --- a/modules/src/flt_arith/flt_str2fl.c +++ b/modules/src/flt_arith/flt_str2fl.c @@ -84,118 +84,116 @@ for (i=1;i<20;i++) { */ static flt_arith s10pow[] = { /* representation of 10 ** i */ - { 0, 0, 0x80000000, 0 }, - { 0, 3, 0xA0000000, 0 }, - { 0, 6, 0xC8000000, 0 }, - { 0, 9, 0xFA000000, 0 }, - { 0, 13, 0x9C400000, 0 }, - { 0, 16, 0xC3500000, 0 }, - { 0, 19, 0xF4240000, 0 }, - { 0, 23, 0x98968000, 0 }, - { 0, 26, 0xBEBC2000, 0 }, - { 0, 29, 0xEE6B2800, 0 }, - { 0, 33, 0x9502F900, 0 }, - { 0, 36, 0xBA43B740, 0 }, - { 0, 39, 0xE8D4A510, 0 }, - { 0, 43, 0x9184E72A, 0 }, - { 0, 46, 0xB5E620F4, 0x80000000 }, - { 0, 49, 0xE35FA931, 0xA0000000 }, - { 0, 53, 0x8E1BC9BF, 0x04000000 }, - { 0, 56, 0xB1A2BC2E, 0xC5000000 }, - { 0, 59, 0xDE0B6B3A, 0x76400000 }, - { 0, 63, 0x8AC72304, 0x89E80000 }, - { 0, 66, 0xAD78EBC5, 0xAC620000 }, - { 0, 69, 0xD8D726B7, 0x177A8000 }, - { 0, 73, 0x87867832, 0x6EAC9000 }, - { 0, 76, 0xA968163F, 0x0A57B400 }, - { 0, 79, 0xD3C21BCE, 0xCCEDA100 }, - { 0, 83, 0x84595161, 0x401484A0 }, - { 0, 86, 0xA56FA5B9, 0x9019A5C8 }, - { 0, 89, 0xCECB8F27, 0xF4200F3A } + { 0, 0, {0x80000000, 0} }, + { 0, 3, {0xA0000000, 0} }, + { 0, 6, {0xC8000000, 0} }, + { 0, 9, {0xFA000000, 0} }, + { 0, 13, {0x9C400000, 0} }, + { 0, 16, {0xC3500000, 0} }, + { 0, 19, {0xF4240000, 0} }, + { 0, 23, {0x98968000, 0} }, + { 0, 26, {0xBEBC2000, 0} }, + { 0, 29, {0xEE6B2800, 0} }, + { 0, 33, {0x9502F900, 0} }, + { 0, 36, {0xBA43B740, 0} }, + { 0, 39, {0xE8D4A510, 0} }, + { 0, 43, {0x9184E72A, 0} }, + { 0, 46, {0xB5E620F4, 0x80000000} }, + { 0, 49, {0xE35FA931, 0xA0000000} }, + { 0, 53, {0x8E1BC9BF, 0x04000000} }, + { 0, 56, {0xB1A2BC2E, 0xC5000000} }, + { 0, 59, {0xDE0B6B3A, 0x76400000} }, + { 0, 63, {0x8AC72304, 0x89E80000} }, + { 0, 66, {0xAD78EBC5, 0xAC620000} }, + { 0, 69, {0xD8D726B7, 0x177A8000} }, + { 0, 73, {0x87867832, 0x6EAC9000} }, + { 0, 76, {0xA968163F, 0x0A57B400} }, + { 0, 79, {0xD3C21BCE, 0xCCEDA100} }, + { 0, 83, {0x84595161, 0x401484A0} }, + { 0, 86, {0xA56FA5B9, 0x9019A5C8} }, + { 0, 89, {0xCECB8F27, 0xF4200F3A }} }; static flt_arith big_10pow[] = { /* representation of 10 ** (28*i) */ - { 0, 0, 0x80000000, 0 }, - { 0, 93, 0x813F3978, 0xF8940984 }, - { 0, 186, 0x82818F12, 0x81ED44A0 }, - { 0, 279, 0x83C7088E, 0x1AAB65DB }, - { 0, 372, 0x850FADC0, 0x9923329E }, - { 0, 465, 0x865B8692, 0x5B9BC5C2 }, - { 0, 558, 0x87AA9AFF, 0x79042287 }, - { 0, 651, 0x88FCF317, 0xF22241E2 }, - { 0, 744, 0x8A5296FF, 0xE33CC930 }, - { 0, 837, 0x8BAB8EEF, 0xB6409C1A }, - { 0, 930, 0x8D07E334, 0x55637EB3 }, - { 0, 1023, 0x8E679C2F, 0x5E44FF8F }, - { 0, 1116, 0x8FCAC257, 0x558EE4E6 }, - { 0, 1209, 0x91315E37, 0xDB165AA9 }, - { 0, 1302, 0x929B7871, 0xDE7F22B9 }, - { 0, 1395, 0x940919BB, 0xD4620B6D }, - { 0, 1488, 0x957A4AE1, 0xEBF7F3D4 }, - { 0, 1581, 0x96EF14C6, 0x454AA840 }, - { 0, 1674, 0x98678061, 0x27ECE4F5 }, - { 0, 1767, 0x99E396C1, 0x3A3ACFF2 } + { 0, 0, {0x80000000, 0} }, + { 0, 93, {0x813F3978, 0xF8940984} }, + { 0, 186, {0x82818F12, 0x81ED44A0} }, + { 0, 279, {0x83C7088E, 0x1AAB65DB} }, + { 0, 372, {0x850FADC0, 0x9923329E} }, + { 0, 465, {0x865B8692, 0x5B9BC5C2} }, + { 0, 558, {0x87AA9AFF, 0x79042287} }, + { 0, 651, {0x88FCF317, 0xF22241E2} }, + { 0, 744, {0x8A5296FF, 0xE33CC930} }, + { 0, 837, {0x8BAB8EEF, 0xB6409C1A} }, + { 0, 930, {0x8D07E334, 0x55637EB3} }, + { 0, 1023, {0x8E679C2F, 0x5E44FF8F} }, + { 0, 1116, {0x8FCAC257, 0x558EE4E6} }, + { 0, 1209, {0x91315E37, 0xDB165AA9} }, + { 0, 1302, {0x929B7871, 0xDE7F22B9} }, + { 0, 1395, {0x940919BB, 0xD4620B6D} }, + { 0, 1488, {0x957A4AE1, 0xEBF7F3D4} }, + { 0, 1581, {0x96EF14C6, 0x454AA840} }, + { 0, 1674, {0x98678061, 0x27ECE4F5} }, + { 0, 1767, {0x99E396C1, 0x3A3ACFF2} } }; static flt_arith r_10pow[] = { /* representation of 10 ** -i */ - { 0, 0, 0x80000000, 0 }, - { 0, -4, 0xCCCCCCCC, 0xCCCCCCCD }, - { 0, -7, 0xA3D70A3D, 0x70A3D70A }, - { 0, -10, 0x83126E97, 0x8D4FDF3B }, - { 0, -14, 0xD1B71758, 0xE219652C }, - { 0, -17, 0xA7C5AC47, 0x1B478423 }, - { 0, -20, 0x8637BD05, 0xAF6C69B6 }, - { 0, -24, 0xD6BF94D5, 0xE57A42BC }, - { 0, -27, 0xABCC7711, 0x8461CEFD }, - { 0, -30, 0x89705F41, 0x36B4A597 }, - { 0, -34, 0xDBE6FECE, 0xBDEDD5BF }, - { 0, -37, 0xAFEBFF0B, 0xCB24AAFF }, - { 0, -40, 0x8CBCCC09, 0x6F5088CC }, - { 0, -44, 0xE12E1342, 0x4BB40E13 }, - { 0, -47, 0xB424DC35, 0x095CD80F }, - { 0, -50, 0x901D7CF7, 0x3AB0ACD9 }, - { 0, -54, 0xE69594BE, 0xC44DE15B }, - { 0, -57, 0xB877AA32, 0x36A4B449 }, - { 0, -60, 0x9392EE8E, 0x921D5D07 }, - { 0, -64, 0xEC1E4A7D, 0xB69561A5 }, - { 0, -67, 0xBCE50864, 0x92111AEB }, - { 0, -70, 0x971DA050, 0x74DA7BEF }, - { 0, -74, 0xF1C90080, 0xBAF72CB1 }, - { 0, -77, 0xC16D9A00, 0x95928A27 }, - { 0, -80, 0x9ABE14CD, 0x44753B53 }, - { 0, -84, 0xF79687AE, 0xD3EEC551 }, - { 0, -87, 0xC6120625, 0x76589DDB }, - { 0, -90, 0x9E74D1B7, 0x91E07E48 } + { 0, 0, {0x80000000, 0} }, + { 0, -4, {0xCCCCCCCC, 0xCCCCCCCD} }, + { 0, -7, {0xA3D70A3D, 0x70A3D70A} }, + { 0, -10, {0x83126E97, 0x8D4FDF3B} }, + { 0, -14, {0xD1B71758, 0xE219652C} }, + { 0, -17, {0xA7C5AC47, 0x1B478423} }, + { 0, -20, {0x8637BD05, 0xAF6C69B6} }, + { 0, -24, {0xD6BF94D5, 0xE57A42BC} }, + { 0, -27, {0xABCC7711, 0x8461CEFD} }, + { 0, -30, {0x89705F41, 0x36B4A597} }, + { 0, -34, {0xDBE6FECE, 0xBDEDD5BF} }, + { 0, -37, {0xAFEBFF0B, 0xCB24AAFF} }, + { 0, -40, {0x8CBCCC09, 0x6F5088CC} }, + { 0, -44, {0xE12E1342, 0x4BB40E13} }, + { 0, -47, {0xB424DC35, 0x095CD80F} }, + { 0, -50, {0x901D7CF7, 0x3AB0ACD9} }, + { 0, -54, {0xE69594BE, 0xC44DE15B} }, + { 0, -57, {0xB877AA32, 0x36A4B449} }, + { 0, -60, {0x9392EE8E, 0x921D5D07} }, + { 0, -64, {0xEC1E4A7D, 0xB69561A5} }, + { 0, -67, {0xBCE50864, 0x92111AEB} }, + { 0, -70, {0x971DA050, 0x74DA7BEF} }, + { 0, -74, {0xF1C90080, 0xBAF72CB1} }, + { 0, -77, {0xC16D9A00, 0x95928A27} }, + { 0, -80, {0x9ABE14CD, 0x44753B53} }, + { 0, -84, {0xF79687AE, 0xD3EEC551} }, + { 0, -87, {0xC6120625, 0x76589DDB} }, + { 0, -90, {0x9E74D1B7, 0x91E07E48} } }; static flt_arith r_big_10pow[] = { /* representation of 10 ** -(28*i) */ - { 0, 0, 0x80000000, 0 }, - { 0, -94, 0xFD87B5F2, 0x8300CA0E }, - { 0, -187, 0xFB158592, 0xBE068D2F }, - { 0, -280, 0xF8A95FCF, 0x88747D94 }, - { 0, -373, 0xF64335BC, 0xF065D37D }, - { 0, -466, 0xF3E2F893, 0xDEC3F126 }, - { 0, -559, 0xF18899B1, 0xBC3F8CA2 }, - { 0, -652, 0xEF340A98, 0x172AACE5 }, - { 0, -745, 0xECE53CEC, 0x4A314EBE }, - { 0, -838, 0xEA9C2277, 0x23EE8BCB }, - { 0, -931, 0xE858AD24, 0x8F5C22CA }, - { 0, -1024, 0xE61ACF03, 0x3D1A45DF }, - { 0, -1117, 0xE3E27A44, 0x4D8D98B8 }, - { 0, -1210, 0xE1AFA13A, 0xFBD14D6E }, - { 0, -1303, 0xDF82365C, 0x497B5454 }, - { 0, -1396, 0xDD5A2C3E, 0xAB3097CC }, - { 0, -1489, 0xDB377599, 0xB6074245 }, - { 0, -1582, 0xD91A0545, 0xCDB51186 }, - { 0, -1675, 0xD701CE3B, 0xD387BF48 }, - { 0, -1768, 0xD4EEC394, 0xD6258BF8 } + { 0, 0, {0x80000000, 0} }, + { 0, -94, {0xFD87B5F2, 0x8300CA0E} }, + { 0, -187, {0xFB158592, 0xBE068D2F} }, + { 0, -280, {0xF8A95FCF, 0x88747D94} }, + { 0, -373, {0xF64335BC, 0xF065D37D} }, + { 0, -466, {0xF3E2F893, 0xDEC3F126} }, + { 0, -559, {0xF18899B1, 0xBC3F8CA2} }, + { 0, -652, {0xEF340A98, 0x172AACE5} }, + { 0, -745, {0xECE53CEC, 0x4A314EBE} }, + { 0, -838, {0xEA9C2277, 0x23EE8BCB} }, + { 0, -931, {0xE858AD24, 0x8F5C22CA} }, + { 0, -1024, {0xE61ACF03, 0x3D1A45DF} }, + { 0, -1117, {0xE3E27A44, 0x4D8D98B8} }, + { 0, -1210, {0xE1AFA13A, 0xFBD14D6E} }, + { 0, -1303, {0xDF82365C, 0x497B5454} }, + { 0, -1396, {0xDD5A2C3E, 0xAB3097CC} }, + { 0, -1489, {0xDB377599, 0xB6074245} }, + { 0, -1582, {0xD91A0545, 0xCDB51186} }, + { 0, -1675, {0xD701CE3B, 0xD387BF48} }, + { 0, -1768, {0xD4EEC394, 0xD6258BF8} } }; #define BIGSZ (sizeof(big_10pow)/sizeof(big_10pow[0])) #define SMALLSZ (sizeof(s10pow)/sizeof(s10pow[0])) -static -add_exponent(e, exp) - register flt_arith *e; +static void add_exponent(register flt_arith *e, int exp) { int neg = exp < 0; int divsz, modsz; @@ -208,7 +206,7 @@ add_exponent(e, exp) if (!status) status = flt_status; flt_mul(e, (neg ? r_10pow : s10pow) + modsz, &x); if (!status) status = flt_status; - while (divsz >= BIGSZ) { + while (divsz >= (int)BIGSZ) { flt_mul(&x, neg ? &r_big_10pow[BIGSZ-1] : &big_10pow[BIGSZ-1],&x); if (!status) status = flt_status; divsz -= BIGSZ-1; @@ -218,10 +216,7 @@ add_exponent(e, exp) flt_status = status; } -void -flt_str2flt(s, e) - register char *s; - register flt_arith *e; +void flt_str2flt(char *s, flt_arith *e) { register int c; int dotseen = 0; @@ -291,10 +286,7 @@ flt_str2flt(s, e) #define NDIG 18 -static char * -flt_ecvt(e, decpt, sign) - register flt_arith *e; - int *decpt, *sign; +static char *flt_ecvt(register flt_arith *e, int *decpt, int *sign) { /* Like ecvt(), but for extended precision */ @@ -420,10 +412,7 @@ flt_ecvt(e, decpt, sign) return buf; } -void -flt_flt2str(e, buf, bufsize) - flt_arith *e; - char *buf; +void flt_flt2str(flt_arith *e, char *buf, int bufsize) { int sign, dp; diff --git a/modules/src/flt_arith/flt_umin.c b/modules/src/flt_arith/flt_umin.c index c1648f8c0..d8ca265d4 100644 --- a/modules/src/flt_arith/flt_umin.c +++ b/modules/src/flt_arith/flt_umin.c @@ -7,9 +7,7 @@ #include "flt_misc.h" -void -flt_umin(e) - flt_arith *e; +void flt_umin(flt_arith *e) { /* Unary minus */ diff --git a/modules/src/flt_arith/test.c b/modules/src/flt_arith/test.c index dfc4a694a..9a8a9707c 100644 --- a/modules/src/flt_arith/test.c +++ b/modules/src/flt_arith/test.c @@ -24,6 +24,8 @@ struct tests { { 0, 0, 0, 0} }; +int dotest(register struct tests *p); + int main() { @@ -37,9 +39,7 @@ main() return exit_status; } -int -dotest(p) - register struct tests *p; +int dotest(register struct tests *p) { char buf[128]; flt_arith e1, e2, e; From 8b290cf68a30fb0675ebe5c0a43a8544a8e4f27b Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 00:57:58 +0800 Subject: [PATCH 44/84] ANSI C conversion of code, rename some parameters to better names and adapt man page accordingly. --- modules/src/string/ack_string.h | 6 +-- modules/src/string/btscat.c | 7 +--- modules/src/string/btscmp.c | 7 +--- modules/src/string/btscpy.c | 5 +-- modules/src/string/btszero.c | 5 +-- modules/src/string/long2str.c | 9 ++--- modules/src/string/str2bts.c | 12 ++---- modules/src/string/str2long.c | 9 +---- modules/src/string/strindex.c | 5 +-- modules/src/string/string.3 | 67 ++++++++++++--------------------- modules/src/string/strrindex.c | 5 +-- modules/src/string/strzero.c | 4 +- 12 files changed, 43 insertions(+), 98 deletions(-) diff --git a/modules/src/string/ack_string.h b/modules/src/string/ack_string.h index 56b646e4c..a74e89f18 100644 --- a/modules/src/string/ack_string.h +++ b/modules/src/string/ack_string.h @@ -13,9 +13,9 @@ char *strzero(char *s); char *str2bts(char *s, char *b, int *n); char *long2str(long l, int b); long str2long(char *s, int b); -char *btscpy(char *s1, char *s2, int n); -char *btscat(char *s1, int n1, char *s2, int n2); -int btscmp(char *s1, int n1, char *s2, int n2); +char *btscpy(char *b1, char *b2, int n); +char *btscat(char *b1, int n1, char *b2, int n2); +int btscmp(char *b1, int n1, char *b2, int n2); char *btszero(char *b, int n); char *bts2str(char *b, int n, char *s); diff --git a/modules/src/string/btscat.c b/modules/src/string/btscat.c index f5d58781e..2506007a7 100644 --- a/modules/src/string/btscat.c +++ b/modules/src/string/btscat.c @@ -8,12 +8,7 @@ #include "ack_string.h" -char * -btscat(b1, n1, b2, n2) - char *b1; - int n1; - register char *b2; - register int n2; +char *btscat(char* b1, int n1, register char *b2, register int n2) { register char *b = b1 + n1; diff --git a/modules/src/string/btscmp.c b/modules/src/string/btscmp.c index 30300babb..5f9ad329a 100644 --- a/modules/src/string/btscmp.c +++ b/modules/src/string/btscmp.c @@ -8,12 +8,9 @@ #include "ack_string.h" -int -btscmp(b1, n1, b2, n2) - register char *b1, *b2; - int n1, n2; +int btscmp(register char *b1, int n1, register char *b2, int n2) { - register n = (n1 <= n2) ? n1 : n2; + register int n = (n1 <= n2) ? n1 : n2; while (n-- > 0) { if (*b1++ != *b2++) diff --git a/modules/src/string/btscpy.c b/modules/src/string/btscpy.c index e54606dcd..fe43ea43b 100644 --- a/modules/src/string/btscpy.c +++ b/modules/src/string/btscpy.c @@ -8,10 +8,7 @@ #include "ack_string.h" -char * -btscpy(b1, b2, n) - register char *b1, *b2; - register int n; +char *btscpy(register char *b1, register char *b2, register int n) { char *b1s = b1; diff --git a/modules/src/string/btszero.c b/modules/src/string/btszero.c index f7e36634b..edb50577d 100644 --- a/modules/src/string/btszero.c +++ b/modules/src/string/btszero.c @@ -8,10 +8,7 @@ #include "ack_string.h" -char * -btszero(b, n) - char *b; - register int n; +char *btszero(char *b, register int n) { register char *s = b; diff --git a/modules/src/string/long2str.c b/modules/src/string/long2str.c index 5ace9bd43..eb54ac285 100644 --- a/modules/src/string/long2str.c +++ b/modules/src/string/long2str.c @@ -14,10 +14,7 @@ #define MAXWIDTH 32 -char * -long2str(val, base) - register long val; - register base; +char *long2str(register long val, register int base) { static char numbuf[MAXWIDTH]; static char vec[] = "0123456789ABCDEF"; @@ -40,10 +37,10 @@ long2str(val, base) if (base < 0) { /* unsigned */ base = -base; if (val < 0L) { /* taken from Amoeba src */ - register mod, i; + register int mod, i; overflow: mod = 0; - for (i = 0; i < 8 * sizeof val; i++) { + for (i = 0; i < 8 * (int)sizeof(val); i++) { mod <<= 1; if (val < 0) mod++; diff --git a/modules/src/string/str2bts.c b/modules/src/string/str2bts.c index d3fd6d856..c9ad2aac1 100644 --- a/modules/src/string/str2bts.c +++ b/modules/src/string/str2bts.c @@ -8,9 +8,7 @@ #include "ack_string.h" -static -is_oct(c) - char c; +static int is_oct(char c) { return ((unsigned int)(c-'0') <= ('7'-'0')); } @@ -20,11 +18,7 @@ is_oct(c) The ascii length of the resulting string is returned, including the terminating null-character. */ -char * -str2bts(str, bts, pn) - register char *str; - char *bts; - int *pn; +char *str2bts(register char *str, char *bts, int *pn) { register char *t = bts; @@ -53,7 +47,7 @@ str2bts(str, bts, pn) break; default: if (is_oct(*str)) { - register cnt = 0, oct = 0; + register int cnt = 0, oct = 0; do oct = oct * 8 + *str - '0'; diff --git a/modules/src/string/str2long.c b/modules/src/string/str2long.c index 66760b91f..3225449eb 100644 --- a/modules/src/string/str2long.c +++ b/modules/src/string/str2long.c @@ -8,9 +8,7 @@ #include "ack_string.h" -value(c, b) - char c; - int b; +static int value(char c, int b) { register int ch; @@ -23,10 +21,7 @@ value(c, b) return b; } -long -str2long(str, base) - register char *str; - int base; +long str2long(register char *str, int base) { int minus = 0, d; long l = 0; diff --git a/modules/src/string/strindex.c b/modules/src/string/strindex.c index 66d2e432f..1d901b72f 100644 --- a/modules/src/string/strindex.c +++ b/modules/src/string/strindex.c @@ -8,10 +8,7 @@ #include "ack_string.h" -char * -strindex(s, c) - register char *s; - int c; +char *strindex(register char *s, int c) { while (*s) if (*s++ == c) diff --git a/modules/src/string/string.3 b/modules/src/string/string.3 index 8d1877a22..bb12a31f9 100644 --- a/modules/src/string/string.3 +++ b/modules/src/string/string.3 @@ -9,46 +9,27 @@ conversions between strings and row of bytes .nf .B #include .PP -.B char *strindex(s, c) -.B char *s, c; +.B char *strindex(char *s, int c) .PP -.B char *strrindex(s, c) -.B char *s, c; +.B char *strrindex(char *s, int c) .PP -.B char *strzero(s) -.B char *s; +.B char *strzero(char *s) .PP -.B char *str2bts(s, b, pn) -.B char *s, *b; -.B int *pn; +.B char *str2bts(char *s, char *b, int *n) .PP -.B char *long2str(l, base) -.B long l; -.B int base; +.B char *long2str(long l, int b) .PP -.B long str2long(s, base) -.B char *s; -.B int base; +.B long str2long(char *s, int b) .PP -.B char *btscpy(b1, b2, n) -.B char *b1, *b2; -.B int n; +.B char *btscpy(char *b1, char *b2, int n) .PP -.B char *btscat(b1, n1, b2, n2) -.B char *b1, *b2; -.B int n1, n2; +.B char *btscat(char *b1, int n1, char *b2, int n2) .PP -.B int btscmp(b1, n1, b2, n2) -.B char *b1, *b2; -.B int n1, n2; +.B int btscmp(char *b1, int n1, char *b2, int n2) .PP -.B char *btszero(b, n) -.B char *b; -.B int n; +.B char *btszero(char *b, int n) .PP -.B char *bts2str(b, n, s) -.B char *b, *s; -.B int n; +.B char *bts2str(char *b, int n, char *s) .fi .SH DESCRIPTION The @@ -60,7 +41,7 @@ functions operate on variable-length rows of bytes, regardless of null bytes. Neither of these functions check for overflow of any receiving area. .PP -.I Strindex +.I strindex .RI ( strrindex ) returns a pointer to the first (last) occurrence of character @@ -72,12 +53,12 @@ or zero if does not occur in .IR s . .PP -.I Strzero +.I strzero turns .I s into a null string. .PP -.I Bts2str +.I bts2str turns a row of .I n consecutive bytes, the first of which is pointed by @@ -100,7 +81,7 @@ is turned into the string consisting of the following characters .RE The latter string could be represented in C as "\e\e000\e\en". .PP -.I Str2bts +.I str2bts turns string .I s into a sequence of bytes pointed by @@ -108,7 +89,7 @@ into a sequence of bytes pointed by It has the inverse effect to .IR bts2str . The length of the resulting byte sequence is returned in -.RI * pn . +.RI *n . .br Both the functions .I bts2str @@ -116,7 +97,7 @@ and .I str2bts return a pointer to the result. .PP -.I Long2str +.I long2str converts a long value .I l into a null-terminated string according to @@ -126,13 +107,13 @@ This base may be any of 2..16. A negative base (in the range -16..-2) indicates that the long must be seen as unsigned. A pointer to the string is returned. -.I Str2long +.I str2long returns the value that is represented in .IR s , according to .IR base . .PP -.I Btscpy +.I btscpy copies .I n bytes from the string of bytes @@ -142,7 +123,7 @@ to and returns .IR b1 . .PP -.I Btscat +.I btscat appends a copy of .I n2 bytes from @@ -152,10 +133,10 @@ to the end of consisting of .I n1 bytes. -.I B1 +.I b1 is returned. .PP -.I Btscmp +.I btscmp compares row of bytes .I b1 with length @@ -170,12 +151,12 @@ is lexicographically greater then, equal to, or less than .IR b2 , respectively. .PP -.I Btszero +.I btszero places .I n null bytes in the string .IR b . -.I B +.I b is returned. .SH FILES ~em/modules/lib/libstring.a diff --git a/modules/src/string/strrindex.c b/modules/src/string/strrindex.c index 63947d835..0468ca8db 100644 --- a/modules/src/string/strrindex.c +++ b/modules/src/string/strrindex.c @@ -6,10 +6,7 @@ #include "ack_string.h" -char * -strrindex(str, chr) - register char *str; - int chr; +char *strrindex(register char *str, int chr) { register char *retptr = 0; diff --git a/modules/src/string/strzero.c b/modules/src/string/strzero.c index 8a0d85060..94e9b90c6 100644 --- a/modules/src/string/strzero.c +++ b/modules/src/string/strzero.c @@ -8,9 +8,7 @@ #include "ack_string.h" -char * -strzero(s) - char *s; +char *strzero(char *s) { *s = '\0'; return s; From 3466e84f46f53782a25417572cc359957743f9ee Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:01:21 +0800 Subject: [PATCH 45/84] ANSI C conversion of code, adapt man pages accordingly. Some autodocs added. --- modules/src/read_em/EM_vars.c | 2 +- modules/src/read_em/em_comp.h | 104 ++++++---- modules/src/read_em/mkcalls.c | 34 ++-- modules/src/read_em/read_em.3 | 15 +- modules/src/read_em/read_em.c | 350 ++++++++++++++++++---------------- modules/src/read_em/reade.c | 102 ++++------ modules/src/read_em/readk.c | 21 +- 7 files changed, 313 insertions(+), 315 deletions(-) diff --git a/modules/src/read_em/EM_vars.c b/modules/src/read_em/EM_vars.c index e8808f27d..3865c82b5 100644 --- a/modules/src/read_em/EM_vars.c +++ b/modules/src/read_em/EM_vars.c @@ -6,7 +6,7 @@ /* Variables must be declared somewhere ... */ -#include +#include "em_arith.h" char *EM_error = 0; char *EM_filename = 0; diff --git a/modules/src/read_em/em_comp.h b/modules/src/read_em/em_comp.h index 520b5e3f5..80f3e1c12 100644 --- a/modules/src/read_em/em_comp.h +++ b/modules/src/read_em/em_comp.h @@ -2,22 +2,34 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ +/** @file + * A module to read EM assembly code in either + * human readable format or in compact format. + * It only permits to have one file open at a time, + * because it contains global variables. + */ + /* $Id$ */ #ifndef __EMCOMP_INCLUDED__ #define __EMCOMP_INCLUDED__ #include +#include "em_arith.h" +#include "em_label.h" +/** Represents instruction arguments. */ struct e_arg { - int ema_argtype; /* type of this argument */ + /** Type of this argument. The different argument + * types are defined in `em_ptyp.h` */ + int ema_argtype; union e_simple_arg { - arith emu_cst; /* a cst */ - label emu_dlb; /* a numeric data label */ - label emu_ilb; /* an instruction label */ - char *emu_dnam; /* a data label */ - char *emu_pnam; /* a procedure name */ - char *emu_string; /* a string (fcon,icon,ucon,scon) */ - } ema_arg; + arith emu_cst; /**< a constant */ + label emu_dlb; /**< a numeric data label */ + label emu_ilb; /**< an instruction label */ + char *emu_dnam; /**< a data label */ + char *emu_pnam; /**< a procedure name */ + char *emu_string; /**< a string (fcon,icon,ucon,scon) */ + } ema_arg; /**< The actual argument, a union representing the args. */ arith ema_szoroff; }; #define ema_cst ema_arg.emu_cst @@ -28,40 +40,53 @@ struct e_arg { #define ema_nlocals ema_szoroff #define ema_string ema_arg.emu_string - +/** Represents an instruction and its arguments. */ struct e_instr { - int em_type; /* Type of this instr */ -#define EM_MNEM 256 /* A machine instruction */ -#define EM_PSEU 257 /* A pseudo */ -#define EM_STARTMES 258 /* Start of a MES pseudo */ -#define EM_MESARG 259 /* A member in a MES list */ -#define EM_ENDMES 260 /* End of a MES pseudo */ -#define EM_DEFILB 261 /* An instruction label definition */ -#define EM_DEFDLB 262 /* A numeric data label definition */ -#define EM_DEFDNAM 263 /* A non-numeric data label def */ -#define EM_ERROR 264 /* Recoverable error */ -#define EM_FATAL 265 /* Unrecoverable error */ -#define EM_EOF 266 /* End of file */ - int em_opcode; - struct e_arg em_arg; + int em_type; /**< Type of this instruction + , one of the EM_XXXX constants. */ +#define EM_MNEM 256 /**< A machine instruction type */ +#define EM_PSEU 257 /**< A pseudo instruction type */ +#define EM_STARTMES 258 /**< Start of a MES pseudo instruction */ +#define EM_MESARG 259 /**< A MES argument type */ +#define EM_ENDMES 260 /**< End of a MES type */ +#define EM_DEFILB 261 /**< An instruction label definition */ +#define EM_DEFDLB 262 /**< A numeric data label definition */ +#define EM_DEFDNAM 263 /**< A non-numeric data label definition */ +#define EM_ERROR 264 /**< Recoverable error */ +#define EM_FATAL 265 /**< Unrecoverable error */ +#define EM_EOF 266 /**< End of file */ + int em_opcode; /**< opcode of the instruction. */ + struct e_arg em_arg; /**< argument of the instruction. */ }; -_PROTOTYPE(int EM_open, (char *)); -_PROTOTYPE(void EM_close, (void)); -_PROTOTYPE(int EM_getinstr, (struct e_instr *)); -_PROTOTYPE(int EM_mkcalls, (struct e_instr *)); +/** Initializes library to read from the specified file `filename`. If + * `filename` is a NULL pointer, reading is done from standard input. + * Returns 1 on success or 0 on failure with an error message in `EM_error`. + */ +int EM_open(char *filename); +/** Closes the library by freeing the resources that were previously opened + * using `EM_open()`. + */ +void EM_close(void); +/** Reads the next EM instruction, and returns it in the structure pointed to by + * `instr`. Returns 0 in case of error. + */ +int EM_getinstr(struct e_instr *instr); +int EM_mkcalls(struct e_instr *instr); -extern arith - EM_holsize; +extern arith EM_holsize; +/** The size of the BSS block in bytes. */ #define EM_bsssize EM_holsize -extern int - EM_holinit; +/** 1 if the value should be initialized to the specified value, + * otherwise 0 */ +extern int EM_holinit; #define EM_bssinit EM_holinit #define em_ilb em_arg.ema_ilb #define em_dlb em_arg.ema_dlb #define em_dnam em_arg.ema_dnam #define em_argtype em_arg.ema_argtype + #define em_cst em_arg.ema_cst #define em_pnam em_arg.ema_pnam #define em_nlocals em_arg.ema_nlocals @@ -75,8 +100,17 @@ extern int extern char *EM_error, *EM_filename; -extern unsigned int - EM_lineno; -extern int - EM_wordsize, EM_pointersize; + +/** Line number of the last line read by `EM_getinstr()`. */ +extern unsigned int EM_lineno; +/** Word size in bytes for this EM assembly file. The + * value is valid only after the first instruction + * has been read. + */ +extern int EM_wordsize; +/** Pointer size in bytes for this EM assembly file. The + * value is valid only after the first instruction + * has been read. + */ +extern int EM_pointersize; #endif /* __EMCOMP_INCLUDED__ */ diff --git a/modules/src/read_em/mkcalls.c b/modules/src/read_em/mkcalls.c index f6dd3cb76..8651427b8 100644 --- a/modules/src/read_em/mkcalls.c +++ b/modules/src/read_em/mkcalls.c @@ -9,12 +9,12 @@ EM_mkcalls */ -#include -#include -#include -#include +#include "em_spec.h" +#include "em_mnem.h" +#include "em_pseu.h" +#include "em_flag.h" #include "em_ptyp.h" -#include +#include "em.h" #include "em_comp.h" #include @@ -31,9 +31,7 @@ static int listtype = 0; /* indicates pseudo when generating code for The argument must be of a type allowed by "typset". Return a pointer to the next argument. */ -PRIVATE int -checkarg(arg, typset) - register struct e_arg *arg; +PRIVATE int checkarg(register struct e_arg *arg, int typset) { if (((!typset) && arg->ema_argtype) || @@ -58,9 +56,7 @@ checkarg(arg, typset) /* EM_doinstr: An EM instruction */ -PRIVATE void -EM_doinstr(p) - register struct e_instr *p; +PRIVATE void EM_doinstr(register struct e_instr *p) { register int parametertype; /* parametertype of the instruction */ @@ -94,9 +90,7 @@ EM_doinstr(p) #include "C_mnem.h" } -PRIVATE void -EM_dopseudo(p) - register struct e_instr *p; +PRIVATE void EM_dopseudo(register struct e_instr *p) { switch(p->em_opcode) { @@ -326,9 +320,7 @@ EM_dopseudo(p) } } -PRIVATE void -EM_docon(p) - register struct e_instr *p; +PRIVATE void EM_docon(register struct e_instr *p) { checkarg(&(p->em_arg), val_ptyp); switch(p->em_argtype) { @@ -365,9 +357,7 @@ EM_docon(p) } } -PRIVATE void -EM_dostartmes(p) - register struct e_instr *p; +PRIVATE void EM_dostartmes(register struct e_instr *p) { if (listtype) { @@ -379,9 +369,7 @@ EM_dostartmes(p) listtype = ps_mes; } -EXPORT int -EM_mkcalls(line) - register struct e_instr *line; +EXPORT int EM_mkcalls(register struct e_instr *line) { #ifdef CHECKING diff --git a/modules/src/read_em/read_em.3 b/modules/src/read_em/read_em.3 index 9910c466d..81be81ec3 100644 --- a/modules/src/read_em/read_em.3 +++ b/modules/src/read_em/read_em.3 @@ -18,18 +18,13 @@ EM_mkcalls\ \-\ a module to read EM assembly code .br .B #include .PP -.B int EM_open(filename) -.br -.B char *filename; +.B int EM_open(char* filename) .PP -.B void EM_close() +.B void EM_close(void) .PP -.B int EM_getinstr(instr) -.B struct e_instr *instr; +.B int EM_getinstr(struct e_instr *instr) .PP -.B int EM_mkcalls(instr) -.br -.B struct e_instr *instr; +.B int EM_mkcalls(struct e_instr *instr) .PP .B char *EM_error; .PP @@ -311,7 +306,7 @@ contain the wordsize and pointersize, but only after the first ~em/modules/lib/libread_emeV.a: checking library for reading human-readable EM code .fi .SH MODULES -em_code(3), string(3), system(3), ~em/lib.bin/em_data.a +em_code(3), string(3), ~em/lib.bin/em_data.a .SH "SEE ALSO" em_code(3) .br diff --git a/modules/src/read_em/read_em.c b/modules/src/read_em/read_em.c index ccf9968c0..4764d6951 100644 --- a/modules/src/read_em/read_em.c +++ b/modules/src/read_em/read_em.c @@ -4,32 +4,31 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* Read_em: a module to read either compact or human readable EM code. - Exported are the following routines: - EM_open() : has a parameter representing either a pointer to a - filename or a null pointer, indicating that input is - from standard input. This routine initializes for - reading. - EM_getinstr() : Delivers the next EM instruction in a format - defined in . - Imported are: - The constants COMPACT (either defined or not defined) and - CHECKING (again either defined or not defined), - some routines from the system module. and the em_code module -*/ + Exported are the following routines: + EM_open() : has a parameter representing either a pointer to a + filename or a null pointer, indicating that input is + from standard input. This routine initializes for + reading. + EM_getinstr() : Delivers the next EM instruction in a format + defined in . + Imported are: + The constants COMPACT (either defined or not defined) and + CHECKING (again either defined or not defined), + some routines from the system module. and the em_code module + */ #include #include #include -#include -#include -#include -#include -#include -#include +#include "alloc.h" +#include "em_label.h" +#include "em_arith.h" +#include "em_pseu.h" +#include "em_spec.h" #include "em_ptyp.h" #include "em_comp.h" -#include -#include +#include "em_flag.h" +#include "em_mes.h" /* Buffered input */ @@ -37,80 +36,76 @@ #define ungetbyte(uch) ((uch) >= 0 && (*--_ich = (uch))) #define init_input() (_fill(), _ich--) -static File *fd; +static FILE *fd; static char *_ich; -PRIVATE int -_fill() +PRIVATE int _fill(void) { static char text[BUFSIZ + 1]; static int sz; - if (_ich && _ich < &text[sz]) return _ich++, '\0'; + if (_ich && _ich < &text[sz]) + return _ich++, '\0'; _ich = text; - if (sys_read(fd, text, BUFSIZ, &sz) && - sz > 0 - ) { + sz = fread(text, 1, BUFSIZ, fd); + if (sz > 0) + { text[sz] = '\0'; - return (*_ich++&0377); + return (*_ich++ & 0377); } - else { + else + { sz = 0; text[0] = 0; return EOF; } } -static struct e_instr *emhead; /* Where we put the head */ +static struct e_instr *emhead; /* Where we put the head */ static struct e_instr aheads[3]; static int ahead; -static struct string { +static struct string +{ int length; unsigned int maxlen; char *str; } string; -static int state; /* What state are we in? */ +static int state; /* What state are we in? */ #define CON 01 /* Reading a CON */ #define ROM 02 /* Reading a ROM */ #define MES 03 /* Reading a MES */ #define PSEUMASK 03 -static int EM_initialized; /* EM_open called? */ +static int EM_initialized; /* EM_open called? */ -static long wordmask[] = { /* allowed bits in a word */ - 0x00000000, - 0x000000FF, - 0x0000FFFF, - 0x00000000, - 0xFFFFFFFF -}; +static long wordmask[] = +{ /* allowed bits in a word */ +0x00000000, 0x000000FF, 0x0000FFFF, 0x00000000, 0xFFFFFFFF }; -static int wsize, psize; /* word size and pointer size */ +static int wsize, psize; /* word size and pointer size */ #ifdef CHECKING static char *argrange = "Argument range error"; -#define check(expr) (expr || EM_error || (EM_error = argrange)) +#define check(expr) ((expr) || (EM_error) || (EM_error = argrange)) #else /* not CHECKING */ #define check(x) /* nothing */ #endif /* CHECKING */ /* Error handling -*/ + */ -PRIVATE void -xerror(s) - char *s; +PRIVATE void xerror(char *s) { - if (emhead->em_type != EM_FATAL) emhead->em_type = EM_ERROR; - if (!EM_error) EM_error = s; + if (emhead->em_type != EM_FATAL) + emhead->em_type = EM_ERROR; + if (!EM_error) + EM_error = s; } #ifdef COMPACT -PRIVATE void -xfatal(s) - char *s; +PRIVATE void xfatal(char *s) { emhead->em_type = EM_FATAL; if (!EM_error) EM_error = s; @@ -122,33 +117,37 @@ xfatal(s) #endif /* COMPACT */ /* EM_open: Open input file, get magic word if COMPACT. -*/ -EXPORT int -EM_open(filename) - char *filename; + */ +EXPORT int EM_open(char *filename) { - if (EM_initialized) { + if (EM_initialized) + { EM_error = "EM_open already called"; return 0; } - - if (filename) { - if (!sys_open(filename, OP_READ, &fd)) { + + if (filename) + { + fd = fopen(filename, "rb"); + if (fd == NULL) + { EM_error = "Could not open input file"; return 0; } } - else fd = STDIN; + else + fd = stdin; EM_filename = filename; init_input(); #ifdef COMPACT - if (get16() != sp_magic) { + if (get16() != sp_magic) + { EM_error = "Illegal magic word"; return 0; } #else /* not COMPACT */ - inithash(); /* initialize hashtable */ + inithash(); /* initialize hashtable */ #endif /* COMPACT */ EM_initialized = 1; @@ -156,37 +155,36 @@ EM_open(filename) } /* EM_close: Close input file -*/ -EXPORT void -EM_close() + */ +EXPORT void EM_close(void) { - - if (fd != STDIN) { - sys_close(fd); - fd = STDIN; + + if (fd != stdin) + { + fclose(fd); + fd = stdin; } EM_initialized = 0; } - /* startmes: handle the start of a message. The only important thing here - is to get the wordsize and pointer size, and remember that they - have already been read, not only to check that they are not specified - again, but also to deliver the arguments on next calls to EM_getinstr. - This is indicated by the variable "argp". -*/ -PRIVATE void -startmes(p) - register struct e_instr *p; + is to get the wordsize and pointer size, and remember that they + have already been read, not only to check that they are not specified + again, but also to deliver the arguments on next calls to EM_getinstr. + This is indicated by the variable "argp". + */ +PRIVATE void startmes(register struct e_instr *p) { getarg(cst_ptyp, &(p->em_arg)); state = MES; - if (p->em_cst == ms_emx) { + if (p->em_cst == ms_emx) + { p = &aheads[ahead++]; getarg(cst_ptyp, &(p->em_arg)); - if (wsize && p->em_cst != wsize && !EM_error) { + if (wsize && p->em_cst != wsize && !EM_error) + { EM_error = "Different wordsize in duplicate ms_emx"; } wsize = p->em_cst; @@ -194,7 +192,8 @@ startmes(p) p->em_type = EM_MESARG; p = &aheads[ahead++]; getarg(cst_ptyp, &(p->em_arg)); - if (psize && p->em_cst != psize && !EM_error) { + if (psize && p->em_cst != psize && !EM_error) + { EM_error = "Different pointersize in duplicate ms_emx"; } psize = p->em_cst; @@ -203,123 +202,133 @@ startmes(p) } } - /* EM_getinstr: read an "EM_line" -*/ -EXPORT int -EM_getinstr(p) - register struct e_instr *p; + */ +EXPORT int EM_getinstr(register struct e_instr *p) { EM_error = 0; - if (ahead) { + if (ahead) + { register int i; ahead--; *p = aheads[0]; - for (i = 0; i < ahead; i++) aheads[i] = aheads[i+1]; + for (i = 0; i < ahead; i++) + aheads[i] = aheads[i + 1]; return 1; } emhead = p; p->em_type = 0; #ifdef CHECKING - if (!EM_initialized) { + if (!EM_initialized) + { EM_error = "Initialization not done"; p->em_type = EM_FATAL; return 0; } #endif /* CHECKING */ - if (!state) { /* All clear, get a new line */ + if (!state) + { /* All clear, get a new line */ gethead(p); - switch(p->em_type) { + switch (p->em_type) + { case EM_EOF: return EM_error == 0; - case EM_MNEM: { - register int i,j; + case EM_MNEM: + { + register int i, j; extern char em_flag[]; - extern short em_ptyp[]; + extern short em_ptyp[]; j = em_flag[p->em_opcode - sp_fmnem] & EM_PAR; i = em_ptyp[j]; - if (j == PAR_NO) { /* No arguments */ + if (j == PAR_NO) + { /* No arguments */ p->em_argtype = 0; } #ifndef COMPACT - if (j == PAR_B) i = ptyp(sp_ilb2); + if (j == PAR_B) + i = ptyp(sp_ilb2); #endif /* COMPACT */ - if (j != PAR_NO) getarg(i, &(p->em_arg)); + if (j != PAR_NO) + getarg(i, &(p->em_arg)); #ifndef COMPACT - if (j == PAR_B) { + if (j == PAR_B) + { p->em_cst = p->em_ilb; p->em_argtype = cst_ptyp; } #endif /* COMPACT */ /* range checking - */ + */ #ifdef CHECKING - if (wsize <= 4 && psize <= 4) switch(j) { - case PAR_B: - check(p->em_cst <= 32767); - /* Fall through */ - case PAR_N: - check(p->em_cst >= 0); - break; - case PAR_G: - if (p->em_argtype != cst_ptyp) { + if (wsize <= 4 && psize <= 4) + switch (j) + { + case PAR_B: + check(p->em_cst <= 32767); + /* Fall through */ + case PAR_N: + check(p->em_cst >= 0); break; - } - check(p->em_cst >= 0); - /* Fall through */ - case PAR_F: - /* ??? not in original em_decode or em_encode */ - case PAR_L: - { arith m = p->em_cst >= 0 ? p->em_cst : - - p->em_cst; + case PAR_G: + if (p->em_argtype != cst_ptyp) + { + break; + } + check(p->em_cst >= 0); + /* Fall through */ + case PAR_F: + /* ??? not in original em_decode or em_encode */ + case PAR_L: + { + arith m = p->em_cst >= 0 ? p->em_cst : -p->em_cst; - /* Check that the number fits in a pointer */ - check((m & ~wordmask[psize]) == 0); - break; - } - case PAR_W: - if (p->em_argtype == 0) { - p->em_cst = 0; + /* Check that the number fits in a pointer */ + check((m & ~wordmask[psize]) == 0); + break; + } + case PAR_W: + if (p->em_argtype == 0) + { + p->em_cst = 0; + break; + } + check((p->em_cst & ~wordmask[wsize]) == 0); + /* Fall through */ + case PAR_S: + check(p->em_cst > 0); + /* Fall through */ + case PAR_Z: + check((p->em_cst >= 0) && (p->em_cst % wsize == 0)); + break; + case PAR_O: + check( + (p->em_cst > 0) && ( (p->em_cst % wsize == 0) || (wsize % p->em_cst == 0))); + break; + case PAR_R: + check((p->em_cst >= 0) && (p->em_cst <= 2)); break; } - check((p->em_cst & ~wordmask[wsize]) == 0); - /* Fall through */ - case PAR_S: - check(p->em_cst > 0); - /* Fall through */ - case PAR_Z: - check(p->em_cst >= 0 && - p->em_cst % wsize == 0); - break; - case PAR_O: - check(p->em_cst > 0 && - ( p->em_cst % wsize == 0 || - wsize % p->em_cst == 0)); - break; - case PAR_R: - check(p->em_cst >= 0 && p->em_cst <= 2); - break; - } #endif /* CHECKING */ #ifndef COMPACT checkeol(); #endif /* COMPACT */ - } + } break; case EM_PSEU: /* handle a pseudo, read possible arguments. CON's and - ROM's are handled especially: Only one argument is - read, and a mark is set that an argument list of - type ROM or CON is in process - */ - { + ROM's are handled especially: Only one argument is + read, and a mark is set that an argument list of + type ROM or CON is in process + */ + { struct e_arg dummy; - switch(p->em_opcode) { + switch (p->em_opcode) + { case ps_bss: case ps_hol: getarg(cst_ptyp, &dummy); @@ -329,10 +338,11 @@ EM_getinstr(p) EM_holinit = dummy.ema_cst; #ifdef CHECKING /* Check that the last value is 0 or 1 - */ - if (EM_holinit != 1 && EM_holinit != 0) { - if (! EM_error) - EM_error="Third argument of hol/bss not 0/1"; + */ + if (EM_holinit != 1 && EM_holinit != 0) + { + if (!EM_error) + EM_error = "Third argument of hol/bss not 0/1"; } #endif /* CHECKING */ break; @@ -352,14 +362,16 @@ EM_getinstr(p) break; case ps_pro: getarg(pro_ptyp, &(p->em_arg)); - getarg(cst_ptyp|ptyp(sp_cend), &dummy); - if (dummy.ema_argtype == 0) { + getarg(cst_ptyp | ptyp(sp_cend), &dummy); + if (dummy.ema_argtype == 0) + { p->em_nlocals = -1; } - else p->em_nlocals = dummy.ema_cst; + else + p->em_nlocals = dummy.ema_cst; break; case ps_end: - getarg(cst_ptyp|ptyp(sp_cend), &(p->em_arg)); + getarg(cst_ptyp | ptyp(sp_cend), &(p->em_arg)); break; case ps_con: getarg(val_ptyp, &(p->em_arg)); @@ -373,9 +385,10 @@ EM_getinstr(p) xerror("Bad pseudo"); break; } - } + } #ifndef COMPACT - if (p->em_opcode != ps_con && p->em_opcode != ps_rom) { + if (p->em_opcode != ps_con && p->em_opcode != ps_rom) + { checkeol(); } #endif /* COMPACT */ @@ -384,7 +397,8 @@ EM_getinstr(p) startmes(p); break; } - if (!wsize && !EM_error) { + if (!wsize && !EM_error) + { wsize = 2; psize = 2; EM_error = "EM code should start with mes 2"; @@ -394,14 +408,17 @@ EM_getinstr(p) /* Here, we are in a state reading arguments */ getarg(any_ptyp, &(p->em_arg)); - if (EM_error && p->em_type != EM_FATAL) { + if (EM_error && p->em_type != EM_FATAL) + { return 0; } - if (p->em_argtype == 0) { /* No more arguments */ + if (p->em_argtype == 0) + { /* No more arguments */ #ifndef COMPACT checkeol(); #endif - if (state == MES) { + if (state == MES) + { state = 0; p->em_type = EM_ENDMES; return EM_error == 0; @@ -412,12 +429,15 @@ EM_getinstr(p) } /* Here, there was an argument */ - if (state == MES) { + if (state == MES) + { p->em_type = EM_MESARG; return EM_error == 0; } p->em_type = EM_PSEU; - if (state == CON) p->em_opcode = ps_con; - else p->em_opcode = ps_rom; + if (state == CON) + p->em_opcode = ps_con; + else + p->em_opcode = ps_rom; return EM_error == 0; } diff --git a/modules/src/read_em/reade.c b/modules/src/read_em/reade.c index 22737ec37..e8c736a90 100644 --- a/modules/src/read_em/reade.c +++ b/modules/src/read_em/reade.c @@ -10,12 +10,13 @@ #include #include -#include +#include +#include "ack_string.h" -/* #define XXX_YYY /* only for early debugging */ +/* #define XXX_YYY *//* only for early debugging */ #ifdef XXX_YYY -#define out(str) (sys_write(STDOUT, str, strlen(str))) +#define out(str) (fwrite(stdout, 1, str, strlen(str))) #else #define out(s) #endif @@ -30,11 +31,17 @@ static int argnum; /* Number of arguments */ #define COMMENTSTARTER ';' +/* Forward declarations */ +PRIVATE void gettyp(int, register struct e_arg *); +PRIVATE int getexpr(register int, register struct e_arg *); + +/* External definitions */ +extern char em_mnem[][4]; +extern char em_pseu[][4]; + /* inithash, pre_hash, hash: Simple hashtable mechanism */ -PRIVATE int -hash(s) - register char *s; +PRIVATE int hash(register char *s) { register int h = 0; @@ -45,9 +52,7 @@ hash(s) return h; } -PRIVATE void -pre_hash(i, s) - char *s; +PRIVATE void pre_hash(int i, char *s) { register int h; @@ -65,11 +70,9 @@ pre_hash(i, s) /*NOTREACHED*/ } -extern char em_mnem[][4]; -extern char em_pseu[][4]; -PRIVATE void -inithash() + +PRIVATE void inithash(void) { register int i; @@ -87,8 +90,7 @@ inithash() /* nospace: skip until we find a non-space character. Also skip comments. */ -PRIVATE int -nospace() +PRIVATE int nospace(void) { register int c; @@ -105,9 +107,7 @@ nospace() /* syntax: Put an error message in EM_error and skip to the end of the line */ -PRIVATE void -syntax(s) - char *s; +PRIVATE void syntax(char *s) { register int c; @@ -119,8 +119,7 @@ syntax(s) /* checkeol: check that we have a complete line (except maybe for spaces) */ -PRIVATE void -checkeol() +PRIVATE void checkeol(void) { if (nospace() != '\n') { @@ -131,8 +130,7 @@ checkeol() /* getescape: read a '\' escape sequence */ -PRIVATE int -getescape() +PRIVATE int getescape(void) { register int c, j, r; @@ -164,8 +162,7 @@ getescape() /* getname: Read a string of characters representing an identifier */ -PRIVATE struct string * -getname() +PRIVATE struct string *getname(void) { register char *p; register struct string *s; @@ -203,8 +200,7 @@ getname() /* getstring: read a string of characters between quotes */ -PRIVATE struct string * -getstring() +PRIVATE struct string *getstring(int isident) { register char *p; struct string *s; @@ -253,11 +249,10 @@ getstring() return s; } -PRIVATE void gettyp(); -PRIVATE int -offsetted(argtyp, ap) - arith *ap; + + +PRIVATE int offsetted(int argtyp, arith *ap) { register int c; @@ -275,10 +270,7 @@ offsetted(argtyp, ap) return argtyp; } -PRIVATE int -getnumber(c, ap) - register int c; - register struct e_arg *ap; +PRIVATE int getnumber(register int c, register struct e_arg *ap) { char str[256 + 1]; register char *p = str; @@ -365,12 +357,8 @@ getnumber(c, ap) return sp_cst4; } -PRIVATE int getexpr(); -PRIVATE int -getfactor(c, ap) - register int c; - register struct e_arg *ap; +PRIVATE int getfactor(register int c, register struct e_arg *ap) { if (c == '(') { if (getexpr(nospace(), ap) != sp_cst4) { @@ -385,10 +373,7 @@ getfactor(c, ap) return getnumber(c, ap); } -PRIVATE int -getterm(c, ap) - register int c; - register struct e_arg *ap; +PRIVATE int getterm(register int c, register struct e_arg *ap) { arith left; @@ -413,10 +398,7 @@ getterm(c, ap) return sp_cst4; } -PRIVATE int -getexpr(c, ap) - register int c; - register struct e_arg *ap; +PRIVATE int getexpr(register int c, register struct e_arg *ap) { arith left; @@ -440,8 +422,7 @@ getexpr(c, ap) return sp_cst4; } -PRIVATE int -get15u() +PRIVATE int get15u(void) { struct e_arg dummy; @@ -452,9 +433,7 @@ get15u() return (int) (dummy.ema_cst); } -PRIVATE void -gettyp(typset, ap) - register struct e_arg *ap; +PRIVATE void gettyp(int typset, register struct e_arg *ap) { register int c, t; register int argtyp; @@ -528,9 +507,7 @@ gettyp(typset, ap) } } -PRIVATE void -getarg(typset, ap) - struct e_arg *ap; +PRIVATE void getarg(int typset, struct e_arg *ap) { register int c; @@ -550,9 +527,7 @@ getarg(typset, ap) /* getmnem: We found the start of either an instruction or a pseudo. get the rest of it */ -PRIVATE void -getmnem(c, p) - register struct e_instr *p; +PRIVATE void getmnem(int c, register struct e_instr *p) { register int h; int i; @@ -592,8 +567,7 @@ getmnem(c, p) } } -PRIVATE void -line_line() +PRIVATE void line_line(void) { static char filebuf[256 + 1]; char *btscpy(); @@ -606,9 +580,7 @@ line_line() EM_filename = filebuf; } -PRIVATE void -getlabel(c, p) - register struct e_instr *p; +PRIVATE void getlabel(int c, register struct e_instr *p) { ungetbyte(c); @@ -629,9 +601,7 @@ getlabel(c, p) checkeol(); } -PRIVATE void -gethead(p) - register struct e_instr *p; +PRIVATE void gethead(register struct e_instr *p) { register int c; diff --git a/modules/src/read_em/readk.c b/modules/src/read_em/readk.c index 80c6a4aaf..972303761 100644 --- a/modules/src/read_em/readk.c +++ b/modules/src/read_em/readk.c @@ -11,8 +11,7 @@ /* get16, get32: read a signed constant */ -PRIVATE int -get16() +PRIVATE int get16(void) { register int l_byte, h_byte; @@ -22,8 +21,7 @@ get16() return l_byte | (h_byte << 8); } -PRIVATE arith -get32() +PRIVATE arith get32(void) { register arith l; register int h_byte; @@ -41,9 +39,7 @@ PRIVATE struct string *getstring(); /* getarg : read an argument of any type, and check it against "typset" if neccesary. Put result in "ap". */ -PRIVATE void -getarg(typset, ap) - register struct e_arg *ap; +PRIVATE void getarg(int typset, register struct e_arg *ap) { register int i = getbyte(); #ifdef CHECKING @@ -190,9 +186,7 @@ getarg(typset, ap) #ifdef CHECKING /* checkident: check that a string indeed represents an identifier */ -PRIVATE int -checkident(s) - register struct string *s; +PRIVATE int checkident(register struct string *s) { register char *p; register int n; @@ -214,8 +208,7 @@ checkident(s) /* getstring: read a string from the input */ /*ARGSUSED*/ -PRIVATE struct string * -getstring(isident) +PRIVATE struct string *getstring(int isident) { register char *p; register int n; @@ -259,9 +252,7 @@ getstring(isident) /* gethead: read the start of an EM-line */ -PRIVATE void -gethead(p) - register struct e_instr *p; +PRIVATE void gethead(register struct e_instr *p) { register int i; From bb6540c5f4f3f698e1d0b663c21c4ba7a084490e Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:01:52 +0800 Subject: [PATCH 46/84] Adapt man page with correct prototype information. --- modules/src/print/print.3 | 28 +++++++++------------------- modules/src/print/print.h | 1 - 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/modules/src/print/print.3 b/modules/src/print/print.3 index 33d880705..0061b8f9b 100644 --- a/modules/src/print/print.3 +++ b/modules/src/print/print.3 @@ -7,36 +7,26 @@ print, fprint, sprint, doprnt -- very simple formatted-output routines .B #include .B #include .PP -.B void print(format [, arg] ... ) -.B char *format; +.B void print(char *format [, arg] ... ) .PP -.B void fprint(filep, format [, arg] ... ) -.B File *filep; -.B char *format; +.B void fprint(File *filep, char *format [, arg] ... ) .PP -.B char *sprint(s, format [, arg] ... ) -.B char *s, *format; +.B char *sprint(char *s, char *format [, arg] ... ) .PP -.B void doprnt(filep, format, args) -.B File *filep; -.B char *format; -.B va_list args; +.B void doprnt(File *filep, char *format, va_list args) .PP -.B int _format(buf, format, args) -.B char *buf; -.B char *format; -.B va_list args; +.B int _format(char *buf, char *format, va_lsit args) .fi .SH DESCRIPTION -.I Print +.I print writes output on standard output. -.I Fprint +.I fprint and .I doprnt place output on the open file known by .IR filep . .I filep could for instance be STDOUT or STDERR. -.I Sprint +.I sprint places `output' in the string .IR s , followed by the character `\\0'. @@ -102,7 +92,7 @@ The routine builds the string, but does not null-terminate it. It returns the length of the string. .PP -.I Doprnt +.I doprnt takes .I args as the address of the arguments of the format string. diff --git a/modules/src/print/print.h b/modules/src/print/print.h index 292796e6d..1cc341b24 100644 --- a/modules/src/print/print.h +++ b/modules/src/print/print.h @@ -2,7 +2,6 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ #ifndef __PRINT_INCLUDED__ #define __PRINT_INCLUDED__ From ccfd8a3e184344532bd4eb39590efd0ebdf2ffd3 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:03:36 +0800 Subject: [PATCH 47/84] rename rd_long/wr_long to rd_int4/wr_int4 for consistency. Align declaration and definition name of parameters and adapt man page accordingly. --- modules/src/object/object.3 | 78 ++++++++++----------- modules/src/object/object.h | 51 ++++++-------- modules/src/object/rd.c | 10 +-- modules/src/object/rd_arhdr.c | 1 + modules/src/object/{rd_long.c => rd_int4.c} | 2 +- modules/src/object/wr.c | 22 +++--- modules/src/object/wr_bytes.c | 6 +- modules/src/object/{wr_long.c => wr_int4.c} | 2 +- modules/src/object/wr_ranlib.c | 10 +-- 9 files changed, 87 insertions(+), 95 deletions(-) rename modules/src/object/{rd_long.c => rd_int4.c} (93%) rename modules/src/object/{wr_long.c => wr_int4.c} (91%) diff --git a/modules/src/object/object.3 b/modules/src/object/object.3 index 70a62ce8e..f82d6d995 100644 --- a/modules/src/object/object.3 +++ b/modules/src/object/object.3 @@ -5,7 +5,7 @@ wr_open, wr_close, wr_ohead, wr_sect, wr_outsect, wr_emit, wr_putc, wr_relo, wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, wr_bytes, rd_open, rd_fdopen, rd_close, rd_ohead, rd_sect, rd_outsect, rd_emit, rd_relo, rd_rew_relo, rd_name, rd_string, rd_arhdr, rd_ranlib, -rd_int2, rd_unsigned2, rd_long, rd_bytes, rd_fd\ \-\ routines to read +rd_int2, rd_unsigned2, rd_int4, rd_bytes, rd_fd\ \-\ routines to read and write ACK-object files and libraries .SH SYNOPSIS .B #include @@ -16,25 +16,25 @@ and write ACK-object files and libraries .br .B #include .PP -.B FILE* wr_open(const char *filename) +.B int wr_open(const char *filename) .PP -.B void wr_close() +.B void wr_close(void) .PP -.B void wr_ohead(struct outhead *head) +.B void wr_ohead(const struct outhead *head) .PP -.B void wr_sect(struct outsect *sect, unsigned int cnt) +.B void wr_sect(const struct outsect *sect, unsigned int cnt) .PP -.B void wr_outsect(int sectionnr) +.B void wr_outsect(int sectno) .PP .B void wr_emit(const char *emit, long cnt) .PP -.B void wr_putc(int ch) +.B void wr_putc(int c) .PP .B void wr_relo(const struct outrelo *relo, unsigned int cnt) .PP -.B void wr_name(struct outname *name, unsigned int cnt) +.B void wr_name(const struct outname *name, unsigned int cnt) .PP -.B void wr_string(const char *stringaddr, long cnt) +.B void wr_string(const char *addr, long len) .PP .B void wr_arhdr(FILE* fd, struct ar_hdr *arhdr) .PP @@ -44,25 +44,25 @@ and write ACK-object files and libraries .PP .B void wr_long(FILE* fd, long l) .PP -.B void wr_bytes(FILE* fd, const char* buf, long l) +.B void wr_bytes(FILE* fd, const char* buf, long cnt) .PP .B int rd_open(const char *filename) .PP .B int rd_fdopen(FILE* fd) .PP -.B void rd_close() +.B void rd_close(void) .PP .B void rd_ohead(struct outhead *head) .PP .B void rd_sect(struct outsect *sect, unsigned int cnt) .PP -.B void rd_outsect(int sectionnr) +.B void rd_outsect(int sectno) .PP .B void rd_emit(char *emit, long cnt) .PP .B void rd_relo(struct outrelo *relo, unsigned int cnt) .PP -.B void rd_rew_relo(struct outhead *head) +.B void rd_rew_relos(struct outhead *head) .PP .B void rd_name(struct outname *name, unsigned int cnt) .PP @@ -76,86 +76,86 @@ and write ACK-object files and libraries .PP .B unsigned int rd_unsigned2(FILE* fd) .PP -.B long rd_long(FILE* fd) +.B long rd_int4FILE* fd) .PP .B void rd_bytes(FILE* fd, char *buf, long l) .PP -.B FILE* rd_fd() +.B FILE* rd_fd(void) .SH DESCRIPTION These routines come in handy when reading or writing ACK-object files or libraries. No checking is performed. .PP -.I Wr_open +.I wr_open opens the file .I filename for writing and initializes some of this modules local variables. It must be called before writing parts of the object file. It returns 1 if it succeeds, 0 if it fails. .PP -.I Wr_close +.I wr_close closes the object file. Don't forget to call it, because it might flush internal buffers. .PP -.I Wr_ohead +.I wr_ohead writes the .I head header structure. This routine must be called before the routines to write the other parts. .PP -.I Wr_sect +.I wr_sect writes .I cnt section headers, starting at .IB sect . Before writing a section, its section header must be written. .PP -.I Wr_outsect +.I wr_outsect indicates that the next section to be written is -.IB sectionnr . +.IB secno . This routine can be used to switch between sections. .PP -.I Wr_emit +.I wr_emit writes .I cnt bytes, starting at .IB emit , of the current section. .PP -.I Wr_putc -adds character +.I wr_putc +adds byte .I ch to the current section. .PP -.I Wr_relo +.I wr_relo writes .I cnt outrelo structures, indicated by .IB relo , in the relocation information part of the object file. .PP -.I Wr_name +.I wr_name writes .I cnt outname structures, indicated by .IB name , in the name-table part of the object file. .PP -.I Wr_string +.I wr_string writes .I cnt bytes, indicated by -.IB stringaddr , +.IB addr, in the string table part of the object file. .PP The next few routines can be used independantly: -.I Wr_arhdr +.I wr_arhdr writes the archive member header .I arhdr to file descriptor .IB fd . .PP -.I Wr_ranlib +.I wr_ranlib writes .I cnt ranlib structures, indicated by @@ -163,23 +163,23 @@ ranlib structures, indicated by to file descriptor .IB fd. .PP -.I Wr_int2 +.I wr_int2 writes a 2-byte integer .I i to file descriptor .IB fd , low order byte first. .PP -.I Wr_long +.I wr_long writes a 4-byte integer .I l to file descriptor .IB fd , low order word first, low order byte first. .PP -.I Wr_bytes +.I wr_bytes writes -.I l +.I cnt bytes from .I buf to file descriptor @@ -191,7 +191,7 @@ routines are the opposite of the .I wr_ routines. However, a few of them deserve special mentioning: .PP -.I Rd_fdopen +.I rd_fdopen initialises for reading an "object file" from file descriptor .IB fd , at its current position. @@ -201,16 +201,16 @@ When using this entry point for reading, .I rd_close does not have to be called. .PP -.I Rd_rew_relo +.I rd_rew_relos rewinds the relocation part, so that it can be read again. \fILed\fR(6) sometimes needs this. .PP -.I Rd_unsigned2 +.I rd_unsigned2 reads two bytes from file descriptor .I fd -and interpretes them as an unsigned integer. +and interprets them as an unsigned integer. .PP -.I Rd_arhdr +.I rd_arhdr returns 1 if a header was read, and 0 on end-of-file. .PP When using any of the reading routines, a routine diff --git a/modules/src/object/object.h b/modules/src/object/object.h index 0e19d330b..2c4716fb4 100644 --- a/modules/src/object/object.h +++ b/modules/src/object/object.h @@ -17,49 +17,40 @@ struct outsect; struct ranlib; struct outname; -int wr_open(const char *f); +int wr_open(const char *filename); void wr_close(void); -void wr_ohead(const struct outhead *h); -void wr_sect(const struct outsect *s, unsigned int c); +void wr_ohead(const struct outhead *head); +void wr_sect(const struct outsect *sect, unsigned int cnt); void wr_outsect(int sectno); -void wr_emit(const char *b, long c); +void wr_emit(const char *emit, long cnt); void wr_putc(int c); -void wr_relo(const struct outrelo *r, unsigned int c); -void wr_name(const struct outname *n, unsigned int c); -void wr_string(const char *s, long c); +void wr_relo(const struct outrelo *relo, unsigned int cnt); +void wr_name(const struct outname *name, unsigned int cnt); +void wr_string(const char *addr, long len); - -void wr_arhdr(FILE* fd, struct ar_hdr *a); -void wr_ranlib(FILE* fd, struct ranlib *r, long cnt); +void wr_arhdr(FILE* fd, struct ar_hdr *arhdr); +void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt); void wr_int2(FILE* fd, int i); -void wr_long(FILE* fd, long l); -void wr_bytes(FILE* fd, const char *buf, long l); +void wr_int4(FILE* fd, long l); +void wr_bytes(FILE* fd, const char *buf, long cnt); -int rd_open(const char *f); +int rd_open(const char *filename); int rd_fdopen(FILE* fd); void rd_close(void); -void rd_ohead(struct outhead *h); -void rd_sect(struct outsect *s, unsigned int c); +void rd_ohead(struct outhead* head); +void rd_sect(struct outsect* sect, unsigned int cnt); void rd_outsect(int sectno); -void rd_emit(char *b, long c); -void rd_relo(struct outrelo *r, unsigned int c); +void rd_emit(char* emit, long cnt); +void rd_relo(struct outrelo* relo, unsigned int cnt); void rd_rew_relos(struct outhead *head); -void rd_name(struct outname *n, unsigned int c); -void rd_string(char *s, long c); +void rd_name(struct outname* name, unsigned int cnt); +void rd_string(char* addr, long len); -/** Reads an archive header and returns the filled - * up archive header structure. Returns 0 if failure - * otherwise returns 1. - * - * @param[in] fd Opened file descriptor to read from. - * @param[out] a Archive header structure. - * - */ -int rd_arhdr(FILE* fd, struct ar_hdr *a); -void rd_ranlib(FILE* fd, struct ranlib *r, long cnt); +int rd_arhdr(FILE* fd, register struct ar_hdr *arhdr); +void rd_ranlib(FILE* fd, register struct ranlib *ran, register long cnt); int rd_int2(FILE* fd); -long rd_long(FILE* fd); +long rd_int4(FILE* fd); unsigned int rd_unsigned2(FILE* fd); void rd_bytes(FILE* fd, char *buf, long l); FILE* rd_fd(void); diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c index 26c9f224c..140bf2eb5 100644 --- a/modules/src/object/rd.c +++ b/modules/src/object/rd.c @@ -61,10 +61,10 @@ OUTREAD(int p, char* b, long n) /* * Open the output file according to the chosen strategy. */ -int rd_open(const char* f) +int rd_open(const char* filename) { - if ((outfile = fopen(f, "rb")) == NULL) + if ((outfile = fopen(filename, "rb")) == NULL) return 0; return rd_fdopen(outfile); } @@ -160,10 +160,10 @@ rd_sect(struct outsect* sect, unsigned int cnt) } void -rd_outsect(int s) +rd_outsect(int sectno) { - OUTSECT(s); - sectionnr = s; + OUTSECT(sectno); + sectionnr = sectno; } /* diff --git a/modules/src/object/rd_arhdr.c b/modules/src/object/rd_arhdr.c index 98138b9ee..cab479e3f 100644 --- a/modules/src/object/rd_arhdr.c +++ b/modules/src/object/rd_arhdr.c @@ -13,6 +13,7 @@ extern void rd_fatal(void); + int rd_arhdr(FILE* fd, register struct ar_hdr *arhdr) { char buf[AR_TOTAL]; diff --git a/modules/src/object/rd_long.c b/modules/src/object/rd_int4.c similarity index 93% rename from modules/src/object/rd_long.c rename to modules/src/object/rd_int4.c index a4495d4cd..55303866f 100644 --- a/modules/src/object/rd_long.c +++ b/modules/src/object/rd_int4.c @@ -11,7 +11,7 @@ #include "obj.h" -long rd_long(FILE* fd) +long rd_int4(FILE* fd) { char buf[4]; diff --git a/modules/src/object/wr.c b/modules/src/object/wr.c index e4f304bca..19c02d477 100644 --- a/modules/src/object/wr.c +++ b/modules/src/object/wr.c @@ -144,18 +144,18 @@ static void BEGINSEEK(int p, long o) /* * Open the output file according to the chosen strategy. */ -int wr_open(const char *f) +int wr_open(const char *filename) { struct fil *fdp; - fclose(fopen(f,"wb")); + fclose(fopen(filename,"wb")); #ifdef OUTSEEK - if ((outfile = fopen(f, "ab+")) == NULL) + if ((outfile = fopen(filename, "ab+")) == NULL) return 0; currpos = 0; #else /* not OUTSEEK */ for (fdp = &__parts[PARTEMIT]; fdp < &__parts[NPARTS]; fdp++) - if ((fdp->fd = fopen(f, "wb+")) == NULL) + if ((fdp->fd = fopen(filename, "wb+")) == NULL) return 0; #endif /* not OUTSEEK */ offcnt = 0; @@ -254,12 +254,12 @@ wr_sect(const struct outsect *sect, unsigned int cnt) } void -wr_outsect(int s) +wr_outsect(int sectno) /* s = section number */ { struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)]; - if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) { + if (sectno != sectionnr && sectno >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) { #ifdef OUTSEEK if (currpos != ptr->currpos) { @@ -273,18 +273,18 @@ wr_outsect(int s) currpos = ptr->currpos; #endif offset[sectionnr] = ptr->currpos; - if (offset[s] != ptr->currpos) { - fseek(ptr->fd, offset[s], SEEK_SET); - ptr->currpos = offset[s]; + if (offset[sectno] != ptr->currpos) { + fseek(ptr->fd, offset[sectno], SEEK_SET); + ptr->currpos = offset[sectno]; #ifdef OUTSEEK currpos = ptr->currpos; #endif } - ptr->cnt = WBUFSIZ - ((int)offset[s] & (WBUFSIZ-1)); + ptr->cnt = WBUFSIZ - ((int)offset[sectno] & (WBUFSIZ-1)); ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt); ptr->pnow = ptr->pbegin; } - sectionnr = s; + sectionnr = sectno; } /* diff --git a/modules/src/object/wr_bytes.c b/modules/src/object/wr_bytes.c index a115660a2..4619cfa1e 100644 --- a/modules/src/object/wr_bytes.c +++ b/modules/src/object/wr_bytes.c @@ -22,7 +22,7 @@ extern void wr_fatal(void); /* * Just write "cnt" bytes to file-descriptor "fd". */ -void wr_bytes(FILE* fd, const char *string, long cnt) +void wr_bytes(FILE* fd, const char *buf, long cnt) { size_t written_bytes; @@ -30,12 +30,12 @@ void wr_bytes(FILE* fd, const char *string, long cnt) { int n = cnt >= maxchunk ? maxchunk : cnt; - written_bytes = fwrite(string, 1, n, fd); + written_bytes = fwrite(buf, 1, n, fd); if (written_bytes != (size_t)n) { wr_fatal(); } - string += n; + buf += n; cnt -= n; } } diff --git a/modules/src/object/wr_long.c b/modules/src/object/wr_int4.c similarity index 91% rename from modules/src/object/wr_long.c rename to modules/src/object/wr_int4.c index da4cb524f..0188b0b14 100644 --- a/modules/src/object/wr_long.c +++ b/modules/src/object/wr_int4.c @@ -10,7 +10,7 @@ #include "object.h" #include "obj.h" -void wr_long(FILE* fd, long l) +void wr_int4(FILE* fd, long l) { char buf[4]; diff --git a/modules/src/object/wr_ranlib.c b/modules/src/object/wr_ranlib.c index 31cc96899..d8ae322b3 100644 --- a/modules/src/object/wr_ranlib.c +++ b/modules/src/object/wr_ranlib.c @@ -12,10 +12,10 @@ #include "obj.h" #include "ranlib.h" -void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt1) +void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt) { struct ranlib *r; - long cnt, val; + long cnt2, val; char *c; /* @@ -30,11 +30,11 @@ void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt1) */ r = ran; c = (char *)r; - cnt = cnt1; - while (cnt--) { + cnt2 = cnt; + while (cnt2--) { val = r->ran_off; put4(val, c); c += 4; val = r->ran_pos; put4(val, c); c += 4; r++; } - wr_bytes(fd, (char *) ran, cnt1 * SZ_RAN); + wr_bytes(fd, (char *) ran, cnt * SZ_RAN); } From 7a642d6df32230d486aca8f3c88fb6c928642b12 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:05:02 +0800 Subject: [PATCH 48/84] Fix some groff warnings. adapt mkdispatch to ANSI C. --- doc/6500.doc | 4 +- doc/LLgen/LLgen.n | 1 - doc/cg.doc | 47 +-- doc/ego/intro/head | 1 - doc/em/assem.nr | 5 +- doc/em/mkdispatch.c | 901 ++++++++++++++++++++++++++------------------ doc/i80.doc | 2 +- doc/install.doc | 275 ++++++++------ doc/nopt.doc | 2 +- 9 files changed, 717 insertions(+), 521 deletions(-) mode change 100644 => 100755 doc/install.doc diff --git a/doc/6500.doc b/doc/6500.doc index 173675807..5a1c8b313 100644 --- a/doc/6500.doc +++ b/doc/6500.doc @@ -405,7 +405,7 @@ The code rule section is the largest section in the table. They specify EM patterns, stack patterns, code to be generated, etc. The syntax is: -.IP code rule: +.IP "code rule:" EM pattern '|' stack pattern '|' code '|' stack replacement '|' EM replacement '|' .PP @@ -605,7 +605,7 @@ loc stl .R $1==0 -.sp1 +.sp 1 and the input is .sp 1 .br diff --git a/doc/LLgen/LLgen.n b/doc/LLgen/LLgen.n index 3d9786a5b..dd163a464 100644 --- a/doc/LLgen/LLgen.n +++ b/doc/LLgen/LLgen.n @@ -9,7 +9,6 @@ . if t .ds <, ,\ \}\ \} -.cs 5 22u .ND .EQ delim @@ diff --git a/doc/cg.doc b/doc/cg.doc index b92e35e4d..6542cded1 100644 --- a/doc/cg.doc +++ b/doc/cg.doc @@ -1333,23 +1333,20 @@ Tables.c Tables.c contains a large number of initialized array's of all sorts. Description of each follows: .br -.in 1i -.ti -0.5i -byte code rules[] +.IP "byte code rules[]" .br Pseudo code interpreted by the code generator. Always starts with some opcode followed by operands depending on the opcode. Integers in this table are between 0 and 32767 and have a one byte encoding if between 0 and 127. -.ti -0.5i -char stregclass[] + +.IP "char stregclass[]" .br Number of computed static register class per register. Two registers are in the same class if they have the same properties and don't share a common subregister. -.ti -0.5i -struct reginfo machregs[] +.IP "struct reginfo machregs[]" .br Info per register. Initialized with representation string, size, @@ -1357,78 +1354,66 @@ members of the register and set of registers affected when this one is changed. Also contains room for runtime information, like contents and reference count. -.ti -0.5i -tkdef_t tokens[] +.IP "tkdef_t tokens[]" .br Information per tokentype. Initialized with size, cost, type of operands and formatstring. -.ti -0.5i -node_t enodes[] +.IP "node_t enodes[]" .br List of triples representing expressions for the code generator. -.ti -0.5i -string code strings[] +.IP "string code strings[]" .br List of strings. All strings are put in a list and checked for duplication, so only one copy per string will reside here. -.ti -0.5i -set_t machsets[] +.IP "set_t machsets[]" .br List of token expression sets. Bit 0 of the set is used for the SCRATCH property of registers, bit 1 upto NREG are for the corresponding registers and bit NREG+1 upto the end are for corresponding tokens. -.ti -0.5i -inst_t tokeninstances[] +.IP "inst_t tokeninstances[]" .br List of descriptions for building tokens. Contains type of rule for building one, plus operands depending on the type. -.ti -0.5i -move_t moves[] +.IP "move_t moves[]" .br List of move rules. Contains token expressions for source and destination plus cost and index for code rule. -.ti -0.5i -byte pattern[] +.IP "byte pattern[]" .br EM patterns. This is structured internally as chains of patterns, each chain pointed at by pathash[]. After each pattern the list of possible code rules is given. -.ti -0.5i -int pathash[256] +.IP "int pathash[256]" .br Indices into pattern[] for all patterns with a certain low order byte of the hashing function. -.ti -0.5i -c1_t c1coercs[] +.IP "c1_t c1coercs[]" .br List of rules to stack tokens. Contains token expressions, register needed, cost and code rule. -.ti -0.5i -c2_t c2coercs[] +.IP "c2_t c2coercs[]" .br List of splitting coercions. Token expressions, split factor, replacements and code rule. -.ti -0.5i -c3_t c3coercs[] +.IP "c3_t c3coercs[]" .br List of one to one coercions. Token expressions, register needed, replacement and code rule. -.ti -0.5i -struct reginfo **reglist[] +.IP "struct reginfo **reglist[]" .br List of lists of pointers to register information. For every property the list is here diff --git a/doc/ego/intro/head b/doc/ego/intro/head index ccc710bd3..b3793888e 100644 --- a/doc/ego/intro/head +++ b/doc/ego/intro/head @@ -7,4 +7,3 @@ .ds >, , .ds [. " [ .ds .] ] -.cs 5 22 diff --git a/doc/em/assem.nr b/doc/em/assem.nr index 59ea75536..db18e8efa 100644 --- a/doc/em/assem.nr +++ b/doc/em/assem.nr @@ -34,8 +34,7 @@ Instruction labels are unsigned positive integers. The scope of an instruction label is its procedure. .QQ The pseudoinstructions CON, ROM and BSS may be preceded by a -line containing a -1\-8 character data label, the first character of which is a +line containing a character based data label, the first character of which is a letter, period or underscore. The period may only be followed by digits, the others may be followed by letters, digits and underscores. @@ -200,7 +199,7 @@ l l l. :\&=:instruction label ::'*' followed by an integer in the range 0..32767. :\&=:procedure number ('$' followed by a procedure name) -:\&=:, , or . +:\&=:, , , or . :\&=: or <...>*:\&=:zero or more of <...> <...>+:\&=:one or more of <...> diff --git a/doc/em/mkdispatch.c b/doc/em/mkdispatch.c index 613b582c6..e48a5c812 100644 --- a/doc/em/mkdispatch.c +++ b/doc/em/mkdispatch.c @@ -5,229 +5,336 @@ */ #include "ip_spec.h" +#include #include +#include +#include #include "em_spec.h" #include "em_flag.h" #ifndef NORCSID -static char rcs_id[] = "$Id$" ; +static char rcs_id[] = "$Id$"; #endif /* This program reads the human readable interpreter specification - and produces a efficient machine representation that can be - translated by a C-compiler. -*/ + and produces a efficient machine representation that can be + translated by a C-compiler. + */ #define NOTAB 600 /* The max no of interpreter specs */ #define ESCAP1 256 #define ESCAP2 257 -struct opform intable[NOTAB] ; -struct opform *lastform = intable-1 ; +struct opform intable[NOTAB]; +struct opform *lastform = intable - 1; -int nerror = 0 ; -int atend = 0 ; -int line = 1 ; +int nerror = 0; +int atend = 0; +int line = 1; -extern char em_mnem[][4] ; -char esca1[] = "escape1" ; -char esca2[] = "escape2" ; +extern char em_mnem[][4]; +char esca1[] = "escape1"; +char esca2[] = "escape2"; #define ename(no) ((no)==ESCAP1?esca1:(no)==ESCAP2?esca2:em_mnem[(no)]) -extern char em_flag[] ; +extern char em_flag[]; -main(argc,argv) char **argv ; { - if ( argc>1 ) { - if ( freopen(argv[1],"r",stdin)==NULL) { - fatal("Cannot open %s",argv[1]) ; +char *ident(void); +void check(int); +int decflag(char *); +void checkall(void); +void chkc(int, int, int, int); +void ckop(int, int, int, int); +int readchar(void); +void pushback(int); +void writeout(void); +void prx(register int, int, int); +void readin(void); +int getmnem(char *); +void error(char *str, ...); +void mess(char *str, ...); +void fatal(char *str, ...); + + + +int main(int argc, char **argv) +{ + if (argc > 1) + { + if (freopen(argv[1], "r", stdin) == NULL) + { + fatal("Cannot open %s", argv[1]); } } - if ( argc>2 ) { - if ( freopen(argv[2],"w",stdout)==NULL) { - fatal("Cannot create %s",argv[2]) ; + if (argc > 2) + { + if (freopen(argv[2], "w", stdout) == NULL) + { + fatal("Cannot create %s", argv[2]); } } - if ( argc>3 ) { - fatal("%s [ file [ file ] ]",argv[0]) ; + if (argc > 3) + { + fatal("%s [ file [ file ] ]", argv[0]); } - atend=0 ; + atend = 0; readin(); - atend=1 ; + atend = 1; checkall(); - if ( nerror==0 ) { + if (nerror == 0) + { writeout(); } - exit(nerror) ; + exit(nerror); } -readin() { - register struct opform *nextform ; - char *ident(); - char *firstid ; +void readin(void) +{ + register struct opform *nextform; + char *firstid; - for ( nextform=intable ; - !feof(stdin) && nextform<&intable[NOTAB] ; ) { - firstid=ident() ; - if ( *firstid=='\n' || feof(stdin) ) continue ; - lastform=nextform ; - nextform->i_opcode = getmnem(firstid) ; - nextform->i_flag = decflag(ident()) ; - switch ( nextform->i_flag&OPTYPE ) { - case OPMINI: - case OPSHORT: - nextform->i_num = atoi(ident()) ; - break ; + for (nextform = intable; !feof(stdin) && nextform < &intable[NOTAB];) + { + firstid = ident(); + if (*firstid == '\n' || feof(stdin)) + continue; + lastform = nextform; + nextform->i_opcode = getmnem(firstid); + nextform->i_flag = decflag(ident()); + switch (nextform->i_flag & OPTYPE) + { + case OPMINI: + case OPSHORT: + nextform->i_num = atoi(ident()); + break; } - nextform->i_low = atoi(ident()) ; - if ( *ident()!='\n' ) { - int c ; + nextform->i_low = atoi(ident()); + if (*ident() != '\n') + { + int c; error("End of line expected"); - while ( (c=readchar())!='\n' && c!=EOF ) ; + while ((c = readchar()) != '\n' && c != EOF) + ; } - nextform++ ; + nextform++; } - if ( !feof(stdin) ) fatal("Internal table too small") ; + if (!feof(stdin)) + fatal("Internal table too small"); } -char *ident() { +char *ident(void) +{ /* skip spaces and tabs, anything up to space,tab or eof is - a identifier. - Anything from # to end-of-line is an end-of-line. - End-of-line is an identifier all by itself. - */ + a identifier. + Anything from # to end-of-line is an end-of-line. + End-of-line is an identifier all by itself. + */ - static char array[200] ; - register int c ; - register char *cc ; + static char array[200]; + register int c; + register char *cc; - do { - c=readchar() ; - } while ( c==' ' || c=='\t' ) ; - for ( cc=array ; cc<&array[(sizeof array) - 1] ; cc++ ) { - if ( c=='#' ) { - do { - c=readchar(); - } while ( c!='\n' && c!=EOF ) ; + do + { + c = readchar(); + } while (c == ' ' || c == '\t'); + for (cc = array; cc < &array[(sizeof array) - 1]; cc++) + { + if (c == '#') + { + do + { + c = readchar(); + } while (c != '\n' && c != EOF); } - *cc = c ; - if ( c=='\n' && cc==array ) break ; - c=readchar() ; - if ( c=='\n' ) { - pushback(c) ; - break ; + *cc = c; + if (c == '\n' && cc == array) + break; + c = readchar(); + if (c == '\n') + { + pushback(c); + break; } - if ( c==' ' || c=='\t' || c==EOF ) break ; + if (c == ' ' || c == '\t' || c == EOF) + break; } - *++cc=0 ; - return array ; + *++cc = 0; + return array; } -int getmnem(str) char *str ; { - char (*ptr)[4] ; +int getmnem(char *str) +{ + char (*ptr)[4]; - for ( ptr = em_mnem ; *ptr<= &em_mnem[sp_lmnem-sp_fmnem][0] ; ptr++ ) { - if ( strcmp(*ptr,str)==0 ) return (ptr-em_mnem) ; + for (ptr = em_mnem; *ptr <= &em_mnem[sp_lmnem - sp_fmnem][0]; ptr++) + { + if (strcmp(*ptr, str) == 0) + return (ptr - em_mnem); } - error("Illegal mnemonic") ; - return 0 ; + error("Illegal mnemonic"); + return 0; } -error(str,a1,a2,a3,a4,a5,a6) /* VARARGS1 */ char *str ; { - if ( !atend ) fprintf(stderr,"line %d: ",line) ; - fprintf(stderr,str,a1,a2,a3,a4,a5,a6) ; - fprintf(stderr,"\n"); - nerror++ ; +void error(char *str, ...) + /* VARARGS1 */ +{ + if (!atend) + fprintf(stderr, "line %d: ", line); + + va_list ap; + va_start(ap, str); + vfprintf(stderr, str, ap); + va_end(ap); + fprintf(stderr, "\n"); + nerror++; } -mess(str,a1,a2,a3,a4,a5,a6) /* VARARGS1 */ char *str ; { - if ( !atend ) fprintf(stderr,"line %d: ",line) ; - fprintf(stderr,str,a1,a2,a3,a4,a5,a6) ; - fprintf(stderr,"\n"); +void mess(char *str, ...) + /* VARARGS1 */ +{ + if (!atend) + fprintf(stderr, "line %d: ", line); + va_list ap; + va_start(ap, str); + vfprintf(stderr, str, ap); + va_end(ap); + fprintf(stderr, "\n"); } -fatal(str,a1,a2,a3,a4,a5,a6) /* VARARGS1 */ char *str ; { - error(str,a1,a2,a3,a4,a5,a6) ; - exit(1) ; +void fatal(char *str, ...) + /* VARARGS1 */ +{ + va_list ap; + va_start(ap, str); + error(str, ap); + va_end(ap); + exit(1); } #define ILLGL -1 -check(val) int val ; { - if ( val!=ILLGL ) error("Illegal flag combination") ; +void check(int val) +{ + if (val != ILLGL) + error("Illegal flag combination"); } -int decflag(str) char *str ; { - int type ; - int escape ; - int range ; - int wordm ; - int notzero ; +int decflag(char *str) +{ + int type; + int escape; + int range; + int wordm; + int notzero; - type=escape=range=wordm=notzero= ILLGL ; - while ( *str ) switch ( *str++ ) { - case 'm' : - check(type) ; type=OPMINI ; break ; - case 's' : - check(type) ; type=OPSHORT ; break ; - case '-' : - check(type) ; type=OPNO ; break ; - case '1' : - check(type) ; type=OP8 ; break ; - case '2' : - check(type) ; type=OP16 ; break ; - case '4' : - check(type) ; type=OP32 ; break ; - case '8' : - check(type) ; type=OP64 ; break ; - case 'u' : - check(type) ; type=OP16U ; break ; - case 'e' : - check(escape) ; escape=0 ; break ; - case 'N' : - check(range) ; range= 2 ; break ; - case 'P' : - check(range) ; range= 1 ; break ; - case 'w' : - check(wordm) ; wordm=0 ; break ; - case 'o' : - check(notzero) ; notzero=0 ; break ; - default : - error("Unknown flag") ; - } - if ( type==ILLGL ) error("Type must be specified") ; - switch ( type ) { - case OP64 : - case OP32 : - if ( escape!=ILLGL ) error("Conflicting escapes") ; - escape=ILLGL ; - case OP16 : - case OP16U : - case OP8 : - case OPSHORT : - case OPNO : - if ( notzero!=ILLGL ) mess("Improbable OPNZ") ; - if ( type==OPNO && range!=ILLGL ) { - mess("No operand in range") ; + type = escape = range = wordm = notzero = ILLGL; + while (*str) + switch (*str++) + { + case 'm': + check(type); + type = OPMINI; + break; + case 's': + check(type); + type = OPSHORT; + break; + case '-': + check(type); + type = OPNO; + break; + case '1': + check(type); + type = OP8; + break; + case '2': + check(type); + type = OP16; + break; + case '4': + check(type); + type = OP32; + break; + case '8': + check(type); + type = OP64; + break; + case 'u': + check(type); + type = OP16U; + break; + case 'e': + check(escape); + escape = 0; + break; + case 'N': + check(range); + range = 2; + break; + case 'P': + check(range); + range = 1; + break; + case 'w': + check(wordm); + wordm = 0; + break; + case 'o': + check(notzero); + notzero = 0; + break; + default: + error("Unknown flag"); } + if (type == ILLGL) + error("Type must be specified"); + switch (type) + { + case OP64: + case OP32: + if (escape != ILLGL) + error("Conflicting escapes"); + escape = ILLGL; + case OP16: + case OP16U: + case OP8: + case OPSHORT: + case OPNO: + if (notzero != ILLGL) + mess("Improbable OPNZ"); + if (type == OPNO && range != ILLGL) + { + mess("No operand in range"); + } } - if ( escape!=ILLGL ) type|=OPESC ; - if ( wordm!=ILLGL ) type|=OPWORD ; - switch ( range) { - case ILLGL : type|=OP_BOTH ; - if ( type==OPMINI || type==OPSHORT ) - error("Minies and shorties must have P or N") ; - break ; - case 1 : type|=OP_POS ; break ; - case 2 : type|=OP_NEG ; break ; + if (escape != ILLGL) + type |= OPESC; + if (wordm != ILLGL) + type |= OPWORD; + switch (range) + { + case ILLGL: + type |= OP_BOTH; + if (type == OPMINI || type == OPSHORT) + error("Minies and shorties must have P or N"); + break; + case 1: + type |= OP_POS; + break; + case 2: + type |= OP_NEG; + break; } - if ( notzero!=ILLGL ) type|=OPNZ ; - return type ; + if (notzero != ILLGL) + type |= OPNZ; + return type; } /* ----------- checking --------------*/ -int ecodes[256],codes[256],lcodes[256] ; -char eflags[256], flags[256], lflags[256] ; +int ecodes[256], codes[256], lcodes[256]; +char eflags[256], flags[256], lflags[256]; int elows[256], lows[256], llows[256]; #define NMNEM (sp_lmnem-sp_fmnem+1) @@ -235,258 +342,326 @@ int elows[256], lows[256], llows[256]; #define MAY 2 #define FORB 3 -char negc[NMNEM], zc[NMNEM], posc[NMNEM], lnegc[NMNEM], lposc[NMNEM] ; +char negc[NMNEM], zc[NMNEM], posc[NMNEM], lnegc[NMNEM], lposc[NMNEM]; -checkall() { - register i,flag ; - register struct opform *next ; - int opc,low ; +void checkall(void) +{ + register int i, flag; + register struct opform *next; + int opc, low; - for ( i=0 ; ii_flag&0377 ; - opc = next->i_opcode&0377 ; - low = next->i_low&0377 ; - chkc(flag,low,opc,low) ; - switch(flag&OPTYPE) { - case OPNO : zc[opc]++ ; break ; - case OPMINI : - case OPSHORT : - for ( i=1 ; i<((next->i_num)&0377) ; i++ ) { - chkc(flag,low+i,opc,low) ; - } - if ( !(em_flag[opc]&PAR_G) && - (flag&OPRANGE)==OP_BOTH) { - mess("Mini's and shorties should have P or N"); - } - break ; - case OP8 : - error("OP8 is removed") ; - break ; - case OP16 : - if ( flag&OP_NEG ) - negc[opc]++ ; - else if ( flag&OP_POS ) - posc[opc]++ ; - break ; - case OP32 : - if ( flag&OP_NEG ) - lnegc[opc]++ ; - else if ( flag&OP_POS ) - lposc[opc]++ ; - break ; - case OP16U : - break ; - default : - error("Illegal type") ; - break ; + atend = 0; + line = 0; + for (next = intable; next <= lastform; next++) + { + line++; + flag = next->i_flag & 0377; + opc = next->i_opcode & 0377; + low = next->i_low & 0377; + chkc(flag, low, opc, low); + switch (flag & OPTYPE) + { + case OPNO: + zc[opc]++; + break; + case OPMINI: + case OPSHORT: + for (i = 1; i < ((next->i_num) & 0377); i++) + { + chkc(flag, low + i, opc, low); + } + if (!(em_flag[opc] & PAR_G) && (flag & OPRANGE) == OP_BOTH) + { + mess("Mini's and shorties should have P or N"); + } + break; + case OP8: + error("OP8 is removed"); + break; + case OP16: + if (flag & OP_NEG) + negc[opc]++; + else if (flag & OP_POS) + posc[opc]++; + break; + case OP32: + if (flag & OP_NEG) + lnegc[opc]++; + else if (flag & OP_POS) + lposc[opc]++; + break; + case OP16U: + break; + default: + error("Illegal type"); + break; } } - atend=1 ; - for ( i=0 ; i<256 ; i++ ) if ( codes[i]== -1 ) { - mess("interpreter opcode %d not used",i) ; - } - for ( opc=0 ; opc 1) + mess("More then one OPNO for %s", ename(emc)); + if (posc[emc] > 1) + mess("More then one OP16(pos) for %s", ename(emc)); + if (negc[emc] > 1) + mess("More then one OP16(neg) for %s", ename(emc)); + if (lposc[emc] > 1) + mess("More then one OP32(pos) for %s", ename(emc)); + if (lnegc[emc] > 1) + mess("More then one OP32(neg) for %s", ename(emc)); + switch (zf) + { + case MUST: + if (zc[emc] == 0) + mess("No OPNO for %s", ename(emc)); + break; + case FORB: + if (zc[emc] == 1) + mess("Forbidden OPNO for %s", ename(emc)); + break; + } + switch (pf) + { + case MUST: + if (posc[emc] == 0) + mess("No OP16(pos) for %s", ename(emc)); + break; + case FORB: + if (posc[emc] == 1) + mess("Forbidden OP16(pos) for %s", ename(emc)); + break; + } + switch (nf) + { + case MUST: + if (negc[emc] == 0) + mess("No OP16(neg) for %s", ename(emc)); + break; + case FORB: + if (negc[emc] == 1) + mess("Forbidden OP16(neg) for %s", ename(emc)); + break; } } -ckop(emc,zf,pf,nf) { - if ( zc[emc]>1 ) mess("More then one OPNO for %s",ename(emc)) ; - if ( posc[emc]>1 ) mess("More then one OP16(pos) for %s",ename(emc)) ; - if ( negc[emc]>1 ) mess("More then one OP16(neg) for %s",ename(emc)) ; - if ( lposc[emc]>1 ) mess("More then one OP32(pos) for %s",ename(emc)) ; - if ( lnegc[emc]>1 ) mess("More then one OP32(neg) for %s",ename(emc)) ; - switch(zf) { - case MUST: - if ( zc[emc]==0 ) mess("No OPNO for %s",ename(emc)) ; - break ; - case FORB: - if ( zc[emc]==1 ) mess("Forbidden OPNO for %s",ename(emc)) ; - break ; +static int pushchar; +static int pushf; + +int readchar(void) +{ + int c; + + if (pushf) + { + pushf = 0; + c = pushchar; } - switch(pf) { - case MUST: - if ( posc[emc]==0 ) mess("No OP16(pos) for %s",ename(emc)) ; - break ; - case FORB: - if ( posc[emc]==1 ) - mess("Forbidden OP16(pos) for %s",ename(emc)) ; - break ; - } - switch(nf) { - case MUST: - if ( negc[emc]==0 ) mess("No OP16(neg) for %s",ename(emc)) ; - break ; - case FORB: - if ( negc[emc]==1 ) - mess("Forbidden OP16(neg) for %s",ename(emc)) ; - break ; + else + { + if (feof(stdin)) + return EOF; + c = getc(stdin); } + if (c == '\n') + line++; + return c; } -static int pushchar ; -static int pushf ; - -int readchar() { - int c ; - - if ( pushf ) { - pushf=0 ; - c = pushchar ; - } else { - if ( feof(stdin) ) return EOF ; - c=getc(stdin) ; +void pushback(int c) +{ + if (pushf) + { + fatal("Double pushback"); } - if ( c=='\n' ) line++ ; - return c ; + pushf++; + pushchar = c; + if (c == '\n') + line--; } -pushback(c) { - if ( pushf ) { - fatal("Double pushback") ; - } - pushf++ ; - pushchar=c ; - if ( c=='\n' ) line-- ; -} - -writeout() { +void writeout(void) +{ register int i; printf("DISPATCH1"); - for (i = 0; i < 256;) { - if (!(i % 8)) printf("\n%d", i); + for (i = 0; i < 256;) + { + if (!(i % 8)) + printf("\n%d", i); printf("\t%s", ename(codes[i])); - if (i < 254) { - prx(flags[i],lows[i],i); + if (i < 254) + { + prx(flags[i], lows[i], i); } i++; } printf("\nDISPATCH2"); - for (i = 0; i < 256;) { - if (ecodes[i] != -1) { - if (!(i % 8)) printf("\n%d", i); + for (i = 0; i < 256;) + { + if (ecodes[i] != -1) + { + if (!(i % 8)) + printf("\n%d", i); printf("\t%s", ename(ecodes[i])); - prx(eflags[i],elows[i],i); + prx(eflags[i], elows[i], i); } - else break; + else + break; i++; } printf("\nDISPATCH3"); i = 0; - while (lcodes[i] != -1) { - if (!(i % 8)) printf("\n%d", i); + while (lcodes[i] != -1) + { + if (!(i % 8)) + printf("\n%d", i); printf("\t%s", ename(lcodes[i])); - prx(lflags[i],llows[i],i); + prx(lflags[i], llows[i], i); i++; } - while (i++ % 8) putchar('\t'); + while (i++ % 8) + putchar('\t'); putchar('\n'); } -prx(flg,low,opc) - register int flg; +void prx(register int flg, int low, int opc) { int arg = opc - low; putchar('.'); - switch(flg&OPTYPE) { - case OPNO: - putchar('z'); - break; - case OP16U: - putchar('u'); - break; - case OP16: - if (flg&OP_POS) putchar('p'); - else if (flg&OP_NEG) putchar('n'); - else putchar('l'); - if (flg&OPWORD) putchar('w'); - break; - case OP32: - if (flg&OP_POS) putchar('P'); - else if (flg&OP_NEG) putchar('N'); - else putchar('L'); - if (flg&OPWORD) putchar('w'); - break; - case OPSHORT: - if (flg & OPWORD) putchar('w'); - else putchar('s'); - /* fall through */ - case OPMINI: - if (flg & OPNZ) arg++; - if (flg & OP_NEG) arg = -arg - 1; - printf("%d",arg); - if((flg&OPTYPE) == OPMINI && (flg & OPWORD)) putchar('W'); + switch (flg & OPTYPE) + { + case OPNO: + putchar('z'); + break; + case OP16U: + putchar('u'); + break; + case OP16: + if (flg & OP_POS) + putchar('p'); + else if (flg & OP_NEG) + putchar('n'); + else + putchar('l'); + if (flg & OPWORD) + putchar('w'); + break; + case OP32: + if (flg & OP_POS) + putchar('P'); + else if (flg & OP_NEG) + putchar('N'); + else + putchar('L'); + if (flg & OPWORD) + putchar('w'); + break; + case OPSHORT: + if (flg & OPWORD) + putchar('w'); + else + putchar('s'); + /* fall through */ + case OPMINI: + if (flg & OPNZ) + arg++; + if (flg & OP_NEG) + arg = -arg - 1; + printf("%d", arg); + if ((flg & OPTYPE) == OPMINI && (flg & OPWORD)) + putchar('W'); } } diff --git a/doc/i80.doc b/doc/i80.doc index e2019b0ad..baca86e67 100644 --- a/doc/i80.doc +++ b/doc/i80.doc @@ -10,7 +10,7 @@ A back end is a part of the Amsterdam Compiler Kit (ACK). It translates EM, a family of intermediate languages, into the assembly language of some target machine, here the Intel 8080 and Intel 8085 microprocessors. .AE -.NH1 +.NH 1 INTRODUCTION .PP To simplify the task of producing portable (cross) compilers and diff --git a/doc/install.doc b/doc/install.doc old mode 100644 new mode 100755 index fd9dae84a..0f2946b33 --- a/doc/install.doc +++ b/doc/install.doc @@ -1,4 +1,3 @@ -.\" $Id$ .if n .nr PD 1v .if n .nr LL 78m .if n .ll 78m @@ -18,13 +17,6 @@ This document describes the process of installing the Amsterdam Compiler Kit (ACK). It depends on the combination of hard- and software how hard it will be to install the Kit. -This description is intended for a Sun-3 or SPARC workstation. -Installation on VAXen running Berkeley -.UX -or Ultrix, -Sun-2 systems and most System V -.UX -systems should be easy. As of this distribution, installation on PDP-11's or other systems with a small address space is no longer supported. See section 8 for installation on other systems. @@ -35,7 +27,7 @@ In the ACK installation process, three directory trees are used: .IP "-" the ACK source tree. This is the tree on the ACK distribution medium. For the rest of this document, we will refer to this directory -as $SRC_HOME; +as $ACK_SRC_HOME; .IP "-" a configuration tree. This tree is built by the installation process and is used to do compilations in. Its structure reflects that of the source tree, @@ -45,10 +37,10 @@ as $CONFIG; .IP "-" an ACK users tree. This tree is also built by the installation process. For the rest of this document, we will refer to this directory -as $TARGET_HOME; +as $ACK_HOME; .LP After installation, -the directories in $TARGET_HOME contain the following information: +the directories in $ACK_HOME contain the following information: .if n .sp 1 .if n .nr PD 0 .IP "bin" 14 @@ -57,30 +49,41 @@ See the section about "Commands". .IP "lib" root of a tree containing almost all libraries used by commands. -Files specific to a certain machine are collected in one subtree -per machine. E.g. "lib/pdp", "lib/z8000". +Files specific to a certain platform are collected in one subtree +per platform. E.g. "lib/cpm", "lib/pdpv7". The names used here are the same names as used for subtrees -of "$SRC_HOME/mach". +of "$ACK_SRC_HOME/plat". Each of the platform specific directory +contains the following libraries: +.TS +l l. +libb B run-time system +libbc Basic run-time system +libc C run-time system +libpc Pascal run-time system +libm2 Modula-2 run-time system +liboc Occam run-time system +.TE + .IP "lib/descr" -command descriptor files used by the program ack. +command descriptor files used by the program ack to determine utilities to call. .IP "lib/LLgen" files used by the LL(1) parser generator. .IP "lib/flex" files used by the lexical analyzer generator Flex. .IP "lib/m2" definition modules for Modula-2. -.IP "lib.bin" +.IP "lib/ack" root of a tree containing almost all binaries used by commands. -All programs specific to a certain machine are collected in one subtree -per machine. E.g. "lib.bin/pdp", "lib.bin/z8000". +All programs specific to a certain platform are collected in one subtree +per machine. E.g. "lib/ack/pdpv7", "lib/ack/cpm". The names used here are the same names as used for subtrees -of "$SRC_HOME/mach". -.IP "lib.bin/ego" +of "$ACK_SRC_HOME/plat". +.IP "lib/ack/ego" files used by the global optimizer. -.IP "lib.bin/lint" +.IP "lib/ack/lint" binaries for the lint passes and lint libraries. -.IP "lib.bin/ceg" +.IP "lib/ack/ceg" files used by the code-expander-generator. .IP "etc" contains the file "ip_spec.t" needed for EM interpreters and EM documentation. @@ -120,7 +123,7 @@ em_abs.h contains trap numbers and address for lin and fil em_ego.h definition of names for some global optimizer messages em_flag.h definition of bits in array em_flag in - $TARGET_HOME/lib.bin/em_data.a. Describes parameters + $ACK_HOME/lib.bin/em_data.a. Describes parameters effect on flow of instructions em_mes.h definition of names for mes pseudo numbers em_mnem.h instruction => compact mapping @@ -187,7 +190,7 @@ The directories in the source tree contain the following information: .IP "bin" 14 source of some shell-scripts. .IP "lib" -mostly description files for the "ack" program. +mostly description files for the "ack" program. .IP "etc" the main description of EM sits here. Files (e.g. em_table) describing @@ -202,30 +205,23 @@ These directories have subdirectories named: .in +3n .TS l l. -cg the backend (*.m => *.s) -ncg the new backend (*.m => *.s) -as the assembler (*.s => *.o) or +cg the backend code generator (*.m => *.s) +ncg the new backend code generator (*.m => *.s) +mcg the modified backend code generator (*.m => *.s) +as the CPU specific assembler (*.s => *.o) or assembler/linker (*.s + libraries => a.out) -cv conversion programs for a.out files +cv conversion programs for a.out files. Mostly replaced by "cvmach" dl down-load programs top the target optimizer -int source for an interpreter +int source for an interpreter (requires POSIX compliant host) +ce code expander (fast back-end) -libbc to create Basic run-time system and libraries -libcc to create C run-time system and libraries -libcc.ansi to create ANSI C run-time system and libraries -libpc to create Pascal run-time system and libraries -libf77 to create Fortran run-time system and libraries -libm2 to create Modula-2 run-time system and libraries -liboc to create occam run-time system and libraries -libem EM runtime system, only depending on CPU type +libem to create runtime system used by code generators libend library defining end, edata, etext -libfp to create floating point library +libfp to create floating point emulation library libdb to create debugger support library -libsys system-dependent EM library libce fast cc-compatible C compiler library support -ce code expander (fast back-end) test various tests .TE @@ -245,6 +241,21 @@ mach/proto/fp floating point package sources mach/proto/libg makefiles for compiling libraries mach/proto/grind machine-independent debugger support .TE + +.IP "plat" +Group of directories which are specific to each operating system. +These dirctories have subdirectories named: + +.TS +l l. +cvmach conversion program to convert from a.out to platform specific binaries. +emu system specific platform emulator or simulator used for testing. +libsys system-dependent library used to interface with the operating system. +include/ack system-dependent include files for building libc library, including mandatory "plat.h" +include/sys system-dependent include files used with libsys. +.TE + + .IP "emtest" contains prototype of em test set. .IP "lang" @@ -262,26 +273,26 @@ the Pascal compiler proper. the C front-end. .IP "lang/cem/libcc" .br -directories with sources of C runtime system, libraries (in EM or C). +directories with sources of C runtime system, libraries (in EM or C). \fIObsolete\fP. .IP "lang/cem/libcc/gen" .br sources for routines in chapter III of .UX programmers manual, -excluding stdio. +excluding stdio. \fIObsolete\fP. .IP "lang/cem/libcc/stdio" .br -stdio sources. +stdio sources. \fIObsolete\fP. .IP "lang/cem/libcc/math" .br sources for mathematical routines, normally available with the -\fB-lm\fP option to \fIcc\fP. +\fB-lm\fP option to \fIcc\fP. \fIObsolete\fP. .IP "lang/cem/libcc/mon" .br -sources for routines in chapter II, mostly written in EM. +sources for routines in chapter II, mostly written in EM. \fIObsolete\fP. .IP "lang/cem/cemcom" .br -the compiler proper. +the compiler proper. \fIObsolete\fP. .IP "lang/cem/cemcom.ansi" .br the ANSI C compiler proper. @@ -290,7 +301,10 @@ the ANSI C compiler proper. the ANSI C preprocessor. .IP "lang/cem/libcc.ansi" .br -the ANSI C library sources. +Portable part of the ANSI C library sources. The platform specific source code is in +libsys. +.IP "lang + .IP "lang/cem/ctest" .br the C test set. @@ -388,54 +402,79 @@ contains sub-directories for installing the fast ACK compatible compilers. contains the sources of the fast ACK compatible compiler drivers. .IP "fcc" contains the fast cc-compatible C compiler for SUN-3 and VAX. +.IP "modules" +root of a tree containing modules (optional install) +.IP "modules/src/alloc" +Memory management module. +.IP "modules/src/data" +Data structures and collections module. +.IP "modules/src/em_code" +EM assembly generator module (*.[km]) +.IP "modules/src/em_data" +EM data managemet module. +.IP "modules/src/em_mes" +EM Message pseudo-instruction generator module. +.IP "modules/src/em_opt" +EM Optimizer +.IP "modules/src/flt_arith" +Floating point support routine module. +.IP "modules/src/object" +ACK Object file format support reader/writer module. +.IP "modules/src/print" +Light version of standard output routines. Optimized for space compared to standard C version. +.IP "modules/src/read_em" +Compact (*.k) EM reader module. +.IP "modules/src/string" +String utility module. +.IP "modules/src/system" +Module related to the ACK system in general as well as wrapper over standard C library calls to +solve portability issues. .IP "util" contains directories with sources for various utilities. .IP "util/ack" the program used for translation with the Kit. -.IP "util/opt" -the EM peephole optimizer (*.k => *.m). -.IP "util/ego" -the global optimizer. -.IP "util/topgen" -the target optimizer generator. -.IP "util/misc" -decode (*.[km] => *.e) + encode (*.e => *.k). -.IP "util/data" -the C-code for $TARGET_HOME/lib.bin/em_data.a. -These sources are created by the Makefile in `etc`. -.IP "util/ass" -the EM assembler (*.[km] + libraries => e.out). -.IP "util/arch" -the archivers to be used for all EM utilities. -.IP "util/cgg" -a program needed for compiling backends. -.IP "util/ncgg" -a program needed for compiling the newest backends. -.IP "util/cpp" -the C preprocessor. -.IP "util/shf" -various shell files. -.IP "util/LLgen" -the extended LL(1) parser generator. .IP "util/amisc" contains some programs handling ACK a.out format, such as anm, asize. +.IP "util/arch" +the archivers to be used for all EM utilities. +.IP "util/ass" +the EM assembler and linker (*.[km] + libraries => e.out). +.IP "util/byacc" +this is Berkeley yacc, in the public domain. \fIObsolete\fP. +.IP "util/ceg" +code expander generator. +.IP "util/cgg" +a program needed for compiling backends. .IP "util/cmisc" contains some programs to help in resolving name conflicts, and a dependency generator for makefiles. -.IP "util/led" -the ACK link-editor, reading ACK relocatable a.out format, and writing -ACK a.out format. -.IP "util/int" -an EM interpreter, written in C. Very useful for checking out software, -but slow. -.IP "util/ceg" -code expander generator. +.IP "util/cpp" +the C preprocessor. \fIObsolete\fP. +.IP "util/ego" +the global optimizer. .IP "util/grind" a symbolic debugger. -.IP "util/byacc" -this is Berkeley yacc, in the public domain. +.IP "util/int" +an EM interpreter, written in C. Very useful for checking out software. +.IP "util/led" +the ACK link-editor, reading CPU specific ACK relocatable a.out format, and writing +ACK a.out format. +.IP "util/LLgen" +the extended LL(1) parser generator. +.IP "util/make" +simple make tool. +.IP "util/misc" +decode (*.[km] => *.e) + encode (*.e => *.k). +.IP "util/ncgg" +a program needed for compiling the newest backends. +.IP "util/opt" +the EM peephole optimizer (*.k => *.m). +.IP "util/shf" +various shell files. +.IP "util/topgen" +the target optimizer generator. .IP "util/flex" -this is a replacement for lex. It carries the following copyright notice: +this is a replacement for lex. \fIObsolete\fP. It carries the following copyright notice: .IP "" .nf Copyright (c) 1990 The Regents of the University of California. @@ -469,8 +508,8 @@ PURPOSE. .if n .nr PD 1v .LP All path names mentioned in the text of this document are relative to -$SRC_HOME, unless they start with '/' or one of $SRC_HOME, -$TARGET_HOME or $CONFIG. +$ACK_SRC_HOME, unless they start with '/' or one of $ACK_SRC_HOME, +$ACK_HOME or $CONFIG. .NH Restoring the ACK tree .PP @@ -480,7 +519,7 @@ distribution tree structure. Proceed as follows .IP " \-" 10 Create a directory, for example /usr/share/local/src/ack, on a device -with at least 15 Megabytes left. This directory will be $SRC_HOME. +with at least 15 Megabytes left. This directory will be $ACK_SRC_HOME. .IP " \-" Change to that directory (cd ...). .IP " \-" @@ -497,7 +536,7 @@ Adapting ACK to the local system Before compiling the sources in the Kit some installation dependent actions have to be taken. Most of these are performed by an interactive shell script in the file -.I $SRC_HOME/first/first. +.I $ACK_SRC_HOME/first/first. Calling this script should be done from another directory, for instance an empty directory which will later become $CONFIG. @@ -508,8 +547,8 @@ script are: .if n .sp 1 .if n .nr PD 0 .IP \- -Asking for the path names of the ACK source directory ($SRC_HOME), the -configuration directory ($CONFIG), and the ACK users directory ($TARGET_HOME). +Asking for the path names of the ACK source directory ($ACK_SRC_HOME), the +configuration directory ($CONFIG), and the ACK users directory ($ACK_HOME). About 5M are needed for the configuration tree. The disk space needed for the ACK users tree depends on which front-ends and back-ends are to be installed. @@ -566,7 +605,7 @@ on a different machine". .IP \- Setting the default machine for which code is produced to the local type of system according to the table above. -This in done in the file "$TARGET_HOME/config/local.h". +This in done in the file "$ACK_HOME/config/local.h". See also section 9.1. .IP \- Asking for things that don't have to be installed. @@ -599,7 +638,7 @@ Most configuration directories will have Makefiles used to compile and install the programs in that directory. All programs needed for compilation and/or cross compilation -with the Kit are installed in $TARGET_HOME by these Makefiles. +with the Kit are installed in $ACK_HOME by these Makefiles. These Makefiles are produced from corresponding files called "proto.make" in the source tree. In fact, the "proto.make" files are almost complete Makefiles, except for some macro definitions that @@ -618,7 +657,7 @@ Calling the "TakeAction" script. All these Makefiles do not have to be called separately. We wrote a shell script calling the make's needed to install the whole Kit. -This script consists of the file $SRC_HOME/TakeAction +This script consists of the file $ACK_SRC_HOME/TakeAction and a few files called Action in some configuration directories. The Action files describe in a very simple form which actions have to be performed in which directories. @@ -645,7 +684,7 @@ what must be installed. .LP If the installation succeeded, the Kit is ready to be used. Read section 6 and the manuals provided -with the Kit (in the $TARGET_HOME/man directory) on how to use it. +with the Kit (in the $ACK_HOME/man directory) on how to use it. .NH 2 Problems .NH 3 @@ -654,7 +693,7 @@ on Unisoft m68000 systems. The Unisoft C compiler has a bug which impedes the correct translation of the peephole optimizer. For a more detailed description of this phenomenon see -the file "$SRC_HOME/mach/m68k2/Unisoft_bug". +the file "$ACK_SRC_HOME/mach/m68k2/Unisoft_bug". (This observation was made in 1985 or so, so it is probably no longer true). .NH 3 @@ -727,7 +766,7 @@ If that directory contains an Action file issue the command .NH Commands .PP -The following commands are available in the $TARGET_HOME/bin directory after compilation +The following commands are available in the $ACK_HOME/bin directory after compilation of the Kit: .IP "\fIack\fP, \fIacc\fP, \fIabc\fP, \fIapc\fP, \fIocm\fP, \fIm2\fP, \fIf2c\fP and their links" 14 .br @@ -780,7 +819,7 @@ this is a cc-compatible fast C compiler, available on SUN-3 and VAX systems. It compiles very fast, but produces slow code. .LP We currently make the Kit available to our users by telling -them that they should include the $TARGET_HOME/bin directory in +them that they should include the $ACK_HOME/bin directory in their PATH shell variable. The programs will still work when moved to a different directory or linked to. @@ -793,7 +832,7 @@ Any call name not being \fIcc\fP, \fIacc\fP, \fIabc\fP, \fIpc\fP, \fIf2c\fP, \fIocm\fP, \fIm2\fP, or \fIapc\fP will be interpreted as the name of a 'machine description' and the program will try to find a description file with that name. -The installation process will only touch the utilities in the $TARGET_HOME/bin +The installation process will only touch the utilities in the $ACK_HOME/bin directory, not copies of these utilities. .NH Machines @@ -802,7 +841,7 @@ Below is a table with entries for all commands in the bin directory used to (cross)compile for a particular machine. The name in the first column gives the name in the bin directory. The column headed dir indicates which subdirectories of -$TARGET_HOME/lib and/or $TARGET_HOME/lib.bin are needed for compilation. +$ACK_HOME/lib and/or $ACK_HOME/lib.bin are needed for compilation. The column head i/p contains the integer and pointer size used in units of bytes. The subdirectories with the same name in mach contain the sources. @@ -1002,11 +1041,11 @@ the second takes 2/4 and 4/4 files, and the last one takes 2/2, 2/4 and 4/4. The PDP 11 interpreter executes floating point instructions. .LP -The program \fB$TARGET_HOME/bin/em\fP calls the appropriate +The program \fB$ACK_HOME/bin/em\fP calls the appropriate interpreter. The interpreters are looked for in the em22, em24 and em44 -subdirectories of $TARGET_HOME/lib.bin. -The third interpreter is available as the program \fB$TARGET_HOME/bin/int\fP +subdirectories of $ACK_HOME/lib.bin. +The third interpreter is available as the program \fB$ACK_HOME/bin/int\fP in the bin directory. .NH Compilation on a different machine. @@ -1036,7 +1075,7 @@ which is a major undertaking. .NH 2 Universal assembler/loader, link editor .PP -For most machines, the description files in $TARGET_HOME/lib/*/descr use our +For most machines, the description files in $ACK_HOME/lib/*/descr use our universal assembler and our link editor. The load file produced is not directly usable in any system known to us, @@ -1046,23 +1085,23 @@ executable files. The \fIdl\fP programs present for some machines unravel our a.out files and transmit commands to load memory to a microprocessor over a serial line. -The file $TARGET_HOME/man/man5/ack.out.5 contains a description of the format of +The file $ACK_HOME/man/man5/ack.out.5 contains a description of the format of the universal assembler load file. It might be useful to those who wish or need to write their own conversion programs. Also, a module is included to read and write our a.out format. -See $TARGET_HOME/man/man3/object.3. +See $ACK_HOME/man/man3/object.3. .NH Options .NH 2 Default machine .PP -There is one important option in $TARGET_HOME/config/local.h. +There is one important option in $ACK_HOME/config/local.h. The utility \fIack\fP uses a default machine name when called as \fIacc\fP, \fIcc\fP, \fIabc\fP, \fIapc\fP, \fIpc\fP, \fIocm\fP, \fIm2\fP, \fIf2c\fP, or \fIack\fP. The machine name used by default is determined by the -definition of ACKM in $TARGET_HOME/config/local.h. +definition of ACKM in $ACK_HOME/config/local.h. The Kit is distributed with "sun3" as the default machine, but the shell script "first" in the directory "first" alters this to suit the target system. @@ -1071,14 +1110,14 @@ and by default produce code that can't run on the local system. .NH 2 Pathnames .PP -Absolute path names are concentrated in "$TARGET_HOME/config/em_path.h". +Absolute path names are concentrated in "$ACK_HOME/config/em_path.h". Only the utilities \fIack\fP, \fIflex\fP, and \fILLgen\fP use absolute path names to access files in the Kit. The tree is distributed with /usr/em as the working directory. The definition of EM_DIR in em_path.h should be altered to specify the root -directory for the Compiler Kit binaries on the local system ($TARGET_HOME). +directory for the Compiler Kit binaries on the local system ($ACK_HOME). This is done automatically by the shell script "first" in the directory "first". Em_path.h also specifies which directory should be used for @@ -1090,7 +1129,7 @@ The shape of the tree should not be altered lightly because most Makefiles and the utility \fIack\fP know the shape of the ACK tree. The knowledge of the utility \fIack\fP about the shape of the tree is -concentrated in the files in the directory $TARGET_HOME/lib/*/descr and $TARGET_HOME/lib/descr/*. +concentrated in the files in the directory $ACK_HOME/lib/*/descr and $ACK_HOME/lib/descr/*. .NH Makefiles .PP @@ -1120,11 +1159,11 @@ Opr should be an off-line printer daemon. On some systems it exists under another name e.g. lpr. The easiest way to call such a spooler is using a shell script with the name opr that calls lpr. -This script should be placed in /usr/bin or $TARGET_HOME/bin or +This script should be placed in /usr/bin or $ACK_HOME/bin or one of the directories in the PATH environment variable. .IP clean remove all files not needed for day-to-day use, -that is binaries not in $TARGET_HOME/bin or $TARGET_HOME/lib.bin, object files etc. +that is binaries not in $ACK_HOME/bin or $ACK_HOME/lib.bin, object files etc. .LP Example: .DS @@ -1132,13 +1171,13 @@ make install .DE given as command in a configuration directory will cause compilation of all programs in the directory and copying of the results -to the $TARGET_HOME/bin and $TARGET_HOME/lib.bin directories. +to the $ACK_HOME/bin and $ACK_HOME/lib.bin directories. .NH Testing .PP Test sets are available in Pascal, C, Basic and EM assembly: .IP EM 8 -the directory $SRC_HOME/emtest contains a few EM test programs. +the directory $ACK_SRC_HOME/emtest contains a few EM test programs. The EM assembly files in these tests must be transformed into load files. These tests use the LIN and NOP instructions to mark the passing of each @@ -1151,7 +1190,7 @@ The test finishes normally with 0 as the last number printed In all other cases a bug showed its existence. .IP Pascal -the directory $SRC_HOME/lang/pc/test contains a few Pascal test programs. +the directory $ACK_SRC_HOME/lang/pc/test contains a few Pascal test programs. All these programs print the number of errors found and a identification of these errors. .sp 1 @@ -1170,7 +1209,7 @@ Easton, Pennsylvania 18042 USA .DE .IP C -the sub-directories in $SRC_HOME/lang/cem/ctest contain C test programs. +the sub-directories in $ACK_SRC_HOME/lang/cem/ctest contain C test programs. The idea behind these tests is: if there is a program called xx.c, compile it into xx.cem. Run it with standard output to xx.cem.r, compare this file to @@ -1184,7 +1223,7 @@ The contents of the result files depend on the word size, the xx.cem.g files on the distribution are intended for a 32-bit machine. .IP Basic -the directory $SRC_HOME/lang/basic/test contains some forty Basic programs. +the directory $ACK_SRC_HOME/lang/basic/test contains some forty Basic programs. Not all of these programs are correct, some have syntactic errors, some simply don't work. The Makefile in that directory attempts to compile and run @@ -1198,8 +1237,8 @@ An example of the output of a make is present in the file Out.std. Documentation .PP After installation, the manual pages for Amsterdam Compiler Kit can be found -in the $TARGET_HOME/man directory. Also, the following documents are provided -in the $TARGET_HOME/doc directory: +in the $ACK_HOME/man directory. Also, the following documents are provided +in the $ACK_HOME/doc directory: .TS l l. toolkit.doc general overview (CACM article) diff --git a/doc/nopt.doc b/doc/nopt.doc index 173790392..0912b7a49 100644 --- a/doc/nopt.doc +++ b/doc/nopt.doc @@ -514,7 +514,7 @@ contains routines to build the data structure from the input .BI C_ xxx routines and place the structure on the pattern queue. These routines are also used to build the data structures when a replacement is constructed. -.IP aux.c 10 +.IP utils.c 10 routines to implement the external functions used in the pattern table. .LP From 82fddaab77459646f554671aa392025e69e6438e Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:05:34 +0800 Subject: [PATCH 49/84] Fully working implementation for C compiler front-end. --- fast/driver/driver.c | 408 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 335 insertions(+), 73 deletions(-) diff --git a/fast/driver/driver.c b/fast/driver/driver.c index 48aed8cc9..c0e70f8b1 100644 --- a/fast/driver/driver.c +++ b/fast/driver/driver.c @@ -14,15 +14,6 @@ Something wrong here! Only one of FM2, FPC, or FCC must be defined #endif -#ifdef sun3 -#define MACHNAME "m68020" -#define SYSNAME "sun3" -#endif - -#ifdef vax4 -#define MACHNAME "vax4" -#define SYSNAME "vax4" -#endif #ifdef i386 #define MACHNAME "i386" @@ -37,6 +28,8 @@ Something wrong here! Only one of FM2, FPC, or FCC must be defined #include #include #include +#include "smap.h" +#include "stringlist.h" #include "em_path.h" #include "system.h" @@ -76,25 +69,158 @@ struct arglist static char *CPP; static char *COMP; +static char *LD; static char *cc = "cc"; static int kids = -1; static int ecount = 0; -struct arglist CPP_FLAGS = + +struct size_info { + /* size in bytes */ + int size; + /* alignment */ + int align; +}; + +/** Contains information on the different systems supported. */ +struct system_information +{ + /** Architecture / machine name */ + char* arch; + /** Platform name */ + char* platform; + /** Linker path and name */ + char *linker; + /** Runtime startup file */ + char *startup; + /** Converter path and name */ + char *cv; + /** C preprocessor command line arguments. */ + struct arglist cpp_flags; + /** Compiler flags. */ + struct arglist compiler_flags; +}; + +const struct system_information machine_info[2] = +{ + { + "em22" /* arch */, + "em22" /* platform */, + "$H/lib/ack/em_ass" /* linker */, #ifdef FCC - 7, + "c-ansi.m" /* startup file */, #else - 13, +#ifdef FPC + "pascal.m" /* startup file */, +#ifdef FM2 + "modula2.m" /* startup file */, #endif - { "-D__unix", "-D_EM_WSIZE=4", "-D_EM_PSIZE=4", "-D_EM_SSIZE=2", - "-D_EM_LSIZE=4", "-D_EM_FSIZE=4", "-D_EM_DSIZE=8", -#ifndef FCC - "-DEM_WSIZE=4", "-DEM_PSIZE=4", "-DEM_SSIZE=2", "-DEM_LSIZE=4", - "-DEM_FSIZE=4", "-DEM_DSIZE=8", #endif - } }; +#endif + NULL /* converter */, + /** CPP Flags */ + {17,{ + "-DEM_WSIZE=2", + "-DEM_PSIZE=2", + "-DEM_SSIZE=2", + "-DEM_LSIZE=4", + "-DEM_FSIZE=4", + "-DEM_DSIZE=8", + "-DEM_XSIZE=8", + "-D_EM_WSIZE=2", + "-D_EM_PSIZE=2", + "-D_EM_SSIZE=2", + "-D_EM_LSIZE=4", + "-D_EM_FSIZE=4", + "-D_EM_DSIZE=8", + "-D_EM_XSIZE=8", + "-Dem22", + "-D__em22", + "-D__unix"}}, + /* compiler flags */ +#ifdef FCC + {1, { + "-Vw2.2i2.2p2.2f4.2s2.2l4.2d8.2x8.2" + }} +#else +#ifdef FPC + /* pc Flags */ + {1, { + "-Vw2.2i2.2l4.2p2.2f8.2S2.2" + }} +#else +#ifdef FM2 + /* pc Flags */ + {1, { + "-Vw2.2i2.2l4.2p2.2f8.2S2.2" + }} +#endif +#endif +#endif + }, + { + "em24" /* arch */, + "em24" /* platform */, + "$H/lib/ack/em_ass" /* linker */, +#ifdef FCC + "c-ansi.m" /* startup file */, +#else +#ifdef FPC + "pascal.m" /* startup file */, +#ifdef FM2 + "modula2.m" /* startup file */, +#endif +#endif +#endif + NULL /* converter */, + /** CPP Flags */ + {17,{ + "-DEM_WSIZE=2", + "-DEM_PSIZE=4", + "-DEM_SSIZE=2", + "-DEM_LSIZE=4", + "-DEM_FSIZE=4", + "-DEM_DSIZE=8", + "-DEM_XSIZE=8", + "-D_EM_WSIZE=2", + "-D_EM_PSIZE=4", + "-D_EM_SSIZE=2", + "-D_EM_LSIZE=4", + "-D_EM_FSIZE=4", + "-D_EM_DSIZE=8", + "-D_EM_XSIZE=8", + "-Dem24", + "-D__em24", + "-D__unix"}}, + /* compiler flags */ +#ifdef FCC + {1, { + "-Vw2.2i2.2p4.2f4.2s2.2l4.2d8.2x8.2" + }} +#else +#ifdef FPC + /* pc Flags */ + {1, { + "-Vw2.2i2.2l4.2p4.2f8.2S2.2" + }} +#else +#ifdef FM2 + /* pc Flags */ + {1, { + "-Vw2.2i2.2l4.2p4.2f8.2S2.2" + }} +#endif +#endif +#endif + } +}; + + +struct arglist CPP_FLAGS = {0,{NULL}}; + + struct arglist LD_HEAD = { 2, @@ -110,28 +236,6 @@ struct arglist LD_HEAD = #endif }}; -struct arglist LD_TAIL = - { -#if defined(sun3) || defined(i386) - 5, -#else - 4, -#endif - { -#ifdef FCC - "$H/lib/$S/tail_$A", -#endif -#ifdef FM2 - "$H/lib/$S/tail_m2", -#endif -#ifdef FPC - "$H/lib/$S/tail_pc", -#endif -#if defined(sun3) || defined(i386) - "$H/lib/$M/tail_fp", -#endif - "$H/lib/$M/tail_em", "$H/lib/$S/tail_mon", - "$H/lib/$M/end_em" } }; struct arglist align = { 5, @@ -189,6 +293,7 @@ static int v_flag = 0; static int O_flag = 0; /* Only ANSI C is now supported. */ static int ansi_c = 1; +static int cv_flag = 0; char *mkstr(char *, ...); static char *alloc(unsigned int); @@ -346,9 +451,10 @@ int lang_opt(char *str) char* stringdup(const char* s) { + char *p; if (s == NULL) return NULL; - char *p = alloc(strlen(s) + sizeof(char)); + p = alloc(strlen(s) + sizeof(char)); strcpy(p, s); return p; } @@ -368,20 +474,89 @@ char* getackhome(void) } +#define LIB_PREFIX "lib" +#define LIB_SUFFIX ".a" +/** From a library library directory list, + * search for the libraries that exist, and return + * the full path to the directory where the + * library is located. + * + * The search starts from the first added directory + * item at the command line. + * + * @param[in] dirs The directory list to search in. + * @param[in] lib The library name to search for. + * @returns The full path specification, allocated in the heap, it must + * be freed by the caller. + */ +char* search_library_path(struct stringlist *dirs, char* lib) +{ + char fname[FILENAME_MAX]; + FILE *fd; + int len; + int dirs_count; + int index = stringlist_count(dirs)-1; + + dirs_count = stringlist_count(dirs); + for (index = 0; index < dirs_count; index++) + { + strcpy(fname, stringlist_get(dirs,index)); + len = strlen(fname); + /* len-1 is the NULL character */ + if (fname[len-1] != '/') + { + /* Add trailing slash */ + fname[len] = '/'; + fname[len+1] = 0; + len++; + } + fname[len] = 0; + strcat(fname,lib); + fd = fopen(fname,"rb"); + if (fd!=NULL) + { + /* Return the path! */ + fclose(fd); + return stringdup(fname); + } + } + return NULL; +} int main(int argc, char *argv[]) { + /* Contains the directories being searched for libraries */ + struct stringlist library_dirs; + /* Contains the library lists */ + struct stringlist libraries; + /* Contains the directory paths. */ + struct smap paths; + /* Contains the src file list */ + struct stringlist srcfiles; char *str; + char *startup_file; char **argvec; int count; + int index; + int libs_count; char *ext; FILE* fd; register struct arglist *call = &CALL_VEC; + char tmpbuffer[256]; char *file; char *ldfile; char *INCLUDE = NULL; int compile_cnt = 0; + struct system_information* sys_info; + + startup_file = NULL; + sys_info = &machine_info[0]; + strcpy(tmpbuffer, LIB_PREFIX); + stringlist_init(&library_dirs); + stringlist_init(&libraries); + stringlist_init(&srcfiles); + smap_init(&paths); ackhome = stringdup(getackhome()); if (ackhome == NULL) @@ -402,17 +577,9 @@ int main(int argc, char *argv[]) COMP = expand_string(comp_name()); /* get c pre-processor to use */ CPP = expand_string(CPP_NAME); + /** get linker to use */ + LD = expand_string(sys_info->linker); -#ifdef vax4 - append(&CPP_FLAGS, "-D__vax"); -#endif -#ifdef sun3 - append(&CPP_FLAGS, "-D__sun"); -#endif -#ifdef m68020 - append(&CPP_FLAGS, "-D__mc68020"); - append(&CPP_FLAGS, "-D__mc68000"); -#endif if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, trapcc); @@ -422,7 +589,7 @@ int main(int argc, char *argv[]) { if (*(str = *argv++) != '-') { - append(&SRCFILES, str); + stringlist_add(&srcfiles,stringdup(str)); continue; } @@ -472,8 +639,11 @@ int main(int argc, char *argv[]) if (str[2] == 'n') noexec = 1; break; + case 'L': + stringlist_add(&library_dirs,stringdup(str+2)); + break; case 'l': /* library file */ - append(&SRCFILES, str); + stringlist_add(&srcfiles,stringdup(str)); break; case 'M': /* use other compiler (for testing) */ free(COMP); @@ -485,6 +655,10 @@ int main(int argc, char *argv[]) CPP = alloc(strlen(str)+2-1); strcpy(CPP, str + 2); break; + case 'X': /* use other linker (for testing) */ + LD = alloc(strlen(str)+2-1); + strcpy(LD, str + 2); + break; case 's': /* strip */ if (str[2] == '\0') { @@ -498,8 +672,48 @@ int main(int argc, char *argv[]) } } + /* Add C preprocessor flags. */ + for (count = 0; count < sys_info->cpp_flags.al_argc; count++) + { + append(&CPP_FLAGS, sys_info->cpp_flags.al_argv[count]); + } + /* Add compiler flags. */ + for (count = 0; count < sys_info->compiler_flags.al_argc; count++) + { + append(&COMP_FLAGS, sys_info->compiler_flags.al_argv[count]); + } + + /* Now for each srcfile, if it starts with -l then replace it with the correct real + * path immediately. + */ + count = stringlist_count(&srcfiles); + for (index = 0; index < count; index++) + { + str = stringlist_get(&srcfiles,index); + /* -l parameter */ + if (*str == '-') + { + /* Search for the directory where this library might be located. */ + strcpy(tmpbuffer,LIB_PREFIX); + strcat(tmpbuffer,str+2); + strcat(tmpbuffer,LIB_SUFFIX); + str = search_library_path(&library_dirs,tmpbuffer); + if (str != NULL) + { + stringlist_add(&srcfiles,str); + append(&SRCFILES,str); + } + } else + { + append(&SRCFILES,str); + } + } + + if (ecount) + { exit(EXIT_FAILURE); + } count = SRCFILES.al_argc; argvec = &(SRCFILES.al_argv[0]); @@ -526,12 +740,12 @@ int main(int argc, char *argv[]) /* INCLUDE = expand_string( ansi_c ? "-I$H/include/tail_ac" : "-I$H/include/_tail_cc"); */ INCLUDE = expand_string("-I$H/share/ack/include"); - append(&COMP_FLAGS, "-L"); +/* append(&COMP_FLAGS, "-L");*/ #endif /* FCC */ count = SRCFILES.al_argc; argvec = &(SRCFILES.al_argv[0]); - /* For each source file... */ + /* For argument file */ while (count-- > 0) { register char *f; @@ -539,7 +753,8 @@ int main(int argc, char *argv[]) ext = extension(file); - /* if not standard input and file is equal to the supported language suffix. */ + /* if not standard input and file is equal to the supported language suffix, + * then compile it */ if (file[0] != '-' && ext != file && (!strcmp(ext, lang_suffix()))) { if (compile_cnt > 1) @@ -617,7 +832,8 @@ int main(int argc, char *argv[]) } cleanup(tmp_file); tmp_file[0] = '\0'; - } + } /* endif compiling source file. */ + else if (file[0] != '-' && strcmp(ext, "o") && strcmp(ext, "a")) { @@ -632,24 +848,48 @@ int main(int argc, char *argv[]) append(&LDFILES, file); } + + /* See if we need to convert the flags. */ + cv_flag = sys_info->cv!=NULL; + /* *.s to a.out */ if (RET_CODE == 0 && LDFILES.al_argc > 0) { init(call); -// expand(&LD_HEAD); +/* expand(&LD_HEAD); // cc = "cc.2g"; -// expand(&LD_TAIL); - append(call, expand_string(LD_NAME)); -// concat(call, &align); + expand(&LD_TAIL);*/ + append(call, LD); +/* concat(call, &align);*/ + append(call, "-p"); + append(call, "-sx"); append(call, "-o"); - if (sys_tmpnam(tmp_file)==NULL) + if (cv_flag) { - panic("Cannot get temporary filename."); + if (sys_tmpnam(tmp_file)==NULL) + { + panic("Cannot get temporary filename."); + } + append(call, tmp_file); + } else + { + append(call, o_FILE); + } +/* concat(call, &LD_HEAD); + concat(call, &LD_FLAGS);*/ + + if (sys_info->startup!=NULL) + { + startup_file = search_library_path(&library_dirs,sys_info->startup); + if (startup_file!=NULL) + { + append(call,startup_file); + } else + { + panic("Cannot find startup file."); + } } - append(call, tmp_file); -// concat(call, &LD_HEAD); -// concat(call, &LD_FLAGS); concat(call, &LDFILES); /* if (g_flag) append(call, expand_string("$H/lib/$M/tail_db")); @@ -663,17 +903,35 @@ int main(int argc, char *argv[]) cleanup(tmp_file); exit(RET_CODE); } - /* init(call); - append(call, expand_string(CV_NAME)); - append(call, tmp_file); - append(call, o_FILE); - runvec(call, (char *) 0);*/ - cleanup(tmp_file); + + /* Check if we need to convert the file to + * a standard executable file for the specific + * target. + * + */ + if (cv_flag) + { + init(call); + append(call, expand_string(sys_info->cv)); + append(call, tmp_file); + append(call, o_FILE); + if (runvec(call, (char *) 0)==EXIT_FAILURE) + { + cleanup(tmp_file); + exit(RET_CODE); + } + cleanup(tmp_file); + } } if ((LDFILES.al_argc == 0) && (SRCFILES.al_argc==0)) { panic("No input source files or input object files specified."); } + stringlist_free(&library_dirs,1); + stringlist_free(&libraries,1); + if (startup_file!=NULL) + free(startup_file); + smap_free(&paths,1,1); exit(RET_CODE); } @@ -811,7 +1069,7 @@ char *mkstr(char *dst, ...) return dst; } -static char * extension(char *fn) +static char *extension(char *fn) { register char *c = fn; @@ -877,6 +1135,10 @@ static int runvec(struct arglist *vec, char *outp) append(vec,redirect); } p = arg2str(vec); + if ((v_flag) && (p != NULL)) + { + fprintf(stdout,"Executing : %s\n",p); + } status = system(p); free(p); From e5336264133339d999a0d449bf17d62fb9cca03a Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:06:36 +0800 Subject: [PATCH 50/84] - Remove rcsid tag. + ANSI C conversion. --- lang/basic/src/basic.lex | 268 +++++++++++++++++++-------------------- 1 file changed, 134 insertions(+), 134 deletions(-) diff --git a/lang/basic/src/basic.lex b/lang/basic/src/basic.lex index 11b3e2bf8..39d87e9ff 100644 --- a/lang/basic/src/basic.lex +++ b/lang/basic/src/basic.lex @@ -4,147 +4,147 @@ */ -#ifndef NORCSID -static char rcs_lex[] = "$Id$" ; -#endif + /* This file contains the new lexical analizer */ typedef struct { char *name; - int token, classvalue,length; + int token; + int classvalue; + int length; } Key; Key keywords [] ={ -"abs", FUNCTION, ABSSYM, 0, -"and", ANDSYM, ANDSYM, 0, -"asc", FUNCTION, ASCSYM, 0, -"as", ASSYM, 0, 0, -"atn", FUNCTION, ATNSYM, 0, -"auto", ILLEGAL, 0, 0, -"base", BASESYM, 0, 0, -"call", CALLSYM, 0, 0, -"cdbl", FUNCTION, CDBLSYM, 0, -"chain", ILLEGAL, 0, 0, -"chr", FUNCTION, CHRSYM, 0, -"cint", FUNCTION, CINTSYM, 0, -"clear", CLEARSYM, 0, 0, -"cload", ILLEGAL, 0, 0, -"close", CLOSESYM, 0, 0, -"common", ILLEGAL, 0, 0, -"cont", ILLEGAL, 0, 0, -"cos", FUNCTION, COSSYM, 0, -"csng", FUNCTION, CSNGSYM, 0, -"csave", ILLEGAL, 0, 0, -"cvi", FUNCTION, CVISYM, 0, -"cvs", FUNCTION, CVSSYM, 0, -"cvd", FUNCTION, CVDSYM, 0, -"data", DATASYM, 0, 0, -"defint", DEFINTSYM, 0, 0, -"defsng", DEFSNGSYM, 0, 0, -"defdbl", DEFDBLSYM, 0, 0, -"defstr", DEFSTRSYM, 0, 0, -"def", DEFSYM, 0, 0, -"delete", ILLEGAL, 0, 0, -"dim", DIMSYM, 0, 0, -"edit", ILLEGAL, 0, 0, -"else", ELSESYM, 0, 0, -"end", ENDSYM, 0, 0, -"eof", FUNCTION, EOFSYM, 0, -"eqv", EQVSYM, EQVSYM, 0, -"erase", ILLEGAL, 0, 0, -"error", ERRORSYM, 0, 0, -"err", ERRSYM, 0, 0, -"erl", ERLSYM, 0, 0, -"exp", FUNCTION, EXPSYM, 0, -"field", FIELDSYM, 0, 0, -"fix", FUNCTION, FIXSYM, 0, -"for", FORSYM, 0, 0, -"fre", FUNCTION, FRESYM, 0, -"get", GETSYM, 0, 0, -"gosub", GOSUBSYM, 0, 0, -"goto", GOTOSYM, 0, 0, -"hex", FUNCTION, HEXSYM, 0, -"if", IFSYM, 0, 0, -"imp", IMPSYM, IMPSYM, 0, -"inkey", INKEYSYM, 0, 0, -"input", INPUTSYM, 0, 0, -"inp", FUNCTION, INPSYM, 0, -"instr", FUNCTION, INSTRSYM, 0, -"int", FUNCTION, INTSYM, 0, -"kill", ILLEGAL, 0, 0, -"left", FUNCTION, LEFTSYM, 0, -"len", FUNCTION, LENSYM, 0, -"let", LETSYM, 0, 0, -"line", LINESYM, 0, 0, -"list", LISTSYM, 0, 0, -"llist", ILLEGAL, 0, 0, -"load", LOADSYM, 0, 0, -"loc", FUNCTION, LOCSYM, 0, -"log", FUNCTION, LOGSYM, 0, -"lpos", FUNCTION, LPOSSYM, 0, -"lprint", ILLEGAL, 0, 0, -"lset", LSETSYM, 0, 0, -"merge", MERGESYM, 0, 0, -"mid", MIDSYM, 0, 0, -"mki", FUNCTION, MKISYM, 0, -"mks", FUNCTION, MKSSYM, 0, -"mkd", FUNCTION, MKDSYM, 0, -"mod", MODSYM, 0, 0, -"name", ILLEGAL, 0, 0, -"new", ILLEGAL, 0, 0, -"next", NEXTSYM, 0, 0, -"not", NOTSYM, 0, 0, -"null", ILLEGAL, 0, 0, -"on", ONSYM, 0, 0, -"oct", FUNCTION, OCTSYM, 0, -"open", OPENSYM, 0, 0, -"option", OPTIONSYM, 0, 0, -"or", ORSYM, ORSYM, 0, -"out", FUNCTION, OUTSYM, 0, -"peek", PEEKSYM, 0, 0, -"poke", POKESYM, 0, 0, -"print", PRINTSYM, 0, 0, -"pos", FUNCTION, POSSYM, 0, -"put", PUTSYM, 0, 0, -"randomize", RANDOMIZESYM, 0, 0, -"read", READSYM, 0, 0, -"rem", REMSYM, 0, 0, -"renum", ILLEGAL, 0, 0, -"ren", ILLEGAL, 0, 0, -"restore", RESTORESYM, 0, 0, -"resume", ILLEGAL, 0, 0, -"return", RETURNSYM, 0, 0, -"right", FUNCTION, RIGHTSYM, 0, -"rnd", FUNCTION, RNDSYM, 0, -"run", ILLEGAL, 0, 0, -"save", ILLEGAL, 0, 0, -"step", STEPSYM, 0, 0, -"sgn", FUNCTION, SGNSYM, 0, -"sin", FUNCTION, SINSYM, 0, -"space", FUNCTION, SPACESYM, 0, -"spc", FUNCTION, SPCSYM, 0, -"sqr", FUNCTION, SQRSYM, 0, -"stop", STOPSYM, 0, 0, -"string", FUNCTION, STRINGSYM, 0, -"str", FUNCTION, STRSYM, 0, -"swap", SWAPSYM, 0, 0, -"tab", FUNCTION, TABSYM, 0, -"tan", FUNCTION, TANSYM, 0, -"then", THENSYM, 0, 0, -"to", TOSYM, 0, 0, -"tron", TRONOFFSYM, TRONSYM, 0, -"troff", TRONOFFSYM, TROFFSYM, 0, -"using", USINGSYM, 0, 0, -"usr", FUNCTION, USRSYM, 0, -"val", FUNCTION, VALSYM, 0, -"varptr", FUNCTION, VARPTRSYM, 0, -"wait", ILLEGAL, 0, 0, -"while", WHILESYM, 0, 0, -"wend", WENDSYM, 0, 0, -"width", ILLEGAL, 0, 0, -"write", WRITESYM, 0, 0, -"xor", XORSYM, XORSYM, 0, -0, 0, 0, 0 +{"abs", FUNCTION, ABSSYM, 0}, +{"and", ANDSYM, ANDSYM, 0}, +{"asc", FUNCTION, ASCSYM, 0}, +{"as", ASSYM, 0, 0}, +{"atn", FUNCTION, ATNSYM, 0}, +{"auto", ILLEGAL, 0, 0}, +{"base", BASESYM, 0, 0}, +{"call", CALLSYM, 0, 0}, +{"cdbl", FUNCTION, CDBLSYM, 0}, +{"chain", ILLEGAL, 0, 0}, +{"chr", FUNCTION, CHRSYM, 0}, +{"cint", FUNCTION, CINTSYM, 0}, +{"clear", CLEARSYM, 0, 0}, +{"cload", ILLEGAL, 0, 0}, +{"close", CLOSESYM, 0, 0}, +{"common", ILLEGAL, 0, 0}, +{"cont", ILLEGAL, 0, 0}, +{"cos", FUNCTION, COSSYM, 0}, +{"csng", FUNCTION, CSNGSYM, 0}, +{"csave", ILLEGAL, 0, 0}, +{"cvi", FUNCTION, CVISYM, 0}, +{"cvs", FUNCTION, CVSSYM, 0}, +{"cvd", FUNCTION, CVDSYM, 0}, +{"data", DATASYM, 0, 0}, +{"defint", DEFINTSYM, 0, 0}, +{"defsng", DEFSNGSYM, 0, 0}, +{"defdbl", DEFDBLSYM, 0, 0}, +{"defstr", DEFSTRSYM, 0, 0}, +{"def", DEFSYM, 0, 0}, +{"delete", ILLEGAL, 0, 0}, +{"dim", DIMSYM, 0, 0}, +{"edit", ILLEGAL, 0, 0}, +{"else", ELSESYM, 0, 0}, +{"end", ENDSYM, 0, 0}, +{"eof", FUNCTION, EOFSYM, 0}, +{"eqv", EQVSYM, EQVSYM, 0}, +{"erase", ILLEGAL, 0, 0}, +{"error", ERRORSYM, 0, 0}, +{"err", ERRSYM, 0, 0}, +{"erl", ERLSYM, 0, 0}, +{"exp", FUNCTION, EXPSYM, 0}, +{"field", FIELDSYM, 0, 0}, +{"fix", FUNCTION, FIXSYM, 0}, +{"for", FORSYM, 0, 0}, +{"fre", FUNCTION, FRESYM, 0}, +{"get", GETSYM, 0, 0}, +{"gosub", GOSUBSYM, 0, 0}, +{"goto", GOTOSYM, 0, 0}, +{"hex", FUNCTION, HEXSYM, 0}, +{"if", IFSYM, 0, 0}, +{"imp", IMPSYM, IMPSYM, 0}, +{"inkey", INKEYSYM, 0, 0}, +{"input", INPUTSYM, 0, 0}, +{"inp", FUNCTION, INPSYM, 0}, +{"instr", FUNCTION, INSTRSYM, 0}, +{"int", FUNCTION, INTSYM, 0}, +{"kill", ILLEGAL, 0, 0}, +{"left", FUNCTION, LEFTSYM, 0}, +{"len", FUNCTION, LENSYM, 0}, +{"let", LETSYM, 0, 0}, +{"line", LINESYM, 0, 0}, +{"list", LISTSYM, 0, 0}, +{"llist", ILLEGAL, 0, 0}, +{"load", LOADSYM, 0, 0}, +{"loc", FUNCTION, LOCSYM, 0}, +{"log", FUNCTION, LOGSYM, 0}, +{"lpos", FUNCTION, LPOSSYM, 0}, +{"lprint", ILLEGAL, 0, 0}, +{"lset", LSETSYM, 0, 0}, +{"merge", MERGESYM, 0, 0}, +{"mid", MIDSYM, 0, 0}, +{"mki", FUNCTION, MKISYM, 0}, +{"mks", FUNCTION, MKSSYM, 0}, +{"mkd", FUNCTION, MKDSYM, 0}, +{"mod", MODSYM, 0, 0}, +{"name", ILLEGAL, 0, 0}, +{"new", ILLEGAL, 0, 0}, +{"next", NEXTSYM, 0, 0}, +{"not", NOTSYM, 0, 0}, +{"null", ILLEGAL, 0, 0}, +{"on", ONSYM, 0, 0}, +{"oct", FUNCTION, OCTSYM, 0}, +{"open", OPENSYM, 0, 0}, +{"option", OPTIONSYM, 0, 0}, +{"or", ORSYM, ORSYM, 0}, +{"out", FUNCTION, OUTSYM, 0}, +{"peek", PEEKSYM, 0, 0}, +{"poke", POKESYM, 0, 0}, +{"print", PRINTSYM, 0, 0}, +{"pos", FUNCTION, POSSYM, 0}, +{"put", PUTSYM, 0, 0}, +{"randomize", RANDOMIZESYM, 0, 0}, +{"read", READSYM, 0, 0}, +{"rem", REMSYM, 0, 0}, +{"renum", ILLEGAL, 0, 0}, +{"ren", ILLEGAL, 0, 0}, +{"restore", RESTORESYM, 0, 0}, +{"resume", ILLEGAL, 0, 0}, +{"return", RETURNSYM, 0, 0}, +{"right", FUNCTION, RIGHTSYM, 0}, +{"rnd", FUNCTION, RNDSYM, 0}, +{"run", ILLEGAL, 0, 0}, +{"save", ILLEGAL, 0, 0}, +{"step", STEPSYM, 0, 0}, +{"sgn", FUNCTION, SGNSYM, 0}, +{"sin", FUNCTION, SINSYM, 0}, +{"space", FUNCTION, SPACESYM, 0}, +{"spc", FUNCTION, SPCSYM, 0}, +{"sqr", FUNCTION, SQRSYM, 0}, +{"stop", STOPSYM, 0, 0}, +{"string", FUNCTION, STRINGSYM, 0}, +{"str", FUNCTION, STRSYM, 0}, +{"swap", SWAPSYM, 0, 0}, +{"tab", FUNCTION, TABSYM, 0}, +{"tan", FUNCTION, TANSYM, 0}, +{"then", THENSYM, 0, 0}, +{"to", TOSYM, 0, 0}, +{"tron", TRONOFFSYM, TRONSYM, 0}, +{"troff", TRONOFFSYM, TROFFSYM, 0}, +{"using", USINGSYM, 0, 0}, +{"usr", FUNCTION, USRSYM, 0}, +{"val", FUNCTION, VALSYM, 0}, +{"varptr", FUNCTION, VARPTRSYM, 0}, +{"wait", ILLEGAL, 0, 0}, +{"while", WHILESYM, 0, 0}, +{"wend", WENDSYM, 0, 0}, +{"width", ILLEGAL, 0, 0}, +{"write", WRITESYM, 0, 0}, +{"xor", XORSYM, XORSYM, 0}, +{0, 0, 0, 0} }; /* Keyword index table */ From e2d2c11a6e1fac983e1b9b471945c248ca33a553 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:07:00 +0800 Subject: [PATCH 51/84] Fix some compiler warnings. --- lang/basic/src/symbols.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lang/basic/src/symbols.c b/lang/basic/src/symbols.c index 2551ece45..08017cc57 100644 --- a/lang/basic/src/symbols.c +++ b/lang/basic/src/symbols.c @@ -13,11 +13,6 @@ #include "util.h" - -#ifndef NORCSID -static char rcs_id[] = "$Id$" ; -#endif - /* Symboltable management module */ int deftype[128]; /* default type declarer */ @@ -32,8 +27,8 @@ void initdeftype(void) { int i; - for(i='a';i<='z';i++) deftype[i]= DOUBLETYPE; - for(i='A';i<='Z';i++) deftype[i]= DOUBLETYPE; + for(i='a';i<='z';i++) deftype[(unsigned char)i]= DOUBLETYPE; + for(i='A';i<='Z';i++) deftype[(unsigned char)i]= DOUBLETYPE; } @@ -223,9 +218,9 @@ void setdefaulttype(int type) last= *cptr; if ( !isalpha(last)) error("letter expected"); - else for(i=first;i<=last;i++) deftype[i]= type; + else for(i=first;i<=last;i++) deftype[(unsigned char)i]= type; cptr++; - } else deftype[first]=type; + } else deftype[(unsigned char)first]=type; if ( *cptr== ',') { cptr++; From 72dcbea3c69c27b52706941d80533b473fbbae7c Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:07:33 +0800 Subject: [PATCH 52/84] Add missing C compiler command line option. --- lang/cem/cemcom.ansi/cemcom.ansi.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom.ansi/cemcom.ansi.1 b/lang/cem/cemcom.ansi/cemcom.ansi.1 index 918ad950a..3ca5de847 100644 --- a/lang/cem/cemcom.ansi/cemcom.ansi.1 +++ b/lang/cem/cemcom.ansi/cemcom.ansi.1 @@ -70,7 +70,7 @@ get rid of the compiler-predefined macro \fIname\fR. .br set the size and alignment requirements. The letter \fIc\fR indicates the simple type, which is one of -\fBs\fR(short), \fBi\fR(int), \fBl\fR(long), \fBf\fR(float), \fBd\fR(double), +\fBs\fR(short), \fBw\fR(word), \fBi\fR(int), \fBl\fR(long), \fBf\fR(float), \fBd\fR(double), \fBx\fR(long double) or \fBp\fR(pointer). The \fIm\fR parameter can be used to specify the length of the type (in bytes) From e8243402be3a58e50d234bb3371368f7e3d3218d Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:09:03 +0800 Subject: [PATCH 53/84] Move to use C structures instead of typedef to align with other ACK compilers and to avoid forward declaration issues with include files. --- lang/m2/comp/LLlex.c | 4 +- lang/m2/comp/casestat.xc | 10 +-- lang/m2/comp/chk_expr.c | 170 +++++++++++++++++++------------------- lang/m2/comp/chk_expr.h | 12 +-- lang/m2/comp/code.c | 96 ++++++++++----------- lang/m2/comp/code.h | 25 +++--- lang/m2/comp/cstoper.c | 46 +++++------ lang/m2/comp/cstoper.h | 12 +-- lang/m2/comp/declar.g | 122 +++++++++++++-------------- lang/m2/comp/def.c | 40 ++++----- lang/m2/comp/def.xh | 26 +++--- lang/m2/comp/defmodule.c | 16 ++-- lang/m2/comp/desig.c | 40 ++++----- lang/m2/comp/desig.h | 25 +++--- lang/m2/comp/enter.c | 90 ++++++++++---------- lang/m2/comp/enter.h | 30 +++---- lang/m2/comp/error.c | 12 +-- lang/m2/comp/error.h | 6 +- lang/m2/comp/expression.g | 46 +++++------ lang/m2/comp/idf.h | 2 +- lang/m2/comp/lookup.c | 12 +-- lang/m2/comp/lookup.h | 14 ++-- lang/m2/comp/main.c | 10 +-- lang/m2/comp/misc.c | 6 +- lang/m2/comp/misc.h | 10 +-- lang/m2/comp/node.c | 22 ++--- lang/m2/comp/node.xh | 26 +++--- lang/m2/comp/program.g | 30 +++---- lang/m2/comp/scope.h | 17 ++-- lang/m2/comp/scope.xc | 36 ++++---- lang/m2/comp/stab.c | 12 +-- lang/m2/comp/stab.h | 8 +- lang/m2/comp/statement.g | 50 +++++------ lang/m2/comp/tmpvar.h | 4 +- lang/m2/comp/tmpvar.xc | 6 +- lang/m2/comp/tokenname.c | 2 +- lang/m2/comp/type.c | 86 +++++++++---------- lang/m2/comp/type.xh | 52 ++++++------ lang/m2/comp/typequiv.c | 26 +++--- lang/m2/comp/typequiv.h | 21 ++--- lang/m2/comp/walk.c | 112 ++++++++++++------------- lang/m2/comp/walk.h | 28 +++---- 42 files changed, 713 insertions(+), 707 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 7c543159d..153c5d181 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -36,7 +36,7 @@ extern char *getwdir(); t_token dot, aside; -t_type *toktype; +struct type *toktype; int idfsize = IDFSIZE; int ForeignFlag; #ifdef DEBUG @@ -347,7 +347,7 @@ again: case STIDF: { register char *tag = &buf[0]; - register t_idf *id; + register struct idf *id; do { if (tag - buf < idfsize) *tag++ = ch; diff --git a/lang/m2/comp/casestat.xc b/lang/m2/comp/casestat.xc index b0c7d5a56..345f88b06 100644 --- a/lang/m2/comp/casestat.xc +++ b/lang/m2/comp/casestat.xc @@ -42,7 +42,7 @@ struct switch_hdr { label sh_break; /* label of statement after this one */ label sh_default; /* label of ELSE part, or 0 */ int sh_nrofentries; /* number of cases */ - t_type *sh_type; /* type of case expression */ + struct type *sh_type; /* type of case expression */ arith sh_lowerbd; /* lowest case label */ arith sh_upperbd; /* highest case label */ struct case_entry *sh_entries; /* the cases with their generated @@ -84,7 +84,7 @@ static int compact(int nr, arith low, arith up) } #define nd_lab nd_symb -static void AddOneCase(struct switch_hdr *sh, t_node *lnode, t_node *rnode, label lbl) +static void AddOneCase(struct switch_hdr *sh, struct node *lnode, struct node *rnode, label lbl) { register struct case_entry *ce = new_case_entry(); register struct case_entry *c1 = sh->sh_entries, *c2 = 0; @@ -201,7 +201,7 @@ node_error(rnode, "multiple case entry for value %ld", (long)(ce->ce_up)); } -static void AddCases(struct switch_hdr *sh, register t_node *node, label lbl) +static void AddCases(struct switch_hdr *sh, register struct node *node, label lbl) { /* Add case labels to the case label list */ @@ -243,7 +243,7 @@ static void FreeSh(struct switch_hdr *sh) free_switch_hdr(sh); } -int CaseCode(t_node *nd, label exitlabel, int end_reached) +int CaseCode(struct node *nd, label exitlabel, int end_reached) { /* Check the expression, stack a new case header and fill in the necessary fields. @@ -251,7 +251,7 @@ int CaseCode(t_node *nd, label exitlabel, int end_reached) LOOP-statement, or 0. */ register struct switch_hdr *sh = new_switch_hdr(); - register t_node *pnode = nd; + register struct node *pnode = nd; register struct case_entry *ce; register arith val; label CaseDescrLab; diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 6825ac51b..64c76d40d 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -26,8 +26,8 @@ #include "Lpars.h" #include "idf.h" -#include "type.h" #include "LLlex.h" +#include "type.h" #include "def.h" #include "node.h" #include "scope.h" @@ -45,16 +45,16 @@ extern char *symbol2str(); /* Forward file declarations */ -static int ChkStandard(t_node **); -static int ChkCast(t_node **); +static int ChkStandard(struct node **); +static int ChkCast(struct node **); static void df_error( - t_node *nd, /* node on which error occurred */ + struct node *nd, /* node on which error occurred */ char *mess, /* error message */ - register t_def *edf) /* do we have a name? */ + register struct def *edf) /* do we have a name? */ { if (edf) { if (edf->df_kind != D_ERROR) { @@ -64,7 +64,7 @@ static void df_error( else node_error(nd, mess); } -void MkCoercion(t_node **pnd, register t_type *tp) +void MkCoercion(struct node **pnd, register struct type *tp) { /* Make a coercion from the node indicated by *pnd to the type indicated by tp. If the node indicated by *pnd @@ -74,8 +74,8 @@ void MkCoercion(t_node **pnd, register t_type *tp) - we are in the second pass and the coercion might cause an error */ - register t_node *nd = *pnd; - register t_type *nd_tp = nd->nd_type; + register struct node *nd = *pnd; + register struct type *nd_tp = nd->nd_type; extern int pass_1; char *wmess = 0; arith op; @@ -170,12 +170,12 @@ void MkCoercion(t_node **pnd, register t_type *tp) *pnd = nd; } -int ChkVariable(register t_node **expp, int flags) +int ChkVariable(register struct node **expp, int flags) { /* Check that "expp" indicates an item that can be assigned to. */ - register t_node *exp; + register struct node *exp; if (! ChkDesig(expp, flags)) return 0; @@ -188,13 +188,13 @@ int ChkVariable(register t_node **expp, int flags) return 1; } -static int ChkArrow(t_node **expp, int flags) +static int ChkArrow(struct node **expp, int flags) { /* Check an application of the '^' operator. The operand must be a variable of a pointer type. */ - register t_type *tp; - register t_node *exp = *expp; + register struct type *tp; + register struct node *exp = *expp; assert(exp->nd_class == Arrow); assert(exp->nd_symb == '^'); @@ -215,7 +215,7 @@ static int ChkArrow(t_node **expp, int flags) return 1; } -static int ChkArr(t_node **expp, int flags) +static int ChkArr(struct node **expp, int flags) { /* Check an array selection. The left hand side must be a variable of an array type, @@ -223,8 +223,8 @@ static int ChkArr(t_node **expp, int flags) assignment compatible with the array-index. */ - register t_type *tpl; - register t_node *exp = *expp; + register struct type *tpl; + register struct node *exp = *expp; assert(exp->nd_class == Arrsel); assert(exp->nd_symb == '[' || exp->nd_symb == ','); @@ -257,7 +257,7 @@ static int ChkArr(t_node **expp, int flags) } /*ARGSUSED*/ -static int ChkValue(t_node **expp, int flags) +static int ChkValue(struct node **expp, int flags) { #ifdef DEBUG switch((*expp)->nd_symb) { @@ -273,13 +273,13 @@ static int ChkValue(t_node **expp, int flags) return 1; } -static int ChkSelOrName(t_node **expp, int flags) +static int ChkSelOrName(struct node **expp, int flags) { /* Check either an ID or a construction of the form ID.ID [ .ID ]* */ - register t_def *df; - register t_node *exp = *expp; + register struct def *df; + register struct node *exp = *expp; exp->nd_type = error_type; @@ -296,7 +296,7 @@ static int ChkSelOrName(t_node **expp, int flags) /* A selection from a record or a module. Modules also have a record type. */ - register t_node *left; + register struct node *left; assert(exp->nd_symb == '.'); @@ -346,13 +346,13 @@ static int ChkSelOrName(t_node **expp, int flags) return exp->nd_def->df_kind != D_ERROR; } -static int ChkExSelOrName(t_node **expp, int flags) +static int ChkExSelOrName(struct node **expp, int flags) { /* Check either an ID or an ID.ID [.ID]* occurring in an expression. */ - register t_def *df; - register t_node *exp; + register struct def *df; + register struct node *exp; if (! ChkSelOrName(expp, D_USED)) return 0; @@ -418,20 +418,20 @@ static int ChkExSelOrName(t_node **expp, int flags) return 1; } -static int ChkEl(register t_node **expp, t_type *tp) +static int ChkEl(register struct node **expp, struct type *tp) { return ChkExpression(expp) && ChkCompat(expp, tp, "set element"); } -static int ChkElement(t_node **expp, t_type *tp, arith *set) +static int ChkElement(struct node **expp, struct type *tp, arith *set) { /* Check elements of a set. This routine may call itself recursively. Also try to compute the set! */ - register t_node *expr = *expp; - t_type *el_type = ElementType(tp); + register struct node *expr = *expp; + struct type *el_type = ElementType(tp); register unsigned int i; arith low, high; @@ -504,15 +504,15 @@ void FreeSet(register arith *s) } } -static int ChkSet(t_node **expp, int flags) +static int ChkSet(struct node **expp, int flags) { /* Check the legality of a SET aggregate, and try to evaluate it compile time. Unfortunately this is all rather complicated. */ - register t_type *tp; - register t_node *exp = *expp; - register t_node *nd; - register t_def *df; + register struct type *tp; + register struct node *exp = *expp; + register struct node *nd; + register struct def *df; int retval = 1; int SetIsConstant = 1; @@ -570,9 +570,9 @@ static int ChkSet(t_node **expp, int flags) return retval; } -static t_node *nextarg(t_node **argp, t_def *edf) +static struct node *nextarg(struct node **argp, struct def *edf) { - register t_node *arg = (*argp)->nd_RIGHT; + register struct node *arg = (*argp)->nd_RIGHT; if (! arg) { df_error(*argp, "too few arguments supplied", edf); @@ -583,7 +583,7 @@ static t_node *nextarg(t_node **argp, t_def *edf) return arg; } -static t_node *getarg(t_node **argp, int bases, int designator, t_def *edf) +static struct node *getarg(struct node **argp, int bases, int designator, struct def *edf) { /* This routine is used to fetch the next argument from an argument list. The argument list is indicated by "argp". @@ -593,8 +593,8 @@ static t_node *getarg(t_node **argp, int bases, int designator, t_def *edf) that it must be a designator and may not be a register variable. */ - register t_node *arg = nextarg(argp, edf); - register t_node *left; + register struct node *arg = nextarg(argp, edf); + register struct node *left; if (! arg || ! arg->nd_LEFT || @@ -608,7 +608,7 @@ static t_node *getarg(t_node **argp, int bases, int designator, t_def *edf) } if (bases) { - t_type *tp = BaseType(left->nd_type); + struct type *tp = BaseType(left->nd_type); if (! designator) MkCoercion(&(arg->nd_LEFT), tp); left = arg->nd_LEFT; @@ -621,14 +621,14 @@ static t_node *getarg(t_node **argp, int bases, int designator, t_def *edf) return left; } -static t_node *getname(t_node **argp, int kinds, int bases, t_def *edf) +static struct node *getname(struct node **argp, int kinds, int bases, struct def *edf) { /* Get the next argument from argument list "argp". The argument must indicate a definition, and the definition kind must be one of "kinds". */ - register t_node *arg = nextarg(argp, edf); - register t_node *left; + register struct node *arg = nextarg(argp, edf); + register struct node *left; if (!arg || !arg->nd_LEFT || ! ChkDesig(&(arg->nd_LEFT), D_USED)) return 0; @@ -647,14 +647,14 @@ static t_node *getname(t_node **argp, int kinds, int bases, t_def *edf) return left; } -static int ChkProcCall(register t_node *exp) +static int ChkProcCall(register struct node *exp) { /* Check a procedure call */ - register t_node *left; - t_node *argp; - t_def *edf = 0; - register t_param *param; + register struct node *left; + struct node *argp; + struct def *edf = 0; + register struct paramlist *param; int retval = 1; int cnt = 0; @@ -708,7 +708,7 @@ static int ChkProcCall(register t_node *exp) return retval; } -static int ChkFunCall(register t_node **expp, int flags) +static int ChkFunCall(register struct node **expp, int flags) { /* Check a call that must have a result */ @@ -723,7 +723,7 @@ static int ChkFunCall(register t_node **expp, int flags) -int ChkCall(t_node **expp) +int ChkCall(struct node **expp) { /* Check something that looks like a procedure or function call. Of course this does not have to be a call at all, @@ -733,7 +733,7 @@ int ChkCall(t_node **expp) /* First, get the name of the function or procedure */ if (ChkDesig(&((*expp)->nd_LEFT), D_USED)) { - register t_node *left = (*expp)->nd_LEFT; + register struct node *left = (*expp)->nd_LEFT; if (IsCast(left)) { /* It was a type cast. @@ -763,7 +763,7 @@ int ChkCall(t_node **expp) return ChkProcCall(*expp); } -static t_type *ResultOfOperation(int operator, t_type *tp) +static struct type *ResultOfOperation(int operator, struct type *tp) { /* Return the result type of the binary operation "operator", with operand type "tp". @@ -820,9 +820,9 @@ static int AllowedTypes(int operator) } static int ChkAddressOper( - register t_type *tpl, - register t_type *tpr, - register t_node *expp) + register struct type *tpl, + register struct type *tpr, + register struct node *expp) { /* Check that either "tpl" or "tpr" are both of type address_type, or that one of them is, but the other is @@ -833,8 +833,8 @@ static int ChkAddressOper( if (tpr == address_type && expp->nd_symb == '+') { /* use the fact that '+' is a commutative operator */ - t_type *tmptype = tpr; - t_node *tmpnode = expp->nd_RIGHT; + struct type *tmptype = tpr; + struct node *tmpnode = expp->nd_RIGHT; tpr = tpl; expp->nd_RIGHT = expp->nd_LEFT; @@ -866,13 +866,13 @@ static int ChkAddressOper( return 0; } -static int ChkBinOper(t_node **expp, int flags) +static int ChkBinOper(struct node **expp, int flags) { /* Check a binary operation. */ - register t_node *exp = *expp; - register t_type *tpl, *tpr; - t_type *result_type; + register struct node *exp = *expp; + register struct type *tpl, *tpr; + struct type *result_type; int allowed; int retval; char *symb; @@ -981,13 +981,13 @@ static int ChkBinOper(t_node **expp, int flags) return 1; } -static int ChkUnOper(t_node **expp, int flags) +static int ChkUnOper(struct node **expp, int flags) { /* Check an unary operation. */ - register t_node *exp = *expp; - register t_node *right = exp->nd_RIGHT; - register t_type *tpr; + register struct node *exp = *expp; + register struct node *right = exp->nd_RIGHT; + register struct type *tpr; if (exp->nd_symb == COERCION) return 1; if (exp->nd_symb == '(') { @@ -1054,12 +1054,12 @@ static int ChkUnOper(t_node **expp, int flags) return 0; } -static t_node *getvariable(t_node **argp, t_def *edf, int flags) +static struct node *getvariable(struct node **argp, struct def *edf, int flags) { /* Get the next argument from argument list "argp". It must obey the rules of "ChkVariable". */ - register t_node *arg = nextarg(argp, edf); + register struct node *arg = nextarg(argp, edf); if (! arg || ! arg->nd_LEFT || @@ -1068,14 +1068,14 @@ static t_node *getvariable(t_node **argp, t_def *edf, int flags) return arg->nd_LEFT; } -static int ChkStandard(t_node **expp) +static int ChkStandard(struct node **expp) { /* Check a call of a standard procedure or function */ - register t_node *exp = *expp; - t_node *arglink = exp; - register t_node *arg; - register t_def *edf = exp->nd_LEFT->nd_def; + register struct node *exp = *expp; + struct node *arglink = exp; + register struct node *arg; + register struct def *edf = exp->nd_LEFT->nd_def; int free_it = 0; int isconstant = 0; @@ -1126,8 +1126,8 @@ static int ChkStandard(t_node **expp) case S_SHORT: case S_LONG: { - t_type *tp; - t_type *s1, *s2, *s3, *d1, *d2, *d3; + struct type *tp; + struct type *s1, *s2, *s3, *d1, *d2, *d3; if (!(arg = getarg(&arglink, 0, 0, edf))) { return 0; @@ -1349,8 +1349,8 @@ static int ChkStandard(t_node **expp) case S_EXCL: case S_INCL: { - register t_type *tp; - t_node *dummy; + register struct type *tp; + struct node *dummy; exp->nd_type = 0; if (!(arg = getvariable(&arglink, edf, D_USED|D_DEFINED))) return 0; @@ -1398,7 +1398,7 @@ static int ChkStandard(t_node **expp) return 1; } -static int ChkCast(t_node **expp) +static int ChkCast(struct node **expp) { /* Check a cast and perform it if the argument is constant. If the sizes don't match, only complain if at least one of them @@ -1407,10 +1407,10 @@ static int ChkCast(t_node **expp) is no problem as such values take a word on the EM stack anyway. */ - register t_node *exp = *expp; - register t_node *arg = exp->nd_RIGHT; - register t_type *lefttype = exp->nd_LEFT->nd_type; - t_def *df = exp->nd_LEFT->nd_def; + register struct node *exp = *expp; + register struct node *arg = exp->nd_RIGHT; + register struct type *lefttype = exp->nd_LEFT->nd_type; + struct def *df = exp->nd_LEFT->nd_def; if ((! arg) || arg->nd_RIGHT) { df_error(exp, "type cast must have 1 parameter", df); @@ -1461,7 +1461,7 @@ static int ChkCast(t_node **expp) return 1; } -void TryToString(register t_node *nd, t_type *tp) +void TryToString(register struct node *nd, struct type *tp) { /* Try a coercion from character constant to string. */ @@ -1479,20 +1479,20 @@ void TryToString(register t_node *nd, t_type *tp) } } -static int no_desig(t_node **expp, int flags) +static int no_desig(struct node **expp, int flags) { node_error(*expp, "designator expected"); return 0; } -static int add_flags(t_node **expp, int flags) +static int add_flags(struct node **expp, int flags) { (*expp)->nd_def->df_flags |= flags; return 1; } -int (*ExprChkTable[])(t_node **, int) = { +int (*ExprChkTable[])(struct node **, int) = { ChkValue, ChkArr, ChkBinOper, @@ -1508,7 +1508,7 @@ int (*ExprChkTable[])(t_node **, int) = { PNodeCrash, }; -int (*DesigChkTable[])(t_node **, int) = { +int (*DesigChkTable[])(struct node **, int) = { no_desig, ChkArr, no_desig, diff --git a/lang/m2/comp/chk_expr.h b/lang/m2/comp/chk_expr.h index 0a162e0ec..1e5406d55 100644 --- a/lang/m2/comp/chk_expr.h +++ b/lang/m2/comp/chk_expr.h @@ -11,10 +11,10 @@ /* $Id$ */ -extern int (*ExprChkTable[])(t_node **, int); /* table of expression checking +extern int (*ExprChkTable[])(struct node **, int); /* table of expression checking functions, indexed by node class */ -extern int (*DesigChkTable[])(t_node **, int); /* table of designator checking +extern int (*DesigChkTable[])(struct node **, int); /* table of designator checking functions, indexed by node class */ @@ -26,10 +26,10 @@ extern int (*DesigChkTable[])(t_node **, int); /* table of designator checking #define dec_refcount(s) (*((int *)(s) - 1) -= 1) #define refcount(s) (*((int *)(s) - 1)) -void MkCoercion(t_node **pnd, register t_type *tp); -int ChkVariable(register t_node **expp, int flags); -int ChkCall(t_node **expp); -void TryToString(register t_node *nd, t_type *tp); +void MkCoercion(struct node **pnd, register struct type *tp); +int ChkVariable(register struct node **expp, int flags); +int ChkCall(struct node **expp); +void TryToString(register struct node *nd, struct type *tp); /* Generates a set of "size" bytes and increments its reference count. */ arith *MkSet(unsigned int size); diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 6367f20d9..eaa9da48b 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -38,19 +38,19 @@ extern int proclevel; extern char options[]; -extern t_desig null_desig; +extern struct desig null_desig; int fp_used; /* Forward declarations */ -static void CodeParameters(t_param *, register t_node *); -static void CodeStd(t_node *); +static void CodeParameters(struct paramlist *, register struct node *); +static void CodeStd(struct node *); static void compare(int, label); static void truthvalue(int); -static void CodeUoper(register t_node *); -static void CodeSet(register t_node *, int); -static void CodeEl(register t_node *, register t_type *, int); -static void CodeDAddress(t_node *, int); -static void DoHIGH(register t_def *); +static void CodeUoper(register struct node *); +static void CodeSet(register struct node *, int); +static void CodeEl(register struct node *, register struct type *, int); +static void CodeDAddress(struct node *, int); +static void DoHIGH(register struct def *); void CodeConst(arith cst, int size) { @@ -65,7 +65,7 @@ void CodeConst(arith cst, int size) } } -void CodeString(register t_node *nd) +void CodeString(register struct node *nd) { if (nd->nd_type->tp_fund != T_STRING) { /* Character constant */ @@ -77,9 +77,9 @@ void CodeString(register t_node *nd) c_lae_dlb(data_label); } -void CodeExpr(t_node *nd, t_desig *ds, label true_label, label false_label) +void CodeExpr(struct node *nd, struct desig *ds, label true_label, label false_label) { - register t_type *tp = nd->nd_type; + register struct type *tp = nd->nd_type; DoLineno(nd); if (tp->tp_fund == T_REAL) fp_used = 1; @@ -174,7 +174,7 @@ void CodeExpr(t_node *nd, t_desig *ds, label true_label, label false_label) } } -void CodeCoercion(t_type *t1, t_type *t2) +void CodeCoercion(struct type *t1, struct type *t2) { int fund1, fund2; int sz1 = t1->tp_size; @@ -293,11 +293,11 @@ void CodeCoercion(t_type *t1, t_type *t2) } } -void CodeCall(t_node *nd) +void CodeCall(struct node *nd) { - register t_node *left = nd->nd_LEFT; - t_type *result_tp; + register struct node *left = nd->nd_LEFT; + struct type *result_tp; int needs_fn; if (left->nd_type == std_type) { @@ -320,7 +320,7 @@ void CodeCall(t_node *nd) switch(left->nd_class) { case Def: { - register t_def *df = left->nd_def; + register struct def *df = left->nd_def; if (df->df_kind == D_CONST) { /* a procedure address */ @@ -358,10 +358,10 @@ void CodeCall(t_node *nd) } /* Generates code to setup the parameters of a procedure call. */ -static void CodeParameters(t_param *param, register t_node *arg) +static void CodeParameters(struct paramlist *param, register struct node *arg) { - register t_type *tp; - register t_type *arg_type; + register struct type *tp; + register struct type *arg_type; assert(param != 0 && arg != 0); @@ -373,7 +373,7 @@ static void CodeParameters(t_param *param, register t_node *arg) arg = arg->nd_LEFT; arg_type = arg->nd_type; if (IsConformantArray(tp)) { - register t_type *elem = tp->arr_elem; + register struct type *elem = tp->arr_elem; C_loc(tp->arr_elsize); if (IsConformantArray(arg_type)) { @@ -439,7 +439,7 @@ static void CodeParameters(t_param *param, register t_node *arg) CodePExpr(arg); } -void CodePString(t_node *nd, t_type *tp) +void CodePString(struct node *nd, struct type *tp) { arith szarg = WA(nd->nd_type->tp_size); register arith zersz = WA(tp->tp_size) - szarg; @@ -471,7 +471,7 @@ static void addu(int sz) C_adu((arith)sz); } -static int complex_lhs(register t_node *nd) +static int complex_lhs(register struct node *nd) { switch(nd->nd_class) { case Value: @@ -487,11 +487,11 @@ static int complex_lhs(register t_node *nd) } /* Generate code for internal procedures */ -static void CodeStd(t_node *nd) +static void CodeStd(struct node *nd) { - register t_node *arg = nd->nd_RIGHT; - register t_node *left = 0; - register t_type *tp = 0; + register struct node *arg = nd->nd_RIGHT; + register struct node *left = 0; + register struct type *tp = 0; int std = nd->nd_LEFT->nd_def->df_value.df_stdname; if (arg) { @@ -642,7 +642,7 @@ static void CodeStd(t_node *nd) } } -static int needs_rangecheck(register t_type *tpl, t_type *tpr) +static int needs_rangecheck(register struct type *tpl, struct type *tpr) { arith rlo, rhi; @@ -665,7 +665,7 @@ static int needs_rangecheck(register t_type *tpl, t_type *tpr) return 0; } -void RangeCheck(register t_type *tpl, t_type *tpr) +void RangeCheck(register struct type *tpl, struct type *tpr) { arith rlo, rhi; @@ -690,7 +690,7 @@ void RangeCheck(register t_type *tpl, t_type *tpr) } } -void Operands(register t_node *nd) +void Operands(register struct node *nd) { CodePExpr(nd->nd_LEFT); @@ -699,13 +699,13 @@ void Operands(register t_node *nd) } void CodeOper( - register t_node *expr, /* the expression tree itself */ + register struct node *expr, /* the expression tree itself */ label true_label, label false_label /* labels to jump to in logical expr's */ ) { - register t_node *leftop = expr->nd_LEFT; - register t_node *rightop = expr->nd_RIGHT; + register struct node *leftop = expr->nd_LEFT; + register struct node *rightop = expr->nd_RIGHT; int fund = expr->nd_type->tp_fund; arith size = expr->nd_type->tp_size; @@ -850,7 +850,7 @@ void CodeOper( case GREATEREQUAL: case '=': case '#': { - t_type *tp; + struct type *tp; Operands(expr); tp = BaseType(leftop->nd_type); @@ -913,7 +913,7 @@ void CodeOper( stack */ label l_toolarge = NO_LABEL, l_cont = NO_LABEL; - t_type *ltp = leftop->nd_type; + struct type *ltp = leftop->nd_type; if (leftop->nd_symb == COERCION) { /* Could be coercion to word_type. */ @@ -968,7 +968,7 @@ void CodeOper( case OR: case AND: { label l_maybe = ++text_label, l_end = NO_LABEL; - t_desig Des; + struct desig Des; Des = null_desig; @@ -1056,9 +1056,9 @@ static void truthvalue(int relop) /* Generates code for an unary expression */ -void CodeUoper(register t_node *nd) +void CodeUoper(register struct node *nd) { - register t_type *tp = nd->nd_type; + register struct type *tp = nd->nd_type; CodePExpr(nd->nd_RIGHT); switch(nd->nd_symb) { @@ -1089,9 +1089,9 @@ void CodeUoper(register t_node *nd) } } -static void CodeSet(register t_node *nd, int null_set) +static void CodeSet(register struct node *nd, int null_set) { - register t_type *tp = nd->nd_type; + register struct type *tp = nd->nd_type; nd = nd->nd_NEXT; while (nd) { @@ -1106,9 +1106,9 @@ static void CodeSet(register t_node *nd, int null_set) if (null_set) C_zer(tp->tp_size); } -static void CodeEl(register t_node *nd, register t_type *tp, int null_set) +static void CodeEl(register struct node *nd, register struct type *tp, int null_set) { - register t_type *eltype = ElementType(tp); + register struct type *eltype = ElementType(tp); if (nd->nd_class == Link && nd->nd_symb == UPTO) { if (null_set) C_zer(tp->tp_size); @@ -1131,23 +1131,23 @@ static void CodeEl(register t_node *nd, register t_type *tp, int null_set) } } -void CodePExpr(register t_node *nd) +void CodePExpr(register struct node *nd) { - t_desig designator; + struct desig designator; designator = null_desig; CodeExpr(nd, &designator, NO_LABEL, NO_LABEL); CodeValue(&designator, nd->nd_type); } -static void CodeDAddress(t_node *nd, int chk_controlvar) +static void CodeDAddress(struct node *nd, int chk_controlvar) { /* Generate code to push the address of the designator "nd" on the stack. */ - t_desig designator; + struct desig designator; int chkptr; designator = null_desig; @@ -1167,11 +1167,11 @@ static void CodeDAddress(t_node *nd, int chk_controlvar) } } -void CodeDStore(register t_node *nd) +void CodeDStore(register struct node *nd) { - t_desig designator; + struct desig designator; designator = null_desig; ChkForFOR(nd); @@ -1179,7 +1179,7 @@ void CodeDStore(register t_node *nd) CodeStore(&designator, nd->nd_type); } -static void DoHIGH(register t_def *df) +static void DoHIGH(register struct def *df) { /* Get the high index of a conformant array, indicated by "nd". The high index is the second field in the descriptor of diff --git a/lang/m2/comp/code.h b/lang/m2/comp/code.h index 4f38a5eb7..7d49ef65a 100644 --- a/lang/m2/comp/code.h +++ b/lang/m2/comp/code.h @@ -13,32 +13,33 @@ #include /* Forward declarations. */ -typedef struct node t_node; -typedef struct desig t_desig; -typedef struct type t_type; +struct node; +struct desig; +struct type; + /* Generate code to push constant "cst" with size "size" bytes. */ void CodeConst(arith cst, int size); /* Generate constant character or string. */ -void CodeString(register t_node *nd); +void CodeString(register struct node *nd); /* Generate code for an expression contained in "nd". */ -void CodeExpr(t_node *nd, t_desig *ds, label true_label, label false_label); +void CodeExpr(struct node *nd, struct desig *ds, label true_label, label false_label); /* Generate implicit type conversion code. */ -void CodeCoercion(t_type *t1, t_type *t2); +void CodeCoercion(struct type *t1, struct type *t2); /* Generate code for a procedure call including parameter setup. Checking of parameters and result is already done. */ -void CodeCall(t_node *nd); -void CodePString(t_node *nd, t_type *tp); +void CodeCall(struct node *nd); +void CodePString(struct node *nd, struct type *tp); /* Generate a range check if necessary */ -void RangeCheck(register t_type *tpl, t_type *tpr); -void CodeOper(register t_node *expr, label true_label, label false_label); +void RangeCheck(register struct type *tpl, struct type *tpr); +void CodeOper(register struct node *expr, label true_label, label false_label); /* Generate code to push the value of the expression "nd" on the stack. */ -void CodePExpr(register t_node *nd); +void CodePExpr(register struct node *nd); /* Generate code to store the expression on the stack into the designator "nd". */ -void CodeDStore(register t_node *nd); +void CodeDStore(register struct node *nd); #ifdef SQUEEZE void c_bra(label l); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index ef2bad9a7..ffaf25a91 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -48,21 +48,21 @@ arith min_int[] = { 0L, -128L, -32768L, 0L, -2147483647L-1 }; extern char options[]; -static void CutSize(register t_node *); +static void CutSize(register struct node *); -static void overflow(t_node *expp) +static void overflow(struct node *expp) { if (expp->nd_type != address_type) { node_warning(expp, W_ORDINARY, "overflow in constant expression"); } } -static void commonbin(t_node **expp) +static void commonbin(struct node **expp) { - register t_node *exp = *expp; - t_type *tp = exp->nd_type; - register t_node *right = exp->nd_RIGHT; + register struct node *exp = *expp; + struct type *tp = exp->nd_type; + register struct node *right = exp->nd_RIGHT; exp->nd_RIGHT = 0; FreeNode(exp); @@ -70,13 +70,13 @@ static void commonbin(t_node **expp) right->nd_type = tp; } -void cstunary(t_node **expp) +void cstunary(struct node **expp) { /* The unary operation in "expp" is performed on the constant expression below it, and the result stored in expp. */ - register t_node *exp = *expp; - register t_node *right = exp->nd_RIGHT; + register struct node *exp = *expp; + register struct node *right = exp->nd_RIGHT; register arith o1 = right->nd_INT; switch(exp->nd_symb) { @@ -119,13 +119,13 @@ static void divide(arith *pdiv, arith *prem) *prem = (unsigned arith) o1 % (unsigned arith) o2; } -void cstibin(t_node **expp) +void cstibin(struct node **expp) { /* The binary operation in "expp" is performed on the constant expressions below it, and the result restored in expp. This version is for INTEGER expressions. */ - register t_node *exp = *expp; + register struct node *exp = *expp; register arith o1 = exp->nd_LEFT->nd_INT; register arith o2 = exp->nd_RIGHT->nd_INT; register int sz = exp->nd_type->tp_size; @@ -228,13 +228,13 @@ void cstibin(t_node **expp) CutSize(*expp); } -void cstfbin(t_node **expp) +void cstfbin(struct node **expp) { /* The binary operation in "expp" is performed on the constant expressions below it, and the result restored in expp. This version is for REAL expressions. */ - register t_node *exp = *expp; + register struct node *exp = *expp; register struct real *p = exp->nd_LEFT->nd_REAL; register flt_arith *o1 = &p->r_val; register flt_arith *o2 = &exp->nd_RIGHT->nd_RVAL; @@ -288,7 +288,7 @@ void cstfbin(t_node **expp) switch(flt_status) { case FLT_OVFL: - node_warning(exp, "floating point overflow on %s", + node_warning(exp, W_ORDINARY, "floating point overflow on %s", symbol2str(exp->nd_symb)); break; case FLT_DIV0: @@ -315,13 +315,13 @@ void cstfbin(t_node **expp) CutSize(exp); } -void cstubin(t_node **expp) +void cstubin(struct node **expp) { /* The binary operation in "expp" is performed on the constant expressions below it, and the result restored in expp. */ - register t_node *exp = *expp; + register struct node *exp = *expp; arith o1 = exp->nd_LEFT->nd_INT; arith o2 = exp->nd_RIGHT->nd_INT; register int sz = exp->nd_type->tp_size; @@ -420,10 +420,10 @@ void cstubin(t_node **expp) CutSize(exp); } -void cstset(t_node **expp) +void cstset(struct node **expp) { extern arith *MkSet(); - register t_node *exp = *expp; + register struct node *exp = *expp; register arith *set1, *set2, *set3; register unsigned int setsize; register int j; @@ -535,13 +535,13 @@ void cstset(t_node **expp) FreeNode(exp); } -void cstcall(t_node **expp, int call) +void cstcall(struct node **expp, int call) { /* a standard procedure call is found that can be evaluated compile time, so do so. */ - register t_node *expr; - register t_type *tp; + register struct node *expr; + register struct type *tp; assert((*expp)->nd_class == Call); expr = (*expp)->nd_RIGHT->nd_LEFT; @@ -609,12 +609,12 @@ void cstcall(t_node **expp, int call) } } -static void CutSize(register t_node *expr) +static void CutSize(register struct node *expr) { /* The constant value of the expression expr is made to conform to the size of the type of the expression. */ - register t_type *tp = BaseType(expr->nd_type); + register struct type *tp = BaseType(expr->nd_type); assert(expr->nd_class == Value); if (tp->tp_fund == T_REAL) return; diff --git a/lang/m2/comp/cstoper.h b/lang/m2/comp/cstoper.h index b186129f3..6a9ece855 100644 --- a/lang/m2/comp/cstoper.h +++ b/lang/m2/comp/cstoper.h @@ -11,18 +11,18 @@ /* Compile time constant evaluations */ -void cstunary(t_node **expp); -void cstibin(t_node **expp); -void cstfbin(t_node **expp); -void cstubin(t_node **expp); +void cstunary(struct node **expp); +void cstibin(struct node **expp); +void cstfbin(struct node **expp); +void cstubin(struct node **expp); /** Evaluates the constant set operators at compile time * and returns the result in "expp". */ -void cstset(t_node **expp); +void cstset(struct node **expp); /* Evaluates the result of internal procedures on constants * at compile time, and returns the result in "expp". */ -void cstcall(t_node **expp, int call); +void cstcall(struct node **expp, int call); /* Compile time constant evaluator system initialization. */ void InitCst(void); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index a075000c9..e27e378bf 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -35,7 +35,7 @@ int proclevel = 0; /* nesting level of procedures */ int return_occurred; /* set if a return occurs in a block */ -extern t_node *EmptyStatement; +extern struct node *EmptyStatement; #define needs_static_link() (proclevel > 1) } @@ -43,7 +43,7 @@ extern t_node *EmptyStatement; /* inline in declaration: need space * ProcedureDeclaration * { - * t_def *df; + * struct def *df; * } : * { ++proclevel; } * ProcedureHeading(&df, D_PROCEDURE) @@ -55,11 +55,11 @@ extern t_node *EmptyStatement; * ; */ -ProcedureHeading(t_def **pdf; int type;) +ProcedureHeading(struct def **pdf; int type;) { - t_type *tp = 0; + struct type *tp = 0; arith parmaddr = needs_static_link() ? pointer_size : 0; - t_param *pr = 0; + struct paramlist *pr = 0; } : PROCEDURE IDENT { *pdf = DeclProc(type, dot.TOK_IDF); } @@ -88,7 +88,7 @@ warning(W_STRICT, "procedure \"%s\" has a constructed result type", } ; -block(t_node **pnd;) : +block(struct node **pnd;) : [ %persistent declaration ]* @@ -104,7 +104,7 @@ block(t_node **pnd;) : declaration { - t_def *df; + struct def *df; } : CONST [ ConstantDeclaration ';' ]* | @@ -129,7 +129,7 @@ declaration ; /* inline in procedureheading: need space - * FormalParameters(t_param **ppr; arith *parmaddr; t_type **ptp;): + * FormalParameters(struct paramlist **ppr; arith *parmaddr; struct type **ptp;): * '(' * [ * FPSection(ppr, parmaddr) @@ -145,21 +145,21 @@ declaration * ; */ -FPSection(t_param **ppr; arith *parmaddr;) +FPSection(struct paramlist **ppr; arith *parmaddr;) { - t_node *FPList; - t_type *tp; + struct node *FPList; + struct type *tp; int VARp; } : var(&VARp) IdentList(&FPList) ':' FormalType(&tp) { EnterParamList(ppr, FPList, tp, VARp, parmaddr); } ; -FormalType(t_type **ptp;) +FormalType(struct type **ptp;) /* index type of conformant array is "CARDINAL". Recognize a conformant array by size 0. */ -{ register t_type *tp; +{ register struct type *tp; } : ARRAY OF { tp = construct_type(T_ARRAY, card_type); } @@ -173,9 +173,9 @@ FormalType(t_type **ptp;) TypeDeclaration { - t_def *df; - t_type *tp; - register t_node *nd; + struct def *df; + struct type *tp; + register struct node *nd; }: IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); nd = dot2leaf(Name); @@ -186,7 +186,7 @@ TypeDeclaration } ; -type(register t_type **ptp;): +type(register struct type **ptp;): %default SimpleType(ptp) | ArrayType(ptp) @@ -200,7 +200,7 @@ type(register t_type **ptp;): ProcedureType(ptp) ; -SimpleType(register t_type **ptp;) : +SimpleType(register struct type **ptp;) : qualtype(ptp) [ /* nothing */ @@ -216,17 +216,17 @@ SimpleType(register t_type **ptp;) : SubrangeType(ptp) ; -enumeration(t_type **ptp;) +enumeration(struct type **ptp;) { - t_node *EnumList; + struct node *EnumList; } : '(' IdentList(&EnumList) ')' { *ptp = enum_type(EnumList); } ; -IdentList(t_node **p;) +IdentList(struct node **p;) { - register t_node *q; + register struct node *q; } : IDENT { *p = q = dot2leaf(Select); } [ %persistent @@ -237,9 +237,9 @@ IdentList(t_node **p;) ]* ; -SubrangeType(t_type **ptp;) +SubrangeType(struct type **ptp;) { - t_node *nd1, *nd2; + struct node *nd1, *nd2; }: /* This is not exactly the rule in the new report, but see @@ -254,10 +254,10 @@ SubrangeType(t_type **ptp;) } ; -ArrayType(t_type **ptp;) +ArrayType(struct type **ptp;) { - t_type *tp; - register t_type *tp1, *tp2; + struct type *tp; + register struct type *tp1, *tp2; } : ARRAY SimpleType(&tp) { tp1 = tp2 = construct_type(T_ARRAY, tp); } @@ -273,9 +273,9 @@ ArrayType(t_type **ptp;) } ; -RecordType(t_type **ptp;) +RecordType(struct type **ptp;) { - register t_scope *scope; + register struct scope *scope; arith size = 0; int xalign = struct_align; } @@ -294,19 +294,19 @@ RecordType(t_type **ptp;) END ; -FieldListSequence(t_scope *scope; arith *cnt; int *palign;): +FieldListSequence(struct scope *scope; arith *cnt; int *palign;): FieldList(scope, cnt, palign) [ ';' FieldList(scope, cnt, palign) ]* ; -FieldList(t_scope *scope; arith *cnt; int *palign;) +FieldList(struct scope *scope; arith *cnt; int *palign;) { - t_node *FldList; - t_type *tp; - t_node *nd; - register t_def *df; + struct node *FldList; + struct type *tp; + struct node *nd; + register struct def *df; arith tcnt, max; } : [ @@ -374,9 +374,9 @@ FieldList(t_scope *scope; arith *cnt; int *palign;) ] ; -variant(t_scope *scope; arith *cnt; t_type *tp; int *palign;) +variant(struct scope *scope; arith *cnt; struct type *tp; int *palign;) { - t_node *nd; + struct node *nd; } : [ CaseLabelList(&tp, &nd) @@ -392,7 +392,7 @@ variant(t_scope *scope; arith *cnt; t_type *tp; int *palign;) /* Changed rule in new modula-2 */ ; -CaseLabelList(t_type **ptp; t_node **pnd;): +CaseLabelList(struct type **ptp; struct node **pnd;): CaseLabels(ptp, pnd) [ { *pnd = dot2node(Link, *pnd, NULLNODE); } @@ -401,14 +401,14 @@ CaseLabelList(t_type **ptp; t_node **pnd;): ]* ; -CaseLabels(t_type **ptp; register t_node **pnd;) +CaseLabels(struct type **ptp; register struct node **pnd;) { - register t_node *nd; + register struct node *nd; }: ConstExpression(pnd) { if (*ptp != 0) { - t_type *tp = intorcard(*ptp, + struct type *tp = intorcard(*ptp, BaseType((*pnd)->nd_type)); if (tp) *ptp = tp; ChkCompat(pnd, *ptp, "case label"); @@ -444,8 +444,8 @@ CaseLabels(t_type **ptp; register t_node **pnd;) } ; -SetType(t_type **ptp;) -{ t_type *tp; +SetType(struct type **ptp;) +{ struct type *tp; } : SET OF SimpleType(&tp) { *ptp = set_type(tp); } @@ -455,8 +455,8 @@ SetType(t_type **ptp;) have to be declared yet, so be careful about identifying type-identifiers. */ -PointerType(register t_type **ptp;) -{ register t_type *tp; +PointerType(register struct type **ptp;) +{ register struct type *tp; } : { tp = construct_type(T_POINTER, NULLTYPE); } POINTER TO @@ -468,19 +468,19 @@ PointerType(register t_type **ptp;) { *ptp = tp; } ; -qualtype(t_type **ptp;) +qualtype(struct type **ptp;) { - t_node *nd; + struct node *nd; } : qualident(&nd) { *ptp = qualified_type(&nd); } ; -ProcedureType(t_type **ptp;) +ProcedureType(struct type **ptp;) { - t_param *pr = 0; + struct paramlist *pr = 0; arith parmaddr = 0; - t_type *tp = 0; + struct type *tp = 0; } : PROCEDURE [ @@ -490,7 +490,7 @@ ProcedureType(t_type **ptp;) { *ptp = proc_type(tp, pr, parmaddr); } ; -FormalTypeList(t_param **ppr; arith *pparmaddr; t_type **ptp;) : +FormalTypeList(struct paramlist **ppr; arith *pparmaddr; struct type **ptp;) : '(' [ VarFormalType(ppr, pparmaddr) @@ -505,9 +505,9 @@ FormalTypeList(t_param **ppr; arith *pparmaddr; t_type **ptp;) : ] ; -VarFormalType(t_param **ppr; arith *pparmaddr;) +VarFormalType(struct paramlist **ppr; arith *pparmaddr;) { - t_type *tp; + struct type *tp; int isvar; } : var(&isvar) @@ -525,9 +525,9 @@ var(int *VARp;) : ConstantDeclaration { - t_idf *id; - t_node *nd; - register t_def *df; + struct idf *id; + struct node *nd; + register struct def *df; }: IDENT { id = dot.TOK_IDF; } '=' ConstExpression(&nd) @@ -540,9 +540,9 @@ ConstantDeclaration VariableDeclaration { - t_node *VarList; - register t_node *nd; - t_type *tp; + struct node *VarList; + register struct node *nd; + struct type *tp; } : IdentAddr(&VarList) { nd = VarList; } @@ -554,9 +554,9 @@ VariableDeclaration { EnterVarList(VarList, tp, proclevel > 0); } ; -IdentAddr(t_node **pnd;) +IdentAddr(struct node **pnd;) { - register t_node *nd; + register struct node *nd; } : IDENT { nd = dot2leaf(Name); *pnd = dot2node(Link, nd, NULLNODE); diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 650525ae1..456d76805 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -48,14 +48,14 @@ static void internal(register char *c) C_inp(c); } -static void DefInFront(register t_def *df) +static void DefInFront(register struct def *df) { /* Put definition "df" in front of the list of definitions in its scope. This is neccessary because in some cases the order in this list is important. */ - register t_def *df1 = df->df_scope->sc_def; + register struct def *df1 = df->df_scope->sc_def; if (df1 != df) { @@ -82,12 +82,12 @@ static void DefInFront(register t_def *df) } } -t_def *MkDef(register t_idf *id, register t_scope *scope, int kind) +struct def *MkDef(register struct idf *id, register struct scope *scope, int kind) { /* Create a new definition structure in scope "scope", with id "id" and kind "kind". */ - register t_def *df; + register struct def *df; df = new_def(); df->df_idf = id; @@ -109,14 +109,14 @@ t_def *MkDef(register t_idf *id, register t_scope *scope, int kind) return df; } -t_def *define(register t_idf *id, register t_scope *scope, int kind) +struct def *define(register struct idf *id, register struct scope *scope, int kind) { /* Declare an identifier in a scope, but first check if it already has been defined. If so, then check for the cases in which this is legal, and otherwise give an error message. */ - register t_def *df; + register struct def *df; DO_DEBUG(options['S'], print("define %s, %x\n", id->id_text, kind)); df = lookup(id, scope, D_IMPORT, 0); @@ -211,14 +211,14 @@ t_def *define(register t_idf *id, register t_scope *scope, int kind) return MkDef(id, scope, kind); } -void end_definition_list(register t_def **pdf) +void end_definition_list(register struct def **pdf) { /* Remove all imports from a definition module. This is neccesary because the implementation module might import them again. Also, mark all other definitions "QUALIFIED EXPORT". */ - register t_def *df; + register struct def *df; while ( (df = *pdf) ) { @@ -241,12 +241,12 @@ void end_definition_list(register t_def **pdf) } } -void RemoveFromIdList(register t_def *df) +void RemoveFromIdList(register struct def *df) { /* Remove definition "df" from the definition list */ - register t_idf *id = df->df_idf; - register t_def *df1; + register struct idf *id = df->df_idf; + register struct def *df1; if ((df1 = id->id_def) == df) id->id_def = df->df_next; @@ -261,14 +261,14 @@ void RemoveFromIdList(register t_def *df) } } -t_def * DeclProc(int type, register t_idf *id) +struct def * DeclProc(int type, register struct idf *id) { /* A procedure is declared, either in a definition or a program module. Create a def structure for it (if neccessary). Also create a name for it. */ - register t_def *df; - register t_scope *scope; + register struct def *df; + register struct scope *scope; static int nmcount; char buf[256]; @@ -326,7 +326,7 @@ t_def * DeclProc(int type, register t_idf *id) return df; } -void EndProc(register t_def *df, t_idf *id) +void EndProc(register struct def *df, struct idf *id) { /* The end of a procedure declaration. Check that the closing identifier matches the name of the @@ -344,13 +344,13 @@ void EndProc(register t_def *df, t_idf *id) } } -t_def * DefineLocalModule(t_idf *id) +struct def * DefineLocalModule(struct idf *id) { /* Create a definition for a local module. Also give it a name to be used for code generation. */ - register t_def *df = define(id, CurrentScope, D_MODULE); - register t_scope *sc; + register struct def *df = define(id, CurrentScope, D_MODULE); + register struct scope *sc; static int modulecount = 0; char buf[256]; extern int proclevel; @@ -385,7 +385,7 @@ t_def * DefineLocalModule(t_idf *id) return df; } -void CheckWithDef(register t_def *df, t_type *tp) +void CheckWithDef(register struct def *df, struct type *tp) { /* Check the header of a procedure declaration against a possible earlier definition in the definition module. @@ -409,7 +409,7 @@ void CheckWithDef(register t_def *df, t_type *tp) } #ifdef DEBUG -void PrDef(register t_def *df) +void PrDef(register struct def *df) { print("n: %s, k: %d\n", df->df_idf->id_text, df->df_kind); } diff --git a/lang/m2/comp/def.xh b/lang/m2/comp/def.xh index 29a5d3dd5..4c755c681 100644 --- a/lang/m2/comp/def.xh +++ b/lang/m2/comp/def.xh @@ -131,23 +131,23 @@ struct def { /* list of definitions for a name */ } df_value; }; -typedef struct def t_def; + /* ALLOCDEF "def" 50 */ -#define NULLDEF ((t_def *) 0) +#define NULLDEF ((struct def *) 0) -typedef struct scope t_scope; -typedef struct idf t_idf; -typedef struct type t_type; +struct scope; +struct idf; -t_def *MkDef(register t_idf *id, register t_scope *scope, int kind); -t_def *define(register t_idf *id, register t_scope *scope, int kind); -void RemoveFromIdList(register t_def *df); -t_def * DeclProc(int type, register t_idf *id); -void EndProc(register t_def *df, t_idf *id); -t_def * DefineLocalModule(t_idf *id); -void CheckWithDef(register t_def *df, t_type *tp); -void end_definition_list(register t_def **pdf); + +struct def *MkDef(register struct idf *id, register struct scope *scope, int kind); +struct def *define(register struct idf *id, register struct scope *scope, int kind); +void RemoveFromIdList(register struct def *df); +struct def * DeclProc(int type, register struct idf *id); +void EndProc(register struct def *df, struct idf *id); +struct def * DefineLocalModule(struct idf *id); +void CheckWithDef(register struct def *df, struct type *tp); +void end_definition_list(register struct def **pdf); #endif /* DEF_H_ */ \ No newline at end of file diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 57cd96c21..1a4b6215d 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -41,7 +41,7 @@ size_t sys_filesize(); extern void DefModule(void); /* Lpars */ -t_idf* DefId; +struct idf* DefId; char* getwdir(register char *fn) { @@ -90,19 +90,19 @@ static int GetFile(char *name) return 1; } -t_def* GetDefinitionModule(register t_idf* id, int incr) +struct def* GetDefinitionModule(register struct idf* id, int incr) { /* Return a pointer to the "def" structure of the definition module indicated by "id". We may have to read the definition module itself. Also increment level by "incr". */ - register t_def* df; + register struct def* df; static int level; - t_scopelist* vis; + struct scopelist* vis; char* fn = FileName; int ln = LineNumber; - t_scope* newsc; + struct scope* newsc; level += incr; df = lookup(id, GlobalScope, D_IMPORTED, 0); @@ -139,9 +139,9 @@ t_def* GetDefinitionModule(register t_idf* id, int incr) remember its name because we have to call its initialization routine */ - static t_node* nd_end; - register t_node* n; - extern t_node* Modules; + static struct node* nd_end; + register struct node* n; + extern struct node* Modules; n = dot2leaf(Def); n->nd_def = newsc->sc_definedby; diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index caecf72b7..0925ca8cb 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -40,7 +40,7 @@ extern int proclevel; extern char options[]; -static int WordOrDouble(t_desig *ds, arith size) +static int WordOrDouble(struct desig *ds, arith size) { /* Check if designator is suitable for word or double-word operation @@ -80,7 +80,7 @@ void STL(arith offset, arith size) } } -int DoLoad(register t_desig *ds, arith size) +int DoLoad(register struct desig *ds, arith size) { /* Try to load designator with word or double-word operation. Return 0 if not done @@ -104,7 +104,7 @@ int DoLoad(register t_desig *ds, arith size) return 1; } -int DoStore(register t_desig *ds, arith size) +int DoStore(register struct desig *ds, arith size) { /* Try to store designator with word or double-word operation. Return 0 if not done @@ -152,7 +152,7 @@ int DoStore(register t_desig *ds, arith size) multiple of word_size only */ -static int suitable_move(register t_type *tp) +static int suitable_move(register struct type *tp) { /* Find out how to load or store the value indicated by "ds". There are four ways: @@ -170,7 +170,7 @@ static int suitable_move(register t_type *tp) return USE_BLM; } -void CodeValue(register t_desig *ds, register t_type *tp) +void CodeValue(register struct desig *ds, register struct type *tp) { /* Generate code to load the value of the designator described in "ds". @@ -233,12 +233,12 @@ void CodeValue(register t_desig *ds, register t_type *tp) ds->dsg_kind = DSG_LOADED; } -void ChkForFOR(register t_node *nd) +void ChkForFOR(register struct node *nd) { /* Check for an assignment to a FOR-loop control variable */ if (nd->nd_class == Def) { - register t_def *df = nd->nd_def; + register struct def *df = nd->nd_def; if (df->df_flags & D_FORLOOP) { node_warning(nd, @@ -250,7 +250,7 @@ void ChkForFOR(register t_node *nd) } } -void CodeStore(register t_desig *ds, register t_type *tp) +void CodeStore(register struct desig *ds, register struct type *tp) { /* Generate code to store the value on the stack in the designator described in "ds" @@ -295,12 +295,12 @@ void CodeStore(register t_desig *ds, register t_type *tp) ds->dsg_kind = DSG_INIT; } -void CodeCopy(register t_desig *lhs, register t_desig *rhs, arith sz, arith *psize) +void CodeCopy(register struct desig *lhs, register struct desig *rhs, arith sz, arith *psize) { /* Do part of a copy, which is assumed to be "reasonable", so that it can be done with LOI/STI or BLM. */ - t_desig l, r; + struct desig l, r; l = *lhs; r = *rhs; *psize -= sz; @@ -318,17 +318,17 @@ void CodeCopy(register t_desig *lhs, register t_desig *rhs, arith sz, arith *psi } } -t_desig null_desig; +struct desig null_desig; -void CodeMove(register t_desig *rhs, register t_node *left, t_type *rtp) +void CodeMove(register struct desig *rhs, register struct node *left, struct type *rtp) { /* Generate code for an assignment. Testing of type compatibility and the like is already done. Go through some (considerable) trouble to see if a BLM can be generated. */ - t_desig lhs; - register t_type *tp = left->nd_type; + struct desig lhs; + register struct type *tp = left->nd_type; int loadedflag = 0; lhs = null_desig; @@ -419,7 +419,7 @@ void CodeMove(register t_desig *rhs, register t_node *left, t_type *rtp) } } -void CodeAddress(register t_desig *ds) +void CodeAddress(register struct desig *ds) { /* Generate code to load the address of the designator described in "ds" @@ -459,7 +459,7 @@ void CodeAddress(register t_desig *ds) ds->dsg_kind = DSG_PLOADED; } -void CodeFieldDesig(register t_def *df, register t_desig *ds) +void CodeFieldDesig(register struct def *df, register struct desig *ds) { /* Generate code for a field designator. Only the code common for address as well as value computation is generated, and the @@ -509,14 +509,14 @@ void CodeFieldDesig(register t_def *df, register t_desig *ds) } } -void CodeVarDesig(register t_def *df, register t_desig *ds) +void CodeVarDesig(register struct def *df, register struct desig *ds) { /* Generate code for a variable represented by a "def" structure. Of course, there are numerous cases: the variable is local, it is a value parameter, it is a var parameter, it is one of those of an enclosing procedure, or it is global. */ - register t_scope *sc = df->df_scope; + register struct scope *sc = df->df_scope; int difflevel; /* Selections from a module are handled earlier, when identifying @@ -585,12 +585,12 @@ void CodeVarDesig(register t_def *df, register t_desig *ds) ds->dsg_def = df; } -void CodeDesig(register t_node *nd, register t_desig *ds) +void CodeDesig(register struct node *nd, register struct desig *ds) { /* Generate code for a designator. Use divide and conquer principle */ - register t_def *df; + register struct def *df; switch(nd->nd_class) { /* Divide */ case Def: diff --git a/lang/m2/comp/desig.h b/lang/m2/comp/desig.h index a76f7fd1b..522b7e303 100644 --- a/lang/m2/comp/desig.h +++ b/lang/m2/comp/desig.h @@ -49,7 +49,6 @@ struct desig { */ }; -typedef struct desig t_desig; /* The next structure describes the designator in a with-statement. We have a linked list of them, as with-statements may be nested. @@ -61,7 +60,7 @@ struct withdesig { struct scope *w_scope; /* scope in which fields of this record reside */ - t_desig w_desig; /* a desig structure for this particular + struct desig w_desig; /* a desig structure for this particular designator */ }; @@ -70,20 +69,20 @@ extern struct withdesig *WithDesigs; #define NO_LABEL ((label) 0) -typedef struct type t_type; -typedef struct node t_node; +struct type; +struct node; void LOL(arith offset, arith size); void STL(arith offset, arith size); -void CodeValue(register t_desig *ds, register t_type *tp); -void ChkForFOR(register t_node *nd); -void CodeStore(register t_desig *ds, register t_type *tp); -void CodeCopy(register t_desig *lhs, register t_desig *rhs, arith sz, arith *psize); -void CodeMove(register t_desig *rhs, register t_node *left, t_type *rtp); -void CodeAddress(register t_desig *ds); -void CodeFieldDesig(register t_def *df, register t_desig *ds); -void CodeVarDesig(register t_def *df, register t_desig *ds); -void CodeDesig(register t_node *nd, register t_desig *ds); +void CodeValue(register struct desig *ds, register struct type *tp); +void ChkForFOR(register struct node *nd); +void CodeStore(register struct desig *ds, register struct type *tp); +void CodeCopy(register struct desig *lhs, register struct desig *rhs, arith sz, arith *psize); +void CodeMove(register struct desig *rhs, register struct node *left, struct type *rtp); +void CodeAddress(register struct desig *ds); +void CodeFieldDesig(register struct def *df, register struct desig *ds); +void CodeVarDesig(register struct def *df, register struct desig *ds); +void CodeDesig(register struct node *nd, register struct desig *ds); #endif /* DESIG_H_ */ diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 6e48efa09..d55ed4f56 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -37,15 +37,15 @@ #include "f_info.h" -static t_def *DoImport(register t_def *, t_scope *, int); +static struct def *DoImport(register struct def *, struct scope *, int); -t_def *Enter(char *name, int kind, t_type *type, int pnam) +struct def *Enter(char *name, int kind, struct type *type, int pnam) { /* Enter a definition for "name" with kind "kind" and type "type" in the Current Scope. If it is a standard name, also put its number in the definition structure. */ - register t_def *df; + register struct def *df; df = define(str2idf(name, 0), CurrentScope, kind); df->df_type = type; @@ -56,7 +56,7 @@ t_def *Enter(char *name, int kind, t_type *type, int pnam) return df; } -t_def *EnterType(char *name, t_type *type) +struct def *EnterType(char *name, struct type *type) { /* Enter a type definition for "name" and type "type" in the Current Scope. @@ -65,7 +65,7 @@ t_def *EnterType(char *name, t_type *type) return Enter(name, D_TYPE, type, 0); } -void EnterEnumList(t_node *Idlist, register t_type *type) +void EnterEnumList(struct node *Idlist, register struct type *type) { /* Put a list of enumeration literals in the symbol table. They all have type "type". @@ -74,8 +74,8 @@ void EnterEnumList(t_node *Idlist, register t_type *type) be exported, in which case its literals must also be exported. Thus, we need an easy way to get to them. */ - register t_def *df, *df1 = 0; - register t_node *idlist = Idlist; + register struct def *df, *df1 = 0; + register struct node *idlist = Idlist; type->enm_ncst = 0; for (; idlist; idlist = idlist->nd_NEXT) { @@ -91,7 +91,7 @@ void EnterEnumList(t_node *Idlist, register t_type *type) FreeNode(Idlist); } -void EnterFieldList(t_node *Idlist, register t_type *type, t_scope *scope, +void EnterFieldList(struct node *Idlist, register struct type *type, struct scope *scope, arith *addr) { /* Put a list of fields in the symbol table. @@ -99,8 +99,8 @@ void EnterFieldList(t_node *Idlist, register t_type *type, t_scope *scope, Mark them as QUALIFIED EXPORT, because that's exactly what fields are, you can get to them by qualifying them. */ - register t_def *df; - register t_node *idlist = Idlist; + register struct def *df; + register struct node *idlist = Idlist; for (; idlist; idlist = idlist->nd_NEXT) { df = define(idlist->nd_IDF, scope, D_FIELD); @@ -112,11 +112,11 @@ void EnterFieldList(t_node *Idlist, register t_type *type, t_scope *scope, FreeNode(Idlist); } -void EnterVarList(t_node *Idlist, t_type *type, int local) +void EnterVarList(struct node *Idlist, struct type *type, int local) { - register t_def *df; - register t_node *idlist = Idlist; - register t_scopelist *sc = CurrVis; + register struct def *df; + register struct node *idlist = Idlist; + register struct scopelist *sc = CurrVis; char buf[256]; extern char *sprint(); @@ -133,7 +133,7 @@ void EnterVarList(t_node *Idlist, t_type *type, int local) if (idlist->nd_LEFT->nd_NEXT) { /* An address was supplied */ - register t_type *tp = idlist->nd_LEFT->nd_NEXT->nd_type; + register struct type *tp = idlist->nd_LEFT->nd_NEXT->nd_type; df->df_flags |= D_ADDRGIVEN | D_NOREG; if (tp != error_type && !(tp->tp_fund & T_CARDINAL)){ @@ -180,17 +180,17 @@ void EnterVarList(t_node *Idlist, t_type *type, int local) FreeNode(Idlist); } -void EnterParamList(t_param **ppr, - t_node *Idlist, - t_type *type, +void EnterParamList(struct paramlist **ppr, + struct node *Idlist, + struct type *type, int VARp, arith *off) { - register t_param *pr; - register t_def *df; - register t_node *idlist = Idlist; - t_node *dummy = 0; - static t_param *last; + register struct paramlist *pr; + register struct def *df; + register struct node *idlist = Idlist; + struct node *dummy = 0; + static struct paramlist *last; if (! idlist) { /* Can only happen when a procedure type is defined */ @@ -230,14 +230,14 @@ void EnterParamList(t_param **ppr, } -static void ImportEffects(register t_def *idef, t_scope *scope, int flag) +static void ImportEffects(register struct def *idef, struct scope *scope, int flag) { /* Handle side effects of an import: - a module could have unqualified exports ??? - importing an enumeration type also imports literals */ - register t_def *df = idef; - register t_type *tp; + register struct def *df = idef; + register struct type *tp; while ((df->df_kind & D_IMPORTED) && df->imp_def != df) { /* The second condition could occur on some (erroneous and @@ -262,7 +262,7 @@ static void ImportEffects(register t_def *idef, t_scope *scope, int flag) in some way, don't do it again; we don't want a multiple defined error message here. */ - t_def *df1; + struct def *df1; df->df_flags |= D_QEXPORTED; if ((!(df1 = lookup(df->df_idf, scope, D_IMPORT, 0)) || @@ -296,11 +296,11 @@ static void ImportEffects(register t_def *idef, t_scope *scope, int flag) } } -static t_def *DoImport(register t_def *df, t_scope *scope, int flag) +static struct def *DoImport(register struct def *df, struct scope *scope, int flag) { /* Definition "df" is imported to scope "scope". */ - register t_def *idef = define(df->df_idf, scope, D_IMPORT); + register struct def *idef = define(df->df_idf, scope, D_IMPORT); idef->imp_def = df; idef->df_flags |= flag; @@ -309,13 +309,13 @@ static t_def *DoImport(register t_def *df, t_scope *scope, int flag) } -static void ForwModule(register t_def *df, t_node *nd) +static void ForwModule(register struct def *df, struct node *nd) { /* An import is done from a not yet defined module "df". We could also end up here for not found DEFINITION MODULES. Create a declaration and a scope for this module. */ - register t_scopelist *vis; + register struct scopelist *vis; if (df->df_scope != GlobalScope) { df->df_scope = enclosing(CurrVis)->sc_scope; @@ -334,12 +334,12 @@ static void ForwModule(register t_def *df, t_node *nd) df->for_node = nd; } -static t_def *ForwDef(register t_node *ids, t_scope *scope) +static struct def *ForwDef(register struct node *ids, struct scope *scope) { /* Enter a forward definition of "ids" in scope "scope", if it is not already defined. */ - register t_def *df; + register struct def *df; if (!(df = lookup(ids->nd_IDF, scope, 0, 0))) { df = define(ids->nd_IDF, scope, D_FORWARD); @@ -350,10 +350,10 @@ static t_def *ForwDef(register t_node *ids, t_scope *scope) return df; } -void EnterExportList(t_node *Idlist, int qualified) +void EnterExportList(struct node *Idlist, int qualified) { - register t_node *idlist = Idlist; - register t_def *df, *df1; + register struct node *idlist = Idlist; + register struct def *df, *df1; for (;idlist; idlist = idlist->nd_NEXT) { df = lookup(idlist->nd_IDF, CurrentScope, 0, 0); @@ -400,7 +400,7 @@ void EnterExportList(t_node *Idlist, int qualified) scope. There are two legal possibilities, which are examined below. */ - t_def *df2 = df; + struct def *df2 = df; while (df2->df_kind & D_IMPORTED) { df2 = df2->imp_def; @@ -426,16 +426,16 @@ void EnterExportList(t_node *Idlist, int qualified) FreeNode(Idlist); } -void CheckForImports(t_def *df) +void CheckForImports(struct def *df) { /* We have a definition for "df"; check all imports of it for side-effects */ - register t_def *df1 = df->df_idf->id_def; + register struct def *df1 = df->df_idf->id_def; while (df1) { if (df1->df_kind & D_IMPORTED) { - register t_def *df2 = df1->imp_def; + register struct def *df2 = df1->imp_def; while (df2->df_kind & D_IMPORTED) df2 = df2->imp_def; if (df2 == df) { @@ -446,12 +446,12 @@ void CheckForImports(t_def *df) } } -void EnterFromImportList(t_node *idlist, t_def *FromDef, t_node *FromId) +void EnterFromImportList(struct node *idlist, struct def *FromDef, struct node *FromId) { /* Import the list Idlist from the module indicated by Fromdef. */ - t_scope *sc; - register t_def *df; + struct scope *sc; + register struct def *df; char *module_name = FromDef->df_idf->id_text; switch(FromDef->df_kind) { @@ -504,13 +504,13 @@ node_error(FromId,"identifier \"%s\" does not represent a module",module_name); FreeNode(FromId); } -void EnterImportList(t_node *idlist, int local, t_scope *sc) +void EnterImportList(struct node *idlist, int local, struct scope *sc) { /* Import "idlist" from scope "sc". If the import is not local, definition modules must be read for "idlist". */ - extern t_def *GetDefinitionModule(); + extern struct def *GetDefinitionModule(); struct f_info f; f = file_info; diff --git a/lang/m2/comp/enter.h b/lang/m2/comp/enter.h index 390e9d445..bb6aec442 100644 --- a/lang/m2/comp/enter.h +++ b/lang/m2/comp/enter.h @@ -9,38 +9,38 @@ #define ENTER_H_ /* Forward declarations. */ -typedef struct type t_type; -typedef struct def t_def; -typedef struct node t_node; -typedef struct scope t_scope; -typedef struct paramlist t_param; +struct type; +struct node; +struct scope; +struct paramlist; +struct def; -t_def *Enter(char *name, int kind, t_type *type, int pnam); -t_def *EnterType(char *name, t_type *type); -void EnterEnumList(t_node *Idlist, register t_type *type); -void EnterFieldList(t_node *Idlist, register t_type *type, t_scope *scope, +struct def *Enter(char *name, int kind, struct type *type, int pnam); +struct def *EnterType(char *name, struct type *type); +void EnterEnumList(struct node *Idlist, register struct type *type); +void EnterFieldList(struct node *Idlist, register struct type *type, struct scope *scope, arith *addr); /* Enter a list of identifiers representing variables into the name list. "type" represents the type of the variables. "local" is set if the variables are declared local to a procedure. */ -void EnterVarList(t_node *Idlist, t_type *type, int local); +void EnterVarList(struct node *Idlist, struct type *type, int local); /* Create (part of) a parameterlist of a procedure. "ids" indicates the list of identifiers, "tp" their type, and "VARp" indicates D_VARPAR or D_VALPAR. */ -void EnterParamList(t_param **ppr, t_node *Idlist, t_type *type, +void EnterParamList(struct paramlist **ppr, struct node *Idlist, struct type *type, int VARp, arith *off); /* From the current scope, the list of identifiers "ids" is exported. Note this fact. If the export is not qualified, make all the "ids" visible in the enclosing scope by defining them in this scope as "imported". */ -void EnterExportList(t_node *Idlist, int qualified); -void CheckForImports(t_def *df); -void EnterFromImportList(t_node *idlist, t_def *FromDef, t_node *FromId); -void EnterImportList(t_node *idlist, int local, t_scope *sc); +void EnterExportList(struct node *Idlist, int qualified); +void CheckForImports(struct def *df); +void EnterFromImportList(struct node *idlist, struct def *FromDef, struct node *FromId); +void EnterImportList(struct node *idlist, int local, struct scope *sc); #endif /* ENTER_H_ */ diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 26a9f4a35..106abdbc2 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -62,7 +62,7 @@ extern char *symbol2str(); FileName, node errors get their information from the node, whereas other errors use the information in the token. */ -static void _error(int, t_node *, char *, register va_list, int); +static void _error(int, struct node *, char *, register va_list, int); #if __STDC__ #ifdef DEBUG @@ -92,7 +92,7 @@ void error(char *fmt, ...) } /*VARARGS*/ -void node_error(t_node *node, char *fmt, ...) +void node_error(struct node *node, char *fmt, ...) { va_list ap; @@ -116,7 +116,7 @@ void warning(int class, char *fmt, ...) } /*VARARGS*/ -void node_warning(t_node *node, int class, char *fmt, ...) +void node_warning(struct node *node, int class, char *fmt, ...) { va_list ap; @@ -219,7 +219,7 @@ void node_error(va_alist) va_start(ap); { - t_node *node = va_arg(ap, t_node *); + struct node *node = va_arg(ap, struct node *); char *fmt = va_arg(ap, char *); _error(ERROR, node, fmt, ap, 0); } @@ -249,7 +249,7 @@ void node_warning(va_alist) va_start(ap); { - t_node *nd = va_arg(ap, t_node *); + struct node *nd = va_arg(ap, struct node *); int class = va_arg(ap, int); char *fmt = va_arg(ap, char *); _error(WARNING, nd, fmt, ap, class); @@ -321,7 +321,7 @@ void crash(va_alist) } #endif -static void _error(int class, t_node *node, char *fmt, register va_list ap, int warn_class) +static void _error(int class, struct node *node, char *fmt, register va_list ap, int warn_class) { /* _error attempts to limit the number of error messages for a given line to MAXERR_LINE. diff --git a/lang/m2/comp/error.h b/lang/m2/comp/error.h index 0c8820214..57b80f595 100644 --- a/lang/m2/comp/error.h +++ b/lang/m2/comp/error.h @@ -8,7 +8,7 @@ #ifndef ERROR_H_ #define ERROR_H_ -typedef struct node t_node; +struct node; #if __STDC__ #ifdef DEBUG @@ -19,11 +19,11 @@ void debug(char *fmt, ...); /*VARARGS*/ void error(char *fmt, ...); /*VARARGS*/ -void node_error(t_node *node, char *fmt, ...); +void node_error(struct node *node, char *fmt, ...); /*VARARGS*/ void warning(int class, char *fmt, ...); /*VARARGS*/ -void node_warning(t_node *node, int class, char *fmt, ...); +void node_warning(struct node *node, int class, char *fmt, ...); /*VARARGS*/ void lexerror(char *fmt, ...); /*VARARGS*/ diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 074e77d06..24a193bf3 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -31,7 +31,7 @@ extern char options[]; } /* inline, we need room for pdp/11 -number(t_node **p;) : +number(struct node **p;) : [ %default INTEGER @@ -43,7 +43,7 @@ number(t_node **p;) : ; */ -qualident(t_node **p;) +qualident(struct node **p;) { } : IDENT { *p = dot2leaf(Name); } @@ -52,16 +52,16 @@ qualident(t_node **p;) ]* ; -selector(register t_node **pnd;) -{ t_node *nd; +selector(register struct node **pnd;) +{ struct node *nd; } : '.' { nd = dot2leaf(Select); nd->nd_NEXT = *pnd; *pnd = nd; } IDENT { (*pnd)->nd_IDF = dot.TOK_IDF; } ; -ExpList(t_node **pnd;) +ExpList(struct node **pnd;) { - register t_node *nd; + register struct node *nd; } : expression(pnd) { *pnd = nd = dot2node(Link,*pnd,NULLNODE); nd->nd_symb = ','; @@ -74,7 +74,7 @@ ExpList(t_node **pnd;) ]* ; -ConstExpression(register t_node **pnd;) +ConstExpression(register struct node **pnd;) { }: expression(pnd) @@ -98,7 +98,7 @@ ConstExpression(register t_node **pnd;) } ; -expression(register t_node **pnd;) +expression(register struct node **pnd;) { } : SimpleExpression(pnd) @@ -117,9 +117,9 @@ relation: ; */ -SimpleExpression(register t_node **pnd;) +SimpleExpression(register struct node **pnd;) { - register t_node *nd = 0; + register struct node *nd = 0; } : [ [ '+' | '-' ] @@ -150,9 +150,9 @@ AddOperator: ; */ -term(t_node **pnd;) +term(struct node **pnd;) { - register t_node *nd; + register struct node *nd; }: factor(pnd) { nd = *pnd; } [ @@ -170,10 +170,10 @@ MulOperator: ; */ -factor(register t_node **p;) +factor(register struct node **p;) { - register t_node *nd; - t_node *nd1; + register struct node *nd; + struct node *nd1; } : qualident(p) [ @@ -224,9 +224,9 @@ factor(register t_node **p;) factor(&((*p)->nd_RIGHT)) ; -bare_set(t_node **pnd;) +bare_set(struct node **pnd;) { - register t_node *nd; + register struct node *nd; } : '{' { DOT = SET; *pnd = nd = dot2leaf(Xset); @@ -242,11 +242,11 @@ bare_set(t_node **pnd;) '}' ; -ActualParameters(t_node **pnd;): +ActualParameters(struct node **pnd;): '(' ExpList(pnd)? ')' ; -element(register t_node *nd;) : +element(register struct node *nd;) : expression(&(nd->nd_RIGHT)) [ UPTO @@ -259,13 +259,13 @@ element(register t_node *nd;) : } ; -designator(t_node **pnd;) +designator(struct node **pnd;) : qualident(pnd) designator_tail(pnd) ; -designator_tail(register t_node **pnd;): +designator_tail(register struct node **pnd;): visible_designator_tail(pnd) [ %persistent %default @@ -276,9 +276,9 @@ designator_tail(register t_node **pnd;): | ; -visible_designator_tail(t_node **pnd;) +visible_designator_tail(struct node **pnd;) { - register t_node *nd = *pnd; + register struct node *nd = *pnd; }: '[' { nd = dot2node(Arrsel, nd, NULLNODE); } expression(&(nd->nd_RIGHT)) diff --git a/lang/m2/comp/idf.h b/lang/m2/comp/idf.h index deff12a79..d75a499e5 100644 --- a/lang/m2/comp/idf.h +++ b/lang/m2/comp/idf.h @@ -20,4 +20,4 @@ struct id_u { #include -typedef struct idf t_idf; + diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c index ba250c089..3938659bc 100644 --- a/lang/m2/comp/lookup.c +++ b/lang/m2/comp/lookup.c @@ -30,14 +30,14 @@ extern int pass_1; extern char options[]; #endif -t_def *lookup(register t_idf *id, t_scope *scope, int import, int flags) +struct def *lookup(register struct idf *id, struct scope *scope, int import, int flags) { /* Look up a definition of an identifier in scope "scope". Make the "def" list self-organizing. Return a pointer to its "def" structure if it exists, otherwise return 0. */ - register t_def *df, *df1; + register struct def *df, *df1; /* Look in the chain of definitions of this "id" for one with scope "scope". @@ -72,15 +72,15 @@ t_def *lookup(register t_idf *id, t_scope *scope, int import, int flags) return df; } -t_def *lookfor(register t_node *id, register t_scopelist *vis, int message, int flags) +struct def *lookfor(register struct node *id, register struct scopelist *vis, int message, int flags) { /* Look for an identifier in the visibility range started by "vis". If it is not defined create a dummy definition and, if message is set, give an error message */ - register t_scopelist *sc; - t_scopelist *sc1 = 0; - t_def *df; + register struct scopelist *sc; + struct scopelist *sc1 = 0; + struct def *df; for (sc = vis; sc; sc = nextvisible(sc)) { df = lookup(id->nd_IDF, sc->sc_scope, D_IMPORTED, flags); diff --git a/lang/m2/comp/lookup.h b/lang/m2/comp/lookup.h index 07b2c9bb3..22cb4aa8f 100644 --- a/lang/m2/comp/lookup.h +++ b/lang/m2/comp/lookup.h @@ -9,13 +9,13 @@ #define LOOKUP_H_ /* Forward declarations. */ -typedef struct idf t_idf; -typedef struct scope t_scope; -typedef struct node t_node; -typedef struct def t_def; -typedef struct scopelist t_scopelist; +struct idf; +struct scope; +struct node; +struct scopelist; +struct def; -t_def *lookup(register t_idf *id, t_scope *scope, int import, int flags); -t_def *lookfor(register t_node *id, register t_scopelist *vis, int message, int flags); +struct def *lookup(register struct idf *id, struct scope *scope, int import, int flags); +struct def *lookfor(register struct node *id, register struct scopelist *vis, int message, int flags); #endif /* LOOKUP_H_ */ diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 07562f257..28677eab6 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -47,11 +47,11 @@ char *ProgName; char **DEFPATH; int nDEF = 2, mDEF = 10; int pass_1 = 1; -t_def *Defined; +struct def *Defined; extern int err_occurred; extern int fp_used; /* set if floating point used */ -static t_node _emptystat = { Stat, 0, NULLTYPE, { ';' }}; -t_node *EmptyStatement = &_emptystat; +static struct node _emptystat = { Stat, 0, NULLTYPE, { ';' }}; +struct node *EmptyStatement = &_emptystat; /* Forward declarations. */ @@ -211,7 +211,7 @@ static struct stdproc sysprocs[] = { { 0, 0 } }; -extern t_def *Enter(), *EnterType(); +extern struct def *Enter(), *EnterType(); static void AddProcs(register struct stdproc *p) { @@ -224,7 +224,7 @@ static void AddProcs(register struct stdproc *p) static void AddStandards(void) { - register t_def *df; + register struct def *df; static t_token nilconst = { INTEGER, 0}; AddProcs(stdprocs); diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index 02781b4a7..031816f1d 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -25,7 +25,7 @@ #include "node.h" #include "error.h" -void match_id(register t_idf *id1, t_idf *id2) +void match_id(register struct idf *id1, struct idf *id2) { /* Check that identifiers id1 and id2 are equal. If they are not, check that we did'nt generate them in the @@ -39,7 +39,7 @@ void match_id(register t_idf *id1, t_idf *id2) } } -t_idf *gen_anon_idf(void) +struct idf *gen_anon_idf(void) { /* A new idf is created out of nowhere, to serve as an anonymous name. @@ -54,7 +54,7 @@ t_idf *gen_anon_idf(void) return str2idf(s, 0); } -void not_declared(char *what, t_node *id, char *where) +void not_declared(char *what, struct node *id, char *where) { /* The identifier "id" is not declared. If it is not generated, give an error message diff --git a/lang/m2/comp/misc.h b/lang/m2/comp/misc.h index 5b984822d..c625f8d8f 100644 --- a/lang/m2/comp/misc.h +++ b/lang/m2/comp/misc.h @@ -13,9 +13,9 @@ #define id_not_declared(x) (not_declared("identifier", (x), "")) /* Forward declarations. */ -typedef struct idf t_idf; -typedef struct node t_node; +struct idf; +struct node; -void match_id(register t_idf *id1, t_idf *id2); -t_idf *gen_anon_idf(void); -void not_declared(char *what, t_node *id, char *where); +void match_id(register struct idf *id1, struct idf *id2); +struct idf *gen_anon_idf(void); +void not_declared(char *what, struct node *id, char *where); diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index d30701232..100ec1abc 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -40,9 +40,9 @@ static int nsubnodes[] = { 2 }; -t_node *getnode(int class) +struct node *getnode(int class) { - register t_node *nd = new_node(); + register struct node *nd = new_node(); if (options['R']) nd->nd_flags |= ROPTION; if (options['A']) nd->nd_flags |= AOPTION; @@ -50,9 +50,9 @@ t_node *getnode(int class) return nd; } -t_node *dot2node(int class, t_node *left, t_node *right) +struct node *dot2node(int class, struct node *left, struct node *right) { - register t_node *nd = getnode(class); + register struct node *nd = getnode(class); nd->nd_symb = dot.tk_symb; nd->nd_lineno = dot.tk_lineno; @@ -61,9 +61,9 @@ t_node *dot2node(int class, t_node *left, t_node *right) return nd; } -t_node *dot2leaf(int class) +struct node *dot2leaf(int class) { - register t_node *nd = getnode(class); + register struct node *nd = getnode(class); nd->nd_token = dot; switch(nsubnodes[class]) { @@ -78,7 +78,7 @@ t_node *dot2leaf(int class) return nd; } -void FreeNode(register t_node *nd) +void FreeNode(register struct node *nd) { /* Put nodes that are no longer needed back onto the free list @@ -97,13 +97,13 @@ void FreeNode(register t_node *nd) } /*ARGSUSED*/ -int NodeCrash(register t_node* expp, label exit_label, int end_reached) +int NodeCrash(register struct node* expp, label exit_label, int end_reached) { crash("(NodeCrash) Illegal node"); } /*ARGSUSED*/ -int PNodeCrash(t_node **expp, int flags) +int PNodeCrash(struct node **expp, int flags) { crash("(PNodeCrash) Illegal node"); } @@ -119,7 +119,7 @@ void indnt(int lvl) } } -void printnode(register t_node *nd, int lvl) +void printnode(register struct node *nd, int lvl) { indnt(lvl); print("Class: %d; Symbol: %s; Flags: %d\n", nd->nd_class, symbol2str(nd->nd_symb), nd->nd_flags); @@ -131,7 +131,7 @@ void printnode(register t_node *nd, int lvl) } } -void PrNode(register t_node *nd, int lvl) +void PrNode(register struct node *nd, int lvl) { if (! nd) { indnt(lvl); print("\n"); diff --git a/lang/m2/comp/node.xh b/lang/m2/comp/node.xh index 469305d3a..27c3cf087 100644 --- a/lang/m2/comp/node.xh +++ b/lang/m2/comp/node.xh @@ -4,10 +4,15 @@ * * Author: Ceriel J.H. Jacobs */ +#ifndef NODE_H_ +#define NODE_H_ + +#include "em_arith.h" +#include "em_label.h" /* N O D E O F A N A B S T R A C T P A R S E T R E E */ -/* $Id$ */ + struct node { char nd_class; /* kind of node */ @@ -47,13 +52,13 @@ struct node { #define nd_RVAL nd_token.TOK_RVAL }; -typedef struct node t_node; + /* ALLOCDEF "node" 50 */ -extern t_node *dot2node(), *dot2leaf(), *getnode(); +extern struct node *dot2node(), *dot2leaf(), *getnode(); -#define NULLNODE ((t_node *) 0) +#define NULLNODE ((struct node *) 0) #define HASSELECTORS 002 #define VARIABLE 004 @@ -64,10 +69,11 @@ extern t_node *dot2node(), *dot2leaf(), *getnode(); -t_node *getnode(int class); -t_node *dot2node(int class, t_node *left, t_node *right); -t_node *dot2leaf(int class); -void FreeNode(register t_node *nd); -int NodeCrash(register t_node* expp, label exit_label, int end_reached); -int PNodeCrash(t_node **expp, int flags); +struct node *getnode(int class); +struct node *dot2node(int class, struct node *left, struct node *right); +struct node *dot2leaf(int class); +void FreeNode(register struct node *nd); +int NodeCrash(register struct node* expp, label exit_label, int end_reached); +int PNodeCrash(struct node **expp, int flags); +#endif /* NODE_H_ */ \ No newline at end of file diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 47a752fb0..4e6180793 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -36,7 +36,7 @@ #include "warning.h" #include "misc.h" -extern t_def *GetDefinitionModule(); +extern struct def *GetDefinitionModule(); } /* @@ -60,8 +60,8 @@ extern t_def *GetDefinitionModule(); ModuleDeclaration { - register t_def *df; - t_node *exportlist; + register struct def *df; + struct node *exportlist; int qualified; } : MODULE IDENT { df = DefineLocalModule(dot.TOK_IDF); } @@ -76,7 +76,7 @@ ModuleDeclaration } ; -priority(register t_node **prio;): +priority(register struct node **prio;): [ '[' ConstExpression(prio) ']' { if (! ((*prio)->nd_type->tp_fund & T_CARDINAL)) { @@ -87,7 +87,7 @@ priority(register t_node **prio;): ] ; -export(int *QUALflag; t_node **ExportList;): +export(int *QUALflag; struct node **ExportList;): { *ExportList = 0; *QUALflag = D_EXPORTED; } [ EXPORT @@ -103,9 +103,9 @@ export(int *QUALflag; t_node **ExportList;): import(int local;) { - t_node *ImportList; - register t_node *FromId = 0; - register t_def *df; + struct node *ImportList; + register struct node *FromId = 0; + register struct def *df; } : /* When parsing a global module, this is the place where we must @@ -139,13 +139,13 @@ import(int local;) DefinitionModule { - register t_def *df; - t_node *exportlist; + register struct def *df; + struct node *exportlist; int dummy; - extern t_idf *DefId; + extern struct idf *DefId; extern int ForeignFlag; extern char *sprint(); - register t_scope *currscope = CurrentScope; + register struct scope *currscope = CurrentScope; char buf[512]; } : DEFINITION @@ -196,8 +196,8 @@ node_warning(exportlist, W_OLDFASHIONED, "export list in definition module ignor definition { - register t_def *df; - t_def *dummy; + register struct def *df; + struct def *dummy; } : CONST [ %persistent ConstantDeclaration ';' ]* | @@ -231,7 +231,7 @@ definition ProgramModule { - register t_def *df; + register struct def *df; } : MODULE IDENT diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 41b4a97d7..17ff96546 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -9,7 +9,7 @@ #ifndef SCOPE_H_ #define SCOPE_H_ - +struct def; #define OPENSCOPE 0 /* Indicating an open scope */ #define CLOSEDSCOPE 1 /* Indicating a closed scope (module) */ @@ -45,13 +45,12 @@ struct scopelist { int sc_count; }; -typedef struct scope t_scope; -typedef struct scopelist t_scopelist; -extern t_scope + +extern struct scope *PervasiveScope; -extern t_scopelist +extern struct scopelist *CurrVis, *GlobalVis; #define CurrentScope (CurrVis->sc_scope) @@ -61,15 +60,15 @@ extern t_scopelist #define nextvisible(x) ((x)->sc_next) /* use with scopelists */ -typedef struct def t_def; -void Reverse(t_def **pdf); + +void Reverse(struct def **pdf); void open_scope(int scopetype); -t_scope * open_and_close_scope(int scopetype); +struct scope * open_and_close_scope(int scopetype); void InitScope(void); void close_scope(int flag); #ifdef DEBUG -void DumpScope(register t_def *df); +void DumpScope(register struct def *df); #endif diff --git a/lang/m2/comp/scope.xc b/lang/m2/comp/scope.xc index def89b35e..9fa1ca7d5 100644 --- a/lang/m2/comp/scope.xc +++ b/lang/m2/comp/scope.xc @@ -26,8 +26,8 @@ #include "lookup.h" #include "error.h" -t_scope *PervasiveScope; -t_scopelist *CurrVis, *GlobalVis; +struct scope *PervasiveScope; +struct scopelist *CurrVis, *GlobalVis; extern int proclevel; extern char options[]; @@ -41,8 +41,8 @@ void open_scope(int scopetype) { /* Open a scope that is either open (automatic imports) or closed. */ - register t_scope *sc = new_scope(); - register t_scopelist *ls = new_scopelist(); + register struct scope *sc = new_scope(); + register struct scopelist *ls = new_scopelist(); assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); @@ -57,9 +57,9 @@ void open_scope(int scopetype) CurrVis = ls; } -t_scope * open_and_close_scope(int scopetype) +struct scope * open_and_close_scope(int scopetype) { - t_scope *sc; + struct scope *sc; open_scope(scopetype); sc = CurrentScope; @@ -69,8 +69,8 @@ t_scope * open_and_close_scope(int scopetype) void InitScope(void) { - register t_scope *sc = new_scope(); - register t_scopelist *ls = new_scopelist(); + register struct scope *sc = new_scope(); + register struct scopelist *ls = new_scopelist(); sc->sc_level = proclevel; PervasiveScope = sc; @@ -78,7 +78,7 @@ void InitScope(void) CurrVis = ls; } -static void chk_proc(register t_def *df) +static void chk_proc(register struct def *df) { /* Called at scope closing. Check all definitions, and if one is a D_PROCHEAD, the procedure was not defined. @@ -100,13 +100,13 @@ static void chk_proc(register t_def *df) } } -static void chk_forw(t_def **pdf) +static void chk_forw(struct def **pdf) { /* Called at scope close. Look for all forward definitions and if the scope was a closed scope, give an error message for them, and otherwise move them to the enclosing scope. */ - register t_def *df; + register struct def *df; while ( (df = *pdf) ) { if (df->df_kind == D_FORWTYPE) { @@ -131,9 +131,9 @@ df->df_idf->id_text); Maybe the definitions are in the enclosing scope? */ - register t_scopelist *ls = + register struct scopelist *ls = nextvisible(CurrVis); - register t_def *df1 = lookup(df->df_idf, ls->sc_scope, 0, 0); + register struct def *df1 = lookup(df->df_idf, ls->sc_scope, 0, 0); *pdf = df->df_nextinscope; @@ -154,14 +154,14 @@ df->df_idf->id_text); } } -void Reverse(t_def **pdf) +void Reverse(struct def **pdf) { /* Reverse the order in the list of definitions in a scope. This is neccesary because this list is built in reverse. Also, while we're at it, remove uninteresting definitions from this list. */ - register t_def *df, *df1; + register struct def *df, *df1; #define INTERESTING (D_MODULE|D_PROCEDURE|D_PROCHEAD|D_VARIABLE|D_IMPORTED|D_TYPE|D_CONST|D_FIELD) df = 0; @@ -169,7 +169,7 @@ void Reverse(t_def **pdf) while (df1) { if (df1->df_kind & INTERESTING) { - t_def *prev = df; + struct def *prev = df; df = df1; df1 = df1->df_nextinscope; @@ -186,7 +186,7 @@ void close_scope(int flag) either POINTER declarations, or EXPORTs, or forward references to MODULES */ - register t_scope *sc = CurrentScope; + register struct scope *sc = CurrentScope; assert(sc != 0); @@ -203,7 +203,7 @@ void close_scope(int flag) } #ifdef DEBUG -void DumpScope(register t_def *df) +void DumpScope(register struct def *df) { while (df) { PrDef(df); diff --git a/lang/m2/comp/stab.c b/lang/m2/comp/stab.c index 47b2cfa69..2f09ec925 100644 --- a/lang/m2/comp/stab.c +++ b/lang/m2/comp/stab.c @@ -68,7 +68,7 @@ static void adds_db_str(char *s) while (*s) addc_db_str(*s++); } -static void stb_type(register t_type *tp, int assign_num) +static void stb_type(register struct type *tp, int assign_num) { char buf[128]; static int stb_count; @@ -249,7 +249,7 @@ static void stb_type(register t_type *tp, int assign_num) } } -void stb_addtp(char *s, t_type *tp) +void stb_addtp(char *s, struct type *tp) { create_db_str(); adds_db_str(s); @@ -265,9 +265,9 @@ void stb_addtp(char *s, t_type *tp) (arith) 0); } -void stb_string(register t_def *df, int kind) +void stb_string(register struct def *df, int kind) { - register t_type *tp = df->df_type; + register struct type *tp = df->df_type; char buf[64]; create_db_str(); @@ -291,10 +291,10 @@ void stb_string(register t_def *df, int kind) else adds_db_str(sprint(buf, "Q%d;", df->prc_vis->sc_count)); stb_type(tp->tp_next ? tp->tp_next : void_type, 0); if (gdb_flag) { - t_scopelist *sc = df->prc_vis; + struct scopelist *sc = df->prc_vis; sc = enclosing(sc); while (sc) { - t_def *d = sc->sc_scope->sc_definedby; + struct def *d = sc->sc_scope->sc_definedby; if (d && d->df_kind == D_PROCEDURE) { adds_db_str(sprint(buf, ",%s", d->df_idf->id_text)); diff --git a/lang/m2/comp/stab.h b/lang/m2/comp/stab.h index 0cddb0ee9..6bb75221b 100644 --- a/lang/m2/comp/stab.h +++ b/lang/m2/comp/stab.h @@ -9,11 +9,11 @@ #define STAB_H_ /* D E B U G G E R S Y M B O L T A B L E */ -typedef struct type t_type; -typedef struct def t_def; -void stb_addtp(char *s, t_type *tp); -void stb_string(register t_def *df, int kind); +struct def; + +void stb_addtp(char *s, struct type *tp); +void stb_string(register struct def *df, int kind); #endif /* STAB_H_ */ diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 1a3deec48..c6fc933e4 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -24,12 +24,12 @@ #include "node.h" static int loopcount = 0; /* Count nested loops */ -extern t_node *EmptyStatement; +extern struct node *EmptyStatement; } -statement(register t_node **pnd;) +statement(register struct node **pnd;) { - register t_node *nd; + register struct node *nd; extern int return_occurred; } : /* @@ -110,10 +110,10 @@ ProcedureCall: ; */ -StatementSequence(register t_node **pnd;) +StatementSequence(register struct node **pnd;) { - t_node *nd; - register t_node *nd1; + struct node *nd; + register struct node *nd1; } : statement(pnd) [ %persistent @@ -129,9 +129,9 @@ StatementSequence(register t_node **pnd;) ]* ; -IfStatement(t_node **pnd;) +IfStatement(struct node **pnd;) { - register t_node *nd; + register struct node *nd; } : IF { nd = dot2leaf(Stat); *pnd = nd; @@ -160,10 +160,10 @@ IfStatement(t_node **pnd;) END ; -CaseStatement(t_node **pnd;) +CaseStatement(struct node **pnd;) { - register t_node *nd; - t_type *tp = 0; + register struct node *nd; + struct type *tp = 0; } : CASE { *pnd = nd = dot2leaf(Stat); } expression(&(nd->nd_LEFT)) @@ -181,7 +181,7 @@ CaseStatement(t_node **pnd;) END ; -case(t_node **pnd; t_type **ptp;) : +case(struct node **pnd; struct type **ptp;) : [ CaseLabelList(ptp, pnd) ':' { *pnd = dot2node(Link, *pnd, NULLNODE); } StatementSequence(&((*pnd)->nd_RIGHT)) @@ -193,9 +193,9 @@ case(t_node **pnd; t_type **ptp;) : ; /* inline in statement; lack of space -WhileStatement(t_node **pnd;) +WhileStatement(struct node **pnd;) { - register t_node *nd; + register struct node *nd; }: WHILE { *pnd = nd = dot2leaf(Stat); } expression(&(nd->nd_LEFT)) @@ -204,9 +204,9 @@ WhileStatement(t_node **pnd;) END ; -RepeatStatement(t_node **pnd;) +RepeatStatement(struct node **pnd;) { - register t_node *nd; + register struct node *nd; }: REPEAT { *pnd = nd = dot2leaf(Stat); } StatementSequence(&(nd->nd_LEFT)) @@ -215,9 +215,9 @@ RepeatStatement(t_node **pnd;) ; */ -ForStatement(t_node **pnd;) +ForStatement(struct node **pnd;) { - register t_node *nd, *nd1; + register struct node *nd, *nd1; }: FOR { *pnd = nd = dot2leaf(Stat); } IDENT { nd1 = dot2leaf(Name); } @@ -249,15 +249,15 @@ ForStatement(t_node **pnd;) ; /* inline in Statement; lack of space -LoopStatement(t_node **pnd;): +LoopStatement(struct node **pnd;): LOOP { *pnd = dot2leaf(Stat); } StatementSequence(&((*pnd)->nd_RIGHT)) END ; -WithStatement(t_node **pnd;) +WithStatement(struct node **pnd;) { - register t_node *nd; + register struct node *nd; }: WITH { *pnd = nd = dot2leaf(Stat); } designator(&(nd->nd_LEFT)) @@ -267,11 +267,11 @@ WithStatement(t_node **pnd;) ; */ -ReturnStatement(t_node **pnd;) +ReturnStatement(struct node **pnd;) { - register t_def *df = CurrentScope->sc_definedby; - register t_type *tp = df->df_type ? ResultType(df->df_type) : 0; - register t_node *nd; + register struct def *df = CurrentScope->sc_definedby; + register struct type *tp = df->df_type ? ResultType(df->df_type) : 0; + register struct node *nd; } : RETURN { *pnd = nd = dot2leaf(Stat); } diff --git a/lang/m2/comp/tmpvar.h b/lang/m2/comp/tmpvar.h index b47c8e23d..1d27f8ee0 100644 --- a/lang/m2/comp/tmpvar.h +++ b/lang/m2/comp/tmpvar.h @@ -11,9 +11,9 @@ #include "em_arith.h" -typedef struct scope t_scope; +struct scope; -void TmpOpen(t_scope *sc); +void TmpOpen(struct scope *sc); arith TmpSpace(arith sz, int al); arith NewInt(void); arith NewPtr(void); diff --git a/lang/m2/comp/tmpvar.xc b/lang/m2/comp/tmpvar.xc index 2ff421012..980cfadc3 100644 --- a/lang/m2/comp/tmpvar.xc +++ b/lang/m2/comp/tmpvar.xc @@ -42,11 +42,11 @@ struct tmpvar { static struct tmpvar *TmpInts, /* for integer temporaries */ *TmpPtrs; /* for pointer temporaries */ -static t_scope *ProcScope; /* scope of procedure in which the +static struct scope *ProcScope; /* scope of procedure in which the temporaries are allocated */ -void TmpOpen(t_scope *sc) +void TmpOpen(struct scope *sc) { /* Initialize for temporaries in scope "sc". */ @@ -55,7 +55,7 @@ void TmpOpen(t_scope *sc) arith TmpSpace(arith sz, int al) { - register t_scope *sc = ProcScope; + register struct scope *sc = ProcScope; sc->sc_off = - WA(align(sz - sc->sc_off, al)); return sc->sc_off; diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index a732404db..d21ffda48 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -104,7 +104,7 @@ void reserve(register struct tokenname *resv) /* The names of the tokens described in resv are entered as reserved words. */ - register t_idf *p; + register struct idf *p; while (resv->tn_symbol) { p = str2idf(resv->tn_name, 0); diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 01355c7b7..dc1c6050c 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -59,7 +59,7 @@ arith arith ret_area_size; -t_type +struct type *bool_type, *char_type, *int_type, @@ -79,12 +79,12 @@ t_type *error_type; -t_type *construct_type(int fund, register t_type *tp) +struct type *construct_type(int fund, register struct type *tp) { /* fund must be a type constructor. The pointer to the constructed type is returned. */ - register t_type *dtp = new_type(); + register struct type *dtp = new_type(); switch (dtp->tp_fund = fund) { case T_PROCEDURE: @@ -129,9 +129,9 @@ arith align(arith pos, int al) return pos; } -t_type *standard_type(int fund, int algn, arith size) +struct type *standard_type(int fund, int algn, arith size) { - register t_type *tp = new_type(); + register struct type *tp = new_type(); tp->tp_fund = fund; tp->tp_align = algn; @@ -145,7 +145,7 @@ t_type *standard_type(int fund, int algn, arith size) void InitTypes(void) { - register t_type *tp; + register struct type *tp; /* first, do some checking */ @@ -221,7 +221,7 @@ int fit(arith sz, int nbytes) return ((sz) + ((arith)0x80<<(((nbytes)-1)*8)) & ~full_mask[(nbytes)]) == 0; } -static void u_small(register t_type *tp, arith n) +static void u_small(register struct type *tp, arith n) { if (ufit(n, 1)) { tp->tp_size = 1; @@ -233,9 +233,9 @@ static void u_small(register t_type *tp, arith n) } } -t_type *enum_type(t_node *EnumList) +struct type *enum_type(struct node *EnumList) { - register t_type *tp = + register struct type *tp = standard_type(T_ENUMERATION, int_align, int_size); EnterEnumList(EnumList, tp); @@ -246,12 +246,12 @@ t_type *enum_type(t_node *EnumList) return tp; } -t_type *qualified_type(t_node **pnd) +struct type *qualified_type(struct node **pnd) { - register t_def *df; + register struct def *df; if (ChkDesig(pnd, D_USED)) { - register t_node *nd = *pnd; + register struct node *nd = *pnd; if (nd->nd_class != Def) { node_error(nd, "type expected"); FreeNode(nd); @@ -291,7 +291,7 @@ int chk_bounds(arith l1, arith l2, int fund) return (unsigned arith) l2 >= (unsigned arith) l1; } -int in_range(arith i, register t_type *tp) +int in_range(arith i, register struct type *tp) { @@ -308,10 +308,10 @@ int in_range(arith i, register t_type *tp) /*NOTREACHED*/ } -t_type *subr_type(t_node *lb, t_node *ub, t_type *base) +struct type *subr_type(struct node *lb, struct node *ub, struct type *base) { - register t_type *tp = BaseType(lb->nd_type); - register t_type *res; + register struct type *tp = BaseType(lb->nd_type); + register struct type *res; if (tp == intorcard_type) { /* Lower bound >= 0; in this case, the base type is CARDINAL, @@ -398,9 +398,9 @@ t_type *subr_type(t_node *lb, t_node *ub, t_type *base) return res; } -t_type *proc_type(t_type *result_type, t_param *parameters, arith n_bytes_params) +struct type *proc_type(struct type *result_type, struct paramlist *parameters, arith n_bytes_params) { - register t_type *tp = construct_type(T_PROCEDURE, result_type); + register struct type *tp = construct_type(T_PROCEDURE, result_type); tp->prc_params = parameters; tp->prc_nbpar = n_bytes_params; @@ -413,7 +413,7 @@ t_type *proc_type(t_type *result_type, t_param *parameters, arith n_bytes_params return tp; } -void genrck(register t_type *tp) +void genrck(register struct type *tp) { /* generate a range check descriptor for type "tp" when neccessary. Return its label. @@ -421,7 +421,7 @@ void genrck(register t_type *tp) arith lb, ub; register label ol; arith size = tp->tp_size; - register t_type *btp = BaseType(tp); + register struct type *btp = BaseType(tp); if (size < word_size) size = word_size; getbounds(tp, &lb, &ub); @@ -448,7 +448,7 @@ void genrck(register t_type *tp) } } -void getbounds(register t_type *tp, arith *plo, arith *phi) +void getbounds(register struct type *tp, arith *plo, arith *phi) { assert(bounded(tp)); @@ -462,7 +462,7 @@ void getbounds(register t_type *tp, arith *plo, arith *phi) } } -t_type *set_type(register t_type *tp) +struct type *set_type(register struct type *tp) { arith lb, ub, diff, alloc_size; @@ -498,14 +498,14 @@ t_type *set_type(register t_type *tp) return tp; } -void ArrayElSize(register t_type *tp) +void ArrayElSize(register struct type *tp) { /* Align element size to alignment requirement of element type. Also make sure that its size is either a dividor of the word_size, or a multiple of it. */ register arith algn; - register t_type *elem_type = tp->arr_elem; + register struct type *elem_type = tp->arr_elem; if (elem_type->tp_fund == T_ARRAY) ArraySizes(elem_type); algn = align(elem_type->tp_size, elem_type->tp_align); @@ -524,11 +524,11 @@ void ArrayElSize(register t_type *tp) } } -void ArraySizes(register t_type *tp) +void ArraySizes(register struct type *tp) { /* Assign sizes to an array type, and check index type */ - register t_type *index_type = IndexType(tp); + register struct type *index_type = IndexType(tp); arith diff; ArrayElSize(tp); @@ -563,13 +563,13 @@ void ArraySizes(register t_type *tp) C_rom_cst(tp->arr_elsize); } -void FreeType(register t_type *tp) +void FreeType(register struct type *tp) { /* Release type structures indicated by "tp". This procedure is only called for types, constructed with T_PROCEDURE. */ - register t_param *pr, *pr1; + register struct paramlist *pr, *pr1; assert(tp->tp_fund == T_PROCEDURE); @@ -584,7 +584,7 @@ void FreeType(register t_type *tp) free_type(tp); } -void DeclareType(t_node *nd, register t_def *df, register t_type *tp) +void DeclareType(struct node *nd, register struct def *df, register struct type *tp) { /* A type with type-description "tp" is declared and must be bound to definition "df". @@ -592,7 +592,7 @@ void DeclareType(t_node *nd, register t_def *df, register t_type *tp) "df" is already bound. In that case, it is either an opaque type, or an error message was given when "df" was created. */ - register t_type *df_tp = df->df_type; + register struct type *df_tp = df->df_type; if (df_tp && df_tp->tp_fund == T_HIDDEN) { if (! (tp->tp_fund & (T_POINTER|T_HIDDEN|T_EQUAL))) { @@ -626,9 +626,9 @@ void DeclareType(t_node *nd, register t_def *df, register t_type *tp) SolveForwardTypeRefs(df); } -void SolveForwardTypeRefs(register t_def *df) +void SolveForwardTypeRefs(register struct def *df) { - register t_node *nd; + register struct node *nd; if (df->df_kind == D_FORWTYPE) { nd = df->df_forw_node; @@ -648,10 +648,10 @@ void SolveForwardTypeRefs(register t_def *df) } -void ForceForwardTypeDef(register t_def *df) +void ForceForwardTypeDef(register struct def *df) { - register t_def *df1 = df, *df2; - register t_node *nd = df->df_forw_node; + register struct def *df1 = df, *df2; + register struct node *nd = df->df_forw_node; while (df && df->df_kind == D_FORWTYPE) { RemoveFromIdList(df); @@ -682,20 +682,20 @@ void ForceForwardTypeDef(register t_def *df) } } -t_type *RemoveEqual(register t_type *tpx) +struct type *RemoveEqual(register struct type *tpx) { if (tpx) while (tpx->tp_fund == T_EQUAL) tpx = tpx->tp_next; return tpx; } -int type_or_forward(t_type *tp) +int type_or_forward(struct type *tp) { /* POINTER TO IDENTIFIER construction. The IDENTIFIER resides in "dot". This routine handles the different cases. */ - register t_node *nd; - register t_def *df, *df1; + register struct node *nd; + register struct def *df, *df1; if ((df1 = lookup(dot.TOK_IDF, CurrentScope, D_IMPORTED, D_USED))) { /* Either a Module or a Type, but in both cases defined @@ -773,10 +773,10 @@ int lcm(int m, int n) return m * (n / gcd(m, n)); } -t_type *intorcard(register t_type *left, register t_type *right) +struct type *intorcard(register struct type *left, register struct type *right) { if (left->tp_fund == T_INTORCARD) { - t_type *tmp = left; + struct type *tmp = left; left = right; right = tmp; } @@ -789,7 +789,7 @@ t_type *intorcard(register t_type *left, register t_type *right) } #ifdef DEBUG -void DumpType(register t_type *tp) +void DumpType(register struct type *tp) { if (!tp) return; @@ -825,7 +825,7 @@ void DumpType(register t_type *tp) break; case T_PROCEDURE: { - register t_param *par = ParamList(tp); + register struct paramlist *par = ParamList(tp); print("PROCEDURE"); if (par) { diff --git a/lang/m2/comp/type.xh b/lang/m2/comp/type.xh index 5c69b1463..98b14f3ca 100644 --- a/lang/m2/comp/type.xh +++ b/lang/m2/comp/type.xh @@ -13,8 +13,8 @@ -typedef struct def t_def; -typedef struct node t_node; +struct def; +struct node; struct paramlist { /* structure for parameterlist of a PROCEDURE */ struct paramlist *par_next; @@ -23,7 +23,7 @@ struct paramlist { /* structure for parameterlist of a PROCEDURE */ #define TypeOfParam(xpar) ((xpar)->par_def->df_type) }; -typedef struct paramlist t_param; +struct paramlist; /* ALLOCDEF "paramlist" 20 */ @@ -124,11 +124,11 @@ struct type { } tp_value; }; -typedef struct type t_type; +struct type; /* ALLOCDEF "type" 50 */ -extern t_type +extern struct type *bool_type, *char_type, *int_type, @@ -198,7 +198,7 @@ extern arith -#define NULLTYPE ((t_type *) 0) +#define NULLTYPE ((struct type *) 0) #define IsConformantArray(tpx) ((tpx)->tp_fund==T_ARRAY && (tpx)->tp_size==0) #define bounded(tpx) ((tpx)->tp_fund & T_INDEX) @@ -250,37 +250,37 @@ int chk_bounds(arith l1, arith l2, int fund); arith align(arith pos, int al); /* Create a new standard type "fund" with specified alignment "algn" and "size" bytes. */ -t_type *standard_type(int fund, int algn, arith size); -t_type *enum_type(t_node *EnumList); -t_type *construct_type(int fund, register t_type *tp); -t_type *qualified_type(t_node **pnd); +struct type *standard_type(int fund, int algn, arith size); +struct type *enum_type(struct node *EnumList); +struct type *construct_type(int fund, register struct type *tp); +struct type *qualified_type(struct node **pnd); /* Check that the value "i" fits in the subrange or enumeration type "tp". Return 1 if so, 0 otherwise */ -int in_range(arith i, register t_type *tp); +int in_range(arith i, register struct type *tp); /* Construct a subrange type from the constant expressions indicated by "lb" and "ub", but first perform some checks. "base" is either a user-specified base-type, or NULL. */ -t_type *subr_type(t_node *lb, t_node *ub, t_type *base); -t_type *proc_type(t_type *result_type, t_param *parameters, arith n_bytes_params); -void genrck(register t_type *tp); +struct type *subr_type(struct node *lb, struct node *ub, struct type *base); +struct type *proc_type(struct type *result_type, struct paramlist *parameters, arith n_bytes_params); +void genrck(register struct type *tp); /* Get the bounds of a bounded type. */ -void getbounds(register t_type *tp, arith *plo, arith *phi); +void getbounds(register struct type *tp, arith *plo, arith *phi); /* Construct a set type with base type "tp", but first * perform some checks */ -t_type *set_type(register t_type *tp); -void ArrayElSize(register t_type *tp); -void ArraySizes(register t_type *tp); -void FreeType(register t_type *tp); -void DeclareType(t_node *nd, register t_def *df, register t_type *tp); -void SolveForwardTypeRefs(register t_def *df); -void ForceForwardTypeDef(register t_def *df); -t_type *RemoveEqual(register t_type *tpx); -int type_or_forward(t_type *tp); -t_type *intorcard(register t_type *left, register t_type *right); +struct type *set_type(register struct type *tp); +void ArrayElSize(register struct type *tp); +void ArraySizes(register struct type *tp); +void FreeType(register struct type *tp); +void DeclareType(struct node *nd, register struct def *df, register struct type *tp); +void SolveForwardTypeRefs(register struct def *df); +void ForceForwardTypeDef(register struct def *df); +struct type *RemoveEqual(register struct type *tpx); +int type_or_forward(struct type *tp); +struct type *intorcard(register struct type *left, register struct type *right); #ifdef DEBUG -void DumpType(register t_type *tp); +void DumpType(register struct type *tp); #endif int fit(arith sz, int nbytes); /* Greatest common divisotr. */ diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 03f6facf4..b622fa3b2 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -35,7 +35,7 @@ #include "chk_expr.h" -static int TstTypeEquiv(t_type *tp1, t_type *tp2) +static int TstTypeEquiv(struct type *tp1, struct type *tp2) { /* test if two types are equivalent. */ @@ -45,7 +45,7 @@ static int TstTypeEquiv(t_type *tp1, t_type *tp2) (tp2 == error_type); } -static int TstParEquiv(register t_type *tp1, register t_type *tp2) +static int TstParEquiv(register struct type *tp1, register struct type *tp2) { /* test if two parameter types are equivalent. This routine is used to check if two different procedure declarations @@ -66,13 +66,13 @@ static int TstParEquiv(register t_type *tp1, register t_type *tp2) ); } -int TstProcEquiv(t_type *tp1, t_type *tp2) +int TstProcEquiv(struct type *tp1, struct type *tp2) { /* Test if two procedure types are equivalent. This routine may also be used for the testing of assignment compatibility between procedure variables and procedures. */ - register t_param *p1, *p2; + register struct paramlist *p1, *p2; /* First check if the result types are equivalent */ @@ -96,7 +96,7 @@ int TstProcEquiv(t_type *tp1, t_type *tp2) return p1 == p2; } -int TstCompat(register t_type *tp1, register t_type *tp2) +int TstCompat(register struct type *tp1, register struct type *tp2) { /* test if two types are compatible. See section 6.3 of the Modula-2 Report for a definition of "compatible". @@ -108,7 +108,7 @@ int TstCompat(register t_type *tp1, register t_type *tp2) tp2 = BaseType(tp2); if (tp2->tp_fund != T_INTORCARD && (tp1->tp_fund == T_INTORCARD || tp1 == address_type)) { - t_type *tmp = tp2; + struct type *tmp = tp2; tp2 = tp1; tp1 = tmp; @@ -133,7 +133,7 @@ int TstCompat(register t_type *tp1, register t_type *tp2) ; } -int TstAssCompat(register t_type *tp1, register t_type *tp2) +int TstAssCompat(register struct type *tp1, register struct type *tp2) { /* Test if two types are assignment compatible. See Def 9.1. @@ -170,7 +170,7 @@ int TstAssCompat(register t_type *tp1, register t_type *tp2) return 0; } -char *incompat(register t_type *tp1, register t_type *tp2) +char *incompat(register struct type *tp1, register struct type *tp2) { if (tp1->tp_fund == T_HIDDEN || tp2->tp_fund == T_HIDDEN) { @@ -179,7 +179,7 @@ char *incompat(register t_type *tp1, register t_type *tp2) return "type incompatibility"; } -int TstParCompat(int parno, register t_type *formaltype, int VARflag, t_node **nd, t_def *edf) +int TstParCompat(int parno, register struct type *formaltype, int VARflag, struct node **nd, struct def *edf) { /* Check type compatibility for a parameter in a procedure call. Assignment compatibility may do if the parameter is @@ -188,7 +188,7 @@ int TstParCompat(int parno, register t_type *formaltype, int VARflag, t_node **n may do too. Or: a WORD may do. */ - register t_type *actualtype = (*nd)->nd_type; + register struct type *actualtype = (*nd)->nd_type; char ebuf[256]; if (edf) { @@ -255,7 +255,7 @@ int TstParCompat(int parno, register t_type *formaltype, int VARflag, t_node **n return 0; } -int CompatCheck(register t_node **nd, t_type *tp, char *message, int (*fc)()) +int CompatCheck(register struct node **nd, struct type *tp, char *message, int (*fc)()) { if (! (*fc)(tp, (*nd)->nd_type)) { if (message) { @@ -269,7 +269,7 @@ int CompatCheck(register t_node **nd, t_type *tp, char *message, int (*fc)()) return 1; } -int ChkAssCompat(t_node **nd, t_type *tp, char *message) +int ChkAssCompat(struct node **nd, struct type *tp, char *message) { /* Check assignment compatibility of node "nd" with type "tp". Give an error message when it fails @@ -281,7 +281,7 @@ int ChkAssCompat(t_node **nd, t_type *tp, char *message) return CompatCheck(nd, tp, message, TstAssCompat); } -int ChkCompat(t_node **nd, t_type *tp, char *message) +int ChkCompat(struct node **nd, struct type *tp, char *message) { /* Check compatibility of node "nd" with type "tp". Give an error message when it fails diff --git a/lang/m2/comp/typequiv.h b/lang/m2/comp/typequiv.h index 5731273cb..ff1985409 100644 --- a/lang/m2/comp/typequiv.h +++ b/lang/m2/comp/typequiv.h @@ -8,18 +8,19 @@ #ifndef TYPEQUIV_H_ #define TYPEQUIV_H_ -typedef struct type t_type; -typedef struct node t_node; -typedef struct def t_def; -int TstProcEquiv(t_type *tp1, t_type *tp2); -int TstCompat(register t_type *tp1, register t_type *tp2); -int TstAssCompat(register t_type *tp1, register t_type *tp2); -int TstParCompat(int parno, register t_type *formaltype, int VARflag, t_node **nd, t_def *edf); +struct node; +struct def; +struct type; -int ChkCompat(t_node **nd, t_type *tp, char *message); -int ChkAssCompat(t_node **nd, t_type *tp, char *message); +int TstProcEquiv(struct type *tp1, struct type *tp2); +int TstCompat(register struct type *tp1, register struct type *tp2); +int TstAssCompat(register struct type *tp1, register struct type *tp2); +int TstParCompat(int parno, register struct type *formaltype, int VARflag, struct node **nd, struct def *edf); -char *incompat(register t_type *tp1, register t_type *tp2); +int ChkCompat(struct node **nd, struct type *tp, char *message); +int ChkAssCompat(struct node **nd, struct type *tp, char *message); + +char *incompat(register struct type *tp1, register struct type *tp2); #endif /* TYPEQUIV_H_ */ diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 9c2a3bf4e..2e7562e1b 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -47,7 +47,7 @@ #include "code.h" #include "warning.h" -int CaseCode(t_node *, label, int); +int CaseCode(struct node *, label, int); extern int proclevel; extern int gdb_flag; @@ -55,10 +55,10 @@ extern int gdb_flag; label text_label; label data_label = 1; struct withdesig* WithDesigs; -t_node* Modules; +struct node* Modules; -static t_type* func_type; -static t_node* priority; +static struct type* func_type; +static struct node* priority; static int oldlineno; @@ -71,17 +71,17 @@ static int oldlineno; #define EXIT_FLAG 2 /* Forward declarations. */ -static void WalkDef(register t_def*); -static void MkCalls(register t_def*); -static void UseWarnings(register t_def*); -static void RegisterMessage(register t_def*); -static void WalkDefList(register t_def*, void (*proc)(t_def*)); +static void WalkDef(register struct def*); +static void MkCalls(register struct def*); +static void UseWarnings(register struct def*); +static void RegisterMessage(register struct def*); +static void WalkDefList(register struct def*, void (*proc)(struct def*)); #ifdef DBSYMTAB -static void stabdef(t_def*); +static void stabdef(struct def*); #endif -int LblWalkNode(label lbl, t_node *nd, int exit, int reach) +int LblWalkNode(label lbl, struct node *nd, int exit, int reach) { /* Generate code for node "nd", after generating instruction label "lbl". "exit" is the exit label for the closest @@ -127,7 +127,7 @@ void def_ilb(label l) oldlineno = 0; } -void DoLineno(register t_node* nd) +void DoLineno(register struct node* nd) { if ((!options['L'] #ifdef DBSYMTAB @@ -173,10 +173,10 @@ void DoFilename(int needed) } } -void WalkModule(register t_def* module) +void WalkModule(register struct def* module) { - register t_scope* sc; - t_scopelist* savevis = CurrVis; + register struct scope* sc; + struct scopelist* savevis = CurrVis; CurrVis = module->mod_vis; priority = module->mod_priority; @@ -216,7 +216,7 @@ void WalkModule(register t_def* module) Call initialization routines of imported modules. Also prevent recursive calls of this one. */ - register t_node* nd = Modules; + register struct node* nd = Modules; if (state == IMPLEMENTATION) { @@ -273,13 +273,13 @@ void WalkModule(register t_def* module) WalkDefList(sc->sc_def, UseWarnings); } -void WalkProcedure(register t_def* procedure) +void WalkProcedure(register struct def* procedure) { - t_scopelist* savevis = CurrVis; - register t_type* tp; - register t_param* param; - register t_scope* procscope = procedure->prc_vis->sc_scope; + struct scopelist* savevis = CurrVis; + register struct type* tp; + register struct paramlist* param; + register struct scope* procscope = procedure->prc_vis->sc_scope; label too_big = 0; /* returnsize larger than returnarea */ arith StackAdjustment = 0; /* space for conformant arrays */ arith retsav = 0; /* temporary space for return value */ @@ -562,7 +562,7 @@ void WalkProcedure(register t_def* procedure) } /* Walk through a list of definitions */ -static void WalkDef(register t_def* df) +static void WalkDef(register struct def* df) { @@ -590,7 +590,7 @@ static void WalkDef(register t_def* df) } /* Generate calls to initialization routines of modules */ -static void MkCalls(register t_def* df) +static void MkCalls(register struct def* df) { @@ -601,7 +601,7 @@ static void MkCalls(register t_def* df) } } -int WalkLink(register t_node* nd, label exit_label, int end_reached) +int WalkLink(register struct node* nd, label exit_label, int end_reached) { while (nd && nd->nd_class == Link) @@ -613,19 +613,19 @@ int WalkLink(register t_node* nd, label exit_label, int end_reached) return WalkNode(nd, exit_label, end_reached); } -static void ForLoopVarExpr(register t_node* nd) +static void ForLoopVarExpr(register struct node* nd) { - register t_type* tp = nd->nd_type; + register struct type* tp = nd->nd_type; CodePExpr(nd); CodeCoercion(tp, BaseType(tp)); } -int WalkStat(register t_node* nd, label exit_label, int end_reached) +int WalkStat(register struct node* nd, label exit_label, int end_reached) { - register t_node* left = nd->nd_LEFT; - register t_node* right = nd->nd_RIGHT; + register struct node* left = nd->nd_LEFT; + register struct node* right = nd->nd_RIGHT; assert(nd->nd_class == Stat); @@ -647,7 +647,7 @@ int WalkStat(register t_node* nd, label exit_label, int end_reached) { case '(': { - t_node* nd1 = nd; + struct node* nd1 = nd; if (ChkCall(&nd1)) { assert(nd == nd1); @@ -741,8 +741,8 @@ int WalkStat(register t_node* nd, label exit_label, int end_reached) label l2 = ++text_label; int uns = 0; arith stepsize; - t_type* bstp; - t_node* loopid; + struct type* bstp; + struct node* loopid; good_forvar = DoForInit(left); loopid = left->nd_LEFT; @@ -840,9 +840,9 @@ int WalkStat(register t_node* nd, label exit_label, int end_reached) case WITH: { - t_scopelist link; + struct scopelist link; struct withdesig wds; - t_desig ds; + struct desig ds; if (!WalkDesignator(&(nd->nd_LEFT), &ds, D_USED)) break; @@ -918,7 +918,7 @@ int WalkStat(register t_node* nd, label exit_label, int end_reached) } -int (*WalkTable[])(t_node*, label, int) = { +int (*WalkTable[])(struct node*, label, int) = { NodeCrash, NodeCrash, NodeCrash, @@ -934,12 +934,12 @@ int (*WalkTable[])(t_node*, label, int) = { WalkLink, }; -extern t_desig null_desig; +extern struct desig null_desig; -void ExpectBool(register t_node** pnd, label true_label, label false_label) +void ExpectBool(register struct node** pnd, label true_label, label false_label) { - t_desig ds; + struct desig ds; ds = null_desig; if (ChkExpression(pnd)) @@ -953,7 +953,7 @@ void ExpectBool(register t_node** pnd, label true_label, label false_label) } } -int WalkDesignator(t_node** pnd, t_desig* ds, int flags) +int WalkDesignator(struct node** pnd, struct desig* ds, int flags) { if (!ChkVariable(pnd, flags)) @@ -964,12 +964,12 @@ int WalkDesignator(t_node** pnd, t_desig* ds, int flags) return 1; } -int DoForInit(t_node* nd) +int DoForInit(struct node* nd) { - register t_node* right = nd->nd_RIGHT; - register t_def* df; - t_type* base_tp; - t_type *tpl, *tpr; + register struct node* right = nd->nd_RIGHT; + register struct def* df; + struct type* base_tp; + struct type *tpl, *tpr; int r; r = ChkVariable(&(nd->nd_LEFT), D_USED | D_DEFINED); @@ -994,7 +994,7 @@ int DoForInit(t_node* nd) if (df->df_scope != CurrentScope) { - register t_scopelist* sc = CurrVis; + register struct scopelist* sc = CurrVis; for (;;) { @@ -1042,15 +1042,15 @@ int DoForInit(t_node* nd) } -void DoAssign(register t_node* nd) +void DoAssign(register struct node* nd) { /* May we do it in this order (expression first) ??? The reference manual sais nothing about it, but the book does: it sais that the left hand side is evaluated first. DAMN THE BOOK! */ - t_desig dsr; - register t_type* tp; + struct desig dsr; + register struct type* tp; if (!(ChkExpression(&(nd->nd_RIGHT)) & ChkVariable(&(nd->nd_LEFT), D_DEFINED))) return; @@ -1078,9 +1078,9 @@ void DoAssign(register t_node* nd) CodeMove(&dsr, nd->nd_LEFT, tp); } -static void RegisterMessage(register t_def* df) +static void RegisterMessage(register struct def* df) { - register t_type* tp; + register struct type* tp; if (df->df_kind == D_VARIABLE) { @@ -1107,7 +1107,7 @@ static void RegisterMessage(register t_def* df) } } -static void df_warning(t_node* nd, t_def* df, char* warning) +static void df_warning(struct node* nd, struct def* df, char* warning) { if (!(df->df_kind & (D_VARIABLE | D_PROCEDURE | D_TYPE | D_CONST | D_PROCHEAD))) { @@ -1123,9 +1123,9 @@ static void df_warning(t_node* nd, t_def* df, char* warning) } } -static void UseWarnings(register t_def* df) +static void UseWarnings(register struct def* df) { - t_node* nd = df->df_scope->sc_end; + struct node* nd = df->df_scope->sc_end; if (is_anon_idf(df->df_idf) || !(df->df_kind & (D_IMPORTED | D_VARIABLE | D_PROCEDURE | D_CONST | D_TYPE)) || (df->df_flags & (D_EXPORTED | D_QEXPORTED))) { @@ -1134,7 +1134,7 @@ static void UseWarnings(register t_def* df) if (df->df_kind & D_IMPORTED) { - register t_def* df1 = df->imp_def; + register struct def* df1 = df->imp_def; df1->df_flags |= df->df_flags & (D_USED | D_DEFINED); if (df->df_kind == D_INUSE) @@ -1170,7 +1170,7 @@ static void UseWarnings(register t_def* df) } } -static void WalkDefList(register t_def* df, void (*proc)(t_def*)) +static void WalkDefList(register struct def* df, void (*proc)(struct def*)) { for (; df; df = df->df_nextinscope) { @@ -1179,7 +1179,7 @@ static void WalkDefList(register t_def* df, void (*proc)(t_def*)) } #ifdef DBSYMTAB -static void stabdef(t_def* df) +static void stabdef(struct def* df) { switch (df->df_kind) { diff --git a/lang/m2/comp/walk.h b/lang/m2/comp/walk.h index 1b0a3210e..cabdbc7ac 100644 --- a/lang/m2/comp/walk.h +++ b/lang/m2/comp/walk.h @@ -11,13 +11,13 @@ #include "em_label.h" /* Forward type declarations. */ -typedef struct node t_node; -typedef struct def t_def; -typedef struct desig t_desig; +struct node; +struct def; +struct desig; /* Definition of WalkNode macro */ -extern int (*WalkTable[])(t_node*, label, int); +extern int (*WalkTable[])(struct node*, label, int); #define WalkNode(xnd, xlab, rch) (*WalkTable[(unsigned int)((xnd)->nd_class)])((xnd), (xlab),(rch)) @@ -33,10 +33,10 @@ extern label data_label; -int LblWalkNode(label lbl, t_node *nd, int exit, int reach); +int LblWalkNode(label lbl, struct node *nd, int exit, int reach); void def_ilb(label l); /* Generate line information as necessary for "nd". */ -void DoLineno(register t_node* nd); +void DoLineno(register struct node* nd); /* Generate filename information, when needed. This routine is called at the generation of a procedure entry, and after generating a call to @@ -49,27 +49,27 @@ void DoFilename(int needed); Also generate code for its body. This code is collected in an initialization routine. */ -void WalkModule(register t_def* module); +void WalkModule(register struct def* module); /* Walk through the definition of a procedure and all its local definitions, checking and generating code. */ -void WalkProcedure(register t_def* procedure); +void WalkProcedure(register struct def* procedure); /* Walk node "nd", which is a link. "exit_label" is set to a label number when inside a LOOP. "end_reached" maintains info about reachability (REACH_FLAG), and whether an EXIT statement was seen (EXIT_FLAG). */ -int WalkLink(register t_node* nd, label exit_label, int end_reached); +int WalkLink(register struct node* nd, label exit_label, int end_reached); /* Walk through a statement node "nd", generating code for it. */ -int WalkStat(register t_node* nd, label exit_label, int end_reached); +int WalkStat(register struct node* nd, label exit_label, int end_reached); /* Generate code to evaluate a boolean expression "pnd" */ -void ExpectBool(register t_node** pnd, label true_label, label false_label); +void ExpectBool(register struct node** pnd, label true_label, label false_label); /* Check designator and generate code for it */ -int WalkDesignator(t_node** pnd, t_desig* ds, int flags); +int WalkDesignator(struct node** pnd, struct desig* ds, int flags); -void DoAssign(register t_node* nd); +void DoAssign(register struct node* nd); -int DoForInit(t_node* nd); +int DoForInit(struct node* nd); #endif /* WALK_H_ */ From 04cb62915914f217c28d3f45dd147698eb01f551 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:10:12 +0800 Subject: [PATCH 54/84] ANSI C conversion --- mach/6500/cg/mach.c | 21 ++++++++++----------- mach/6500/cg/mach.h | 11 +++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/mach/6500/cg/mach.c b/mach/6500/cg/mach.c index 386e826f8..b89241d14 100644 --- a/mach/6500/cg/mach.c +++ b/mach/6500/cg/mach.c @@ -3,8 +3,8 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -con_part(sz,w) register sz; word w; { - +void con_part(register int sz, word w) +{ while (part_size % sz) part_size++; if (part_size == TEM_WSIZE) @@ -21,17 +21,16 @@ con_part(sz,w) register sz; word w; { part_size += sz; } -con_mult(sz) word sz; { - long atol(); - +void con_mult(word sz) +{ if (sz != 4) fatal("bad icon/ucon size"); fprintf(codefile,".data4 %ld\n", atol(str)); } -con_float() { - +void con_float(void) +{ static int been_here; if (argval != 4 && argval != 8) fatal("bad fcon size"); @@ -45,8 +44,8 @@ static int been_here; } } -prolog(nlocals) full nlocals; { - +void prolog(full nlocals) +{ fprintf(codefile,"\tjsr Pro\n"); if (nlocals == 0) return; @@ -56,9 +55,9 @@ prolog(nlocals) full nlocals; { nlocals, nlocals); } -mes(type) word type; { +void mes(word type) +{ int argt ; - switch ( (int)type ) { case ms_ext : for (;;) { diff --git a/mach/6500/cg/mach.h b/mach/6500/cg/mach.h index 66f66d547..c736ffd05 100644 --- a/mach/6500/cg/mach.h +++ b/mach/6500/cg/mach.h @@ -4,6 +4,9 @@ */ /* $Id$ */ +#include "tables.h" +#include "types.h" + #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ @@ -29,3 +32,11 @@ #define fmt_id(ft, fs) sprintf(fs,"_%s",ft) #define BSS_INIT 0 + +void con_float(void); +void con_mult(word sz); +void con_part(register int sz, word w); +void mes(word type); +void prolog(full nlocals); + + From 628dcb3cbf2cc863cec087eff201ae4834cc90f9 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:10:47 +0800 Subject: [PATCH 55/84] ANSI C conversion --- mach/pdp/cg/mach.c | 41 ++++++++++++++++++++--------------------- mach/pdp/cg/mach.h | 19 ++++++++++++++++--- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/mach/pdp/cg/mach.c b/mach/pdp/cg/mach.c index e71a3ced8..15c816f36 100644 --- a/mach/pdp/cg/mach.c +++ b/mach/pdp/cg/mach.c @@ -1,7 +1,3 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". @@ -13,10 +9,12 @@ static char rcsid[] = "$Id$"; * machine dependent back end routines for the PDP-11 */ -/* #define REGPATCH /* save all registers in markblock */ +/* #define REGPATCH */ /* save all registers in markblock */ -con_part(sz,w) register sz; word w; { + +void con_part(register int sz, word w) +{ while (part_size % sz) part_size++; if (part_size == TEM_WSIZE) @@ -33,8 +31,8 @@ con_part(sz,w) register sz; word w; { part_size += sz; } -con_mult(sz) word sz; { - long l, atol(); +void con_mult(word sz) { + long l; if (sz != 4) fatal("bad icon/ucon size"); @@ -63,8 +61,8 @@ struct regadm { } regadm[2]; int n_regvars; -regscore(off,size,typ,score,totyp) long off; { - +int regscore(long off,int size,int typ,int score,int totyp) +{ if (size != 2) return(-1); score -= 1; /* allow for save/restore */ @@ -79,14 +77,14 @@ regscore(off,size,typ,score,totyp) long off; { return(score); /* estimated # of words of profit */ } -i_regsave() { +void i_regsave(void) { Rstring[0] = 0; n_regvars=0; } -f_regsave() { - register i; +void f_regsave(void) { + register int i; if (n_regvars==0 || lbytes==0) { #ifdef REGPATCH @@ -113,8 +111,8 @@ f_regsave() { regadm[i].ra_str); } -regsave(regstr,off,size) char *regstr; long off; { - +void regsave(char *regstr,long off,int size) +{ fprintf(codefile,"%c Local %ld into %s\n",COMMENTCHAR,off,regstr); /* commented away #ifndef REGPATCH @@ -131,7 +129,7 @@ end of commented away */ n_regvars++; } -regreturn() { +void regreturn(void) { #ifdef REGPATCH fprintf(codefile,"jmp eret\n"); @@ -142,7 +140,7 @@ regreturn() { #endif -prolog(nlocals) full nlocals; { +void prolog(full nlocals) { #ifndef REGVARS #ifdef REGPATCH @@ -160,8 +158,8 @@ prolog(nlocals) full nlocals; { #endif } -dlbdlb(as,ls) string as,ls; { - +void dlbdlb(string as,string ls) +{ if (strlen(as)+strlen(ls)+2 Date: Sat, 11 May 2019 01:11:03 +0800 Subject: [PATCH 56/84] ANSI C conversion --- mach/vax4/cg/mach.c | 33 +++++++++++---------------------- mach/vax4/cg/mach.h | 11 ++++++++++- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/mach/vax4/cg/mach.c b/mach/vax4/cg/mach.c index 23e880a82..66b016d4e 100644 --- a/mach/vax4/cg/mach.c +++ b/mach/vax4/cg/mach.c @@ -16,9 +16,7 @@ static char rcsid[] = "$Id$"; /* * Byte order: | 3 | 2 | 1 | 0 | */ -con_part(sz, w) - register int sz; - word w; +void con_part(register int sz, word w) { /* * Align new bytes on boundary of its on size. @@ -39,8 +37,7 @@ con_part(sz, w) part_size += sz; } -con_mult(sz) - word sz; +void con_mult(word sz) { if (sz != 4) fatal("bad icon/ucon size"); @@ -50,8 +47,7 @@ con_mult(sz) #ifdef MACH_OPTIONS static int gdb_flag = 0; -mach_option(s) - char *s; +void mach_option(char *s) { if (! strcmp(s, "-gdb")) { gdb_flag = 1; @@ -62,12 +58,11 @@ mach_option(s) } #endif /* MACH_OPTIONS */ -mes(mesno) - word mesno; +void mes(word type) { int argt, a1, a2 ; - switch ( (int)mesno ) { + switch ( (int)type ) { case ms_ext : for (;;) { switch ( argt=getarg( @@ -137,8 +132,7 @@ mes(mesno) #include #ifndef REGVARS -prolog(nlocals) - full nlocals; +void prolog(full nlocals) { fprintf(codefile,".data2 00\n"); if (nlocals == 0) @@ -170,7 +164,7 @@ static full nlocals; /* Number of local variables. */ /* * Save number of locals. */ -prolog(n) +void prolog(full n) { nlocals = n; } @@ -187,7 +181,7 @@ static struct s_reg { /* * Initialize saving of registers. */ -i_regsave() +void i_regsave(void) { p_reg = a_reg; } @@ -196,10 +190,7 @@ i_regsave() * Called for each register to be saved. * Save the parameters in the struct. */ -regsave(str, off, size) - char *str; - long off; - int size; +void regsave(char *str, long off, int size) { p_reg->sr_str = str; p_reg->sr_off = off; @@ -213,7 +204,7 @@ regsave(str, off, size) /* * Generate code to save the registers. */ -f_regsave() +void f_regsave(void) { register struct s_reg *p; register int mask; @@ -267,9 +258,7 @@ f_regsave() regreturn() { } -regscore(off, size, typ, score, totyp) - long off; - int size, typ, totyp, score; +int regscore(long off, int size, int typ, int score, int totyp) { register int i = score; diff --git a/mach/vax4/cg/mach.h b/mach/vax4/cg/mach.h index 399b1dfaf..ed58cbbdc 100644 --- a/mach/vax4/cg/mach.h +++ b/mach/vax4/cg/mach.h @@ -2,7 +2,10 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ + +#include "tables.h" +#include "types.h" + #define ex_ap(x) fprintf(codefile,".extern\t%s\n",x) #define in_ap(x) /* nothing */ @@ -30,3 +33,9 @@ #define MACH_OPTIONS #define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" + +void con_float(void); +void con_mult(word sz); +void con_part(register int sz, word w); +void mes(word type); +void prolog(full nlocals); From e6ba8034f02603a6cb90a71e71a54166577fb5eb Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:11:17 +0800 Subject: [PATCH 57/84] ANSI C conversion --- mach/z80/cg/mach.c | 25 +++++++++++-------------- mach/z80/cg/mach.h | 11 ++++++++--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mach/z80/cg/mach.c b/mach/z80/cg/mach.c index 1fb86268d..1ab1cd0fa 100644 --- a/mach/z80/cg/mach.c +++ b/mach/z80/cg/mach.c @@ -4,16 +4,13 @@ * */ -#ifndef NORCSID -static char rcs_mach[] = "$Id$" ; -static char rcs_h[] = RCS_H ; -#endif - /* * machine dependent back end routines for the Zilog Z80 (as well as Intel 8080) */ -con_part(sz,w) register sz; word w; { + +void con_part(register int sz, word w) +{ while (part_size % sz) part_size++; @@ -31,15 +28,15 @@ con_part(sz,w) register sz; word w; { part_size += sz; } -con_mult(sz) word sz; { - long atol(); - +void con_mult(word sz) +{ if (argval != 4) fatal("bad icon/ucon size"); fprintf(codefile, ".data4\t%ld\n", atol(str)); } -con_float() { +void con_float(void) +{ static int been_here; int sz = argval; @@ -56,9 +53,8 @@ con_float() { } } - -prolog(nlocals) full nlocals; { - +void prolog(full nlocals) +{ fprintf(codefile,"\tpush\tiy\n\tld\thl,0\n\tadd\thl,sp\n\tpush\thl\n\tpop\tiy\n"); switch (nlocals) { case 8: fprintf(codefile,"\tpush\thl\n"); @@ -72,7 +68,8 @@ prolog(nlocals) full nlocals; { } } -mes(type) word type ; { +void mes(word type) +{ int argt ; switch ( (int)type ) { diff --git a/mach/z80/cg/mach.h b/mach/z80/cg/mach.h index 0c34ccd1f..a0e1eb271 100644 --- a/mach/z80/cg/mach.h +++ b/mach/z80/cg/mach.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_H "$Id$" -#endif +#include "tables.h" +#include "types.h" #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ @@ -33,3 +32,9 @@ #define fmt_id(fs, ft) sprintf(ft, "_%s", fs) #define BSS_INIT 0 + +void con_float(void); +void con_mult(word sz); +void con_part(register int sz, word w); +void mes(word type); +void prolog(full nlocals); From 708c1ba1b0cc2f0a90736c69b70e8230351edd84 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:11:26 +0800 Subject: [PATCH 58/84] ANSI C conversion --- mach/z8000/cg/mach.c | 18 ++++++++++-------- mach/z8000/cg/mach.h | 10 +++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/mach/z8000/cg/mach.c b/mach/z8000/cg/mach.c index 2c809778b..38b7dd6d5 100644 --- a/mach/z8000/cg/mach.c +++ b/mach/z8000/cg/mach.c @@ -9,8 +9,8 @@ * machine dependent back end routines for the z8000 */ -con_part(sz,w) register sz; word w; { - +void con_part(register int sz, word w) +{ while (part_size % sz) part_size++; if (part_size == TEM_WSIZE) @@ -27,15 +27,15 @@ con_part(sz,w) register sz; word w; { part_size += sz; } -con_mult(sz) word sz; { - +void con_mult(word sz) +{ if (sz != 4) fatal("bad icon/ucon size"); fprintf(codefile,"\t.data4 %s\n", str); } -con_float() { - +void con_float(void) +{ static int been_here; if (argval != 4 && argval != 8) fatal("bad fcon size"); @@ -58,7 +58,8 @@ string holstr(n) word n; { } */ -prolog(nlocals) full nlocals; { +void prolog(full nlocals) +{ fprintf(codefile,"\tpush\t*RR14, R13\n\tld\tR13, R15\n"); if (nlocals == 0) @@ -67,7 +68,8 @@ prolog(nlocals) full nlocals; { fprintf(codefile,"\tsub\tR15, $%d\n",nlocals); } -mes(type) word type ; { +void mes(word type) +{ int argt ; switch ( (int)type ) { diff --git a/mach/z8000/cg/mach.h b/mach/z8000/cg/mach.h index 76581ecfc..7a54dd0b7 100644 --- a/mach/z8000/cg/mach.h +++ b/mach/z8000/cg/mach.h @@ -1,8 +1,10 @@ -/* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include "tables.h" +#include "types.h" + #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ @@ -28,3 +30,9 @@ #define fmt_id(sf,st) sprintf(st,"_%s", sf) #define BSS_INIT 0 + +void con_float(void); +void con_mult(word sz); +void con_part(register int sz, word w); +void mes(word type); +void prolog(full nlocals); From de45c1036de25773b883072195710cab1d57ffde Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:11:54 +0800 Subject: [PATCH 59/84] ANSI C conversion --- mach/proto/cg/codegen.c | 1337 ++++++++++++++++++++++----------------- mach/proto/cg/codegen.h | 13 + mach/proto/cg/compute.c | 32 +- mach/proto/cg/data.h | 7 +- mach/proto/cg/equiv.c | 29 +- mach/proto/cg/equiv.h | 7 +- mach/proto/cg/fillem.c | 126 ++-- mach/proto/cg/fillem.h | 22 + mach/proto/cg/gencode.c | 68 +- mach/proto/cg/gencode.h | 22 + mach/proto/cg/glosym.c | 29 +- mach/proto/cg/glosym.h | 7 +- mach/proto/cg/main.c | 46 +- mach/proto/cg/move.c | 25 +- mach/proto/cg/nextem.c | 65 +- mach/proto/cg/reg.c | 51 +- mach/proto/cg/reg.h | 17 + mach/proto/cg/regvar.c | 45 +- mach/proto/cg/regvar.h | 12 +- mach/proto/cg/salloc.c | 91 +-- mach/proto/cg/salloc.h | 20 + mach/proto/cg/state.c | 54 +- mach/proto/cg/state.h | 11 +- mach/proto/cg/subr.c | 123 ++-- mach/proto/cg/subr.h | 47 ++ mach/proto/cg/types.h | 8 +- mach/proto/cg/var.c | 16 +- 27 files changed, 1370 insertions(+), 960 deletions(-) create mode 100644 mach/proto/cg/codegen.h create mode 100644 mach/proto/cg/fillem.h create mode 100644 mach/proto/cg/gencode.h create mode 100644 mach/proto/cg/reg.h create mode 100644 mach/proto/cg/salloc.h create mode 100644 mach/proto/cg/subr.h diff --git a/mach/proto/cg/codegen.c b/mach/proto/cg/codegen.c index cfc1e37bf..9bec53ea1 100644 --- a/mach/proto/cg/codegen.c +++ b/mach/proto/cg/codegen.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include "assert.h" #include "param.h" #include "tables.h" @@ -12,13 +14,11 @@ static char rcsid[] = "$Id$"; #include "state.h" #include "equiv.h" #include "extern.h" - -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ +#include "subr.h" +#include "gencode.h" +#include "reg.h" +#include "salloc.h" +#include "fillem.h" #define SHORTCUT /* Stop searching at distance 0 */ @@ -31,14 +31,16 @@ static char rcsid[] = "$Id$"; #define MAXPATTERN 5 #define MAXREPLLEN 5 /* Max length of EM-replacement, should come from boot */ -byte startupcode[] = { DO_NEXTEM }; +byte startupcode[] = +{ DO_NEXTEM }; -byte *nextem(); -unsigned costcalc(); -unsigned docoerc(); -unsigned stackupto(); +extern byte *nextem(int); string tostring(); +extern int move(token_p,token_p,int,int,unsigned int); +extern struct perm* tuples(rl_p*, int); + + #ifdef NDEBUG #define DEBUG(xxxxx) #else @@ -49,18 +51,22 @@ string tostring(); #define BROKE() {assert(origcp!=startupcode);DEBUG("BROKE");goto doreturn;} #define CHKCOST() {if (totalcost>=costlimit) BROKE();} -unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned costlimit; { + + + +unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, int forced) +{ #ifndef NDEBUG - byte *origcp=codep; - static int level=0; + byte *origcp = codep; + static int level = 0; #endif unsigned totalcost = 0; byte *bp; int n; - unsigned mindistance,dist; + unsigned mindistance, dist; register int i; int cindex; - int npos,npos2,pos[MAXPOS],pos2[MAXPOS]; + int npos, npos2, pos[MAXPOS], pos2[MAXPOS]; #ifdef STONSTACK state_t state; #define SAVEST savestatus(&state) @@ -72,14 +78,14 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost #define RESTST restorestatus(state) #define FREEST freestatus(state) #endif - unsigned mincost,t; - int texpno,nodeno; + unsigned mincost, t; + int texpno, nodeno; token_p tp; tkdef_p tdp; int tinstno; register struct reginfo *rp; struct reginfo **rpp; - token_t token,mtoken,token2; + token_t token, mtoken, token2; int propno; int exactmatch; int j; @@ -87,606 +93,759 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost int stringno; result_t result; cost_t cost; - int size,lsize,repllen; + int size, lsize, repllen; int tokexp[MAXPATTERN]; int nregneeded; token_p regtp[MAXCREG]; c3_p regcp[MAXCREG]; rl_p regls[MAXCREG]; - c3_p findcoerc(); +#ifdef MAXSPLIT int sret; +#endif /* MAXSPLIT */ token_t reptoken[MAXREPLLEN]; - int emrepllen,eminstr; - int inscoerc=0; + int emrepllen, eminstr; + int inscoerc = 0; int stackpad; - struct perm *tup,*ntup,*besttup,*tuples(); + struct perm *tup, *ntup, *besttup; #ifndef NDEBUG level++; DEBUG("Entering codegen"); #endif - for (;;) { - switch( (*codep++)&037 ) { - default: - assert(FALSE); - /* NOTREACHED */ - case DO_NEXTEM: - DEBUG("NEXTEM"); - tokpatlen = 0; - nallreg=0; - if (toplevel) { - garbage_collect(); - totalcost=0; - } else { - if (--ply <= 0) - goto doreturn; - } - if (stackheight>MAXFSTACK-7) - totalcost += stackupto(&fakestack[6],ply,toplevel); - bp = nextem(toplevel); - if (bp == 0) { - /* - * No pattern found, can be pseudo or error - * in table. - */ - if (toplevel) { - codep--; - DEBUG("pseudo"); - dopseudo(); - } else - goto doreturn; - } else { -#ifndef NDEBUG - chkregs(); -#endif - if (! toplevel) { - ply -= emp-saveemp+1; - if (ply <= 0) ply = 1; - } - n = *bp++; - assert(n>0 && n<=MAXRULE); - if (n>1) { - mindistance = MAXINT; npos=0; - for(i=0;i1) { - /* - * More than 1 tokenpattern is a candidate. - * Decision has to be made by lookahead. - */ - SAVEST; - mincost = costlimit-totalcost+1; - for(i=0;i MAXFSTACK - 7) + totalcost += stackupto(&fakestack[6], ply, toplevel); + bp = nextem(toplevel); + if (bp == 0) + { + /* + * No pattern found, can be pseudo or error + * in table. + */ + if (toplevel) + { + codep--; + DEBUG("pseudo"); + dopseudo(); } + else + goto doreturn; + } + else + { +#ifndef NDEBUG + chkregs(); +#endif + if (!toplevel) + { + ply -= emp - saveemp + 1; + if (ply <= 0) + ply = 1; + } + n = *bp++; + assert(n>0 && n<=MAXRULE); + if (n > 1) + { + mindistance = MAXINT; + npos = 0; + for (i = 0; i < n; i++) + { + getint(cindex, bp); + dist = distance(cindex); +#ifndef NDEBUG + if (Debug) + fprintf(stderr, "distance of pos %d is %u\n", i, + dist); +#endif + if (dist <= mindistance) + { + if (dist < mindistance) + { +#ifdef SHORTCUT + if (dist == 0) + goto gotit; +#endif + npos = 0; + mindistance = dist; + } + pos[npos++] = cindex; + } + } + assert(mindistance 1) + { + /* + * More than 1 tokenpattern is a candidate. + * Decision has to be made by lookahead. + */ + SAVEST; + mincost = costlimit - totalcost + 1; + for (i = 0; i < npos; i++) + { + t = codegen(&coderules[pos[i]], ply, FALSE, + costlimit < MAXINT ? mincost : MAXINT, + 0); +#ifndef NDEBUG + if (Debug) + fprintf(stderr, + "mincost %u,cost %u,pos %d\n", + mincost, t, i); +#endif + if (t < mincost) + { + mincost = t; + cindex = pos[i]; + } + RESTST; + } FREEST; + if (totalcost + mincost > costlimit) + { + totalcost += mincost; + BROKE(); + } + } + else + { + cindex = pos[0]; + } + } + else + { + getint(cindex, bp); + } + + gotit: + /* + * Now cindex contains the code-index of the best candidate + * so proceed to use it. + */ + codep = &coderules[cindex]; + } + break; + case DO_COERC: + DEBUG("COERC") + ; + tokpatlen = 1; + inscoerc = 1; + break; + case DO_XXMATCH: + DEBUG("XXMATCH") + ; + case DO_XMATCH: + DEBUG("XMATCH") + ; + tokpatlen = (codep[-1] >> 5) & 07; + for (i = 0; i < tokpatlen; i++) + getint(tokexp[i], codep) + ; + tokexp[i] = 0; + break; /* match already checked by distance() */ + case DO_MATCH: + DEBUG("MATCH") + ; + tokpatlen = (codep[-1] >> 5) & 07; + for (i = 0; i < tokpatlen; i++) + getint(tokexp[i], codep) + ; + tokexp[i] = 0; + tp = &fakestack[stackheight - 1]; + i = 0; + while (i < tokpatlen && tp >= fakestack) + { + size = tsize(tp); + while (i < tokpatlen && (lsize = ssize(tokexp[i])) <= size) + { + size -= lsize; + i++; + } + if (i < tokpatlen && size != 0) + { + totalcost += stackupto(tp, ply, toplevel); + CHKCOST(); + break; + } + tp--; + } + tp = &fakestack[stackheight - 1]; + i = 0; + while (i < tokpatlen && tp >= fakestack) + { + size = tsize(tp); + lsize = ssize(tokexp[i]); + if (size != lsize) + { /* find coercion */ +#ifdef MAXSPLIT + sret = split(tp,&tokexp[i],ply,toplevel); + if (sret==0) + { +#endif /* MAXSPLIT */ + totalcost += stackupto(tp, ply, toplevel); + CHKCOST(); + break; +#ifdef MAXSPLIT + } + i += sret; +#endif /* MAXSPLIT */ + } + else + i += 1; + tp--; + } + nextmatch: tp = &fakestack[stackheight - 1]; + i = 0; + nregneeded = 0; + while (i < tokpatlen && tp >= fakestack) + { + if (!match(tp, &machsets[tokexp[i]], 0)) + { + register c3_p cp = findcoerc(tp, &machsets[tokexp[i]]); + if (cp == 0) + { + for (j = 0; j < nregneeded; j++) + regtp[j] -= (tp - fakestack + 1); + totalcost += stackupto(tp, ply, toplevel); + CHKCOST(); + break; + } + else + { + if (cp->c3_prop == 0) + { + totalcost += docoerc(tp, cp, ply, toplevel, 0); + CHKCOST(); + } + else + { + assert(nregneeded stackheight) + { + int k; + stackpad = tokpatlen - stackheight; + for (j = stackheight - 1, k = j + stackpad; j >= 0; + j--, k--) + { + fakestack[k] = fakestack[j]; + /* fakestack[j+stackpad] = fakestack[j]; does not + compile under Xenix + */ + } + for (j = 0; j < stackpad; j++) + fakestack[j].t_token = 0; + stackheight += stackpad; + for (j = 0; j < nregneeded; j++) + regtp[j] += stackpad; + tp = &fakestack[stackpad - 1]; + while (i < tokpatlen && tp >= fakestack) + { + register c3_p cp = findcoerc((token_p) 0, + &machsets[tokexp[i]]); + if (cp == 0) + { + assert(!toplevel); + for (j = 0; j < nregneeded; j++) + myfree(regls[j]); + totalcost = INFINITY; + BROKE(); + } + if (cp->c3_prop == 0) + { + totalcost += docoerc(tp, cp, ply, toplevel, 0); + CHKCOST(); + } + else + { + assert(nregneeded 1) + { + fprintf(stderr, "Next tuple %d,%d,%d,%d\n", + tup->p_rar[0], tup->p_rar[1], tup->p_rar[2], + tup->p_rar[3]); + fprintf(stderr, + "totalcost = %u, costlimit = %u, mincost = %u\n", + totalcost, costlimit, mincost); + } +#endif + ntup = tup->p_next; + for (i = 0, t = 0; i < nregneeded && t < mincost; i++) + t += docoerc(regtp[i], regcp[i], ply, FALSE, + tup->p_rar[i]); +#ifndef NDEBUG + if (Debug > 1) + fprintf(stderr, "cost after coercions: %u\n", t); +#endif + if (t < mincost) + t += codegen(codep, ply, FALSE, + mincost < MAXINT ? mincost - t : MAXINT, 0); + if (t < mincost) + { + mincost = t; + besttup = tup; + } + else + myfree(tup); RESTST; } FREEST; - if (totalcost+mincost>costlimit) { + for (i = 0; i < nregneeded; i++) + myfree(regls[i]); + if (totalcost + mincost > costlimit) + { + if (besttup) + myfree(besttup); + if (stackpad != tokpatlen) + { + if (stackpad) + { + if (costlimit < MAXINT) + { + totalcost = costlimit + 1; + BROKE(); + } + for (i = 0; i < stackheight - stackpad; i++) + fakestack[i] = fakestack[i + stackpad]; + stackheight -= stackpad; + totalcost += stackupto(&fakestack[stackheight - 1], + ply, toplevel); + } + else + totalcost += stackupto(fakestack, ply, toplevel); + CHKCOST(); + goto nextmatch; + } totalcost += mincost; BROKE(); } - } else { - cindex = pos[0]; - } - } else { - getint(cindex,bp); - } - - gotit: - /* - * Now cindex contains the code-index of the best candidate - * so proceed to use it. - */ - codep = &coderules[cindex]; - } - break; - case DO_COERC: - DEBUG("COERC"); - tokpatlen=1; - inscoerc=1; - break; - case DO_XXMATCH: - DEBUG("XXMATCH"); - case DO_XMATCH: - DEBUG("XMATCH"); - tokpatlen=(codep[-1]>>5)&07; - for (i=0;i>5)&07; - for(i=0;i=fakestack) { - size=tsize(tp); - while (i= fakestack) { - size = tsize(tp); - lsize= ssize(tokexp[i]); - if (size != lsize) { /* find coercion */ -#ifdef MAXSPLIT - sret = split(tp,&tokexp[i],ply,toplevel); - if (sret==0) { -#endif /* MAXSPLIT */ - totalcost += stackupto(tp,ply,toplevel); - CHKCOST(); + for (i = 0; i < nregneeded; i++) + totalcost += docoerc(regtp[i], regcp[i], ply, toplevel, + besttup->p_rar[i]); + myfree(besttup); break; -#ifdef MAXSPLIT - } - i += sret; -#endif /* MAXSPLIT */ - } else - i += 1; - tp--; - } - nextmatch: - tp = &fakestack[stackheight-1]; - i=0; nregneeded = 0; - while (i=fakestack) { - if (!match(tp,&machsets[tokexp[i]],0)) { - register c3_p cp = findcoerc(tp, &machsets[tokexp[i]]); - if (cp==0) { - for (j=0;j= &fakestack[0]; tp--) + if (match(tp, &machsets[texpno], nodeno)) + { + /* investigate possible coercion to register */ + totalcost += stackupto(tp, ply, toplevel); + CHKCOST(); + break; + } + for (rp = machregs + 2; rp < machregs + NREGS; rp++) + if (match(&rp->r_contents, &machsets[texpno], nodeno)) + rp->r_contents.t_token = 0; break; - } else { - if (cp->c3_prop==0) { - totalcost+=docoerc(tp,cp,ply,toplevel,0); - CHKCOST(); - } else { - assert(nregneeded= &fakestack[0]; tp--) + if (tp->t_token == -1) + { + if (tp->t_att[0].ar == result.e_v.e_reg) + goto gotone; + } + else + { + tdp = &tokens[tp->t_token]; + for (i = 0; i < TOKENSIZE; i++) + if (tdp->t_type[i] == EV_REG + && tp->t_att[i].ar == result.e_v.e_reg) + goto gotone; + } + break; + gotone: + /* investigate possible coercion to register */ + totalcost += stackupto(tp, ply, toplevel); + CHKCOST() + ; + break; + case DO_DEALLOCATE: + DEBUG("DEALLOCATE") + ; + getint(tinstno, codep) + ; + instance(tinstno, &token); + if (token.t_token == -1) + chrefcount(token.t_att[0].ar, -1, TRUE); + else + { + tdp = &tokens[token.t_token]; + for (i = 0; i < TOKENSIZE; i++) + if (tdp->t_type[i] == EV_REG) + chrefcount(token.t_att[i].ar, -1, TRUE); } - } - } - i++; tp--; - } - if (tokpatlen>stackheight) { - int k; - stackpad = tokpatlen-stackheight; - for (j=stackheight-1, k = j + stackpad;j>=0;j--, k--) { - fakestack[k] = fakestack[j]; - /* fakestack[j+stackpad] = fakestack[j]; does not - compile under Xenix - */ - } - for (j=0;j=fakestack) { - register c3_p cp = findcoerc((token_p) 0, &machsets[tokexp[i]]); - if (cp==0) { - assert(!toplevel); - for (j=0;jc3_prop==0) { - totalcost+=docoerc(tp,cp,ply,toplevel,0); - CHKCOST(); - } else { - assert(nregneeded1) { fprintf(stderr,"Next tuple %d,%d,%d,%d\n", - tup->p_rar[0], - tup->p_rar[1], - tup->p_rar[2], - tup->p_rar[3]); - fprintf(stderr, "totalcost = %u, costlimit = %u, mincost = %u\n", - totalcost, costlimit, mincost); - } -#endif - ntup = tup->p_next; - for (i=0,t=0;ip_rar[i]); -#ifndef NDEBUG -if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t); -#endif - if (tcostlimit) { - if (besttup) - myfree(besttup); - if (stackpad!=tokpatlen) { - if (stackpad) { - if (costlimitr_tcount) + { + rp->r_refcount -= rp->r_tcount; + rp->r_tcount = 0; + } + break; + case DO_ALLOCATE: + DEBUG("ALLOCATE") + ; + if (codep[-1] & 32) + { + getint(propno, codep); + getint(tinstno, codep); } - for (i=0;ip_rar[i]); - myfree(besttup); - break; - case DO_REMOVE: - DEBUG("REMOVE"); - if (codep[-1]&32) { - getint(texpno,codep); - getint(nodeno,codep); - } else { - getint(texpno,codep); - nodeno=0; - } - for (tp= &fakestack[stackheight-tokpatlen-1];tp>=&fakestack[0];tp--) - if (match(tp,&machsets[texpno],nodeno)) { - /* investigate possible coercion to register */ - totalcost += stackupto(tp,ply,toplevel); - CHKCOST(); - break; - } - for (rp=machregs+2;rpr_contents,&machsets[texpno],nodeno)) - rp->r_contents.t_token=0; - break; - case DO_RREMOVE: /* register remove */ - DEBUG("RREMOVE"); - getint(nodeno,codep); - result=compute(&enodes[nodeno]); - assert(result.e_typ==EV_REG); - for (tp= &fakestack[stackheight-tokpatlen-1];tp>=&fakestack[0];tp--) - if (tp->t_token==-1) { - if(tp->t_att[0].ar==result.e_v.e_reg) - goto gotone; - } else { - tdp = &tokens[tp->t_token]; - for(i=0;it_type[i]==EV_REG && - tp->t_att[i].ar==result.e_v.e_reg) - goto gotone; - } - break; - gotone: - /* investigate possible coercion to register */ - totalcost += stackupto(tp,ply,toplevel); - CHKCOST(); - break; - case DO_DEALLOCATE: - DEBUG("DEALLOCATE"); - getint(tinstno,codep); - instance(tinstno,&token); - if (token.t_token==-1) - chrefcount(token.t_att[0].ar,-1,TRUE); - else { - tdp= &tokens[token.t_token]; - for (i=0;it_type[i]==EV_REG) - chrefcount(token.t_att[i].ar,-1,TRUE); - } - break; - case DO_REALLOCATE: - DEBUG("REALLOCATE"); - for(rp=machregs;rpr_tcount) { - rp->r_refcount -= rp->r_tcount; - rp->r_tcount = 0; - } - break; - case DO_ALLOCATE: - DEBUG("ALLOCATE"); - if (codep[-1]&32) { - getint(propno,codep); - getint(tinstno,codep); - } else { - getint(propno,codep); - tinstno=0; - } - instance(tinstno,&token); - if (!forced) { - do { - npos=exactmatch=0; - for(rpp=reglist[propno];rp= *rpp; rpp++) - if (getrefcount((int)(rp-machregs), FALSE)==0) { - pos[npos++] = rp-machregs; - if (eqtoken(&rp->r_contents,&token)) - exactmatch++; + else + { + getint(propno, codep); + tinstno = 0; } - /* - * Now pos[] contains all free registers with desired - * property. If none then some stacking has to take place. - */ - if (npos==0) { - if (stackheight<=tokpatlen) { - if (!toplevel) { - totalcost = INFINITY; - BROKE(); - } else { - fatal("No regs available"); + instance(tinstno, &token); + if (!forced) + { + do + { + npos = exactmatch = 0; + for (rpp = reglist[propno]; (rp = *rpp); rpp++) + if (getrefcount((int) (rp - machregs), FALSE) == 0) + { + pos[npos++] = rp - machregs; + if (eqtoken(&rp->r_contents, &token)) + exactmatch++; + } + /* + * Now pos[] contains all free registers with desired + * property. If none then some stacking has to take place. + */ + if (npos == 0) + { + if (stackheight <= tokpatlen) + { + if (!toplevel) + { + totalcost = INFINITY; + BROKE(); + } + else + { + fatal("No regs available"); + } + } + totalcost += stackupto(&fakestack[0], ply, + toplevel); + CHKCOST(); + } + } while (npos == 0); + if (!exactmatch) + { + npos2 = npos; + for (i = 0; i < npos; i++) + pos2[i] = pos[i]; + } + else + { + /* + * Now we are reducing the number of possible registers. + * We take only one equally likely register out of every + * equivalence class as given by set of properties. + */ + mtoken = token; + npos2 = 0; + for (i = 0; i < npos; i++) + if (eqtoken(&machregs[pos[i]].r_contents, &mtoken)) + { + pos2[npos2++] = pos[i]; + for (j = 0; j < npos2 - 1; j++) + if (eqregclass(pos2[j], pos[i])) + { + npos2--; + break; + } + } + } + /* + * Now pos2[] contains all possibilities to try, if more than + * one, lookahead is necessary. + */ + token2.t_token = -1; + for (i = 1; i < TOKENSIZE; i++) + token2.t_att[i].aw = 0; + if (npos2 == 1) + decision = pos2[0]; + else + { + SAVEST; + mincost = costlimit - totalcost + 1; + for (j = 0; j < npos2; j++) + { + chrefcount(pos2[j], 1, FALSE); + token2.t_att[0].ar = pos2[j]; + allreg[nallreg++] = pos2[j]; + if (token.t_token != 0) + t = move(&token, &token2, ply, FALSE, mincost); + else + { + t = 0; + erasereg(pos2[j]); + } + if (t < mincost) + t += codegen(codep, ply, FALSE, + mincost < MAXINT ? mincost - t : MAXINT, + 0); + if (t < mincost) + { + mincost = t; + decision = pos2[j]; + } + RESTST; + } FREEST; + if (totalcost + mincost > costlimit) + { + totalcost = INFINITY; + BROKE(); + } } } - totalcost += stackupto( &fakestack[0],ply,toplevel); - CHKCOST(); - } - } while (npos==0); - if (!exactmatch) { - npos2=npos; - for(i=0;icostlimit) { - totalcost = INFINITY; - BROKE(); - } - } - } else { - decision = forced; - if (getrefcount(decision, FALSE)!=0) { - totalcost = INFINITY; - BROKE(); - } - token2.t_token = -1; - } - chrefcount(decision,1,FALSE); - token2.t_att[0].ar=decision; - if (token.t_token != 0) { - totalcost+=move(&token,&token2,ply,toplevel,MAXINT); - CHKCOST(); - } else - erasereg(decision); - allreg[nallreg++]=decision; - break; - case DO_LOUTPUT: - DEBUG("LOUTPUT"); - getint(stringno,codep); - getint(nodeno,codep); - if (toplevel) { - gencode(codestrings[stringno]); - genexpr(nodeno); - } - break; - case DO_ROUTPUT: - DEBUG("ROUTPUT"); - i=((codep[-1]>>5)&07); - do { - getint(stringno,codep); - if (toplevel) { - gencode(codestrings[stringno]); - gennl(); - } - } while (i--); - break; - case DO_MOVE: - DEBUG("MOVE"); - getint(tinstno,codep); - instance(tinstno,&token); - getint(tinstno,codep); - instance(tinstno,&token2); - totalcost += move(&token,&token2,ply,toplevel,costlimit-totalcost+1); - CHKCOST(); - break; - case DO_ERASE: - DEBUG("ERASE"); - getint(nodeno,codep); - result=compute(&enodes[nodeno]); - assert(result.e_typ==EV_REG); - erasereg(result.e_v.e_reg); - break; - case DO_TOKREPLACE: - DEBUG("TOKREPLACE"); - assert(stackheight>=tokpatlen); - repllen=(codep[-1]>>5)&07; - for(i=0;i>5)&07; - j=emp-emlines; - if (emrepllen>j) { - int k = nemlines + emrepllen - j; - assert(k=0;i--, k--) - emlines[k] = emlines[i]; - nemlines += emrepllen-j; - emp += emrepllen-j; - } - emp -= emrepllen; - for (i=0;i> 5) & 07); + do + { + getint(stringno, codep); + if (toplevel) + { + gencode(codestrings[stringno]); + gennl(); + } + } while (i--); + break; + case DO_MOVE: + DEBUG("MOVE") + ; + getint(tinstno, codep) + ; + instance(tinstno, &token); + getint(tinstno, codep) + ; + instance(tinstno, &token2); + totalcost += move(&token, &token2, ply, toplevel, + costlimit - totalcost + 1); + CHKCOST() + ; + break; + case DO_ERASE: + DEBUG("ERASE") + ; + getint(nodeno, codep) + ; + result = compute(&enodes[nodeno]); + assert(result.e_typ==EV_REG); + erasereg(result.e_v.e_reg); + break; + case DO_TOKREPLACE: + DEBUG("TOKREPLACE") + ; + assert(stackheight >= tokpatlen); + repllen = (codep[-1] >> 5) & 07; + for (i = 0; i < repllen; i++) + { + getint(tinstno, codep); + instance(tinstno, &reptoken[i]); + tref(&reptoken[i], 1); + } + for (i = 0; i < tokpatlen; i++) + { + if (!inscoerc) + tref(&fakestack[stackheight - 1], -1); + stackheight--; + } + for (i = 0; i < repllen; i++) + { + assert(stackheight> 5) & 07; + j = emp - emlines; + if (emrepllen > j) + { + int k = nemlines + emrepllen - j; + assert(k= 0; i--, k--) + emlines[k] = emlines[i]; + nemlines += emrepllen - j; + emp += emrepllen - j; + } + emp -= emrepllen; + for (i = 0; i < emrepllen; i++) + { + getint(eminstr, codep); + getint(nodeno, codep); + emp[i].em_instr = eminstr; + result = compute(&enodes[nodeno]); + switch (result.e_typ) + { + default: + assert(FALSE); + case 0: + emp[i].em_optyp = OPNO; + emp[i].em_soper = 0; + break; + case EV_INT: + emp[i].em_optyp = OPINT; + emp[i].em_soper = tostring(result.e_v.e_con); + emp[i].em_u.em_ioper = result.e_v.e_con; + break; + case EV_STR: + emp[i].em_optyp = OPSYMBOL; + emp[i].em_soper = result.e_v.e_str; + break; + } + } + if (!toplevel) + { + ply += emrepllen; + } + break; + case DO_COST: + DEBUG("COST") + ; + getint(cost.c_size, codep) + ; + getint(cost.c_time, codep) + ; + totalcost += costcalc(cost); + CHKCOST() + ; + break; #ifdef REGVARS - case DO_PRETURN: - if (toplevel) { - swtxt(); - regreturn(); /* in mach.c */ - } - break; + case DO_PRETURN: + if (toplevel) + { + swtxt(); + regreturn(); /* in mach.c */ + } + break; #endif - case DO_RETURN: - DEBUG("RETURN"); - assert(origcp!=startupcode); - doreturn: + case DO_RETURN: + DEBUG("RETURN") + ; + assert(origcp != startupcode); + doreturn: #ifndef NDEBUG - level--; + level--; #endif - return(totalcost); - } + return (totalcost); + } } } diff --git a/mach/proto/cg/codegen.h b/mach/proto/cg/codegen.h new file mode 100644 index 000000000..7c288de19 --- /dev/null +++ b/mach/proto/cg/codegen.h @@ -0,0 +1,13 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-04-14 + * + */ +#ifndef CODEGEN_H_ +#define CODEGEN_H_ + +unsigned int codegen(byte *codep, int ply, int toplevel, unsigned int costlimit, int forced); + +#endif /* CODEGEN_H_ */ diff --git a/mach/proto/cg/compute.c b/mach/proto/cg/compute.c index 49d2381fa..a55a1ace0 100644 --- a/mach/proto/cg/compute.c +++ b/mach/proto/cg/compute.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include #include @@ -14,13 +16,9 @@ static char rcsid[] = "$Id$"; #include "result.h" #include "glosym.h" #include "extern.h" +#include "subr.h" +#include "salloc.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ #define LLEAF 01 #define LDEF 02 @@ -73,9 +71,10 @@ char opdesc[] = { LLDEF, /* EX_REGVAR */ }; -string salloc(); -string mycat(s1,s2) string s1,s2; { + +string mycat(string s1,string s2) +{ register string s; s=salloc(strlen(s1)+strlen(s2)); @@ -84,7 +83,8 @@ string mycat(s1,s2) string s1,s2; { return(s); } -string mystrcpy(s) string s; { +string mystrcpy(string s) +{ register string r; r=salloc(strlen(s)); @@ -94,7 +94,8 @@ string mystrcpy(s) string s; { char digstr[21][15]; -string tostring(n) word n; { +string tostring(word n) +{ char buf[25]; if (n>=-20 && n<=20 && (n&1)==0) { @@ -108,7 +109,8 @@ string tostring(n) word n; { result_t undefres= {EV_UNDEF}; -result_t compute(node) register node_p node; { +result_t compute(register node_p node) +{ result_t leaf1,leaf2,result; token_p tp; int desc; diff --git a/mach/proto/cg/data.h b/mach/proto/cg/data.h index e02cb2726..b55fea2a3 100644 --- a/mach/proto/cg/data.h +++ b/mach/proto/cg/data.h @@ -2,7 +2,10 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ +#ifndef DATA_H_ +#define DATA_H_ + +#include "types.h" typedef struct { int t_token; /* kind of token, -1 for register */ @@ -56,3 +59,5 @@ typedef struct { int rl_n; /* number in list */ int rl_list[NREGS]; } rl_t,*rl_p; + +#endif /* DATA_H_ */ diff --git a/mach/proto/cg/equiv.c b/mach/proto/cg/equiv.c index 77e1c0c0a..f18e4dcb2 100644 --- a/mach/proto/cg/equiv.c +++ b/mach/proto/cg/equiv.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include "assert.h" #include "equiv.h" #include "param.h" @@ -11,15 +13,12 @@ static char rcsid[] = "$Id$"; #include "data.h" #include "result.h" #include "extern.h" +#include "subr.h" +#include "salloc.h" +#include "reg.h" + -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ -extern string myalloc(); int rar[MAXCREG]; rl_p* lar; @@ -27,12 +26,12 @@ int maxindex; int regclass[NREGS]; struct perm* perms; -void permute(int index); +static void permute(int index); struct perm* tuples(rl_p* regls, int nregneeded) { int class = 0; - register i, j; + register int i, j; /* * First compute equivalence classes of registers. @@ -66,11 +65,11 @@ struct perm* tuples(rl_p* regls, int nregneeded) return (perms); } -void permute(int index) +static void permute(int index) { register struct perm* pp; register rl_p rlp; - register i, j; + register int i, j; if (index == maxindex) { diff --git a/mach/proto/cg/equiv.h b/mach/proto/cg/equiv.h index fcd7971da..fe97bd999 100644 --- a/mach/proto/cg/equiv.h +++ b/mach/proto/cg/equiv.h @@ -2,7 +2,9 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ +#ifndef EQUIV_H_ +#define EQUIV_H_ + #define MAXCREG 4 @@ -10,3 +12,6 @@ struct perm { struct perm *p_next; int p_rar[MAXCREG]; }; + + +#endif /* EQUIV_H_ */ diff --git a/mach/proto/cg/fillem.c b/mach/proto/cg/fillem.c index 25caeb513..f33520e8b 100644 --- a/mach/proto/cg/fillem.c +++ b/mach/proto/cg/fillem.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid2[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include #include @@ -18,23 +20,48 @@ static char rcsid2[] = "$Id$"; #include #include "data.h" #include "result.h" +#include "subr.h" +#include "reg.h" +#include "salloc.h" +#include "gencode.h" +#include "glosym.h" #ifdef REGVARS #include "regvar.h" #include #endif #include "extern.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ + #ifndef newplb /* retrofit for older mach.h */ #define newplb newilb #endif +string tostring(); +static string holstr(word n); +static char *strarg(int t); +string mystrcpy(); +static int get16(void); +static long get32(void); +static int getarg(int typset); +static void getstring(void); +static void switchseg(int s); +static int table1(void); +static int table2(void); +static int table3(int i); +static void bss(full n, int t, int b); +void swtxt(void); +static void savelab(void); +static void dumplab(void); +static void xdumplab(void); +static void part_flush(void); +static long con(int t); + + + + + + #ifdef fmt_id #ifdef id_first It is an error to define both fmt_id and id_first. @@ -55,7 +82,7 @@ Read the documentation. #define SEGROM 2 #define SEGBSS 3 -long con(); + #define get8() getc(emfile) @@ -63,7 +90,6 @@ long con(); FILE *emfile; extern FILE *codefile; -extern FILE *freopen(); int nextispseu,savetab1; int opcode; @@ -84,14 +110,14 @@ int regallowed=0; extern char em_flag[]; extern short em_ptyp[]; -extern double atof(); -extern void con_float(void); + + + /* Own version of atol that continues computing on overflow. We don't know that about the ANSI C one. */ -long our_atol(s) -register char *s; +static long our_atol(register char *s) { register long total = 0; register unsigned digit; @@ -112,13 +138,8 @@ register char *s; #define sp_cstx sp_cst2 -string tostring(); -string holstr(); -string strarg(); -string mystrcpy(); -long get32(); -in_init(filename) char *filename; { +void in_init(char *filename) { if ((emfile=freopen(filename,"r",stdin))==NULL) error("Can't open %s",filename); @@ -126,16 +147,16 @@ in_init(filename) char *filename; { error("Bad format %s",filename); } -in_start() { +void in_start(void) { #ifdef modhead fprintf(codefile,"%s",modhead) ; #endif } -in_finish() { +void in_finish(void) { } -fillemlines() { +void fillemlines(void) { int t,i; register struct emline *lp; @@ -214,14 +235,14 @@ fillemlines() { } } -dopseudo() { - register b,t; +void dopseudo(void) { + register int b,t; register full n; register long save; word romcont[MAXROM+1]; int nromwords; int rombit,rommask; - unsigned dummy,stackupto(); + int dummy; if (nextispseu==0 || nemlines>0) error("No table entry for %d",emlines[0].em_instr); @@ -396,8 +417,8 @@ dopseudo() { /* ----- input ----- */ -int getarg(typset) { - register t,argtyp; +static int getarg(int typset) { + register int t,argtyp; argtyp = t = table2(); if (t == EOF) @@ -409,8 +430,8 @@ int getarg(typset) { return(argtyp); } -int table1() { - register i; +static int table1(void) { + register int i; i = get8(); if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) { @@ -428,8 +449,8 @@ int table1() { return(table3(i)); } -int table2() { - register i; +static int table2(void) { + register int i; i = get8(); if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) { @@ -439,7 +460,7 @@ int table2() { return(table3(i)); } -int table3(i) { +static int table3(int i) { word consiz; switch(i) { @@ -482,7 +503,7 @@ int table3(i) { return(i); } -int get16() { +static int get16(void) { register int l_byte, h_byte; l_byte = get8(); @@ -491,7 +512,7 @@ int get16() { return l_byte | (h_byte*256) ; } -long get32() { +static long get32(void) { register long l; register int h_byte; @@ -503,9 +524,9 @@ long get32() { return l | (h_byte*256L*256*256L) ; } -getstring() { +static void getstring(void) { register char *p; - register n; + register int n; getarg(cst_ptyp); if (argval < 0 || argval > MAXSTR-1) @@ -517,7 +538,7 @@ getstring() { *p++ = '\0'; } -char *strarg(t) { +static char *strarg(int t) { register char *p; switch (t) { @@ -565,7 +586,8 @@ char *strarg(t) { return(mystrcpy(argstr)); } -bss(n,t,b) full n; { +static void bss(full n, int t, int b) +{ register long s; if (n % TEM_WSIZE) @@ -588,8 +610,8 @@ bss(n,t,b) full n; { fatal("bad BSS initializer"); } -long con(t) { - register i; +static long con(int t) { + register int i; strarg(t); switch (t) { @@ -633,11 +655,11 @@ long con(t) { extern char *segname[]; -swtxt() { +void swtxt(void) { switchseg(SEGTXT); } -switchseg(s) { +static void switchseg(int s) { if (s == curseg) return; @@ -646,9 +668,9 @@ switchseg(s) { fprintf(codefile,"%s\n",segname[s]); } -savelab() { +static void savelab(void) +{ register char *p,*q; - part_flush(); if (labstr[0]) { dlbdlb(argstr,labstr); @@ -656,11 +678,11 @@ savelab() { } p = argstr; q = labstr; - while (*q++ = *p++) + while ((*q++ = *p++)) ; } -dumplab() { +static void dumplab(void) { if (labstr[0] == 0) return; @@ -669,7 +691,7 @@ dumplab() { labstr[0] = 0; } -xdumplab() { +static void xdumplab(void) { if (labstr[0] == 0) return; @@ -677,7 +699,7 @@ xdumplab() { newdlb(labstr); } -part_flush() { +static void part_flush(void) { /* * Each new data fragment and each data label starts at @@ -690,7 +712,7 @@ part_flush() { part_word = 0; } -string holstr(n) word n; { +static string holstr(word n) { sprintf(str,hol_off,n,holno); return(mystrcpy(str)); diff --git a/mach/proto/cg/fillem.h b/mach/proto/cg/fillem.h new file mode 100644 index 000000000..e8708b32c --- /dev/null +++ b/mach/proto/cg/fillem.h @@ -0,0 +1,22 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-04-14 + * + */ +#ifndef FILLEM_H_ +#define FILLEM_H_ + +/** Switch to text segment. */ +void swtxt(void); + + +void in_init(char *filename); +void in_start(void); +void in_finish(void); +void fillemlines(void); + +void dopseudo(void); + +#endif /* FILLEM_H_ */ diff --git a/mach/proto/cg/gencode.c b/mach/proto/cg/gencode.c index c15bd9b94..7582808ab 100644 --- a/mach/proto/cg/gencode.c +++ b/mach/proto/cg/gencode.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include "assert.h" #include #include "param.h" @@ -11,39 +13,35 @@ static char rcsid[] = "$Id$"; #include "data.h" #include "result.h" #include "extern.h" - -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ +#include "subr.h" +#include "gencode.h" +#include "fillem.h" FILE *codefile; -extern FILE *freopen(); -out_init(filename) char *filename; { + +void out_init(char *filename) +{ #ifndef NDEBUG - static char stderrbuff[BUFSIZ]; - if (Debug) { - codefile = stderr; - if (!isatty(2)) - setbuf(stderr,stderrbuff); - } else { -#endif - if (filename == (char *) 0) - codefile = stdout; + if (Debug) + { + codefile = stderr; + } else - if ((codefile=freopen(filename,"w",stdout))==NULL) - error("Can't create %s",filename); + { +#endif + if (filename == (char *) 0) + codefile = stdout; + else if ((codefile = freopen(filename, "w", stdout)) == NULL) + error("Can't create %s", filename); #ifndef NDEBUG - } + } #endif } -out_finish() { +void out_finish(void) { #ifndef NDEBUG if (Debug) @@ -53,14 +51,15 @@ out_finish() { fclose(codefile); } -tstoutput() { +void tstoutput(void) { if (ferror(codefile)) error("Write error on output"); } -gencode(code) register char *code; { - register c; +void gencode(register char *code) +{ + register int c; int tokno,fldno,insno,regno,subno; register token_p tp; @@ -131,7 +130,8 @@ gencode(code) register char *code; { } } -genexpr(nodeno) { +void genexpr(int nodeno) +{ result_t result; result= compute(&enodes[nodeno]); @@ -149,12 +149,14 @@ genexpr(nodeno) { } } -gennl() { +void gennl(void) +{ fputc('\n',codefile); } -prtoken(tp) token_p tp; { - register c; +void prtoken(token_p tp) +{ + register int c; register char *code; register tkdef_p tdp; diff --git a/mach/proto/cg/gencode.h b/mach/proto/cg/gencode.h new file mode 100644 index 000000000..467df4539 --- /dev/null +++ b/mach/proto/cg/gencode.h @@ -0,0 +1,22 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-04-12 + * + */ +#ifndef GENCODE_H_ +#define GENCODE_H_ + +#include "data.h" + +void out_init(char *filename); +void out_finish(void); +void tstoutput(void); +void gencode(register char *code); +void genexpr(int nodeno); +void gennl(void); +void prtoken(token_p tp); + + +#endif /* GENCODE_H_ */ diff --git a/mach/proto/cg/glosym.c b/mach/proto/cg/glosym.c index 4052c1bfe..55e283ffc 100644 --- a/mach/proto/cg/glosym.c +++ b/mach/proto/cg/glosym.c @@ -1,28 +1,26 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - -#include -#include -#include "param.h" -#include "tables.h" -#include "types.h" -#include "glosym.h" - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". * * Author: Hans van Staveren */ +#include +#include +#include "param.h" +#include "tables.h" +#include "types.h" +#include "glosym.h" +#include "salloc.h" + + -extern string myalloc(); glosym_p glolist= (glosym_p) 0; -enterglo(name,romp) string name; word *romp; { +void enterglo(string name,word *romp) +{ register glosym_p gp; - register i; + register int i; gp = (glosym_p) myalloc(sizeof *gp); gp->gl_next = glolist; @@ -33,7 +31,8 @@ enterglo(name,romp) string name; word *romp; { glolist = gp; } -glosym_p lookglo(name) string name; { +glosym_p lookglo(string name) +{ register glosym_p gp; for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next) diff --git a/mach/proto/cg/glosym.h b/mach/proto/cg/glosym.h index 1449b9b1b..b4b2157fe 100644 --- a/mach/proto/cg/glosym.h +++ b/mach/proto/cg/glosym.h @@ -2,7 +2,9 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ +#ifndef GLOSYM_H_ +#define GLOSYM_H_ + typedef struct glosym { struct glosym *gl_next; @@ -10,4 +12,7 @@ typedef struct glosym { word gl_rom[MAXROM+1]; } glosym_t,*glosym_p; +void enterglo(string name, word *romp); glosym_p lookglo(); + +#endif /* GLOSYM_H_ */ diff --git a/mach/proto/cg/main.c b/mach/proto/cg/main.c index 592bcb877..f7fc09a11 100644 --- a/mach/proto/cg/main.c +++ b/mach/proto/cg/main.c @@ -1,19 +1,24 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - -#include "param.h" -#include "mach.h" - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". * * Author: Hans van Staveren */ +#include +#include "tables.h" +#include "types.h" +#include +#include "data.h" +#include "tables.h" +#include "param.h" +#include "mach.h" +#include "subr.h" +#include "fillem.h" +#include "gencode.h" +#include "codegen.h" char *progname; -extern char startupcode[]; +extern byte startupcode[]; int maxply=1; #ifndef NDEBUG int Debug=0; @@ -21,10 +26,23 @@ int Debug=0; extern int endofprog; -main(argc,argv) char **argv; { + +unsigned ggd(unsigned int a,unsigned int b) +{ + register unsigned c; + + do { + c = a%b; a=b; b=c; + } while (c!=0); + return(a); +} + + +int main(int argc, char **argv) +{ register unsigned n; extern unsigned cc1,cc2,cc3,cc4; - unsigned ggd(); + progname = argv[0]; while (--argc && **++argv == '-') { @@ -70,11 +88,3 @@ main(argc,argv) char **argv; { out_finish(); } -unsigned ggd(a,b) register unsigned a,b; { - register unsigned c; - - do { - c = a%b; a=b; b=c; - } while (c!=0); - return(a); -} diff --git a/mach/proto/cg/move.c b/mach/proto/cg/move.c index f0fe5da15..8aa739f8f 100644 --- a/mach/proto/cg/move.c +++ b/mach/proto/cg/move.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include "assert.h" #include "param.h" #include "tables.h" @@ -10,23 +12,18 @@ static char rcsid[] = "$Id$"; #include "data.h" #include "result.h" #include "extern.h" +#include "subr.h" +#include "reg.h" +#include "codegen.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ -unsigned costcalc(); - -move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; { +int move(token_p tp1,token_p tp2,int ply,int toplevel,unsigned int maxcost) +{ register move_p mp; register unsigned t; register struct reginfo *rp; tkdef_p tdp; int i; - unsigned codegen(); if (eqtoken(tp1,tp2)) return(0); diff --git a/mach/proto/cg/nextem.c b/mach/proto/cg/nextem.c index 765d14d1d..f0d9af598 100644 --- a/mach/proto/cg/nextem.c +++ b/mach/proto/cg/nextem.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include #include "assert.h" @@ -12,21 +14,36 @@ static char rcsid[] = "$Id$"; #include "data.h" #include "result.h" #include "extern.h" - -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ +#include "fillem.h" #ifndef NDEBUG #include extern char em_mnem[][4]; #endif -byte *trypat(bp,len) register byte *bp; { - register patlen,i; +extern char em_flag[]; + +static int argtyp(int mn) { + + switch(em_flag[mn-sp_fmnem]&EM_PAR) { + case PAR_W: + case PAR_S: + case PAR_Z: + case PAR_O: + case PAR_N: + case PAR_L: + case PAR_F: + case PAR_R: + case PAR_C: + return(EV_INT); + default: + return(EV_STR); + } +} + +byte *trypat(register byte *bp, int len) +{ + register int patlen,i; result_t result; getint(patlen,bp); @@ -71,28 +88,10 @@ byte *trypat(bp,len) register byte *bp; { return(bp); } -extern char em_flag[]; -argtyp(mn) { - switch(em_flag[mn-sp_fmnem]&EM_PAR) { - case PAR_W: - case PAR_S: - case PAR_Z: - case PAR_O: - case PAR_N: - case PAR_L: - case PAR_F: - case PAR_R: - case PAR_C: - return(EV_INT); - default: - return(EV_STR); - } -} - -byte *nextem(toplevel) { - register i; +byte *nextem(int toplevel) { + register int i; short hash[3]; register byte *bp; byte *cp; diff --git a/mach/proto/cg/reg.c b/mach/proto/cg/reg.c index 705fc71d7..4675c3557 100644 --- a/mach/proto/cg/reg.c +++ b/mach/proto/cg/reg.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include "assert.h" #include "param.h" #include "tables.h" @@ -10,17 +12,16 @@ static char rcsid[] = "$Id$"; #include "data.h" #include "result.h" #include "extern.h" +#include "subr.h" +#include "reg.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ +/* Froward local declarations */ +static void awayreg(int); -chrefcount(regno,amount,tflag) { +void chrefcount(int regno, int amount, int tflag) +{ register struct reginfo *rp; - register i; + register int i; rp= &machregs[regno]; #if MAXMEMBERS!=0 @@ -38,9 +39,10 @@ chrefcount(regno,amount,tflag) { #endif } -getrefcount(regno, tflag) { +int getrefcount(int regno, int tflag) +{ register struct reginfo *rp; - register i,maxcount; + register int i,maxcount; rp= &machregs[regno]; #if MAXMEMBERS!=0 @@ -58,7 +60,8 @@ getrefcount(regno, tflag) { #endif } -erasereg(regno) { +void erasereg(int regno) +{ register struct reginfo *rp; register int i; @@ -83,10 +86,11 @@ erasereg(regno) { #endif } -awayreg(regno) { +static void awayreg(int regno) +{ register struct reginfo *rp; register tkdef_p tdp; - register i; + register int i; /* Now erase recursively all registers containing * something using this one @@ -107,9 +111,10 @@ awayreg(regno) { } } -cleanregs() { +void cleanregs(void) +{ register struct reginfo *rp; - register i; + register int i; for (rp=machregs;rpr_contents.t_token = 0; @@ -119,9 +124,10 @@ cleanregs() { } #ifndef NDEBUG -inctcount(regno) { +void inctcount(int regno) +{ register struct reginfo *rp; - register i; + register int i; rp = &machregs[regno]; #if MAXMEMBERS!=0 @@ -137,7 +143,8 @@ inctcount(regno) { #endif } -chkregs() { +void chkregs(void) +{ register struct reginfo *rp; register token_p tp; register tkdef_p tdp; diff --git a/mach/proto/cg/reg.h b/mach/proto/cg/reg.h new file mode 100644 index 000000000..70525b15c --- /dev/null +++ b/mach/proto/cg/reg.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-04-14 + * + */ +#ifndef REG_H_ +#define REG_H_ + +void chrefcount(int regno, int amount, int tflag); +int getrefcount(int regno, int tflag); +void erasereg(int regno); +void cleanregs(void); +void chkregs(void); + +#endif /* REG_H_ */ diff --git a/mach/proto/cg/regvar.c b/mach/proto/cg/regvar.c index 5b5859615..03dbe14b0 100644 --- a/mach/proto/cg/regvar.c +++ b/mach/proto/cg/regvar.c @@ -1,12 +1,16 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include "assert.h" #include "param.h" #include "tables.h" #ifdef REGVARS -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif + #include "types.h" #include @@ -15,18 +19,20 @@ static char rcsid[] = "$Id$"; #include #include "result.h" #include "extern.h" +#include "salloc.h" +#include "fillem.h" +#include "regvar.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ -extern string myalloc(); struct regvar *rvlist; -struct regvar * -linkreg(of,sz,tp,sc) long of; { +/* Defined in mach.c of the specific machine. */ +extern int regscore(long off,int size,int typ,int score,int totyp); +extern void i_regsave(void); +extern void f_regsave(void); +void regsave(char *regstr,long off,int size); + +struct regvar *linkreg(long of,int sz,int tp,int sc) +{ struct regvar *rvlp; rvlp= (struct regvar *) myalloc(sizeof *rvlp); @@ -40,9 +46,10 @@ linkreg(of,sz,tp,sc) long of; { return(rvlp); } -tryreg(rvlp,typ) struct regvar *rvlp; { +void tryreg(struct regvar *rvlp, int typ) +{ int score; - register i; + register int i; struct regassigned *ra; struct regvar *save; @@ -85,9 +92,10 @@ tryreg(rvlp,typ) struct regvar *rvlp; { } } -fixregvars(saveall) { +void fixregvars(int saveall) +{ register struct regvar *rv; - register rvtyp,i; + register int rvtyp,i; swtxt(); i_regsave(); /* machine dependent initialization */ @@ -107,7 +115,8 @@ fixregvars(saveall) { f_regsave(); } -isregvar(off) long off; { +int isregvar(long off) +{ register struct regvar *rvlp; for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next) @@ -116,7 +125,7 @@ isregvar(off) long off; { return(-1); } -unlinkregs() { +void unlinkregs(void) { register struct regvar *rvlp,*t; register struct regassigned *ra; int rvtyp,i; diff --git a/mach/proto/cg/regvar.h b/mach/proto/cg/regvar.h index e04350356..34298cad8 100644 --- a/mach/proto/cg/regvar.h +++ b/mach/proto/cg/regvar.h @@ -2,7 +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". */ -/* $Id$ */ +#ifndef REGVAR_H_ +#define REGVAR_H_ struct regvar { struct regvar *rv_next; @@ -21,3 +22,12 @@ struct regassigned { extern struct regvar *rvlist; extern int nregvar[]; extern struct regassigned *regassigned[]; + + +struct regvar *linkreg(long of,int sz,int tp,int sc); +void tryreg(struct regvar *rvlp, int typ); +void fixregvars(int saveall); +int isregvar(long off); +void unlinkregs(void); + +#endif /* REGVAR_H_ */ diff --git a/mach/proto/cg/salloc.c b/mach/proto/cg/salloc.c index 30554a471..73d081650 100644 --- a/mach/proto/cg/salloc.c +++ b/mach/proto/cg/salloc.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include "assert.h" #include "param.h" @@ -11,13 +13,10 @@ static char rcsid[] = "$Id$"; #include "data.h" #include "result.h" #include "extern.h" +#include "subr.h" +#include "salloc.h" + -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ /* * Package for string allocation and garbage collection. @@ -31,7 +30,33 @@ static char rcsid[] = "$Id$"; char *stab[MAXSTAB]; int nstab=0; -string myalloc(size) { +static void chkstr(string str,char used[]) +{ + register int low,middle,high; + + low=0; high=nstab-1; + while (high>low) { + middle= (low+high)>>1; + if (str==stab[middle]) { + used[middle]=1; + return; + } + if (strlow) { - middle= (low+high)>>1; - if (str==stab[middle]) { - used[middle]=1; - return; - } - if (str>=1; + do + *to++ = *from++; + while (--nbytes); +} + #ifdef STONSTACK -savestatus(sp) register state_p sp; { +state_p savestatus(register state_p sp) +{ #else -state_p savestatus() { +state_p state_p savestatus(void) +{ register state_p sp; if ((sp=stlist)==0) @@ -56,8 +69,8 @@ state_p savestatus() { #endif } -restorestatus(sp) register state_p sp; { - +void restorestatus(register state_p sp) +{ stackheight = sp->st_sh; bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t)); nallreg = sp->st_na; @@ -74,20 +87,11 @@ restorestatus(sp) register state_p sp; { } #ifndef STONSTACK -freestatus(sp) state_p sp; { - +void freestatus(state_p sp) +{ sp->st_next = stlist; stlist = sp; } #endif -bmove(from,to,nbytes) register short *from,*to; register nbytes; { - if (nbytes<=0) - return; - assert(sizeof(short)==2 && (nbytes&1)==0); - nbytes>>=1; - do - *to++ = *from++; - while (--nbytes); -} diff --git a/mach/proto/cg/state.h b/mach/proto/cg/state.h index f7f10e3ba..0e4eb5ca1 100644 --- a/mach/proto/cg/state.h +++ b/mach/proto/cg/state.h @@ -2,7 +2,9 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ +#ifndef STATE_H_ +#define STATE_H_ + #define STONSTACK /* if defined state is saved in stackframe */ @@ -24,5 +26,10 @@ typedef struct state { } state_t,*state_p; #ifndef STONSTACK -state_p savestatus(); +state_p state_p savestatus(void); #endif + +void restorestatus(register state_p sp); +state_p savestatus(register state_p sp); + +#endif /* STATE_H_ */ diff --git a/mach/proto/cg/subr.c b/mach/proto/cg/subr.c index 325f54a2c..dd7a77806 100644 --- a/mach/proto/cg/subr.c +++ b/mach/proto/cg/subr.c @@ -1,8 +1,12 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include +#include +#include #include "assert.h" #include #include "param.h" @@ -12,19 +16,20 @@ static char rcsid[] = "$Id$"; #include "data.h" #include "result.h" #include "extern.h" +#include "subr.h" +#include "reg.h" +#include "salloc.h" +#include "gencode.h" +#include "regvar.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ -extern string myalloc(); unsigned codegen(); +extern unsigned cc1,cc2,cc3,cc4; -match(tp,tep,optexp) register token_p tp; register set_p tep; { - register bitno; + +int match(register token_p tp, register set_p tep, int optexp) +{ + register int bitno; token_p ct; result_t result; @@ -49,7 +54,8 @@ match(tp,tep,optexp) register token_p tp; register set_p tep; { return(result.e_v.e_con); } -instance(instno,token) register token_p token; { +void instance(int instno,register token_p token) +{ register inst_p inp; int i; token_p tp; @@ -128,7 +134,9 @@ instance(instno,token) register token_p token; { } } -cinstance(instno,token,tp,regno) register token_p token,tp; { +void cinstance(int instno,register token_p token, + register token_p tp,int regno) +{ register inst_p inp; int i; struct reginfo *rp; @@ -195,8 +203,9 @@ cinstance(instno,token,tp,regno) register token_p token,tp; { } } -eqtoken(tp1,tp2) token_p tp1,tp2; { - register i; +int eqtoken(token_p tp1,token_p tp2) +{ + register int i; register tkdef_p tdp; if (tp1->t_token!=tp2->t_token) @@ -229,9 +238,9 @@ eqtoken(tp1,tp2) token_p tp1,tp2; { return(1); } -distance(cindex) { - register char *bp; - register i; +int distance(int cindex) { + register byte *bp; + register int i; register token_p tp; int tokexp,tpl; int expsize,toksize,exact; @@ -281,9 +290,9 @@ distance(cindex) { return(20-exact); } -unsigned costcalc(cost) cost_t cost; { +unsigned costcalc(cost_t cost) +{ result_t result1,result2; - extern unsigned cc1,cc2,cc3,cc4; result1=compute(&enodes[cost.c_size]); result2=compute(&enodes[cost.c_time]); @@ -291,20 +300,20 @@ unsigned costcalc(cost) cost_t cost; { return(result1.e_v.e_con*cc1/cc2 + result2.e_v.e_con*cc3/cc4); } -ssize(tokexpno) { +int ssize(int tokexpno) { return(machsets[tokexpno].set_size); } -tsize(tp) register token_p tp; { - +int tsize(register token_p tp) +{ if (tp->t_token==-1) return(machregs[tp->t_att[0].ar].r_size); return(tokens[tp->t_token].t_size); } #ifdef MAXSPLIT -instsize(tinstno,tp) token_p tp; { +int instsize(int tinstno,token_p tp) { inst_p inp; struct reginfo *rp; @@ -335,8 +344,8 @@ instsize(tinstno,tp) token_p tp; { } #endif /* MAXSPLIT */ -tref(tp,amount) register token_p tp; { - register i; +void tref(register token_p tp,int amount) { + register int i; register tkdef_p tdp; if (tp->t_token==-1) @@ -352,11 +361,12 @@ tref(tp,amount) register token_p tp; { #define MAXSAVE 10 #ifdef MAXSPLIT -split(tp,ip,ply,toplevel) token_p tp; int *ip; { +int split(token_p tp,int *ip,int ply,int toplevel) +{ c2_p cp; token_t savestack[MAXSAVE]; int ok; - register i; + register int i; int diff; token_p stp; int tpl; @@ -392,11 +402,12 @@ found: } #endif /* MAXSPLIT */ -unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; c3_p cp; { +unsigned docoerc(token_p tp,c3_p cp,int ply,int toplevel,int forced) +{ token_t savestack[MAXSAVE]; token_p stp; int i,diff; - unsigned cost; + unsigned int cost; int tpl; /* saved tokpatlen */ stp = &fakestack[stackheight-1]; @@ -415,7 +426,8 @@ unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; c3_p cp; { return(cost); } -unsigned stackupto(limit,ply,toplevel) token_p limit; { +unsigned stackupto(token_p limit,int ply,int toplevel) +{ token_t savestack[MAXFSTACK]; token_p stp; int i,diff; @@ -473,10 +485,11 @@ unsigned stackupto(limit,ply,toplevel) token_p limit; { return(totalcost); } -c3_p findcoerc(tp,tep) token_p tp; set_p tep; { +c3_p findcoerc(token_p tp,set_p tep) +{ register c3_p cp; token_t rtoken; - register i; + register int i; register struct reginfo **rpp; for (cp=c3coercs;cp< &c3coercs[NC3]; cp++) { @@ -508,30 +521,42 @@ c3_p findcoerc(tp,tep) token_p tp; set_p tep; { return(0); /* nothing found */ } - -error(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; { - - fatal(s,a1,a2,a3,a4,a5,a6,a7,a8); -} - -fatal(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; { - +static void error_str(char *s, va_list argptr) +{ fprintf(stderr,"Error: "); - fprintf(stderr,s,a1,a2,a3,a4,a5,a6,a7,a8); + vfprintf(stderr, s, argptr); fprintf(stderr,"\n"); out_finish(); abort(); - exit(-1); + exit(EXIT_FAILURE); + } -#ifndef NDEBUG -badassertion(asstr,file,line) char *asstr, *file; { +void error(char *s, ...) +{ + va_list ap; + va_start(ap, s); + error_str(s, ap); + va_end(ap); +} +void fatal(char *s, ...) +{ + va_list ap; + va_start(ap, s); + error_str(s, ap); + va_end(ap); +} + + +#ifndef NDEBUG +void badassertion(char* asstr,char *file,int line) +{ fatal("Assertion \"%s\" failed %s(%d)",asstr,file,line); } #endif -max(a,b) { - +int max(int a,int b) +{ return(a>b ? a : b); } diff --git a/mach/proto/cg/subr.h b/mach/proto/cg/subr.h new file mode 100644 index 000000000..8d3e78add --- /dev/null +++ b/mach/proto/cg/subr.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-04-12 + * + */ +#ifndef SUBR_H_ +#define SUBR_H_ + +#include "data.h" +#include "types.h" + +int match(register token_p tp, register set_p tep, int optexp); +void instance(int instno,register token_p token); +void cinstance(int instno,register token_p token, + register token_p tp,int regno); +int eqtoken(token_p tp1,token_p tp2); +int distance(int cindex); +unsigned costcalc(cost_t cost); +int ssize(int tokexpno); +int tsize(register token_p tp); + +#ifdef MAXSPLIT +int instsize(int tinstno,token_p tp); +#endif /* MAXSPLIT */ + +void tref(register token_p tp,int amount); + +#ifdef MAXSPLIT +int split(token_p tp,int *ip,int ply,int toplevel); +#endif /* MAXSPLIT */ + +unsigned docoerc(token_p tp,c3_p cp,int ply,int toplevel,int forced); +unsigned stackupto(token_p limit,int ply,int toplevel); +c3_p findcoerc(token_p tp,set_p tep); +void error(char *s, ...); +void fatal(char *s, ...); + +#ifndef NDEBUG +void badassertion(char* asstr,char *file,int line); +#endif + +int max(int a,int b); + + +#endif /* SUBR_H_ */ diff --git a/mach/proto/cg/types.h b/mach/proto/cg/types.h index 1b8a86b13..b8029ed68 100644 --- a/mach/proto/cg/types.h +++ b/mach/proto/cg/types.h @@ -2,7 +2,9 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ +#ifndef TYPES_H_ +#define TYPES_H_ + #ifndef TEM_WSIZE TEM_WSIZE should be defined at this point @@ -15,7 +17,7 @@ Implementation will not be correct unless a long integer has more then 4 bytes of precision. #endif -typedef char byte; +typedef unsigned char byte; typedef char * string; #if TEM_WSIZE>2 || TEM_PSIZE>2 @@ -28,3 +30,5 @@ typedef char * string; #ifndef WRD_FMT #define WRD_FMT "%ld" #endif /* WRD_FMT */ + +#endif /* TYPES_H_ */ diff --git a/mach/proto/cg/var.c b/mach/proto/cg/var.c index e55fe545e..b62486243 100644 --- a/mach/proto/cg/var.c +++ b/mach/proto/cg/var.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include "param.h" #include "tables.h" #include "types.h" @@ -9,12 +11,6 @@ static char rcsid[] = "$Id$"; #include "data.h" #include "result.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ int stackheight = 0; token_t fakestack[MAXFSTACK]; From f9916fb68099bd6f84db84ce04209a7bc1f758eb Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:12:48 +0800 Subject: [PATCH 60/84] Fix call to fwrite with proper parameters. --- util/arch/archiver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/arch/archiver.c b/util/arch/archiver.c index 3d6d30a0f..1a0e85afa 100644 --- a/util/arch/archiver.c +++ b/util/arch/archiver.c @@ -214,7 +214,7 @@ void error(BOOL quit, char *str1, char *str2) char errbuf[256]; sprint(errbuf, str1, str2); - fwrite(errbuf, strlen(errbuf), 1, stderr); + fwrite(errbuf, 1, strlen(errbuf), stderr); if (quit) { remove(temp_arch); @@ -792,7 +792,7 @@ void write_symdef(FILE *ar) } #endif wr_arhdr(ar, &arbuf); - wr_long(ar, (long) tnum); + wr_int4(ar, (long) tnum); /* * Account for the space occupied by the magic number * and the ranlib table. @@ -804,7 +804,7 @@ void write_symdef(FILE *ar) } wr_ranlib(ar, tab, (long) tnum); - wr_long(ar, (long) tssiz); + wr_int4(ar, (long) tssiz); wr_bytes(ar, tstrtab, (long) tssiz); } From dfefbcae86100dddc837c3c9e55e614e61f2c454 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:13:43 +0800 Subject: [PATCH 61/84] ANSI C conversion. --- util/cgg/bootgram.y | 42 +- util/cgg/booth.h | 197 +++--- util/cgg/bootlex.l | 23 +- util/cgg/main.c | 1403 ++++++++++++++++++++++++------------------- 4 files changed, 922 insertions(+), 743 deletions(-) diff --git a/util/cgg/bootgram.y b/util/cgg/bootgram.y index d1ff22cfb..8f530713f 100644 --- a/util/cgg/bootgram.y +++ b/util/cgg/bootgram.y @@ -1,9 +1,5 @@ %{ -#ifndef NORCSID -static char rcsid[]="$Id$"; -#endif - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". @@ -15,13 +11,17 @@ static char rcsid[]="$Id$"; #include #include #include -#include -#include -#include +#include "em_spec.h" +#include "em_flag.h" +#include "em_reg.h" -#define extern +#define INIT_VAR +#define EXTERN #include "booth.h" -#undef extern +#undef INIT_VAR +#undef EXTERN + +extern int yylex(void); %} @@ -268,7 +268,7 @@ tokenexpression : PIDENT { $$ = machprops[$1->i_i.i_prpno].propset; } | TIDENT - { register i; + { register int i; for(i=0;ii_i.i_tokno+nmachregs+1)>>4] |= @@ -278,7 +278,7 @@ tokenexpression | EIDENT { $$=machsets[$1->i_i.i_expno]; } | tokenexpression '*' tokenexpression - { register i; + { register int i; if (($$.set_size=$1.set_size)==0) $$.set_size = $3.set_size; @@ -286,7 +286,7 @@ tokenexpression $$.set_val[i] = $1.set_val[i] & $3.set_val[i]; } | tokenexpression '+' tokenexpression - { register i; + { register int i; if ($1.set_size == -1) $$.set_size = $3.set_size; @@ -300,7 +300,7 @@ tokenexpression $$.set_val[i] = $1.set_val[i] | $3.set_val[i]; } | tokenexpression '-' tokenexpression - { register i; + { register int i; if ($1.set_size == -1) $$.set_size = $3.set_size; @@ -403,7 +403,7 @@ empattern : /* empty */ { empatlen=0; } | mnemlist optboolexpr - { register i; + { register int i; empatexpr = $2; patbyte(0); @@ -441,7 +441,7 @@ mnem : IDENT stackpattern : optnocoerc tokenexpressionlist optstack - { register i; + { register int i; if (tokpatlen != 0) { outbyte(($1 ? ( $3 ? DO_XXMATCH: DO_XMATCH ) : DO_MATCH)+(tokpatlen<<5)); @@ -1053,7 +1053,7 @@ tokeninstanceno tokeninstance : '%' '[' tokargno subreg ']' - { register i; + { register int i; if ($4!=0) chkregexp(pattokexp[$3]); @@ -1065,7 +1065,7 @@ tokeninstance } | '%' '[' tokargno '.' IDENT ']' { int typ; - register i; + register int i; $$.in_which = IN_COPY; $$.in_info[0] = $3; $$.in_info[1] = findstructel(pattokexp[$3],$5,&typ); @@ -1075,14 +1075,14 @@ tokeninstance $$.in_info[i] = 0; } | RIDENT - { register i; + { register int i; $$.in_which = IN_RIDENT; $$.in_info[0] = $1->i_i.i_regno; for (i=1;i= 'a'+nallreg) yyerror("Bad letter in %[x] construct"); $$.in_which = IN_ALLOC; @@ -1100,7 +1100,7 @@ tokeninstance $$.in_info[i] = 0; } | '{' TIDENT attlist '}' - { register i; + { register int i; $$.in_which = IN_DESCR; $$.in_info[0] = $2->i_i.i_tokno; for(i=0;i -#ifdef extern +#ifdef INIT_VAR #define INIT(x) = x #else #define INIT(x) /* empty */ @@ -33,9 +33,9 @@ #define MAXSPLIT 4 /* Maximum degree of split */ #define MAXNSTR 40 /* Maximum consecutive strings in coderule */ -extern char *hname INIT("tables.h"); -extern char *cname INIT("tables.c"); -extern char *iname; /* stdin */ +EXTERN char *hname INIT("tables.h"); +EXTERN char *cname INIT("tables.c"); +EXTERN char *iname; /* stdin */ /* Derived constants */ @@ -53,7 +53,7 @@ extern char *iname; /* stdin */ typedef char byte; typedef char * string; -extern char *myalloc(); +EXTERN char *myalloc(); #include @@ -108,7 +108,7 @@ typedef struct ident { } ident_t,*ident_p; #define ITABSIZE 32 -extern ident_p identtab[ITABSIZE]; +EXTERN ident_p identtab[ITABSIZE]; #define LOOKUP 0 #define HALFWAY 1 @@ -125,90 +125,90 @@ typedef struct expr { int expr_index; } expr_t,*expr_p; -extern unsigned cc1 INIT(1),cc2 INIT(1),cc3 INIT(1),cc4 INIT(1); +EXTERN unsigned cc1 INIT(1),cc2 INIT(1),cc3 INIT(1),cc4 INIT(1); -extern node_t nodes[MAXNODES]; -extern node_p lastnode INIT(nodes+1); +EXTERN node_t nodes[MAXNODES]; +EXTERN node_p lastnode INIT(nodes+1); -extern string codestrings[MAXSTRINGS]; -extern int ncodestrings; +EXTERN string codestrings[MAXSTRINGS]; +EXTERN int ncodestrings; -extern int strar[MAXNSTR]; -extern int nstr; +EXTERN int strar[MAXNSTR]; +EXTERN int nstr; -extern int pathash[256]; +EXTERN int pathash[256]; -extern reginfo machregs[MAXREGS]; -extern char stregclass[MAXREGS]; -extern int nmachregs INIT(1); -extern int nregclasses INIT(1); -extern int maxmembers; -extern struct { +EXTERN reginfo machregs[MAXREGS]; +EXTERN char stregclass[MAXREGS]; +EXTERN int nmachregs INIT(1); +EXTERN int nregclasses INIT(1); +EXTERN int maxmembers; +EXTERN struct { ident_p propname; set_t propset; } machprops[MAXPROPS]; -extern int nprops; -extern token_t machtokens[MAXTOKENS]; -extern int nmachtokens INIT(1); -extern set_t machsets[MAXSETS]; -extern int nmachsets; -extern int patmnem[MAXEMPATLEN]; -extern int empatlen; -extern int maxempatlen; -extern int empatexpr; -extern int maxrule INIT(1); -extern int pattokexp[MAXPATLEN]; -extern int tokpatlen; -extern int lookident; /* lexical analyzer flag */ -extern list3 structpool; -extern int nallreg; -extern int allreg[MAXALLREG]; -extern int maxallreg; -extern int lino; -extern int nerrors; -extern int curtokexp; -extern expr_t arexp[TOKENSIZE]; -extern int narexp; -extern inst_t arinstance[MAXINSTANCE]; -extern int narinstance INIT(1); -extern move_t machmoves[NMOVES]; -extern int nmoves; -extern byte pattern[MAXPATTERN]; -extern int npatbytes; -extern int prevind; -extern int rulecount; /* Temporary index for ... construct */ -extern int ncoderules; -extern int codebytes; -extern FILE *cfile; -extern FILE *hfile; -extern int maxtokensize; -extern int dealflag; -extern int emrepllen; -extern int replmnem[MAXEMPATLEN]; -extern int tokrepllen; -extern int replinst[MAXPATLEN]; -extern int replexpr[MAXPATLEN]; -extern c1_t c1coercs[MAXC1]; -extern c2_t c2coercs[MAXC2]; -extern c3_t c3coercs[MAXC3]; -extern int nc1,nc2,nc3; -extern int maxsplit; -extern int wsize INIT(-1); -extern int psize INIT(-1); -extern int bsize INIT(-1); -extern char *fmt; +EXTERN int nprops; +EXTERN token_t machtokens[MAXTOKENS]; +EXTERN int nmachtokens INIT(1); +EXTERN set_t machsets[MAXSETS]; +EXTERN int nmachsets; +EXTERN int patmnem[MAXEMPATLEN]; +EXTERN int empatlen; +EXTERN int maxempatlen; +EXTERN int empatexpr; +EXTERN int maxrule INIT(1); +EXTERN int pattokexp[MAXPATLEN]; +EXTERN int tokpatlen; +EXTERN int lookident; /* lexical analyzer flag */ +EXTERN list3 structpool; +EXTERN int nallreg; +EXTERN int allreg[MAXALLREG]; +EXTERN int maxallreg; +EXTERN int lino; +EXTERN int nerrors; +EXTERN int curtokexp; +EXTERN expr_t arexp[TOKENSIZE]; +EXTERN int narexp; +EXTERN inst_t arinstance[MAXINSTANCE]; +EXTERN int narinstance INIT(1); +EXTERN move_t machmoves[NMOVES]; +EXTERN int nmoves; +EXTERN byte pattern[MAXPATTERN]; +EXTERN int npatbytes; +EXTERN int prevind; +EXTERN int rulecount; /* Temporary index for ... construct */ +EXTERN int ncoderules; +EXTERN int codebytes; +EXTERN FILE *cfile; +EXTERN FILE *hfile; +EXTERN int maxtokensize; +EXTERN int dealflag; +EXTERN int emrepllen; +EXTERN int replmnem[MAXEMPATLEN]; +EXTERN int tokrepllen; +EXTERN int replinst[MAXPATLEN]; +EXTERN int replexpr[MAXPATLEN]; +EXTERN c1_t c1coercs[MAXC1]; +EXTERN c2_t c2coercs[MAXC2]; +EXTERN c3_t c3coercs[MAXC3]; +EXTERN int nc1,nc2,nc3; +EXTERN int maxsplit; +EXTERN int wsize INIT(-1); +EXTERN int psize INIT(-1); +EXTERN int bsize INIT(-1); +EXTERN char *fmt; -extern int cchandled; -extern int ccspoiled; -extern int ccregexpr; -extern int ccinstanceno; -extern int cocopropno; -extern int cocosetno; -extern int allexpno; +EXTERN int cchandled; +EXTERN int ccspoiled; +EXTERN int ccregexpr; +EXTERN int ccinstanceno; +EXTERN int cocopropno; +EXTERN int cocosetno; +EXTERN int allexpno; -extern int rvused; /* regvars used */ -extern int nregvar[4]; /* # of register variables of all kinds */ -extern int rvnumbers[4][MAXREGVARS]; /* The register numbers */ +EXTERN int rvused; /* regvars used */ +EXTERN int nregvar[4]; /* # of register variables of all kinds */ +EXTERN int rvnumbers[4][MAXREGVARS]; /* The register numbers */ #define chktabsiz(size,maxsize,which) if(size>=maxsize) tabovf(which) @@ -217,7 +217,36 @@ extern int rvnumbers[4][MAXREGVARS]; /* The register numbers */ #define MUST1BEBOOL(e) int exp1=e.expr_index;tstbool(e) #define MUST2BEBOOL(e1,e2) int exp1=e1.expr_index,exp2=e2.expr_index;tstbool(e1);tstbool(e2) -extern ident_p ilookup(); -extern list2 lookstruct(); -extern string scopy(); -extern unsigned hash(); +ident_p ilookup(string name, int enterf); +unsigned hash(register string name); +int lookup(int comm, int operator, int lnode, int rnode); +list2 lookstruct(list2 ll); +string scopy(string s); +void tabovf(string tablename); +int strlookup(string s); +int structsize(register list2 s); +void yyerror(string s, ...); +int instno(inst_t inst); +int yyparse(void); +int stringno(register string s); +int exprlookup(set_t sett); +void tstint(expr_t e); +void tstbool(expr_t e); +void inbetween(void); +int formconversion(register char *p, register token_p tp); +void setfields(register token_p tp, string format); +void chkregexp(int number); +int findstructel(int number, string name, int *t); +int argtyp(int mn); +int commontype(expr_t e1, expr_t e2); +void inithash(void); +void enter(char *name, int value); +int mlookup(char *name); +void hashpatterns(void); +int max(int a, int b); +void out(int n); +void outbyte(int n); +void pat(int n); +void patshort(int n); +void patbyte(int n); + diff --git a/util/cgg/bootlex.l b/util/cgg/bootlex.l index 3fba33c7e..07599eeb3 100644 --- a/util/cgg/bootlex.l +++ b/util/cgg/bootlex.l @@ -1,8 +1,5 @@ %{ -#ifndef NORCSID -static char rcsid2[]="$Id$"; -#endif /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". @@ -14,11 +11,14 @@ static char rcsid2[]="$Id$"; #include #include -#include -#include -#include +#include +#include "em_spec.h" +#include "em_flag.h" +#include "em_reg.h" +#define EXTERN extern #include "booth.h" +#undef EXTERN #include "y.tab.h" int lineno = 1; @@ -158,10 +158,15 @@ return return(RETURN); . return(yytext[0]); %% -yyerror(s,a1,a2,a3,a4) string s; { +void yyerror(string s, ...) +{ + va_list ap; + va_start(ap, s); + fprintf(stderr,"\"%s\", line %d:",iname ? iname : "",lineno); - fprintf(stderr,s,a1,a2,a3,a4); + vfprintf(stderr,s,ap); fprintf(stderr,"\n"); - nerrors++; + nerrors++; + va_end(ap); } diff --git a/util/cgg/main.c b/util/cgg/main.c index 86375b776..75a066e5e 100644 --- a/util/cgg/main.c +++ b/util/cgg/main.c @@ -3,248 +3,316 @@ #include #include #include -#include -#include -#include +#include "em_spec.h" +#include "em_flag.h" +#include "em_reg.h" +#define EXTERN extern #include "booth.h" +#undef EXTERN -char * myalloc(n) { +/* Forward local declarations. */ +static void debug(void); +static void verbose(void); +static void outregvar(void); +static void finishio(void); +static void inittables(void); +static void initio(void); +static int eqregclass(int r1, int r2); +static void compueq(void); + + + +char *myalloc(int n) +{ register char *p; - p= malloc((unsigned)n); - if (p==0) { + p = malloc((unsigned) n); + if (p == 0) + { yyerror("Out of core"); exit(1); } - return(p); + return (p); } -tstint(e) expr_t e; { +void tstint(expr_t e) +{ - if(e.expr_typ != TYPINT) + if (e.expr_typ != TYPINT) yyerror("Must be integer expression"); } -tstbool(e) expr_t e; { +void tstbool(expr_t e) +{ - if(e.expr_typ != TYPBOOL) + if (e.expr_typ != TYPBOOL) yyerror("Must be boolean expression"); } -structsize(s) register list2 s; { +int structsize(register list2 s) +{ register list1 l; - register sum; + register int sum; sum = 0; - while ( s != 0 ) { + while (s != 0) + { l = s->l2list->l1next; - while ( l != 0 ) { + while (l != 0) + { sum++; l = l->l1next; } s = s->l2next; } - return(sum); + return (sum); } -list2 lookstruct(ll) list2 ll; { - list3 l3; - list2 l21,l22; - list1 l11,l12; +static int isasc(int c) +{ + if ((c >= 0 && c <= 0177)) + return 1; + return 0; +} - for (l3=structpool;l3 != 0;l3=l3->l3next) { - for (l21=l3->l3list,l22=ll;l21!=0 && l22!=0; - l21=l21->l2next,l22=l22->l2next) { - for(l11=l21->l2list,l12=l22->l2list; - l11!=0 && l12!=0 && strcmp(l11->l1name,l12->l1name)==0; - l11=l11->l1next,l12=l12->l1next) +list2 lookstruct(list2 ll) +{ + list3 l3; + list2 l21, l22; + list1 l11, l12; + + for (l3 = structpool; l3 != 0; l3 = l3->l3next) + { + for (l21 = l3->l3list, l22 = ll; l21 != 0 && l22 != 0; l21 = + l21->l2next, l22 = l22->l2next) + { + for (l11 = l21->l2list, l12 = l22->l2list; + l11 != 0 && l12 != 0 + && strcmp(l11->l1name, l12->l1name) == 0; + l11 = l11->l1next, l12 = l12->l1next) ; - if (l11!=0 || l12!=0) + if (l11 != 0 || l12 != 0) goto contin; } - if(l21==0 && l22==0) - return(l3->l3list); - contin:; + if (l21 == 0 && l22 == 0) + return (l3->l3list); + contin: ; } l3 = (list3) myalloc(sizeof(struct list3str)); - l3->l3next=structpool; - l3->l3list=ll; - structpool=l3; - return(ll); + l3->l3next = structpool; + l3->l3list = ll; + structpool = l3; + return (ll); } -instno(inst) inst_t inst; { - register i,j; +int instno(inst_t inst) +{ + register int i, j; - for(i=1;itokpatlen) - yyerror("Number within %[] out of range"); - if (*s == ']') { + case '$': s++; - *p++ = PR_TOK; - *p++ = num; - } else if (*s++ != '.') - yyerror("Bad character following %%[digit in codestring"); - else { - char field[256]; - register char *f=field; - int type,offset; - - while( *s != ']' && *s != 0) - *f++ = *s++; - *f++ = 0; - if (*s != ']') - yyerror("Unterminated %[] construction in codestring"); + switch (*s) + { + default: + yyerror("Bad character after $ in codestring"); + case '$': + *p++ = *s++; + continue; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + *p++ = argtyp(patmnem[*s - '0']) == TYPINT ? + PR_EMINT : PR_EMSTR; + *p++ = *s++ - '0'; + continue; + } + case '%': + s++; + if (*s != '[') + { + if (*s == '%') + { + *p++ = *s++; + continue; + } + else + yyerror("Bad character following %% in codestring"); + } else s++; - if (isdigit(field[0])) { - chkregexp(pattokexp[num]); - *p++ = PR_SUBREG; - *p++ = num; - *p++ = atoi(field); - } else { - offset = findstructel(pattokexp[num],field,&type); - *p++ = PR_TOKFLD; - *p++ = num; - *p++ = offset; + if (isdigit(*s)) + { + int num; + num = *s++ - '0'; + if (num < 1 || num > tokpatlen) + yyerror("Number within %[] out of range"); + if (*s == ']') + { + s++; + *p++ = PR_TOK; + *p++ = num; + } + else if (*s++ != '.') + yyerror( + "Bad character following %%[digit in codestring"); + else + { + char field[256]; + register char *f = field; + int type, offset; + + while (*s != ']' && *s != 0) + *f++ = *s++; + *f++ = 0; + if (*s != ']') + yyerror( + "Unterminated %[] construction in codestring"); + else + s++; + if (isdigit(field[0])) + { + chkregexp(pattokexp[num]); + *p++ = PR_SUBREG; + *p++ = num; + *p++ = atoi(field); + } + else + { + offset = findstructel(pattokexp[num], field, &type); + *p++ = PR_TOKFLD; + *p++ = num; + *p++ = offset; + } + } } - } - } else if (*s >= 'a' && *s < 'a'+nallreg) { - int reg,subreg; - reg = *s++ -'a'+1; - if(*s == ']') - subreg = 255; - else { - if (*s != '.') - yyerror("Bad character following %%[x in codestring"); - s++; - if(!isdigit(*s)) - yyerror("Bad character following %%[x. in codestring"); - subreg = *s - '0'; - s++; - if(*s != ']') - yyerror("Bad character following %%[x.y in codestring"); - } - s++; - *p++ = PR_ALLREG; - *p++ = reg; - *p++ = subreg; - } else - yyerror("Bad character following %%[ in codestring"); - } + else if (*s >= 'a' && *s < 'a' + nallreg) + { + int reg, subreg; + reg = *s++ - 'a' + 1; + if (*s == ']') + subreg = 255; + else + { + if (*s != '.') + yyerror( + "Bad character following %%[x in codestring"); + s++; + if (!isdigit(*s)) + yyerror( + "Bad character following %%[x. in codestring"); + subreg = *s - '0'; + s++; + if (*s != ']') + yyerror( + "Bad character following %%[x.y in codestring"); + } + s++; + *p++ = PR_ALLREG; + *p++ = reg; + *p++ = subreg; + } + else + yyerror("Bad character following %%[ in codestring"); + } *p++ = 0; - return(strlookup(buf)); + return (strlookup(buf)); } -tabovf(tablename) string tablename; { +void tabovf(string tablename) +{ char buf[256]; - sprintf(buf,"%s overflow",tablename); + sprintf(buf, "%s overflow", tablename); yyerror(buf); - exit(-1); + exit(EXIT_FAILURE); } -main(argc,argv) char *argv[]; { +int main(int argc, char *argv[]) +{ - while (--argc) { + while (--argc) + { ++argv; - if (argv[0][0]=='-') { - switch (argv[0][1]) { - case 'h': - hname= &argv[0][2]; - break; - case 'c': - cname= &argv[0][2]; - break; - default: - fprintf(stderr,"Bad flag %s\n",argv[0]); - break; + if (argv[0][0] == '-') + { + switch (argv[0][1]) + { + case 'h': + hname = &argv[0][2]; + break; + case 'c': + cname = &argv[0][2]; + break; + default: + fprintf(stderr, "Bad flag %s\n", argv[0]); + break; } - } else { - iname= argv[0]; + } + else + { + iname = argv[0]; } } inithash(); initio(); inittables(); yyparse(); - if (nerrors==0) { + if (nerrors == 0) + { compueq(); hashpatterns(); finishio(); @@ -254,16 +322,18 @@ main(argc,argv) char *argv[]; { exit(nerrors); } -lookup(comm,operator,lnode,rnode) { +int lookup(int comm, int operator, int lnode, int rnode) +{ register node_p p; - for (p=nodes+1;pex_operator != operator) continue; - if (!(p->ex_lnode == lnode && p->ex_rnode == rnode || - comm && p->ex_lnode == rnode && p->ex_rnode == lnode)) + if (!((p->ex_lnode == lnode && p->ex_rnode == rnode) + || (comm && p->ex_lnode == rnode && p->ex_rnode == lnode))) continue; - return(p-nodes); + return (p - nodes); } if (lastnode >= &nodes[MAXNODES]) yyerror("node table overflow"); @@ -271,444 +341,481 @@ lookup(comm,operator,lnode,rnode) { p->ex_operator = operator; p->ex_lnode = lnode; p->ex_rnode = rnode; - return(p-nodes); + return (p - nodes); } -compueq() { - register i,j; +static void compueq(void) +{ + register int i, j; - for (i=1;i>4]; +static int eqregclass(int r1, int r2) +{ + register reginfo rp1, rp2; + register int i; + short regbits[(MAXREGS + 15) >> 4]; int member; - rp1 = machregs[r1]; rp2 = machregs[r2]; - for (i=0;i<((nprops+15)>>4);i++) + rp1 = machregs[r1]; + rp2 = machregs[r2]; + for (i = 0; i < ((nprops + 15) >> 4); i++) if (rp1->rprop[i] != rp2->rprop[i]) - return(0); - for (i=0;i<((MAXREGS+15)>>4);i++) + return (0); + for (i = 0; i < ((MAXREGS + 15) >> 4); i++) regbits[i] = 0; - for (i=0;irmembers[i]) - regbits[member>>4] |= (1<<(member&017)); + for (i = 0; i < maxmembers; i++) + { + if ((member = rp1->rmembers[i])) + regbits[member >> 4] |= (1 << (member & 017)); } - for (i=0;irmembers[i]; - if (regbits[member>>4]&(1<<(member&017))) - return(0); + if (regbits[member >> 4] & (1 << (member & 017))) + return (0); } - return(1); + return (1); } -unsigned hash(name) register string name; { +unsigned hash(register string name) +{ register unsigned sum; - register i; + register int i; - for (sum=i=0;*name;i+=3) - sum ^= (*name++)<<(i&07); - return(sum); + for (sum = i = 0; *name; i += 3) + sum ^= (*name++) << (i & 07); + return (sum); } -ident_p ilookup(name,enterf) string name; int enterf; { - register ident_p p,*pp; +ident_p ilookup(string name, int enterf) +{ + register ident_p p, *pp; - pp = &identtab[hash(name)%ITABSIZE]; - while (*pp != 0) { - if (strcmp((*pp)->i_name,name)==0) + pp = &identtab[hash(name) % ITABSIZE]; + while (*pp != 0) + { + if (strcmp((*pp)->i_name, name) == 0) + { if (enterf != ENTER) - return(*pp); + return (*pp); else yyerror("Multiply defined symbol"); + } pp = &(*pp)->i_next; } if (enterf == LOOKUP) yyerror("Undefined symbol"); if (enterf == JUSTLOOKING) - return(0); + return (0); p = *pp = (ident_p) myalloc(sizeof(ident_t)); p->i_name = name; p->i_next = 0; p->i_type = 0; - return(p); + return (p); } -initio() { +static void initio(void) +{ - if (iname!=0 && freopen(iname,"r",stdin)==NULL) { - fprintf(stderr,"Can't open %s\n",iname); + if (iname != 0 && freopen(iname, "r", stdin) == NULL) + { + fprintf(stderr, "Can't open %s\n", iname); exit(-1); } - if ((cfile=fopen(cname,"w"))==NULL) { - fprintf(stderr,"Can't create %s\n",cname); + if ((cfile = fopen(cname, "w")) == NULL) + { + fprintf(stderr, "Can't create %s\n", cname); exit(-1); } - if ((hfile=fopen(hname,"w"))==NULL) { - fprintf(stderr,"Can't create %s\n",hname); + if ((hfile = fopen(hname, "w")) == NULL) + { + fprintf(stderr, "Can't create %s\n", hname); exit(-1); } - fprintf(cfile,"#include \"param.h\"\n"); - fprintf(cfile,"#include \"tables.h\"\n"); - fprintf(cfile,"#include \"types.h\"\n"); - fprintf(cfile,"#include \n"); - fprintf(cfile,"#include \"data.h\"\n"); - fprintf(cfile,"\nbyte coderules[] = {\n"); + fprintf(cfile, "#include \"param.h\"\n"); + fprintf(cfile, "#include \"tables.h\"\n"); + fprintf(cfile, "#include \"types.h\"\n"); + fprintf(cfile, "#include \n"); + fprintf(cfile, "#include \"data.h\"\n"); + fprintf(cfile, "\nbyte coderules[] = {\n"); patbyte(0); } -exprlookup(sett) set_t sett; { - register i,j,ok; +int exprlookup(set_t sett) +{ + register int i, j, ok; - for(i=0;irname = "cc reg"; r->rrepr = "CC"; r->rsize = -1; - r->rregvar= -1; - for(i=0;irregvar = -1; + for (i = 0; i < MAXMEMBERS; i++) r->rmembers[i] = 0; - for(i=0;irprop[i] = 0; - r->rprop[cocopropno>>4] |= (1<<(cocopropno&017)); - chktabsiz(nmachregs,MAXREGS,"Register table"); - machregs[nmachregs++] = r; + r->rprop[cocopropno >> 4] |= (1 << (cocopropno & 017)); + chktabsiz(nmachregs, MAXREGS, "Register table"); + machregs[nmachregs++] = r; inst.in_which = IN_RIDENT; - inst.in_info[0] = nmachregs-1; - for(i=1;i>4] |= (01<<(nmachregs&017)); - cocosetno=exprlookup(sett); + inst.in_info[0] = nmachregs - 1; + for (i = 1; i < TOKENSIZE; i++) + inst.in_info[i] = 0; + ccinstanceno = instno(inst); + ccregexpr = lookup(0, EX_REG, nmachregs - 1, 0); + sett.set_size = 0; + for (i = 0; i < SETSIZE; i++) + sett.set_val[i] = 0; + sett.set_val[nmachregs >> 4] |= (01 << (nmachregs & 017)); + cocosetno = exprlookup(sett); } -outregs() { - register i,j,k; - static short rset[(MAXREGS+15)>>4]; - int t,ready; +static void outregs(void) +{ + register int i, j, k; + static short rset[(MAXREGS + 15) >> 4]; + int t, ready; - fprintf(cfile,"char stregclass[] = {\n"); - for (i=0;irrepr), - machregs[i]->rsize); - if (maxmembers!=0) { - fprintf(cfile,",{"); - for(j=0;jrmembers[j]); + fprintf(cfile, "char stregclass[] = {\n"); + for (i = 0; i < nmachregs; i++) + fprintf(cfile, "\t%d,\n", stregclass[i]); + fprintf(cfile, "};\n\nstruct reginfo machregs[] = {\n{0},\n"); + for (i = 1; i < nmachregs; i++) + { + fprintf(cfile, "{%d,%d", strlookup(machregs[i]->rrepr), + machregs[i]->rsize); + if (maxmembers != 0) + { + fprintf(cfile, ",{"); + for (j = 0; j < maxmembers; j++) + fprintf(cfile, "%d,", machregs[i]->rmembers[j]); /* now compute and print set of registers * that clashes with this register. * A register clashes with al its children (and theirs) * and with all their parents. */ - for (j=0;j<((MAXREGS+15)>>4);j++) - rset[j]=0; - rset[i>>4] |= (1<<(i&017)); - do { - ready=1; - for (j=1;j>4]&(1<<(j&017))) - for (k=0;krmembers[k])!=0) { - if ((rset[t>>4]&(1<<(t&017)))==0) - ready=0; - rset[t>>4] |= (1<<(t&017)); - } + for (j = 0; j < ((MAXREGS + 15) >> 4); j++) + rset[j] = 0; + rset[i >> 4] |= (1 << (i & 017)); + do + { + ready = 1; + for (j = 1; j < nmachregs; j++) + if (rset[j >> 4] & (1 << (j & 017))) + for (k = 0; k < maxmembers; k++) + if ((t = machregs[j]->rmembers[k]) != 0) + { + if ((rset[t >> 4] & (1 << (t & 017))) == 0) + ready = 0; + rset[t >> 4] |= (1 << (t & 017)); + } } while (!ready); - do { - ready=1; - for (j=1;jrmembers[k])!=0) - if (rset[t>>4]&(1<<(t&017))) { - if (rset[j>>4]&(1<<(j&017))==0) - ready=0; - rset[j>>4] |= (1<<(j&017)); - } + do + { + ready = 1; + for (j = 1; j < nmachregs; j++) + for (k = 0; k < maxmembers; k++) + if ((t = machregs[j]->rmembers[k]) != 0) + if (rset[t >> 4] & (1 << (t & 017))) + { + if ((rset[j >> 4] & (1 << (j & 017))) == 0) + ready = 0; + rset[j >> 4] |= (1 << (j & 017)); + } } while (!ready); - fprintf(cfile,"},{"); - for (j=0;j<((nmachregs+15)>>4);j++) - fprintf(cfile,"%d,",rset[j]); - fprintf(cfile,"}"); + fprintf(cfile, "},{"); + for (j = 0; j < ((nmachregs + 15) >> 4); j++) + fprintf(cfile, "%d,", rset[j]); + fprintf(cfile, "}"); } - if (machregs[i]->rregvar>=0) - fprintf(cfile,",1"); - fprintf(cfile,"},\n"); + if (machregs[i]->rregvar >= 0) + fprintf(cfile, ",1"); + fprintf(cfile, "},\n"); } - fprintf(cfile,"};\n\n"); + fprintf(cfile, "};\n\n"); } -finishio() { - register i; +static void finishio(void) +{ + register int i; register node_p np; int j; int setsize; register move_p mp; - fprintf(cfile,"};\n\n"); - if (wsize>0) - fprintf(hfile,"#define TEM_WSIZE %d\n",wsize); + fprintf(cfile, "};\n\n"); + if (wsize > 0) + fprintf(hfile, "#define TEM_WSIZE %d\n", wsize); else yyerror("Wordsize undefined"); - if (psize>0) - fprintf(hfile,"#define TEM_PSIZE %d\n",psize); + if (psize > 0) + fprintf(hfile, "#define TEM_PSIZE %d\n", psize); else yyerror("Pointersize undefined"); - if (bsize>=0) - fprintf(hfile,"#define TEM_BSIZE %d\n",bsize); + if (bsize >= 0) + fprintf(hfile, "#define TEM_BSIZE %d\n", bsize); else yyerror("EM_BSIZE undefined"); - if (fmt!=0) - fprintf(hfile,"#define WRD_FMT \"%s\"\n",fmt); - fprintf(hfile,"#define MAXALLREG %d\n",maxallreg); - setsize = (nmachregs+1 + nmachtokens + 15)>>4; - fprintf(hfile,"#define SETSIZE %d\n",setsize); - fprintf(hfile,"#define NPROPS %d\n",nprops); - fprintf(hfile,"#define NREGS %d\n",nmachregs); - fprintf(hfile,"#define REGSETSIZE %d\n",(nmachregs+15)>>4); - fprintf(hfile,"#define TOKENSIZE %d\n",maxtokensize); - fprintf(hfile,"#define MAXMEMBERS %d\n",maxmembers); - fprintf(hfile,"#define LONGESTPATTERN %d\n",maxempatlen); - fprintf(hfile,"#define MAXRULE %d\n",maxrule); - fprintf(hfile,"#define NMOVES %d\n",nmoves); - fprintf(hfile,"#define NC1 %d\n",nc1); - if (nc2) { - assert(maxsplit!=0); - fprintf(hfile,"#define NC2 %d\n",nc2); - fprintf(hfile,"#define MAXSPLIT %d\n",maxsplit); + if (fmt != 0) + fprintf(hfile, "#define WRD_FMT \"%s\"\n", fmt); + fprintf(hfile, "#define MAXALLREG %d\n", maxallreg); + setsize = (nmachregs + 1 + nmachtokens + 15) >> 4; + fprintf(hfile, "#define SETSIZE %d\n", setsize); + fprintf(hfile, "#define NPROPS %d\n", nprops); + fprintf(hfile, "#define NREGS %d\n", nmachregs); + fprintf(hfile, "#define REGSETSIZE %d\n", (nmachregs + 15) >> 4); + fprintf(hfile, "#define TOKENSIZE %d\n", maxtokensize); + fprintf(hfile, "#define MAXMEMBERS %d\n", maxmembers); + fprintf(hfile, "#define LONGESTPATTERN %d\n", maxempatlen); + fprintf(hfile, "#define MAXRULE %d\n", maxrule); + fprintf(hfile, "#define NMOVES %d\n", nmoves); + fprintf(hfile, "#define NC1 %d\n", nc1); + if (nc2) + { + assert(maxsplit != 0); + fprintf(hfile, "#define NC2 %d\n", nc2); + fprintf(hfile, "#define MAXSPLIT %d\n", maxsplit); } - fprintf(hfile,"#define NC3 %d\n",nc3); + fprintf(hfile, "#define NC3 %d\n", nc3); outregs(); - fprintf(cfile,"tkdef_t tokens[] = {\n"); - for(i=0;iex_operator,np->ex_lnode, + fprintf(cfile, "};\n\nnode_t enodes[] = {\n"); + for (np = nodes; np < lastnode; np++) + fprintf(cfile, "{%d,%d,%d},\n", np->ex_operator, np->ex_lnode, np->ex_rnode); - fprintf(cfile,"};\n\nstring codestrings[] = {\n"); - for(i=0;i>6)&03, - but this triggered a bug in GCC 2.4.5 - on SPARC. - */ - fprintf(cfile,"\\%c%c%c",((*p>>6) &03)+'0', - ((c>>3)&07)+'0',(c&07)+'0'); + but this triggered a bug in GCC 2.4.5 + on SPARC. + */ + fprintf(cfile, "\\%c%c%c", ((*p >> 6) & 03) + '0', + ((c >> 3) & 07) + '0', (c & 07) + '0'); } - else putc(c, cfile); + else + putc(c, cfile); p++; } - fprintf(cfile,"\",\n"); + fprintf(cfile, "\",\n"); } - fprintf(cfile,"};\n\nset_t machsets[] = {\n"); - for(i=0;im_set1, mp->m_expr1, - mp->m_set2, mp->m_expr2, - mp->m_cindex, - mp->m_cost.c_size,mp->m_cost.c_time); + fprintf(cfile, "{%d,%d,%d,%d,%d,{%d,%d}},\n", mp->m_set1, mp->m_expr1, + mp->m_set2, mp->m_expr2, mp->m_cindex, mp->m_cost.c_size, + mp->m_cost.c_time); } - fprintf(cfile,"};\n\nbyte pattern[] = {\n"); - for (i=0;irregvar<0 && - (machprops[i].propset.set_val[j>>4]&(1<<(j&017)))) - fprintf(cfile,"\t&machregs[%d],\n",j-1); + fprintf(cfile, "};\n\nc3_t c3coercs[] = {\n"); + for (i = 0; i < nc3; i++) + fprintf(cfile, "{%d,%d,%d,%d},\n", c3coercs[i].c3_texpno, + c3coercs[i].c3_prop, c3coercs[i].c3_repl, c3coercs[i].c3_codep); + fprintf(cfile, "};\n\n"); + for (i = 0; i < nprops; i++) + { + fprintf(cfile, "struct reginfo *rlist%d[] = {\n", i); + for (j = 2; j <= nmachregs; j++) + { + if (machregs[j - 1]->rregvar < 0 + && (machprops[i].propset.set_val[j >> 4] & (1 << (j & 017)))) + fprintf(cfile, "\t&machregs[%d],\n", j - 1); } - fprintf(cfile,"\t0\n};\n"); + fprintf(cfile, "\t0\n};\n"); } - fprintf(cfile,"struct reginfo **reglist[] = {\n"); - for (i=0;i0) - fprintf(cfile,"struct regassigned ratar%d[%d];\n", - i,nregvar[i]); - for (i=0;i<4;i++) if (nregvar[i]>0) { - fprintf(cfile,"int rvtar%d[] = {",i); - for (j=0;j0) - fprintf(cfile,"\trvtar%d,\n",i); + fprintf(hfile, "#define REGVARS\n"); + fprintf(cfile, "#include \"regvar.h\"\n"); + fprintf(cfile, "int nregvar[4] = { "); + for (i = 0; i < 4; i++) + fprintf(cfile, "%d, ", nregvar[i]); + fprintf(cfile, "};\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(cfile, "struct regassigned ratar%d[%d];\n", i, nregvar[i]); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + { + fprintf(cfile, "int rvtar%d[] = {", i); + for (j = 0; j < nregvar[i]; j++) + fprintf(cfile, "%d,", rvnumbers[i][j]); + fprintf(cfile, "};\n"); + } + fprintf(cfile, "\nint *rvnumbers[] = {\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(cfile, "\trvtar%d,\n", i); else - fprintf(cfile,"\t0,\n"); - fprintf(cfile,"};\n\nstruct regassigned *regassigned[] = {\n"); - for (i=0;i<4;i++) - if (nregvar[i]>0) - fprintf(cfile,"\tratar%d,\n",i); + fprintf(cfile, "\t0,\n"); + fprintf(cfile, "};\n\nstruct regassigned *regassigned[] = {\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(cfile, "\tratar%d,\n", i); else - fprintf(cfile,"\t0,\n"); - fprintf(cfile,"};\n"); + fprintf(cfile, "\t0,\n"); + fprintf(cfile, "};\n"); } -verbose() { +static void verbose(void) +{ - fprintf(stderr,"Codebytes %d\n",codebytes); - fprintf(stderr,"Registers %d(%d)\n",nmachregs,MAXREGS); - fprintf(stderr,"Properties %d(%d)\n",nprops,MAXPROPS); - fprintf(stderr,"Tokens %d(%d)\n",nmachtokens,MAXTOKENS); - fprintf(stderr,"Sets %d(%d)\n",nmachsets,MAXSETS); - fprintf(stderr,"Tokeninstances %d(%d)\n",narinstance,MAXINSTANCE); - fprintf(stderr,"Strings %d(%d)\n",ncodestrings,MAXSTRINGS); - fprintf(stderr,"Enodes %d(%d)\n",lastnode-nodes,MAXNODES); - fprintf(stderr,"Patbytes %d(%d)\n",npatbytes,MAXPATTERN); + fprintf(stderr, "Codebytes %d\n", codebytes); + fprintf(stderr, "Registers %d(%d)\n", nmachregs, MAXREGS); + fprintf(stderr, "Properties %d(%d)\n", nprops, MAXPROPS); + fprintf(stderr, "Tokens %d(%d)\n", nmachtokens, MAXTOKENS); + fprintf(stderr, "Sets %d(%d)\n", nmachsets, MAXSETS); + fprintf(stderr, "Tokeninstances %d(%d)\n", narinstance, MAXINSTANCE); + fprintf(stderr, "Strings %d(%d)\n", ncodestrings, MAXSTRINGS); + fprintf(stderr, "Enodes %d(%d)\n", lastnode - nodes, MAXNODES); + fprintf(stderr, "Patbytes %d(%d)\n", npatbytes, MAXPATTERN); } -inbetween() { +void inbetween(void) +{ register ident_p ip; - register i,j; + register int i, j; register move_p mp; - lookident=1; /* for lexical analysis */ + lookident = 1; /* for lexical analysis */ - chktabsiz(nmachsets+1,MAXSETS,"Expressiontable"); - for (i=0;ii_type=IEXP; + ip = ilookup("SCRATCH", ENTER); + ip->i_type = IEXP; ip->i_i.i_expno = nmachsets++; - for (i=0;ii_type=IEXP; + ip = ilookup("ALL", ENTER); + ip->i_type = IEXP; allexpno = ip->i_i.i_expno = nmachsets++; mp = &machmoves[nmoves++]; mp->m_set1 = cocosetno; mp->m_expr1 = 0; - mp->m_set2 = nmachsets-1; + mp->m_set2 = nmachsets - 1; mp->m_expr2 = 0; mp->m_cindex = 0; mp->m_cost.c_size = 0; @@ -718,299 +825,337 @@ inbetween() { * Create sets of registers per property */ - for (i=0;irprop[i>>4]&(1<<(i&017))) - sp[j>>4] |= (1<<(j&017)); + for (j = 2; j <= nmachregs; j++) + if (machregs[j - 1]->rprop[i >> 4] & (1 << (i & 017))) + sp[j >> 4] |= (1 << (j & 017)); } } -formconversion(p,tp) register char *p; register token_p tp; { +int formconversion(register char *p, register token_p tp) +{ char buf[256]; - register char *q=buf; + register char *q = buf; char field[256]; register char *f; int i; - if (p==0) - return(0); - while (*p) switch(*p) { - default: *q++ = *p++; continue; - case '%': - p++; - if(*p == '%') { - *q++ = *p++; - continue; + if (p == 0) + return (0); + while (*p) + switch (*p) + { + default: + *q++ = *p++; + continue; + case '%': + p++; + if (*p == '%') + { + *q++ = *p++; + continue; + } + if (*p == '[') + p++; + else + yyerror("Bad character after % in format"); + f = field; + while (*p != 0 && *p != ']') + *f++ = *p++; + *f++ = 0; + if (*p == ']') + p++; + else + yyerror("Unterminated %[] construct in format"); + for (i = 0; i < TOKENSIZE - 1; i++) + if (strcmp(field, tp->t_fields[i].t_sname) == 0) + break; + if (i == TOKENSIZE - 1) + yyerror("Unknown field in %[] construct in format"); + *q++ = i + 1; } - if (*p == '[') - p++; - else - yyerror("Bad character after % in format"); - f=field; - while (*p != 0 && *p != ']') - *f++ = *p++; - *f++ = 0; - if (*p == ']') - p++; - else - yyerror("Unterminated %[] construct in format"); - for (i=0;it_fields[i].t_sname)==0) - break; - if (i==TOKENSIZE-1) - yyerror("Unknown field in %[] construct in format"); - *q++ = i+1; - } *q++ = 0; - return(strlookup(buf)); + return (strlookup(buf)); } -setfields(tp,format) register token_p tp; string format; { - register i; +void setfields(register token_p tp, string format) +{ + register int i; list2 ll; register list1 l; int type; - for(i=0;it_fields[i].t_type = 0; - i=0; - for(ll=tp->t_struct;ll!=0;ll=ll->l2next) { - l=ll->l2list; - if(strcmp(l->l1name,"REGISTER")==0) + i = 0; + for (ll = tp->t_struct; ll != 0; ll = ll->l2next) + { + l = ll->l2list; + if (strcmp(l->l1name, "REGISTER") == 0) type = TYPREG; - else if (strcmp(l->l1name,"INT")==0) + else if (strcmp(l->l1name, "INT") == 0) type = TYPINT; - else type = TYPSTR; - for(l=l->l1next;l!=0;l=l->l1next) { + else + type = TYPSTR; + for (l = l->l1next; l != 0; l = l->l1next) + { tp->t_fields[i].t_type = type; tp->t_fields[i].t_sname = l->l1name; i++; } } if (format != 0) - tp->t_format = formconversion(format,tp); + tp->t_format = formconversion(format, tp); else tp->t_format = -1; } -chkregexp(number) { - register i; +void chkregexp(int number) +{ + register int i; - for(i=nmachregs+1;i>4]&(01<<(i&017))) + for (i = nmachregs + 1; i < nmachregs + 1 + nmachtokens; i++) + if (machsets[number].set_val[i >> 4] & (01 << (i & 017))) yyerror("No tokens allowed in this set"); } -findstructel(number,name,t) string name; int *t; { - register i; +int findstructel(int number, string name, int *t) +{ + register int i; register token_p tp; register list2 structdecl; int offset; - for(i=1;i<=nmachregs;i++) - if (machsets[number].set_val[i>>4]&(01<<(i&017))) + for (i = 1; i <= nmachregs; i++) + if (machsets[number].set_val[i >> 4] & (01 << (i & 017))) yyerror("No registers allowed in this set"); structdecl = 0; - for (i=nmachregs+1;i>4]&(01<<(i&017))) { - if (structdecl == 0) { - structdecl = machtokens[i-(nmachregs+1)].t_struct; - tp = &machtokens[i-(nmachregs+1)]; - } else if(structdecl != machtokens[i-(nmachregs+1)].t_struct) - yyerror("Multiple structs in this set"); + for (i = nmachregs + 1; i < nmachregs + 1 + nmachtokens; i++) + { + if (machsets[number].set_val[i >> 4] & (01 << (i & 017))) + { + if (structdecl == 0) + { + structdecl = machtokens[i - (nmachregs + 1)].t_struct; + tp = &machtokens[i - (nmachregs + 1)]; + } + else if (structdecl != machtokens[i - (nmachregs + 1)].t_struct) + yyerror("Multiple structs in this set"); } } - if (structdecl == 0) { + if (structdecl == 0) + { yyerror("No structs in this set"); - return(0); + return (0); } - for(offset=0;offsett_fields[offset].t_type != 0 && - strcmp(tp->t_fields[offset].t_sname,name)==0) { + for (offset = 0; offset < TOKENSIZE - 1; offset++) + if (tp->t_fields[offset].t_type != 0 + && strcmp(tp->t_fields[offset].t_sname, name) == 0) + { *t = tp->t_fields[offset].t_type; - return(offset+1); + return (offset + 1); } yyerror("No such field in this struct"); - return(0); + return (0); } extern char em_flag[]; -argtyp(mn) { +int argtyp(int mn) +{ - switch(em_flag[mn-sp_fmnem]&EM_PAR) { - case PAR_W: - case PAR_S: - case PAR_Z: - case PAR_O: - case PAR_N: - case PAR_L: - case PAR_F: - case PAR_R: - case PAR_C: - return(TYPINT); - default: - return(TYPSTR); + switch (em_flag[mn - sp_fmnem] & EM_PAR) + { + case PAR_W: + case PAR_S: + case PAR_Z: + case PAR_O: + case PAR_N: + case PAR_L: + case PAR_F: + case PAR_R: + case PAR_C: + return (TYPINT); + default: + return (TYPSTR); } } -commontype(e1,e2) expr_t e1,e2; { - - if(e1.expr_typ != e2.expr_typ) +int commontype(expr_t e1, expr_t e2) +{ + if (e1.expr_typ != e2.expr_typ) yyerror("Type incompatibility"); - return(e1.expr_typ); + return (e1.expr_typ); } extern char em_mnem[][4]; #define HASHSIZE (2*(sp_lmnem-sp_fmnem)) -struct hashmnem { +struct hashmnem +{ char h_name[3]; byte h_value; } hashmnem[HASHSIZE]; -inithash() { - register i; +void inithash(void) +{ + register int i; - for(i=0;i<=sp_lmnem-sp_fmnem;i++) - enter(em_mnem[i],i+sp_fmnem); + for (i = 0; i <= sp_lmnem - sp_fmnem; i++) + enter(em_mnem[i], i + sp_fmnem); } -enter(name,value) char *name; { +void enter(char *name, int value) +{ register unsigned h; - h=hash(name)%HASHSIZE; + h = hash(name) % HASHSIZE; while (hashmnem[h].h_name[0] != 0) - h = (h+1)%HASHSIZE; - strncpy(hashmnem[h].h_name,name,3); + h = (h + 1) % HASHSIZE; + strncpy(hashmnem[h].h_name, name, 3); hashmnem[h].h_value = value; } -int mlookup(name) char *name; { - register unsigned h; +int mlookup(char *name) +{ + register unsigned int h; - h = hash(name)%HASHSIZE; - while (strncmp(hashmnem[h].h_name,name,3) != 0 && - hashmnem[h].h_name[0] != 0) - h = (h+1)%HASHSIZE; - return(hashmnem[h].h_value&BMASK); /* 0 if not found */ + h = hash(name) % HASHSIZE; + while (strncmp(hashmnem[h].h_name, name, 3) != 0 + && hashmnem[h].h_name[0] != 0) + h = (h + 1) % HASHSIZE; + return (hashmnem[h].h_value & BMASK); /* 0 if not found */ } -hashpatterns() { +void hashpatterns(void) +{ short index; - register byte *bp,*tp; + register byte *bp, *tp; register short i; unsigned short hashvalue; int patlen; index = prevind; - while (index != 0) { + while (index != 0) + { bp = &pattern[index]; tp = &bp[PO_MATCH]; - i = *tp++&BMASK; - if (i==BMASK) { - i = *tp++&BMASK; - i |= (*tp++&BMASK)<>BSHIFT; + i = index; + index = (bp[PO_NEXT] & BMASK) | (bp[PO_NEXT + 1] << BSHIFT); + bp[PO_HASH] = hashvalue >> BSHIFT; hashvalue &= BMASK; - bp[PO_NEXT] = pathash[hashvalue]&BMASK; - bp[PO_NEXT+1] = pathash[hashvalue]>>BSHIFT; + bp[PO_NEXT] = pathash[hashvalue] & BMASK; + bp[PO_NEXT + 1] = pathash[hashvalue] >> BSHIFT; pathash[hashvalue] = i; } } -debug() { - register i,j; +static void debug(void) +{ + register int i, j; - for(i=0;ii_next) - printf("%-14s %1d %3d\n",ip->i_name, - ip->i_type,ip->i_i.i_regno); + for (ip = identtab[i]; ip != 0; ip = ip->i_next) + printf("%-14s %1d %3d\n", ip->i_name, ip->i_type, ip->i_i.i_regno); } - for(i=2;irname,rp->rrepr,rp->rsize); - for(j=0;jrmembers[j] != 0) - printf(", %s",machregs[rp->rmembers[j]]->rname); + rp = machregs[i]; + printf("%s = (\"%s\", %d", rp->rname, rp->rrepr, rp->rsize); + for (j = 0; j < MAXMEMBERS; j++) + if (rp->rmembers[j] != 0) + printf(", %s", machregs[rp->rmembers[j]]->rname); printf(")"); - for(j=0;jrprop[j>>4]&(1<<(j&017))) - printf(", %s",machprops[j].propname->i_name); + for (j = 0; j < nprops; j++) + if (rp->rprop[j >> 4] & (1 << (j & 017))) + printf(", %s", machprops[j].propname->i_name); printf(".\n"); } } -out(n) { +void out(int n) +{ - assert(n>=0); - if (n<128) + assert(n >= 0); + if (n < 128) outbyte(n); - else { - outbyte(n/256+128); - outbyte(n%256); + else + { + outbyte(n / 256 + 128); + outbyte(n % 256); } } -outbyte(n) { +void outbyte(int n) +{ - fprintf(cfile,"%d, ",n&BMASK); + fprintf(cfile, "%d, ", n & BMASK); codebytes++; } -pat(n) { +void pat(int n) +{ - assert(n>=0); - if (n<128) + assert(n >= 0); + if (n < 128) patbyte(n); - else { - patbyte(n/256+128); - patbyte(n%256); + else + { + patbyte(n / 256 + 128); + patbyte(n % 256); } } -patshort(n) { +void patshort(int n) +{ - patbyte(n&BMASK); - patbyte(n>>BSHIFT); + patbyte(n & BMASK); + patbyte(n >> BSHIFT); } -patbyte(n) { - - chktabsiz(npatbytes,MAXPATTERN,"Pattern table"); +void patbyte(int n) +{ + chktabsiz(npatbytes, MAXPATTERN, "Pattern table"); pattern[npatbytes++] = n; } -max(a,b) { - - if (a>b) - return(a); - return(b); +int max(int a, int b) +{ + if (a > b) + return (a); + return (b); } -int yywrap(void) { +int yywrap(void) +{ return 1; } From fa2859df797152b9d8ab383b94460c5c7e9e8a13 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:14:01 +0800 Subject: [PATCH 62/84] ANSI C conversion. --- util/cmisc/GCIPM.c | 56 +++++++++++--------- util/cmisc/cclash.c | 58 ++++++++++---------- util/cmisc/cid.c | 55 ++++++++++--------- util/cmisc/mkdep.c | 125 ++++++++++++++++++++++++-------------------- 4 files changed, 157 insertions(+), 137 deletions(-) diff --git a/util/cmisc/GCIPM.c b/util/cmisc/GCIPM.c index 3d579e79a..78b3a9d7e 100644 --- a/util/cmisc/GCIPM.c +++ b/util/cmisc/GCIPM.c @@ -10,17 +10,30 @@ #include -extern CheckId(); -extern DoOption(); -extern BeginOfProgram(), EndOfProgram(); +extern void BeginOfProgram(void); +extern void EndOfProgram(void); +extern void DoOption(char*); +extern void CheckId(char *, int); + #define MAX_ID_LEN 256 char *ProgName; int GCcopy; -main(argc, argv) - char *argv[]; + +void DoFile(FILE *); +void SkipString(FILE *, int); +void SkipComment(FILE *); +void DoIdent(FILE *, int); +int StartId(int); +int InId(int); +int StartNum(int); +void DoNum(register FILE *, int); + + + +int main(int argc, char *argv[]) { char **nargv; int nargc = 0; @@ -55,13 +68,12 @@ main(argc, argv) DoFile(stdin); } EndOfProgram(); - exit(0); + return 0; } -DoFile(fp) - FILE *fp; +void DoFile(FILE *fp) { - register c; + register int c; while ((c = getc(fp)) != EOF) { switch (c) { @@ -98,10 +110,9 @@ DoFile(fp) fclose(fp); } -SkipString(fp, stopc) - FILE *fp; +void SkipString(FILE *fp, int stopc) { - register c; + register int c; while ((c = getc(fp)) != EOF) { if (GCcopy) putchar(c); @@ -116,10 +127,9 @@ SkipString(fp, stopc) } } -SkipComment(fp) - FILE *fp; +void SkipComment(FILE *fp) { - register c; + register int c; while ((c = getc(fp)) != EOF) { if (GCcopy) putchar(c); @@ -133,12 +143,11 @@ SkipComment(fp) } } -DoIdent(fp, s) - FILE *fp; +void DoIdent(FILE *fp, int s) { char id_buf[MAX_ID_LEN]; - register cnt = 1; - register c; + register int cnt = 1; + register int c; id_buf[0] = s; @@ -155,7 +164,7 @@ DoIdent(fp, s) } } -StartId(c) +int StartId(int c) { switch (c) { @@ -179,7 +188,7 @@ StartId(c) } } -InId(c) +int InId(int c) { switch (c) { @@ -205,7 +214,7 @@ InId(c) } } -StartNum(c) +int StartNum(int c) { switch(c) { case '0': case '1': case '2': case '3': case '4': @@ -223,8 +232,7 @@ StartNum(c) #define getoct(c, fp) do { c = getc((fp)); if (GCcopy) putchar(c);} while (isoct(c)) #define gethex(c, fp) do { c = getc((fp)); if (GCcopy) putchar(c);} while (ishex(c)) -DoNum(fp, c) - register FILE *fp; +void DoNum(register FILE *fp, int c) { if (c != '0') { getdec(c, fp); diff --git a/util/cmisc/cclash.c b/util/cmisc/cclash.c index 1bc8c68b3..9221c1df9 100644 --- a/util/cmisc/cclash.c +++ b/util/cmisc/cclash.c @@ -30,6 +30,7 @@ */ #include +#include #include #define DEF_LENGTH 8 @@ -84,20 +85,32 @@ char * keywords[] = { 0 }; + +void InsertId(char *,int); +char *Malloc(unsigned int); +char *Salloc(char *); +int EnHash(char*); +void EndOfProgram(void); +void DoOption(char*); +void CheckId(char *, int); +void saveline(register struct idf *); +void mapline(char *); + + + struct idf *maplist = 0; -DefineKeys() +void DefineKeys(void) { register char **pkey = &keywords[0]; register char *id; - while (id = *pkey++) + while ((id = *pkey++)) if (strlen(id) >= maxlen) InsertId(id, 1); } -DoOption(str) - char *str; +void DoOption(char *str) { switch (str[1]) { @@ -129,8 +142,7 @@ struct idf *hash_tab[HASHSIZE]; char *Malloc(), *Salloc(); -InsertId(id, key) - char *id; +void InsertId(char *id, int key) { int hash_val = EnHash(id); register struct idf *idp = hash_tab[hash_val]; @@ -168,11 +180,9 @@ InsertId(id, key) p->id_key = key; } -char * -Malloc(n) - unsigned n; +char *Malloc(unsigned n) { - char *mem, *malloc(); + char *mem; if ((mem = malloc(n)) == 0) { fprintf(stderr, "%s: out of memory\n", ProgName); @@ -181,9 +191,7 @@ Malloc(n) return mem; } -char * -Salloc(str) - char *str; +char *Salloc(char *str) { if (str == 0) str = ""; @@ -191,11 +199,10 @@ Salloc(str) return strcpy(Malloc((unsigned)strlen(str) + 1), str); } -EnHash(id) - char *id; +int EnHash(char *id) { register unsigned hash_val = 0; - register n = maxlen; + register int n = maxlen; while (n-- && *id) hash_val = 31 * hash_val + *id++; @@ -203,9 +210,9 @@ EnHash(id) return hash_val % (unsigned) HASHSIZE; } -BeginOfProgram() { DefineKeys(); } +void BeginOfProgram(void) { DefineKeys(); } -EndOfProgram() +void EndOfProgram(void) { register int i; register struct idf *idp, *p; @@ -216,12 +223,12 @@ EndOfProgram() continue; switch (action) { - register n; + register int n; case ACT_LISTONLY: n = 0; if (idp->id_key == 0) { - printf(idp->id_name); + printf("%s",idp->id_name); n++; } for (p = idp->id_same; p; p = p->id_same) @@ -260,8 +267,7 @@ EndOfProgram() } } -saveline(p) - register struct idf *p; +void saveline(register struct idf *p) { register struct idf *idp = maplist, *idp1 = 0; @@ -278,10 +284,9 @@ saveline(p) } } -mapline(nm) - char *nm; +void mapline(char *nm) { - static map_count = 0; + static int map_count = 0; switch (action) { @@ -295,8 +300,7 @@ mapline(nm) } } -CheckId(id, s) - char *id; +void CheckId(char *id, int s) { if (s >= maxlen) InsertId(id, 0); diff --git a/util/cmisc/cid.c b/util/cmisc/cid.c index b09136e33..96e20df09 100644 --- a/util/cmisc/cid.c +++ b/util/cmisc/cid.c @@ -15,6 +15,7 @@ #include #include +#include #ifndef DEF_LENGTH #define DEF_LENGTH 8 @@ -32,13 +33,22 @@ struct idf { struct idf *hash_tab[HASHSIZE]; -char *Malloc(), *Salloc(); -struct idf *FindId(); +char *Malloc(unsigned int); +char *Salloc(char *); +int EnHash(char*); +void EndOfProgram(void); +void DoOption(char*); +void CheckId(char *, int); +void DoMacro(char *); +void GetMacros(char *); +void InsertMacro(char *, char *); +struct idf *FindId(char *); + + extern char *ProgName; -DoOption(str) - char *str; +void DoOption(char* str) { switch (str[1]) { @@ -57,8 +67,7 @@ DoOption(str) } /*ARGSUSED*/ -CheckId(id, len) - char *id; +void CheckId(char *id, int len) { struct idf *idp = FindId(id); @@ -70,8 +79,7 @@ CheckId(id, len) } } -DoMacro(str) - char *str; +void DoMacro(char *str) { char *id, *text; @@ -92,11 +100,10 @@ DoMacro(str) InsertMacro(id, text); } -GetMacros(fn) - char *fn; +void GetMacros(char *fn) { FILE *fp; - register c; + register int c; char buf[LINE_LEN]; char *bufp = &buf[0]; @@ -118,8 +125,7 @@ GetMacros(fn) fclose(fp); } -InsertMacro(id, text) - char *id, *text; +void InsertMacro(char *id, char *text) { int hash_val = EnHash(id); struct idf *idp = hash_tab[hash_val]; @@ -143,11 +149,9 @@ InsertMacro(id, text) hash_tab[hash_val] = idp; } -char * -Malloc(n) - unsigned n; +char *Malloc(unsigned int n) { - char *mem, *malloc(); + char *mem; if ((mem = malloc(n)) == 0) { fprintf(stderr, "%s: out of memory\n", ProgName); @@ -156,9 +160,7 @@ Malloc(n) return mem; } -char * -Salloc(str) - char *str; +char *Salloc(char *str) { if (str == 0) { str = ""; @@ -166,11 +168,9 @@ Salloc(str) return strcpy(Malloc((unsigned)strlen(str) + 1), str); } -struct idf * -FindId(id) - char *id; +struct idf *FindId(char *id) { - register hash_val = EnHash(id); + register int hash_val = EnHash(id); register struct idf *idp = hash_tab[hash_val]; while (idp) { @@ -182,8 +182,7 @@ FindId(id) return 0; } -EnHash(id) - char *id; +int EnHash(char *id) { register unsigned hash_val = 0; @@ -196,11 +195,11 @@ EnHash(id) extern int GCcopy; -BeginOfProgram() +void BeginOfProgram(void) { GCcopy = 1; } -EndOfProgram() +void EndOfProgram(void) { } diff --git a/util/cmisc/mkdep.c b/util/cmisc/mkdep.c index 065678929..1e2749c07 100644 --- a/util/cmisc/mkdep.c +++ b/util/cmisc/mkdep.c @@ -5,19 +5,21 @@ */ /* make dependencies; Date: jan 07, 1986; Author: Erik Baalbergen */ /* Log: - [Thu Oct 6 09:56:30 MET 1988; erikb] - Added option '-d' which suppresses "file.c :" be printed + [Thu Oct 6 09:56:30 MET 1988; erikb] + Added option '-d' which suppresses "file.c :" be printed */ #include -#incoude +#include +#include #define BSIZ 1024 char *prog; -int dflag = 0; /* suppress "file.c :" */ +int dflag = 0; /* suppress "file.c :" */ -struct namelist { +struct namelist +{ struct namelist *next; char *name; }; @@ -26,13 +28,19 @@ struct namelist *freelist; struct namelist *new_namelist(); struct namelist *nl = 0; +char *Malloc(unsigned int); + +char *include_line(char *); +int dofile(char *); + char *Malloc(u) unsigned u; { - char *sp, *malloc(); + char *sp; - if ((sp = malloc(u)) == 0) { - fprintf(stderr, "%s: out of space\n"); + if ((sp = malloc(u)) == 0) + { + fprintf(stderr, "%s:", " out of space\n"); exit(1); } return sp; @@ -43,7 +51,8 @@ new_namelist() { register struct namelist *nlp = freelist; - if (nlp) { + if (nlp) + { freelist = nlp->next; return nlp; } @@ -51,48 +60,50 @@ new_namelist() return (struct namelist *) Malloc(sizeof(struct namelist)); } -free_namelist(nlp) - struct namelist *nlp; +void free_namelist(struct namelist *nlp) { - if (nlp) { + if (nlp) + { free_namelist(nlp->next); nlp->next = freelist; freelist = nlp; } } -add_name(nm) - char *nm; +void add_name(char *nm) { struct namelist *nlp = nl, *lnlp = 0, *nnlp; - while (nlp) { - register i = strcmp(nm, nlp->name); + while (nlp) + { + register int i = strcmp(nm, nlp->name); if (i < 0) break; - if (i == 0) /* already present */ + if (i == 0) /* already present */ return; lnlp = nlp; nlp = nlp->next; } - (nnlp = new_namelist())->name = strcpy(Malloc((unsigned)strlen(nm) + 1), nm); + (nnlp = new_namelist())->name = strcpy(Malloc((unsigned) strlen(nm) + 1), + nm); - if (lnlp) { + if (lnlp) + { nnlp->next = lnlp->next; lnlp->next = nnlp; } - else { + else + { nnlp->next = nl; nl = nnlp; } } -print_namelist(nm, nlp) - char *nm; - struct namelist *nlp; +void print_namelist(char *nm, struct namelist *nlp) { - while (nlp) { + while (nlp) + { if (!dflag) printf("%s: ", nm); printf("%s\n", nlp->name); @@ -101,23 +112,25 @@ print_namelist(nm, nlp) } /*ARGSUSED*/ -main(argc, argv) - char *argv[]; +int main(int argc, char *argv[]) { int err = 0; prog = *argv++; - if (*argv && **argv == '-') { + if (*argv && **argv == '-') + { char *opt = &(*argv++)[1]; - if (*opt++ != 'd' || *opt) { + if (*opt++ != 'd' || *opt) + { fprintf(stderr, "use: %s [-d] [file ...]\n", prog); exit(1); } dflag = 1; } - while (*argv) { + while (*argv) + { free_namelist(nl); nl = 0; if (dofile(*argv) == 0) @@ -127,67 +140,63 @@ main(argc, argv) exit(err ? 1 : 0); } -int -contains_slash(s) - register char *s; +int contains_slash(register char *s) { while (*s) - if (*s++ == '/') return 1; + if (*s++ == '/') + return 1; return 0; } -extern char *fgets(); - -dofile(fn) - char *fn; +int dofile(char *fn) { char buf[BSIZ]; FILE *fp; - char *nm, *include_line(); + char *nm; - if ((fp = fopen(fn, "r")) == 0) { + if ((fp = fopen(fn, "r")) == 0) + { fprintf(stderr, "%s: cannot read %s\n", prog, fn); return 0; } - if (contains_slash(fn)) { - fprintf(stderr, "%s: (warning) %s not in current directory; not checked\n", prog, fn); + if (contains_slash(fn)) + { + fprintf(stderr, + "%s: (warning) %s not in current directory; not checked\n", + prog, fn); fclose(fp); return 1; } while (fgets(buf, BSIZ, fp) != NULL) - if (nm = include_line(buf)) { + if ((nm = include_line(buf))) + { add_name(nm); - if (dofile(nm)) ; + if (dofile(nm)) + ; } fclose(fp); return 1; } -char * -include_line(s) - char *s; +char *include_line(char *s) { while ((*s == '\t') || (*s == ' ')) s++; - - if (*s++ == '#') { + + if (*s++ == '#') + { while ((*s == '\t') || (*s == ' ')) s++; - if ( - (*s++ == 'i') && - (*s++ == 'n') && - (*s++ == 'c') && - (*s++ == 'l') && - (*s++ == 'u') && - (*s++ == 'd') && - (*s++ == 'e') - ) { + if ((*s++ == 'i') && (*s++ == 'n') && (*s++ == 'c') && (*s++ == 'l') + && (*s++ == 'u') && (*s++ == 'd') && (*s++ == 'e')) + { while ((*s == '\t') || (*s == ' ')) s++; - if (*s++ == '"') { + if (*s++ == '"') + { char *nm = s; while (*s != 0 && *s != '"') From 16f89747b10a3d8f48b98994e9e07701289ac564 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:14:54 +0800 Subject: [PATCH 63/84] ANSI C conversion. --- util/int/global.h | 5 +- util/int/switch/mkiswitch.c | 256 +++++++++++++++--------------- util/int/switch/mkswitch.c | 300 ++++++++++++++++++------------------ 3 files changed, 282 insertions(+), 279 deletions(-) diff --git a/util/int/global.h b/util/int/global.h index d90f09b7a..216835325 100644 --- a/util/int/global.h +++ b/util/int/global.h @@ -1,8 +1,8 @@ /* Defines and externs of general interest */ - -/* $Id$ */ +#ifndef GLOBAL_H_ +#define GLOBAL_H_ #include #include @@ -157,3 +157,4 @@ extern ptr SL; /* Stack Limit */ #define min(i,j) (((i) < (j)) ? (i) : (j)) +#endif /* GLOBAL_H_ */ diff --git a/util/int/switch/mkiswitch.c b/util/int/switch/mkiswitch.c index 8be3d54a9..b66122949 100644 --- a/util/int/switch/mkiswitch.c +++ b/util/int/switch/mkiswitch.c @@ -9,9 +9,11 @@ /* $Id$ */ +#include #include +#include + -extern FILE *popen(); #include #include @@ -26,7 +28,132 @@ FILE *ifp; /* Input File Pointer */ FILE *ofp; /* Output File Pointer */ char *Prefix; /* Prefix for function name */ -main(argc, argv) + +int +in(flgs, c) + char *flgs; + char c; +{ + while (*flgs) + if (c == *flgs++) + return 1; + return 0; +} + + + +void OutCase(mnem, base, first, i, argstr) + char *mnem; + char *base; + int first; + int i; + char *argstr; +{ + /* Output a case in the switch statement */ + fprintf(ofp, "\t\tcase %s+%d:\t%s%s(%s); break;\n", + base, first+i, Prefix, mnem, argstr); +} + + + + +void ImplicitArg(argstr) + char *argstr; +{ + sprintf(argstr, "uwpop()"); +} + +void NoArgs(argstr) + char *argstr; +{ + sprintf(argstr, ""); +} + +void Mini(argstr, i, flgs) + char *argstr; + int i; + char *flgs; +{ + int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i; + + switch (newi) { + case -1: + sprintf(argstr, "%s", + in(flgs, 'w') ? "-wsize" : "-1L"); + break; + case 0: + sprintf(argstr, "0L"); + break; + case 1: + sprintf(argstr, "%s", + in(flgs, 'w') ? "wsize" : "1L"); + break; + default: + sprintf(argstr, "%dL%s", + newi, in(flgs, 'w') ? "*wsize" : ""); + break; + } +} + +void Shortie(argstr, i, flgs) + char *argstr; + int i; + char *flgs; +{ + int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i; + + sprintf(argstr, "S_arg(%d)*%s", + newi, in(flgs, 'w') ? "wsize" : "1L"); +} + +void TwoSgn(argstr, flgs) + char *argstr; + char *flgs; +{ + + sprintf(argstr, "%s*%s", in(flgs, 'P') ? "P_arg_2()" : in(flgs, 'N') ? "N_arg_2()" : "L_arg_2()", + in(flgs, 'w') ? "wsize" : "1L"); +} + +void TwoUns(argstr, flgs) + char *argstr; + char *flgs; +{ + + sprintf(argstr, "%s*%s", "U_arg()", + in(flgs, 'w') ? "wsize" : "((unsigned long) 1)"); +} + +void FourSgn(argstr, flgs) + char *argstr; + char *flgs; +{ + + sprintf(argstr, "%s*%s", in(flgs, 'P') ? "P_arg_4()" : in(flgs, 'N') ? "N_arg_4()" : "L_arg_4()", + in(flgs, 'w') ? "wsize" : "1L"); +} + + +void fatal(fmt, str) + char *fmt; + char *str; +{ + fprintf(stderr, "%s, (fatal error): ", progname); + fprintf(stderr, fmt, str); + fprintf(stderr, "\n"); + exit(1); +} +int getmnem(str) char *str ; { + char (*ptr)[4] ; + + for ( ptr = em_mnem ; *ptr<= &em_mnem[sp_lmnem][0] ; ptr++ ) { + if ( strcmp(*ptr,str)==0 ) return (ptr-em_mnem) ; + } + fatal("%s","Illegal mnemonic") ; + return 0 ; +} + +int main(argc, argv) int argc; char **argv; { @@ -148,128 +275,5 @@ main(argc, argv) fatal("no opcode flag in ip_spec %s\n", flgs); } } - exit(0); + return EXIT_SUCCESS; } - - -OutCase(mnem, base, first, i, argstr) - char *mnem; - char *base; - int first; - int i; - char *argstr; -{ - /* Output a case in the switch statement */ - fprintf(ofp, "\t\tcase %s+%d:\t%s%s(%s); break;\n", - base, first+i, Prefix, mnem, argstr); -} - - - - -ImplicitArg(argstr) - char *argstr; -{ - sprintf(argstr, "uwpop()"); -} - -NoArgs(argstr) - char *argstr; -{ - sprintf(argstr, ""); -} - -Mini(argstr, i, flgs) - char *argstr; - int i; - char *flgs; -{ - int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i; - - switch (newi) { - case -1: - sprintf(argstr, "%s", - in(flgs, 'w') ? "-wsize" : "-1L"); - break; - case 0: - sprintf(argstr, "0L"); - break; - case 1: - sprintf(argstr, "%s", - in(flgs, 'w') ? "wsize" : "1L"); - break; - default: - sprintf(argstr, "%dL%s", - newi, in(flgs, 'w') ? "*wsize" : ""); - break; - } -} - -Shortie(argstr, i, flgs) - char *argstr; - int i; - char *flgs; -{ - int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i; - - sprintf(argstr, "S_arg(%d)*%s", - newi, in(flgs, 'w') ? "wsize" : "1L"); -} - -TwoSgn(argstr, flgs) - char *argstr; - char *flgs; -{ - - sprintf(argstr, "%s*%s", in(flgs, 'P') ? "P_arg_2()" : in(flgs, 'N') ? "N_arg_2()" : "L_arg_2()", - in(flgs, 'w') ? "wsize" : "1L"); -} - -TwoUns(argstr, flgs) - char *argstr; - char *flgs; -{ - - sprintf(argstr, "%s*%s", "U_arg()", - in(flgs, 'w') ? "wsize" : "((unsigned long) 1)"); -} - -FourSgn(argstr, flgs) - char *argstr; - char *flgs; -{ - - sprintf(argstr, "%s*%s", in(flgs, 'P') ? "P_arg_4()" : in(flgs, 'N') ? "N_arg_4()" : "L_arg_4()", - in(flgs, 'w') ? "wsize" : "1L"); -} - -int -in(flgs, c) - char *flgs; - char c; -{ - while (*flgs) - if (c == *flgs++) - return 1; - return 0; -} - -fatal(fmt, str) - char *fmt; - char *str; -{ - fprintf(stderr, "%s, (fatal error): ", progname); - fprintf(stderr, fmt, str); - fprintf(stderr, "\n"); - exit(1); -} -int getmnem(str) char *str ; { - char (*ptr)[4] ; - - for ( ptr = em_mnem ; *ptr<= &em_mnem[sp_lmnem][0] ; ptr++ ) { - if ( strcmp(*ptr,str)==0 ) return (ptr-em_mnem) ; - } - fatal("Illegal mnemonic") ; - return 0 ; -} - diff --git a/util/int/switch/mkswitch.c b/util/int/switch/mkswitch.c index 2ada08a3c..b90e0133b 100644 --- a/util/int/switch/mkswitch.c +++ b/util/int/switch/mkswitch.c @@ -11,6 +11,7 @@ /* $Id$ */ +#include #include extern FILE *popen(); @@ -22,7 +23,154 @@ FILE *ofp; /* Output File Pointer */ FILE *ffp = 0; /* Function File Pointer */ char *Prefix; /* Prefix for function name */ -main(argc, argv) +int in(char *flgs, char c) +{ + while (*flgs) + if (c == *flgs++) + return 1; + return 0; +} + + +void NoArgs(base, first, mnem) + char *base; + int first; + char *mnem; +{ + fprintf(ofp, "\t\tcase %s+%d:\t%s%sz(); break;\n", + base, first, Prefix, mnem); + if (ffp) { + fprintf(ffp, "%s%sz() {", Prefix, mnem); + fprintf(ffp, "LOG((\"@ %s%sz()\"));}\n", Prefix, mnem); + } +} + +void Mini(i, flgs, base, first, mnem) + int i; + char *flgs; + char *base; + int first; + char *mnem; +{ + char arg[16]; + int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i; + + switch (newi) { + case -1: + sprintf(arg, "%s", + in(flgs, 'w') ? "-wsize" : "-1L"); + break; + case 0: + sprintf(arg, "0L"); + break; + case 1: + sprintf(arg, "%s", + in(flgs, 'w') ? "wsize" : "1L"); + break; + default: + sprintf(arg, "%dL%s", + newi, in(flgs, 'w') ? "*wsize" : ""); + break; + } + fprintf(ofp, "\t\tcase %s+%d:\t%s%sm(%s); break;\n", + base, first+i, Prefix, mnem, arg); + if (ffp) { + fprintf(ffp, "%s%sm(arg) long arg; {", + Prefix, mnem); + fprintf(ffp, "LOG((\"@ %s%sm(%%d)\", arg));}\n", + Prefix, mnem); + } +} + +void Shortie(i, flgs, base, first, mnem) + int i; + char *flgs; + char *base; + int first; + char *mnem; +{ + char arg[16]; + int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i; + + sprintf(arg, "%dL, %s", newi, (in(flgs, 'w') ? "wsize" : "1L")); + fprintf(ofp, "\t\tcase %s+%d:\t%s%ss(%s); break;\n", + base, first+i, Prefix, mnem, arg); + if (ffp) { + fprintf(ffp, "%s%ss(hob, wfac) long hob; size wfac; {", + Prefix, mnem); + fprintf(ffp, "LOG((\"@ %s%ss(%%d)\", hob, wfac));", + Prefix, mnem); + fprintf(ffp, " newPC(PC+1);}\n"); + } +} + +void TwoSgn(flgs, base, first, mnem) + char *flgs; + char *base; + int first; + char *mnem; +{ + char *xy = in(flgs, 'P') ? "p2" : in(flgs, 'N') ? "n2" : "l2"; + + fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n", + base, first, Prefix, mnem, xy, + in(flgs, 'w') ? "wsize" : "1L"); + if (ffp) { + fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy); + fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));", + Prefix, mnem, xy); + fprintf(ffp, " newPC(PC+2);}\n"); + } +} + +void TwoUns(flgs, base, first, mnem) + char *flgs; + char *base; + int first; + char *mnem; +{ + char *xy = "u"; + + fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n", + base, first, Prefix, mnem, xy, + in(flgs, 'w') ? "wsize" : "1L"); + if (ffp) { + fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy); + fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));", + Prefix, mnem, xy); + fprintf(ffp, " newPC(PC+2);}\n"); + } +} + +void FourSgn(flgs, base, first, mnem) + char *flgs; + char *base; + int first; + char *mnem; +{ + char *xy = in(flgs, 'P') ? "p4" : in(flgs, 'N') ? "n4" : "l4"; + + fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n", + base, first, Prefix, mnem, xy, + in(flgs, 'w') ? "wsize" : "1L"); + if (ffp) { + fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy); + fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));", + Prefix, mnem, xy); + fprintf(ffp, " newPC(PC+4);}\n"); + } +} + + +void fatal(char *fmt, char *str) +{ + fprintf(stderr, "%s, (fatal error): ", progname); + fprintf(stderr, fmt, str); + fprintf(stderr, "\n"); + exit(1); +} + +int main(argc, argv) int argc; char **argv; { @@ -136,153 +284,3 @@ main(argc, argv) } exit(0); } - -NoArgs(base, first, mnem) - char *base; - int first; - char *mnem; -{ - fprintf(ofp, "\t\tcase %s+%d:\t%s%sz(); break;\n", - base, first, Prefix, mnem); - if (ffp) { - fprintf(ffp, "%s%sz() {", Prefix, mnem); - fprintf(ffp, "LOG((\"@ %s%sz()\"));}\n", Prefix, mnem); - } -} - -Mini(i, flgs, base, first, mnem) - int i; - char *flgs; - char *base; - int first; - char *mnem; -{ - char arg[16]; - int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i; - - switch (newi) { - case -1: - sprintf(arg, "%s", - in(flgs, 'w') ? "-wsize" : "-1L"); - break; - case 0: - sprintf(arg, "0L"); - break; - case 1: - sprintf(arg, "%s", - in(flgs, 'w') ? "wsize" : "1L"); - break; - default: - sprintf(arg, "%dL%s", - newi, in(flgs, 'w') ? "*wsize" : ""); - break; - } - fprintf(ofp, "\t\tcase %s+%d:\t%s%sm(%s); break;\n", - base, first+i, Prefix, mnem, arg); - if (ffp) { - fprintf(ffp, "%s%sm(arg) long arg; {", - Prefix, mnem); - fprintf(ffp, "LOG((\"@ %s%sm(%%d)\", arg));}\n", - Prefix, mnem); - } -} - -Shortie(i, flgs, base, first, mnem) - int i; - char *flgs; - char *base; - int first; - char *mnem; -{ - char arg[16]; - int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i; - - sprintf(arg, "%dL, %s", newi, (in(flgs, 'w') ? "wsize" : "1L")); - fprintf(ofp, "\t\tcase %s+%d:\t%s%ss(%s); break;\n", - base, first+i, Prefix, mnem, arg); - if (ffp) { - fprintf(ffp, "%s%ss(hob, wfac) long hob; size wfac; {", - Prefix, mnem); - fprintf(ffp, "LOG((\"@ %s%ss(%%d)\", hob, wfac));", - Prefix, mnem); - fprintf(ffp, " newPC(PC+1);}\n"); - } -} - -TwoSgn(flgs, base, first, mnem) - char *flgs; - char *base; - int first; - char *mnem; -{ - char *xy = in(flgs, 'P') ? "p2" : in(flgs, 'N') ? "n2" : "l2"; - - fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n", - base, first, Prefix, mnem, xy, - in(flgs, 'w') ? "wsize" : "1L"); - if (ffp) { - fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy); - fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));", - Prefix, mnem, xy); - fprintf(ffp, " newPC(PC+2);}\n"); - } -} - -TwoUns(flgs, base, first, mnem) - char *flgs; - char *base; - int first; - char *mnem; -{ - char *xy = "u"; - - fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n", - base, first, Prefix, mnem, xy, - in(flgs, 'w') ? "wsize" : "1L"); - if (ffp) { - fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy); - fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));", - Prefix, mnem, xy); - fprintf(ffp, " newPC(PC+2);}\n"); - } -} - -FourSgn(flgs, base, first, mnem) - char *flgs; - char *base; - int first; - char *mnem; -{ - char *xy = in(flgs, 'P') ? "p4" : in(flgs, 'N') ? "n4" : "l4"; - - fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n", - base, first, Prefix, mnem, xy, - in(flgs, 'w') ? "wsize" : "1L"); - if (ffp) { - fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy); - fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));", - Prefix, mnem, xy); - fprintf(ffp, " newPC(PC+4);}\n"); - } -} - -int -in(flgs, c) - char *flgs; - char c; -{ - while (*flgs) - if (c == *flgs++) - return 1; - return 0; -} - -fatal(fmt, str) - char *fmt; - char *str; -{ - fprintf(stderr, "%s, (fatal error): ", progname); - fprintf(stderr, fmt, str); - fprintf(stderr, "\n"); - exit(1); -} From 970e7da89632bdd6e8b75693cc9ad92f1b44000e Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:15:18 +0800 Subject: [PATCH 64/84] Adapt to new object API --- util/led/archive.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/led/archive.c b/util/led/archive.c index 6e21e01cf..b9d53d66b 100644 --- a/util/led/archive.c +++ b/util/led/archive.c @@ -45,10 +45,10 @@ static long getsymdeftable(void) register struct ranlib *ran; register long count; register long nran, nchar; - extern long rd_long(); + extern long rd_int4(); extern FILE* infile; - count = nran = rd_long(infile); + count = nran = rd_int4(infile); debug("%ld ranlib structs, ", nran, 0, 0, 0); if (nran > SIZE_MAX / sizeof(struct ranlib)) off = BADOFF; /* nran * size would overflow. */ @@ -58,7 +58,7 @@ static long getsymdeftable(void) fatal("no space for ranlib structs"); ran = (struct ranlib *)address(ALLORANL, off); rd_ranlib(infile, ran, count); - nchar = rd_long(infile); + nchar = rd_int4(infile); debug("%ld ranlib chars\n", nchar, 0, 0, 0); if (nchar != (size_t)nchar || (off = hard_alloc(ALLORANL, nchar)) == BADOFF) From 03018274824797b7a66a9b946d9fc35938908860 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:15:51 +0800 Subject: [PATCH 65/84] ANSI C conversion. --- util/misc/convert.c | 74 ++++++++++++++++-------------- util/misc/em_decode.6 | 10 ++-- util/misc/esize.c | 103 +++++++++++++++++++++++------------------- 3 files changed, 101 insertions(+), 86 deletions(-) diff --git a/util/misc/convert.c b/util/misc/convert.c index 9bdc12011..6b8c885a0 100644 --- a/util/misc/convert.c +++ b/util/misc/convert.c @@ -7,18 +7,17 @@ static char rcsid[] = "$Id$"; #endif /* This program converts either human-readable or compact EM - assembly code to calls of the procedure-interface. - It must be linked with two libraries: - - a library to read EM code, according to read_em(3) - - a library implementing the em_code(3) interface. - Thus, this program could serve as an EM_encoder, an - EM_decoder, or some code generator, depending on how it is - linked. -*/ + assembly code to calls of the procedure-interface. + It must be linked with two libraries: + - a library to read EM code, according to read_em(3) + - a library implementing the em_code(3) interface. + Thus, this program could serve as an EM_encoder, an + EM_decoder, or some code generator, depending on how it is + linked. + */ #include #include -#include "system.h" #include "print.h" #include "em_pseu.h" #include "em_mnem.h" @@ -28,62 +27,69 @@ static char rcsid[] = "$Id$"; #include "em.h" #include "em_comp.h" -char *filename; /* Name of input file */ -int errors; /* Number of errors */ +char *filename; /* Name of input file */ +int errors; /* Number of errors */ extern char *C_error; +extern int C_out(register struct e_instr *); void error(const char *, ...); void fatal(const char *, ...); -int -main(int argc, char **argv) +int main(int argc, char **argv) { struct e_instr buf; register struct e_instr *p = &buf; - if (argc >= 2) { + if (argc >= 2) + { filename = argv[1]; } - else filename = 0; - if (!EM_open(filename)) { + else + filename = 0; + if (!EM_open(filename)) + { fatal(EM_error); } EM_getinstr(p); C_init((arith) EM_wordsize, (arith) EM_pointersize); - if (argc >= 3) { - if (!C_open(argv[2])) { + if (argc >= 3) + { + if (!C_open(argv[2])) + { fatal("C_open failed"); } } - else if (!C_open( (char *) 0)) fatal("C_open failed"); + else if (!C_open((char *) 0)) + fatal("C_open failed"); C_magic(); - while (p->em_type != EM_EOF) { - if (p->em_type == EM_FATAL) { + while (p->em_type != EM_EOF) + { + if (p->em_type == EM_FATAL) + { fatal("%s", EM_error); } - if (EM_error) { + if (EM_error) + { error("%s", EM_error); } - if (p->em_type != EM_ERROR && !C_out(p)) { + if (p->em_type != EM_ERROR && !C_out(p)) + { error("%s", C_error); } EM_getinstr(p); } C_close(); EM_close(); - exit(errors ? 1 : 0); + exit(errors ? EXIT_FAILURE : EXIT_SUCCESS); } /* VARARGS */ -void -error(const char *s, ...) +void error(const char *s, ...) { va_list ap; va_start(ap, s); - fprint(STDERR, - "%s, line %d: ", - filename ? filename : "standard input", - EM_lineno); + fprint(STDERR, "%s, line %d: ", filename ? filename : "standard input", + EM_lineno); doprnt(STDERR, s, ap); fprint(STDERR, "\n"); errors++; @@ -91,12 +97,12 @@ error(const char *s, ...) } /* VARARGS */ -void -fatal(const char *s, ...) +void fatal(const char *s, ...) { va_list ap; va_start(ap, s); - if (C_busy()) C_close(); + if (C_busy()) + C_close(); error(s, ap); - exit(1); + exit(EXIT_FAILURE); } diff --git a/util/misc/em_decode.6 b/util/misc/em_decode.6 index a21c939eb..acc72af46 100644 --- a/util/misc/em_decode.6 +++ b/util/misc/em_decode.6 @@ -3,10 +3,10 @@ .SH NAME em_decode, em_encode \- compact to readable EM and v.v. .SH SYNOPSIS -.B ~em/lib.bin/em_decode +.B em_decode [ inputfile [ outputfile ] ] .br -.B ~em/lib.bin/em_encode +.B em_encode [ inputfile [ outputfile ] ] .SH DESCRIPTION Most programs involved with the EM project only produce and accept @@ -15,12 +15,12 @@ These files are only machine readable. A description of this compact form can be found in [1]. To inspect the code produced by compilers or to patch them for one reason or another, human readable assembly code is needed. -Em_decode produces human readable assembly code from the compact form. +em_decode produces human readable assembly code from the compact form. .PP -Em_decode accepts the normal compact form in both optimized and +em_decode accepts the normal compact form in both optimized and unoptimized form. .PP -Em_encode produces the compact form +em_encode produces the compact form out of these human readable assembly code. .PP The first argument is the input file. diff --git a/util/misc/esize.c b/util/misc/esize.c index e9c58b20a..af81ad0ce 100644 --- a/util/misc/esize.c +++ b/util/misc/esize.c @@ -1,5 +1,5 @@ /* esize: prints info from e.out header -*/ + */ #include #include @@ -12,9 +12,9 @@ FILE *load_fp; int eof; /* Much of the code has been borrowed from the EM interpreter -*/ + */ -typedef /* unsigned */ long ptr; /* pointer to EM adress */ +typedef /* unsigned */long ptr; /* pointer to EM adress */ long magic; long flags; @@ -33,51 +33,65 @@ long szdata; long ptr7; long ptr8; -main(argc, argv) - int argc; - char *argv[]; +/* Forward declarations. */ +static void esize(char *); +static int rd_open(char*); +static int rd_byte(void); +static long rd_int(long n); +static int rd_header(void); +static void rd_close(void); +#define rd_ptr() ((ptr) rd_int(psize)) + + +int main(int argc, char *argv[]) { printf("TPFCRE uref vers w/p text nproc szdata\n"); - - if (argc == 1) { + + if (argc == 1) + { esize("e.out"); } - else { - while (argc > 1) { + else + { + while (argc > 1) + { esize(argv[1]); argc--, argv++; } } - exit(0); + exit(EXIT_SUCCESS); } -esize(fname) - char *fname; +static void esize(char *fname) { eof = 0; - if (!rd_open(fname)) { + if (!rd_open(fname)) + { printf("%s: cannot open\n", fname); } - else { - if (!rd_header()) { + else + { + if (!rd_header()) + { printf("%s: not EM object format\n", fname); } - else { - printf("%c", flags&0001 ? 'T' : '-'); - printf("%c", flags&0002 ? 'P' : '-'); - printf("%c", flags&0004 ? 'F' : '-'); - printf("%c", flags&0010 ? 'C' : '-'); - printf("%c", flags&0020 ? 'R' : '-'); - printf("%c", flags&0040 ? 'E' : '-'); - printf("%c", flags&0100 ? '?' : ' '); - printf("%c", flags&0200 ? '?' : ' '); - + else + { + printf("%c", flags & 0001 ? 'T' : '-'); + printf("%c", flags & 0002 ? 'P' : '-'); + printf("%c", flags & 0004 ? 'F' : '-'); + printf("%c", flags & 0010 ? 'C' : '-'); + printf("%c", flags & 0020 ? 'R' : '-'); + printf("%c", flags & 0040 ? 'E' : '-'); + printf("%c", flags & 0100 ? '?' : ' '); + printf("%c", flags & 0200 ? '?' : ' '); + printf("%3ld ", uref); printf("%3ld ", version); printf("%1ld/%1ld", wsize, psize); printf("%c", int7 ? '?' : ' '); printf("%c", int8 ? '?' : ' '); - + printf("%5ld ", ntext); printf("%5ld ", nproc); printf("%6ld", szdata); @@ -91,15 +105,12 @@ esize(fname) #define btol(a) ((long)(((long) (a)) & 0xFF)) -int -rd_open(load_file) - char *load_file; +static int rd_open(char* load_file) { - return (load_fp = fopen(load_file, "r")) != NULL; + return (load_fp = fopen(load_file, "rb")) != NULL; } -int -rd_byte() +static int rd_byte(void) { int i; @@ -108,35 +119,33 @@ rd_byte() return (i); } -long -rd_int(n) - long n; +static long rd_int(long n) { long l; register int i; l = btol(rd_byte()); for (i = 1; i < n; i++) - l = l | (btol(rd_byte()) << (long) (i*8)); + l = l | (btol(rd_byte()) << (long) (i * 8)); return (l); } -#define rd_ptr() ((ptr) rd_int(psize)) -int -rd_header() + +/* read e.out header information */ +static int rd_header(void) { magic = rd_int(2L); if (magic != MAGIC || eof) return 0; - + flags = rd_int(2L); uref = rd_int(2L); version = rd_int(2L); wsize = rd_int(2L); psize = rd_int(2L); - int7 = rd_int(2L); /* Entry 7 is unused */ - int8 = rd_int(2L); /* Entry 8 is unused */ + int7 = rd_int(2L); /* Entry 7 is unused */ + int8 = rd_int(2L); /* Entry 8 is unused */ ntext = rd_ptr(); ndata = rd_ptr(); @@ -144,13 +153,13 @@ rd_header() entrypoint = rd_ptr(); nline = rd_ptr(); szdata = rd_ptr(); - ptr7 = rd_ptr(); /* entry 7 is unused */ - ptr8 = rd_ptr(); /* entry 8 is unused */ - + ptr7 = rd_ptr(); /* entry 7 is unused */ + ptr8 = rd_ptr(); /* entry 8 is unused */ + return !eof; } -rd_close() +static void rd_close(void) { fclose(load_fp); } From 472654c36656afc69a33032cde71a1037b760568 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:17:24 +0800 Subject: [PATCH 66/84] ANSI C conversion and add procedure declarations. --- util/ncgg/cgg.y | 11 + util/ncgg/coerc.c | 248 +++++---- util/ncgg/coerc.h | 30 ++ util/ncgg/emlookup.c | 84 +-- util/ncgg/error.c | 11 +- util/ncgg/expr.c | 391 ++++++++------ util/ncgg/expr.h | 23 + util/ncgg/extern.h | 7 +- util/ncgg/hall.c | 149 +++--- util/ncgg/hall.h | 17 + util/ncgg/instruct.c | 260 ++++----- util/ncgg/instruct.h | 7 + util/ncgg/iocc.c | 219 ++++---- util/ncgg/iocc.h | 6 + util/ncgg/lookup.c | 91 ++-- util/ncgg/lookup.h | 7 +- util/ncgg/main.c | 71 ++- util/ncgg/output.c | 1168 +++++++++++++++++++++++------------------ util/ncgg/scan.l | 10 +- util/ncgg/set.c | 198 +++---- util/ncgg/set.h | 14 + util/ncgg/strlookup.c | 21 +- util/ncgg/subr.c | 468 +++++++++-------- util/ncgg/subr.h | 42 ++ 24 files changed, 2035 insertions(+), 1518 deletions(-) create mode 100644 util/ncgg/coerc.h create mode 100644 util/ncgg/hall.h create mode 100644 util/ncgg/subr.h diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index c77f566d7..c648d276c 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -14,6 +14,9 @@ static char rcsid[]= "$Id$"; #include "iocc.h" #include "instruct.h" #include "expr.h" +#include "coerc.h" +#include "hall.h" +#include "subr.h" #include "extern.h" #include #include @@ -49,6 +52,14 @@ iocc_t subr_iocc(),tokm_iocc(),ident_iocc(),all_iocc(),percident_iocc(), descr_i extern int narexpr; extern expr_t arexp[]; +extern void skipupto(int tok,char *str); +extern void outpatterns(void); +extern void dopattern(int stackcoerc, varinfo *kills, varinfo *allocates, + varinfo *generates, varinfo *yields, varinfo *leaving); +extern int yylex(void); +extern int argtyp(int mn); +extern void yyerror (char const *s); + int niops; iocc_t iops[20]; %} diff --git a/util/ncgg/coerc.c b/util/ncgg/coerc.c index 85148cd43..23b711b22 100644 --- a/util/ncgg/coerc.c +++ b/util/ncgg/coerc.c @@ -3,7 +3,7 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ #ifndef NORCSID -static char rcsid[]= "$Id$"; +static char rcsid[] = "$Id$"; #endif #include @@ -14,6 +14,9 @@ static char rcsid[]= "$Id$"; #include "token.h" #include "varinfo.h" #include "iocc.h" +#include "subr.h" +#include "hall.h" +#include "coerc.h" #include #include "pseudo.h" #include "extern.h" @@ -22,165 +25,181 @@ extern set_t l_sets[]; int nmoves; move_t l_moves[MAXMOVES]; -short posmoves[MAXREGS+MAXTOKENS][SETSIZE]; +short posmoves[MAXREGS + MAXTOKENS][SETSIZE]; -void -n_move(s1,e1,s2,e2,vi) struct varinfo *vi; { +void n_split(int , int, struct varinfo *, struct varinfo *, struct varinfo *, int); + +extern void dopattern(int stackcoerc, varinfo *kills, varinfo *allocates, + varinfo *generates, varinfo *yields, varinfo *leaving);; + +void n_move(int s1, int e1, int s2, int e2, struct varinfo *vi) +{ register move_p mp; - register i,j; + register int i, j; - NEXT(nmoves,MAXMOVES,"Moves"); - mp = &l_moves[nmoves-1]; + NEXT(nmoves, MAXMOVES, "Moves"); + mp = &l_moves[nmoves - 1]; mp->m_set1 = s1; mp->m_expr1 = e1; mp->m_set2 = s2; mp->m_expr2 = e2; mp->m_cindex = codeindex; - dopattern(0,VI_NULL,VI_NULL,vi,VI_NULL,VI_NULL); - if (mp->m_expr1!=0 || mp->m_expr2!=0) + dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL); + if (mp->m_expr1 != 0 || mp->m_expr2 != 0) return; - for (i=0;im_set1].set_val,i)) - for(j=0;jm_set2].set_val[j]; + for (i = 0; i < MAXREGS + MAXTOKENS; i++) + if (BIT(l_sets[mp->m_set1].set_val, i)) + for (j = 0; j < SETSIZE; j++) + posmoves[i][j] |= l_sets[mp->m_set2].set_val[j]; } -existmove(from,sp) iocc_t from; short *sp; { - register i; +int existmove(iocc_t from, short *sp) +{ + register int i; - for (i=0;ivi_int[0] = INSMOVE; vp->vi_int[1] = from.in_index; vp->vi_int[2] = to.in_index; - return(vp); + return (vp); } int ntests; test_t l_tests[MAXTESTS]; short postests[SETSIZE]; -void -n_test(s,e,vi) struct varinfo *vi; { +void n_test(int s, int e, struct varinfo *vi) +{ register test_p tp; - register i; + register int i; - NEXT(ntests,MAXTESTS,"Tests"); - tp = &l_tests[ntests-1]; + NEXT(ntests, MAXTESTS, "Tests"); + tp = &l_tests[ntests - 1]; tp->t_set = s; - tp->t_expr = e; + tp->t_expr = e; tp->t_cindex = codeindex; - dopattern(0,VI_NULL,VI_NULL,vi,VI_NULL,VI_NULL); - if (tp->t_expr!=0) + dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL); + if (tp->t_expr != 0) return; - for(i=0;it_set].set_val[i]; } -struct varinfo *gen_test(from) iocc_t from; { +struct varinfo *gen_test(iocc_t from) +{ register struct varinfo *vp; - if (!subset(from.in_set,postests,SETSIZE)) { + if (!subset(from.in_set, postests, SETSIZE)) + { error("No such test"); - return(0); + return (0); } - NEW(vp,struct varinfo); + NEW(vp, struct varinfo); vp->vi_int[0] = INSTEST; vp->vi_int[1] = from.in_index; - return(vp); + return (vp); } -struct varinfo *gen_label(arg) int arg; { +struct varinfo *gen_label(int arg) +{ register struct varinfo *vp; - NEW(vp,struct varinfo); + NEW(vp, struct varinfo); vp->vi_int[0] = INSLABDEF; vp->vi_int[1] = arg; - return(vp); + return (vp); } -struct varinfo *gen_preturn() { +struct varinfo *gen_preturn(void) +{ register struct varinfo *vp; - NEW(vp,struct varinfo); + NEW(vp, struct varinfo); vp->vi_int[0] = INSPRETURN; - return(vp); + return (vp); } -struct varinfo *gen_tlab(n) { +struct varinfo *gen_tlab(int n) +{ register struct varinfo *vp; - assert(n>=0 && n<=9); - NEW(vp,struct varinfo); + assert(n >= 0 && n <= 9); + NEW(vp, struct varinfo); vp->vi_int[0] = INSTLAB; vp->vi_int[1] = n; - return(vp); + return (vp); } int nstacks; c1_t l_stacks[MAXSTACKS]; -set_t ustackset,cstackset; +set_t ustackset, cstackset; -n_stack(s,e,p,vi) struct varinfo *vi; { +void n_stack(int s, int e, int p, struct varinfo *vi) +{ register c1_p c1p; register short *sp; - register i; + register int i; - NEXT(nstacks,MAXSTACKS,"Stacks"); - c1p= & l_stacks[nstacks-1]; + NEXT(nstacks, MAXSTACKS, "Stacks"); + c1p = &l_stacks[nstacks - 1]; c1p->c1_texpno = s; c1p->c1_expr = e; c1p->c1_prop = p; c1p->c1_codep = codeindex; - dopattern(0,VI_NULL,VI_NULL,vi,VI_NULL,VI_NULL); + dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL); - if (e==0 && p== -1) + if (e == 0 && p == -1) sp = ustackset.set_val; else sp = cstackset.set_val; - for(i=0;itk_name); + chkset = ustackset.set_val; + warn = ""; + for (i = 1; i < nregs; i++) + if (BIT(sp,i) && !BIT(chkset, i)) + error("No %sstacking rule for register %s", warn, + l_regs[i].ri_name); + for (; i < nregs + MAXTOKENS; i++) + if (BIT(sp,i) && !BIT(chkset, i)) + error("No %sstacking rule for token %s", warn, + l_tokens[i - nregs]->tk_name); } int ncoercs; @@ -189,78 +208,89 @@ set_t unstackset; /*VARARGS5*/ -void -n_coerc(ti,be,al,ge,rp,in) struct varinfo *al,*ge,*rp; iocc_t in; { +void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in) +{ register c3_p c3p; - register i; + register int i; register struct varinfo *vi; - if (ti!=0) { - for(i=0,vi=rp;vi!=0;vi=vi->vi_next,i++) + if (ti != 0) + { + for (i = 0, vi = rp; vi != 0; vi = vi->vi_next, i++) ; - if (i>1) { - n_split(ti,be,al,ge,rp,i); + if (i > 1) + { + n_split(ti, be, al, ge, rp, i); return; - } else { - if (i==0) { + } + else + { + if (i == 0) + { error("Coercion should have a result!"); return; } } - } else { - NEW(rp,struct varinfo); + } + else + { + NEW(rp, struct varinfo); rp->vi_next = 0; rp->vi_int[0] = in.in_index; } - if (nallreg>1) + if (nallreg > 1) error("More than 1 register may not be allocated"); - NEXT(ncoercs,MAXCOERCS,"Coercions"); - c3p = & l_coercs[ncoercs-1]; + NEXT(ncoercs, MAXCOERCS, "Coercions"); + c3p = &l_coercs[ncoercs - 1]; c3p->c3_texpno = ti; c3p->c3_expr = be; - c3p->c3_prop = nallreg==0 ? -1 : allreg[0]; + c3p->c3_prop = nallreg == 0 ? -1 : allreg[0]; c3p->c3_repl = rp->vi_int[0]; c3p->c3_codep = codeindex; - dopattern(ti==0,VI_NULL,al,ge,rp,VI_NULL); - if (ti==0) - for(i=0;iMAXSPLIT) { - error("Maximum split factor is %d",MAXSPLIT); + NEXT(nsplit, MAXSPLCOERC, "Splitting coercions"); + c2p = &l_split[nsplit - 1]; + if (n > MAXSPLIT) + { + error("Maximum split factor is %d", MAXSPLIT); n = MAXSPLIT; } - if (n>maxsplit) maxsplit=n; + if (n > maxsplit) + maxsplit = n; c2p->c2_texpno = ti; c2p->c2_expr = be; if (nallreg) error("No register uses allowed in splitting coercion"); c2p->c2_nsplit = n; - for (i=0,vi=rp; ivi_next) + for (i = 0, vi = rp; i < n; i++, vi = vi->vi_next) c2p->c2_repl[i] = vi->vi_int[0]; c2p->c2_codep = codeindex; - dopattern(0,VI_NULL,al,ge,rp,VI_NULL); + dopattern(0, VI_NULL, al, ge, rp, VI_NULL); } diff --git a/util/ncgg/coerc.h b/util/ncgg/coerc.h new file mode 100644 index 000000000..b34338e2f --- /dev/null +++ b/util/ncgg/coerc.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-05-03 + * + */ +#ifndef COERC_H_ +#define COERC_H_ + +#include "iocc.h" + +struct varinfo; + + +void n_move(int s1, int e1, int s2, int e2, struct varinfo *vi); +int existalmove(iocc_t from, int prpno); +struct varinfo *gen_move(iocc_t from, iocc_t to); +void n_test(int s, int e, struct varinfo *vi); +struct varinfo *gen_test(iocc_t from); +struct varinfo *gen_label(int arg); +struct varinfo *gen_preturn(void); +struct varinfo *gen_tlab(int n); +void n_stack(int s, int e, int p, struct varinfo *vi); +void checkstacking(register short *sp); +/* cgg.y is buggy!!! it has one less parameter.. */ +/*void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in);*/ +void checkunstacking(int setno); + +#endif /* COERC_H_ */ diff --git a/util/ncgg/emlookup.c b/util/ncgg/emlookup.c index 6927f9259..13f5b892b 100644 --- a/util/ncgg/emlookup.c +++ b/util/ncgg/emlookup.c @@ -3,7 +3,7 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ #ifndef NORCSID -static char rcsid[]= "$Id$"; +static char rcsid[] = "$Id$"; #endif #include @@ -18,64 +18,76 @@ extern char em_mnem[][4]; #define HASHSIZE (2*(sp_lmnem-sp_fmnem)) -struct emhashmnem { +struct emhashmnem +{ char h_name[3]; char h_value; } emhashmnem[HASHSIZE]; -initemhash() { - register i; +/* Forward declarations */ +static void enter(char *, int); +static unsigned emhash(register char *); - for(i=0;i<=sp_lmnem-sp_fmnem;i++) - enter(em_mnem[i],i+sp_fmnem); + +void initemhash(void) +{ + register int i; + + for (i = 0; i <= sp_lmnem - sp_fmnem; i++) + enter(em_mnem[i], i + sp_fmnem); enter("lab", op_lab); } -unsigned emhash(name) register char *name; { - register unsigned sum; - register i; +static unsigned emhash(register char *name) +{ + register unsigned int sum; + register int i; - for (sum=i=0;*name;i+=3) - sum ^= (*name++)<<(i&07); - return(sum); + for (sum = i = 0; *name; i += 3) + sum ^= (*name++) << (i & 07); + return (sum); } -enter(name,value) char *name; { +static void enter(char *name, int value) +{ register unsigned h; - h=emhash(name)%HASHSIZE; + h = emhash(name) % HASHSIZE; while (emhashmnem[h].h_name[0] != 0) - h = (h+1)%HASHSIZE; - strncpy(emhashmnem[h].h_name,name,3); + h = (h + 1) % HASHSIZE; + strncpy(emhashmnem[h].h_name, name, 3); emhashmnem[h].h_value = value; } -int mlookup(name) char *name; { +int mlookup(char *name) +{ register unsigned h; - h = emhash(name)%HASHSIZE; - while (strncmp(emhashmnem[h].h_name,name,3) != 0 && - emhashmnem[h].h_name[0] != 0) - h = (h+1)%HASHSIZE; - return(emhashmnem[h].h_value&0xFF); /* 0 if not found */ + h = emhash(name) % HASHSIZE; + while (strncmp(emhashmnem[h].h_name, name, 3) != 0 + && emhashmnem[h].h_name[0] != 0) + h = (h + 1) % HASHSIZE; + return (emhashmnem[h].h_value & 0xFF); /* 0 if not found */ } extern char em_flag[]; -argtyp(mn) { +int argtyp(int mn) +{ - switch(em_flag[mn-sp_fmnem]&EM_PAR) { - case PAR_W: - case PAR_S: - case PAR_Z: - case PAR_O: - case PAR_N: - case PAR_L: - case PAR_F: - case PAR_R: - case PAR_C: - return(TYPINT); - default: - return(TYPADDR); + switch (em_flag[mn - sp_fmnem] & EM_PAR) + { + case PAR_W: + case PAR_S: + case PAR_Z: + case PAR_O: + case PAR_N: + case PAR_L: + case PAR_F: + case PAR_R: + case PAR_C: + return (TYPINT); + default: + return (TYPADDR); } } diff --git a/util/ncgg/error.c b/util/ncgg/error.c index 6eaf59784..0ac822f24 100644 --- a/util/ncgg/error.c +++ b/util/ncgg/error.c @@ -13,12 +13,12 @@ static char rcsid[]= "$Id$"; int nerrors=0; -yyerror(s) char *s; { - +void yyerror(char *s) +{ error("Parser gives %s",s); } -goodbye() { +void goodbye(void) { error("This was fatal, goodbye!"); #ifndef NDEBUG @@ -60,7 +60,8 @@ void error(const char* s, ...) va_end(ap); } -tabovf(string) char *string; { - +int tabovf(char *string) +{ fatal("%s overflow",string); + return 0; } diff --git a/util/ncgg/expr.c b/util/ncgg/expr.c index d1a345961..1a70e7e13 100644 --- a/util/ncgg/expr.c +++ b/util/ncgg/expr.c @@ -3,7 +3,7 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ #ifndef NORCSID -static char rcsid[]= "$Id$"; +static char rcsid[] = "$Id$"; #endif #include @@ -24,263 +24,308 @@ static char rcsid[]= "$Id$"; extern set_t l_sets[]; -i_expr(e) expr_t e; { +int i_expr(expr_t e) +{ if (e.ex_typ != TYPINT) error("Expression should be integer"); - return(e.ex_index); + return (e.ex_index); } -b_expr(e) expr_t e; { +int b_expr(expr_t e) +{ if (e.ex_typ != TYPBOOL) error("Expression should be boolean"); - return(e.ex_index); + return (e.ex_index); } -expr_t make_expr(type,operator,op1,op2) { +expr_t make_expr(int type, int operator, int op1, int op2) +{ expr_t result; - result.ex_typ=type; - result.ex_index=ex_lookup(operator,op1,op2); - return(result); + result.ex_typ = type; + result.ex_index = ex_lookup(operator, op1, op2); + return (result); } -expr_t regno_expr(regno) { +expr_t regno_expr(int regno) +{ expr_t result; - register i; + register int i; result.ex_typ = TYPREG; - result.ex_index = ex_lookup(EX_REG,regno,0); - for (i=0;isy_type==symconst) - return(make_expr(TYPINT,EX_CON, - (int) (sy_p->sy_value.syv_cstval&0xFFFF), - (int) (sy_p->sy_value.syv_cstval>>16))); - else if (sy_p->sy_type==symsconst) - return(make_expr(TYPADDR,EX_STRING,sy_p->sy_value.syv_stringno,0)); - else if (sy_p->sy_type!=symreg) - error("Wrong type of identifier %s",name); - return(regno_expr(sy_p->sy_value.syv_regno)); + sy_p = lookup(name, symany, mustexist); + if (sy_p->sy_type == symconst) + return (make_expr(TYPINT, EX_CON, + (int) (sy_p->sy_value.syv_cstval & 0xFFFF), + (int) (sy_p->sy_value.syv_cstval >> 16))); + else if (sy_p->sy_type == symsconst) + return (make_expr(TYPADDR, EX_STRING, sy_p->sy_value.syv_stringno, 0)); + else if (sy_p->sy_type != symreg) + error("Wrong type of identifier %s", name); + return (regno_expr(sy_p->sy_value.syv_regno)); } -expr_t subreg_expr(tokarg,subreg) { +expr_t subreg_expr(int tokarg, int subreg) +{ expr_t result; result.ex_typ = TYPREG; - subregset(l_sets[tokpatset[tokarg > 0 ? tokarg-1 : tokarg]].set_val, - subreg,result.ex_regset); - result.ex_index = ex_lookup(EX_SUBREG,tokarg,subreg); - return(result); + subregset(l_sets[tokpatset[tokarg > 0 ? tokarg - 1 : tokarg]].set_val, + subreg, result.ex_regset); + result.ex_index = ex_lookup(EX_SUBREG, tokarg, subreg); + return (result); } -subregset(sp,subreg,regset) register short *sp; register short *regset; { - register i; +void subregset(register short *sp, int subreg, register short *regset) +{ + register int i; register reginfo *rp; - for (i=0;iri_memb[subreg-1]==0) - error("Register %s in set has no member %d", - rp->ri_name,subreg); - BIS(regset,rp->ri_memb[subreg-1]); - } else - BIS(regset,i); - } - for(;itk_name); + for (i = 0; i < SZOFSET(MAXREGS); i++) + regset[i] = 0; + for (i = 1; i < nregs; i++) + if (BIT(sp, i)) + { + if (subreg) + { + rp = &l_regs[i]; + if (rp->ri_memb[subreg - 1] == 0) + error("Register %s in set has no member %d", rp->ri_name, + subreg); + BIS(regset, rp->ri_memb[subreg - 1]); + } + else + BIS(regset, i); + } + for (; i < nregs + MAXTOKENS; i++) + if (BIT(sp, i)) + error("Set contains %s, which is not a register", + l_tokens[i - nregs]->tk_name); } -membset(setno,name,regset,appearance,restyp,typp) -char *name,*appearance; -short *regset; -int *typp; +int membset(int setno, char *name, short *regset, char *appearance, int restyp, int *typp) { register short *sp; register token_p tp; - register i,j,k; + register int i, j, k; int thistyp; - int typesdiffer=0; - int res_j= -1; + int typesdiffer = 0; + int res_j = -1; - if (setno < 0) return 0; + if (setno < 0) + return 0; sp = l_sets[setno].set_val; - for (i=1;itk_att[j].ta_type == -3 || - strcmp(tp->tk_att[j].ta_name,name));j++) - ; - if (j==MAXATT) - error("Token %s does not contain %s",tp->tk_name,name); - else if (j!=res_j && res_j != -1) - typesdiffer=1; - else { - res_j = j; - thistyp = tp->tk_att[j].ta_type; - if (thistyp== -2) { - if (restyp!=TYPADDR && restyp!=0) - typesdiffer=1; + for (i = nregs; i < nregs + MAXTOKENS; i++) + if (BIT(sp, i)) + { + tp = l_tokens[i - nregs]; + for (j = 0; + j < MAXATT + && (tp->tk_att[j].ta_type == -3 + || strcmp(tp->tk_att[j].ta_name, name)); + j++) + ; + if (j == MAXATT) + error("Token %s does not contain %s", tp->tk_name, name); + else if (j != res_j && res_j != -1) + typesdiffer = 1; + else + { + res_j = j; + thistyp = tp->tk_att[j].ta_type; + if (thistyp == -2) + { + if (restyp != TYPADDR && restyp != 0) + typesdiffer = 1; + else + restyp = TYPADDR; + } + else if (thistyp == -1) + { + if (restyp != TYPINT && restyp != 0) + typesdiffer = 1; + else + restyp = TYPINT; + } else - restyp=TYPADDR; - } else if (thistyp== -1) { - if (restyp!=TYPINT && restyp!=0) - typesdiffer=1; - else - restyp=TYPINT; - } else { - if (restyp!=TYPREG && restyp!=0) - typesdiffer=1; - else { - restyp=TYPREG; - for(k=0;ktk_att[j].ta_type].pr_regset[k]; + { + if (restyp != TYPREG && restyp != 0) + typesdiffer = 1; + else + { + restyp = TYPREG; + for (k = 0; k < SZOFSET(MAXREGS); k++) + regset[k] |= + l_props[tp->tk_att[j].ta_type].pr_regset[k]; + } } } } - } if (typesdiffer) error("%s is not a valid expression; types differ in the set", - appearance); - *typp = restyp==0 ? TYPINT : restyp; - return(res_j == -1 ? 0 : res_j); + appearance); + *typp = restyp == 0 ? TYPINT : restyp; + return (res_j == -1 ? 0 : res_j); } -expr_t memb_expr(setno,name,appearance,tokarg) char *name,*appearance; { +expr_t memb_expr(int setno, char *name, char *appearance, int tokarg) +{ expr_t result; int res_j; - res_j = membset(setno,name,result.ex_regset,appearance,0,&result.ex_typ); - result.ex_index = ex_lookup(EX_TOKFIELD,tokarg,res_j+1); - return(result); + res_j = membset(setno, name, result.ex_regset, appearance, 0, + &result.ex_typ); + result.ex_index = ex_lookup(EX_TOKFIELD, tokarg, res_j + 1); + return (result); } -expr_t tokm_expr(tokarg,name) char *name; { +expr_t tokm_expr(int tokarg, char *name) +{ char app[100]; int tokarg1 = tokarg > 0 ? tokarg : 1; - sprintf(app,"%%%d.%s",tokarg1,name); - return(memb_expr(tokpatset[tokarg1-1],name,app,tokarg)); + sprintf(app, "%%%d.%s", tokarg1, name); + return (memb_expr(tokpatset[tokarg1 - 1], name, app, tokarg)); } -expr_t perc_ident_expr(name) char *name; { +expr_t perc_ident_expr(char *name) +{ char app[100]; - sprintf(app,"%%%s",name); - return(memb_expr(cursetno,name,app,0)); + sprintf(app, "%%%s", name); + return (memb_expr(cursetno, name, app, 0)); } -expr_t all_expr(all_no,subreg) { +expr_t all_expr(int all_no, int subreg) +{ set_t localset; - register i; + register int i; register short *sp; expr_t result; sp = l_props[allreg[all_no]].pr_regset; - for (i=0;iex_operator != operator) continue; if (p->ex_lnode != lnode) continue; if (p->ex_rnode != rnode) continue; - return(p-nodes); + return (p - nodes); } - NEXT(nnodes,MAXNODES,"Node"); + NEXT(nnodes, MAXNODES, "Node"); p->ex_operator = operator; p->ex_lnode = lnode; p->ex_rnode = rnode; - return(p-nodes); + return (p - nodes); } diff --git a/util/ncgg/expr.h b/util/ncgg/expr.h index 177a71f7b..00f080d7a 100644 --- a/util/ncgg/expr.h +++ b/util/ncgg/expr.h @@ -3,6 +3,8 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* $Id$ */ +#ifndef EXPR_H_ +#define EXPR_H_ typedef struct expr { int ex_typ; @@ -15,6 +17,27 @@ typedef struct expr { #define TYPADDR 3 #define TYPREG 4 +int ex_lookup(int operator, int lnode, int rnode); +void initnodes(void); +expr_t regvar_expr(expr_t e, int regtyp, int regsiz); +expr_t iextoaddr(expr_t e); +expr_t sum_expr(expr_t e1, expr_t e2); +int ne2expr(expr_t e1, expr_t e2); +int eq2expr(expr_t e1, expr_t e2); +expr_t all_expr(int all_no, int subreg); +expr_t perc_ident_expr(char *name); +expr_t tokm_expr(int tokarg, char *name); +int membset(int setno, char *name, short *regset, char *appearance, int restyp, int *typp); +void subregset(register short *sp, int subreg, register short *regset); +expr_t subreg_expr(int tokarg, int subreg); +expr_t ident_expr(char *name); +expr_t make_expr(int type, int operator, int op1, int op2); +int b_expr(expr_t e); +int i_expr(expr_t e); + + /* When the type is register the regset contains the set of possible registers for checking purposes only. */ + +#endif /* EXPR_H_ */ diff --git a/util/ncgg/extern.h b/util/ncgg/extern.h index 561591627..bcff46002 100644 --- a/util/ncgg/extern.h +++ b/util/ncgg/extern.h @@ -38,9 +38,8 @@ extern int maxtokensize; extern int nprocargs, maxprocargs; extern int use_tes; -extern char *mystrcpy(); -extern char *myalloc(); - extern void error(const char* s, ...); extern void fatal(const char* s, ...); - +extern int tabovf(char *string); +extern int strlookup(char *str); +extern void errorexit(void); diff --git a/util/ncgg/hall.c b/util/ncgg/hall.c index f670b24b8..53d695be0 100644 --- a/util/ncgg/hall.c +++ b/util/ncgg/hall.c @@ -3,18 +3,19 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ #ifndef NORCSID -static char rcsid[]= "$Id$"; +static char rcsid[] = "$Id$"; #endif #include #include "param.h" #include "set.h" #include "extern.h" +#include "hall.h" #include /* * This file implements the marriage thesis from Hall. - * The thesis says that given a number, say N, of subsets from + * The thesis says that givoid hallverbose(void)ven a number, say N, of subsets from * a finite set, it is possible to create a set with cardinality N, * that contains one member for each of the subsets, * iff for each number, say M, of subsets from 2 to N the union of @@ -29,56 +30,66 @@ static char rcsid[]= "$Id$"; #define MAXHALL (TOKPATMAX+MAXALLREG) short hallsets[MAXHALL][SETSIZE]; -int nhallsets= -1; +int nhallsets = -1; int hallfreq[MAXHALL][2]; -hallverbose() { - register i; - register max; - - fprintf(stderr,"Table of hall frequencies\n # pre post\n"); - for (max=MAXHALL-1;hallfreq[max][0]==0 && hallfreq[max][1]==0;max--) +int recurhall(int, short [][SETSIZE]); +void unite(register short *, short *); + + +void hallverbose(void) +{ + register int i; + register int max; + + fprintf(stderr, "Table of hall frequencies\n # pre post\n"); + for (max = MAXHALL - 1; hallfreq[max][0] == 0 && hallfreq[max][1] == 0; + max--) ; - for (i=0;i<=max;i++) - fprintf(stderr,"%3d%6d%6d\n",i,hallfreq[i][0],hallfreq[i][1]); + for (i = 0; i <= max; i++) + fprintf(stderr, "%3d%6d%6d\n", i, hallfreq[i][0], hallfreq[i][1]); } -inithall() { +void inithall(void) +{ assert(nhallsets == -1); - nhallsets=0; + nhallsets = 0; } -nexthall(sp) register short *sp; { - register i; - - assert(nhallsets>=0); - for(i=0;i= 0); + for (i = 0; i < SETSIZE; i++) hallsets[nhallsets][i] = sp[i]; nhallsets++; } -card(sp) register short *sp; { - register sum,i; - - sum=0; - for(i=0;i<8*sizeof(short)*SETSIZE;i++) - if (BIT(sp,i)) +int card(register short *sp) +{ + register int sum, i; + + sum = 0; + for (i = 0; i < 8 * sizeof(short) * SETSIZE; i++) + if (BIT(sp, i)) sum++; - return(sum); + return (sum); } -checkhall() { - - assert(nhallsets>=0); +void checkhall(void) +{ + assert(nhallsets >= 0); if (!hall()) error("Hall says: \"You can't have those registers\""); } -hall() { - register i,j,k; +int hall(void) +{ + register int i, j, k; int ok; - + hallfreq[nhallsets][0]++; /* * If a set has cardinality >= nhallsets it can never be the cause @@ -86,66 +97,72 @@ hall() { * But then nhallsets is less, so this step can be re-applied. */ - do { + do + { ok = 0; - for(i=0;i=nhallsets) { - for (j=i+1;j= nhallsets) + { + for (j = i + 1; j < nhallsets; j++) + for (k = 0; k < SETSIZE; k++) + hallsets[j - 1][k] = hallsets[j][k]; nhallsets--; ok = 1; break; } } while (ok); - + /* * Now all sets have cardinality < nhallsets */ - + hallfreq[nhallsets][1]++; - ok=recurhall(nhallsets,hallsets); + ok = recurhall(nhallsets, hallsets); nhallsets = -1; - return(ok); + return (ok); } -recurhall(nhallsets,hallsets) short hallsets[][SETSIZE]; { +int recurhall(int nhallsets, short hallsets[][SETSIZE]) +{ short copysets[MAXHALL][SETSIZE]; short setsum[SETSIZE]; - register i,j,k,ncopys; - + register int i, j, k, ncopys; + /* * First check cardinality of union of all */ - for(k=0;k @@ -14,192 +14,198 @@ static char rcsid[]= "$Id$"; #include "set.h" #include "expr.h" #include "iocc.h" +#include "subr.h" #include #include "extern.h" extern int niops; extern iocc_t iops[]; -extern inproc; +extern int inproc; extern set_t l_sets[]; extern inst_t l_instances[]; -extern expr_t subreg_expr(),regno_expr(); +extern expr_t subreg_expr(), regno_expr(); -struct varinfo * setcoco(n) { +static struct varinfo * setcoco(int n) +{ struct varinfo *vi; - - NEW(vi,struct varinfo); + + NEW(vi, struct varinfo); vi->vi_next = VI_NULL; vi->vi_int[0] = INSSETCC; vi->vi_int[1] = n; - return(vi); + return (vi); } -struct varinfo * generase(n) { +static struct varinfo * generase(int n) +{ struct varinfo *vi; - NEW(vi,struct varinfo); + NEW(vi, struct varinfo); vi->vi_next = VI_NULL; vi->vi_int[0] = INSERASE; vi->vi_int[1] = n; - return(vi); + return (vi); } -struct varinfo * genremove(n) { +static struct varinfo * genremove(int n) +{ struct varinfo *vi; - NEW(vi,struct varinfo); + NEW(vi, struct varinfo); vi->vi_next = VI_NULL; vi->vi_int[0] = INSREMOVE; vi->vi_int[1] = n; - return(vi); + return (vi); } -onlyreg(argno) { - register bitno; +static int onlyreg(int argno) +{ + register int bitno; register short *sp; - - if (! argno) argno++; - sp = l_sets[tokpatset[argno-1]].set_val; - for(bitno=nregs;bitnoi_name)) + for (ip = l_instr; ip < l_instr + ninstr; ip++) + { + if (strcmp(ident, ip->i_name)) continue; - if (ip->i_nops!=niops) + if (ip->i_nops != niops) continue; - for(i=0,op=ip->i_oplist;io_next) { - if (!subset(iops[i].in_set,l_sets[op->o_setno].set_val,SETSIZE)) + for (i = 0, op = ip->i_oplist; i < niops; i++, op = op->o_next) + { + if (!subset(iops[i].in_set, l_sets[op->o_setno].set_val, SETSIZE)) goto cont; } - goto found; /* oh well, one more won't hurt */ - cont:; + goto found; + /* oh well, one more won't hurt */ + cont: ; } - error("Such an \"%s\" does not exist",ident); - return(0); -found: - NEW(vi,struct varinfo); - vi->vi_int[0] = ip-l_instr; + error("Such an \"%s\" does not exist", ident); + return (0); + found: + NEW(vi, struct varinfo); + vi->vi_int[0] = ip - l_instr; vi->vi_int[1] = star; - vi->vi_next=0; + vi->vi_next = 0; retval = vi; - for(i=0;ivi_vi,struct varinfo); - vi=vi->vi_vi; + for (i = 0; i < niops; i++) + { + NEW(vi->vi_vi, struct varinfo); + vi = vi->vi_vi; vi->vi_int[0] = iops[i].in_index; } vi->vi_vi = 0; vi = retval; - for(i=0,op=ip->i_oplist;io_next) { - if(op->o_adorn&AD_CC) { - vi->vi_next = setcoco(iops[i].in_index); - vi=vi->vi_next; - } - switch(op->o_adorn&AD_RWMASK) { - default: - /* Nothing possible to do */ - break; - case AD_RO: - /* It might be possible to do something - * here but not now. - */ - break; - case AD_RW: - case AD_WO: - /* Treated the same for now */ - insta = &l_instances[iops[i].in_index]; - switch(insta->in_which) { - case IN_COPY: - if(insta->in_info[1]==0 && !onlyreg(insta->in_info[0])) - break; - makescratch(insta->in_info[0]); - vi->vi_next = generase( - ex_lookup( - EX_SUBREG,insta->in_info[0], - insta->in_info[1] - ) - ); + for (i = 0, op = ip->i_oplist; i < niops; i++, op = op->o_next) + { + if (op->o_adorn & AD_CC) + { + vi->vi_next = setcoco(iops[i].in_index); vi = vi->vi_next; - break; - case IN_MEMB: - vi->vi_next = generase( - ex_lookup( - EX_TOKFIELD,insta->in_info[0], - insta->in_info[1] - ) - ); - vi=vi->vi_next; - break; - case IN_RIDENT: - vi->vi_next = generase( - ex_lookup( - EX_REG,insta->in_info[0],0 - ) - ); - vi = vi->vi_next; - break; - case IN_ALLOC: - vi->vi_next = generase( - ex_lookup( - EX_ALLREG,insta->in_info[0]+1, - insta->in_info[1] - ) - ); - vi = vi->vi_next; - break; - case IN_S_DESCR: - case IN_D_DESCR: - { int temp; - - if (insta->in_which == IN_S_DESCR) - temp = wordsize; - else - temp = 2 * wordsize; - temp=ex_lookup(EX_REGVAR,insta->in_info[1],temp); - vi->vi_next = generase(temp); - vi = vi->vi_next; - vi->vi_next = genremove(temp); - vi = vi->vi_next; - break; - } } - break; - } + switch (op->o_adorn & AD_RWMASK) + { + default: + /* Nothing possible to do */ + break; + case AD_RO: + /* It might be possible to do something + * here but not now. + */ + break; + case AD_RW: + case AD_WO: + /* Treated the same for now */ + insta = &l_instances[iops[i].in_index]; + switch (insta->in_which) + { + case IN_COPY: + if (insta->in_info[1] == 0 + && !onlyreg(insta->in_info[0])) + break; + makescratch(insta->in_info[0]); + vi->vi_next = generase(ex_lookup( + EX_SUBREG, insta->in_info[0], insta->in_info[1])); + vi = vi->vi_next; + break; + case IN_MEMB: + vi->vi_next = generase(ex_lookup( + EX_TOKFIELD, insta->in_info[0], insta->in_info[1])); + vi = vi->vi_next; + break; + case IN_RIDENT: + vi->vi_next = generase(ex_lookup( + EX_REG, insta->in_info[0], 0)); + vi = vi->vi_next; + break; + case IN_ALLOC: + vi->vi_next = generase(ex_lookup( + EX_ALLREG, insta->in_info[0] + 1, insta->in_info[1])); + vi = vi->vi_next; + break; + case IN_S_DESCR: + case IN_D_DESCR: + { + int temp; + + if (insta->in_which == IN_S_DESCR) + temp = wordsize; + else + temp = 2 * wordsize; + temp = ex_lookup(EX_REGVAR, insta->in_info[1], temp); + vi->vi_next = generase(temp); + vi = vi->vi_next; + vi->vi_next = genremove(temp); + vi = vi->vi_next; + break; + } + } + break; + } } - for (eravi=ip->i_erases;eravi != VI_NULL;eravi=eravi->vi_next) { + for (eravi = ip->i_erases; eravi != VI_NULL ; eravi = eravi->vi_next) + { if (eravi->vi_int[0] < 0) vi->vi_next = setcoco(0); - else { + else + { vi->vi_next = generase(eravi->vi_int[0]); - vi=vi->vi_next; + vi = vi->vi_next; vi->vi_next = genremove(eravi->vi_int[0]); } - vi=vi->vi_next; + vi = vi->vi_next; } - return(retval); + return (retval); } diff --git a/util/ncgg/instruct.h b/util/ncgg/instruct.h index 68828f99b..5dea2d28c 100644 --- a/util/ncgg/instruct.h +++ b/util/ncgg/instruct.h @@ -3,6 +3,8 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* $Id$ */ +#ifndef INSTRUCT_H_ +#define INSTRUCT_H_ #ifndef _COST_ #include "cost.h" @@ -39,3 +41,8 @@ extern instr_t l_instr[]; * if it contains the same information and is allowed as an operand * in this place. Too difficult for now. */ +struct varinfo; + +struct varinfo *gen_inst(char *ident, int star); + +#endif /* INSTRUCT_H_ */ diff --git a/util/ncgg/iocc.c b/util/ncgg/iocc.c index 9519b1cd6..96ad56f6f 100644 --- a/util/ncgg/iocc.c +++ b/util/ncgg/iocc.c @@ -3,7 +3,7 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ #ifndef NORCSID -static char rcsid[]= "$Id$"; +static char rcsid[] = "$Id$"; #endif #include @@ -14,6 +14,7 @@ static char rcsid[]= "$Id$"; #include "set.h" #include "expr.h" #include "lookup.h" +#include "subr.h" #include "token.h" #include "property.h" #include "iocc.h" @@ -28,184 +29,204 @@ expr_t arexp[MAXATT]; expr_t iextoaddr(); -iocc_t subr_iocc(tokarg,subreg) { +/* Forward declarations */ +static int instalookup(inst_t, int); + +iocc_t subr_iocc(int tokarg, int subreg) +{ inst_t insta; - iocc_t result; - register i; + iocc_t result; + register int i; insta.in_which = IN_COPY; insta.in_info[0] = tokarg; insta.in_info[1] = subreg; - result.in_index = instalookup(insta,2); - if (tokarg < 1) tokarg = 1; - if (subreg==0) - for (i=0;isy_value.syv_regno; - result.in_index = instalookup(insta,1); - BIS(result.in_set,sy_p->sy_value.syv_regno); - return(result); + result.in_index = instalookup(insta, 1); + BIS(result.in_set, sy_p->sy_value.syv_regno); + return (result); } -iocc_t all_iocc(all_no,subreg) { +iocc_t all_iocc(int all_no, int subreg) +{ iocc_t result; inst_t insta; - register i; + register int i; set_t localset; register short *sp; sp = l_props[allreg[all_no]].pr_regset; - for (i=0;isy_value.syv_tokno]; - BIS(result.in_set,sy_p->sy_value.syv_tokno+nregs); + BIS(result.in_set, sy_p->sy_value.syv_tokno + nregs); insta.in_which = IN_DESCR; - if (rvused&SL_REGVAR && strcmp(ident,"LOCAL")==0) + if (rvused & SL_REGVAR && strcmp(ident, "LOCAL") == 0) insta.in_which = IN_S_DESCR; - else if (rvused&DL_REGVAR && strcmp(ident,"DLOCAL")==0) + else if (rvused & DL_REGVAR && strcmp(ident, "DLOCAL") == 0) insta.in_which = IN_D_DESCR; insta.in_info[0] = sy_p->sy_value.syv_tokno; - for (i=0;itk_att[i].ta_type == -3) { - if (narexpr>i) - error("token %s initialized with too many attributes",ident); + for (i = 0; i < MAXATT; i++) + { + if (tp->tk_att[i].ta_type == -3) + { + if (narexpr > i) + error("token %s initialized with too many attributes", ident); break; } - if (i>= narexpr) { - error("token %s initialized with too few attributes", - ident); + if (i >= narexpr) + { + error("token %s initialized with too few attributes", ident); break; } typerr = 0; - switch(arexp[i].ex_typ) { - default: assert(0); - case TYPINT: - if (tp->tk_att[i].ta_type != -1) - if (tp->tk_att[i].ta_type == -2) - arexp[i] = iextoaddr(arexp[i]); - else + switch (arexp[i].ex_typ) + { + default: + assert(0); + case TYPINT: + if (tp->tk_att[i].ta_type != -1) + if (tp->tk_att[i].ta_type == -2) + arexp[i] = iextoaddr(arexp[i]); + else + typerr++; + break; + case TYPBOOL: + typerr++; + break; + case TYPADDR: + if (tp->tk_att[i].ta_type != -2) typerr++; - break; - case TYPBOOL: - typerr++; break; - case TYPADDR: - if (tp->tk_att[i].ta_type != -2) - typerr++; - break; - case TYPREG: - if (tp->tk_att[i].ta_type<0) - typerr++; - else if (!subset(arexp[i].ex_regset, - l_props[tp->tk_att[i].ta_type].pr_regset, - SZOFSET(MAXREGS))) - typerr++; - break; + break; + case TYPREG: + if (tp->tk_att[i].ta_type < 0) + typerr++; + else if (!subset(arexp[i].ex_regset, + l_props[tp->tk_att[i].ta_type].pr_regset, + SZOFSET(MAXREGS))) + typerr++; + break; } if (typerr) - error("Attribute %s.%s given wrong type of value", - ident,tp->tk_att[i].ta_name); - insta.in_info[i+1] = arexp[i].ex_index; + error("Attribute %s.%s given wrong type of value", ident, + tp->tk_att[i].ta_name); + insta.in_info[i + 1] = arexp[i].ex_index; } - result.in_index = instalookup(insta,i+1); - return(result); + result.in_index = instalookup(insta, i + 1); + return (result); } /* low level instance package */ -int ninstances=1; +int ninstances = 1; inst_t l_instances[MAXINSTANCES]; -instalookup(insta,filled) inst_t insta; { - register i,j; +static int instalookup(inst_t insta, int filled) +{ + register int i, j; - for (j=filled;j<=MAXATT;j++) + for (j = filled; j <= MAXATT; j++) insta.in_info[j] = 0; - for (i=0;i @@ -11,61 +11,66 @@ static char rcsid[]= "$Id$"; #include "param.h" #include "lookup.h" #include "extern.h" +#include "subr.h" -char *myalloc(); -char *mystrcpy(); +; -symbol dumsym; /* dummy to return in case of error */ +symbol dumsym; /* dummy to return in case of error */ -symbol *lookup(name,type,style) -char *name; -symtype type; -lookupstyle style; +/* Forward declarations */ +static int hashvalue(register char *); + +symbol *lookup(char *name, symtype type, lookupstyle style) { - symbol *sy_p,**sy_pp; + symbol *sy_p, **sy_pp; - for (sy_pp = &symhash[hashvalue(name)];(sy_p= *sy_pp) != 0;sy_pp= &sy_p->sy_next) { - if (strcmp(sy_p->sy_name,name)!=0) + for (sy_pp = &symhash[hashvalue(name)]; (sy_p = *sy_pp) != 0; + sy_pp = &sy_p->sy_next) + { + if (strcmp(sy_p->sy_name, name) != 0) continue; - switch(style) { + switch (style) + { + default: + assert(0); + case justlooking: + case mustexist: + case makeexist: + if (type == symany || type == sy_p->sy_type) + return (sy_p); + continue; + case newsymbol: + error("%s already defined", name); + return (&dumsym); + } + } + switch (style) + { default: assert(0); case justlooking: + return ((symbol *) 0); case mustexist: - case makeexist: - if (type==symany || type==sy_p->sy_type) - return(sy_p); - continue; + fatal("%s is unknown symbol", name); + /* NOTREACHED */ case newsymbol: - error("%s already defined",name); - return(&dumsym); - } - } - switch(style) { - default: - assert(0); - case justlooking: - return((symbol *) 0); - case mustexist: - fatal("%s is unknown symbol",name); - /* NOTREACHED */ - case newsymbol: - case makeexist: - NEW(sy_p,symbol); - sy_p->sy_next = 0; - sy_p->sy_name = mystrcpy(name); - assert(type!=symany); - sy_p->sy_type = type; - *sy_pp = sy_p; - return(sy_p); + case makeexist: + NEW(sy_p, symbol); + sy_p->sy_next = 0; + sy_p->sy_name = mystrcpy(name); + assert(type != symany); + sy_p->sy_type = type; + *sy_pp = sy_p; + return (sy_p); } } -hashvalue(s) register char *s; { - register unsigned sum=0; - register i; +static int hashvalue(register char *s) +{ + register unsigned sum = 0; + register int i; - for(i=0;*s;s++,i=(i+3)&07) - sum += *s< #include +#include "param.h" +#include "hall.h" +#include "expr.h" #include "extern.h" char *filename; -main(argc,argv) char **argv; { +extern void enterkeyw(void); +extern void initio(void); +extern void initemhash(void); +extern void finishio(void); +extern void statistics(void); +extern int yyparse(void); + +int main(int argc, char **argv) +{ extern int nerrors; extern int code_in_c; extern int tabledebug; extern int verbose; - while (argc >1 && argv[1][0]=='-') { - switch(argv[1][1]) { - case 'c': - code_in_c = 0; - break; - case 'd': - tabledebug++; - break; - case 'v': - verbose++; - break; - default: - error("Unknown flag -%c",argv[1][1]); + while (argc > 1 && argv[1][0] == '-') + { + switch (argv[1][1]) + { + case 'c': + code_in_c = 0; + break; + case 'd': + tabledebug++; + break; + case 'v': + verbose++; + break; + default: + error("Unknown flag -%c", argv[1][1]); } - argc--; argv++; + argc--; + argv++; } - if (argc==2) { - if (freopen(argv[1],"r",stdin)==NULL) { - error("Can't open %s",argv[1]); + if (argc == 2) + { + if (freopen(argv[1], "r", stdin) == NULL) + { + error("Can't open %s", argv[1]); exit(-1); } filename = argv[1]; } - else if (argc == 1) { + else if (argc == 1) + { filename = ""; - } else - error("Usage: %s [-c] [-d] [-v] [table]",argv[0]); + } + else + error("Usage: %s [-c] [-d] [-v] [table]", argv[0]); initemhash(); enterkeyw(); initnodes(); initio(); yyparse(); - if (nerrors==0) { + if (nerrors == 0) + { finishio(); statistics(); if (verbose) hallverbose(); - } else { + } + else + { errorexit(); } - exit(nerrors==0 ? 0 : -1); + exit(nerrors == 0 ? 0 : -1); } diff --git a/util/ncgg/output.c b/util/ncgg/output.c index 40733bab0..84ce8dd7a 100644 --- a/util/ncgg/output.c +++ b/util/ncgg/output.c @@ -2,34 +2,34 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* #define CODEDEBUG /* print readable code */ +/* #define CODEDEBUG *//* print readable code */ #ifdef CODEDEBUG -int code_in_c=0; /* put readable code in "code" */ -int tabledebug=1; /* generate code for table debugging */ +int code_in_c=0; /* put readable code in "code" */ +int tabledebug=1; /* generate code for table debugging */ #else -int code_in_c=1; /* put code in "tables.c" */ -int tabledebug=0; /* do not generate code for table debugging */ +int code_in_c = 1; /* put code in "tables.c" */ +int tabledebug = 0; /* do not generate code for table debugging */ #endif -int verbose=0; /* print all statistics */ -int use_tes; /* use top element size information */ -char *c_file= "tables.c"; -char *h_file= "tables.H"; -char *cd_file= "code"; +int verbose = 0; /* print all statistics */ +int use_tes; /* use top element size information */ +char *c_file = "tables.c"; +char *h_file = "tables.H"; +char *cd_file = "code"; #ifndef NORCSID -static char rcsid[]= "$Id$"; +static char rcsid[] = "$Id$"; #endif #include #include #include -#include #include "varinfo.h" #include "param.h" #include "reg.h" #include "property.h" #include "token.h" #include "set.h" +#include "subr.h" #include "instruct.h" #include "lookup.h" #include @@ -40,7 +40,7 @@ static char rcsid[]= "$Id$"; #define BMASK 0xFF #define BSHIFT 8 -FILE *ctable,*htable; +FILE *ctable, *htable; FILE *code; short *lineset; int maxline; @@ -59,66 +59,94 @@ extern int nstacks; extern c1_t l_stacks[]; extern int ncoercs; extern c3_t l_coercs[]; -extern int nsplit,maxsplit; +extern int nsplit, maxsplit; extern c2_t l_split[]; extern set_t l_sets[]; -int maxallreg=0; -int maxregvars=0; +int maxallreg = 0; +int maxregvars = 0; int setsize; -opnfile(f,s) FILE **f; char *s; { +int prevind = 0; +int npatbytes = -1; +char pattern[MAXPATBYTES]; +int pathash[256]; - if ((*f=fopen(s,"w"))==NULL) - fatal("Can't create %s",s); +extern int npatterns; +extern int patindex[]; +extern int empatlen; +extern int emmnem[]; +extern int empatexpr; + +extern node_t nodes[]; +extern int nnodes; + +extern char * filename; + +/* Forward declarations */ +static void patbyte(int); +static void patshort(int); +static void pat(int); + +void opnfile(FILE **f, char *s) +{ + + if ((*f = fopen(s, "w")) == NULL) + fatal("Can't create %s", s); } -unlfile(f,s) FILE *f; char *s; { - - if (f) fclose(f); - if (unlink(s)<0) - error("%s incorrect, must be removed!!",s); +void unlfile(FILE *f, char *s) +{ + if (f) + fclose(f); + if (remove(s) < 0) + error("%s incorrect, must be removed!!", s); } -initio() { - extern char *myalloc(); +void initio(void) +{ - opnfile(&ctable,c_file); - opnfile(&htable,h_file); + opnfile(&ctable, c_file); + opnfile(&htable, h_file); if (code_in_c) - fprintf(ctable,"char coderules[] = {"); + fprintf(ctable, "char coderules[] = {"); else - opnfile(&code,cd_file); + opnfile(&code, cd_file); patbyte(0); if (tabledebug) - lineset = (short *) myalloc(SZOFSET(MAXSOURCELINES)*sizeof(short)); + lineset = (short *) myalloc(SZOFSET(MAXSOURCELINES) * sizeof(short)); } -finishcode() { +void finishcode(void) +{ if (code_in_c) - fprintf(ctable,"\n};\n\n"); + fprintf(ctable, "\n};\n\n"); fprintf(ctable, "int allsetno = %d;\n", allsetno); - if (tabledebug) { - int fd; + if (tabledebug) + { + FILE *fd; int sz; - - if ((fd=creat("lineset",0666))>=0) { - sz = SZOFSET(maxline)*2; - write(fd,&sz,sizeof(int)); - write(fd,lineset,sz); - close(fd); - } else + + fd = fopen("lineset","wb"); + if (fd != NULL) + { + sz = SZOFSET(maxline) * 2; + fwrite(&sz,1,sizeof(int),fd); + fwrite(lineset,1,sz,fd); + fclose(fd); + } + else error("Can't create lineset"); } } -errorexit() { - - unlfile(ctable,c_file); - unlfile(htable,h_file); +void errorexit(void) +{ + unlfile(ctable, c_file); + unlfile(htable, h_file); if (!code_in_c) - unlfile(code,cd_file); + unlfile(code, cd_file); } #ifdef CODEDEBUG @@ -131,190 +159,208 @@ errorexit() { #define codenl() #define code8nl(x) code8(x) -code8(x) { +void code8(int x) +{ codeindex++; if (code_in_c) - fprintf(ctable,"%d,",x&0377); + fprintf(ctable, "%d,", x & 0377); else - putc(x,code); + putc(x, code); } -code53(x,y) { - - code8(x+(y<<5)); +void code53(int x, int y) +{ + code8(x + (y << 5)); } -codeint(x) { - - assert(x>=0 && x<=32767); - if (x<128) { +void codeint(int x) +{ + assert(x >= 0 && x <= 32767); + if (x < 128) + { code8(x); - } else { - code8(x/256+128); - code8(x%256); + } + else + { + code8(x / 256 + 128); + code8(x % 256); } } #endif -int prevind=0; -int npatbytes= -1; -char pattern[MAXPATBYTES]; -int pathash[256]; -outpatterns() { - extern int npatterns; - extern int patindex[]; - extern int empatlen; - extern int emmnem[]; - extern int empatexpr; - register i; +void outpatterns(void) +{ + register int i; - if (!inproc) { + if (!inproc) + { patbyte(0); patshort(prevind); - prevind = npatbytes-2; + prevind = npatbytes - 2; patbyte(empatlen); - for(i=0;i=0); - if (n<128) + assert(n >= 0); + if (n < 128) patbyte(n); - else { - patbyte(n/256+128); - patbyte(n%256); + else + { + patbyte(n / 256 + 128); + patbyte(n % 256); } } -patshort(n) { +static void patshort(int n) +{ - patbyte(n%256); - patbyte(n/256); + patbyte(n % 256); + patbyte(n / 256); } -patbyte(n) { +static void patbyte(int n) +{ NEXT(npatbytes, MAXPATBYTES, "Pattern bytes"); - pattern[npatbytes]=n; + pattern[npatbytes] = n; } -hashpatterns() { +void hashpatterns(void) +{ short index; - register char *bp,*tp; + register char *bp, *tp; register short i; unsigned short hashvalue; int patlen; index = prevind; - while (index != 0) { + while (index != 0) + { bp = &pattern[index]; tp = &bp[PO_MATCH]; - i = *tp++&BMASK; - if (i==BMASK) { - i = *tp++&BMASK; - i |= (*tp++&BMASK)<>BSHIFT; + i = index; + index = (bp[PO_NEXT] & BMASK) | (bp[PO_NEXT + 1] << BSHIFT); + bp[PO_HASH] = hashvalue >> BSHIFT; hashvalue &= BMASK; - bp[PO_NEXT] = pathash[hashvalue]&BMASK; - bp[PO_NEXT+1] = pathash[hashvalue]>>BSHIFT; + bp[PO_NEXT] = pathash[hashvalue] & BMASK; + bp[PO_NEXT + 1] = pathash[hashvalue] >> BSHIFT; pathash[hashvalue] = i; } } -outincludes() { +void outincludes(void) +{ - fprintf(ctable,"#include \"param.h\"\n"); - fprintf(ctable,"#include \"tables.h\"\n"); - fprintf(ctable,"#include \"types.h\"\n"); - fprintf(ctable,"#include \n"); - fprintf(ctable,"#include \"data.h\"\n"); + fprintf(ctable, "#include \"param.h\"\n"); + fprintf(ctable, "#include \"tables.h\"\n"); + fprintf(ctable, "#include \"types.h\"\n"); + fprintf(ctable, "#include \n"); + fprintf(ctable, "#include \"data.h\"\n"); } -outregs() { - register i,j,k; +void outregs(void) +{ + register int i, j, k; short rset[SZOFSET(MAXREGS)]; - short clashlist[MAXREGS*MAXREGS]; + short clashlist[MAXREGS * MAXREGS]; int iclashlist = 0; - int t,ready; + int t, ready; - - fprintf(ctable,"char stregclass[] = {\n"); - for (i=0;i=0 && l_regs[i].ri_memb[0]==0); - fprintf(ctable,"},\n"); + fprintf(ctable, ",%d", + l_regs[i].ri_rregvar >= 0 && l_regs[i].ri_memb[0] == 0); + fprintf(ctable, "},\n"); } - fprintf(ctable,"};\n\n short clashlist[] = {\n\t"); - for (i = 0; i < iclashlist; i++) { + fprintf(ctable, "};\n\n short clashlist[] = {\n\t"); + for (i = 0; i < iclashlist; i++) + { fprintf(ctable, "%d, ", clashlist[i]); - if (clashlist[i] == 0) fprintf(ctable, "\n\t"); + if (clashlist[i] == 0) + fprintf(ctable, "\n\t"); } fprintf(ctable, "0};\n\n"); } -outregvars() { - register i,j; +void outregvars(void) +{ + register int i, j; - fprintf(htable,"#define REGVARS\n"); - if (reglap!=0) - fprintf(htable,"#define REGLAP\n"); - fprintf(ctable,"#include \"regvar.h\"\n"); - fprintf(ctable,"int nregvar[4] = { "); - for (i=0;i<4;i++) { - fprintf(ctable,"%d, ",nregvar[i]); - if (nregvar[i]>maxregvars) + fprintf(htable, "#define REGVARS\n"); + if (reglap != 0) + fprintf(htable, "#define REGLAP\n"); + fprintf(ctable, "#include \"regvar.h\"\n"); + fprintf(ctable, "int nregvar[4] = { "); + for (i = 0; i < 4; i++) + { + fprintf(ctable, "%d, ", nregvar[i]); + if (nregvar[i] > maxregvars) maxregvars = nregvar[i]; } - fprintf(ctable,"};\n"); - for (i=0;i<4;i++) - if (nregvar[i]>0) - fprintf(ctable,"struct regassigned ratar%d[%d];\n", - i,nregvar[i]); - for (i=0;i<4;i++) if (nregvar[i]>0) { - fprintf(ctable,"int rvtar%d[] = {",i); - for (j=0;j0) - fprintf(ctable,"\trvtar%d,\n",i); + fprintf(ctable, "};\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(ctable, "struct regassigned ratar%d[%d];\n", i, nregvar[i]); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + { + fprintf(ctable, "int rvtar%d[] = {", i); + for (j = 0; j < nregvar[i]; j++) + fprintf(ctable, "%d,", rvnumbers[i][j]); + fprintf(ctable, "};\n"); + } + fprintf(ctable, "\nint *rvnumbers[] = {\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(ctable, "\trvtar%d,\n", i); else - fprintf(ctable,"\t0,\n"); - fprintf(ctable,"};\n\nstruct regassigned *regassigned[] = {\n"); - for (i=0;i<4;i++) - if (nregvar[i]>0) - fprintf(ctable,"\tratar%d,\n",i); + fprintf(ctable, "\t0,\n"); + fprintf(ctable, "};\n\nstruct regassigned *regassigned[] = {\n"); + for (i = 0; i < 4; i++) + if (nregvar[i] > 0) + fprintf(ctable, "\tratar%d,\n", i); else - fprintf(ctable,"\t0,\n"); - fprintf(ctable,"};\n"); + fprintf(ctable, "\t0,\n"); + fprintf(ctable, "};\n"); } -typeconv(n) { +int typeconv(int n) +{ - if (n>=0) return(2); - if (n== -1) return(1); - if (n== -2) return(3); - assert (n== -3); - return(0); + if (n >= 0) + return (2); + if (n == -1) + return (1); + if (n == -2) + return (3); + assert(n == -3); + return (0); } -outfmt(p) -register char *p; +static int is_ascii(int c) +{ + if ((c >= 0) && (c <= 127)) + return 1; + return 0; +} + +void outfmt(register char *p) { register int c; - fprintf(ctable,"\""); - while ((c= (*p++&0377))!=0) { - if (! isascii(c) || iscntrl(c)) { - fprintf(ctable,"\\%c%c%c", - ((c&~0300)>>6) + '0', ((c&070)>>3)+'0', - (c&07)+'0'); + fprintf(ctable, "\""); + while ((c = (*p++ & 0377)) != 0) + { + if (!is_ascii(c) || iscntrl(c)) + { + fprintf(ctable, "\\%c%c%c", ((c & ~0300) >> 6) + '0', + ((c & 070) >> 3) + '0', (c & 07) + '0'); } - else fprintf(ctable, "%c",c); + else + fprintf(ctable, "%c", c); } - fprintf(ctable,"\""); + fprintf(ctable, "\""); } -outtokens() { - register tokno,i; +void outtokens(void) +{ + register int tokno, i; register token_p tp; - fprintf(ctable,"tkdef_t tokens[] = {{0},\n"); - for (tokno=1;toknotk_size, tp->tk_cost.ct_space, tp->tk_cost.ct_time); - for(i=0;itk_att[i].ta_type)); - fprintf(ctable,"},%d},\t/* ",tp->tk_format); - if (tp->tk_format >= 0) outfmt(l_strings[tp->tk_format]); - else fprintf(ctable, "(no format)"); - fprintf(ctable," */\n"); + fprintf(ctable, "/* %3d */{%d,{%d,%d},{", tokno, tp->tk_size, + tp->tk_cost.ct_space, tp->tk_cost.ct_time); + for (i = 0; i < maxtokensize; i++) + fprintf(ctable, "%d,", typeconv(tp->tk_att[i].ta_type)); + fprintf(ctable, "},%d},\t/* ", tp->tk_format); + if (tp->tk_format >= 0) + outfmt(l_strings[tp->tk_format]); + else + fprintf(ctable, "(no format)"); + fprintf(ctable, " */\n"); } - fprintf(ctable,"{0}};\n\n"); + fprintf(ctable, "{0}};\n\n"); } -outenodes() { +void outenodes(void) +{ register node_p np; - extern node_t nodes[]; - extern int nnodes; - fprintf(ctable,"node_t enodes[] = {\n"); - for (np=nodes;np<&nodes[nnodes];np++) - fprintf(ctable,"{%d,%d,%d},\n", - np->ex_operator,np->ex_lnode,np->ex_rnode); - fprintf(ctable,"};\n\n"); + fprintf(ctable, "node_t enodes[] = {\n"); + for (np = nodes; np < &nodes[nnodes]; np++) + fprintf(ctable, "{%d,%d,%d},\n", np->ex_operator, np->ex_lnode, + np->ex_rnode); + fprintf(ctable, "};\n\n"); } -outstrings() { - register i; +void outstrings(void) +{ + register int i; +#if 0 register char *p; register int c; - extern char * filename; +#endif if (tabledebug) - fprintf(ctable,"char *tablename = \"%s\";\n",filename); - fprintf(ctable,"string codestrings[] = {\n"); - for(i=0;i>6) + '0', ((c&070)>>3)+'0', - (c&07)+'0'); + ((c&~0300)>>6) + '0', ((c&070)>>3)+'0', + (c&07)+'0'); } else fprintf(ctable, "%c",c); } fprintf(ctable,"\",\n"); #endif - fprintf(ctable,",\n"); + fprintf(ctable, ",\n"); } - fprintf(ctable,"};\n\n"); + fprintf(ctable, "};\n\n"); } extern set_t unstackset; -outsets() { - register i; +void outsets(void) +{ + register int i; register set_p sp; - fprintf(ctable,"set_t machsets[] = {\n"); - for (sp=l_sets;sp< &l_sets[nsets]; sp++) { - fprintf(ctable,"/* %3ld */ {%3d,{",(long)(sp-l_sets),sp->set_size); - for (i=0;iset_val[i]&0xFFFF); - fprintf(ctable,"}},\n"); + fprintf(ctable, "set_t machsets[] = {\n"); + for (sp = l_sets; sp < &l_sets[nsets]; sp++) + { + fprintf(ctable, "/* %3ld */ {%3d,{", (long) (sp - l_sets), + sp->set_size); + for (i = 0; i < setsize; i++) + fprintf(ctable, "0x%x,", sp->set_val[i] & 0xFFFF); + fprintf(ctable, "}},\n"); } - fprintf(ctable,"};\n\n"); + fprintf(ctable, "};\n\n"); fprintf(ctable, "set_t unstackset = { %3d,{\n", unstackset.set_size); - for (i = 0; iin_which); - for(i=0;i<=maxtokensize;i++) - fprintf(ctable,"%d,",ip->in_info[i]); - fprintf(ctable,"}},\n"); + fprintf(ctable, "inst_t tokeninstances[] = {\n"); + for (ip = l_instances; ip < &l_instances[ninstances]; ip++) + { + fprintf(ctable, "{ %d, {", ip->in_which); + for (i = 0; i <= maxtokensize; i++) + fprintf(ctable, "%d,", ip->in_info[i]); + fprintf(ctable, "}},\n"); } - fprintf(ctable,"};\n\n"); + fprintf(ctable, "};\n\n"); } -outmoves() { +void outmoves(void) +{ register move_p mp; - fprintf(ctable,"move_t moves[] = {\n"); - for (mp=l_moves; mp< &l_moves[nmoves]; mp++) - fprintf(ctable,"{%d,%d,%d,%d,%d},\n", - mp->m_set1, mp->m_expr1, - mp->m_set2, mp->m_expr2, - mp->m_cindex); - fprintf(ctable,"{-1}\n};\n\n"); + fprintf(ctable, "move_t moves[] = {\n"); + for (mp = l_moves; mp < &l_moves[nmoves]; mp++) + fprintf(ctable, "{%d,%d,%d,%d,%d},\n", mp->m_set1, mp->m_expr1, + mp->m_set2, mp->m_expr2, mp->m_cindex); + fprintf(ctable, "{-1}\n};\n\n"); } -outtests() { +void outtests(void) +{ register test_p tp; - fprintf(ctable,"test_t tests[] = {\n"); - for (tp=l_tests; tp< &l_tests[ntests]; tp++) - fprintf(ctable,"{%d,%d,%d},\n", - tp->t_set, tp->t_expr, - tp->t_cindex); - fprintf(ctable,"{-1}\n};\n\n"); + fprintf(ctable, "test_t tests[] = {\n"); + for (tp = l_tests; tp < &l_tests[ntests]; tp++) + fprintf(ctable, "{%d,%d,%d},\n", tp->t_set, tp->t_expr, tp->t_cindex); + fprintf(ctable, "{-1}\n};\n\n"); } -outstacks() { +void outstacks(void) +{ register c1_p cp; - fprintf(ctable,"c1_t c1coercs[] = {\n"); - for (cp=l_stacks; cp< &l_stacks[nstacks]; cp++) - fprintf(ctable,"{%d,%d,%d,%d},\n", - cp->c1_texpno, cp->c1_expr, - cp->c1_prop, cp->c1_codep); - fprintf(ctable,"{-1}\n};\n\n"); + fprintf(ctable, "c1_t c1coercs[] = {\n"); + for (cp = l_stacks; cp < &l_stacks[nstacks]; cp++) + fprintf(ctable, "{%d,%d,%d,%d},\n", cp->c1_texpno, cp->c1_expr, + cp->c1_prop, cp->c1_codep); + fprintf(ctable, "{-1}\n};\n\n"); } -outsplits() { +void outsplits(void) +{ register c2_p cp; - register i; + register int i; - fprintf(ctable,"c2_t c2coercs[] = {\n"); - for (cp=l_split; cp< &l_split[nsplit]; cp++) { - fprintf(ctable,"{%d,%d,%d,{", - cp->c2_texpno, cp->c2_expr, cp->c2_nsplit); - for (i=0;ic2_repl[i]); - fprintf(ctable,"},%d},\n",cp->c2_codep); + fprintf(ctable, "c2_t c2coercs[] = {\n"); + for (cp = l_split; cp < &l_split[nsplit]; cp++) + { + fprintf(ctable, "{%d,%d,%d,{", cp->c2_texpno, cp->c2_expr, + cp->c2_nsplit); + for (i = 0; i < maxsplit; i++) + fprintf(ctable, "%d,", cp->c2_repl[i]); + fprintf(ctable, "},%d},\n", cp->c2_codep); } - fprintf(ctable,"{-1}\n};\n\n"); + fprintf(ctable, "{-1}\n};\n\n"); } -outcoercs() { +void outcoercs(void) +{ register c3_p cp; - fprintf(ctable,"c3_t c3coercs[] = {\n"); - for (cp=l_coercs; cp< &l_coercs[ncoercs]; cp++) - fprintf(ctable,"{%d,%d,%d,%d,%d},\n", - cp->c3_texpno, cp->c3_expr, - cp->c3_prop, cp->c3_repl, cp->c3_codep); - fprintf(ctable,"{-1}\n};\n\n"); + fprintf(ctable, "c3_t c3coercs[] = {\n"); + for (cp = l_coercs; cp < &l_coercs[ncoercs]; cp++) + fprintf(ctable, "{%d,%d,%d,%d,%d},\n", cp->c3_texpno, cp->c3_expr, + cp->c3_prop, cp->c3_repl, cp->c3_codep); + fprintf(ctable, "{-1}\n};\n\n"); } -outproplists() { - register propno; - register regno; +void outproplists(void) +{ + register int propno; + register int regno; - for(propno=0;propnosy_value.syv_stringno]; - fprintf(htable,"#define WRD_FMT \"%s\"\n",wrdfmt); + fprintf(htable, "#define WRD_FMT \"%s\"\n", wrdfmt); } - cdef("MAXALLREG",maxallreg); - cdef("SETSIZE",setsize); - cdef("NREGS",nregs); - cdef("REGSETSIZE",SZOFSET(nregs)); - cdef("TOKENSIZE",maxtokensize); - cdef("MAXMEMBERS",maxmembers); - cdef("LONGESTPATTERN",maxempatlen); - cdef("MAXPATLEN",maxtokpatlen); - cdef("MAXREPLLEN",maxtokrepllen); - cdef("MAXEMREPLLEN",maxemrepllen); - cdef("MAXPROCARG",maxprocargs); - cdef("MAXRULE",maxrule<16 ? 16 : maxrule); - if (nsplit>0) { - cdef("MAXSPLIT",maxsplit); + cdef("MAXALLREG", maxallreg); + cdef("SETSIZE", setsize); + cdef("NREGS", nregs); + cdef("REGSETSIZE", SZOFSET(nregs)); + cdef("TOKENSIZE", maxtokensize); + cdef("MAXMEMBERS", maxmembers); + cdef("LONGESTPATTERN", maxempatlen); + cdef("MAXPATLEN", maxtokpatlen); + cdef("MAXREPLLEN", maxtokrepllen); + cdef("MAXEMREPLLEN", maxemrepllen); + cdef("MAXPROCARG", maxprocargs); + cdef("MAXRULE", maxrule < 16 ? 16 : maxrule); + if (nsplit > 0) + { + cdef("MAXSPLIT", maxsplit); } if (tabledebug) - cdef("TABLEDEBUG",1); + cdef("TABLEDEBUG", 1); if (use_tes) - cdef("USE_TES",1); + cdef("USE_TES", 1); } -outars() { - register i; - +void outars(void) +{ + register int i; + if (code_in_c) - fprintf(htable,"#define CODEINC 1\n"); - else { - fprintf(ctable,"char coderules[%d];\n",codeindex); - fprintf(ctable,"int ncodebytes=%d;\n",codeindex); + fprintf(htable, "#define CODEINC 1\n"); + else + { + fprintf(ctable, "char coderules[%d];\n", codeindex); + fprintf(ctable, "int ncodebytes=%d;\n", codeindex); } - fprintf(ctable,"char pattern[%d]={\n",npatbytes+1); - for(i=0;i<=npatbytes;i++) { - fprintf(ctable,"%d,%c",pattern[i]&BMASK,i%16==15 ? '\n' : ' '); + fprintf(ctable, "char pattern[%d]={\n", npatbytes + 1); + for (i = 0; i <= npatbytes; i++) + { + fprintf(ctable, "%d,%c", pattern[i] & BMASK, i % 16 == 15 ? '\n' : ' '); } - fprintf(ctable,"};\n\n"); - fprintf(ctable,"int pathash[256]={\n"); - for(i=0;i<256;i++) { - fprintf(ctable,"%d,%c",pathash[i]&0xFFFF,i%10==9 ? '\n' : ' '); + fprintf(ctable, "};\n\n"); + fprintf(ctable, "int pathash[256]={\n"); + for (i = 0; i < 256; i++) + { + fprintf(ctable, "%d,%c", pathash[i] & 0xFFFF, i % 10 == 9 ? '\n' : ' '); } - fprintf(ctable,"};\n"); + fprintf(ctable, "};\n"); } -finishio() { +void finishio(void) +{ extern int nregs; finishcode(); hashpatterns(); - setsize = SZOFSET(nregs+ntokens); + setsize = SZOFSET(nregs + ntokens); outdefs(); outincludes(); outregs(); @@ -663,7 +752,7 @@ finishio() { outmoves(); outtests(); outstacks(); - if (nsplit>0) + if (nsplit > 0) outsplits(); outcoercs(); outproplists(); @@ -673,31 +762,31 @@ finishio() { outars(); } -void -codecoco(cocono) { +void codecoco(int cocono) +{ - if (cocono== -1) + if (cocono == -1) return; code8(DO_SETCC); codeint(cocono); codenl(); } -dopattern(stackcoerc,kills,allocates,generates,yields,leaving) -varinfo *kills,*allocates,*generates,*yields,*leaving; +void dopattern(int stackcoerc, varinfo *kills, varinfo *allocates, + varinfo *generates, varinfo *yields, varinfo *leaving) { - register i; - int n,nops; - register struct varinfo *vp,*vivp; + register int i; + int n, nops; + register struct varinfo *vp, *vivp; register instr_p instp; - int al,deal; + int al, deal; int vil; - int cocono= -1; + int cocono = -1; cost_t totcost; int nremoves; int removelist[100]; static char tlab[] = "0:"; - extern int optexact,optstack,startline; + extern int optexact, optstack, startline; extern char *filename; extern int lineno; @@ -705,90 +794,114 @@ varinfo *kills,*allocates,*generates,*yields,*leaving; fprintf(code,"Code(%d) at \"%s\", line %d\n",stackcoerc,filename,lineno); #endif if (code_in_c) - fprintf(ctable,"\n/* \"%s\", line %d */ ",filename,lineno); - if (tabledebug) { + fprintf(ctable, "\n/* \"%s\", line %d */ ", filename, lineno); + if (tabledebug) + { code8(DO_DLINE); - codeint(startline); + codeint(startline); codenl(); - if (startlinemaxline) - maxline=startline; - BIS(lineset,startline); - } else { - static int beenhere=0; + if (startline < MAXSOURCELINES) + { + if (startline > maxline) + maxline = startline; + BIS(lineset, startline); + } + else + { + static int beenhere = 0; - if (!beenhere) { + if (!beenhere) + { beenhere++; error("Too many source lines for table debug"); } } } /* MATCH part */ - if (tokpatlen) { + if (tokpatlen) + { if (optexact) if (optstack) - code53(DO_XXMATCH,tokpatlen); + code53(DO_XXMATCH, tokpatlen); else - code53(DO_XMATCH,tokpatlen); + code53(DO_XMATCH, tokpatlen); else - code53(DO_MATCH,tokpatlen); - for (i=0;ivi_next) { - if (vp->vi_int[1] != 0) { - code53(DO_REMOVE,1); + for (vp = kills; vp != 0; vp = vp->vi_next) + { + if (vp->vi_int[1] != 0) + { + code53(DO_REMOVE, 1); codeint(vp->vi_int[0]); codeint(vp->vi_int[1]); - } else if (vp->vi_int[0] >= 0) { - code53(DO_REMOVE,0); + } + else if (vp->vi_int[0] >= 0) + { + code53(DO_REMOVE, 0); codeint(vp->vi_int[0]); - } else { + } + else + { code8(DO_KILLREG); codeint(-vp->vi_int[0] - 1); - } - codenl(); + } codenl(); } - nremoves=0; - for(vp=generates;vp!=0;vp=vp->vi_next) { + nremoves = 0; + for (vp = generates; vp != 0; vp = vp->vi_next) + { if (vp->vi_int[0] != INSREMOVE) continue; - for(i=0;ivi_int[1]==removelist[i]) + for (i = 0; i < nremoves; i++) + if (vp->vi_int[1] == removelist[i]) break; - if (i==nremoves) { - assert(nremoves<(sizeof(removelist)/sizeof(int))); + if (i == nremoves) + { + assert(nremoves < (sizeof(removelist) / sizeof(int))); removelist[nremoves++] = vp->vi_int[1]; } } - for(i=0;ivi_next) { - if (vp->vi_int[0] == -1) { /* Deallocate */ + deal = 0; + al = 0; + for (vp = allocates; vp != 0; vp = vp->vi_next) + { + if (vp->vi_int[0] == -1) + { /* Deallocate */ deal++; code8(DO_DEALLOCATE); codeint(vp->vi_int[1]); codenl(); - } else { - if (vp->vi_int[1]==0) { - code53(DO_ALLOCATE,0); + } + else + { + if (vp->vi_int[1] == 0) + { + code53(DO_ALLOCATE, 0); codeint(vp->vi_int[0]); codenl(); - } else { - code53(DO_ALLOCATE,1); + } + else + { + code53(DO_ALLOCATE, 1); codeint(vp->vi_int[0]); codeint(vp->vi_int[1]); codenl(); @@ -798,132 +911,143 @@ varinfo *kills,*allocates,*generates,*yields,*leaving; } if (deal) code8nl(DO_REALLOCATE); - if (al>maxallreg) - maxallreg=al; + if (al > maxallreg) + maxallreg = al; totcost.ct_space = 0; - totcost.ct_time = 0; - for(vp=generates;vp!=0;vp=vp->vi_next) { - n= vp->vi_int[0]; - switch(n) { - default: - assert(n>=0); - instp = &l_instr[n]; - nops=instp->i_nops; - code53(DO_INSTR,nops); - if (vp->vi_int[1]==0) { - codeint(instp->i_asname); - } else { - codeint(10000+vp->vi_int[1]); - } - vivp=vp->vi_vi; - for(i=0;ivi_int[0]); - vivp = vivp->vi_vi; - } - codenl(); - totcost.ct_space += instp->i_cost.ct_space; - totcost.ct_time += instp->i_cost.ct_time ; - break; - case INSREMOVE: - break; - case INSMOVE: - codecoco(cocono); - code8(DO_MOVE); - codeint(vp->vi_int[1]); - codeint(vp->vi_int[2]); - codenl(); - break; - case INSTEST: - codecoco(cocono); - code8(DO_TEST); - codeint(vp->vi_int[1]); - codenl(); - break; - case INSPRETURN: - code8(DO_PRETURN); - codenl(); - break; - case INSTLAB: - cocono = 0; - tlab[0] = vp->vi_int[1] + '0'; - code53(DO_INSTR,0); - codeint(strlookup(tlab)); - codenl(); - break; - case INSSETCC: - cocono=vp->vi_int[1]; - break; - case INSERASE: - code8(DO_ERASE); - codeint(vp->vi_int[1]); - codenl(); - break; - case INSLABDEF: - cocono = 0; - code8(DO_LABDEF); - codeint(vp->vi_int[1]); - codenl(); - break; + totcost.ct_time = 0; + for (vp = generates; vp != 0; vp = vp->vi_next) + { + n = vp->vi_int[0]; + switch (n) + { + default: + assert(n >= 0); + instp = &l_instr[n]; + nops = instp->i_nops; + code53(DO_INSTR, nops); + if (vp->vi_int[1] == 0) + { + codeint(instp->i_asname); + } + else + { + codeint(10000 + vp->vi_int[1]); + } + vivp = vp->vi_vi; + for (i = 0; i < nops; i++) + { + codeint(vivp->vi_int[0]); + vivp = vivp->vi_vi; + } + codenl(); + totcost.ct_space += instp->i_cost.ct_space; + totcost.ct_time += instp->i_cost.ct_time; + break; + case INSREMOVE: + break; + case INSMOVE: + codecoco(cocono); + code8(DO_MOVE); + codeint(vp->vi_int[1]); + codeint(vp->vi_int[2]); + codenl(); + break; + case INSTEST: + codecoco(cocono); + code8(DO_TEST); + codeint(vp->vi_int[1]); + codenl(); + break; + case INSPRETURN: + code8(DO_PRETURN); + codenl(); + break; + case INSTLAB: + cocono = 0; + tlab[0] = vp->vi_int[1] + '0'; + code53(DO_INSTR, 0); + codeint(strlookup(tlab)); + codenl(); + break; + case INSSETCC: + cocono = vp->vi_int[1]; + break; + case INSERASE: + code8(DO_ERASE); + codeint(vp->vi_int[1]); + codenl(); + break; + case INSLABDEF: + cocono = 0; + code8(DO_LABDEF); + codeint(vp->vi_int[1]); + codenl(); + break; } } codecoco(cocono); vil = vilength(yields); - if (vil!=0 || tokpatlen!=0 || allocates!=0) { - code53(DO_TOKREPLACE,vilength(yields)); - for(vp=yields;vp!=0;vp=vp->vi_next) { + if (vil != 0 || tokpatlen != 0 || allocates != 0) + { + code53(DO_TOKREPLACE, vilength(yields)); + for (vp = yields; vp != 0; vp = vp->vi_next) + { codeint(vp->vi_int[0]); - } - codenl(); + } codenl(); } - if (leaving!=0) { - code53(DO_EMREPLACE,vilength(leaving)); - while (leaving!=0) { + if (leaving != 0) + { + code53(DO_EMREPLACE, vilength(leaving)); + while (leaving != 0) + { codeint(leaving->vi_int[0]); codeint(leaving->vi_int[1]); leaving = leaving->vi_next; - } - codenl(); + } codenl(); } - if (totcost.ct_space!=0 || totcost.ct_time!=0) { + if (totcost.ct_space != 0 || totcost.ct_time != 0) + { code8(DO_COST); codeint(totcost.ct_space); codeint(totcost.ct_time); codenl(); } - if (empatlen==0 && !inproc) + if (empatlen == 0 && !inproc) code8nl(DO_RETURN); else code8nl(DO_NEXTEM); } -used(resource,use,max) char *resource; { +void used(char *resource, int use, int max) +{ - if (verbose || 4*use > 3*max) - fprintf(stderr,"%s %d(%d)\n",resource,use,max); + if (verbose || 4 * use > 3 * max) + fprintf(stderr, "%s %d(%d)\n", resource, use, max); } -statistics() { - extern int nnodes, maxempatlen,maxrule; +void statistics(void) +{ + extern int nnodes, maxempatlen, maxrule; - used("Registers",nregs,MAXREGS); - used("Properties",nprops,MAXPROPS); - used("Tokens",ntokens,MAXTOKENS); - used("Tokensize",maxtokensize,MAXATT); - used("Sets",nsets,MAXSETS); - used("Instructions",ninstr,MAXINSTR); - used("Strings",nstrings,MAXSTRINGS); - used("Exp-nodes",nnodes,MAXNODES); - used("EM-pat length",maxempatlen,EMPATMAX); - used("rules/EM-pattern",maxrule,MAXPATTERNS); - used("Allocates/rule",maxallreg,MAXALLREG); - used("Instances",ninstances,MAXINSTANCES); - used("Moves",nmoves,MAXMOVES); - used("Tests",ntests,MAXTESTS); - used("Stacks",nstacks,MAXSTACKS); - used("1->1 Coercions",ncoercs,MAXCOERCS); - used("Splitting coercions",nsplit,MAXSPLCOERC); - used("Register variables",maxregvars,MAXREGVAR); - used("Pat bytes",npatbytes+1,MAXPATBYTES); + used("Registers", nregs, MAXREGS); + used("Properties", nprops, MAXPROPS); + used("Tokens", ntokens, MAXTOKENS); + used("Tokensize", maxtokensize, MAXATT); + used("Sets", nsets, MAXSETS); + used("Instructions", ninstr, MAXINSTR); + used("Strings", nstrings, MAXSTRINGS); + used("Exp-nodes", nnodes, MAXNODES); + used("EM-pat length", maxempatlen, EMPATMAX); + used("rules/EM-pattern", maxrule, MAXPATTERNS); + used("Allocates/rule", maxallreg, MAXALLREG); + used("Instances", ninstances, MAXINSTANCES); + used("Moves", nmoves, MAXMOVES); + used("Tests", ntests, MAXTESTS); + used("Stacks", nstacks, MAXSTACKS); + used("1->1 Coercions", ncoercs, MAXCOERCS); + used("Splitting coercions", nsplit, MAXSPLCOERC); + used("Register variables", maxregvars, MAXREGVAR); + used("Pat bytes", npatbytes + 1, MAXPATBYTES); if (tabledebug) - used("Source lines",maxline,MAXSOURCELINES); + used("Source lines", maxline, MAXSOURCELINES); } diff --git a/util/ncgg/scan.l b/util/ncgg/scan.l index 46ea6d5e4..f57bc9e97 100644 --- a/util/ncgg/scan.l +++ b/util/ncgg/scan.l @@ -15,14 +15,14 @@ static char rcsid2[]= "$Id$"; #include "instruct.h" #include "expr.h" #include "extern.h" +#include "subr.h" #include #include #include "y.tab.h" extern int emhere; -char *mystrcpy(); -int myatoi(); +extern int mlookup(char *name); int lineno=1; extern char *filename; @@ -101,7 +101,7 @@ extern char *filename; %% int skipping=0; -yywrap() { +int yywrap(void) { if (skipping) fatal("EOF reached during error recovery"); @@ -113,8 +113,8 @@ yywrap() { #define yytext_ptr yytext -skipupto(tok,str) char *str; { - register i; +void skipupto(int tok,char *str) { + register int i; skipping=1; while (yylex()!=tok) diff --git a/util/ncgg/set.c b/util/ncgg/set.c index d2d9b0d8f..dd37590c2 100644 --- a/util/ncgg/set.c +++ b/util/ncgg/set.c @@ -3,7 +3,7 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ #ifndef NORCSID -static char rcsid[]= "$Id$"; +static char rcsid[] = "$Id$"; #endif #include "param.h" @@ -12,143 +12,161 @@ static char rcsid[]= "$Id$"; #include "token.h" #include "lookup.h" #include "reg.h" +#include "subr.h" #include #include "extern.h" extern set_t l_sets[]; - -setlookup(s) set_t s; { - register set_p p; - register i; - int setno; - - for(p=l_sets;p<&l_sets[nsets];p++) { - if (p->set_size != s.set_size) - continue; - for (i=0;iset_val[i] != s.set_val[i]) - goto cont; - return(p-l_sets); - cont:; - } - setno = NEXT(nsets,MAXSETS,"Sets"); - l_sets[setno] = s; - return(setno); -} - -make_std_sets() { - set_t s; - register i; - - for(i=0;iset_size != s.set_size) + continue; + for (i = 0; i < SETSIZE; i++) + if (p->set_val[i] != s.set_val[i]) + goto cont; + return (p - l_sets); + cont: ; + } + setno = NEXT(nsets, MAXSETS, "Sets"); + l_sets[setno] = s; + return (setno); +} + +void make_std_sets(void) +{ + set_t s; + register int i; + + for (i = 0; i < SETSIZE; i++) + s.set_val[i] = 0; + for (i = 0; i < nregs + ntokens; i++) + BIS(s.set_val, i); + s.set_size = 0; + allsetno = setlookup(s); + n_set("ALL", allsetno); +} + +set_t ident_to_set(char *name) +{ register symbol *sy_p; - register i; + register int i; register struct propinfo *pp; int bitno; set_t result; - sy_p = lookup(name,symany,mustexist); - switch(sy_p->sy_type) { - default: - error("%s is wrong kind of symbol",name); - return(emptyset); - case symprop: - pp = &l_props[sy_p->sy_value.syv_propno]; - result.set_size = pp->pr_size; - for (i=0;ipr_regset[i]; - BIS(result.set_val,0); - for (;isy_value.syv_tokno+nregs; - for (i=0;isy_value.syv_tokno]->tk_size; - break; - case symset: - return(l_sets[sy_p->sy_value.syv_setno]); + sy_p = lookup(name, symany, mustexist); + switch (sy_p->sy_type) + { + default: + error("%s is wrong kind of symbol", name); + return (emptyset); + case symprop: + pp = &l_props[sy_p->sy_value.syv_propno]; + result.set_size = pp->pr_size; + for (i = 0; i < SZOFSET(MAXREGS); i++) + result.set_val[i] = pp->pr_regset[i]; + BIS(result.set_val, 0); + for (; i < SETSIZE; i++) + result.set_val[i] = 0; + break; + case symtok: + bitno = sy_p->sy_value.syv_tokno + nregs; + for (i = 0; i < SETSIZE; i++) + result.set_val[i] = 0; + BIS(result.set_val, bitno); + result.set_size = l_tokens[sy_p->sy_value.syv_tokno]->tk_size; + break; + case symset: + return (l_sets[sy_p->sy_value.syv_setno]); } - return(result); + return (result); } -static void -checksize(s) - register set_p s; +static void checksize(register set_p s) { register int i; register int size = -1; s->set_size = 0; - for (i = 1; i <= nregs; i++) { - if (BIT(s->set_val, i)) { + for (i = 1; i <= nregs; i++) + { + if (BIT(s->set_val, i)) + { register int sz = l_regs[i].ri_size; - if (size == -1) size = sz; - else if (size != sz) return; + if (size == -1) + size = sz; + else if (size != sz) + return; } } - for (i = 1; i <= ntokens; i++) { - if (BIT(s->set_val, i+nregs)) { + for (i = 1; i <= ntokens; i++) + { + if (BIT(s->set_val, i + nregs)) + { register int sz = l_tokens[i]->tk_size; - if (size == -1) size = sz; - else if (size != sz) return; + if (size == -1) + size = sz; + else if (size != sz) + return; } } - if (size != -1) s->set_size = size; + if (size != -1) + s->set_size = size; } -set_t setproduct(s1,s2) set_t s1,s2; { +set_t setproduct(set_t s1, set_t s2) +{ set_t result; - register i; + register int i; - for(i=0;i #define BIS(sp,n) (sp)[(n)>>4] |= 1<<((n)&0xF) #define BIC(sp,n) (sp)[(n)>>4] &= ~(1<<((n)&0xF)) #define BIT(sp,n) (((sp)[(n)>>4]&(1<<((n)&0xF)))!=0) + +int setlookup(set_t s); +void make_std_sets(void); +set_t ident_to_set(char *name); +set_t setproduct(set_t s1, set_t s2); +set_t setsum(set_t s1, set_t s2); +set_t setdiff(set_t s1, set_t s2); + + +#endif /* SET_H_ */ diff --git a/util/ncgg/strlookup.c b/util/ncgg/strlookup.c index 708dd9b41..52eca7e74 100644 --- a/util/ncgg/strlookup.c +++ b/util/ncgg/strlookup.c @@ -3,24 +3,25 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ #ifndef NORCSID -static char rcsid[]= "$Id$"; +static char rcsid[] = "$Id$"; #endif #include #include "param.h" +#include "subr.h" #include "extern.h" -int nstrings=0; +int nstrings = 0; char *l_strings[MAXSTRINGS]; -strlookup(str) char *str; { - register i; - extern char *mystrcpy(); +int strlookup(char *str) +{ + register int i; - for(i=0;i @@ -20,77 +20,86 @@ static char rcsid[]= "$Id$"; #include "regvar.h" #include #include +#include "subr.h" +#include "hall.h" #include "extern.h" -n_proc(name) char *name; { - register symbol *sy_p; - extern int npatbytes; +extern int npatbytes; +extern set_t l_sets[]; - sy_p = lookup(name,symproc,newsymbol); + +void n_proc(char *name) +{ + register symbol *sy_p; + + sy_p = lookup(name, symproc, newsymbol); sy_p->sy_value.syv_procoff = npatbytes + 1; } -struct varinfo * -make_erase(name) char *name; { - expr_t e,ident_expr(); +struct varinfo * make_erase(char *name) +{ + expr_t e; struct varinfo *result; e = ident_expr(name); if (e.ex_typ != TYPREG) error("Register name required here"); - NEW(result,struct varinfo); + NEW(result, struct varinfo); result->vi_next = VI_NULL; result->vi_int[0] = e.ex_index; - return(result); + return (result); } -n_instr(name,asname,oplist,eraselist,cost) -char *name,*asname; -operand *oplist; -struct varinfo *eraselist,*cost; +void n_instr(char *name, char *asname, operand *oplist, struct varinfo *eraselist, + struct varinfo *cost) { - register instrno; - register cc_count; + register int instrno; + register int cc_count; register instr_p ip; - instrno = NEXT(ninstr,MAXINSTR,"Instructions"); + instrno = NEXT(ninstr, MAXINSTR, "Instructions"); ip = &l_instr[instrno]; ip->i_name = name; - ip->i_asname = strlookup(asname!=0 ? asname : name); + ip->i_asname = strlookup(asname != 0 ? asname : name); ip->i_nops = 0; ip->i_oplist = oplist; ip->i_erases = eraselist; - if (cost==0) { + if (cost == 0) + { ip->i_cost.ct_space = 0; ip->i_cost.ct_time = 0; - } else { + } + else + { ip->i_cost.ct_space = cost->vi_int[0]; ip->i_cost.ct_space = cost->vi_int[1]; } - for (cc_count=0; oplist!=0; oplist = oplist->o_next) { + for (cc_count = 0; oplist != 0; oplist = oplist->o_next) + { ip->i_nops++; - if(oplist->o_adorn&AD_CC) + if (oplist->o_adorn & AD_CC) cc_count++; } - while (eraselist!=VI_NULL) { + while (eraselist != VI_NULL ) + { if (eraselist->vi_int[0] == -1 && cc_count) error("Instruction can't both set and break the condition codes"); - eraselist=eraselist->vi_next; + eraselist = eraselist->vi_next; } - if (cc_count>1) + if (cc_count > 1) error("No instruction can set condition codes more than once"); } -n_set(name,number) char *name; { +void n_set(char *name, int number) +{ register symbol *sy_p; - sy_p = lookup(name,symset,newsymbol); + sy_p = lookup(name, symset, newsymbol); sy_p->sy_value.syv_setno = number; } -n_tok(name,atts,size,cost,format) -char *name; -struct varinfo *atts,*cost,*format; +void n_tok(char *name, struct varinfo *atts, int size, + struct varinfo *cost, struct varinfo *format) { register symbol *sy_p; register token_p tp; @@ -98,146 +107,164 @@ struct varinfo *atts,*cost,*format; int i; int tokno; int thistokensize; - char formstr[50],smallstr[2]; + char formstr[50], smallstr[2]; - sy_p = lookup(name,symtok,newsymbol); - NEW(tp,token_t); - tokno = NEXT(ntokens,MAXTOKENS,"Tokens"); + sy_p = lookup(name, symtok, newsymbol); + NEW(tp, token_t); + tokno = NEXT(ntokens, MAXTOKENS, "Tokens"); sy_p->sy_value.syv_tokno = tokno; l_tokens[tokno] = tp; tp->tk_name = sy_p->sy_name; tp->tk_size = size; - if (cost != 0) { + if (cost != 0) + { tp->tk_cost.ct_space = cost->vi_int[0]; - tp->tk_cost.ct_time = cost->vi_int[1]; - } else { - tp->tk_cost.ct_space = 0; - tp->tk_cost.ct_time = 0; + tp->tk_cost.ct_time = cost->vi_int[1]; } - for(i=0,vip=atts;ivi_next) { + else + { + tp->tk_cost.ct_space = 0; + tp->tk_cost.ct_time = 0; + } + for (i = 0, vip = atts; i < MAXATT && vip != 0; i++, vip = vip->vi_next) + { tp->tk_att[i].ta_type = vip->vi_int[0]; tp->tk_att[i].ta_name = vip->vi_str[0]; - vip->vi_str[0]=0; + vip->vi_str[0] = 0; } - thistokensize=i; - if (i>maxtokensize) - maxtokensize=i; - if (vip!=0) - error("More then %d attributes, rest discarded",MAXATT); - for(;itk_att[i].ta_type= -3; - if (format!=0) { + thistokensize = i; + if (i > maxtokensize) + maxtokensize = i; + if (vip != 0) + error("More then %d attributes, rest discarded", MAXATT); + for (; i < MAXATT; i++) + tp->tk_att[i].ta_type = -3; + if (format != 0) + { formstr[0] = 0; - for (vip=format;vip!=0;vip=vip->vi_next) { - if (vip->vi_int[0]==0) - strcat(formstr,vip->vi_str[0]); - else { - for(i=0;ivi_str[0],tp->tk_att[i].ta_name)==0) { - smallstr[0] = i+1; + for (vip = format; vip != 0; vip = vip->vi_next) + { + if (vip->vi_int[0] == 0) + strcat(formstr, vip->vi_str[0]); + else + { + for (i = 0; i < thistokensize; i++) + { + if (strcmp(vip->vi_str[0], tp->tk_att[i].ta_name) == 0) + { + smallstr[0] = i + 1; smallstr[1] = 0; - strcat(formstr,smallstr); + strcat(formstr, smallstr); break; } } - if (i==thistokensize) - error("%s not a known attribute", - vip->vi_str[0]); + if (i == thistokensize) + error("%s not a known attribute", vip->vi_str[0]); } } tp->tk_format = strlookup(formstr); - } else + } + else tp->tk_format = -1; } -checkprintformat(n) { +void checkprintformat(int n) +{ register short *s; - register i; - extern set_t l_sets[]; - - s= l_sets[n].set_val; - for(i=nregs;itk_format<0) + register int i; + + s = l_sets[n].set_val; + for (i = nregs; i < nregs + ntokens; i++) + if (BIT(s,i) && l_tokens[i - nregs]->tk_format < 0) error("Token %s in set does not have printformat", - l_tokens[i-nregs]->tk_name); + l_tokens[i - nregs]->tk_name); } -n_prop(name,size) char *name; int size; { +void n_prop(char *name, int size) +{ int propno; register symbol *sp; - propno = NEXT(nprops,MAXPROPS,"Properties"); - sp = lookup(name,symprop,newsymbol); + propno = NEXT(nprops, MAXPROPS, "Properties"); + sp = lookup(name, symprop, newsymbol); sp->sy_value.syv_propno = propno; - if (size <= 0) { + if (size <= 0) + { error("Size of property must be >0"); size = wordsize; } l_props[propno].pr_size = size; } -void -prophall(n) { - register i; +void prophall(int n) +{ + register int i; short hallset[SETSIZE]; - - if (n < 0) return; - for(i=0;isy_value.syv_regno = regno = NEXT(nregs,MAXREGS,"Number of registers"); + sy_p = lookup(name, symreg, newsymbol); + sy_p->sy_value.syv_regno = regno = NEXT(nregs, MAXREGS, + "Number of registers"); ri_p = &l_regs[regno]; ri_p->ri_name = mystrcpy(name); - ri_p->ri_repr = printstring!=0 ? mystrcpy(printstring) : ri_p->ri_name; + ri_p->ri_repr = printstring != 0 ? mystrcpy(printstring) : ri_p->ri_name; ri_p->ri_memb[0] = member1; ri_p->ri_memb[1] = member2; - if (nmemb>maxmembers) - maxmembers=nmemb; - return(regno); + if (nmemb > maxmembers) + maxmembers = nmemb; + return (regno); } -make_const() { +void make_const(void) +{ wordsize = cmustbeset("EM_WSIZE"); pointersize = cmustbeset("EM_PSIZE"); } -cmustbeset(ident) char *ident; { +int cmustbeset(char *ident) +{ - return(lookup(ident,symconst,mustexist)->sy_value.syv_cstval); + return (lookup(ident, symconst, mustexist)->sy_value.syv_cstval); } -n_const(ident,val) char *ident; { +void n_const(char *ident, int val) +{ register symbol *sy_p; - sy_p = lookup(ident,symconst,newsymbol); + sy_p = lookup(ident, symconst, newsymbol); sy_p->sy_value.syv_cstval = val; } -n_sconst(ident,val) char *ident,*val; { +void n_sconst(char *ident, char *val) +{ register symbol *sy_p; - sy_p = lookup(ident,symsconst,newsymbol); + sy_p = lookup(ident, symsconst, newsymbol); sy_p->sy_value.syv_stringno = strlookup(val); } -static void -add_regvar(int rvnum, reginfo *regp, int rv) +static void add_regvar(int rvnum, reginfo *regp, int rv) { int overlap, wrong; overlap = wrong = 0; - if (regp->ri_memb[0]!=0) { + if (regp->ri_memb[0] != 0) + { /* reglap: float may overlap with one subregister */ - if (rv==reg_float && regp->ri_memb[1]==0) + if (rv == reg_float && regp->ri_memb[1] == 0) overlap = 1; else wrong = 1; @@ -248,28 +275,34 @@ add_regvar(int rvnum, reginfo *regp, int rv) rvused |= ANY_REGVAR; if (regp->ri_size == wordsize) rvused |= SL_REGVAR; - else if (regp->ri_size == 2*wordsize) + else if (regp->ri_size == 2 * wordsize) rvused |= DL_REGVAR; wrong = 0; - if (overlap) { + if (overlap) + { /* reglap = size of overlap float */ - if (reglap==0) { + if (reglap == 0) + { reglap = regp->ri_size; if (reglap == rvsize[reg_float]) error("Two sizes of reg_float can't be same size"); - } else if (reglap!=regp->ri_size) + } + else if (reglap != regp->ri_size) wrong = 1; - } else { - if (nregvar[rv]==0) + } + else + { + if (nregvar[rv] == 0) rvsize[rv] = regp->ri_size; - else if (rvsize[rv]!=regp->ri_size) + else if (rvsize[rv] != regp->ri_size) wrong = 1; } if (wrong) error("All register variables of one type must have the same size"); - if (overlap) { + if (overlap) + { reginfo *member_p = &l_regs[regp->ri_memb[0]]; int i; @@ -278,54 +311,59 @@ add_regvar(int rvnum, reginfo *regp, int rv) * Add reg_p in its place. */ wrong = 1; - for (i = 0; i < nregvar[rv]; i++) { - if (rvnumbers[rv][i] == regp->ri_memb[0]) { + for (i = 0; i < nregvar[rv]; i++) + { + if (rvnumbers[rv][i] == regp->ri_memb[0]) + { rvnumbers[rv][i] = rvnum; wrong = 0; break; } } if (wrong) - error("Register variable %s can't overlap %s", - regp->ri_name, member_p->ri_name); - } else { - NEXT(nregvar[rv],MAXREGVAR,"Register variable"); - rvnumbers[rv][nregvar[rv]-1] = rvnum; + error("Register variable %s can't overlap %s", regp->ri_name, + member_p->ri_name); + } + else + { + NEXT(nregvar[rv], MAXREGVAR, "Register variable"); + rvnumbers[rv][nregvar[rv] - 1] = rvnum; } } -void -regline(rl,pl,rv) varinfo *rl,*pl; { - register varinfo *rrl,*rpl; +void regline(varinfo *rl, varinfo *pl, int rv) +{ + register varinfo *rrl, *rpl; register short *sp; register reginfo *regp; int thissize; int propno; - for(rrl=rl;rrl!=0;rrl=rrl->vi_next) { + for (rrl = rl; rrl != 0; rrl = rrl->vi_next) + { regp = &l_regs[rrl->vi_int[0]]; thissize = 0; - for(rpl=pl;rpl!=0;rpl=rpl->vi_next) { + for (rpl = pl; rpl != 0; rpl = rpl->vi_next) + { propno = rpl->vi_int[0]; - sp= l_props[propno].pr_regset; - BIS(sp,rrl->vi_int[0]); - if (thissize==0) + sp = l_props[propno].pr_regset; + BIS(sp, rrl->vi_int[0]); + if (thissize == 0) thissize = l_props[propno].pr_size; - else if (thissize!=-1 && thissize!=l_props[propno].pr_size) - error("Register %s has no clear size", - regp->ri_name); + else if (thissize != -1 && thissize != l_props[propno].pr_size) + error("Register %s has no clear size", regp->ri_name); } regp->ri_size = thissize; regp->ri_class = regclass; regp->ri_rregvar = rv; - if (rv>=0) + if (rv >= 0) add_regvar(rrl->vi_int[0], regp, rv); } regclass++; } -void -check_reglap() { +void check_reglap(void) +{ reginfo *regp; int i; @@ -333,129 +371,147 @@ check_reglap() { return; /* reglap: Check that every reg_float has size == reglap. */ - for (i = 0; i < nregvar[reg_float]; i++) { + for (i = 0; i < nregvar[reg_float]; i++) + { regp = &l_regs[rvnumbers[reg_float][i]]; if (regp->ri_size != reglap) - error("Missing reg_float of size %d to contain %s", - reglap, regp->ri_name); + error("Missing reg_float of size %d to contain %s", reglap, + regp->ri_name); } } -setallreg(vi) struct varinfo *vi; { +void setallreg(struct varinfo *vi) +{ - nallreg=0; - for(;vi!=0;vi=vi->vi_next) { - if (vi->vi_int[0]<0) + nallreg = 0; + for (; vi != 0; vi = vi->vi_next) + { + if (vi->vi_int[0] < 0) continue; allreg[nallreg++] = vi->vi_int[0]; } } -void -freevi(vip) register struct varinfo *vip; { - register i; +void freevi(register struct varinfo *vip) +{ + register int i; - if (vip==0) + if (vip == 0) return; freevi(vip->vi_next); freevi(vip->vi_vi); - for (i=0;ivi_str[i]); free(vip); } -int myatoi(s) register char *s; { - register int base=10; - register sum=0; +int myatoi(register char *s) +{ + register int base = 10; + register int sum = 0; - if (*s=='0') { + if (*s == '0') + { base = 8; s++; - if (*s=='x') { - base=16; + if (*s == 'x') + { + base = 16; s++; } } - for (;;) { - switch (*s) { - default: return(sum); - case '8': - case '9': - if (base==8) error("Bad digit in octal number"); - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - sum = sum*base + *s++ - '0'; - break; - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - if (base!=16) error("Hexletter in number not expected"); - sum = sum*base + 10 + *s++ - 'a'; - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - if (base!=16) error("Hexletter in number not expected"); - sum = sum*base + 10 + *s++ - 'A'; - break; + for (;;) + { + switch (*s) + { + default: + return (sum); + case '8': + case '9': + if (base == 8) + error("Bad digit in octal number"); + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + sum = sum * base + *s++ - '0'; + break; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + if (base != 16) + error("Hexletter in number not expected"); + sum = sum * base + 10 + *s++ - 'a'; + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + if (base != 16) + error("Hexletter in number not expected"); + sum = sum * base + 10 + *s++ - 'A'; + break; } } } -char *mystrcpy(s) char *s; { +char *mystrcpy(char *s) +{ register char *p; - char *myalloc(); - p=myalloc(strlen(s)+1); - strcpy(p,s); - return(p); + p = myalloc(strlen(s) + 1); + strcpy(p, s); + return (p); } -char *myalloc(n) register n; { - register char *p,*result; +char *myalloc(register int n) +{ + register char *p, *result; - result=p=malloc(n); - if (p== (char *) 0) + result = p = malloc(n); + if (p == (char *) 0) fatal("Out of memory"); - do *p++=0; while (--n); - return(result); + do + *p++ = 0; + while (--n); + return (result); } -chkincl(value,lwb,upb) { +int chkincl(int value, int lwb, int upb) +{ - if (valueupb) - error("Number %d should have been between %d and %d", - value,lwb,upb); - return(value); + if (value < lwb || value > upb) + error("Number %d should have been between %d and %d", value, lwb, upb); + return (value); } -subset(sp1,sp2,setsize) short *sp1,*sp2; { - register i; +int subset(short *sp1, short *sp2, int setsize) +{ + register int i; - for(i=0;ivi_next; + while (vip != 0) + { + vip = vip->vi_next; l++; } - return(l); + return (l); } diff --git a/util/ncgg/subr.h b/util/ncgg/subr.h new file mode 100644 index 000000000..dd5fa3ac2 --- /dev/null +++ b/util/ncgg/subr.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-05-02 + * + */ +#ifndef SUBR_H_ +#define SUBR_H_ + +#include "instruct.h" + +struct varinfo; + + +void n_proc(char *name); +struct varinfo * make_erase(char *name); +void n_instr(char *name, char *asname, operand *oplist, struct varinfo *eraselist, + struct varinfo *cost); +void n_set(char *name, int number); +void n_tok(char *name, struct varinfo *atts, int size, + struct varinfo *cost, struct varinfo *format); +void checkprintformat(int n); +void n_prop(char *name, int size); +void prophall(int n); +int n_reg(char *name, char *printstring, int nmemb, int member1, int member2); +void make_const(void); +int cmustbeset(char *ident); +void n_const(char *ident, int val); +void n_sconst(char *ident, char *val); +void regline(struct varinfo *rl, struct varinfo *pl, int rv); +void check_reglap(void); +void setallreg(struct varinfo *vi); +void freevi(register struct varinfo *vip); +int myatoi(register char *s); +char *mystrcpy(char *s); +char *myalloc(register int n); +int chkincl(int value, int lwb, int upb); +int subset(short *sp1, short *sp2, int setsize); +int vilength(register struct varinfo *vip); + +#endif /* SUBR_H_ */ From 21e15965cce430e194da4089e7c42b5abf7d6574 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:17:40 +0800 Subject: [PATCH 67/84] ANSI C conversion and add procedure declarations. --- util/opt/alloc.c | 266 ++++++---- util/opt/alloc.h | 16 +- util/opt/backward.c | 285 +++++----- util/opt/build.lua | 6 +- util/opt/cleanup.c | 69 ++- util/opt/em_opt.6 | 2 +- util/opt/ext.h | 2 +- util/opt/flow.c | 138 ++--- util/opt/getline.c | 867 ++++++++++++++++-------------- util/opt/getline.h | 17 + util/opt/lookup.c | 82 +-- util/opt/lookup.h | 16 +- util/opt/main.c | 127 +++-- util/opt/mktab.y | 89 ++-- util/opt/patterns | 2 +- util/opt/peephole.c | 1217 ++++++++++++++++++++++++------------------- util/opt/process.c | 277 +++++----- util/opt/putline.c | 508 +++++++++--------- util/opt/putline.h | 25 + util/opt/reg.c | 114 ++-- util/opt/reg.h | 17 + util/opt/scan.l | 6 +- util/opt/special.c | 15 +- util/opt/tes.c | 214 +++++--- util/opt/tes.h | 11 +- util/opt/types.h | 7 +- util/opt/util.c | 51 +- util/opt/util.h | 15 + util/opt/var.c | 19 +- 29 files changed, 2510 insertions(+), 1970 deletions(-) create mode 100644 util/opt/getline.h create mode 100644 util/opt/putline.h create mode 100644 util/opt/reg.h create mode 100644 util/opt/util.h diff --git a/util/opt/alloc.c b/util/opt/alloc.c index cc6dc6607..9bdb77caa 100644 --- a/util/opt/alloc.c +++ b/util/opt/alloc.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include #include @@ -9,20 +11,14 @@ static char rcsid[] = "$Id$"; #include "types.h" #include "tes.h" #include "alloc.h" +#include "util.h" #include "line.h" #include "lookup.h" #include "proinf.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ - #ifdef USEMALLOC -short * myalloc(); +short *myalloc(register unsigned int); #define newcore(size) myalloc(size) #define oldcore(p,size) free(p) @@ -94,101 +90,111 @@ int asizetab[] = { * PART 1 */ -line_p newline(optyp) int optyp; { +line_p newline(int optyp) +{ register line_p lnp; - register kind=optyp; + register int kind = optyp; - if (kind>OPMINI) + if (kind > OPMINI) kind = OPMINI; lnp = (line_p) newcore(lsizetab[kind]); lnp->l_optyp = optyp; - return(lnp); + return (lnp); } -oldline(lnp) register line_p lnp; { - register kind=lnp->l_optyp&BMASK; +void oldline(register line_p lnp) +{ + register int kind = lnp->l_optyp & BMASK; - if (kind>OPMINI) + if (kind > OPMINI) kind = OPMINI; if (kind == OPLIST) oldargs(lnp->l_a.la_arg); - oldcore((short *) lnp,lsizetab[kind]); + oldcore((short * ) lnp, lsizetab[kind]); } -arg_p newarg(kind) int kind; { +arg_p newarg(int kind) +{ register arg_p ap; ap = (arg_p) newcore(asizetab[kind]); ap->a_typ = kind; - return(ap); + return (ap); } -oldargs(ap) register arg_p ap; { - register arg_p next; +void oldargs(register arg_p ap) +{ + register arg_p next; - while (ap != (arg_p) 0) { + while (ap != (arg_p) 0) + { next = ap->a_next; - switch(ap->a_typ) { - case ARGSTR: - oldargb(ap->a_a.a_string.ab_next); - break; - case ARGICN: - case ARGUCN: - case ARGFCN: - oldargb(ap->a_a.a_con.ac_con.ab_next); - break; + switch (ap->a_typ) + { + case ARGSTR: + oldargb(ap->a_a.a_string.ab_next); + break; + case ARGICN: + case ARGUCN: + case ARGFCN: + oldargb(ap->a_a.a_con.ac_con.ab_next); + break; } - oldcore((short *) ap,asizetab[ap->a_typ]); + oldcore((short * ) ap, asizetab[ap->a_typ]); ap = next; } } -oldargb(abp) register argb_p abp; { +void oldargb(register argb_p abp) +{ register argb_p next; - while (abp != (argb_p) 0) { + while (abp != (argb_p) 0) + { next = abp->ab_next; - oldcore((short *) abp,sizeof (argb_t)); + oldcore((short * ) abp, sizeof (argb_t)); abp = next; } } -reg_p newreg() { - - return((reg_p) newcore(sizeof(reg_t))); +reg_p newreg(void) +{ + return ((reg_p) newcore(sizeof(reg_t))); } -oldreg(rp) reg_p rp; { +void oldreg(reg_p rp) +{ - oldcore((short *) rp,sizeof(reg_t)); + oldcore((short * ) rp, sizeof(reg_t)); } -num_p newnum() { - - return((num_p) newcore(sizeof(num_t))); +num_p newnum(void) +{ + return ((num_p) newcore(sizeof(num_t))); } -oldnum(lp) num_p lp; { - - oldcore((short *) lp,sizeof(num_t)); +void oldnum(num_p lp) +{ + oldcore((short * ) lp, sizeof(num_t)); } -offset *newrom() { - - return((offset *) newcore(MAXROM*sizeof(offset))); +offset *newrom(void) +{ + return ((offset *) newcore(MAXROM*sizeof(offset))); } -sym_p newsym(len) int len; { +sym_p newsym(int len) +{ /* * sym_t includes a 2 character s_name at the end * extend this structure with len-2 characters */ - return((sym_p) newcore(sizeof(sym_t) - 2 + len)); + return ((sym_p) newcore(sizeof(sym_t) - 2 + len)); } -argb_p newargb() { - - return((argb_p) newcore(sizeof(argb_t))); +argb_p newargb(void) +{ + return ((argb_p) newcore(sizeof(argb_t))); } #ifndef USEMALLOC @@ -201,68 +207,80 @@ argb_p newargb() { short *freelist[MAXSHORT]; -typedef struct coreblock { +typedef struct coreblock +{ struct coreblock *co_next; short co_size; -} core_t,*core_p; +}core_t,*core_p; #define SINC (sizeof(core_t)/sizeof(short)) #ifdef COREDEBUG -coreverbose() { +coreverbose() +{ register size; register short *p; register sum; sum = 0; for(size=1;sizeco_next; tp->co_size = size; - if (corelist==0 || tpco_next = corelist; corelist = tp; - } else { + } + else + { for(cl=corelist;cl->co_next != 0 && tp>cl->co_next; - cl = cl->co_next) - ; + cl = cl->co_next) + ; tp->co_next = cl->co_next; cl->co_next = tp; } } } - while (corelist != 0) { + while (corelist != 0) + { while ((short *) corelist->co_next == - (short *) corelist + corelist->co_size) { + (short *) corelist + corelist->co_size) + { corelist->co_size += corelist->co_next->co_size; - corelist->co_next = corelist->co_next->co_next; + corelist->co_next = corelist->co_next->co_next; } assert(corelist->co_next==0 || - (short *) corelist->co_next > - (short *) corelist + corelist->co_size); - while (corelist->co_size >= MAXSHORT+SINC) { + (short *) corelist->co_next > + (short *) corelist + corelist->co_size); + while (corelist->co_size >= MAXSHORT+SINC) + { oldcore((short *) corelist + corelist->co_size-(MAXSHORT-1), - sizeof(short)*(MAXSHORT-1)); + sizeof(short)*(MAXSHORT-1)); corelist->co_size -= MAXSHORT; } - if (corelist->co_size >= MAXSHORT) { + if (corelist->co_size >= MAXSHORT) + { oldcore((short *) corelist + corelist->co_size-SINC, - sizeof(short)*SINC); + sizeof(short)*SINC); corelist->co_size -= SINC; } cl = corelist->co_next; @@ -271,7 +289,8 @@ compactcore() { } } -short *grabcore(size) int size; { +short *grabcore(size) int size; +{ register short *p; register trysize; @@ -283,9 +302,11 @@ short *grabcore(size) int size; { */ assert(size<2*MAXSHORT); - for(trysize=2*MAXSHORT-2; trysize>size; trysize -= 2) { + for(trysize=2*MAXSHORT-2; trysize>size; trysize -= 2) + { p = freelist[trysize/sizeof(short)]; - if ( p != (short *) 0) { + if ( p != (short *) 0) + { freelist[trysize/sizeof(short)] = *(short **) p; oldcore(p+size/sizeof(short),trysize-size); return(p); @@ -299,13 +320,16 @@ short *grabcore(size) int size; { */ compactcore(); - if ((p=freelist[size/sizeof(short)]) != 0) { + if ((p=freelist[size/sizeof(short)]) != 0) + { freelist[size/sizeof(short)] = * (short **) p; return(p); } - for(trysize=2*MAXSHORT-2; trysize>size; trysize -= 2) { + for(trysize=2*MAXSHORT-2; trysize>size; trysize -= 2) + { p = freelist[trysize/sizeof(short)]; - if ( p != (short *) 0) { + if ( p != (short *) 0) + { freelist[trysize/sizeof(short)] = *(short **) p; oldcore(p+size/sizeof(short),trysize-size); return(p); @@ -320,26 +344,30 @@ short *grabcore(size) int size; { } #endif /* SEPID */ -short *newcore(size) int size; { +short *newcore(size) int size; +{ register short *p,*q; size = (size + sizeof(int) - 1) & ~(sizeof(int) - 1); - if( size < 2*MAXSHORT ) { + if( size < 2*MAXSHORT ) + { if ((p=freelist[size/sizeof(short)]) != (short *) 0) - freelist[size/sizeof(short)] = *(short **) p; - else { + freelist[size/sizeof(short)] = *(short **) p; + else + { p = freshcore(size); #ifdef SEPID if (p == (short *) 0) - p = grabcore(size); + p = grabcore(size); #endif } - } else - p = freshcore(size); + } + else + p = freshcore(size); if (p == 0) - error("out of memory"); - for (q=p; size > 0 ; size -= sizeof(short)) - *q++ = 0; + error("out of memory"); + for (q=p; size > 0; size -= sizeof(short)) + *q++ = 0; return(p); } @@ -350,7 +378,8 @@ short *newcore(size) int size; { * you can use these as substitutes */ -char *malloc(size) int size; { +char *malloc(size) int size; +{ /* * malloc(III) is called by stdio, @@ -360,12 +389,14 @@ char *malloc(size) int size; { return( (char *) newcore(size)); } -free() { +free() +{ } #endif -oldcore(p,size) short *p; int size; { +oldcore(p,size) short *p; int size; +{ #ifdef CORECHECK register short *cp; #endif @@ -373,8 +404,8 @@ oldcore(p,size) short *p; int size; { assert(size<2*MAXSHORT); #ifdef CORECHECK for (cp=freelist[size/sizeof(short)]; cp != (short *) 0; - cp = *(short **) cp) - assert(cp != p); + cp = *(short **) cp) + assert(cp != p); #endif *(short **) p = freelist[size/sizeof(short)]; freelist[size/sizeof(short)] = p; @@ -382,7 +413,8 @@ oldcore(p,size) short *p; int size; { short *ccur,*cend; -coreinit(p1,p2) short *p1,*p2; { +coreinit(p1,p2) short *p1,*p2; +{ /* * coreinit is called with the boundaries of a piece of @@ -393,25 +425,28 @@ coreinit(p1,p2) short *p1,*p2; { cend = p2; } -short *freshcore(size) int size; { +short *freshcore(size) int size; +{ register short *temp; static int cchunk=CCHUNK; - - while(&ccur[size/sizeof(short)] >= cend && cchunk>0) { - do { + + while(&ccur[size/sizeof(short)] >= cend && cchunk>0) + { + do + { temp = (short *) sbrk(cchunk*sizeof(short)); if (temp == (short *) -1) - cchunk >>= 1; + cchunk >>= 1; else if (temp != cend) - ccur = cend = temp; - } while (temp == (short *) -1 && cchunk>0); + ccur = cend = temp; + }while (temp == (short *) -1 && cchunk>0); cend += cchunk; #ifdef COREDEBUG shortsasked += cchunk; #endif } if (cchunk==0) - return(0); + return(0); temp = ccur; ccur = &ccur[size/sizeof(short)]; return(temp); @@ -419,21 +454,22 @@ short *freshcore(size) int size; { #else /* USEMALLOC */ -coreinit() { - +void coreinit(void) +{ /* * Empty function, no initialization needed */ } -short *myalloc(size) register size; { - register short *p,*q; +short *myalloc(register unsigned int size) +{ + register short *p, *q; - p = (short *)malloc(size); + p = (short *) malloc(size); if (p == 0) error("out of memory"); - for(q=p;size>0;size -= sizeof(short)) + for (q = p; size > 0; size -= sizeof(short)) *q++ = 0; - return(p); + return (p); } #endif diff --git a/util/opt/alloc.h b/util/opt/alloc.h index 2c1de3e19..5af71fe5f 100644 --- a/util/opt/alloc.h +++ b/util/opt/alloc.h @@ -2,7 +2,10 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ +#ifndef ALLOC_H_ +#define ALLOC_H_ + +#include "types.h" extern line_p newline(); extern offset *newrom(); @@ -12,9 +15,12 @@ extern arg_p newarg(); extern argb_p newargb(); extern reg_p newreg(); -extern oldline(); -extern oldloc(); -extern oldreg(); +void oldline(register line_p lnp); +void oldreg(reg_p rp); +void oldargs(register arg_p ap); +void oldargb(register argb_p abp); +void oldnum(num_p lp); +void coreinit(void); #define USEMALLOC /* if defined malloc() and free() are used */ @@ -47,3 +53,5 @@ extern oldreg(); #define STACKROOM 1 /* 0 gives problems */ #endif /* USEMALLOC */ + +#endif /* ALLOC_H_ */ diff --git a/util/opt/backward.c b/util/opt/backward.c index 83304ce55..d20cb878e 100644 --- a/util/opt/backward.c +++ b/util/opt/backward.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include "param.h" #include "types.h" @@ -15,13 +17,8 @@ static char rcsid[] = "$Id$"; #include #include #include "ext.h" - -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ +#include "getline.h" +#include "reg.h" #define local(x) ((((x)->s_flags&SYMKNOWN) == 0 && \ ((x)->s_flags &= ~ SYMGLOBAL)),\ @@ -34,49 +31,52 @@ static char rcsid[] = "$Id$"; #define DTYPBSS 2 #define DTYPCON 3 #define DTYPROM 4 -byte curdtyp; -bool goodrom; -short curfrag = 3; /* see also peephole.c */ +byte curdtyp; +bool goodrom; +short curfrag = 3; /* see also peephole.c */ offset rombuf[MAXROM]; -int rc; +int rc; -extern offset aoff(); - -backward() { +void backward(void) +{ register line_p lnp; - line_p next; + line_p next; register arg_p ap; - line_p i,p; + line_p i, p; int n; register sym_p sp; i = p = (line_p) 0; - curdtyp=0; - for (lnp = curpro.lastline; lnp != (line_p) 0; lnp = next) { + curdtyp = 0; + for (lnp = curpro.lastline; lnp != (line_p) 0; lnp = next) + { next = lnp->l_next; - switch(lnp->l_optyp) { - case OPSYMBOL: - global(lnp->l_a.la_sp); - break; - case OPSVAL: - global(lnp->l_a.la_sval.lasv_sp); - break; - case OPLVAL: - global(lnp->l_a.la_lval.lalv_sp); - break; - case OPLIST: - ap = lnp->l_a.la_arg; - while (ap != (arg_p) 0 ) { - switch(ap->a_typ) { - case ARGSYM: - global(ap->a_a.a_sp); - break; - case ARGVAL: - global(ap->a_a.a_val.av_sp); + switch (lnp->l_optyp) + { + case OPSYMBOL: + global(lnp->l_a.la_sp); + break; + case OPSVAL: + global(lnp->l_a.la_sval.lasv_sp); + break; + case OPLVAL: + global(lnp->l_a.la_lval.lalv_sp); + break; + case OPLIST: + ap = lnp->l_a.la_arg; + while (ap != (arg_p) 0) + { + switch (ap->a_typ) + { + case ARGSYM: + global(ap->a_a.a_sp); + break; + case ARGVAL: + global(ap->a_a.a_val.av_sp); + } + ap = ap->a_next; } - ap = ap->a_next; - } - break; + break; } /* @@ -84,107 +84,118 @@ backward() { * for plain instructions nothing else is needed */ - switch(lnp->l_instr&BMASK) { - /* - * count all local occurences for register counts; - * op_lal is omitted and not by accident. - */ - case op_del: - case op_inl: - case op_ldl: - case op_lil: - case op_lol: - case op_sdl: - case op_sil: - case op_stl: - case op_zrl: - switch(lnp->l_optyp) { - case OPNO: - case OPNUMLAB: - case OPSYMBOL: - case OPSVAL: - case OPLVAL: - case OPLIST: - break; - case OPOFFSET: - incregusage(lnp->l_a.la_offset); - break; - case OPSHORT: - incregusage((offset)lnp->l_a.la_short); - break; + switch (lnp->l_instr & BMASK) + { + /* + * count all local occurences for register counts; + * op_lal is omitted and not by accident. + */ + case op_del: + case op_inl: + case op_ldl: + case op_lil: + case op_lol: + case op_sdl: + case op_sil: + case op_stl: + case op_zrl: + switch (lnp->l_optyp) + { + case OPNO: + case OPNUMLAB: + case OPSYMBOL: + case OPSVAL: + case OPLVAL: + case OPLIST: + break; + case OPOFFSET: + incregusage(lnp->l_a.la_offset); + break; + case OPSHORT: + incregusage((offset) lnp->l_a.la_short); + break; + default: + incregusage((offset) (lnp->l_optyp & BMASK) - Z_OPMINI); + break; + } + /* fall through !! */ default: - incregusage((offset)(lnp->l_optyp&BMASK)-Z_OPMINI); - break; - } - /* fall through !! */ - default: - assert((lnp->l_instr&BMASK)<=op_last); - lnp->l_next = i; - i = lnp; - continue; - case ps_sym: - sp = lnp->l_a.la_sp; - local(sp); - if (curdtyp == DTYPROM && goodrom) { - sp->s_rom = newrom(); - for (n=0;ns_rom[n] = rombuf[n]; - } - sp->s_frag = curfrag; - break; - case ps_hol: - curdtyp = DTYPHOL; - curfrag++; - break; - case ps_bss: - curdtyp = DTYPBSS; - curfrag++; - break; - case ps_con: - if (curdtyp != DTYPCON) { - curdtyp = DTYPCON; - curfrag++; - } - break; - case ps_rom: - if (curdtyp != DTYPROM) { - curdtyp = DTYPROM; - curfrag++; - } - ap = lnp->l_a.la_arg; - rc = 0; - while (ap != (arg_p) 0 && rc < MAXROM) { - if (ap->a_typ == ARGOFF) { - rombuf[rc++] = ap->a_a.a_offset; - ap = ap->a_next; - } else - ap = (arg_p) 0; - } - goodrom = (rc >= 2); - break; - case ps_mes: - if (prodepth != 0 && - ((int) aoff(lnp->l_a.la_arg, 0) == ms_std || - (int) aoff(lnp->l_a.la_arg, 0) == ms_stb || - (int) aoff(lnp->l_a.la_arg, 0) == ms_ego)) { + assert((lnp->l_instr&BMASK)<=op_last); lnp->l_next = i; i = lnp; continue; - } - break; - case ps_inp: - case ps_ina: - local(lnp->l_a.la_sp); - case ps_exp: - case ps_exa: - case ps_exc: - oldline(lnp); - continue; + case ps_sym: + sp = lnp->l_a.la_sp; + local(sp); + if (curdtyp == DTYPROM && goodrom) + { + sp->s_rom = newrom(); + for (n = 0; n < rc; n++) + sp->s_rom[n] = rombuf[n]; + } + sp->s_frag = curfrag; + break; + case ps_hol: + curdtyp = DTYPHOL; + curfrag++; + break; + case ps_bss: + curdtyp = DTYPBSS; + curfrag++; + break; + case ps_con: + if (curdtyp != DTYPCON) + { + curdtyp = DTYPCON; + curfrag++; + } + break; + case ps_rom: + if (curdtyp != DTYPROM) + { + curdtyp = DTYPROM; + curfrag++; + } + ap = lnp->l_a.la_arg; + rc = 0; + while (ap != (arg_p) 0 && rc < MAXROM) + { + if (ap->a_typ == ARGOFF) + { + rombuf[rc++] = ap->a_a.a_offset; + ap = ap->a_next; + } + else + ap = (arg_p) 0; + } + goodrom = (rc >= 2); + break; + case ps_mes: + if (prodepth != 0 + && ((int) aoff(lnp->l_a.la_arg, 0) == ms_std + || (int) aoff(lnp->l_a.la_arg, 0) == ms_stb + || (int) aoff(lnp->l_a.la_arg, 0) == ms_ego)) + { + lnp->l_next = i; + i = lnp; + continue; + } + break; + case ps_inp: + case ps_ina: + local(lnp->l_a.la_sp); + case ps_exp: + case ps_exa: + case ps_exc: + oldline(lnp); + continue; } lnp->l_next = p; p = lnp; } if (prodepth != 0) local(curpro.symbol); - instrs = i; pseudos = p; curpro.lastline = (line_p) 0; + instrs = i; + pseudos = p; + curpro.lastline = (line_p) 0; } diff --git a/util/opt/build.lua b/util/opt/build.lua index cb86b3fff..a503a6f35 100644 --- a/util/opt/build.lua +++ b/util/opt/build.lua @@ -11,9 +11,9 @@ flex { } local headers = { - "./alloc.h", "./ext.h", "./line.h", "./lookup.h", "./optim.h", - "./param.h", "./pattern.h", "./pop_push.h", "./proinf.h", - "./tes.h", "./types.h", + "./alloc.h", "./ext.h", "./getline.h", "./line.h", "./lookup.h", "./optim.h", + "./param.h", "./pattern.h", "./pop_push.h", "./proinf.h","./putline.h", + "./reg.h","./tes.h", "./types.h","./util.h" } cprogram { diff --git a/util/opt/cleanup.c b/util/opt/cleanup.c index 504e712f4..3ac39c53d 100644 --- a/util/opt/cleanup.c +++ b/util/opt/cleanup.c @@ -1,61 +1,58 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - -#include -#include -#include -#include "param.h" -#include "types.h" -#include -#include -#include -#include "lookup.h" -#include "ext.h" - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". * * Author: Hans van Staveren */ +#include +#include +#include "param.h" +#include "types.h" +#include +#include +#include +#include "lookup.h" +#include "putline.h" +#include "util.h" +#include "ext.h" - -void -cleanup() { +void cleanup(void) +{ FILE *infile; - register c; - register sym_p *spp,sp; + register int c; + register sym_p *spp, sp; - for (spp=symhash;spp< &symhash[NSYMHASH];spp++) - for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next) - if ((sp->s_flags & SYMOUT) == 0) - outdef(sp); - if(!Lflag) + for (spp = symhash; spp < &symhash[NSYMHASH]; spp++) + for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next) + if ((sp->s_flags & SYMOUT) == 0) + outdef(sp); + if (!Lflag) return; - c=fclose(outfile); + c = fclose(outfile); assert(c != EOF); outfile = stdout; - infile = fopen(template,"r"); + infile = fopen(tempname, "r"); if (infile == NULL) error("temp file disappeared"); outshort(sp_magic); /* Attempt to first output the word_size message */ - while ((c = getc(infile)) != sp_cend && c != EOF) { + while ((c = getc(infile)) != sp_cend && c != EOF) + { putc(c, outfile); } - if (c == sp_cend) putc(c, outfile); + if (c == sp_cend) + putc(c, outfile); outinst(ps_mes); outint(ms_ext); - for (spp=symhash;spp< &symhash[NSYMHASH];spp++) + for (spp = symhash; spp < &symhash[NSYMHASH]; spp++) for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next) - if ((sp->s_flags&(SYMDEF|SYMGLOBAL)) == (SYMDEF|SYMGLOBAL)) + if ((sp->s_flags & (SYMDEF | SYMGLOBAL)) == (SYMDEF | SYMGLOBAL)) outsym(sp); - putc(sp_cend,outfile); - while ( (c=getc(infile)) != EOF) - putc(c,outfile); - c=fclose(infile); + putc(sp_cend, outfile); + while ((c = getc(infile)) != EOF) + putc(c, outfile); + c = fclose(infile); assert(c != EOF); - c=unlink(template); + c = remove(tempname); assert(c == 0); } diff --git a/util/opt/em_opt.6 b/util/opt/em_opt.6 index 267bd9c69..f42ab1d56 100644 --- a/util/opt/em_opt.6 +++ b/util/opt/em_opt.6 @@ -3,7 +3,7 @@ .SH NAME em_opt \- EM peephole optimizer .SH SYNOPSIS -.B ~em/lib.bin/em_opt +.B em_opt [\-Ln] [\-m[l]] [ argument ] .SH DESCRIPTION Em_opt reads a compact EM-program, argument or standard input, diff --git a/util/opt/ext.h b/util/opt/ext.h index 4adeca38b..342ab17c0 100644 --- a/util/opt/ext.h +++ b/util/opt/ext.h @@ -16,7 +16,7 @@ extern bool repl_longmuls; extern byte em_flag[]; extern line_p instrs,pseudos; extern FILE *outfile; -extern char template[]; +extern char tempname[]; extern offset wordsize; extern offset pointersize; extern char *progname; diff --git a/util/opt/flow.c b/util/opt/flow.c index 73ae715af..08a04cf26 100644 --- a/util/opt/flow.c +++ b/util/opt/flow.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include "param.h" #include "types.h" #include "tes.h" @@ -14,97 +16,110 @@ static char rcsid[] = "$Id$"; #include "optim.h" #include "ext.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ +/* Forward declarations */ +static void reach(register line_p); +static void findreach(void); +static void cleaninstrs(void); -void reach(); - -flow() { - - findreach(); /* determine reachable labels */ - cleaninstrs(); /* throw away unreachable code */ +void flow(void) +{ + findreach(); /* determine reachable labels */ + cleaninstrs(); /* throw away unreachable code */ } -findreach() { - register num_p *npp,np; +static void findreach(void) +{ + register num_p *npp, np; reach(instrs); - for(npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++) - for(np= *npp; np != (num_p) 0 ; np = np->n_next) - if (np->n_flags&NUMDATA) { + for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) + for (np = *npp; np != (num_p) 0; np = np->n_next) + if (np->n_flags & NUMDATA) + { np->n_repl->n_flags |= NUMREACH; np->n_repl->n_jumps++; - if (!(np->n_flags&NUMSCAN)) { + if (!(np->n_flags & NUMSCAN)) + { np->n_flags |= NUMSCAN; - if (np->n_line) { + if (np->n_line) + { reach(np->n_line->l_next); continue; } - if (!(np->n_repl->n_flags&NUMSCAN)) { + if (!(np->n_repl->n_flags & NUMSCAN)) + { np->n_repl->n_flags |= NUMSCAN; if (np->n_repl->n_line) - reach(np->n_repl->n_line->l_next); + reach(np->n_repl->n_line->l_next); } } } } -void -reach(lnp) register line_p lnp; { +static void reach(register line_p lnp) +{ register num_p np; - for (;lnp != (line_p) 0; lnp = lnp->l_next) { - if(lnp->l_optyp == OPNUMLAB) { + for (; lnp != (line_p) 0; lnp = lnp->l_next) + { + if (lnp->l_optyp == OPNUMLAB) + { /* * Branch instruction or label */ np = lnp->l_a.la_np; - if ((lnp->l_instr&BMASK) != op_lab) + if ((lnp->l_instr & BMASK) != op_lab) lnp->l_a.la_np = np = np->n_repl; np->n_flags |= NUMREACH; - if (!(np->n_flags&NUMSCAN)) { + if (!(np->n_flags & NUMSCAN)) + { np->n_flags |= NUMSCAN; if (np->n_line) reach(np->n_line->l_next); - else { + else + { np = np->n_repl; np->n_flags |= NUMREACH; - if (!(np->n_flags & NUMSCAN)) { + if (!(np->n_flags & NUMSCAN)) + { np->n_flags |= NUMSCAN; if (np->n_line) reach(np->n_line->l_next); } } } - if ((lnp->l_instr&BMASK) == op_lab) + if ((lnp->l_instr & BMASK) == op_lab) return; else np->n_jumps++; } - if ((lnp->l_instr & BMASK) > sp_lmnem) continue; - if ((em_flag[(lnp->l_instr&BMASK)-sp_fmnem]&EM_FLO)==FLO_T) + if ((lnp->l_instr & BMASK) > sp_lmnem) + continue; + if ((em_flag[(lnp->l_instr & BMASK) - sp_fmnem] & EM_FLO) == FLO_T) return; } } -cleaninstrs() { - register line_p *lpp,lp,*lastbra; - bool reachable,superfluous; +static void cleaninstrs(void) +{ + register line_p *lpp, lp, *lastbra; + bool reachable, superfluous; int instr; - lpp = &instrs; lastbra = (line_p *) 0; reachable = TRUE; - while ((lp = *lpp) != (line_p) 0) { - instr = lp->l_instr&BMASK; - if (instr == op_lab) { - if ((lp->l_a.la_np->n_flags&NUMREACH) != 0) { + lpp = &instrs; + lastbra = (line_p *) 0; + reachable = TRUE; + while ((lp = *lpp) != (line_p) 0) + { + instr = lp->l_instr & BMASK; + if (instr == op_lab) + { + if ((lp->l_a.la_np->n_flags & NUMREACH) != 0) + { reachable = TRUE; - if (lastbra != (line_p *) 0 - && (*lastbra)->l_next == lp - && (*lastbra)->l_a.la_np->n_repl==lp->l_a.la_np) { + if (lastbra != (line_p *) 0 && (*lastbra)->l_next == lp + && (*lastbra)->l_a.la_np->n_repl == lp->l_a.la_np) + { oldline(*lastbra); OPTIM(O_BRALAB); lpp = lastbra; @@ -113,19 +128,23 @@ cleaninstrs() { lp->l_a.la_np->n_jumps--; } } - if ( lp->l_a.la_np->n_repl != lp->l_a.la_np || - ((lp->l_a.la_np->n_flags&NUMDATA)==0 && - lp->l_a.la_np->n_jumps == 0)) + if (lp->l_a.la_np->n_repl != lp->l_a.la_np + || ((lp->l_a.la_np->n_flags & NUMDATA) == 0 + && lp->l_a.la_np->n_jumps == 0)) superfluous = TRUE; else superfluous = FALSE; - } else + } + else superfluous = FALSE; - if ( (!reachable) || superfluous) { - if (instr == op_lab) { + if ((!reachable) || superfluous) + { + if (instr == op_lab) + { lp->l_a.la_np->n_line = 0; } - else if (instr > sp_lmnem) { + else if (instr > sp_lmnem) + { /* leave pseudo's */ lpp = &lp->l_next; continue; @@ -134,11 +153,14 @@ cleaninstrs() { oldline(*lpp); OPTIM(O_UNREACH); *lpp = lp; - } else { - if ( instr <= sp_lmnem && - (em_flag[instr-sp_fmnem]&EM_FLO)==FLO_T) { + } + else + { + if (instr <= sp_lmnem + && (em_flag[instr - sp_fmnem] & EM_FLO) == FLO_T) + { reachable = FALSE; - if ((lp->l_instr&BMASK) == op_bra) + if ((lp->l_instr & BMASK) == op_bra) lastbra = lpp; } lpp = &lp->l_next; diff --git a/util/opt/getline.c b/util/opt/getline.c index 9ecdf08fd..4fb4c4917 100644 --- a/util/opt/getline.c +++ b/util/opt/getline.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include #include "param.h" @@ -16,18 +18,13 @@ static char rcsid[] = "$Id$"; #include #include #include "ext.h" +#include "reg.h" +#include "getline.h" +#include "util.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ - - -static short tabval; /* temp store for shorts */ -static offset tabval2; /* temp store for offsets */ -static char string[IDL+1]; /* temp store for names */ +static short tabval; /* temp store for shorts */ +static offset tabval2; /* temp store for offsets */ +static char string[IDL + 1]; /* temp store for names */ /* * The next constants are close to sp_cend for fast switches @@ -44,275 +41,220 @@ static char string[IDL+1]; /* temp store for names */ #define readbyte getchar -short readshort() { +/* Other external declarations */ +extern void process(void); + +/* Forward declarations */ +static int table2(void); + +static void tstinpro(void) +{ + if (prodepth == 0) + error("This is not allowed outside a procedure"); +} + +short readshort(void) +{ register int l_byte, h_byte; l_byte = readbyte(); h_byte = readbyte(); - if ( h_byte>=128 ) h_byte -= 256 ; - return l_byte | (h_byte*256) ; + if (h_byte >= 128) + h_byte -= 256; + return l_byte | (h_byte * 256); } #ifdef LONGOFF -offset readoffset() { +static offset readoffset(void) +{ register long l; register int h_byte; l = readbyte(); - l |= ((unsigned) readbyte())*256 ; - l |= readbyte()*256L*256L ; - h_byte = readbyte() ; - if ( h_byte>=128 ) h_byte -= 256 ; - return l | (h_byte*256L*256*256L) ; + l |= ((unsigned) readbyte()) * 256; + l |= readbyte() * 256L * 256L; + h_byte = readbyte(); + if (h_byte >= 128) + h_byte -= 256; + return l | (h_byte * 256L * 256 * 256L); } #endif -draininput() { - +static void draininput(void) +{ /* * called when MES ERR is encountered. * Drain input in case it is a pipe. */ - while (getchar() != EOF) ; } -short getint() { +static short getint(void) +{ - switch(table2()) { - default: error("int expected"); - case CSTX1: - return(tabval); + switch (table2()) + { + default: + error("int expected"); + case CSTX1: + return (tabval); } } -sym_p getsym(status) int status; { - - switch(table2()) { - default: - error("symbol expected"); - case DLBX: - return(symlookup(string,status,0)); - case sp_pnam: - return(symlookup(string,status,SYMPRO)); +static sym_p getsym(int status) +{ + switch (table2()) + { + default: + error("symbol expected"); + case DLBX: + return (symlookup(string, status, 0)); + case sp_pnam: + return (symlookup(string, status, SYMPRO)); } } -offset getoff() { - - switch (table2()) { - default: error("offset expected"); - case CSTX1: - return((offset) tabval); +static offset getoff(void) +{ + switch (table2()) + { + default: + error("offset expected"); + case CSTX1: + return ((offset) tabval); #ifdef LONGOFF - case CSTX2: - return(tabval2); + case CSTX2: + return (tabval2); #endif } } -make_string(n) int n; { - - sprintf(string,".%u",n); +static void make_string(int n) +{ + sprintf(string, ".%u", n); } -inident() { - register n; +static void inident(void) +{ + register int n; register char *p = string; - register c; + register int c; n = getint(); - while (n--) { + while (n--) + { c = readbyte(); - if (p<&string[IDL]) + if (p < &string[IDL]) *p++ = c; } *p++ = 0; } -int table3(n) int n; { - - switch (n) { - case sp_ilb1: tabval = readbyte(); return(ILBX); - case sp_ilb2: tabval = readshort(); return(ILBX); - case sp_dlb1: make_string(readbyte()); return(DLBX); - case sp_dlb2: make_string(readshort()); return(DLBX); - case sp_dnam: inident(); return(DLBX); - case sp_pnam: inident(); return(n); - case sp_cst2: tabval = readshort(); return(CSTX1); +static int table3(int n) +{ + switch (n) + { + case sp_ilb1: + tabval = readbyte(); + return (ILBX); + case sp_ilb2: + tabval = readshort(); + return (ILBX); + case sp_dlb1: + make_string(readbyte()); + return (DLBX); + case sp_dlb2: + make_string(readshort()); + return (DLBX); + case sp_dnam: + inident(); + return (DLBX); + case sp_pnam: + inident(); + return (n); + case sp_cst2: + tabval = readshort(); + return (CSTX1); #ifdef LONGOFF - case sp_cst4: tabval2 = readoffset(); return(CSTX2); + case sp_cst4: + tabval2 = readoffset(); + return (CSTX2); #endif - case sp_doff: if (table2()!=DLBX) error("symbol expected"); - switch(table2()) { - default: error("offset expected"); - case CSTX1: return(VALX1); + case sp_doff: + if (table2() != DLBX) + error("symbol expected"); + switch (table2()) + { + default: + error("offset expected"); + case CSTX1: + return (VALX1); #ifdef LONGOFF - case CSTX2: return(VALX2); + case CSTX2: + return (VALX2); #endif } - default: return(n); + default: + return (n); } } -int table1() { - register n; +static int table1(void) +{ + register int n; n = readbyte(); if (n == EOF) - return(ATEOF); - if ((n <= sp_lmnem) && (n >= sp_fmnem)) { + return (ATEOF); + if ((n <= sp_lmnem) && (n >= sp_fmnem)) + { tabval = n; - return(INST); + return (INST); } - if ((n <= sp_lpseu) && (n >= sp_fpseu)) { + if ((n <= sp_lpseu) && (n >= sp_fpseu)) + { tabval = n; - return(PSEU); + return (PSEU); } - if ((n < sp_filb0 + sp_nilb0) && (n >= sp_filb0)) { + if ((n < sp_filb0 + sp_nilb0) && (n >= sp_filb0)) + { tabval = n - sp_filb0; - return(ILBX); + return (ILBX); } - return(table3(n)); + return (table3(n)); } -int table2() { - register n; +static int table2(void) +{ + register int n; n = readbyte(); - if ((n < sp_fcst0 + sp_ncst0) && (n >= sp_fcst0)) { + if ((n < sp_fcst0 + sp_ncst0) && (n >= sp_fcst0)) + { tabval = n - sp_zcst0; - return(CSTX1); + return (CSTX1); } - return(table3(n)); + return (table3(n)); } -void -getlines() { - register line_p lnp; - register instr; - - for(;;) { - linecount++; - switch(table1()) { - default: - error("unknown instruction byte"); - /* NOTREACHED */ - - case ATEOF: - if (prodepth!=0) - error("procedure unterminated at eof"); - process(); - return; - case INST: - tstinpro(); - instr = tabval; - break; - case DLBX: - lnp = newline(OPSYMBOL); - lnp->l_instr = ps_sym; - lnp->l_a.la_sp= symlookup(string,DEFINING,0); - lnp->l_next = curpro.lastline; - curpro.lastline = lnp; - continue; - case ILBX: - tstinpro(); - lnp = newline(OPNUMLAB); - lnp->l_instr = op_lab; - lnp->l_a.la_np = numlookup((unsigned) tabval); - if (lnp->l_a.la_np->n_line != (line_p) 0) - error("label %u multiple defined",(unsigned) tabval); - lnp->l_a.la_np->n_line = lnp; - lnp->l_next = curpro.lastline; - curpro.lastline = lnp; - continue; - case PSEU: - if(inpseudo(tabval)) - return; - continue; - } - - /* - * Now we have an instruction number in instr - * There might be an operand, look for it - */ - - if ((em_flag[instr-sp_fmnem]&EM_PAR)==PAR_NO) { - lnp = newline(OPNO); - } else switch(table2()) { - default: - error("unknown offset byte"); - case sp_cend: - lnp = newline(OPNO); - break; - case CSTX1: - if ((em_flag[instr-sp_fmnem]&EM_PAR)!= PAR_B) { - if (CANMINI(tabval)) - lnp = newline(tabval+Z_OPMINI); - else { - lnp = newline(OPSHORT); - lnp->l_a.la_short = tabval; - } - } else { - lnp = newline(OPNUMLAB); - lnp->l_a.la_np = numlookup((unsigned) tabval); - } - break; -#ifdef LONGOFF - case CSTX2: - lnp = newline(OPOFFSET); - lnp->l_a.la_offset = tabval2; - break; -#endif - case ILBX: - tstinpro(); - lnp = newline(OPNUMLAB); - lnp->l_a.la_np = numlookup((unsigned) tabval); - break; - case DLBX: - lnp = newline(OPSYMBOL); - lnp->l_a.la_sp = symlookup(string,OCCURRING,0); - break; - case sp_pnam: - lnp = newline(OPSYMBOL); - lnp->l_a.la_sp = symlookup(string,OCCURRING,SYMPRO); - break; - case VALX1: - lnp = newline(OPSVAL); - lnp->l_a.la_sval.lasv_sp = symlookup(string,OCCURRING,0); - lnp->l_a.la_sval.lasv_short = tabval; - break; -#ifdef LONGOFF - case VALX2: - lnp = newline(OPLVAL); - lnp->l_a.la_lval.lalv_sp = symlookup(string,OCCURRING,0); - lnp->l_a.la_lval.lalv_offset = tabval2; - break; -#endif - } - lnp->l_instr = instr; - lnp->l_next = curpro.lastline; - curpro.lastline = lnp; - } -} - -argstring(length,abp) offset length; register argb_p abp; { - - while (length--) { +static void argstring(offset length, register argb_p abp) +{ + while (length--) + { if (abp->ab_index == NARGBYTES) abp = abp->ab_next = newargb(); abp->ab_contents[abp->ab_index++] = readbyte(); } } -line_p arglist(n) int n; { - line_p lnp; - register arg_p ap,*app; +static line_p arglist(int n) +{ + line_p lnp; + register arg_p ap, *app; bool moretocome; offset length; - /* * creates an arglist with n elements * if n == 0 the arglist is variable and terminated by sp_cend @@ -321,74 +263,77 @@ line_p arglist(n) int n; { lnp = newline(OPLIST); app = &lnp->l_a.la_arg; moretocome = TRUE; - do { - switch(table2()) { - default: - error("unknown byte in arglist"); - case CSTX1: - tabval2 = (offset) tabval; - case CSTX2: - *app = ap = newarg(ARGOFF); - ap->a_a.a_offset = tabval2; - app = &ap->a_next; - break; - case ILBX: - tstinpro(); - *app = ap = newarg(ARGNUM); - ap->a_a.a_np = numlookup((unsigned) tabval); - ap->a_a.a_np->n_flags |= NUMDATA; - app = &ap->a_next; - break; - case DLBX: - *app = ap = newarg(ARGSYM); - ap->a_a.a_sp = symlookup(string,OCCURRING,0); - app = &ap->a_next; - break; - case sp_pnam: - *app = ap = newarg(ARGSYM); - ap->a_a.a_sp = symlookup(string,OCCURRING,SYMPRO); - app = &ap->a_next; - break; - case VALX1: - tabval2 = (offset) tabval; - case VALX2: - *app = ap = newarg(ARGVAL); - ap->a_a.a_val.av_sp = symlookup(string,OCCURRING,0); - ap->a_a.a_val.av_offset = tabval2; - app = &ap->a_next; - break; - case sp_scon: - *app = ap = newarg(ARGSTR); - length = getoff(); - argstring(length,&ap->a_a.a_string); - app = &ap->a_next; - break; - case sp_icon: - *app = ap = newarg(ARGICN); - goto casecon; - case sp_ucon: - *app = ap = newarg(ARGUCN); - goto casecon; - case sp_fcon: - *app = ap = newarg(ARGFCN); - casecon: - length = getint(); - ap->a_a.a_con.ac_length = (short) length; - argstring(getoff(),&ap->a_a.a_con.ac_con); - app = &ap->a_next; - break; - case sp_cend: - moretocome = FALSE; + do + { + switch (table2()) + { + default: + error("unknown byte in arglist"); + case CSTX1: + tabval2 = (offset) tabval; + case CSTX2: + *app = ap = newarg(ARGOFF); + ap->a_a.a_offset = tabval2; + app = &ap->a_next; + break; + case ILBX: + tstinpro(); + *app = ap = newarg(ARGNUM); + ap->a_a.a_np = numlookup((unsigned) tabval); + ap->a_a.a_np->n_flags |= NUMDATA; + app = &ap->a_next; + break; + case DLBX: + *app = ap = newarg(ARGSYM); + ap->a_a.a_sp = symlookup(string, OCCURRING, 0); + app = &ap->a_next; + break; + case sp_pnam: + *app = ap = newarg(ARGSYM); + ap->a_a.a_sp = symlookup(string, OCCURRING, SYMPRO); + app = &ap->a_next; + break; + case VALX1: + tabval2 = (offset) tabval; + case VALX2: + *app = ap = newarg(ARGVAL); + ap->a_a.a_val.av_sp = symlookup(string, OCCURRING, 0); + ap->a_a.a_val.av_offset = tabval2; + app = &ap->a_next; + break; + case sp_scon: + *app = ap = newarg(ARGSTR); + length = getoff(); + argstring(length, &ap->a_a.a_string); + app = &ap->a_next; + break; + case sp_icon: + *app = ap = newarg(ARGICN); + goto casecon; + case sp_ucon: + *app = ap = newarg(ARGUCN); + goto casecon; + case sp_fcon: + *app = ap = newarg(ARGFCN); + casecon: length = getint(); + ap->a_a.a_con.ac_length = (short) length; + argstring(getoff(), &ap->a_a.a_con.ac_con); + app = &ap->a_next; + break; + case sp_cend: + moretocome = FALSE; } if (n && (--n) == 0) moretocome = FALSE; } while (moretocome); - return(lnp); + return (lnp); } -offset aoff(ap,n) register arg_p ap; { +offset aoff(register arg_p ap, int n) +{ - while (n>0) { + while (n > 0) + { if (ap != (arg_p) 0) ap = ap->a_next; n--; @@ -397,154 +342,284 @@ offset aoff(ap,n) register arg_p ap; { error("too few parameters"); if (ap->a_typ != ARGOFF) error("offset expected"); - return(ap->a_a.a_offset); + return (ap->a_a.a_offset); } -int inpseudo(n) short n; { - register line_p lnp,head,tail; - short n1,n2; +static int inpseudo(short n) +{ + register line_p lnp, head, tail; + short n1, n2; proinf savearea; #ifdef PSEUBETWEEN - static int pcount=0; + static int pcount = 0; - if (pcount++ >= PSEUBETWEEN && prodepth==0) { + if (pcount++ >= PSEUBETWEEN && prodepth == 0) + { process(); - pcount=0; + pcount = 0; } #endif - switch(n) { - default: - error("unknown pseudo"); - case ps_bss: - case ps_hol: - lnp = arglist(3); - break; - case ps_rom: - case ps_con: - lnp = arglist(0); - break; - case ps_ina: - case ps_inp: - case ps_exa: - case ps_exp: - lnp = newline(OPSYMBOL); - lnp->l_a.la_sp = getsym(NOTHING); - break; - case ps_exc: - n1 = getint(); n2 = getint(); - if (n1 != 0 && n2 != 0) { - tail = curpro.lastline; - while (--n2) tail = tail->l_next; - head = tail; - while (n1--) head = head->l_next; - lnp = tail->l_next; - tail->l_next = head->l_next; - head->l_next = curpro.lastline; - curpro.lastline = lnp; - } - lnp = newline(OPNO); - break; - case ps_mes: - lnp = arglist(0); - switch((int) aoff(lnp->l_a.la_arg,0)) { - case ms_err: - draininput(); exit(-1); - case ms_opt: - nflag = TRUE; break; - case ms_emx: - wordsize = aoff(lnp->l_a.la_arg,1); - pointersize = aoff(lnp->l_a.la_arg,2); -#ifndef LONGOFF - if (wordsize>2) - error("This optimizer cannot handle wordsize>2"); -#endif - break; - case ms_gto: - curpro.gtoproc=1; - /* Treat as empty mes ms_reg */ - case ms_reg: - tstinpro(); - regvar(lnp->l_a.la_arg->a_next); - oldline(lnp); - lnp=newline(OPNO); - n=ps_exc; /* kludge to force out this line */ - break; - case ms_tes: - tstinpro(); - oldline(lnp); - lnp=newline(OPNO); - n=ps_exc; /* kludge to force out this line */ - break; - } - break; - case ps_pro: - if (prodepth>0) - savearea = curpro; - else - process(); - curpro.symbol = getsym(DEFINING); - switch(table2()) { - case sp_cend: - curpro.localbytes = (offset) -1; - break; - case CSTX1: - tabval2 = (offset) tabval; - case CSTX2: - curpro.localbytes = tabval2; - break; + switch (n) + { default: - error("bad second arg of PRO"); - } - prodepth++; - curpro.gtoproc=0; - if (prodepth>1) { - register i; - - curpro.lastline = (line_p) 0; - curpro.freg = (reg_p) 0; - for(i=0;il_a.la_sp = getsym(NOTHING); + break; + case ps_exc: + n1 = getint(); + n2 = getint(); + if (n1 != 0 && n2 != 0) + { + tail = curpro.lastline; + while (--n2) + tail = tail->l_next; + head = tail; + while (n1--) + head = head->l_next; + lnp = tail->l_next; + tail->l_next = head->l_next; + head->l_next = curpro.lastline; + curpro.lastline = lnp; + } + lnp = newline(OPNO); + break; + case ps_mes: + lnp = arglist(0); + switch ((int) aoff(lnp->l_a.la_arg, 0)) + { + case ms_err: + draininput(); + exit(-1); + case ms_opt: + nflag = TRUE; + break; + case ms_emx: + wordsize = aoff(lnp->l_a.la_arg, 1); + pointersize = aoff(lnp->l_a.la_arg, 2); +#ifndef LONGOFF + if (wordsize>2) + error("This optimizer cannot handle wordsize>2"); #endif - return(0); - } else - return(1); + break; + case ms_gto: + curpro.gtoproc = 1; + /* Treat as empty mes ms_reg */ + case ms_reg: + tstinpro(); + regvar(lnp->l_a.la_arg->a_next); + oldline(lnp); + lnp = newline(OPNO); + n = ps_exc; /* kludge to force out this line */ + break; + case ms_tes: + tstinpro(); + oldline(lnp); + lnp = newline(OPNO); + n = ps_exc; /* kludge to force out this line */ + break; + } + break; + case ps_pro: + if (prodepth > 0) + savearea = curpro; + else + process(); + curpro.symbol = getsym(DEFINING); + switch (table2()) + { + case sp_cend: + curpro.localbytes = (offset) -1; + break; + case CSTX1: + tabval2 = (offset) tabval; + case CSTX2: + curpro.localbytes = tabval2; + break; + default: + error("bad second arg of PRO"); + } + prodepth++; + curpro.gtoproc = 0; + if (prodepth > 1) + { + register int i; + + curpro.lastline = (line_p) 0; + curpro.freg = (reg_p) 0; + for (i = 0; i < NNUMHASH; i++) + curpro.numhash[i] = (num_p) 0; + getlines(); + curpro = savearea; + prodepth--; + } + return (0); + case ps_end: + if (prodepth == 0) + error("END misplaced"); + switch (table2()) + { + case sp_cend: + if (curpro.localbytes == (offset) -1) + error("bytes for locals still unknown"); + break; + case CSTX1: + tabval2 = (offset) tabval; + case CSTX2: + if (curpro.localbytes != (offset) -1 + && curpro.localbytes != tabval2) + error("inconsistency in number of bytes for locals"); + curpro.localbytes = tabval2; + break; + } + process(); + curpro.symbol = (sym_p) 0; + if (prodepth == 1) + { + prodepth = 0; +#ifdef PSEUBETWEEN + pcount = 0; +#endif + return (0); + } + else + return (1); } lnp->l_instr = n; lnp->l_next = curpro.lastline; curpro.lastline = lnp; - return(0); + return (0); } -tstinpro() { +void getlines(void) +{ + register line_p lnp; + register int instr; - if (prodepth==0) - error("This is not allowed outside a procedure"); + for (;;) + { + linecount++; + switch (table1()) + { + default: + error("unknown instruction byte"); + /* NOTREACHED */ + + case ATEOF: + if (prodepth != 0) + error("procedure unterminated at eof"); + process(); + return; + case INST: + tstinpro(); + instr = tabval; + break; + case DLBX: + lnp = newline(OPSYMBOL); + lnp->l_instr = ps_sym; + lnp->l_a.la_sp = symlookup(string, DEFINING, 0); + lnp->l_next = curpro.lastline; + curpro.lastline = lnp; + continue; + case ILBX: + tstinpro(); + lnp = newline(OPNUMLAB); + lnp->l_instr = op_lab; + lnp->l_a.la_np = numlookup((unsigned) tabval); + if (lnp->l_a.la_np->n_line != (line_p) 0) + error("label %u multiple defined", (unsigned) tabval); + lnp->l_a.la_np->n_line = lnp; + lnp->l_next = curpro.lastline; + curpro.lastline = lnp; + continue; + case PSEU: + if (inpseudo(tabval)) + return; + continue; + } + + /* + * Now we have an instruction number in instr + * There might be an operand, look for it + */ + + if ((em_flag[instr - sp_fmnem] & EM_PAR) == PAR_NO) + { + lnp = newline(OPNO); + } + else + switch (table2()) + { + default: + error("unknown offset byte"); + case sp_cend: + lnp = newline(OPNO); + break; + case CSTX1: + if ((em_flag[instr - sp_fmnem] & EM_PAR) != PAR_B) + { + if (CANMINI(tabval)) + lnp = newline(tabval + Z_OPMINI); + else + { + lnp = newline(OPSHORT); + lnp->l_a.la_short = tabval; + } + } + else + { + lnp = newline(OPNUMLAB); + lnp->l_a.la_np = numlookup((unsigned) tabval); + } + break; +#ifdef LONGOFF + case CSTX2: + lnp = newline(OPOFFSET); + lnp->l_a.la_offset = tabval2; + break; +#endif + case ILBX: + tstinpro(); + lnp = newline(OPNUMLAB); + lnp->l_a.la_np = numlookup((unsigned) tabval); + break; + case DLBX: + lnp = newline(OPSYMBOL); + lnp->l_a.la_sp = symlookup(string, OCCURRING, 0); + break; + case sp_pnam: + lnp = newline(OPSYMBOL); + lnp->l_a.la_sp = symlookup(string, OCCURRING, SYMPRO); + break; + case VALX1: + lnp = newline(OPSVAL); + lnp->l_a.la_sval.lasv_sp = symlookup(string, OCCURRING, 0); + lnp->l_a.la_sval.lasv_short = tabval; + break; +#ifdef LONGOFF + case VALX2: + lnp = newline(OPLVAL); + lnp->l_a.la_lval.lalv_sp = symlookup(string, OCCURRING, 0); + lnp->l_a.la_lval.lalv_offset = tabval2; + break; +#endif + } + lnp->l_instr = instr; + lnp->l_next = curpro.lastline; + curpro.lastline = lnp; + } } + diff --git a/util/opt/getline.h b/util/opt/getline.h new file mode 100644 index 000000000..6491e0f6c --- /dev/null +++ b/util/opt/getline.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-04-07 + * + */ +#ifndef GETLINE_H_ +#define GETLINE_H_ + +#include "types.h" + +void getlines(void); +offset aoff(register arg_p ap, int n); +short readshort(void); + +#endif /* GETLINE_H_ */ diff --git a/util/opt/lookup.c b/util/opt/lookup.c index 8cda8e518..434e1d198 100644 --- a/util/opt/lookup.c +++ b/util/opt/lookup.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include #include "param.h" @@ -10,68 +12,68 @@ static char rcsid[] = "$Id$"; #include "lookup.h" #include "alloc.h" #include "proinf.h" +#include "util.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ - -unsigned hash(string) char *string; { +unsigned hash(char *string) +{ register char *p; - register unsigned i,sum; + register unsigned i, sum; - for (sum=i=0,p=string;*p;i += 3) - sum ^= (*p++)<<(i&07); - return(sum); + for (sum = i = 0, p = string; *p; i += 3) + sum ^= (*p++) << (i & 07); + return (sum); } -sym_p symlookup(name,status,flags) char *name; int status,flags; { - register sym_p *spp,sp; - register i; +sym_p symlookup(char *name, int status, int flags) +{ + register sym_p *spp, sp; + register int i; static short genfrag = 32767; - spp = &symhash[hash(name)%NSYMHASH]; + spp = &symhash[hash(name) % NSYMHASH]; while (*spp != (sym_p) 0) - if (strncmp((*spp)->s_name,name,IDL)==0) { + if (strncmp((*spp)->s_name, name, IDL) == 0) + { sp = *spp; - if ((sp->s_flags^flags)&SYMPRO) - error("%s is both proc and datalabel",name); - if (status == DEFINING) { - if (sp->s_flags&SYMDEF) - error("redefined symbol %s",name); + if ((sp->s_flags ^ flags) & SYMPRO) + error("%s is both proc and datalabel", name); + if (status == DEFINING) + { + if (sp->s_flags & SYMDEF) + error("redefined symbol %s", name); sp->s_flags |= SYMDEF; } - return(sp); - } else + return (sp); + } + else spp = &(*spp)->s_next; /* * symbol not found, enter in table */ - i = strlen(name) + 1; - if (i & 1) - i++; - if (i > IDL) - i = IDL; - *spp = sp = newsym(i); - strncpy(sp->s_name,name,i); + i = strlen(name) + 1; + if (i & 1) + i++; + if (i > IDL) + i = IDL; + *spp = sp = newsym(i); + strncpy(sp->s_name, name, i); sp->s_flags = flags; if (status == DEFINING) sp->s_flags |= SYMDEF; sp->s_frag = genfrag--; - return(sp); + return (sp); } -num_p numlookup(number) unsigned number; { +num_p numlookup(unsigned number) +{ register num_p *npp, np; - npp = &curpro.numhash[number%NNUMHASH]; + npp = &curpro.numhash[number % NNUMHASH]; while (*npp != (num_p) 0) if ((*npp)->n_number == number) - return(*npp); + return (*npp); else npp = &(*npp)->n_next; @@ -82,5 +84,5 @@ num_p numlookup(number) unsigned number; { *npp = np = newnum(); np->n_number = number; np->n_repl = np; - return(np); + return (np); } diff --git a/util/opt/lookup.h b/util/opt/lookup.h index 194c4501d..e37efa8e5 100644 --- a/util/opt/lookup.h +++ b/util/opt/lookup.h @@ -2,7 +2,10 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ +#ifndef LOOKUP_H_ +#define LOOKUP_H_ + +#include "types.h" #define IDL 100 @@ -28,3 +31,14 @@ extern sym_p symhash[NSYMHASH],symlookup(); #define OCCURRING 0 #define DEFINING 1 #define NOTHING 2 + +/** Return the hash value of the specified string. */ +unsigned hash(char *string); +num_p numlookup(unsigned number); +/** Search the hash table for the specified name + * and symbol type specified in `flags`. + */ +sym_p symlookup(char *name, int status, int flags); + + +#endif /* LOOKUP_H_ */ diff --git a/util/opt/main.c b/util/opt/main.c index a3df98a73..2856ffd33 100644 --- a/util/opt/main.c +++ b/util/opt/main.c @@ -1,72 +1,99 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - -#include -#include -#include "param.h" -#include "types.h" -#include "tes.h" -#include "alloc.h" -#include -#include "ext.h" - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". * * Author: Hans van Staveren */ +#include +#include +#include "param.h" +#include "types.h" +#include "tes.h" +#include "alloc.h" +#include "system.h" +#include +#include "ext.h" +#include "util.h" +#include "getline.h" +#include "putline.h" + +/* Other external definitions */ +extern void cleanup(void); + +void flags(register char *s) +{ + for (s++; *s; s++) + switch (*s) + { + case 'L': + Lflag = TRUE; + break; + case 'n': + nflag = TRUE; + break; + case 'm': + if (*(s + 1) == 'l') + { + s++; + repl_longmuls = TRUE; + } + repl_muls = atoi(s + 1); + break; + } +} + +void fileinit(void) +{ + if (readshort() != (short) sp_magic) + error("wrong input file"); + if (Lflag) + { + + if (sys_tmpnam(tempname)==NULL) + { + error("can't create temporary file."); + } + outfile = fopen(tempname, "wb"); + if (outfile == NULL) + error("can't create %s", tempname); + } + else + { + outfile = stdout; + outshort(sp_magic); + } +} + /* * Main program for EM optimizer */ -main(argc,argv) int argc; char *argv[]; { +int main(int argc, char* argv[]) +{ +#ifndef USEMALLOC int somespace[STACKROOM]; +#endif progname = argv[0]; - while (argc-->1 && **++argv == '-') + while (argc-- > 1 && **++argv == '-') flags(*argv); - if (argc>1) { - fprintf(stderr,"Usage: %s [-Ln] [-m] [name]\n",progname); - exit(-1); + if (argc > 1) + { + fprintf(stderr, "Usage: %s [-Ln] [-m] [name]\n", progname); + exit(EXIT_FAILURE); } if (argc) - if (freopen(*argv,"r",stdin) == NULL) - error("Cannot open %s",*argv); + if (freopen(*argv, "r", stdin) == NULL) + error("Cannot open %s", *argv); fileinit(); - coreinit((short *)somespace,(short *)(somespace+STACKROOM)); +#ifdef USEMALLOC + coreinit(); +#else + coreinit((short *) somespace, (short *) (somespace + STACKROOM)); +#endif getlines(); cleanup(); - return(0); + return (EXIT_SUCCESS); } -flags(s) register char *s; { - - for (s++;*s;s++) - switch(*s) { - case 'L': Lflag = TRUE; break; - case 'n': nflag = TRUE; break; - case 'm': if (*(s+1) == 'l') { - s++; - repl_longmuls = TRUE; - } - repl_muls = atoi(s+1); break; - } -} - -fileinit() { - short readshort(); - - if (readshort() != (short) sp_magic) - error("wrong input file"); - if (Lflag) { - outfile = fdopen(mkstemp(template),"w"); - if (outfile == NULL) - error("can't create %s",template); - } else { - outfile = stdout; - outshort(sp_magic); - } -} diff --git a/util/opt/mktab.y b/util/opt/mktab.y index 7208919c5..d2e39d5f2 100644 --- a/util/opt/mktab.y +++ b/util/opt/mktab.y @@ -1,8 +1,10 @@ %{ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include #include @@ -13,12 +15,7 @@ static char rcsid[] = "$Id$"; #include #include "optim.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ + #define op_CBO (op_plast+1) @@ -48,6 +45,22 @@ int CBO_instrs[] = { int patCBO; int rplCBO; + +/* Forward declarations */ +void inithash(void); +unsigned hashname(register char *name); +void enter(char *name,int value); +int mlookup(char* name); +int lookup(int comm,int operator,int lnode,int rnode); +void printnodes(void); +void initio(void); +void outpat(int exprno, int instrno); +void outbyte(int b); +void outshort(int s); +void out(int w); +int yylex(void); +void yyerror(const char*); + %} %union { @@ -241,8 +254,9 @@ struct hashmnem { byte h_value; } hashmnem[HASHSIZE]; -inithash() { - register i; +void inithash(void) +{ + register int i; enter("lab",op_lab); enter("LLP",op_LLP); @@ -254,7 +268,8 @@ inithash() { enter(em_mnem[i],i+sp_fmnem); } -unsigned hashname(name) register char *name; { +unsigned hashname(register char *name) +{ register unsigned h; h = (*name++)&BMASK; @@ -263,7 +278,8 @@ unsigned hashname(name) register char *name; { return(h); } -enter(name,value) char *name; { +void enter(char *name,int value) +{ register unsigned h; h=hashname(name)%HASHSIZE; @@ -273,7 +289,8 @@ enter(name,value) char *name; { hashmnem[h].h_value = value; } -int mlookup(name) char *name; { +int mlookup(char* name) +{ register unsigned h; h = hashname(name)%HASHSIZE; @@ -283,8 +300,8 @@ int mlookup(name) char *name; { return(hashmnem[h].h_value&BMASK); /* 0 if not found */ } -main() { - +int main(void) +{ inithash(); initio(); yyparse(); @@ -293,24 +310,26 @@ main() { return nerrors; } -int yywrap(void) { +int yywrap(void) +{ return 1; } -yyerror(s) char *s; { - +void yyerror(const char *s) +{ fprintf(stderr,"line %d: %s\n",lino,s); nerrors++; } -lookup(comm,operator,lnode,rnode) { +int lookup(int comm,int operator,int lnode,int rnode) { + register expr_p p; for (p=nodes+1;pex_operator != operator) continue; - if (!(p->ex_lnode == lnode && p->ex_rnode == rnode || - comm && p->ex_lnode == rnode && p->ex_rnode == lnode)) + if (!((p->ex_lnode == lnode && p->ex_rnode == rnode) || + (comm && p->ex_lnode == rnode && p->ex_rnode == lnode))) continue; return(p-nodes); } @@ -323,20 +342,22 @@ lookup(comm,operator,lnode,rnode) { return(p-nodes); } -printnodes() { +void printnodes(void) +{ register expr_p p; printf("};\n\nshort lastind = %d;\n\nexpr_t enodes[] = {\n",prevind); for (p=nodes;pex_operator,p->ex_lnode,p->ex_rnode); printf("};\n\niarg_t iargs[%d];\n", (maxpatlen>0 ? maxpatlen : 1)); if (patid[0]) printf("static char rcsid[] = %s;\n",patid); } -initio() { - register i; +void initio(void) +{ + register int i; printf("#include \"param.h\"\n#include \"types.h\"\n"); printf("#include \"pattern.h\"\n\n"); @@ -377,7 +398,7 @@ initio() { curind = 1; } -outpat(exprno, instrno) +void outpat(int exprno, int instrno) { register int i; @@ -403,20 +424,20 @@ outpat(exprno, instrno) if (patlen>maxpatlen) maxpatlen=patlen; } -outbyte(b) { - +void outbyte(int b) +{ printf(",%3d",b); curind++; } -outshort(s) { - +void outshort(int s) +{ outbyte(s&0377); outbyte((s>>8)&0377); } -out(w) { - +void out(int w) +{ if (w<255) { outbyte(w); } else { diff --git a/util/opt/patterns b/util/opt/patterns index 34bcc760a..58f5204f9 100644 --- a/util/opt/patterns +++ b/util/opt/patterns @@ -1,4 +1,4 @@ -"$Id$" + inc dec: inc loc adi $3==w: loc $2+1 adi w inc loc sbi $3==w: loc $2-1 sbi w diff --git a/util/opt/peephole.c b/util/opt/peephole.c index 9ad466ad2..ba310388f 100644 --- a/util/opt/peephole.c +++ b/util/opt/peephole.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include "param.h" #include "types.h" @@ -10,39 +12,42 @@ static char rcsid[] = "$Id$"; #include "lookup.h" #include "proinf.h" #include "alloc.h" +#include "reg.h" #include "pattern.h" #include #include #include "optim.h" #include "ext.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ - #undef CHK_HASH /* print numbers patterns are hashed to */ #ifdef CHK_HASH #include #endif #define ILLHASH 0177777 -short pathash[256]; /* table of indices into pattern[] */ +short pathash[256]; /* table of indices into pattern[] */ -int opind = 0; /* second index of next matrix */ -byte transl[op_plast-op_pfirst+1][3] = { - /* LLP */ { op_LLP, op_lol, op_ldl }, - /* LEP */ { op_LEP, op_loe, op_lde }, - /* SLP */ { op_SLP, op_stl, op_sdl }, - /* SEP */ { op_SEP, op_ste, op_sde } -}; +int opind = 0; /* second index of next matrix */ +byte transl[op_plast - op_pfirst + 1][3] = +{ +/* LLP */ +{ op_LLP, op_lol, op_ldl }, +/* LEP */ +{ op_LEP, op_loe, op_lde }, +/* SLP */ +{ op_SLP, op_stl, op_sdl }, +/* SEP */ +{ op_SEP, op_ste, op_sde } }; -opcheck(bp) register byte *bp; { +/* Forward declarations */ +static int repl_mul(register line_p, line_p *, line_p *); +static int optimize(void); +static int basicblock(line_p *); - if (((*bp)&BMASK) >= op_pfirst) - *bp = transl[((*bp)&BMASK)-op_pfirst][opind]; +static void opcheck(register byte *bp) +{ + if (((*bp) & BMASK) >= op_pfirst) + *bp = transl[((*bp) & BMASK) - op_pfirst][opind]; } /* @@ -54,41 +59,46 @@ opcheck(bp) register byte *bp; { * Estimated improvement possible: about 2% */ -hashpatterns() { +static void hashpatterns(void) +{ short index; - register byte *bp,*tp; + register byte *bp, *tp; register short i; unsigned short hashvalue; byte *save; int patlen; if (pointersize == wordsize) - opind=1; - else if (pointersize == 2*wordsize) - opind=2; - index = lastind; /* set by mktab */ - while (index != 0) { + opind = 1; + else if (pointersize == 2 * wordsize) + opind = 2; + index = lastind; /* set by mktab */ + while (index != 0) + { bp = &pattern[index]; tp = &bp[PO_MATCH]; - i = *tp++&BMASK; - if (i==BMASK) { - i = *tp++&BMASK; - i |= (*tp++&BMASK)<<8; + i = *tp++ & BMASK; + if (i == BMASK) + { + i = *tp++ & BMASK; + i |= (*tp++ & BMASK) << 8; } save = tp; patlen = i; while (i--) opcheck(tp++); - if ((*tp++&BMASK)==BMASK) + if ((*tp++ & BMASK) == BMASK) tp += 2; - i = *tp++&BMASK; - if (i==BMASK) { - i = *tp++&BMASK; - i |= (*tp++&BMASK)<<8; + i = *tp++ & BMASK; + if (i == BMASK) + { + i = *tp++ & BMASK; + i |= (*tp++ & BMASK) << 8; } - while (i--) { + while (i--) + { opcheck(tp++); - if ((*tp++&BMASK)==BMASK) + if ((*tp++ & BMASK) == BMASK) tp += 2; } @@ -99,21 +109,22 @@ hashpatterns() { hashvalue = 0; tp = save; - switch(patlen) { - default: /* 3 or more */ - hashvalue = (hashvalue<<4)^(*tp++&BMASK); - case 2: - hashvalue = (hashvalue<<4)^(*tp++&BMASK); - case 1: - hashvalue = (hashvalue<<4)^(*tp++&BMASK); + switch (patlen) + { + default: /* 3 or more */ + hashvalue = (hashvalue << 4) ^ (*tp++ & BMASK); + case 2: + hashvalue = (hashvalue << 4) ^ (*tp++ & BMASK); + case 1: + hashvalue = (hashvalue << 4) ^ (*tp++ & BMASK); } assert(hashvalue!= ILLHASH); - i=index; - index = (bp[PO_NEXT]&BMASK)|(bp[PO_NEXT+1]<<8); - bp[PO_HASH] = hashvalue>>8; + i = index; + index = (bp[PO_NEXT] & BMASK) | (bp[PO_NEXT + 1] << 8); + bp[PO_HASH] = hashvalue >> 8; hashvalue &= BMASK; - bp[PO_NEXT] = pathash[hashvalue]&BMASK; - bp[PO_NEXT+1] = pathash[hashvalue]>>8; + bp[PO_NEXT] = pathash[hashvalue] & BMASK; + bp[PO_NEXT + 1] = pathash[hashvalue] >> 8; pathash[hashvalue] = i; #ifdef CHK_HASH fprintf(stderr,"%d\n",hashvalue); @@ -121,352 +132,386 @@ hashpatterns() { } } -peephole() { +int peephole(void) +{ static bool phashed = FALSE; - if (!phashed) { + if (!phashed) + { hashpatterns(); - phashed=TRUE; + phashed = TRUE; } return optimize(); } -optimize() { - register num_p *npp,np; - register instr; +static int optimize(void) +{ + register num_p *npp, np; + register int instr; bool madeopt; madeopt = basicblock(&instrs); - for (npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++) - for (np = *npp; np != (num_p) 0; np=np->n_next) { - if (! np->n_line) continue; - if(np->n_line->l_next == (line_p) 0) + for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) + for (np = *npp; np != (num_p) 0; np = np->n_next) + { + if (!np->n_line) continue; - instr = np->n_line->l_next->l_instr&BMASK; + if (np->n_line->l_next == (line_p) 0) + continue; + instr = np->n_line->l_next->l_instr & BMASK; if (instr == op_lab || instr == op_bra) np->n_repl = np->n_line->l_next->l_a.la_np; - else - if (basicblock(&np->n_line->l_next)) - madeopt = TRUE; + else if (basicblock(&np->n_line->l_next)) + madeopt = TRUE; } return madeopt; } -offset oabs(off) offset off; { +static offset oabs(offset off) +{ - return(off >= 0 ? off : -off); + return (off >= 0 ? off : -off); } -line_p repline(ev,patlen) eval_t ev; { +static line_p repline(eval_t ev, int patlen) +{ register line_p lp; register iarg_p iap; register sym_p sp; - offset diff,newdiff; + offset diff, newdiff; assert(ev.e_typ != EV_UNDEF); - switch(ev.e_typ) { - case EV_CONST: - if ((short) ev.e_v.e_con == ev.e_v.e_con) { - if (CANMINI((short) ev.e_v.e_con)) - lp = newline((short) (ev.e_v.e_con)+Z_OPMINI); - else { - lp = newline(OPSHORT); - lp->l_a.la_short = (short) ev.e_v.e_con; - } - } else { - lp = newline(OPOFFSET); - lp->l_a.la_offset = ev.e_v.e_con; - } - return(lp); - case EV_NUMLAB: - lp = newline(OPNUMLAB); - lp->l_a.la_np = ev.e_v.e_np; - return(lp); - default: /* fragment + offset */ - /* - * There is a slight problem here, because we have to - * map fragment+offset to symbol+offset. - * Fortunately the fragment we have must be the fragment - * of one of the symbols in the matchpattern. - * So a short search should do the job. - */ - sp = (sym_p) 0; - for (iap= &iargs[patlen-1]; iap >= iargs; iap--) - if (iap->ia_ev.e_typ == ev.e_typ) { - /* - * Although lint complains, diff is not used - * before set. - * - * The proof is left as an exercise to the - * reader. - */ - newdiff = oabs(iap->ia_sp->s_value-ev.e_v.e_con); - if (sp==(sym_p) 0 || newdiff < diff) { - sp = iap->ia_sp; - diff = newdiff; + switch (ev.e_typ) + { + case EV_CONST: + if ((short) ev.e_v.e_con == ev.e_v.e_con) + { + if (CANMINI((short ) ev.e_v.e_con)) + lp = newline((short) (ev.e_v.e_con) + Z_OPMINI); + else + { + lp = newline(OPSHORT); + lp->l_a.la_short = (short) ev.e_v.e_con; } } - assert(sp != (sym_p) 0); - if (diff == 0) { - lp = newline(OPSYMBOL); - lp->l_a.la_sp = sp; - } else { - diff = ev.e_v.e_con - sp->s_value; - if ((short) diff == diff) { - lp = newline(OPSVAL); - lp->l_a.la_sval.lasv_short = (short) diff; - lp->l_a.la_sval.lasv_sp = sp; - } else { - lp = newline(OPLVAL); - lp->l_a.la_lval.lalv_offset = diff; - lp->l_a.la_lval.lalv_sp = sp; + else + { + lp = newline(OPOFFSET); + lp->l_a.la_offset = ev.e_v.e_con; } - } - return(lp); + return (lp); + case EV_NUMLAB: + lp = newline(OPNUMLAB); + lp->l_a.la_np = ev.e_v.e_np; + return (lp); + default: /* fragment + offset */ + /* + * There is a slight problem here, because we have to + * map fragment+offset to symbol+offset. + * Fortunately the fragment we have must be the fragment + * of one of the symbols in the matchpattern. + * So a short search should do the job. + */ + sp = (sym_p) 0; + for (iap = &iargs[patlen - 1]; iap >= iargs; iap--) + if (iap->ia_ev.e_typ == ev.e_typ) + { + /* + * Although lint complains, diff is not used + * before set. + * + * The proof is left as an exercise to the + * reader. + */ + newdiff = oabs(iap->ia_sp->s_value - ev.e_v.e_con); + if (sp == (sym_p) 0 || newdiff < diff) + { + sp = iap->ia_sp; + diff = newdiff; + } + } + assert(sp != (sym_p ) 0); + if (diff == 0) + { + lp = newline(OPSYMBOL); + lp->l_a.la_sp = sp; + } + else + { + diff = ev.e_v.e_con - sp->s_value; + if ((short) diff == diff) + { + lp = newline(OPSVAL); + lp->l_a.la_sval.lasv_short = (short) diff; + lp->l_a.la_sval.lasv_sp = sp; + } + else + { + lp = newline(OPLVAL); + lp->l_a.la_lval.lalv_offset = diff; + lp->l_a.la_lval.lalv_sp = sp; + } + } + return (lp); } } -offset rotate(w,amount) offset w,amount; { - offset highmask,lowmask; +static offset rotate(offset w, offset amount) +{ + offset highmask, lowmask; #ifndef LONGOFF assert(wordsize<=4); #endif - highmask = (offset)(-1) << amount; + highmask = (offset) (-1) << amount; lowmask = ~highmask; if (wordsize != 4) - highmask &= wordsize==2 ? 0xFFFF : 0xFF; - return(((w<>(8*wordsize-amount))&lowmask)); + highmask &= wordsize == 2 ? 0xFFFF : 0xFF; + return (((w << amount) & highmask) + | ((w >> (8 * wordsize - amount)) & lowmask)); } -eval_t undefres = { EV_UNDEF }; +eval_t undefres = +{ EV_UNDEF }; -eval_t compute(pexp) register expr_p pexp; { - eval_t leaf1,leaf2,res; - register i; +static eval_t compute(register expr_p pexp) +{ + eval_t leaf1, leaf2, res; + register int i; register sym_p sp; offset mask; - switch(nparam[pexp->ex_operator]) { - default: - assert(FALSE); - case 2: - leaf2 = compute(&enodes[pexp->ex_rnode]); - if (leaf2.e_typ == EV_UNDEF || - nonumlab[pexp->ex_operator] && leaf2.e_typ == EV_NUMLAB || - onlyconst[pexp->ex_operator] && leaf2.e_typ != EV_CONST) - return(undefres); - case 1: - leaf1 = compute(&enodes[pexp->ex_lnode]); - if (leaf1.e_typ == EV_UNDEF || - nonumlab[pexp->ex_operator] && leaf1.e_typ == EV_NUMLAB || - onlyconst[pexp->ex_operator] && leaf1.e_typ != EV_CONST) - return(undefres); - case 0: - break; + switch (nparam[pexp->ex_operator]) + { + default: + assert(FALSE); + case 2: + leaf2 = compute(&enodes[pexp->ex_rnode]); + if (leaf2.e_typ == EV_UNDEF + || (nonumlab[pexp->ex_operator] && leaf2.e_typ == EV_NUMLAB) + || (onlyconst[pexp->ex_operator] && leaf2.e_typ != EV_CONST)) + return (undefres); + case 1: + leaf1 = compute(&enodes[pexp->ex_lnode]); + if (leaf1.e_typ == EV_UNDEF + || (nonumlab[pexp->ex_operator] && leaf1.e_typ == EV_NUMLAB) + || (onlyconst[pexp->ex_operator] && leaf1.e_typ != EV_CONST)) + return (undefres); + case 0: + break; } res.e_typ = EV_CONST; res.e_v.e_con = 0; - switch(pexp->ex_operator) { - default: - assert(FALSE); - case EX_CON: - res.e_v.e_con = (offset) pexp->ex_lnode; - break; - case EX_ARG: - return(iargs[pexp->ex_lnode - 1].ia_ev); - case EX_CMPEQ: - if (leaf1.e_typ != leaf2.e_typ) - return(undefres); - if (leaf1.e_typ == EV_NUMLAB) { - if (leaf1.e_v.e_np == leaf2.e_v.e_np) + switch (pexp->ex_operator) + { + default: + assert(FALSE); + break; + case EX_CON: + res.e_v.e_con = (offset) pexp->ex_lnode; + break; + case EX_ARG: + return (iargs[pexp->ex_lnode - 1].ia_ev); + case EX_CMPEQ: + if (leaf1.e_typ != leaf2.e_typ) + return (undefres); + if (leaf1.e_typ == EV_NUMLAB) + { + if (leaf1.e_v.e_np == leaf2.e_v.e_np) + res.e_v.e_con = 1; + break; + } + if (leaf1.e_v.e_con == leaf2.e_v.e_con) res.e_v.e_con = 1; break; - } - if (leaf1.e_v.e_con == leaf2.e_v.e_con) - res.e_v.e_con = 1; - break; - case EX_CMPNE: - if (leaf1.e_typ != leaf2.e_typ) { - res.e_v.e_con = 1; - break; - } - if (leaf1.e_typ == EV_NUMLAB) { - if (leaf1.e_v.e_np != leaf2.e_v.e_np) + case EX_CMPNE: + if (leaf1.e_typ != leaf2.e_typ) + { + res.e_v.e_con = 1; + break; + } + if (leaf1.e_typ == EV_NUMLAB) + { + if (leaf1.e_v.e_np != leaf2.e_v.e_np) + res.e_v.e_con = 1; + break; + } + if (leaf1.e_v.e_con != leaf2.e_v.e_con) res.e_v.e_con = 1; break; - } - if (leaf1.e_v.e_con != leaf2.e_v.e_con) - res.e_v.e_con = 1; - break; - case EX_CMPGT: - if (leaf1.e_typ != leaf2.e_typ) - return(undefres); - res.e_v.e_con = leaf1.e_v.e_con > leaf2.e_v.e_con; - break; - case EX_CMPGE: - if (leaf1.e_typ != leaf2.e_typ) - return(undefres); - res.e_v.e_con = leaf1.e_v.e_con >= leaf2.e_v.e_con; - break; - case EX_CMPLT: - if (leaf1.e_typ != leaf2.e_typ) - return(undefres); - res.e_v.e_con = leaf1.e_v.e_con < leaf2.e_v.e_con; - break; - case EX_CMPLE: - if (leaf1.e_typ != leaf2.e_typ) - return(undefres); - res.e_v.e_con = leaf1.e_v.e_con <= leaf2.e_v.e_con; - break; - case EX_OR2: - if (leaf1.e_v.e_con != 0) - return(leaf1); - leaf2 = compute(&enodes[pexp->ex_rnode]); - if (leaf2.e_typ != EV_CONST) - return(undefres); - return(leaf2); - case EX_AND2: - if (leaf1.e_v.e_con == 0) - return(leaf1); - leaf2 = compute(&enodes[pexp->ex_rnode]); - if (leaf2.e_typ != EV_CONST) - return(undefres); - return(leaf2); - case EX_OR1: - res.e_v.e_con = leaf1.e_v.e_con | leaf2.e_v.e_con; - break; - case EX_XOR1: - res.e_v.e_con = leaf1.e_v.e_con ^ leaf2.e_v.e_con; - break; - case EX_AND1: - res.e_v.e_con = leaf1.e_v.e_con & leaf2.e_v.e_con; - break; - case EX_TIMES: - res.e_v.e_con = leaf1.e_v.e_con * leaf2.e_v.e_con; - break; - case EX_DIVIDE: - res.e_v.e_con = leaf1.e_v.e_con / leaf2.e_v.e_con; - break; - case EX_MOD: - res.e_v.e_con = leaf1.e_v.e_con % leaf2.e_v.e_con; - break; - case EX_LSHIFT: - res.e_v.e_con = leaf1.e_v.e_con << leaf2.e_v.e_con; - break; - case EX_RSHIFT: - res.e_v.e_con = leaf1.e_v.e_con >> leaf2.e_v.e_con; - break; - case EX_UMINUS: - res.e_v.e_con = -leaf1.e_v.e_con; - break; - case EX_NOT: - res.e_v.e_con = !leaf1.e_v.e_con; - break; - case EX_COMP: - res.e_v.e_con = ~leaf1.e_v.e_con; - break; - case EX_PLUS: - if (leaf1.e_typ >= EV_FRAG) { - if (leaf2.e_typ >= EV_FRAG) - return(undefres); - res.e_typ = leaf1.e_typ; - } else - res.e_typ = leaf2.e_typ; - res.e_v.e_con = leaf1.e_v.e_con + leaf2.e_v.e_con; - break; - case EX_MINUS: - if (leaf1.e_typ >= EV_FRAG) { - if (leaf2.e_typ == EV_CONST) - res.e_typ = leaf1.e_typ; - else if (leaf2.e_typ != leaf1.e_typ) - return(undefres); - } else if (leaf2.e_typ >= EV_FRAG) - return(undefres); - res.e_v.e_con = leaf1.e_v.e_con - leaf2.e_v.e_con; - break; - case EX_POINTERSIZE: - res.e_v.e_con = pointersize; - break; - case EX_WORDSIZE: - res.e_v.e_con = wordsize; - break; - case EX_NOTREG: - res.e_v.e_con = !inreg(leaf1.e_v.e_con); - break; - case EX_DEFINED: - leaf1 = compute(&enodes[pexp->ex_lnode]); - res.e_v.e_con = leaf1.e_typ != EV_UNDEF; - break; - case EX_SAMESIGN: - res.e_v.e_con = (leaf1.e_v.e_con ^ leaf2.e_v.e_con) >= 0; - break; - case EX_ROM: - if ((sp = iargs[pexp->ex_lnode - 1].ia_sp) != (sym_p) 0 && - sp->s_rom != (offset *) 0) { + case EX_CMPGT: + if (leaf1.e_typ != leaf2.e_typ) + return (undefres); + res.e_v.e_con = leaf1.e_v.e_con > leaf2.e_v.e_con; + break; + case EX_CMPGE: + if (leaf1.e_typ != leaf2.e_typ) + return (undefres); + res.e_v.e_con = leaf1.e_v.e_con >= leaf2.e_v.e_con; + break; + case EX_CMPLT: + if (leaf1.e_typ != leaf2.e_typ) + return (undefres); + res.e_v.e_con = leaf1.e_v.e_con < leaf2.e_v.e_con; + break; + case EX_CMPLE: + if (leaf1.e_typ != leaf2.e_typ) + return (undefres); + res.e_v.e_con = leaf1.e_v.e_con <= leaf2.e_v.e_con; + break; + case EX_OR2: + if (leaf1.e_v.e_con != 0) + return (leaf1); leaf2 = compute(&enodes[pexp->ex_rnode]); - if (leaf2.e_typ != EV_CONST || - leaf2.e_v.e_con < 0 || - leaf2.e_v.e_con >= MAXROM) - return(undefres); - res.e_v.e_con = sp->s_rom[(int)(leaf2.e_v.e_con)]; + if (leaf2.e_typ != EV_CONST) + return (undefres); + return (leaf2); + case EX_AND2: + if (leaf1.e_v.e_con == 0) + return (leaf1); + leaf2 = compute(&enodes[pexp->ex_rnode]); + if (leaf2.e_typ != EV_CONST) + return (undefres); + return (leaf2); + case EX_OR1: + res.e_v.e_con = leaf1.e_v.e_con | leaf2.e_v.e_con; + break; + case EX_XOR1: + res.e_v.e_con = leaf1.e_v.e_con ^ leaf2.e_v.e_con; + break; + case EX_AND1: + res.e_v.e_con = leaf1.e_v.e_con & leaf2.e_v.e_con; + break; + case EX_TIMES: + res.e_v.e_con = leaf1.e_v.e_con * leaf2.e_v.e_con; + break; + case EX_DIVIDE: + res.e_v.e_con = leaf1.e_v.e_con / leaf2.e_v.e_con; + break; + case EX_MOD: + res.e_v.e_con = leaf1.e_v.e_con % leaf2.e_v.e_con; + break; + case EX_LSHIFT: + res.e_v.e_con = leaf1.e_v.e_con << leaf2.e_v.e_con; + break; + case EX_RSHIFT: + res.e_v.e_con = leaf1.e_v.e_con >> leaf2.e_v.e_con; + break; + case EX_UMINUS: + res.e_v.e_con = -leaf1.e_v.e_con; + break; + case EX_NOT: + res.e_v.e_con = !leaf1.e_v.e_con; + break; + case EX_COMP: + res.e_v.e_con = ~leaf1.e_v.e_con; + break; + case EX_PLUS: + if (leaf1.e_typ >= EV_FRAG) + { + if (leaf2.e_typ >= EV_FRAG) + return (undefres); + res.e_typ = leaf1.e_typ; + } + else + res.e_typ = leaf2.e_typ; + res.e_v.e_con = leaf1.e_v.e_con + leaf2.e_v.e_con; + break; + case EX_MINUS: + if (leaf1.e_typ >= EV_FRAG) + { + if (leaf2.e_typ == EV_CONST) + res.e_typ = leaf1.e_typ; + else if (leaf2.e_typ != leaf1.e_typ) + return (undefres); + } + else if (leaf2.e_typ >= EV_FRAG) + return (undefres); + res.e_v.e_con = leaf1.e_v.e_con - leaf2.e_v.e_con; + break; + case EX_POINTERSIZE: + res.e_v.e_con = pointersize; + break; + case EX_WORDSIZE: + res.e_v.e_con = wordsize; + break; + case EX_NOTREG: + res.e_v.e_con = !inreg(leaf1.e_v.e_con); + break; + case EX_DEFINED: + leaf1 = compute(&enodes[pexp->ex_lnode]); + res.e_v.e_con = leaf1.e_typ != EV_UNDEF; + break; + case EX_SAMESIGN: + res.e_v.e_con = (leaf1.e_v.e_con ^ leaf2.e_v.e_con) >= 0; + break; + case EX_ROM: + if ((sp = iargs[pexp->ex_lnode - 1].ia_sp) != (sym_p) 0 + && sp->s_rom != (offset *) 0) + { + leaf2 = compute(&enodes[pexp->ex_rnode]); + if (leaf2.e_typ != EV_CONST || leaf2.e_v.e_con < 0|| + leaf2.e_v.e_con >= MAXROM) + return (undefres); + res.e_v.e_con = sp->s_rom[(int) (leaf2.e_v.e_con)]; + break; + } + else + return (undefres); + case EX_SFIT: + mask = 0; + for (i = leaf2.e_v.e_con - 1; i < (int)(8 * sizeof(offset)); i++) + mask |= ((offset) 1) << i; + res.e_v.e_con = (leaf1.e_v.e_con & mask) == 0 + || (leaf1.e_v.e_con & mask) == mask; + break; + case EX_UFIT: + mask = 0; + for (i = leaf2.e_v.e_con; i < (int)(8 * sizeof(offset)); i++) + mask |= ((offset) 1) << i; + res.e_v.e_con = (leaf1.e_v.e_con & mask) == 0; + break; + case EX_ROTATE: + res.e_v.e_con = rotate(leaf1.e_v.e_con, leaf2.e_v.e_con); break; - } else - return(undefres); - case EX_SFIT: - mask = 0; - for (i=leaf2.e_v.e_con - 1;i < 8*sizeof(offset); i++) - mask |= ((offset)1)<0;patlen--,tp=lp,lp=lp->l_next) + for (lp = *lpp; patlen > 0; patlen--, tp = lp, lp = lp->l_next) ; tp->l_next = (line_p) 0; *rlpp = lp; lp = *lpp; *lpp = replacement; - while ( lp != (line_p) 0 ) { + while (lp != (line_p) 0) + { tp = lp->l_next; oldline(lp); lp = tp; } - return(TRUE); + return (TRUE); } -bool trypat(lpp,bp,len) -line_p *lpp; -register byte *bp; -int len; +static bool trypat(line_p *lpp, register byte *bp, int len) { register iarg_p iap; - int i,patlen; + int i, patlen; register line_p lp; eval_t result; - patlen = *bp++&BMASK; - if (patlen == BMASK) { - patlen = *bp++&BMASK; - patlen |= (*bp++&BMASK)<<8; + patlen = *bp++ & BMASK; + if (patlen == BMASK) + { + patlen = *bp++ & BMASK; + patlen |= (*bp++ & BMASK) << 8; } - if (len == 3) { - if (patlen<3) - return(FALSE); - } else { + if (len == 3) + { + if (patlen < 3) + return (FALSE); + } + else + { if (patlen != len) - return(FALSE); + return (FALSE); } /* * Length is ok, now check opcodes */ - for (i=0,lp= *lpp;il_next) + for (i = 0, lp = *lpp; i < patlen && lp != (line_p) 0; i++, lp = lp->l_next) if (lp->l_instr != *bp++) - return(FALSE); + return (FALSE); if (i != patlen) - return(FALSE); + return (FALSE); /* * opcodes are also correct, now comes the hard part */ - for(i=0,lp= *lpp,iap= iargs; il_next) { - switch(lp->l_optyp) { - case OPNO: - iap->ia_ev.e_typ = EV_UNDEF; - break; - default: - iap->ia_ev.e_typ = EV_CONST; - iap->ia_ev.e_v.e_con = (lp->l_optyp&BMASK)-Z_OPMINI; - break; - case OPSHORT: - iap->ia_ev.e_typ = EV_CONST; - iap->ia_ev.e_v.e_con = lp->l_a.la_short; - break; + for (i = 0, lp = *lpp, iap = iargs; i < patlen; i++, iap++, lp = lp->l_next) + { + switch (lp->l_optyp) + { + case OPNO: + iap->ia_ev.e_typ = EV_UNDEF; + break; + default: + iap->ia_ev.e_typ = EV_CONST; + iap->ia_ev.e_v.e_con = (lp->l_optyp & BMASK) - Z_OPMINI; + break; + case OPSHORT: + iap->ia_ev.e_typ = EV_CONST; + iap->ia_ev.e_v.e_con = lp->l_a.la_short; + break; #ifdef LONGOFF - case OPOFFSET: - iap->ia_ev.e_typ = EV_CONST; - iap->ia_ev.e_v.e_con = lp->l_a.la_offset; - break; + case OPOFFSET: + iap->ia_ev.e_typ = EV_CONST; + iap->ia_ev.e_v.e_con = lp->l_a.la_offset; + break; #endif - case OPNUMLAB: - iap->ia_ev.e_typ = EV_NUMLAB; - iap->ia_ev.e_v.e_np = lp->l_a.la_np; - break; - case OPSYMBOL: - iap->ia_ev.e_typ = lp->l_a.la_sp->s_frag; - iap->ia_sp = lp->l_a.la_sp; - iap->ia_ev.e_v.e_con = lp->l_a.la_sp->s_value; - break; - case OPSVAL: - iap->ia_ev.e_typ = lp->l_a.la_sval.lasv_sp->s_frag; - iap->ia_sp = lp->l_a.la_sval.lasv_sp; - iap->ia_ev.e_v.e_con = lp->l_a.la_sval.lasv_sp->s_value + lp->l_a.la_sval.lasv_short; - break; + case OPNUMLAB: + iap->ia_ev.e_typ = EV_NUMLAB; + iap->ia_ev.e_v.e_np = lp->l_a.la_np; + break; + case OPSYMBOL: + iap->ia_ev.e_typ = lp->l_a.la_sp->s_frag; + iap->ia_sp = lp->l_a.la_sp; + iap->ia_ev.e_v.e_con = lp->l_a.la_sp->s_value; + break; + case OPSVAL: + iap->ia_ev.e_typ = lp->l_a.la_sval.lasv_sp->s_frag; + iap->ia_sp = lp->l_a.la_sval.lasv_sp; + iap->ia_ev.e_v.e_con = lp->l_a.la_sval.lasv_sp->s_value + + lp->l_a.la_sval.lasv_short; + break; #ifdef LONGOFF - case OPLVAL: - iap->ia_ev.e_typ = lp->l_a.la_lval.lalv_sp->s_frag; - iap->ia_sp = lp->l_a.la_lval.lalv_sp; - iap->ia_ev.e_v.e_con = lp->l_a.la_lval.lalv_sp->s_value + lp->l_a.la_lval.lalv_offset; - break; + case OPLVAL: + iap->ia_ev.e_typ = lp->l_a.la_lval.lalv_sp->s_frag; + iap->ia_sp = lp->l_a.la_lval.lalv_sp; + iap->ia_ev.e_v.e_con = lp->l_a.la_lval.lalv_sp->s_value + + lp->l_a.la_lval.lalv_offset; + break; #endif } } - i = *bp++&BMASK; - if ( i==BMASK ) { - i = *bp++&BMASK; - i |= (*bp++&BMASK)<<8; + i = *bp++ & BMASK; + if (i == BMASK) + { + i = *bp++ & BMASK; + i |= (*bp++ & BMASK) << 8; } - if ( i != 0) { + if (i != 0) + { /* there is a condition */ result = compute(&enodes[i]); if (result.e_typ != EV_CONST || result.e_v.e_con == 0) - return(FALSE); + return (FALSE); } - return(tryrepl(lpp,bp,patlen)); + return (tryrepl(lpp, bp, patlen)); } -int -basicblock(alpp) line_p *alpp; { - register line_p *lpp,lp; +static int basicblock(line_p *alpp) +{ + register line_p *lpp, lp; unsigned short hash[3]; line_p *next; register byte *bp; @@ -606,20 +658,25 @@ basicblock(alpp) line_p *alpp; { bool madeopt; int count = 0; - lpp = alpp; madeopt = FALSE; - while ((*lpp) != (line_p) 0 && ((*lpp)->l_instr&BMASK) != op_lab) { + lpp = alpp; + madeopt = FALSE; + while ((*lpp) != (line_p) 0 && ((*lpp)->l_instr & BMASK) != op_lab) + { lp = *lpp; next = &lp->l_next; - hash[0] = lp->l_instr&BMASK; - lp=lp->l_next; - if (lp != (line_p) 0) { - hash[1] = (hash[0]<<4)^(lp->l_instr&BMASK); - lp=lp->l_next; + hash[0] = lp->l_instr & BMASK; + lp = lp->l_next; + if (lp != (line_p) 0) + { + hash[1] = (hash[0] << 4) ^ (lp->l_instr & BMASK); + lp = lp->l_next; if (lp != (line_p) 0) - hash[2] = (hash[1]<<4)^(lp->l_instr&BMASK); + hash[2] = (hash[1] << 4) ^ (lp->l_instr & BMASK); else hash[2] = ILLHASH; - } else { + } + else + { hash[1] = ILLHASH; hash[2] = ILLHASH; } @@ -628,195 +685,259 @@ basicblock(alpp) line_p *alpp; { * hashvalues computed. Try for longest pattern first */ - for (i=2;i>=0;i--) { - index = pathash[hash[i]&BMASK]; - while (index != 0) { - bp = &pattern[index]; - if((bp[PO_HASH]&BMASK) == (hash[i]>>8)) - if(trypat(lpp,&bp[PO_MATCH],i+1)) { - madeopt = TRUE; - next = lpp; - i = 0; /* dirty way of double break */ - break; - } - index=(bp[PO_NEXT]&BMASK)|(bp[PO_NEXT+1]<<8); - } + for (i = 2; i >= 0; i--) + { + index = pathash[hash[i] & BMASK]; + while (index != 0) + { + bp = &pattern[index]; + if ((bp[PO_HASH] & BMASK) == (hash[i] >> 8)) + if (trypat(lpp, &bp[PO_MATCH], i + 1)) + { + madeopt = TRUE; + next = lpp; + i = 0; /* dirty way of double break */ + break; + } + index = (bp[PO_NEXT] & BMASK) | (bp[PO_NEXT + 1] << 8); + } } - if (lpp == next) { + if (lpp == next) + { count++; - if (count > 1000) { + if (count > 1000) + { /* probably loop in table */ - fprintf(stderr, "Warning: possible loop in patterns; call an expert\n"); + fprintf(stderr, + "Warning: possible loop in patterns; call an expert\n"); next = &((*lpp)->l_next); count = 0; } } - else count = 0; + else + count = 0; lpp = next; } lpp = alpp; - if (repl_muls) { - while ((lp = *lpp) != (line_p) 0 && (lp->l_instr&BMASK) != op_lab) { - line_p b_repl, e_repl; - int cnt; - - if ((cnt = (lp->l_instr & BMASK)) != op_loc && cnt != op_ldc) { - lpp = &lp->l_next; - continue; - } + if (repl_muls) + { + while ((lp = *lpp) != (line_p) 0 && (lp->l_instr & BMASK) != op_lab) + { + line_p b_repl, e_repl; + int cnt; - cnt = repl_mul(lp, &b_repl, &e_repl); - - lp = *lpp; - if (cnt > 0 && cnt <= repl_muls) { - *lpp = b_repl; - e_repl->l_next = lp->l_next->l_next; - oldline(lp->l_next); - oldline(lp); - lpp = &e_repl->l_next; - madeopt = TRUE; - } - else { - while (b_repl != (line_p) 0) { - line_p n = b_repl->l_next; - - oldline(b_repl); - b_repl = n; + if ((cnt = (lp->l_instr & BMASK)) != op_loc && cnt != op_ldc) + { + lpp = &lp->l_next; + continue; + } + + cnt = repl_mul(lp, &b_repl, &e_repl); + + lp = *lpp; + if (cnt > 0 && cnt <= repl_muls) + { + *lpp = b_repl; + e_repl->l_next = lp->l_next->l_next; + oldline(lp->l_next); + oldline(lp); + lpp = &e_repl->l_next; + madeopt = TRUE; + } + else + { + while (b_repl != (line_p) 0) + { + line_p n = b_repl->l_next; + + oldline(b_repl); + b_repl = n; + } + lpp = &lp->l_next; } - lpp = &lp->l_next; } - } } return madeopt; } -repl_mul(lp, b, e) - register line_p lp; - line_p *b, *e; +static int repl_mul(register line_p lp, line_p *b, line_p *e) { register line_p next = lp->l_next; - int ins; - int sz; - unsigned long n; - int n0, n1; - int virgin = 1; - int retval = 0; + int ins; + int sz; + unsigned long n; + int n0, n1; + int virgin = 1; + int retval = 0; *b = 0; - if (! next) return 0; - if ((ins = (next->l_instr & BMASK)) != op_mli && ins != op_mlu) { + if (!next) + return 0; + if ((ins = (next->l_instr & BMASK)) != op_mli && ins != op_mlu) + { return 0; } - switch(next->l_optyp) { - case OPNO: - return 0; - case OPSHORT: - sz = next->l_a.la_short; - break; + switch (next->l_optyp) + { + case OPNO: + return 0; + case OPSHORT: + sz = next->l_a.la_short; + break; #ifdef LONGOFF - case OPOFFSET: - sz = next->l_a.la_offset; - break; + case OPOFFSET: + sz = next->l_a.la_offset; + break; #endif - default: - sz = (next->l_optyp & BMASK) - Z_OPMINI; - break; + default: + sz = (next->l_optyp & BMASK) - Z_OPMINI; + break; } - if (ins == op_loc && sz != wordsize) return 0; - if (ins == op_ldc && sz != 2*wordsize) return 0; - if (! repl_longmuls && sz != wordsize) return 0; - switch(lp->l_optyp) { - case OPSHORT: - n = (long) lp->l_a.la_short; - break; + if (ins == op_loc && sz != wordsize) + return 0; + if (ins == op_ldc && sz != 2 * wordsize) + return 0; + if (!repl_longmuls && sz != wordsize) + return 0; + switch (lp->l_optyp) + { + case OPSHORT: + n = (long) lp->l_a.la_short; + break; #ifdef LONGOFF - case OPOFFSET: - n = lp->l_a.la_offset; - break; + case OPOFFSET: + n = lp->l_a.la_offset; + break; #endif - default: - n = (long)((lp->l_optyp & BMASK) - Z_OPMINI); - break; + default: + n = (long) ((lp->l_optyp & BMASK) - Z_OPMINI); + break; } #define newinstr(res, opcode, val) (*(res) = newline((short)(val)+Z_OPMINI), (*(res))->l_instr = (opcode)) - while (n) { + while (n) + { /* first find "0*1*$" in n */ - for (n1 = 0; n & 1; n>>=1) ++n1; /* count "1" bits */ + for (n1 = 0; n & 1; n >>= 1) + ++n1; /* count "1" bits */ if (n) - for (n0 = 0; !(n & 1); n>>=1) /* count "0" bits */ + for (n0 = 0; !(n & 1); n >>= 1) /* count "0" bits */ ++n0; else n0 = 0; - if (n1 == 0) { - if (n0) { - newinstr(b, op_loc, n0); b = &((*b)->l_next); - newinstr(b, op_slu, sz); b = &((*b)->l_next); - retval++; - } - } else if (n1 == 1) { - if (virgin) { - newinstr(b, op_dup, sz); b = &((*b)->l_next); - virgin = 0; - } - else { - newinstr(b, op_exg, sz); b = &((*b)->l_next); - newinstr(b, op_dup, 2*sz); b = &((*b)->l_next); - newinstr(b, op_asp, sz); b = &((*b)->l_next); - newinstr(b, op_adu, sz); b = &((*b)->l_next); - newinstr(b, op_exg, sz); b = &((*b)->l_next); - retval++; - } - if (n) { - newinstr(b, op_loc, n0+n1); b = &((*b)->l_next); - newinstr(b, op_slu, sz); b = &((*b)->l_next); - retval++; - } - } else { - if (virgin) { - newinstr(b, op_dup, sz); b = &((*b)->l_next); - if (sz == wordsize) { - newinstr(b, op_loc, 0); b = &((*b)->l_next); - } - else { - newinstr(b, op_ldc, 0); b = &((*b)->l_next); - } - newinstr(b, op_exg, sz); b = &((*b)->l_next); - virgin = 0; - } - else { - newinstr(b, op_exg, sz); b = &((*b)->l_next); - newinstr(b, op_dup, 2*sz); b = &((*b)->l_next); - newinstr(b, op_asp, sz); b = &((*b)->l_next); - } - newinstr(b, op_sbu, sz); b = &((*b)->l_next); - newinstr(b, op_exg, sz); b = &((*b)->l_next); - retval++; - if (n1 != 8*sz) { - newinstr(b, op_loc, n1); b = &((*b)->l_next); - newinstr(b, op_slu, sz); b = &((*b)->l_next); - retval++; - newinstr(b, op_exg, sz); b = &((*b)->l_next); - newinstr(b, op_dup, 2*sz); b = &((*b)->l_next); - newinstr(b, op_asp, sz); b = &((*b)->l_next); - newinstr(b, op_adu, sz); b = &((*b)->l_next); - newinstr(b, op_exg, sz); b = &((*b)->l_next); - retval++; - } - if (n0) { - newinstr(b, op_loc, n0); b = &((*b)->l_next); - newinstr(b, op_slu, sz); b = &((*b)->l_next); + if (n1 == 0) + { + if (n0) + { + newinstr(b, op_loc, n0); + b = &((*b)->l_next); + newinstr(b, op_slu, sz); + b = &((*b)->l_next); retval++; } } - } + else if (n1 == 1) + { + if (virgin) + { + newinstr(b, op_dup, sz); + b = &((*b)->l_next); + virgin = 0; + } + else + { + newinstr(b, op_exg, sz); + b = &((*b)->l_next); + newinstr(b, op_dup, 2 * sz); + b = &((*b)->l_next); + newinstr(b, op_asp, sz); + b = &((*b)->l_next); + newinstr(b, op_adu, sz); + b = &((*b)->l_next); + newinstr(b, op_exg, sz); + b = &((*b)->l_next); + retval++; + } + if (n) + { + newinstr(b, op_loc, n0 + n1); + b = &((*b)->l_next); + newinstr(b, op_slu, sz); + b = &((*b)->l_next); + retval++; + } + } + else + { + if (virgin) + { + newinstr(b, op_dup, sz); + b = &((*b)->l_next); + if (sz == wordsize) + { + newinstr(b, op_loc, 0); + b = &((*b)->l_next); + } + else + { + newinstr(b, op_ldc, 0); + b = &((*b)->l_next); + } + newinstr(b, op_exg, sz); + b = &((*b)->l_next); + virgin = 0; + } + else + { + newinstr(b, op_exg, sz); + b = &((*b)->l_next); + newinstr(b, op_dup, 2 * sz); + b = &((*b)->l_next); + newinstr(b, op_asp, sz); + b = &((*b)->l_next); + } + newinstr(b, op_sbu, sz); + b = &((*b)->l_next); + newinstr(b, op_exg, sz); + b = &((*b)->l_next); + retval++; + if (n1 != 8 * sz) + { + newinstr(b, op_loc, n1); + b = &((*b)->l_next); + newinstr(b, op_slu, sz); + b = &((*b)->l_next); + retval++; + newinstr(b, op_exg, sz); + b = &((*b)->l_next); + newinstr(b, op_dup, 2 * sz); + b = &((*b)->l_next); + newinstr(b, op_asp, sz); + b = &((*b)->l_next); + newinstr(b, op_adu, sz); + b = &((*b)->l_next); + newinstr(b, op_exg, sz); + b = &((*b)->l_next); + retval++; + } + if (n0) + { + newinstr(b, op_loc, n0); + b = &((*b)->l_next); + newinstr(b, op_slu, sz); + b = &((*b)->l_next); + retval++; + } + } + } newinstr(b, op_asp, sz); - if (virgin) { + if (virgin) + { b = &((*b)->l_next); newinstr(b, sz == wordsize ? op_loc : op_ldc, 0); - } + } *e = *b; return retval == 0 ? 1 : retval; #undef newinstr diff --git a/util/opt/process.c b/util/opt/process.c index c1ab7d238..631805b67 100644 --- a/util/opt/process.c +++ b/util/opt/process.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include "param.h" #include "types.h" @@ -9,59 +11,23 @@ static char rcsid[] = "$Id$"; #include #include #include "alloc.h" +#include "util.h" +#include "putline.h" #include "line.h" +#include "reg.h" #include "lookup.h" #include "proinf.h" #include "ext.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ +/* External definitions */ +extern void flow(void); +extern void backward(void); +extern int peephole(void); -process() { - - if (wordsize == 0 || pointersize == 0) - error("No MES EMX encountered"); - backward(); /* reverse and cleanup list */ - symknown(); /* symbol scope is now known */ - if (!nflag) - symvalue(); /* give symbols value */ - if (prodepth != 0) { - if (!nflag) { - int npasses = 0; - bool madeopt; - - checklocs(); /* check definition of locals */ - do { - madeopt = peephole(); /* local optimization */ - relabel(); /* relabel local labels */ - flow(); /* throw away unreachable code */ - } while (madeopt && ++npasses < 5000); - assert(!madeopt); - } - do_tes(); /* top elt. size computation phase */ - outpro(); /* generate PRO pseudo */ - outregs(); /* generate MES ms_reg pseudos */ - outtes(); /* generate MES ms_tes pseudos */ - } - putlines(pseudos); /* pseudos first */ - if (prodepth != 0) { - putlines(instrs); /* instructions next */ - outend(); /* generate END pseudo */ - cleanlocals(); /* forget instruction labels */ - } else if(instrs != (line_p) 0) - error("instructions outside procedure"); -#ifdef COREDEBUG - coreverbose(); -#endif -} - -relabel() { - register num_p *npp,np,tp; - register num_p repl,ttp; +static void relabel(void) +{ + register num_p *npp, np, tp; + register num_p repl, ttp; /* * For each label find its final destination after crossjumping. @@ -70,30 +36,33 @@ relabel() { */ for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) - for (np = *npp; np != (num_p) 0; np = np->n_next) { - assert(! np->n_line || - ((np->n_line->l_instr&BMASK) == op_lab - && np->n_line->l_a.la_np == np)); - for(tp=np; (tp->n_flags&(NUMKNOWN|NUMMARK))==0; - tp = tp->n_repl) + for (np = *npp; np != (num_p) 0; np = np->n_next) + { + assert( + ! np->n_line || ((np->n_line->l_instr&BMASK) == op_lab && np->n_line->l_a.la_np == np)); + for (tp = np; (tp->n_flags & (NUMKNOWN | NUMMARK)) == 0; + tp = tp->n_repl) tp->n_flags |= NUMMARK; repl = tp->n_repl; - for(tp=np; tp->n_flags&NUMMARK; tp = ttp) { + for (tp = np; tp->n_flags & NUMMARK; tp = ttp) + { ttp = tp->n_repl; tp->n_repl = repl; tp->n_flags &= ~ NUMMARK; - tp->n_flags |= NUMKNOWN; + tp->n_flags |= NUMKNOWN; } } for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) - for (np = *npp; np != (num_p) 0; np = np->n_next) { - np->n_flags &= ~(NUMKNOWN|NUMSCAN|NUMREACH); + for (np = *npp; np != (num_p) 0; np = np->n_next) + { + np->n_flags &= ~(NUMKNOWN | NUMSCAN | NUMREACH); np->n_jumps = 0; } } -symknown() { - register sym_p *spp,sp; +static void symknown(void) +{ + register sym_p *spp, sp; for (spp = symhash; spp < &symhash[NSYMHASH]; spp++) for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next) @@ -101,12 +70,15 @@ symknown() { sp->s_flags |= SYMKNOWN; } -cleanlocals() { - register num_p *npp,np,tp; +static void cleanlocals(void) +{ + register num_p *npp, np, tp; - for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) { + for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) + { np = *npp; - while (np != (num_p) 0) { + while (np != (num_p) 0) + { tp = np->n_next; oldnum(np); np = tp; @@ -115,23 +87,25 @@ cleanlocals() { } } -checklocs() { - register num_p *npp,np; +static void checklocs(void) +{ + register num_p *npp, np; - for (npp=curpro.numhash; npp < & curpro.numhash[NNUMHASH]; npp++) - for (np = *npp; np != (num_p) 0; np=np->n_next) + for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) + for (np = *npp; np != (num_p) 0; np = np->n_next) if (np->n_line == (line_p) 0) - error("local label %u undefined", - (unsigned) np->n_number); + error("local label %u undefined", (unsigned) np->n_number); } -offset align(count,alignment) offset count,alignment; { +static offset align(offset count, offset alignment) +{ - assert(alignment==1||alignment==2||alignment==4); - return((count+alignment-1)&~(alignment-1)); + assert(alignment == 1 || alignment == 2 || alignment == 4); + return ((count + alignment - 1) & ~(alignment - 1)); } -symvalue() { +static void symvalue(void) +{ register line_p lp; register sym_p sp; register arg_p ap; @@ -139,66 +113,117 @@ symvalue() { short curfrag = 0; offset count; - for (lp=pseudos; lp != (line_p) 0; lp = lp->l_next) - switch(lp->l_instr&BMASK) { - default: - assert(FALSE); - case ps_sym: - sp = lp->l_a.la_sp; - if (sp->s_frag != curfrag) { - count = 0; - curfrag = sp->s_frag; + for (lp = pseudos; lp != (line_p) 0; lp = lp->l_next) + switch (lp->l_instr & BMASK) + { + default: + assert(FALSE); + break; + case ps_sym: + sp = lp->l_a.la_sp; + if (sp->s_frag != curfrag) + { + count = 0; + curfrag = sp->s_frag; + } + count = align(count, wordsize); + sp->s_value = count; + break; + case ps_bss: + case ps_hol: + /* nothing to do, all bss pseudos are in diff frags */ + case ps_mes: + break; + case ps_con: + case ps_rom: + for (ap = lp->l_a.la_arg; ap != (arg_p) 0; ap = ap->a_next) + switch (ap->a_typ) + { + default: + assert(FALSE); + case ARGOFF: + count = align(count, wordsize) + wordsize; + break; + case ARGNUM: + case ARGSYM: + case ARGVAL: + count = align(count, wordsize) + pointersize; + break; + case ARGICN: + case ARGUCN: + case ARGFCN: + if (ap->a_a.a_con.ac_length < wordsize) + count = align(count, + (offset) ap->a_a.a_con.ac_length); + else + count = align(count, wordsize); + count += ap->a_a.a_con.ac_length; + break; + case ARGSTR: + for (abp = &ap->a_a.a_string; abp != (argb_p) 0; + abp = abp->ab_next) + count += abp->ab_index; + break; + } } - count = align(count,wordsize); - sp->s_value = count; - break; - case ps_bss: - case ps_hol: - /* nothing to do, all bss pseudos are in diff frags */ - case ps_mes: - break; - case ps_con: - case ps_rom: - for (ap=lp->l_a.la_arg; ap != (arg_p) 0; ap = ap->a_next) - switch(ap->a_typ) { - default: - assert(FALSE); - case ARGOFF: - count = align(count,wordsize)+wordsize; - break; - case ARGNUM: - case ARGSYM: - case ARGVAL: - count = align(count,wordsize)+pointersize; - break; - case ARGICN: - case ARGUCN: - case ARGFCN: - if (ap->a_a.a_con.ac_length < wordsize) - count = align(count,(offset)ap->a_a.a_con.ac_length); - else - count = align(count,wordsize); - count += ap->a_a.a_con.ac_length; - break; - case ARGSTR: - for (abp = &ap->a_a.a_string; abp != (argb_p) 0; - abp = abp->ab_next) - count += abp->ab_index; - break; - } - } } -do_tes() +static void do_tes(void) { register line_p insptr = instrs, oldlin = NULL, oldlin2 = NULL; init_state(); tes_pseudos(); - while (insptr != NULL) { + while (insptr != NULL) + { tes_instr(insptr, oldlin, oldlin2); oldlin2 = oldlin; oldlin = insptr; insptr = insptr->l_next; } } + +void process(void) +{ + + if (wordsize == 0 || pointersize == 0) + error("No MES EMX encountered"); + backward(); /* reverse and cleanup list */ + symknown(); /* symbol scope is now known */ + if (!nflag) + symvalue(); /* give symbols value */ + if (prodepth != 0) + { + if (!nflag) + { + int npasses = 0; + bool madeopt; + + checklocs(); /* check definition of locals */ + do + { + madeopt = peephole(); /* local optimization */ + relabel(); /* relabel local labels */ + flow(); /* throw away unreachable code */ + } while (madeopt && ++npasses < 5000); + assert(!madeopt); + } + do_tes(); /* top elt. size computation phase */ + outpro(); /* generate PRO pseudo */ + outregs(); /* generate MES ms_reg pseudos */ + outtes(); /* generate MES ms_tes pseudos */ + } + putlines(pseudos); /* pseudos first */ + if (prodepth != 0) + { + putlines(instrs); /* instructions next */ + outend(); /* generate END pseudo */ + cleanlocals(); /* forget instruction labels */ + } + else if (instrs != (line_p) 0) + error("instructions outside procedure"); +#ifdef COREDEBUG + coreverbose(); +#endif +} + diff --git a/util/opt/putline.c b/util/opt/putline.c index 50a8a6697..60c40ebf3 100644 --- a/util/opt/putline.c +++ b/util/opt/putline.c @@ -1,8 +1,11 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include +#include #include "param.h" #include "types.h" #include "tes.h" @@ -12,167 +15,179 @@ static char rcsid[] = "$Id$"; #include #include "alloc.h" #include "line.h" +#include "putline.h" +#include "util.h" #include "lookup.h" #include "proinf.h" #include "optim.h" #include "ext.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ - #define outbyte(b) putc(b,outfile) -putlines(lnp) register line_p lnp; { +/* Forward declarations. */ +static void numlab(register num_p); +static void putargs(register arg_p); +static void putstr(register argb_p); + +void putlines(register line_p lnp) +{ register arg_p ap; line_p temp; - register instr; - short curlin= -2; + register int instr; + short curlin = -2; short thislin; - while ( lnp != (line_p) 0) { - instr = lnp->l_instr&BMASK; - switch(lnp->l_optyp) { - case OPSYMBOL: - if ((lnp->l_instr&BMASK) == ps_sym) - outdef(lnp->l_a.la_sp); - else - outocc(lnp->l_a.la_sp); - break; - case OPSVAL: - outocc(lnp->l_a.la_sval.lasv_sp); - break; + while (lnp != (line_p) 0) + { + instr = lnp->l_instr & BMASK; + switch (lnp->l_optyp) + { + case OPSYMBOL: + if ((lnp->l_instr & BMASK) == ps_sym) + outdef(lnp->l_a.la_sp); + else + outocc(lnp->l_a.la_sp); + break; + case OPSVAL: + outocc(lnp->l_a.la_sval.lasv_sp); + break; #ifdef LONGOFF - case OPLVAL: - outocc(lnp->l_a.la_lval.lalv_sp); - break; + case OPLVAL: + outocc(lnp->l_a.la_lval.lalv_sp); + break; #endif - case OPLIST: - ap = lnp->l_a.la_arg; - while (ap != (arg_p) 0) { - switch(ap->a_typ) { - case ARGSYM: - outocc(ap->a_a.a_sp); - break; - case ARGVAL: - outocc(ap->a_a.a_val.av_sp); - break; + case OPLIST: + ap = lnp->l_a.la_arg; + while (ap != (arg_p) 0) + { + switch (ap->a_typ) + { + case ARGSYM: + outocc(ap->a_a.a_sp); + break; + case ARGVAL: + outocc(ap->a_a.a_val.av_sp); + break; + } + ap = ap->a_next; } - ap = ap->a_next; - } - break; + break; } /* * global symbols now taken care of */ - - switch(instr) { - case ps_sym: - break; - case op_lni: - if (curlin != -2) - curlin++; - outinst(instr); - break; - case op_lin: - switch(lnp->l_optyp) { - case OPNO: - case OPOFFSET: - case OPNUMLAB: - case OPSYMBOL: - case OPSVAL: - case OPLVAL: - case OPLIST: + switch (instr) + { + case ps_sym: + break; + case op_lni: + if (curlin != -2) + curlin++; outinst(instr); - goto processoperand; - case OPSHORT: - thislin = lnp->l_a.la_short; + break; + case op_lin: + switch (lnp->l_optyp) + { + case OPNO: + case OPOFFSET: + case OPNUMLAB: + case OPSYMBOL: + case OPSVAL: + case OPLVAL: + case OPLIST: + outinst(instr); + goto processoperand; + case OPSHORT: + thislin = lnp->l_a.la_short; + break; + default: + thislin = (lnp->l_optyp & BMASK) - Z_OPMINI; + break; + } + if (thislin == curlin && !nflag) + { + temp = lnp->l_next; + oldline(lnp); + lnp = temp; + OPTIM(O_LINGONE); + continue; + } + else if (thislin == curlin + 1 && !nflag) + { + instr = op_lni; + outinst(instr); + temp = lnp->l_next; + oldline(lnp); + OPTIM(O_LINLNI); + lnp = newline(OPNO); + lnp->l_next = temp; + lnp->l_instr = instr; + } + else + { + outinst(instr); + } + curlin = thislin; + break; + case op_lab: + curlin = -2; break; default: - thislin = (lnp->l_optyp&BMASK)-Z_OPMINI; - break; - } - if (thislin == curlin && !nflag) { - temp = lnp->l_next; - oldline(lnp); - lnp = temp; - OPTIM(O_LINGONE); - continue; - } else if (thislin == curlin+1 && !nflag) { - instr = op_lni; + if ((em_flag[instr - sp_fmnem] & EM_FLO) == FLO_P) + curlin = -2; outinst(instr); - temp = lnp->l_next; - oldline(lnp); - OPTIM(O_LINLNI); - lnp = newline(OPNO); - lnp->l_next = temp; - lnp->l_instr = instr; - } else { - outinst(instr); - } - curlin = thislin; - break; - case op_lab: - curlin = -2; - break; - default: - if ((em_flag[instr-sp_fmnem]&EM_FLO)==FLO_P) - curlin = -2; - outinst(instr); } -processoperand: - switch(lnp->l_optyp) { - case OPNO: - if ((em_flag[instr-sp_fmnem]&EM_PAR)!=PAR_NO) - outbyte( (byte) sp_cend) ; - break; - default: - outint((lnp->l_optyp&BMASK)-Z_OPMINI); - break; - case OPSHORT: - outint(lnp->l_a.la_short); - break; + processoperand: switch (lnp->l_optyp) + { + case OPNO: + if ((em_flag[instr - sp_fmnem] & EM_PAR) != PAR_NO) + outbyte((byte) sp_cend); + break; + default: + outint((lnp->l_optyp & BMASK) - Z_OPMINI); + break; + case OPSHORT: + outint(lnp->l_a.la_short); + break; #ifdef LONGOFF - case OPOFFSET: - outoff(lnp->l_a.la_offset); - break; + case OPOFFSET: + outoff(lnp->l_a.la_offset); + break; #endif - case OPNUMLAB: - if (instr == op_lab) - numlab(lnp->l_a.la_np->n_repl); - else if (instr < sp_fpseu) /* plain instruction */ - outint((short) lnp->l_a.la_np->n_repl->n_number); - else - outnum(lnp->l_a.la_np->n_repl); - break; - case OPSYMBOL: - outsym(lnp->l_a.la_sp); - break; - case OPSVAL: - outbyte( (byte) sp_doff) ; - outsym(lnp->l_a.la_sval.lasv_sp); - outint(lnp->l_a.la_sval.lasv_short); - break; + case OPNUMLAB: + if (instr == op_lab) + numlab(lnp->l_a.la_np->n_repl); + else if (instr < sp_fpseu) /* plain instruction */ + outint((short) lnp->l_a.la_np->n_repl->n_number); + else + outnum(lnp->l_a.la_np->n_repl); + break; + case OPSYMBOL: + outsym(lnp->l_a.la_sp); + break; + case OPSVAL: + outbyte((byte) sp_doff); + outsym(lnp->l_a.la_sval.lasv_sp); + outint(lnp->l_a.la_sval.lasv_short); + break; #ifdef LONGOFF - case OPLVAL: - outbyte( (byte) sp_doff) ; - outsym(lnp->l_a.la_lval.lalv_sp); - outoff(lnp->l_a.la_lval.lalv_offset); - break; + case OPLVAL: + outbyte((byte) sp_doff); + outsym(lnp->l_a.la_lval.lalv_sp); + outoff(lnp->l_a.la_lval.lalv_offset); + break; #endif - case OPLIST: - putargs(lnp->l_a.la_arg); - switch(instr) { - case ps_con: - case ps_rom: - case ps_mes: - outbyte( (byte) sp_cend) ; - } + case OPLIST: + putargs(lnp->l_a.la_arg); + switch (instr) + { + case ps_con: + case ps_rom: + case ps_mes: + outbyte((byte) sp_cend); + } } /* * instruction is output now. @@ -187,185 +202,212 @@ processoperand: } } -putargs(ap) register arg_p ap; { +static void putargs(register arg_p ap) +{ - while (ap != (arg_p) 0) { - switch(ap->a_typ) { - default: - assert(FALSE); - case ARGOFF: - outoff(ap->a_a.a_offset); - break; - case ARGNUM: - outnum(ap->a_a.a_np->n_repl); - break; - case ARGSYM: - outsym(ap->a_a.a_sp); - break; - case ARGVAL: - outbyte( (byte) sp_doff) ; - outsym(ap->a_a.a_val.av_sp); - outoff(ap->a_a.a_val.av_offset); - break; - case ARGSTR: - outbyte( (byte) sp_scon) ; - putstr(&ap->a_a.a_string); - break; - case ARGICN: - outbyte( (byte) sp_icon) ; - goto casecon; - case ARGUCN: - outbyte( (byte) sp_ucon) ; - goto casecon; - case ARGFCN: - outbyte( (byte) sp_fcon) ; - casecon: - outint(ap->a_a.a_con.ac_length); - putstr(&ap->a_a.a_con.ac_con); - break; + while (ap != (arg_p) 0) + { + switch (ap->a_typ) + { + default: + assert(FALSE); + break; + case ARGOFF: + outoff(ap->a_a.a_offset); + break; + case ARGNUM: + outnum(ap->a_a.a_np->n_repl); + break; + case ARGSYM: + outsym(ap->a_a.a_sp); + break; + case ARGVAL: + outbyte((byte) sp_doff); + outsym(ap->a_a.a_val.av_sp); + outoff(ap->a_a.a_val.av_offset); + break; + case ARGSTR: + outbyte((byte) sp_scon); + putstr(&ap->a_a.a_string); + break; + case ARGICN: + outbyte((byte) sp_icon); + goto casecon; + case ARGUCN: + outbyte((byte) sp_ucon); + goto casecon; + case ARGFCN: + outbyte((byte) sp_fcon); + casecon: outint(ap->a_a.a_con.ac_length); + putstr(&ap->a_a.a_con.ac_con); + break; } ap = ap->a_next; } } -putstr(abp) register argb_p abp; { +static void putstr(register argb_p abp) +{ register argb_p tbp; - register length; + register int length; length = 0; tbp = abp; - while (tbp!= (argb_p) 0) { + while (tbp != (argb_p) 0) + { length += tbp->ab_index; tbp = tbp->ab_next; } outint(length); - while (abp != (argb_p) 0) { - for (length=0;lengthab_index;length++) - outbyte( (byte) abp->ab_contents[length] ); + while (abp != (argb_p) 0) + { + for (length = 0; length < abp->ab_index; length++) + outbyte((byte ) abp->ab_contents[length]); abp = abp->ab_next; } } -outdef(sp) register sym_p sp; { +void outdef(register sym_p sp) +{ /* * The surrounding If statement is removed to be friendly * to Backend writers having to deal with assemblers * not following our conventions. - if ((sp->s_flags&SYMOUT)==0) { + if ((sp->s_flags&SYMOUT)==0) { */ - sp->s_flags |= SYMOUT; - if (sp->s_flags&SYMGLOBAL) { - outinst(sp->s_flags&SYMPRO ? ps_exp : ps_exa); - outsym(sp); - } + sp->s_flags |= SYMOUT; + if (sp->s_flags & SYMGLOBAL) + { + outinst(sp->s_flags & SYMPRO ? ps_exp : ps_exa); + outsym(sp); + } /* - } + } */ } -outocc(sp) register sym_p sp; { +void outocc(register sym_p sp) +{ - if ((sp->s_flags&SYMOUT)==0) { + if ((sp->s_flags & SYMOUT) == 0) + { sp->s_flags |= SYMOUT; - if ((sp->s_flags&SYMGLOBAL)==0) { - outinst(sp->s_flags&SYMPRO ? ps_inp : ps_ina); + if ((sp->s_flags & SYMGLOBAL) == 0) + { + outinst(sp->s_flags & SYMPRO ? ps_inp : ps_ina); outsym(sp); } } } -outpro() { - +void outpro(void) +{ outdef(curpro.symbol); outinst(ps_pro); outsym(curpro.symbol); outoff(curpro.localbytes); } -outend() { - +void outend(void) +{ outinst(ps_end); outoff(curpro.localbytes); } -outinst(m) { - - outbyte( (byte) m ); +void outinst(int m) +{ + outbyte((byte ) m); } -outoff(off) offset off; { - +void outoff(offset off) +{ #ifdef LONGOFF if ((short) off == off) #endif outint((short) off); #ifdef LONGOFF - else { - outbyte( (byte) sp_cst4) ; - outshort( (short) (off&0177777L) ); - outshort( (short) (off>>16) ); + else + { + outbyte((byte) sp_cst4); + outshort((short) (off & 0177777L)); + outshort((short) (off >> 16)); } #endif } -outint(i) short i; { +void outint(short i) +{ - if (i>= -sp_zcst0 && i< sp_ncst0-sp_zcst0) - outbyte( (byte) (i+sp_zcst0+sp_fcst0) ); - else { - outbyte( (byte) sp_cst2) ; + if (i >= -sp_zcst0 && i < sp_ncst0 - sp_zcst0) + outbyte((byte) (i+sp_zcst0+sp_fcst0)); + else + { + outbyte((byte) sp_cst2); outshort(i); } } -outshort(i) short i; { - - outbyte( (byte) (i&BMASK) ); - outbyte( (byte) (i>>8) ); +void outshort(short i) +{ + outbyte((byte) (i&BMASK)); + outbyte((byte ) (i >> 8)); } -numlab(np) register num_p np; { - +static void numlab(register num_p np) +{ if (np->n_number < sp_nilb0) - outbyte( (byte) (np->n_number + sp_filb0) ); + outbyte((byte) (np->n_number + sp_filb0)); else outnum(np); } -outnum(np) register num_p np; { - - if(np->n_number<256) { - outbyte( (byte) sp_ilb1) ; - outbyte( (byte) (np->n_number) ); - } else { - outbyte( (byte) sp_ilb2) ; +void outnum(register num_p np) +{ + if (np->n_number < 256) + { + outbyte((byte) sp_ilb1); + outbyte((byte ) (np->n_number)); + } + else + { + outbyte((byte) sp_ilb2); outshort((short) np->n_number); } } -outsym(sp) register sym_p sp; { - register byte *p; +void outsym(register sym_p sp) +{ + register char *p; register unsigned num; - if (sp->s_name[0] == '.') { + if (sp->s_name[0] == '.') + { num = atoi(&sp->s_name[1]); - if (num < 256) { - outbyte( (byte) sp_dlb1) ; - outbyte( (byte) (num) ); - } else { - outbyte( (byte) sp_dlb2) ; + if (num < 256) + { + outbyte((byte) sp_dlb1); + outbyte((byte ) (num)); + } + else + { + outbyte((byte) sp_dlb2); outshort((short) num); } - } else { - p= sp->s_name; + } + else + { + p = sp->s_name; + /* This is not a real warning, because s_name is dynamically + * allocated as necessary. + */ while (*p && p < &sp->s_name[IDL]) p++; num = p - sp->s_name; - outbyte( (byte) (sp->s_flags&SYMPRO ? sp_pnam : sp_dnam) ); + outbyte((byte) (sp->s_flags&SYMPRO ? sp_pnam : sp_dnam)); outint((short) num); p = sp->s_name; while (num--) - outbyte( (byte) *p++ ); + outbyte((byte ) *p++); } } diff --git a/util/opt/putline.h b/util/opt/putline.h new file mode 100644 index 000000000..2b798901f --- /dev/null +++ b/util/opt/putline.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-04-06 + * + */ +#ifndef PUTLINE_H_ +#define PUTLINE_H_ + +#include "types.h" + +void putlines(register line_p lnp); +void outdef(register sym_p sp); +void outocc(register sym_p sp); +void outpro(void); +void outend(void); +void outinst(int m); +void outoff(offset off); +void outint(short i); +void outshort(short i); +void outnum(register num_p np); +void outsym(register sym_p sp); + +#endif /* PUTLINE_H_ */ diff --git a/util/opt/reg.c b/util/opt/reg.c index c00dcd11e..62385630d 100644 --- a/util/opt/reg.c +++ b/util/opt/reg.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include "param.h" #include "types.h" @@ -9,62 +11,69 @@ static char rcsid[] = "$Id$"; #include "tes.h" #include "proinf.h" #include "alloc.h" +#include "putline.h" +#include "reg.h" #include #include #include #include "ext.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ - -void -regvar(ap) register arg_p ap; { +void regvar(register arg_p ap) +{ register reg_p rp; - register i; + register int i; rp = newreg(); - i=0; - while (ap!=(arg_p)0 && ap->a_typ==ARGOFF && i<4) { - rp->r_par[i++]=ap->a_a.a_offset; - ap=ap->a_next; + i = 0; + while (ap != (arg_p) 0 && ap->a_typ == ARGOFF && i < 4) + { + rp->r_par[i++] = ap->a_a.a_offset; + ap = ap->a_next; } /* * Omit incomplete messages */ - switch(i) { - default:assert(FALSE); - case 0: - case 1: - case 2: oldreg(rp); return; - case 3: rp->r_par[3]= (offset) 0; break; - case 4: break; + switch (i) + { + default: + assert(FALSE); + break; + case 0: + case 1: + case 2: + oldreg(rp); + return; + case 3: + rp->r_par[3] = (offset) 0; + break; + case 4: + break; } rp->r_next = curpro.freg; curpro.freg = rp; } -inreg(off) offset off; { +int inreg(offset off) +{ register reg_p rp; - for (rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next) - if( rp->r_par[0] == off) - return(TRUE); - return(FALSE); + for (rp = curpro.freg; rp != (reg_p) 0; rp = rp->r_next) + if (rp->r_par[0] == off) + return (TRUE); + return (FALSE); } -outregs() { - register reg_p rp,tp; - register i; +void outregs(void) +{ + register reg_p rp, tp; + register int i; - for(rp=curpro.freg; rp != (reg_p) 0; rp = tp) { + for (rp = curpro.freg; rp != (reg_p) 0; rp = tp) + { tp = rp->r_next; outinst(ps_mes); - outoff((offset)ms_reg); - for(i=0;i<4;i++) + outoff((offset) ms_reg); + for (i = 0; i < 4; i++) outoff(rp->r_par[i]); outinst(sp_cend); oldreg(rp); @@ -74,39 +83,44 @@ outregs() { * will be output. Kludgy. */ outinst(ps_mes); - outoff((offset)(curpro.gtoproc? ms_gto : ms_reg)); + outoff((offset) (curpro.gtoproc ? ms_gto : ms_reg)); outinst(sp_cend); curpro.freg = (reg_p) 0; } /* outtes() handles the output of the top elt. messages */ -outtes() { +void outtes(void) +{ register num_p *npp, np; - for (npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++) { - for (np = *npp; np != (num_p) 0; np=np->n_next) { - if (! (np->n_flags & NUMSET) || np->n_size == 0 || - (np->n_flags & NUMCOND)) continue; + for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) + { + for (np = *npp; np != (num_p) 0; np = np->n_next) + { + if (!(np->n_flags & NUMSET) || np->n_size == 0 + || (np->n_flags & NUMCOND)) + continue; outinst(ps_mes); - outoff((offset)ms_tes); - outoff((offset)np->n_number); - outoff((offset)np->n_size); - outoff((offset)((np->n_flags & NUMFALLTHROUGH) ? 1 : 0)); + outoff((offset) ms_tes); + outoff((offset) np->n_number); + outoff((offset) np->n_size); + outoff((offset) ((np->n_flags & NUMFALLTHROUGH) ? 1 : 0)); outinst(sp_cend); } } } -void -incregusage(off) offset off; { +void incregusage(offset off) +{ register reg_p rp; #ifndef GLOBAL_OPT /* If we're optimizing the output of the global optimizer * we must not change the count fields of the register messages. */ - for(rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next) - if (rp->r_par[0]==off) { + for (rp = curpro.freg; rp != (reg_p) 0; rp = rp->r_next) + if (rp->r_par[0] == off) + { rp->r_par[3]++; return; } diff --git a/util/opt/reg.h b/util/opt/reg.h new file mode 100644 index 000000000..144c224df --- /dev/null +++ b/util/opt/reg.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + */ +#ifndef REG_H_ +#define REG_H_ + +#include "types.h" + +void regvar(register arg_p ap); +void outregs(void); +int inreg(offset off); +void outtes(void); +void incregusage(offset off); + +#endif /* REG_H_ */ diff --git a/util/opt/scan.l b/util/opt/scan.l index 1c26f1857..a14690253 100644 --- a/util/opt/scan.l +++ b/util/opt/scan.l @@ -1,8 +1,4 @@ %{ -#ifndef NORCSID -static char rcsid2[] = "$Id$"; -#endif - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". @@ -13,6 +9,8 @@ static char rcsid2[] = "$Id$"; extern long atol(); extern char patid[128]; extern int lino; +extern int mlookup(char* name); +extern void yyerror(const char *); #include "y.tab.h" diff --git a/util/opt/special.c b/util/opt/special.c index 132e83344..3679e00b1 100644 --- a/util/opt/special.c +++ b/util/opt/special.c @@ -1,22 +1,15 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - -#include "param.h" -#include "types.h" - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". * * Author: Hans van Staveren */ +#include "param.h" +#include "types.h" + #ifdef ALLOWSPECIAL -bool special(lpp,bp,patlen) -line_p *lpp; -byte *bp; -int patlen; +bool special(line_p *lpp,byte *bp,int patlen) { return(FALSE); diff --git a/util/opt/tes.c b/util/opt/tes.c index 028bf845f..3f2803217 100644 --- a/util/opt/tes.c +++ b/util/opt/tes.c @@ -1,12 +1,8 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif /* * This file contains the main part of the top element size computation phase. * * Author: Hans van Eck. */ - #include #include #include @@ -39,152 +35,206 @@ extern char flow_tab[]; int state; static int stacktop = 0; -init_state() +/* Forward declarations */ +static void do_inst_label(line_p); +static void assign_label(register num_p); + +void init_state(void) { stacktop = 0; state = KNOWN; } -tes_pseudos() +void tes_pseudos(void) { register line_p lp; - for (lp = pseudos; lp != (line_p)0; lp = lp->l_next) { - switch(INSTR(lp)) { - case ps_con: - case ps_rom: - if (lp->l_optyp == OPLIST) { - register arg_p ap = lp->l_a.la_arg; + for (lp = pseudos; lp != (line_p) 0; lp = lp->l_next) + { + switch (INSTR(lp)) + { + case ps_con: + case ps_rom: + if (lp->l_optyp == OPLIST) + { + register arg_p ap = lp->l_a.la_arg; - while (ap != (arg_p) 0) { - if (ap->a_typ == ARGNUM) { - assign_label(ap->a_a.a_np->n_repl); + while (ap != (arg_p) 0) + { + if (ap->a_typ == ARGNUM) + { + assign_label(ap->a_a.a_np->n_repl); + } + ap = ap->a_next; } - ap = ap->a_next; } - } else if (lp->l_optyp == OPNUMLAB) - assign_label(lp->l_a.la_np->n_repl); + else if (lp->l_optyp == OPNUMLAB) + assign_label(lp->l_a.la_np->n_repl); } } } -void -tes_instr(lnp, x, y) -line_p lnp, x, y; +void tes_instr(line_p lnp, line_p x, line_p y) { char *s; - register instr = INSTR(lnp); + register int instr = INSTR(lnp); register int arg, argdef; int neg = 0; - if (instr == op_lab) { + if (instr == op_lab) + { do_inst_label(lnp); return; } - if (instr < sp_fmnem || instr > sp_lmnem) { + if (instr < sp_fmnem || instr > sp_lmnem) + { return; } - if (state == NOTREACHED) return; /* What else ? */ + if (state == NOTREACHED) + return; /* What else ? */ s = pop_push[instr]; - if (*s != '0') { - while (*s != '\0') { + if (*s != '0') + { + while (*s != '\0') + { neg = (*s++ == '-'); - if (TYPE(lnp) == OPSHORT) { + if (TYPE(lnp) == OPSHORT) + { arg = SHORT(lnp); - if (arg < wordsize) arg = wordsize; + if (arg < wordsize) + arg = wordsize; argdef = TRUE; - } else if (IS_MINI(lnp)) { + } + else if (IS_MINI(lnp)) + { arg = MINI(lnp); - if (arg > 0 && arg < wordsize) arg = wordsize; - if (arg < 0 && -arg < wordsize) arg = -wordsize; + if (arg > 0 && arg < wordsize) + arg = wordsize; + if (arg < 0 && -arg < wordsize) + arg = -wordsize; argdef = TRUE; - } else { + } + else + { argdef = FALSE; } - switch (*s++) { - case 'w': stacktop = wordsize; break; - case 'd': stacktop = wordsize * 2; break; - case 'p': stacktop = pointersize; break; - case 'a': - if (argdef == FALSE || instr == op_ass) { + switch (*s++) + { + case 'w': + stacktop = wordsize; + break; + case 'd': + stacktop = wordsize * 2; + break; + case 'p': + stacktop = pointersize; + break; + case 'a': + if (argdef == FALSE || instr == op_ass) + { + stacktop = 0; + } + else + { + stacktop = arg; + } + break; + case 'x': + if (IS_LOC(x)) + { + arg = MINI(x); + if (arg < wordsize) + arg = wordsize; + stacktop = arg; + } + else + { + stacktop = 0; + } + break; + case 'y': + if (IS_LOC(y)) + { + arg = MINI(y); + if (arg < wordsize) + arg = wordsize; + stacktop = arg; + } + else + { + stacktop = 0; + } + break; + case '?': stacktop = 0; - } else { - stacktop = arg; - } - break; - case 'x': - if (IS_LOC(x)) { - arg = MINI(x); - if (arg < wordsize) arg = wordsize; - stacktop = arg; - } else { - stacktop = 0; - } - break; - case 'y': - if (IS_LOC(y)) { - arg = MINI(y); - if (arg < wordsize) arg = wordsize; - stacktop = arg; - } else { - stacktop = 0; - } - break; - case '?': - stacktop = 0; - break; - default: - assert(FALSE); + break; + default: + assert(FALSE); } } /* * When the last argument was negative, the element size * must be negated. This is to catch 'asp -4'. */ - if (neg) stacktop = -stacktop; + if (neg) + stacktop = -stacktop; } - if (stacktop < 0) stacktop = 0; + if (stacktop < 0) + stacktop = 0; - if (ISABRANCH(instr)) do_inst_label(lnp); - if (NON_CONTINUABLE(instr)) { + if (ISABRANCH(instr)) + do_inst_label(lnp); + if (NON_CONTINUABLE(instr)) + { state = NOTREACHED; stacktop = 0; } } -assign_label(label) -register num_p label; +static void assign_label(register num_p label) { - if (label->n_flags & NUMSET) { - if (state == NOTREACHED || stacktop > label->n_size) { + if (label->n_flags & NUMSET) + { + if (state == NOTREACHED || stacktop > label->n_size) + { stacktop = label->n_size; - } else if ( stacktop < label->n_size) { + } + else if (stacktop < label->n_size) + { label->n_size = stacktop; } - } else { + } + else + { label->n_size = stacktop; label->n_flags |= NUMSET; } } -do_inst_label(lnp) /* (re-)install a label */ -line_p lnp; +/* (re-)install a label */ +static void do_inst_label(line_p lnp) { num_p label = lnp->l_a.la_np->n_repl; int instr = INSTR(lnp); assign_label(label); - if (instr == op_lab) { - if (state == NOTREACHED) { - } else { + if (instr == op_lab) + { + if (state == NOTREACHED) + { + } + else + { label->n_flags |= NUMFALLTHROUGH; } - } else if (ISCONDBRANCH(instr)) { /* conditional branch */ + } + else if (ISCONDBRANCH(instr)) + { /* conditional branch */ label->n_flags |= NUMCOND; } state = KNOWN; diff --git a/util/opt/tes.h b/util/opt/tes.h index 770512166..4fb4f76ff 100644 --- a/util/opt/tes.h +++ b/util/opt/tes.h @@ -1,8 +1,17 @@ /* * Author: Hans van Eck. */ -/* $Id$ */ +#ifndef TES_H_ +#define TES_H_ + +#include "types.h" extern int state; #define KNOWN 1 #define NOTREACHED 2 + +void init_state(void); +void tes_pseudos(void); +void tes_instr(line_p lnp, line_p x, line_p y); + +#endif /* TES_H_ */ diff --git a/util/opt/types.h b/util/opt/types.h index c9ff1824d..4c73c3787 100644 --- a/util/opt/types.h +++ b/util/opt/types.h @@ -2,9 +2,10 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* $Id$ */ +#ifndef TYPES_H_ +#define TYPES_H_ -typedef char byte; +typedef unsigned char byte; typedef char bool; typedef struct line line_t; typedef struct line *line_p; @@ -23,3 +24,5 @@ typedef long offset; #else typedef short offset; #endif + +#endif /* TYPES_H_ */ diff --git a/util/opt/util.c b/util/opt/util.c index b38796507..f62542a34 100644 --- a/util/opt/util.c +++ b/util/opt/util.c @@ -1,46 +1,47 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - -#include -#include -#include "param.h" -#include "types.h" -#include "tes.h" -#include "lookup.h" -#include "proinf.h" -#include "optim.h" -#include "ext.h" - /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". * * Author: Hans van Staveren */ - +#include +#include +#include +#include "param.h" +#include "types.h" +#include "tes.h" +#include "lookup.h" +#include "proinf.h" +#include "optim.h" +#include "util.h" +#include "ext.h" /* VARARGS1 */ -error(s,a) char *s,*a; { +void error(char *s, ...) +{ + va_list ap; + va_start(ap, s); - fprintf(stderr,"%s: error on line %u",progname,linecount); + fprintf(stderr, "%s: error on line %u", progname, linecount); if (prodepth != 0) - fprintf(stderr,"(%.*s)",IDL,curpro.symbol->s_name); - fprintf(stderr,": "); - fprintf(stderr,s,a); - fprintf(stderr,"\n"); + fprintf(stderr, "(%.*s)", IDL, curpro.symbol->s_name); + fprintf(stderr, ": "); + vfprintf(stderr, s, ap); + fprintf(stderr, "\n"); + + va_end(ap); #ifndef NDEBUG abort(); #endif - exit(-1); + exit(EXIT_FAILURE); } #ifdef DIAGOPT -optim(n) { - +void optim(int n) +{ fprintf(stderr,"Made optimization %d",n); if (prodepth) - fprintf(stderr," (%.*s)",IDL,curpro.symbol->s_name); + fprintf(stderr," (%.*s)",IDL,curpro.symbol->s_name); fprintf(stderr,"\n"); } #endif diff --git a/util/opt/util.h b/util/opt/util.h new file mode 100644 index 000000000..c5f56f4cc --- /dev/null +++ b/util/opt/util.h @@ -0,0 +1,15 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * + */ +#ifndef UTIL_H_ +#define UTIL_H_ + +void error(char *s, ...); +#ifdef DIAGOPT +void optim(int n); +#endif + +#endif /* UTIL_H_ */ diff --git a/util/opt/var.c b/util/opt/var.c index 58c803f03..3e51a9a70 100644 --- a/util/opt/var.c +++ b/util/opt/var.c @@ -1,7 +1,9 @@ -#ifndef NORCSID -static char rcsid[] = "$Id$"; -#endif - +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * Author: Hans van Staveren + */ #include #include "param.h" #include "types.h" @@ -9,12 +11,7 @@ static char rcsid[] = "$Id$"; #include "lookup.h" #include "proinf.h" -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - * - * Author: Hans van Staveren - */ + unsigned linecount = 0; /* "line"number for errormessages */ int prodepth = 0; /* Level of nesting */ @@ -25,7 +22,7 @@ bool repl_longmuls = 0; /* replacing longmuls as well? */ line_p instrs,pseudos; /* pointers to chains */ sym_p symhash[NSYMHASH]; /* array of pointers to chains */ FILE *outfile; -char template[] = "/tmp/emoptXXXXXX"; +char tempname[L_tmpnam]; offset wordsize = 0; offset pointersize = 0; char *progname; From 53d2894ed1be08778b3633fb56e90646ac5c42c2 Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 11 May 2019 01:18:01 +0800 Subject: [PATCH 68/84] ANSI C conversion. --- util/topgen/symtab.c | 74 ++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/util/topgen/symtab.c b/util/topgen/symtab.c index da1af3dfd..0c1d07cb5 100644 --- a/util/topgen/symtab.c +++ b/util/topgen/symtab.c @@ -8,7 +8,7 @@ * Contains the routine findident, which builds the symbol table and * searches identifiers */ - + #include #include #include "symtab.h" @@ -17,40 +17,46 @@ struct symtab *idtable, *deftable; extern void error(char *s, char* s1); -struct symtab * -findident(s, mode, table) char *s; struct symtab **table; { - /* - * Look for identifier s in the symboltable referred to by *table. - * If mode = LOOKING, no new entry's will be made. - * If mode = ENTERING, a new entry will be made if s is not in the - * table yet, otherwise an error results - */ - register struct symtab *p; - register int n; - - if (!*table) { /* No entry for this symbol */ - if (mode == LOOKING) return (struct symtab *) 0; +struct symtab * findident(char *s, int mode, struct symtab **table) +{ /* - * Make new entry + * Look for identifier s in the symboltable referred to by *table. + * If mode = LOOKING, no new entry's will be made. + * If mode = ENTERING, a new entry will be made if s is not in the + * table yet, otherwise an error results */ - p = (struct symtab *) malloc(sizeof *p); - p->s_left = p->s_right = (struct symtab *) 0; - p->s_name = malloc( (unsigned) (strlen(s) + 1)); - strcpy(p->s_name,s); - *table = p; - return p; - } - else { - p = *table; - if ((n = strcmp(p->s_name,s)) == 0) { /* This is it! */ - if (mode == ENTERING) { - error("Identifier %s redefined",s); - } - return p; + register struct symtab *p; + register int n; + + if (!*table) + { /* No entry for this symbol */ + if (mode == LOOKING) + return (struct symtab *) 0; + /* + * Make new entry + */ + p = (struct symtab *) malloc(sizeof *p); + p->s_left = p->s_right = (struct symtab *) 0; + p->s_name = malloc((unsigned) (strlen(s) + 1)); + strcpy(p->s_name, s); + *table = p; + return p; } - /* Binary tree ..... */ - if (n < 0) return findident(s,mode,&(p->s_left)); - return findident(s,mode,&(p->s_right)); - } - /* NOTREACHED */ + else + { + p = *table; + if ((n = strcmp(p->s_name, s)) == 0) + { /* This is it! */ + if (mode == ENTERING) + { + error("Identifier %s redefined", s); + } + return p; + } + /* Binary tree ..... */ + if (n < 0) + return findident(s, mode, &(p->s_left)); + return findident(s, mode, &(p->s_right)); + } + /* NOTREACHED */ } From cb65e6426cf8f07dd6f0416424003be7b7479ee7 Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 14 May 2019 23:14:59 +0800 Subject: [PATCH 69/84] Memory overflow bugfix --- lang/pc/comp/cstoper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/pc/comp/cstoper.c b/lang/pc/comp/cstoper.c index 3acf027fc..07ebc0288 100644 --- a/lang/pc/comp/cstoper.c +++ b/lang/pc/comp/cstoper.c @@ -486,7 +486,7 @@ void InitCst(void) max_int = full_mask[int_size] & ~(1L << (int_size * 8 - 1)); min_int = - max_int; maxint_str = long2str(max_int, 10); - maxint_str = Salloc(maxint_str, (unsigned int) strlen(maxint_str)); + maxint_str = Salloc(maxint_str, (unsigned int) strlen(maxint_str)+sizeof(char)); wrd_bits = 8 * (int) word_size; if( !max_intset ) max_intset = wrd_bits - 1; } From 9bb69bbb9890c104a8cbd803cc487c0f0bfd1ff5 Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 14 May 2019 23:21:19 +0800 Subject: [PATCH 70/84] Fix several compiler warnings by adding braces --- mach/6500/as/mach3.c | 126 ++--- mach/6800/as/mach3.c | 218 ++++---- mach/6805/as/mach3.c | 174 +++--- mach/6809/as/mach3.c | 320 +++++------ mach/arm/as/mach3.c | 204 +++---- mach/i386/as/mach3.c | 796 +++++++++++++------------- mach/i80/as/mach3.c | 202 +++---- mach/i86/as/mach3.c | 628 ++++++++++----------- mach/m68020/as/mach3.c | 782 +++++++++++++------------- mach/m68k2/as/mach3.c | 662 +++++++++++----------- mach/ns/as/mach3.c | 824 +++++++++++++-------------- mach/pdp/as/mach3.c | 292 +++++----- mach/powerpc/as/mach3.c | 1174 +++++++++++++++++++-------------------- mach/proto/as/comm3.c | 46 +- mach/s2650/as/mach3.c | 170 +++--- mach/vax4/as/mach3.c | 742 ++++++++++++------------- mach/vc4/as/mach3.c | 254 ++++----- mach/z80/as/mach3.c | 184 +++--- mach/z8000/as/mach3.c | 552 +++++++++--------- 19 files changed, 4175 insertions(+), 4175 deletions(-) diff --git a/mach/6500/as/mach3.c b/mach/6500/as/mach3.c index e235b80ac..ab8d90ff7 100644 --- a/mach/6500/as/mach3.c +++ b/mach/6500/as/mach3.c @@ -8,66 +8,66 @@ * Mostek 6500 keywords */ -0, EXTENSION, 0, ".l", -0, EXTENSION, 8, ".h", -0, A, 0, "a", -0, X, 0, "x", -0, Y, 0, "y", -0, ADDOP, 0x60, "adc", -0, ADDOP, 0x20, "and", -0, ADDOP, 0xC0, "cmp", -0, ADDOP, 0x40, "eor", -0, ADDOP, 0xA0, "lda", -0, ADDOP, 0x00, "ora", -0, ADDOP, 0xE0, "sbc", -0, ADDOP, 0x80, "sta", -0, ROLOP, 0x00, "asl", -0, ROLOP, 0x40, "lsr", -0, ROLOP, 0x20, "rol", -0, ROLOP, 0x60, "ror", -0, BRAOP, 0x90, "bcc", -0, BRAOP, 0xB0, "bcs", -0, BRAOP, 0xF0, "beq", -0, BRAOP, 0x30, "bmi", -0, BRAOP, 0xD0, "bne", -0, BRAOP, 0x10, "bpl", -0, BRAOP, 0x50, "bvc", -0, BRAOP, 0x70, "bvs", -0, BITOP, 0x24, "bit", -0, NOPOP, 0x00, "brk", -0, NOPOP, 0x18, "clc", -0, NOPOP, 0xD8, "cld", -0, NOPOP, 0x58, "cli", -0, NOPOP, 0xB8, "clv", -0, NOPOP, 0xCA, "dex", -0, NOPOP, 0x88, "dey", -0, NOPOP, 0xE8, "inx", -0, NOPOP, 0xC8, "iny", -0, NOPOP, 0xEA, "nop", -0, NOPOP, 0x48, "pha", -0, NOPOP, 0x08, "php", -0, NOPOP, 0x68, "pla", -0, NOPOP, 0x28, "plp", -0, NOPOP, 0x40, "rti", -0, NOPOP, 0x60, "rts", -0, NOPOP, 0x38, "sec", -0, NOPOP, 0xF8, "sed", -0, NOPOP, 0x78, "sei", -0, NOPOP, 0xAA, "tax", -0, NOPOP, 0xA8, "tay", -0, NOPOP, 0x98, "tya", -0, NOPOP, 0xBA, "tsx", -0, NOPOP, 0x8A, "txa", -0, NOPOP, 0x9A, "txs", -0, CPXOP, 0xE0, "cpx", -0, CPXOP, 0xC0, "cpy", -0, INCOP, 0xC0, "dec", -0, INCOP, 0xE0, "inc", -0, JMPOP, 0x4C, "jmp", -0, JSROP, 0x20, "jsr", -0, LDXOP, 0xA0, "ldx", -0, LDYOP, 0xA0, "ldy", -0, STXOP, 0x80, "stx", -0, STYOP, 0x80, "sty", -0, PSEU, 0x1860, "add", -0, PSEU, 0x38E0, "sub", +{0, EXTENSION, 0, ".l"}, +{0, EXTENSION, 8, ".h"}, +{0, A, 0, "a"}, +{0, X, 0, "x"}, +{0, Y, 0, "y"}, +{0, ADDOP, 0x60, "adc"}, +{0, ADDOP, 0x20, "and"}, +{0, ADDOP, 0xC0, "cmp"}, +{0, ADDOP, 0x40, "eor"}, +{0, ADDOP, 0xA0, "lda"}, +{0, ADDOP, 0x00, "ora"}, +{0, ADDOP, 0xE0, "sbc"}, +{0, ADDOP, 0x80, "sta"}, +{0, ROLOP, 0x00, "asl"}, +{0, ROLOP, 0x40, "lsr"}, +{0, ROLOP, 0x20, "rol"}, +{0, ROLOP, 0x60, "ror"}, +{0, BRAOP, 0x90, "bcc"}, +{0, BRAOP, 0xB0, "bcs"}, +{0, BRAOP, 0xF0, "beq"}, +{0, BRAOP, 0x30, "bmi"}, +{0, BRAOP, 0xD0, "bne"}, +{0, BRAOP, 0x10, "bpl"}, +{0, BRAOP, 0x50, "bvc"}, +{0, BRAOP, 0x70, "bvs"}, +{0, BITOP, 0x24, "bit"}, +{0, NOPOP, 0x00, "brk"}, +{0, NOPOP, 0x18, "clc"}, +{0, NOPOP, 0xD8, "cld"}, +{0, NOPOP, 0x58, "cli"}, +{0, NOPOP, 0xB8, "clv"}, +{0, NOPOP, 0xCA, "dex"}, +{0, NOPOP, 0x88, "dey"}, +{0, NOPOP, 0xE8, "inx"}, +{0, NOPOP, 0xC8, "iny"}, +{0, NOPOP, 0xEA, "nop"}, +{0, NOPOP, 0x48, "pha"}, +{0, NOPOP, 0x08, "php"}, +{0, NOPOP, 0x68, "pla"}, +{0, NOPOP, 0x28, "plp"}, +{0, NOPOP, 0x40, "rti"}, +{0, NOPOP, 0x60, "rts"}, +{0, NOPOP, 0x38, "sec"}, +{0, NOPOP, 0xF8, "sed"}, +{0, NOPOP, 0x78, "sei"}, +{0, NOPOP, 0xAA, "tax"}, +{0, NOPOP, 0xA8, "tay"}, +{0, NOPOP, 0x98, "tya"}, +{0, NOPOP, 0xBA, "tsx"}, +{0, NOPOP, 0x8A, "txa"}, +{0, NOPOP, 0x9A, "txs"}, +{0, CPXOP, 0xE0, "cpx"}, +{0, CPXOP, 0xC0, "cpy"}, +{0, INCOP, 0xC0, "dec"}, +{0, INCOP, 0xE0, "inc"}, +{0, JMPOP, 0x4C, "jmp"}, +{0, JSROP, 0x20, "jsr"}, +{0, LDXOP, 0xA0, "ldx"}, +{0, LDYOP, 0xA0, "ldy"}, +{0, STXOP, 0x80, "stx"}, +{0, STYOP, 0x80, "sty"}, +{0, PSEU, 0x1860, "add"}, +{0, PSEU, 0x38E0, "sub"}, diff --git a/mach/6800/as/mach3.c b/mach/6800/as/mach3.c index 390d08ebc..eddf26d83 100644 --- a/mach/6800/as/mach3.c +++ b/mach/6800/as/mach3.c @@ -7,112 +7,112 @@ /* * Motorola 6800 keywords */ -0, X, 0, "x", -0, BRANCH, 0x20, "bra", -0, BRANCH, 0x22, "bhi", -0, BRANCH, 0x23, "bls", -0, BRANCH, 0x24, "bhs", /* bcc */ -0, BRANCH, 0x24, "bcc", -0, BRANCH, 0x25, "blo", /* bcs */ -0, BRANCH, 0x25, "bcs", -0, BRANCH, 0x26, "bne", -0, BRANCH, 0x27, "beq", -0, BRANCH, 0x28, "bvc", -0, BRANCH, 0x29, "bvs", -0, BRANCH, 0x2A, "bpl", -0, BRANCH, 0x2B, "bmi", -0, BRANCH, 0x2C, "bge", -0, BRANCH, 0x2D, "blt", -0, BRANCH, 0x2E, "bgt", -0, BRANCH, 0x2F, "ble", -0, BRANCH, 0x8D, "bsr", -0, XOP, 0xA0, "suba", -0, XOP, 0xA1, "cmpa", -0, XOP, 0xA2, "sbca", -0, XOP, 0xA4, "anda", -0, XOP, 0xA5, "bita", -0, XOP, 0xA6, "ldaa", -0, XOP, 0xA8, "eora", -0, XOP, 0xA9, "adca", -0, XOP, 0xAA, "oraa", -0, XOP, 0xAB, "adda", -0, XOP, 0xE0, "subb", -0, XOP, 0xE1, "cmpb", -0, XOP, 0xE2, "sbcb", -0, XOP, 0xE4, "andb", -0, XOP, 0xE5, "bitb", -0, XOP, 0xE6, "ldab", -0, XOP, 0xE8, "eorb", -0, XOP, 0xE9, "adcb", -0, XOP, 0xEA, "orab", -0, XOP, 0xEB, "addb", -0, AOP, 0x60, "neg", -0, NOARG, 0x40, "nega", -0, NOARG, 0x50, "negb", -0, AOP, 0x63, "com", -0, NOARG, 0x43, "coma", -0, NOARG, 0x53, "comb", -0, AOP, 0x64, "lsr", -0, NOARG, 0x44, "lsra", -0, NOARG, 0x54, "lsrb", -0, AOP, 0x66, "ror", -0, NOARG, 0x46, "rora", -0, NOARG, 0x56, "rorb", -0, AOP, 0x67, "asr", -0, NOARG, 0x47, "asra", -0, NOARG, 0x57, "asrb", -0, AOP, 0x68, "asl", -0, NOARG, 0x48, "asla", -0, NOARG, 0x58, "aslb", -0, AOP, 0x68, "lsl", -0, NOARG, 0x48, "lsla", -0, NOARG, 0x58, "lslb", -0, AOP, 0x69, "rol", -0, NOARG, 0x49, "rola", -0, NOARG, 0x59, "rolb", -0, AOP, 0x6A, "dec", -0, NOARG, 0x4A, "deca", -0, NOARG, 0x5A, "decb", -0, AOP, 0x6C, "inc", -0, NOARG, 0x4C, "inca", -0, NOARG, 0x5C, "incb", -0, AOP, 0x6D, "tst", -0, NOARG, 0x4D, "tsta", -0, NOARG, 0x5D, "tstb", -0, AOP, 0x6F, "clr", -0, NOARG, 0x4F, "clra", -0, NOARG, 0x5F, "clrb", -0, XOP, 0x6E, "jmp", -0, XOP, 0xAD, "jsr", -0, XOP, 0xAC, "cpx", -0, XOP, 0xAE, "ldx", -0, XOP, 0xEE, "lds", -0, XOP, 0xA7, "sta", -0, XOP, 0xE7, "stb", -0, XOP, 0xAF, "stx", -0, XOP, 0xEF, "sts", -0, NOARG, 0x19, "daa", -0, NOARG, 0x01, "nop", -0, NOARG, 0x3B, "rti", -0, NOARG, 0x39, "rts", -0, NOARG, 0x3F, "swi", -0, NOARG, 0x0C, "clc", -0, NOARG, 0x0D, "sec", -0, NOARG, 0x0E, "cli", -0, NOARG, 0x0F, "sei", -0, NOARG, 0x0A, "clv", -0, NOARG, 0x0B, "sev", -0, NOARG, 0x3E, "wai", -0, NOARG, 0x06, "tap", -0, NOARG, 0x07, "tpa", -0, NOARG, 0x1B, "aba", -0, NOARG, 0x11, "cba", -0, NOARG, 0x10, "sba", -0, NOARG, 0x16, "tab", -0, NOARG, 0x17, "tba", -0, NOARG, 0x09, "dex", -0, NOARG, 0x08, "inx", -0, NOARG, 0x34, "des", -0, NOARG, 0x31, "ins", -0, NOARG, 0x35, "txs", -0, NOARG, 0x30, "tsx", +{0, X, 0, "x"}, +{0, BRANCH, 0x20, "bra"}, +{0, BRANCH, 0x22, "bhi"}, +{0, BRANCH, 0x23, "bls"}, +{0, BRANCH, 0x24, "bhs"}, /* bcc */ +{0, BRANCH, 0x24, "bcc"}, +{0, BRANCH, 0x25, "blo"}, /* bcs */ +{0, BRANCH, 0x25, "bcs"}, +{0, BRANCH, 0x26, "bne"}, +{0, BRANCH, 0x27, "beq"}, +{0, BRANCH, 0x28, "bvc"}, +{0, BRANCH, 0x29, "bvs"}, +{0, BRANCH, 0x2A, "bpl"}, +{0, BRANCH, 0x2B, "bmi"}, +{0, BRANCH, 0x2C, "bge"}, +{0, BRANCH, 0x2D, "blt"}, +{0, BRANCH, 0x2E, "bgt"}, +{0, BRANCH, 0x2F, "ble"}, +{0, BRANCH, 0x8D, "bsr"}, +{0, XOP, 0xA0, "suba"}, +{0, XOP, 0xA1, "cmpa"}, +{0, XOP, 0xA2, "sbca"}, +{0, XOP, 0xA4, "anda"}, +{0, XOP, 0xA5, "bita"}, +{0, XOP, 0xA6, "ldaa"}, +{0, XOP, 0xA8, "eora"}, +{0, XOP, 0xA9, "adca"}, +{0, XOP, 0xAA, "oraa"}, +{0, XOP, 0xAB, "adda"}, +{0, XOP, 0xE0, "subb"}, +{0, XOP, 0xE1, "cmpb"}, +{0, XOP, 0xE2, "sbcb"}, +{0, XOP, 0xE4, "andb"}, +{0, XOP, 0xE5, "bitb"}, +{0, XOP, 0xE6, "ldab"}, +{0, XOP, 0xE8, "eorb"}, +{0, XOP, 0xE9, "adcb"}, +{0, XOP, 0xEA, "orab"}, +{0, XOP, 0xEB, "addb"}, +{0, AOP, 0x60, "neg"}, +{0, NOARG, 0x40, "nega"}, +{0, NOARG, 0x50, "negb"}, +{0, AOP, 0x63, "com"}, +{0, NOARG, 0x43, "coma"}, +{0, NOARG, 0x53, "comb"}, +{0, AOP, 0x64, "lsr"}, +{0, NOARG, 0x44, "lsra"}, +{0, NOARG, 0x54, "lsrb"}, +{0, AOP, 0x66, "ror"}, +{0, NOARG, 0x46, "rora"}, +{0, NOARG, 0x56, "rorb"}, +{0, AOP, 0x67, "asr"}, +{0, NOARG, 0x47, "asra"}, +{0, NOARG, 0x57, "asrb"}, +{0, AOP, 0x68, "asl"}, +{0, NOARG, 0x48, "asla"}, +{0, NOARG, 0x58, "aslb"}, +{0, AOP, 0x68, "lsl"}, +{0, NOARG, 0x48, "lsla"}, +{0, NOARG, 0x58, "lslb"}, +{0, AOP, 0x69, "rol"}, +{0, NOARG, 0x49, "rola"}, +{0, NOARG, 0x59, "rolb"}, +{0, AOP, 0x6A, "dec"}, +{0, NOARG, 0x4A, "deca"}, +{0, NOARG, 0x5A, "decb"}, +{0, AOP, 0x6C, "inc"}, +{0, NOARG, 0x4C, "inca"}, +{0, NOARG, 0x5C, "incb"}, +{0, AOP, 0x6D, "tst"}, +{0, NOARG, 0x4D, "tsta"}, +{0, NOARG, 0x5D, "tstb"}, +{0, AOP, 0x6F, "clr"}, +{0, NOARG, 0x4F, "clra"}, +{0, NOARG, 0x5F, "clrb"}, +{0, XOP, 0x6E, "jmp"}, +{0, XOP, 0xAD, "jsr"}, +{0, XOP, 0xAC, "cpx"}, +{0, XOP, 0xAE, "ldx"}, +{0, XOP, 0xEE, "lds"}, +{0, XOP, 0xA7, "sta"}, +{0, XOP, 0xE7, "stb"}, +{0, XOP, 0xAF, "stx"}, +{0, XOP, 0xEF, "sts"}, +{0, NOARG, 0x19, "daa"}, +{0, NOARG, 0x01, "nop"}, +{0, NOARG, 0x3B, "rti"}, +{0, NOARG, 0x39, "rts"}, +{0, NOARG, 0x3F, "swi"}, +{0, NOARG, 0x0C, "clc"}, +{0, NOARG, 0x0D, "sec"}, +{0, NOARG, 0x0E, "cli"}, +{0, NOARG, 0x0F, "sei"}, +{0, NOARG, 0x0A, "clv"}, +{0, NOARG, 0x0B, "sev"}, +{0, NOARG, 0x3E, "wai"}, +{0, NOARG, 0x06, "tap"}, +{0, NOARG, 0x07, "tpa"}, +{0, NOARG, 0x1B, "aba"}, +{0, NOARG, 0x11, "cba"}, +{0, NOARG, 0x10, "sba"}, +{0, NOARG, 0x16, "tab"}, +{0, NOARG, 0x17, "tba"}, +{0, NOARG, 0x09, "dex"}, +{0, NOARG, 0x08, "inx"}, +{0, NOARG, 0x34, "des"}, +{0, NOARG, 0x31, "ins"}, +{0, NOARG, 0x35, "txs"}, +{0, NOARG, 0x30, "tsx"}, diff --git a/mach/6805/as/mach3.c b/mach/6805/as/mach3.c index 2d9d57cf8..d254105e8 100644 --- a/mach/6805/as/mach3.c +++ b/mach/6805/as/mach3.c @@ -10,118 +10,118 @@ /* * The X register */ -0, X, 0, "x", +{0, X, 0, "x"}, /* * Bit test and branch */ -0, BBRANCH, 0x00, "brset", -0, BBRANCH, 0x01, "brclr", +{0, BBRANCH, 0x00, "brset"}, +{0, BBRANCH, 0x01, "brclr"}, /* * Bit manipulation */ -0, BIT, 0x10, "bset", -0, BIT, 0x11, "bclr", +{0, BIT, 0x10, "bset"}, +{0, BIT, 0x11, "bclr"}, /* * Branches */ -0, BRANCH, 0x20, "bra", -0, BRANCH, 0x21, "brn", -0, BRANCH, 0x22, "bhi", -0, BRANCH, 0x23, "bls", -0, BRANCH, 0x24, "bcc", -0, BRANCH, 0x25, "bcs", -0, BRANCH, 0x26, "bne", -0, BRANCH, 0x27, "beq", -0, BRANCH, 0x28, "bhcc", -0, BRANCH, 0x29, "bhcs", -0, BRANCH, 0x2a, "bpl", -0, BRANCH, 0x2b, "bmi", -0, BRANCH, 0x2c, "bmc", -0, BRANCH, 0x2d, "bms", -0, BRANCH, 0x2e, "bil", -0, BRANCH, 0x2f, "bih", +{0, BRANCH, 0x20, "bra"}, +{0, BRANCH, 0x21, "brn"}, +{0, BRANCH, 0x22, "bhi"}, +{0, BRANCH, 0x23, "bls"}, +{0, BRANCH, 0x24, "bcc"}, +{0, BRANCH, 0x25, "bcs"}, +{0, BRANCH, 0x26, "bne"}, +{0, BRANCH, 0x27, "beq"}, +{0, BRANCH, 0x28, "bhcc"}, +{0, BRANCH, 0x29, "bhcs"}, +{0, BRANCH, 0x2a, "bpl"}, +{0, BRANCH, 0x2b, "bmi"}, +{0, BRANCH, 0x2c, "bmc"}, +{0, BRANCH, 0x2d, "bms"}, +{0, BRANCH, 0x2e, "bil"}, +{0, BRANCH, 0x2f, "bih"}, /* * Read modify write on anything but registers */ -0, RMR, 0x30, "neg", -0, RMR, 0x33, "com", -0, RMR, 0x34, "lsr", -0, RMR, 0x36, "ror", -0, RMR, 0x36, "asr", -0, RMR, 0x38, "lsl", -0, RMR, 0x39, "rol", -0, RMR, 0x3a, "dec", -0, RMR, 0x3c, "inc", -0, RMR, 0x3d, "tst", -0, RMR, 0x3f, "clr", +{0, RMR, 0x30, "neg"}, +{0, RMR, 0x33, "com"}, +{0, RMR, 0x34, "lsr"}, +{0, RMR, 0x36, "ror"}, +{0, RMR, 0x36, "asr"}, +{0, RMR, 0x38, "lsl"}, +{0, RMR, 0x39, "rol"}, +{0, RMR, 0x3a, "dec"}, +{0, RMR, 0x3c, "inc"}, +{0, RMR, 0x3d, "tst"}, +{0, RMR, 0x3f, "clr"}, /* * Implied stuff */ -0, NOARG, 0x80, "rti", -0, NOARG, 0x81, "rts", -0, NOARG, 0x83, "swi", -0, NOARG, 0x97, "tax", -0, NOARG, 0x98, "clc", -0, NOARG, 0x99, "sec", -0, NOARG, 0x9a, "cli", -0, NOARG, 0x9b, "sei", -0, NOARG, 0x9c, "rsp", -0, NOARG, 0x9d, "nop", -0, NOARG, 0x9f, "txa", +{0, NOARG, 0x80, "rti"}, +{0, NOARG, 0x81, "rts"}, +{0, NOARG, 0x83, "swi"}, +{0, NOARG, 0x97, "tax"}, +{0, NOARG, 0x98, "clc"}, +{0, NOARG, 0x99, "sec"}, +{0, NOARG, 0x9a, "cli"}, +{0, NOARG, 0x9b, "sei"}, +{0, NOARG, 0x9c, "rsp"}, +{0, NOARG, 0x9d, "nop"}, +{0, NOARG, 0x9f, "txa"}, /* * Register memory. * Warning. Some imediate opcodes excluded in parser actions. */ -0, RM, 0xa0, "sub", -0, RM, 0xa1, "cmp", -0, RM, 0xa2, "sbc", -0, RM, 0xa3, "cpx", -0, RM, 0xa4, "and", -0, RM, 0xa5, "bit", -0, RM, 0xa6, "lda", -0, RM, 0xa7, "sta", -0, RM, 0xa8, "eor", -0, RM, 0xa9, "adc", -0, RM, 0xaa, "ora", -0, RM, 0xab, "add", -0, RM, 0xac, "jmp", -0, BRANCH, 0xad, "bsr", -0, RM, 0xad, "jsr", -0, RM, 0xae, "ldx", -0, RM, 0xaf, "stx", +{0, RM, 0xa0, "sub"}, +{0, RM, 0xa1, "cmp"}, +{0, RM, 0xa2, "sbc"}, +{0, RM, 0xa3, "cpx"}, +{0, RM, 0xa4, "and"}, +{0, RM, 0xa5, "bit"}, +{0, RM, 0xa6, "lda"}, +{0, RM, 0xa7, "sta"}, +{0, RM, 0xa8, "eor"}, +{0, RM, 0xa9, "adc"}, +{0, RM, 0xaa, "ora"}, +{0, RM, 0xab, "add"}, +{0, RM, 0xac, "jmp"}, +{0, BRANCH, 0xad, "bsr"}, +{0, RM, 0xad, "jsr"}, +{0, RM, 0xae, "ldx"}, +{0, RM, 0xaf, "stx"}, /* * Branch synonyms */ -0, BRANCH, 0x24, "bhs", /* bcc */ -0, BRANCH, 0x25, "blo", /* bcs */ +{0, BRANCH, 0x24, "bhs"}, /* bcc */ +{0, BRANCH, 0x25, "blo"}, /* bcs */ /* * Brain damaged concatenated opcodes for RMR on registers */ -0, NOARG, 0x40, "nega", -0, NOARG, 0x43, "coma", -0, NOARG, 0x44, "lsra", -0, NOARG, 0x46, "rora", -0, NOARG, 0x47, "asra", -0, NOARG, 0x48, "lsla", -0, NOARG, 0x49, "rola", -0, NOARG, 0x4a, "deca", -0, NOARG, 0x4c, "inca", -0, NOARG, 0x4d, "tsta", -0, NOARG, 0x4f, "clra", -0, NOARG, 0x50, "negx", -0, NOARG, 0x53, "comx", -0, NOARG, 0x54, "lsrx", -0, NOARG, 0x56, "rorx", -0, NOARG, 0x57, "asrx", -0, NOARG, 0x58, "lslx", -0, NOARG, 0x59, "rolx", -0, NOARG, 0x5a, "decx", -0, NOARG, 0x5c, "incx", -0, NOARG, 0x5d, "tstx", -0, NOARG, 0x5f, "clrx", +{0, NOARG, 0x40, "nega"}, +{0, NOARG, 0x43, "coma"}, +{0, NOARG, 0x44, "lsra"}, +{0, NOARG, 0x46, "rora"}, +{0, NOARG, 0x47, "asra"}, +{0, NOARG, 0x48, "lsla"}, +{0, NOARG, 0x49, "rola"}, +{0, NOARG, 0x4a, "deca"}, +{0, NOARG, 0x4c, "inca"}, +{0, NOARG, 0x4d, "tsta"}, +{0, NOARG, 0x4f, "clra"}, +{0, NOARG, 0x50, "negx"}, +{0, NOARG, 0x53, "comx"}, +{0, NOARG, 0x54, "lsrx"}, +{0, NOARG, 0x56, "rorx"}, +{0, NOARG, 0x57, "asrx"}, +{0, NOARG, 0x58, "lslx"}, +{0, NOARG, 0x59, "rolx"}, +{0, NOARG, 0x5a, "decx"}, +{0, NOARG, 0x5c, "incx"}, +{0, NOARG, 0x5d, "tstx"}, +{0, NOARG, 0x5f, "clrx"}, /* * CMOS support */ -0, CMOS, 0, ".cmos", -0, CMOS, 0x8e, "stop", -0, CMOS, 0x8f, "wait", +{0, CMOS, 0, ".cmos"}, +{0, CMOS, 0x8e, "stop"}, +{0, CMOS, 0x8f, "wait"}, diff --git a/mach/6809/as/mach3.c b/mach/6809/as/mach3.c index f7a8fb922..a349f9f68 100644 --- a/mach/6809/as/mach3.c +++ b/mach/6809/as/mach3.c @@ -8,163 +8,163 @@ * Motorola 6809 keywords */ -0, REG, A, "a", -0, REG, B, "b", -0, REG, CC, "cc", -0, REG, DP, "dp", -0, REG, D, "d", -0, REG, X, "x", -0, REG, Y, "y", -0, REG, U, "u", -0, REG, S, "s", -0, REG, PC, "pc", -0, ALL, 0xFF, "all", -0, SETDP, 0, "setdp", -0, NOARG, 0x3A, "abx", -0, NOARG, 0x19, "daa", -0, NOARG, 0x3D, "mul", -0, NOARG, 0x12, "nop", -0, NOARG, 0x10, "page2", -0, NOARG, 0x11, "page3", -0, NOARG, 0x3B, "rti", -0, NOARG, 0x4F, "clra", -0, NOARG, 0x5F, "clrb", -0, NOARG, 0x4A, "deca", -0, NOARG, 0x5A, "decb", -0, NOARG, 0x43, "coma", -0, NOARG, 0x53, "comb", -0, NOARG, 0x44, "lsra", -0, NOARG, 0x54, "lsrb", -0, NOARG, 0x40, "nega", -0, NOARG, 0x50, "negb", -0, NOARG, 0x46, "rora", -0, NOARG, 0x56, "rorb", -0, NOARG, 0x47, "asra", -0, NOARG, 0x57, "asrb", -0, NOARG, 0x49, "rola", -0, NOARG, 0x59, "rolb", -0, NOARG, 0x48, "asla", -0, NOARG, 0x58, "aslb", -0, NOARG, 0x48, "lsla", -0, NOARG, 0x58, "lslb", -0, NOARG, 0x4C, "inca", -0, NOARG, 0x5C, "incb", -0, NOARG, 0x4D, "tsta", -0, NOARG, 0x5D, "tstb", -0, NOARG, 0x39, "rts", -0, NOARG, 0x1D, "sex", -0, NOARG, 0x3F, "swi", -0, NOARG, 0x103F, "swi2", -0, NOARG, 0x113F, "swi3", -0, NOARG, 0x13, "sync", -0, BRANCH, 0x20, "bra", -0, BRANCH, 0x21, "brn", -0, BRANCH, 0x22, "bhi", -0, BRANCH, 0x23, "bls", -0, BRANCH, 0x24, "bhs", -0, BRANCH, 0x24, "bcc", -0, BRANCH, 0x25, "blo", -0, BRANCH, 0x25, "bcs", -0, BRANCH, 0x26, "bne", -0, BRANCH, 0x27, "beq", -0, BRANCH, 0x28, "bvc", -0, BRANCH, 0x29, "bvs", -0, BRANCH, 0x2A, "bpl", -0, BRANCH, 0x2B, "bmi", -0, BRANCH, 0x2C, "bge", -0, BRANCH, 0x2D, "blt", -0, BRANCH, 0x2E, "bgt", -0, BRANCH, 0x2F, "ble", -0, BRANCH, 0x8D, "bsr", -0, STACK, 0x34, "pshs", -0, STACK, 0x35, "puls", -0, STACK, 0x36, "pshu", -0, STACK, 0x37, "pulu", -0, IMMED, 0x1A, "orcc", -0, IMMED, 0x1C, "andcc", -0, IMMED, 0x3C, "cwai", -0, TWOREG, 0x1E, "exg", -0, TWOREG, 0x1F, "tfr", -0, XOP, 0xA0, "suba", -0, XOP, 0xA1, "cmpa", -0, XOP, 0xA2, "sbca", -0, XOP, 0xA4, "anda", -0, XOP, 0xA5, "bita", -0, XOP, 0xA6, "lda", -0, XOP, 0xA8, "eora", -0, XOP, 0xA9, "adca", -0, XOP, 0xAA, "ora", -0, XOP, 0xAB, "adda", -0, XOP, 0xE0, "subb", -0, XOP, 0xE1, "cmpb", -0, XOP, 0xE2, "sbcb", -0, XOP, 0xE4, "andb", -0, XOP, 0xE5, "bitb", -0, XOP, 0xE6, "ldb", -0, XOP, 0xE8, "eorb", -0, XOP, 0xE9, "adcb", -0, XOP, 0xEA, "orb", -0, XOP, 0xEB, "addb", -0, XOP, 0x30, "leax", -0, XOP, 0x31, "leay", -0, XOP, 0x32, "leas", -0, XOP, 0x33, "leau", -0, XOP, 0x60, "neg", -0, XOP, 0x63, "com", -0, XOP, 0x64, "lsr", -0, XOP, 0x66, "ror", -0, XOP, 0x67, "asr", -0, XOP, 0x68, "asl", -0, XOP, 0x68, "lsl", -0, XOP, 0x69, "rol", -0, XOP, 0x6A, "dec", -0, XOP, 0x6C, "inc", -0, XOP, 0x6D, "tst", -0, XOP, 0x6F, "clr", -0, XOP, 0x6E, "jmp", -0, XOP, 0xA3, "subd", -0, XOP, 0x10A3, "cmpd", -0, XOP, 0x11A3, "cmpu", -0, XOP, 0xAC, "cmpx", -0, XOP, 0x10AC, "cmpy", -0, XOP, 0x11AC, "cmps", -0, XOP, 0xAE, "ldx", -0, XOP, 0x10AE, "ldy", -0, XOP, 0xE3, "addd", -0, XOP, 0xEC, "ldd", -0, XOP, 0xEE, "ldu", -0, XOP, 0x10EE, "lds", -0, XOP, 0xA7, "sta", -0, XOP, 0xAD, "jsr", -0, XOP, 0xAF, "stx", -0, XOP, 0x10AF, "sty", -0, XOP, 0xE7, "stb", -0, XOP, 0xED, "std", -0, XOP, 0xEF, "stu", -0, XOP, 0x10EF, "sts", -0, LBRNCH, 0x21, "lbrn", -0, LBRNCH, 0x22, "lbhi", -0, LBRNCH, 0x23, "lbls", -0, LBRNCH, 0x24, "lbhs", -0, LBRNCH, 0x24, "lbcc", -0, LBRNCH, 0x25, "lblo", -0, LBRNCH, 0x25, "lbcs", -0, LBRNCH, 0x26, "lbne", -0, LBRNCH, 0x27, "lbeq", -0, LBRNCH, 0x28, "lbvc", -0, LBRNCH, 0x29, "lbvs", -0, LBRNCH, 0x2A, "lbpl", -0, LBRNCH, 0x2B, "lbmi", -0, LBRNCH, 0x2C, "lbge", -0, LBRNCH, 0x2D, "lblt", -0, LBRNCH, 0x2E, "lbgt", -0, LBRNCH, 0x2F, "lble", -0, SBRNCH, 0x16, "lbra", -0, SBRNCH, 0x17, "lbsr", -0, NOARG, 0x1CFE, "clc", -0, NOARG, 0x1A01, "sec", -0, NOARG, 0x1CEF, "cli", -0, NOARG, 0x1A10, "sei", -0, NOARG, 0x1CFD, "clv", -0, NOARG, 0x1A02, "sev", -0, NOARG, 0x3CFF, "wai", +{0, REG, A, "a"}, +{0, REG, B, "b"}, +{0, REG, CC, "cc"}, +{0, REG, DP, "dp"}, +{0, REG, D, "d"}, +{0, REG, X, "x"}, +{0, REG, Y, "y"}, +{0, REG, U, "u"}, +{0, REG, S, "s"}, +{0, REG, PC, "pc"}, +{0, ALL, 0xFF, "all"}, +{0, SETDP, 0, "setdp"}, +{0, NOARG, 0x3A, "abx"}, +{0, NOARG, 0x19, "daa"}, +{0, NOARG, 0x3D, "mul"}, +{0, NOARG, 0x12, "nop"}, +{0, NOARG, 0x10, "page2"}, +{0, NOARG, 0x11, "page3"}, +{0, NOARG, 0x3B, "rti"}, +{0, NOARG, 0x4F, "clra"}, +{0, NOARG, 0x5F, "clrb"}, +{0, NOARG, 0x4A, "deca"}, +{0, NOARG, 0x5A, "decb"}, +{0, NOARG, 0x43, "coma"}, +{0, NOARG, 0x53, "comb"}, +{0, NOARG, 0x44, "lsra"}, +{0, NOARG, 0x54, "lsrb"}, +{0, NOARG, 0x40, "nega"}, +{0, NOARG, 0x50, "negb"}, +{0, NOARG, 0x46, "rora"}, +{0, NOARG, 0x56, "rorb"}, +{0, NOARG, 0x47, "asra"}, +{0, NOARG, 0x57, "asrb"}, +{0, NOARG, 0x49, "rola"}, +{0, NOARG, 0x59, "rolb"}, +{0, NOARG, 0x48, "asla"}, +{0, NOARG, 0x58, "aslb"}, +{0, NOARG, 0x48, "lsla"}, +{0, NOARG, 0x58, "lslb"}, +{0, NOARG, 0x4C, "inca"}, +{0, NOARG, 0x5C, "incb"}, +{0, NOARG, 0x4D, "tsta"}, +{0, NOARG, 0x5D, "tstb"}, +{0, NOARG, 0x39, "rts"}, +{0, NOARG, 0x1D, "sex"}, +{0, NOARG, 0x3F, "swi"}, +{0, NOARG, 0x103F, "swi2"}, +{0, NOARG, 0x113F, "swi3"}, +{0, NOARG, 0x13, "sync"}, +{0, BRANCH, 0x20, "bra"}, +{0, BRANCH, 0x21, "brn"}, +{0, BRANCH, 0x22, "bhi"}, +{0, BRANCH, 0x23, "bls"}, +{0, BRANCH, 0x24, "bhs"}, +{0, BRANCH, 0x24, "bcc"}, +{0, BRANCH, 0x25, "blo"}, +{0, BRANCH, 0x25, "bcs"}, +{0, BRANCH, 0x26, "bne"}, +{0, BRANCH, 0x27, "beq"}, +{0, BRANCH, 0x28, "bvc"}, +{0, BRANCH, 0x29, "bvs"}, +{0, BRANCH, 0x2A, "bpl"}, +{0, BRANCH, 0x2B, "bmi"}, +{0, BRANCH, 0x2C, "bge"}, +{0, BRANCH, 0x2D, "blt"}, +{0, BRANCH, 0x2E, "bgt"}, +{0, BRANCH, 0x2F, "ble"}, +{0, BRANCH, 0x8D, "bsr"}, +{0, STACK, 0x34, "pshs"}, +{0, STACK, 0x35, "puls"}, +{0, STACK, 0x36, "pshu"}, +{0, STACK, 0x37, "pulu"}, +{0, IMMED, 0x1A, "orcc"}, +{0, IMMED, 0x1C, "andcc"}, +{0, IMMED, 0x3C, "cwai"}, +{0, TWOREG, 0x1E, "exg"}, +{0, TWOREG, 0x1F, "tfr"}, +{0, XOP, 0xA0, "suba"}, +{0, XOP, 0xA1, "cmpa"}, +{0, XOP, 0xA2, "sbca"}, +{0, XOP, 0xA4, "anda"}, +{0, XOP, 0xA5, "bita"}, +{0, XOP, 0xA6, "lda"}, +{0, XOP, 0xA8, "eora"}, +{0, XOP, 0xA9, "adca"}, +{0, XOP, 0xAA, "ora"}, +{0, XOP, 0xAB, "adda"}, +{0, XOP, 0xE0, "subb"}, +{0, XOP, 0xE1, "cmpb"}, +{0, XOP, 0xE2, "sbcb"}, +{0, XOP, 0xE4, "andb"}, +{0, XOP, 0xE5, "bitb"}, +{0, XOP, 0xE6, "ldb"}, +{0, XOP, 0xE8, "eorb"}, +{0, XOP, 0xE9, "adcb"}, +{0, XOP, 0xEA, "orb"}, +{0, XOP, 0xEB, "addb"}, +{0, XOP, 0x30, "leax"}, +{0, XOP, 0x31, "leay"}, +{0, XOP, 0x32, "leas"}, +{0, XOP, 0x33, "leau"}, +{0, XOP, 0x60, "neg"}, +{0, XOP, 0x63, "com"}, +{0, XOP, 0x64, "lsr"}, +{0, XOP, 0x66, "ror"}, +{0, XOP, 0x67, "asr"}, +{0, XOP, 0x68, "asl"}, +{0, XOP, 0x68, "lsl"}, +{0, XOP, 0x69, "rol"}, +{0, XOP, 0x6A, "dec"}, +{0, XOP, 0x6C, "inc"}, +{0, XOP, 0x6D, "tst"}, +{0, XOP, 0x6F, "clr"}, +{0, XOP, 0x6E, "jmp"}, +{0, XOP, 0xA3, "subd"}, +{0, XOP, 0x10A3, "cmpd"}, +{0, XOP, 0x11A3, "cmpu"}, +{0, XOP, 0xAC, "cmpx"}, +{0, XOP, 0x10AC, "cmpy"}, +{0, XOP, 0x11AC, "cmps"}, +{0, XOP, 0xAE, "ldx"}, +{0, XOP, 0x10AE, "ldy"}, +{0, XOP, 0xE3, "addd"}, +{0, XOP, 0xEC, "ldd"}, +{0, XOP, 0xEE, "ldu"}, +{0, XOP, 0x10EE, "lds"}, +{0, XOP, 0xA7, "sta"}, +{0, XOP, 0xAD, "jsr"}, +{0, XOP, 0xAF, "stx"}, +{0, XOP, 0x10AF, "sty"}, +{0, XOP, 0xE7, "stb"}, +{0, XOP, 0xED, "std"}, +{0, XOP, 0xEF, "stu"}, +{0, XOP, 0x10EF, "sts"}, +{0, LBRNCH, 0x21, "lbrn"}, +{0, LBRNCH, 0x22, "lbhi"}, +{0, LBRNCH, 0x23, "lbls"}, +{0, LBRNCH, 0x24, "lbhs"}, +{0, LBRNCH, 0x24, "lbcc"}, +{0, LBRNCH, 0x25, "lblo"}, +{0, LBRNCH, 0x25, "lbcs"}, +{0, LBRNCH, 0x26, "lbne"}, +{0, LBRNCH, 0x27, "lbeq"}, +{0, LBRNCH, 0x28, "lbvc"}, +{0, LBRNCH, 0x29, "lbvs"}, +{0, LBRNCH, 0x2A, "lbpl"}, +{0, LBRNCH, 0x2B, "lbmi"}, +{0, LBRNCH, 0x2C, "lbge"}, +{0, LBRNCH, 0x2D, "lblt"}, +{0, LBRNCH, 0x2E, "lbgt"}, +{0, LBRNCH, 0x2F, "lble"}, +{0, SBRNCH, 0x16, "lbra"}, +{0, SBRNCH, 0x17, "lbsr"}, +{0, NOARG, 0x1CFE, "clc"}, +{0, NOARG, 0x1A01, "sec"}, +{0, NOARG, 0x1CEF, "cli"}, +{0, NOARG, 0x1A10, "sei"}, +{0, NOARG, 0x1CFD, "clv"}, +{0, NOARG, 0x1A02, "sev"}, +{0, NOARG, 0x3CFF, "wai"}, diff --git a/mach/arm/as/mach3.c b/mach/arm/as/mach3.c index a35feb540..9ea286650 100644 --- a/mach/arm/as/mach3.c +++ b/mach/arm/as/mach3.c @@ -1,121 +1,121 @@ /* $Id: mach3.c, v2.0 23-Feb-89 AJM */ -0, COND, 0x00000000, ".EQ", -0, COND, 0x10000000, ".NE", -0, COND, 0x20000000, ".CS", -0, COND, 0x20000000, ".HS", -0, COND, 0x30000000, ".CC", -0, COND, 0x30000000, ".LO", -0, COND, 0x40000000, ".MI", -0, COND, 0x50000000, ".PL", -0, COND, 0x60000000, ".VS", -0, COND, 0x70000000, ".VC", -0, COND, 0x80000000, ".HI", -0, COND, 0x90000000, ".LS", -0, COND, 0xA0000000, ".GE", -0, COND, 0xB0000000, ".LT", -0, COND, 0xC0000000, ".GT", -0, COND, 0xD0000000, ".LE", -0, COND, 0xE0000000, ".AL", -0, COND, 0xF0000000, ".NV", +{0, COND, 0x00000000, ".EQ"}, +{0, COND, 0x10000000, ".NE"}, +{0, COND, 0x20000000, ".CS"}, +{0, COND, 0x20000000, ".HS"}, +{0, COND, 0x30000000, ".CC"}, +{0, COND, 0x30000000, ".LO"}, +{0, COND, 0x40000000, ".MI"}, +{0, COND, 0x50000000, ".PL"}, +{0, COND, 0x60000000, ".VS"}, +{0, COND, 0x70000000, ".VC"}, +{0, COND, 0x80000000, ".HI"}, +{0, COND, 0x90000000, ".LS"}, +{0, COND, 0xA0000000, ".GE"}, +{0, COND, 0xB0000000, ".LT"}, +{0, COND, 0xC0000000, ".GT"}, +{0, COND, 0xD0000000, ".LE"}, +{0, COND, 0xE0000000, ".AL"}, +{0, COND, 0xF0000000, ".NV"}, -0, LINK, 0x01000000, ".L", +{0, LINK, 0x01000000, ".L"}, -0, BRANCH, 0x0A000000, "BEQ", -0, BRANCH, 0x1A000000, "BNE", -0, BRANCH, 0x2A000000, "BCS", -0, BRANCH, 0x2A000000, "BHS", -0, BRANCH, 0x3A000000, "BCC", -0, BRANCH, 0x3A000000, "BLO", -0, BRANCH, 0x4A000000, "BMI", -0, BRANCH, 0x5A000000, "BPL", -0, BRANCH, 0x6A000000, "BVS", -0, BRANCH, 0x7A000000, "BVC", -0, BRANCH, 0x8A000000, "BHI", -0, BRANCH, 0x9A000000, "BLS", -0, BRANCH, 0xAA000000, "BGE", -0, BRANCH, 0xBA000000, "BLT", -0, BRANCH, 0xCA000000, "BGT", -0, BRANCH, 0xDA000000, "BLE", -0, BRANCH, 0xEA000000, "BAL", -0, BRANCH, 0xFA000000, "BNV", +{0, BRANCH, 0x0A000000, "BEQ"}, +{0, BRANCH, 0x1A000000, "BNE"}, +{0, BRANCH, 0x2A000000, "BCS"}, +{0, BRANCH, 0x2A000000, "BHS"}, +{0, BRANCH, 0x3A000000, "BCC"}, +{0, BRANCH, 0x3A000000, "BLO"}, +{0, BRANCH, 0x4A000000, "BMI"}, +{0, BRANCH, 0x5A000000, "BPL"}, +{0, BRANCH, 0x6A000000, "BVS"}, +{0, BRANCH, 0x7A000000, "BVC"}, +{0, BRANCH, 0x8A000000, "BHI"}, +{0, BRANCH, 0x9A000000, "BLS"}, +{0, BRANCH, 0xAA000000, "BGE"}, +{0, BRANCH, 0xBA000000, "BLT"}, +{0, BRANCH, 0xCA000000, "BGT"}, +{0, BRANCH, 0xDA000000, "BLE"}, +{0, BRANCH, 0xEA000000, "BAL"}, +{0, BRANCH, 0xFA000000, "BNV"}, -0, DATA1, ADC, "ADC", -0, DATA1, ADD, "ADD", -0, DATA1, AND, "AND", -0, DATA1, BIC, "BIC", -0, DATA1, EOR, "EOR", -0, DATA1, ORR, "ORR", -0, DATA1, RSB, "RSB", -0, DATA1, RSC, "RSC", -0, DATA1, SBC, "SBC", -0, DATA1, SUB, "SUB", -0, DATA2, MOV, "MOV", -0, DATA2, MVN, "MVN", -0, DATA3, CMN, "CMN", -0, DATA3, CMP, "CMP", -0, DATA3, TEQ, "TEQ", -0, DATA3, TST, "TST", +{0, DATA1, ADC, "ADC"}, +{0, DATA1, ADD, "ADD"}, +{0, DATA1, AND, "AND"}, +{0, DATA1, BIC, "BIC"}, +{0, DATA1, EOR, "EOR"}, +{0, DATA1, ORR, "ORR"}, +{0, DATA1, RSB, "RSB"}, +{0, DATA1, RSC, "RSC"}, +{0, DATA1, SBC, "SBC"}, +{0, DATA1, SUB, "SUB"}, +{0, DATA2, MOV, "MOV"}, +{0, DATA2, MVN, "MVN"}, +{0, DATA3, CMN, "CMN"}, +{0, DATA3, CMP, "CMP"}, +{0, DATA3, TEQ, "TEQ"}, +{0, DATA3, TST, "TST"}, -0, SET, 0x00100000, ".S", +{0, SET, 0x00100000, ".S"}, -0, PEE, 0x0010F000, ".P", +{0, PEE, 0x0010F000, ".P"}, -0, REG, 0, "R0", -0, REG, 1, "R1", -0, REG, 2, "R2", -0, REG, 3, "R3", -0, REG, 4, "R4", -0, REG, 5, "R5", -0, REG, 6, "R6", -0, REG, 7, "R7", -0, REG, 8, "R8", -0, REG, 9, "R9", -0, REG, 10, "R10", -0, REG, 11, "R11", -0, REG, 12, "R12", -0, REG, 13, "R13", -0, REG, 14, "R14", -0, REG, 15, "R15", -0, REG, 15, "PC", +{0, REG, 0, "R0"}, +{0, REG, 1, "R1"}, +{0, REG, 2, "R2"}, +{0, REG, 3, "R3"}, +{0, REG, 4, "R4"}, +{0, REG, 5, "R5"}, +{0, REG, 6, "R6"}, +{0, REG, 7, "R7"}, +{0, REG, 8, "R8"}, +{0, REG, 9, "R9"}, +{0, REG, 10, "R10"}, +{0, REG, 11, "R11"}, +{0, REG, 12, "R12"}, +{0, REG, 13, "R13"}, +{0, REG, 14, "R14"}, +{0, REG, 15, "R15"}, +{0, REG, 15, "PC"}, -0, SHIFT, 0x00000000, "LSL", -0, SHIFT, 0x00000000, "ASL", -0, SHIFT, 0x00000020, "LSR", -0, SHIFT, 0x00000040, "ASR", -0, SHIFT, 0x00000060, "ROR", +{0, SHIFT, 0x00000000, "LSL"}, +{0, SHIFT, 0x00000000, "ASL"}, +{0, SHIFT, 0x00000020, "LSR"}, +{0, SHIFT, 0x00000040, "ASR"}, +{0, SHIFT, 0x00000060, "ROR"}, -0, RRX, 0x00000060, "RRX", +{0, RRX, 0x00000060, "RRX"}, -0, SDT, 0x04100000, "LDR", -0, SDT, 0x04000000, "STR", +{0, SDT, 0x04100000, "LDR"}, +{0, SDT, 0x04000000, "STR"}, -0, BYTE, 0x00400000, ".B", +{0, BYTE, 0x00400000, ".B"}, -0, TRANS, 0x00200000, ".T", +{0, TRANS, 0x00200000, ".T"}, -0, BDT, 0x09100000, "LDMDB", -0, BDT, 0x08100000, "LDMDA", -0, BDT, 0x09900000, "LDMIB", -0, BDT, 0x08900000, "LDMIA", -0, BDT, 0x08900000, "LDMFD", -0, BDT, 0x08100000, "LDMFA", -0, BDT, 0x09900000, "LDMED", -0, BDT, 0x09100000, "LDMEA", -0, BDT, 0x09000000, "STMDB", -0, BDT, 0x08000000, "STMDA", -0, BDT, 0x09800000, "STMIB", -0, BDT, 0x08800000, "STMIA", -0, BDT, 0x09000000, "STMFD", -0, BDT, 0x09800000, "STMFA", -0, BDT, 0x08000000, "STMED", -0, BDT, 0x08800000, "STMEA", +{0, BDT, 0x09100000, "LDMDB"}, +{0, BDT, 0x08100000, "LDMDA"}, +{0, BDT, 0x09900000, "LDMIB"}, +{0, BDT, 0x08900000, "LDMIA"}, +{0, BDT, 0x08900000, "LDMFD"}, +{0, BDT, 0x08100000, "LDMFA"}, +{0, BDT, 0x09900000, "LDMED"}, +{0, BDT, 0x09100000, "LDMEA"}, +{0, BDT, 0x09000000, "STMDB"}, +{0, BDT, 0x08000000, "STMDA"}, +{0, BDT, 0x09800000, "STMIB"}, +{0, BDT, 0x08800000, "STMIA"}, +{0, BDT, 0x09000000, "STMFD"}, +{0, BDT, 0x09800000, "STMFA"}, +{0, BDT, 0x08000000, "STMED"}, +{0, BDT, 0x08800000, "STMEA"}, -0, SWI, 0x0F000000, "SWI", +{0, SWI, 0x0F000000, "SWI"}, -0, ADR, 0x00000000, "ADR", +{0, ADR, 0x00000000, "ADR"}, -0, MUL, 0x00000090, "MUL", -0, MLA, 0x00200090, "MLA", +{0, MUL, 0x00000090, "MUL"}, +{0, MLA, 0x00200090, "MLA"}, diff --git a/mach/i386/as/mach3.c b/mach/i386/as/mach3.c index 1a348b584..37f03566b 100644 --- a/mach/i386/as/mach3.c +++ b/mach/i386/as/mach3.c @@ -10,411 +10,411 @@ * No system registers for now ... */ -0, USE16, 0, ".use16", -0, USE32, 0, ".use32", -0, R32, 0, "ax", -0, R32, 1, "cx", -0, R32, 2, "dx", -0, R32, 3, "bx", -0, R32, 4, "sp", -0, R32, 5, "bp", -0, R32, 6, "si", -0, R32, 7, "di", -0, R32, 0, "eax", -0, R32, 1, "ecx", -0, R32, 2, "edx", -0, R32, 3, "ebx", -0, R32, 4, "esp", -0, R32, 5, "ebp", -0, R32, 6, "esi", -0, R32, 7, "edi", -0, R8, 0, "al", -0, R8, 1, "cl", -0, R8, 2, "dl", -0, R8, 3, "bl", -0, R8, 4, "ah", -0, R8, 5, "ch", -0, R8, 6, "dh", -0, R8, 7, "bh", -0, RSEG, 0, "es", -0, RSEG, 1, "cs", -0, RSEG, 2, "ss", -0, RSEG, 3, "ds", -0, RSEG, 4, "fs", -0, RSEG, 5, "gs", -0, RSYSCR, 0, "cr0", -0, RSYSCR, 2, "cr2", -0, RSYSCR, 3, "cr3", -0, RSYSDR, 0, "dr0", -0, RSYSDR, 1, "dr1", -0, RSYSDR, 2, "dr2", -0, RSYSDR, 3, "dr3", -0, RSYSDR, 6, "dr6", -0, RSYSDR, 7, "dr7", -0, RSYSTR, 3, "tr3", /* i486 */ -0, RSYSTR, 4, "tr4", /* i486 */ -0, RSYSTR, 5, "tr5", /* i486 */ -0, RSYSTR, 6, "tr6", -0, RSYSTR, 7, "tr7", -0, ADDOP, 000, "addb", -0, ADDOP, 001, "add", -0, ADDOP, 010, "orb", -0, ADDOP, 011, "or", -0, ADDOP, 020, "adcb", -0, ADDOP, 021, "adc", -0, ADDOP, 030, "sbbb", -0, ADDOP, 031, "sbb", -0, ADDOP, 040, "andb", -0, ADDOP, 041, "and", -0, ADDOP, 050, "subb", -0, ADDOP, 051, "sub", -0, ADDOP, 060, "xorb", -0, ADDOP, 061, "xor", -0, ADDOP, 070, "cmpb", -0, ADDOP, 071, "cmp", -0, BITTEST, 04, "bt", -0, BITTEST, 05, "bts", -0, BITTEST, 06, "btr", -0, BITTEST, 07, "btc", -0, CALFOP, 030+(0232<<8), "callf", -0, CALFOP, 050+(0352<<8), "jmpf", -0, CALLOP, 020+(0350<<8), "call", -0, CALLOP, 040+(0351<<8), "jmp", -0, ENTER, 0310, "enter", -0, EXTEND, 0267, "movzx", -0, EXTEND, 0266, "movzxb", -0, EXTEND, 0277, "movsx", -0, EXTEND, 0276, "movsxb", -0, EXTOP, 0002, "lar", -0, EXTOP, 0003, "lsl", -0, EXTOP, 0274, "bsf", -0, EXTOP, 0275, "bsr", -0, EXTOP1, 0000, "sldt", -0, EXTOP1, 0001, "sgdt", -0, EXTOP1, 0010, "str", -0, EXTOP1, 0011, "sidt", -0, EXTOP1, 0020, "lldt", -0, EXTOP1, 0021, "lgdt", -0, EXTOP1, 0030, "ltr", -0, EXTOP1, 0031, "lidt", -0, EXTOP1, 0040, "verr", -0, EXTOP1, 0041, "smsw", -0, EXTOP1, 0050, "verw", -0, EXTOP1, 0061, "lmsw", -0, IMUL, 00, "imul", -0, IMULB, 050, "imulb", -0, INCOP, 000, "incb", -0, INCOP, 001, "inc", -0, INCOP, 010, "decb", -0, INCOP, 011, "dec", -0, INT, 0, "int", -0, IOOP, 0344, "inb", -0, IOOP, 0345, "in", -0, IOOP, 0346, "outb", -0, IOOP, 0347, "out", -0, JOP, 0340, "loopne", -0, JOP, 0340, "loopnz", -0, JOP, 0341, "loope", -0, JOP, 0341, "loopz", -0, JOP, 0342, "loop", -0, JOP, 0343, "jcxz", -0, JOP, 0343, "jecxz", -0, JOP2, 0000, "jo", -0, JOP2, 0001, "jno", -0, JOP2, 0002, "jb", -0, JOP2, 0002, "jc", -0, JOP2, 0002, "jnae", -0, JOP2, 0003, "jae", -0, JOP2, 0003, "jnb", -0, JOP2, 0003, "jnc", -0, JOP2, 0004, "je", -0, JOP2, 0004, "jz", -0, JOP2, 0005, "jne", -0, JOP2, 0005, "jnz", -0, JOP2, 0006, "jbe", -0, JOP2, 0006, "jna", -0, JOP2, 0007, "ja", -0, JOP2, 0007, "jnbe", -0, JOP2, 0010, "js", -0, JOP2, 0011, "jns", -0, JOP2, 0012, "jp", -0, JOP2, 0012, "jpe", -0, JOP2, 0013, "jnp", -0, JOP2, 0013, "jpo", -0, JOP2, 0014, "jl", -0, JOP2, 0014, "jnge", -0, JOP2, 0015, "jge", -0, JOP2, 0015, "jnl", -0, JOP2, 0016, "jle", -0, JOP2, 0016, "jng", -0, JOP2, 0017, "jg", -0, JOP2, 0017, "jnle", -0, LEAOP, 0142, "bound", -0, LEAOP, 0215, "lea", -0, LEAOP, 0304, "les", -0, LEAOP, 0305, "lds", -0, LEAOP2, 0262, "lss", -0, LEAOP2, 0264, "lfs", -0, LEAOP2, 0265, "lgs", -0, LSHFT, 0244, "shld", -0, LSHFT, 0254, "shrd", -0, MOV, 0, "movb", -0, MOV, 1, "mov", -0, NOOP_1, 0140, "pusha", -0, NOOP_1, 0140, "pushad", -0, NOOP_1, 0141, "popa", -0, NOOP_1, 0141, "popad", -0, NOOP_1, 0156, "outsb", -0, NOOP_1, 0157, "outs", -0, NOOP_1, 0220, "nop", -0, NOOP_1, 0230, "cbw", -0, NOOP_1, 0230, "cwde", /* same opcode as cbw! */ -0, NOOP_1, 0231, "cdq", /* same opcode as cwd! */ -0, NOOP_1, 0231, "cwd", -0, NOOP_1, 0233, "wait", -0, NOOP_1, 0234, "pushf", -0, NOOP_1, 0235, "popf", -0, NOOP_1, 0236, "sahf", -0, NOOP_1, 0237, "lahf", -0, NOOP_1, 0244, "movsb", -0, NOOP_1, 0245, "movs", -0, NOOP_1, 0246, "cmpsb", -0, NOOP_1, 0154, "insb", -0, NOOP_1, 0247, "cmps", -0, NOOP_1, 0155, "ins", -0, NOOP_1, 0252, "stosb", -0, NOOP_1, 0253, "stos", -0, NOOP_1, 0254, "lodsb", -0, NOOP_1, 0255, "lods", -0, NOOP_1, 0256, "scasb", -0, NOOP_1, 0257, "scas", -0, NOOP_1, 0311, "leave", -0, NOOP_1, 0316, "into", -0, NOOP_1, 0317, "iret", -0, NOOP_1, 0317, "iretd", -0, NOOP_1, 0327, "xlat", -0, NOOP_1, 0364, "hlt", -0, NOOP_1, 0365, "cmc", -0, NOOP_1, 0370, "clc", -0, NOOP_1, 0371, "stc", -0, NOOP_1, 0372, "cli", -0, NOOP_1, 0373, "sti", -0, NOOP_1, 0374, "cld", -0, NOOP_1, 0375, "std", -0, NOOP_1, 047, "daa", -0, NOOP_1, 057, "das", -0, NOOP_1, 067, "aaa", -0, NOOP_1, 077, "aas", -0, NOOP_2, 017+(06<<8), "clts", -0, NOOP_2, 0324+(012<<8), "aam", -0, NOOP_2, 0325+(012<<8), "aad", -0, NOTOP, 020, "notb", -0, NOTOP, 021, "not", -0, NOTOP, 030, "negb", -0, NOTOP, 031, "neg", -0, NOTOP, 040, "mulb", -0, NOTOP, 041, "mul", -0, NOTOP, 060, "divb", -0, NOTOP, 061, "div", -0, NOTOP, 070, "idivb", -0, NOTOP, 071, "idiv", -0, PREFIX, 0144, "fseg", -0, PREFIX, 0145, "gseg", -0, OTOGGLE, 0146, "o16", /* operand size toggle */ -0, OTOGGLE, 0346, "o32", /* operand size toggle */ -0, ATOGGLE, 0147, "a16", /* address size toggle */ -0, ATOGGLE, 0347, "a32", /* address size toggle */ -0, PREFIX, 0360, "lock", -0, PREFIX, 0362, "repne", -0, PREFIX, 0362, "repnz", -0, PREFIX, 0363, "rep", -0, PREFIX, 0363, "repe", -0, PREFIX, 0363, "repz", -0, PREFIX, 046, "eseg", -0, PREFIX, 056, "cseg", -0, PREFIX, 066, "sseg", -0, PREFIX, 076, "dseg", -0, PUSHOP, 0, "push", -0, PUSHOP, 1, "pop", -0, RET, 0303, "ret", -0, RET, 0313, "retf", -0, ROLOP, 000, "rolb", -0, ROLOP, 001, "rol", -0, ROLOP, 010, "rorb", -0, ROLOP, 011, "ror", -0, ROLOP, 020, "rclb", -0, ROLOP, 021, "rcl", -0, ROLOP, 030, "rcrb", -0, ROLOP, 031, "rcr", -0, ROLOP, 040, "salb", -0, ROLOP, 040, "shlb", -0, ROLOP, 041, "sal", -0, ROLOP, 041, "shl", -0, ROLOP, 050, "shrb", -0, ROLOP, 051, "shr", -0, ROLOP, 070, "sarb", -0, ROLOP, 071, "sar", -0, SETCC, 0000, "seto", -0, SETCC, 0001, "setno", -0, SETCC, 0002, "setb", -0, SETCC, 0002, "setnae", -0, SETCC, 0003, "setae", -0, SETCC, 0003, "setnb", -0, SETCC, 0004, "sete", -0, SETCC, 0004, "setz", -0, SETCC, 0005, "setne", -0, SETCC, 0005, "setnz", -0, SETCC, 0006, "setbe", -0, SETCC, 0006, "setna", -0, SETCC, 0007, "seta", -0, SETCC, 0007, "setnbe", -0, SETCC, 0010, "sets", -0, SETCC, 0011, "setns", -0, SETCC, 0012, "setp", -0, SETCC, 0012, "setpe", -0, SETCC, 0013, "setnp", -0, SETCC, 0013, "setpo", -0, SETCC, 0014, "setl", -0, SETCC, 0014, "setnge", -0, SETCC, 0015, "setge", -0, SETCC, 0015, "setnl", -0, SETCC, 0016, "setle", -0, SETCC, 0016, "setng", -0, SETCC, 0017, "setg", -0, SETCC, 0017, "setnle", -0, TEST, 0, "testb", -0, TEST, 1, "test", -0, XCHG, 0, "xchgb", -0, XCHG, 1, "xchg", -0, ARPLOP, 0143, "arpl", +{0, USE16, 0, ".use16"}, +{0, USE32, 0, ".use32"}, +{0, R32, 0, "ax"}, +{0, R32, 1, "cx"}, +{0, R32, 2, "dx"}, +{0, R32, 3, "bx"}, +{0, R32, 4, "sp"}, +{0, R32, 5, "bp"}, +{0, R32, 6, "si"}, +{0, R32, 7, "di"}, +{0, R32, 0, "eax"}, +{0, R32, 1, "ecx"}, +{0, R32, 2, "edx"}, +{0, R32, 3, "ebx"}, +{0, R32, 4, "esp"}, +{0, R32, 5, "ebp"}, +{0, R32, 6, "esi"}, +{0, R32, 7, "edi"}, +{0, R8, 0, "al"}, +{0, R8, 1, "cl"}, +{0, R8, 2, "dl"}, +{0, R8, 3, "bl"}, +{0, R8, 4, "ah"}, +{0, R8, 5, "ch"}, +{0, R8, 6, "dh"}, +{0, R8, 7, "bh"}, +{0, RSEG, 0, "es"}, +{0, RSEG, 1, "cs"}, +{0, RSEG, 2, "ss"}, +{0, RSEG, 3, "ds"}, +{0, RSEG, 4, "fs"}, +{0, RSEG, 5, "gs"}, +{0, RSYSCR, 0, "cr0"}, +{0, RSYSCR, 2, "cr2"}, +{0, RSYSCR, 3, "cr3"}, +{0, RSYSDR, 0, "dr0"}, +{0, RSYSDR, 1, "dr1"}, +{0, RSYSDR, 2, "dr2"}, +{0, RSYSDR, 3, "dr3"}, +{0, RSYSDR, 6, "dr6"}, +{0, RSYSDR, 7, "dr7"}, +{0, RSYSTR, 3, "tr3"}, /* i486 */ +{0, RSYSTR, 4, "tr4"}, /* i486 */ +{0, RSYSTR, 5, "tr5"}, /* i486 */ +{0, RSYSTR, 6, "tr6"}, +{0, RSYSTR, 7, "tr7"}, +{0, ADDOP, 000, "addb"}, +{0, ADDOP, 001, "add"}, +{0, ADDOP, 010, "orb"}, +{0, ADDOP, 011, "or"}, +{0, ADDOP, 020, "adcb"}, +{0, ADDOP, 021, "adc"}, +{0, ADDOP, 030, "sbbb"}, +{0, ADDOP, 031, "sbb"}, +{0, ADDOP, 040, "andb"}, +{0, ADDOP, 041, "and"}, +{0, ADDOP, 050, "subb"}, +{0, ADDOP, 051, "sub"}, +{0, ADDOP, 060, "xorb"}, +{0, ADDOP, 061, "xor"}, +{0, ADDOP, 070, "cmpb"}, +{0, ADDOP, 071, "cmp"}, +{0, BITTEST, 04, "bt"}, +{0, BITTEST, 05, "bts"}, +{0, BITTEST, 06, "btr"}, +{0, BITTEST, 07, "btc"}, +{0, CALFOP, 030+(0232<<8), "callf"}, +{0, CALFOP, 050+(0352<<8), "jmpf"}, +{0, CALLOP, 020+(0350<<8), "call"}, +{0, CALLOP, 040+(0351<<8), "jmp"}, +{0, ENTER, 0310, "enter"}, +{0, EXTEND, 0267, "movzx"}, +{0, EXTEND, 0266, "movzxb"}, +{0, EXTEND, 0277, "movsx"}, +{0, EXTEND, 0276, "movsxb"}, +{0, EXTOP, 0002, "lar"}, +{0, EXTOP, 0003, "lsl"}, +{0, EXTOP, 0274, "bsf"}, +{0, EXTOP, 0275, "bsr"}, +{0, EXTOP1, 0000, "sldt"}, +{0, EXTOP1, 0001, "sgdt"}, +{0, EXTOP1, 0010, "str"}, +{0, EXTOP1, 0011, "sidt"}, +{0, EXTOP1, 0020, "lldt"}, +{0, EXTOP1, 0021, "lgdt"}, +{0, EXTOP1, 0030, "ltr"}, +{0, EXTOP1, 0031, "lidt"}, +{0, EXTOP1, 0040, "verr"}, +{0, EXTOP1, 0041, "smsw"}, +{0, EXTOP1, 0050, "verw"}, +{0, EXTOP1, 0061, "lmsw"}, +{0, IMUL, 00, "imul"}, +{0, IMULB, 050, "imulb"}, +{0, INCOP, 000, "incb"}, +{0, INCOP, 001, "inc"}, +{0, INCOP, 010, "decb"}, +{0, INCOP, 011, "dec"}, +{0, INT, 0, "int"}, +{0, IOOP, 0344, "inb"}, +{0, IOOP, 0345, "in"}, +{0, IOOP, 0346, "outb"}, +{0, IOOP, 0347, "out"}, +{0, JOP, 0340, "loopne"}, +{0, JOP, 0340, "loopnz"}, +{0, JOP, 0341, "loope"}, +{0, JOP, 0341, "loopz"}, +{0, JOP, 0342, "loop"}, +{0, JOP, 0343, "jcxz"}, +{0, JOP, 0343, "jecxz"}, +{0, JOP2, 0000, "jo"}, +{0, JOP2, 0001, "jno"}, +{0, JOP2, 0002, "jb"}, +{0, JOP2, 0002, "jc"}, +{0, JOP2, 0002, "jnae"}, +{0, JOP2, 0003, "jae"}, +{0, JOP2, 0003, "jnb"}, +{0, JOP2, 0003, "jnc"}, +{0, JOP2, 0004, "je"}, +{0, JOP2, 0004, "jz"}, +{0, JOP2, 0005, "jne"}, +{0, JOP2, 0005, "jnz"}, +{0, JOP2, 0006, "jbe"}, +{0, JOP2, 0006, "jna"}, +{0, JOP2, 0007, "ja"}, +{0, JOP2, 0007, "jnbe"}, +{0, JOP2, 0010, "js"}, +{0, JOP2, 0011, "jns"}, +{0, JOP2, 0012, "jp"}, +{0, JOP2, 0012, "jpe"}, +{0, JOP2, 0013, "jnp"}, +{0, JOP2, 0013, "jpo"}, +{0, JOP2, 0014, "jl"}, +{0, JOP2, 0014, "jnge"}, +{0, JOP2, 0015, "jge"}, +{0, JOP2, 0015, "jnl"}, +{0, JOP2, 0016, "jle"}, +{0, JOP2, 0016, "jng"}, +{0, JOP2, 0017, "jg"}, +{0, JOP2, 0017, "jnle"}, +{0, LEAOP, 0142, "bound"}, +{0, LEAOP, 0215, "lea"}, +{0, LEAOP, 0304, "les"}, +{0, LEAOP, 0305, "lds"}, +{0, LEAOP2, 0262, "lss"}, +{0, LEAOP2, 0264, "lfs"}, +{0, LEAOP2, 0265, "lgs"}, +{0, LSHFT, 0244, "shld"}, +{0, LSHFT, 0254, "shrd"}, +{0, MOV, 0, "movb"}, +{0, MOV, 1, "mov"}, +{0, NOOP_1, 0140, "pusha"}, +{0, NOOP_1, 0140, "pushad"}, +{0, NOOP_1, 0141, "popa"}, +{0, NOOP_1, 0141, "popad"}, +{0, NOOP_1, 0156, "outsb"}, +{0, NOOP_1, 0157, "outs"}, +{0, NOOP_1, 0220, "nop"}, +{0, NOOP_1, 0230, "cbw"}, +{0, NOOP_1, 0230, "cwde"}, /* same opcode as cbw! */ +{0, NOOP_1, 0231, "cdq"}, /* same opcode as cwd! */ +{0, NOOP_1, 0231, "cwd"}, +{0, NOOP_1, 0233, "wait"}, +{0, NOOP_1, 0234, "pushf"}, +{0, NOOP_1, 0235, "popf"}, +{0, NOOP_1, 0236, "sahf"}, +{0, NOOP_1, 0237, "lahf"}, +{0, NOOP_1, 0244, "movsb"}, +{0, NOOP_1, 0245, "movs"}, +{0, NOOP_1, 0246, "cmpsb"}, +{0, NOOP_1, 0154, "insb"}, +{0, NOOP_1, 0247, "cmps"}, +{0, NOOP_1, 0155, "ins"}, +{0, NOOP_1, 0252, "stosb"}, +{0, NOOP_1, 0253, "stos"}, +{0, NOOP_1, 0254, "lodsb"}, +{0, NOOP_1, 0255, "lods"}, +{0, NOOP_1, 0256, "scasb"}, +{0, NOOP_1, 0257, "scas"}, +{0, NOOP_1, 0311, "leave"}, +{0, NOOP_1, 0316, "into"}, +{0, NOOP_1, 0317, "iret"}, +{0, NOOP_1, 0317, "iretd"}, +{0, NOOP_1, 0327, "xlat"}, +{0, NOOP_1, 0364, "hlt"}, +{0, NOOP_1, 0365, "cmc"}, +{0, NOOP_1, 0370, "clc"}, +{0, NOOP_1, 0371, "stc"}, +{0, NOOP_1, 0372, "cli"}, +{0, NOOP_1, 0373, "sti"}, +{0, NOOP_1, 0374, "cld"}, +{0, NOOP_1, 0375, "std"}, +{0, NOOP_1, 047, "daa"}, +{0, NOOP_1, 057, "das"}, +{0, NOOP_1, 067, "aaa"}, +{0, NOOP_1, 077, "aas"}, +{0, NOOP_2, 017+(06<<8), "clts"}, +{0, NOOP_2, 0324+(012<<8), "aam"}, +{0, NOOP_2, 0325+(012<<8), "aad"}, +{0, NOTOP, 020, "notb"}, +{0, NOTOP, 021, "not"}, +{0, NOTOP, 030, "negb"}, +{0, NOTOP, 031, "neg"}, +{0, NOTOP, 040, "mulb"}, +{0, NOTOP, 041, "mul"}, +{0, NOTOP, 060, "divb"}, +{0, NOTOP, 061, "div"}, +{0, NOTOP, 070, "idivb"}, +{0, NOTOP, 071, "idiv"}, +{0, PREFIX, 0144, "fseg"}, +{0, PREFIX, 0145, "gseg"}, +{0, OTOGGLE, 0146, "o16"}, /* operand size toggle */ +{0, OTOGGLE, 0346, "o32"}, /* operand size toggle */ +{0, ATOGGLE, 0147, "a16"}, /* address size toggle */ +{0, ATOGGLE, 0347, "a32"}, /* address size toggle */ +{0, PREFIX, 0360, "lock"}, +{0, PREFIX, 0362, "repne"}, +{0, PREFIX, 0362, "repnz"}, +{0, PREFIX, 0363, "rep"}, +{0, PREFIX, 0363, "repe"}, +{0, PREFIX, 0363, "repz"}, +{0, PREFIX, 046, "eseg"}, +{0, PREFIX, 056, "cseg"}, +{0, PREFIX, 066, "sseg"}, +{0, PREFIX, 076, "dseg"}, +{0, PUSHOP, 0, "push"}, +{0, PUSHOP, 1, "pop"}, +{0, RET, 0303, "ret"}, +{0, RET, 0313, "retf"}, +{0, ROLOP, 000, "rolb"}, +{0, ROLOP, 001, "rol"}, +{0, ROLOP, 010, "rorb"}, +{0, ROLOP, 011, "ror"}, +{0, ROLOP, 020, "rclb"}, +{0, ROLOP, 021, "rcl"}, +{0, ROLOP, 030, "rcrb"}, +{0, ROLOP, 031, "rcr"}, +{0, ROLOP, 040, "salb"}, +{0, ROLOP, 040, "shlb"}, +{0, ROLOP, 041, "sal"}, +{0, ROLOP, 041, "shl"}, +{0, ROLOP, 050, "shrb"}, +{0, ROLOP, 051, "shr"}, +{0, ROLOP, 070, "sarb"}, +{0, ROLOP, 071, "sar"}, +{0, SETCC, 0000, "seto"}, +{0, SETCC, 0001, "setno"}, +{0, SETCC, 0002, "setb"}, +{0, SETCC, 0002, "setnae"}, +{0, SETCC, 0003, "setae"}, +{0, SETCC, 0003, "setnb"}, +{0, SETCC, 0004, "sete"}, +{0, SETCC, 0004, "setz"}, +{0, SETCC, 0005, "setne"}, +{0, SETCC, 0005, "setnz"}, +{0, SETCC, 0006, "setbe"}, +{0, SETCC, 0006, "setna"}, +{0, SETCC, 0007, "seta"}, +{0, SETCC, 0007, "setnbe"}, +{0, SETCC, 0010, "sets"}, +{0, SETCC, 0011, "setns"}, +{0, SETCC, 0012, "setp"}, +{0, SETCC, 0012, "setpe"}, +{0, SETCC, 0013, "setnp"}, +{0, SETCC, 0013, "setpo"}, +{0, SETCC, 0014, "setl"}, +{0, SETCC, 0014, "setnge"}, +{0, SETCC, 0015, "setge"}, +{0, SETCC, 0015, "setnl"}, +{0, SETCC, 0016, "setle"}, +{0, SETCC, 0016, "setng"}, +{0, SETCC, 0017, "setg"}, +{0, SETCC, 0017, "setnle"}, +{0, TEST, 0, "testb"}, +{0, TEST, 1, "test"}, +{0, XCHG, 0, "xchgb"}, +{0, XCHG, 1, "xchg"}, +{0, ARPLOP, 0143, "arpl"}, /* Intel 80[23]87 coprocessor keywords */ -0, ST, 0, "st", +{0, ST, 0, "st"}, -0, FNOOP, FESC+1+(0xF0<<8), "f2xm1", -0, FNOOP, FESC+1+(0xE1<<8), "fabs", -0, FNOOP, FESC+1+(0xE0<<8), "fchs", -0, FNOOP, FESC+3+(0xE2<<8), "fclex", -0, FNOOP, FESC+6+(0xD9<<8), "fcompp", -0, FNOOP, FESC+2+(0xE9<<8), "fucompp", -0, FNOOP, FESC+1+(0xF6<<8), "fdecstp", -0, FNOOP, FESC+3+(0xE1<<8), "fdisi", -0, FNOOP, FESC+3+(0xE0<<8), "feni", -0, FNOOP, FESC+1+(0xF7<<8), "fincstp", -0, FNOOP, FESC+3+(0xE3<<8), "finit", -0, FNOOP, FESC+1+(0xE8<<8), "fld1", -0, FNOOP, FESC+1+(0xEA<<8), "fldl2e", -0, FNOOP, FESC+1+(0xE9<<8), "fldl2t", -0, FNOOP, FESC+1+(0xEC<<8), "fldlg2", -0, FNOOP, FESC+1+(0xED<<8), "fldln2", -0, FNOOP, FESC+1+(0xEB<<8), "fldpi", -0, FNOOP, FESC+1+(0xEE<<8), "fldz", -0, FNOOP, FESC+1+(0xD0<<8), "fnop", -0, FNOOP, FESC+1+(0xF3<<8), "fpatan", -0, FNOOP, FESC+1+(0xFF<<8), "fcos", -0, FNOOP, FESC+1+(0xFE<<8), "fsin", -0, FNOOP, FESC+1+(0xFB<<8), "fsincos", -0, FNOOP, FESC+1+(0xF8<<8), "fprem", -0, FNOOP, FESC+1+(0xF5<<8), "fprem1", -0, FNOOP, FESC+1+(0xF2<<8), "fptan", -0, FNOOP, FESC+1+(0xFC<<8), "frndint", -0, FNOOP, FESC+1+(0xFD<<8), "fscale", -0, FNOOP, FESC+1+(0xFA<<8), "fsqrt", -0, FNOOP, FESC+1+(0xE4<<8), "ftst", -0, FNOOP, FESC+1+(0xE5<<8), "fxam", -0, FNOOP, FESC+1+(0xF4<<8), "fxtract", -0, FNOOP, FESC+1+(0xF1<<8), "fyl2x", -0, FNOOP, FESC+1+(0xF9<<8), "fyl2xp1", +{0, FNOOP, FESC+1+(0xF0<<8), "f2xm1"}, +{0, FNOOP, FESC+1+(0xE1<<8), "fabs"}, +{0, FNOOP, FESC+1+(0xE0<<8), "fchs"}, +{0, FNOOP, FESC+3+(0xE2<<8), "fclex"}, +{0, FNOOP, FESC+6+(0xD9<<8), "fcompp"}, +{0, FNOOP, FESC+2+(0xE9<<8), "fucompp"}, +{0, FNOOP, FESC+1+(0xF6<<8), "fdecstp"}, +{0, FNOOP, FESC+3+(0xE1<<8), "fdisi"}, +{0, FNOOP, FESC+3+(0xE0<<8), "feni"}, +{0, FNOOP, FESC+1+(0xF7<<8), "fincstp"}, +{0, FNOOP, FESC+3+(0xE3<<8), "finit"}, +{0, FNOOP, FESC+1+(0xE8<<8), "fld1"}, +{0, FNOOP, FESC+1+(0xEA<<8), "fldl2e"}, +{0, FNOOP, FESC+1+(0xE9<<8), "fldl2t"}, +{0, FNOOP, FESC+1+(0xEC<<8), "fldlg2"}, +{0, FNOOP, FESC+1+(0xED<<8), "fldln2"}, +{0, FNOOP, FESC+1+(0xEB<<8), "fldpi"}, +{0, FNOOP, FESC+1+(0xEE<<8), "fldz"}, +{0, FNOOP, FESC+1+(0xD0<<8), "fnop"}, +{0, FNOOP, FESC+1+(0xF3<<8), "fpatan"}, +{0, FNOOP, FESC+1+(0xFF<<8), "fcos"}, +{0, FNOOP, FESC+1+(0xFE<<8), "fsin"}, +{0, FNOOP, FESC+1+(0xFB<<8), "fsincos"}, +{0, FNOOP, FESC+1+(0xF8<<8), "fprem"}, +{0, FNOOP, FESC+1+(0xF5<<8), "fprem1"}, +{0, FNOOP, FESC+1+(0xF2<<8), "fptan"}, +{0, FNOOP, FESC+1+(0xFC<<8), "frndint"}, +{0, FNOOP, FESC+1+(0xFD<<8), "fscale"}, +{0, FNOOP, FESC+1+(0xFA<<8), "fsqrt"}, +{0, FNOOP, FESC+1+(0xE4<<8), "ftst"}, +{0, FNOOP, FESC+1+(0xE5<<8), "fxam"}, +{0, FNOOP, FESC+1+(0xF4<<8), "fxtract"}, +{0, FNOOP, FESC+1+(0xF1<<8), "fyl2x"}, +{0, FNOOP, FESC+1+(0xF9<<8), "fyl2xp1"}, -0, FMEM, FESC+6+(0<<11), "fiadds", -0, FMEM, FESC+2+(0<<11), "fiaddl", -0, FMEM, FESC+0+(0<<11), "fadds", -0, FMEM, FESC+4+(0<<11), "faddd", -0, FMEM, FESC+7+(4<<11), "fbld", -0, FMEM, FESC+7+(6<<11), "fbstp", -0, FMEM, FESC+6+(2<<11), "ficoms", -0, FMEM, FESC+2+(2<<11), "ficoml", -0, FMEM, FESC+0+(2<<11), "fcoms", -0, FMEM, FESC+4+(2<<11), "fcomd", -0, FMEM, FESC+6+(3<<11), "ficomps", -0, FMEM, FESC+2+(3<<11), "ficompl", -0, FMEM, FESC+0+(3<<11), "fcomps", -0, FMEM, FESC+4+(3<<11), "fcompd", -0, FMEM, FESC+6+(6<<11), "fidivs", -0, FMEM, FESC+2+(6<<11), "fidivl", -0, FMEM, FESC+0+(6<<11), "fdivs", -0, FMEM, FESC+4+(6<<11), "fdivd", -0, FMEM, FESC+6+(7<<11), "fidivrs", -0, FMEM, FESC+2+(7<<11), "fidivrl", -0, FMEM, FESC+0+(7<<11), "fdivrs", -0, FMEM, FESC+4+(7<<11), "fdivrd", -0, FMEM, FESC+7+(5<<11), "fildq", -0, FMEM, FESC+7+(0<<11), "filds", -0, FMEM, FESC+3+(0<<11), "fildl", -0, FMEM, FESC+1+(0<<11), "flds", -0, FMEM, FESC+5+(0<<11), "fldd", -0, FMEM, FESC+3+(5<<11), "fldx", -0, FMEM, FESC+1+(5<<11), "fldcw", -0, FMEM, FESC+1+(4<<11), "fldenv", -0, FMEM, FESC+6+(1<<11), "fimuls", -0, FMEM, FESC+2+(1<<11), "fimull", -0, FMEM, FESC+0+(1<<11), "fmuls", -0, FMEM, FESC+4+(1<<11), "fmuld", -0, FMEM, FESC+5+(4<<11), "frstor", -0, FMEM, FESC+5+(6<<11), "fsave", -0, FMEM, FESC+7+(2<<11), "fists", -0, FMEM, FESC+3+(2<<11), "fistl", -0, FMEM, FESC+1+(2<<11), "fsts", -0, FMEM, FESC+5+(2<<11), "fstd", -0, FMEM, FESC+7+(7<<11), "fistpq", -0, FMEM, FESC+7+(3<<11), "fistps", -0, FMEM, FESC+3+(3<<11), "fistpl", -0, FMEM, FESC+1+(3<<11), "fstps", -0, FMEM, FESC+5+(3<<11), "fstpd", -0, FMEM, FESC+3+(7<<11), "fstpx", -0, FMEM, FESC+1+(7<<11), "fstcw", -0, FMEM, FESC+1+(6<<11), "fstenv", -0, FMEM_AX, FESC+5+(7<<11), "fstsw", -0, FMEM, FESC+6+(4<<11), "fisubs", -0, FMEM, FESC+2+(4<<11), "fisubl", -0, FMEM, FESC+0+(4<<11), "fsubs", -0, FMEM, FESC+4+(4<<11), "fsubd", -0, FMEM, FESC+6+(5<<11), "fisubrs", -0, FMEM, FESC+2+(5<<11), "fisubrl", -0, FMEM, FESC+0+(5<<11), "fsubrs", -0, FMEM, FESC+4+(5<<11), "fsubrd", +{0, FMEM, FESC+6+(0<<11), "fiadds"}, +{0, FMEM, FESC+2+(0<<11), "fiaddl"}, +{0, FMEM, FESC+0+(0<<11), "fadds"}, +{0, FMEM, FESC+4+(0<<11), "faddd"}, +{0, FMEM, FESC+7+(4<<11), "fbld"}, +{0, FMEM, FESC+7+(6<<11), "fbstp"}, +{0, FMEM, FESC+6+(2<<11), "ficoms"}, +{0, FMEM, FESC+2+(2<<11), "ficoml"}, +{0, FMEM, FESC+0+(2<<11), "fcoms"}, +{0, FMEM, FESC+4+(2<<11), "fcomd"}, +{0, FMEM, FESC+6+(3<<11), "ficomps"}, +{0, FMEM, FESC+2+(3<<11), "ficompl"}, +{0, FMEM, FESC+0+(3<<11), "fcomps"}, +{0, FMEM, FESC+4+(3<<11), "fcompd"}, +{0, FMEM, FESC+6+(6<<11), "fidivs"}, +{0, FMEM, FESC+2+(6<<11), "fidivl"}, +{0, FMEM, FESC+0+(6<<11), "fdivs"}, +{0, FMEM, FESC+4+(6<<11), "fdivd"}, +{0, FMEM, FESC+6+(7<<11), "fidivrs"}, +{0, FMEM, FESC+2+(7<<11), "fidivrl"}, +{0, FMEM, FESC+0+(7<<11), "fdivrs"}, +{0, FMEM, FESC+4+(7<<11), "fdivrd"}, +{0, FMEM, FESC+7+(5<<11), "fildq"}, +{0, FMEM, FESC+7+(0<<11), "filds"}, +{0, FMEM, FESC+3+(0<<11), "fildl"}, +{0, FMEM, FESC+1+(0<<11), "flds"}, +{0, FMEM, FESC+5+(0<<11), "fldd"}, +{0, FMEM, FESC+3+(5<<11), "fldx"}, +{0, FMEM, FESC+1+(5<<11), "fldcw"}, +{0, FMEM, FESC+1+(4<<11), "fldenv"}, +{0, FMEM, FESC+6+(1<<11), "fimuls"}, +{0, FMEM, FESC+2+(1<<11), "fimull"}, +{0, FMEM, FESC+0+(1<<11), "fmuls"}, +{0, FMEM, FESC+4+(1<<11), "fmuld"}, +{0, FMEM, FESC+5+(4<<11), "frstor"}, +{0, FMEM, FESC+5+(6<<11), "fsave"}, +{0, FMEM, FESC+7+(2<<11), "fists"}, +{0, FMEM, FESC+3+(2<<11), "fistl"}, +{0, FMEM, FESC+1+(2<<11), "fsts"}, +{0, FMEM, FESC+5+(2<<11), "fstd"}, +{0, FMEM, FESC+7+(7<<11), "fistpq"}, +{0, FMEM, FESC+7+(3<<11), "fistps"}, +{0, FMEM, FESC+3+(3<<11), "fistpl"}, +{0, FMEM, FESC+1+(3<<11), "fstps"}, +{0, FMEM, FESC+5+(3<<11), "fstpd"}, +{0, FMEM, FESC+3+(7<<11), "fstpx"}, +{0, FMEM, FESC+1+(7<<11), "fstcw"}, +{0, FMEM, FESC+1+(6<<11), "fstenv"}, +{0, FMEM_AX, FESC+5+(7<<11), "fstsw"}, +{0, FMEM, FESC+6+(4<<11), "fisubs"}, +{0, FMEM, FESC+2+(4<<11), "fisubl"}, +{0, FMEM, FESC+0+(4<<11), "fsubs"}, +{0, FMEM, FESC+4+(4<<11), "fsubd"}, +{0, FMEM, FESC+6+(5<<11), "fisubrs"}, +{0, FMEM, FESC+2+(5<<11), "fisubrl"}, +{0, FMEM, FESC+0+(5<<11), "fsubrs"}, +{0, FMEM, FESC+4+(5<<11), "fsubrd"}, -0, FST_I, FESC+1+(0xC0<<8), "fld", -0, FST_I, FESC+5+(0xD0<<8), "fst", -0, FST_I, FESC+5+(0xD8<<8), "fstp", -0, FST_I, FESC+1+(0xC8<<8), "fxch", -0, FST_I, FESC+0+(0xD0<<8), "fcom", -0, FST_I, FESC+5+(0xE0<<8), "fucom", -0, FST_I, FESC+0+(0xD8<<8), "fcomp", -0, FST_I, FESC+5+(0xE8<<8), "fucomp", -0, FST_I, FESC+5+(0xC0<<8), "ffree", +{0, FST_I, FESC+1+(0xC0<<8), "fld"}, +{0, FST_I, FESC+5+(0xD0<<8), "fst"}, +{0, FST_I, FESC+5+(0xD8<<8), "fstp"}, +{0, FST_I, FESC+1+(0xC8<<8), "fxch"}, +{0, FST_I, FESC+0+(0xD0<<8), "fcom"}, +{0, FST_I, FESC+5+(0xE0<<8), "fucom"}, +{0, FST_I, FESC+0+(0xD8<<8), "fcomp"}, +{0, FST_I, FESC+5+(0xE8<<8), "fucomp"}, +{0, FST_I, FESC+5+(0xC0<<8), "ffree"}, -0, FST_ST, FESC+0+(0xC0<<8), "fadd", -0, FST_ST, FESC+2+(0xC0<<8), "faddp", -0, FST_ST2, FESC+0+(0xF0<<8), "fdiv", -0, FST_ST2, FESC+2+(0xF0<<8), "fdivp", -0, FST_ST2, FESC+0+(0xF8<<8), "fdivr", -0, FST_ST2, FESC+2+(0xF8<<8), "fdivrp", -0, FST_ST, FESC+0+(0xC8<<8), "fmul", -0, FST_ST, FESC+2+(0xC8<<8), "fmulp", -0, FST_ST2, FESC+0+(0xE0<<8), "fsub", -0, FST_ST2, FESC+2+(0xE0<<8), "fsubp", -0, FST_ST2, FESC+0+(0xE8<<8), "fsubr", -0, FST_ST2, FESC+2+(0xE8<<8), "fsubrp", +{0, FST_ST, FESC+0+(0xC0<<8), "fadd"}, +{0, FST_ST, FESC+2+(0xC0<<8), "faddp"}, +{0, FST_ST2, FESC+0+(0xF0<<8), "fdiv"}, +{0, FST_ST2, FESC+2+(0xF0<<8), "fdivp"}, +{0, FST_ST2, FESC+0+(0xF8<<8), "fdivr"}, +{0, FST_ST2, FESC+2+(0xF8<<8), "fdivrp"}, +{0, FST_ST, FESC+0+(0xC8<<8), "fmul"}, +{0, FST_ST, FESC+2+(0xC8<<8), "fmulp"}, +{0, FST_ST2, FESC+0+(0xE0<<8), "fsub"}, +{0, FST_ST2, FESC+2+(0xE0<<8), "fsubp"}, +{0, FST_ST2, FESC+0+(0xE8<<8), "fsubr"}, +{0, FST_ST2, FESC+2+(0xE8<<8), "fsubrp"}, /* Intel 486 instructions */ -0, EXTOPBW, 0xC0, "xaddb", -0, EXTOPBW, 0xC1, "xadd", -0, EXTOPBW, 0xB0, "cmpxchgb", -0, EXTOPBW, 0xB1, "cmpxchg", -0, BSWAP, 0xC8, "bswap", -0, NOOP_2, 017+(010<<8), "invd", -0, EXTOP1, 071, "invlpg", -0, NOOP_2, 017+(011<<8), "wbinvd", +{0, EXTOPBW, 0xC0, "xaddb"}, +{0, EXTOPBW, 0xC1, "xadd"}, +{0, EXTOPBW, 0xB0, "cmpxchgb"}, +{0, EXTOPBW, 0xB1, "cmpxchg"}, +{0, BSWAP, 0xC8, "bswap"}, +{0, NOOP_2, 017+(010<<8), "invd"}, +{0, EXTOP1, 071, "invlpg"}, +{0, NOOP_2, 017+(011<<8), "wbinvd"}, diff --git a/mach/i80/as/mach3.c b/mach/i80/as/mach3.c index 94b531d2e..3dd2a689f 100644 --- a/mach/i80/as/mach3.c +++ b/mach/i80/as/mach3.c @@ -8,101 +8,101 @@ * Specials */ -0, KILL, 0, "kill", +{0, KILL, 0, "kill"}, /* * Intel 8080 keywords */ -0, REG, B, "b", -0, REG, C, "c", -0, REG, D, "d", -0, REG, E, "e", -0, REG, H, "h", -0, REG, L, "l", -0, REG, M, "m", -0, REG, A, "a", -0, REG, SP, "sp", -0, REG, PSW, "psw", -0, D16OP, 0315, "call", -0, D16OP, 0334, "cc", -0, D16OP, 0324, "cnc", -0, D16OP, 0314, "cz", -0, D16OP, 0304, "cnz", -0, D16OP, 0364, "cp", -0, D16OP, 0374, "cm", -0, D16OP, 0354, "cpe", -0, D16OP, 0344, "cpo", -0, NOOPOP, 0311, "ret", -0, NOOPOP, 0330, "rc", -0, NOOPOP, 0320, "rnc", -0, NOOPOP, 0310, "rz", -0, NOOPOP, 0300, "rnz", -0, NOOPOP, 0360, "rp", -0, NOOPOP, 0370, "rm", -0, NOOPOP, 0350, "rpe", -0, NOOPOP, 0340, "rpo", -0, RST, 0307, "rst", -0, D8OP, 0333, "in", -0, D8OP, 0323, "out", -0, LXI, 0001, "lxi", -0, R16OP, 0305, "push", -0, R16OP, 0301, "pop", -0, D16OP, 0062, "sta", -0, D16OP, 0072, "lda", -0, NOOPOP, 0353, "xchg", -0, NOOPOP, 0343, "xthl", -0, NOOPOP, 0371, "sphl", -0, NOOPOP, 0351, "pchl", -0, R16OP, 0011, "dad", -0, STLDAX, 0002, "stax", -0, STLDAX, 0012, "ldax", -0, R16OP, 0003, "inx", -0, MOV, 0100, "mov", -0, NOOPOP, 0166, "hlt", -0, MVI, 0006, "mvi", -0, DSTOP, 0004, "inr", -0, DSTOP, 0005, "dcr", -0, SRCOP, 0200, "add", -0, SRCOP, 0210, "adc", -0, SRCOP, 0220, "sub", -0, SRCOP, 0230, "sbb", -0, SRCOP, 0240, "ana", -0, SRCOP, 0250, "xra", -0, SRCOP, 0260, "ora", -0, SRCOP, 0270, "cmp", -0, D8OP, 0306, "adi", -0, D8OP, 0316, "aci", -0, D8OP, 0326, "sui", -0, D8OP, 0336, "sbi", -0, D8OP, 0346, "ani", -0, D8OP, 0356, "xri", -0, D8OP, 0366, "ori", -0, D8OP, 0376, "cpi", -0, NOOPOP, 0007, "rlc", -0, NOOPOP, 0017, "rrc", -0, NOOPOP, 0027, "ral", -0, NOOPOP, 0037, "rar", -0, D16OP, 0303, "jmp", -0, D16OP, 0332, "jc", -0, D16OP, 0322, "jnc", -0, D16OP, 0312, "jz", -0, D16OP, 0302, "jnz", -0, D16OP, 0362, "jp", -0, D16OP, 0372, "jm", -0, D16OP, 0352, "jpe", -0, D16OP, 0342, "jpo", -0, R16OP, 0013, "dcx", -0, NOOPOP, 0057, "cma", -0, NOOPOP, 0067, "stc", -0, NOOPOP, 0077, "cmc", -0, NOOPOP, 0047, "daa", -0, D16OP, 0042, "shld", -0, D16OP, 0052, "lhld", -0, NOOPOP, 0373, "ei", -0, NOOPOP, 0363, "di", -0, NOOPOP, 0000, "nop", -0, NOOPOP, 0040, "rim", /* 8085 */ -0, NOOPOP, 0060, "sim", /* 8085 */ +{0, REG, B, "b"}, +{0, REG, C, "c"}, +{0, REG, D, "d"}, +{0, REG, E, "e"}, +{0, REG, H, "h"}, +{0, REG, L, "l"}, +{0, REG, M, "m"}, +{0, REG, A, "a"}, +{0, REG, SP, "sp"}, +{0, REG, PSW, "psw"}, +{0, D16OP, 0315, "call"}, +{0, D16OP, 0334, "cc"}, +{0, D16OP, 0324, "cnc"}, +{0, D16OP, 0314, "cz"}, +{0, D16OP, 0304, "cnz"}, +{0, D16OP, 0364, "cp"}, +{0, D16OP, 0374, "cm"}, +{0, D16OP, 0354, "cpe"}, +{0, D16OP, 0344, "cpo"}, +{0, NOOPOP, 0311, "ret"}, +{0, NOOPOP, 0330, "rc"}, +{0, NOOPOP, 0320, "rnc"}, +{0, NOOPOP, 0310, "rz"}, +{0, NOOPOP, 0300, "rnz"}, +{0, NOOPOP, 0360, "rp"}, +{0, NOOPOP, 0370, "rm"}, +{0, NOOPOP, 0350, "rpe"}, +{0, NOOPOP, 0340, "rpo"}, +{0, RST, 0307, "rst"}, +{0, D8OP, 0333, "in"}, +{0, D8OP, 0323, "out"}, +{0, LXI, 0001, "lxi"}, +{0, R16OP, 0305, "push"}, +{0, R16OP, 0301, "pop"}, +{0, D16OP, 0062, "sta"}, +{0, D16OP, 0072, "lda"}, +{0, NOOPOP, 0353, "xchg"}, +{0, NOOPOP, 0343, "xthl"}, +{0, NOOPOP, 0371, "sphl"}, +{0, NOOPOP, 0351, "pchl"}, +{0, R16OP, 0011, "dad"}, +{0, STLDAX, 0002, "stax"}, +{0, STLDAX, 0012, "ldax"}, +{0, R16OP, 0003, "inx"}, +{0, MOV, 0100, "mov"}, +{0, NOOPOP, 0166, "hlt"}, +{0, MVI, 0006, "mvi"}, +{0, DSTOP, 0004, "inr"}, +{0, DSTOP, 0005, "dcr"}, +{0, SRCOP, 0200, "add"}, +{0, SRCOP, 0210, "adc"}, +{0, SRCOP, 0220, "sub"}, +{0, SRCOP, 0230, "sbb"}, +{0, SRCOP, 0240, "ana"}, +{0, SRCOP, 0250, "xra"}, +{0, SRCOP, 0260, "ora"}, +{0, SRCOP, 0270, "cmp"}, +{0, D8OP, 0306, "adi"}, +{0, D8OP, 0316, "aci"}, +{0, D8OP, 0326, "sui"}, +{0, D8OP, 0336, "sbi"}, +{0, D8OP, 0346, "ani"}, +{0, D8OP, 0356, "xri"}, +{0, D8OP, 0366, "ori"}, +{0, D8OP, 0376, "cpi"}, +{0, NOOPOP, 0007, "rlc"}, +{0, NOOPOP, 0017, "rrc"}, +{0, NOOPOP, 0027, "ral"}, +{0, NOOPOP, 0037, "rar"}, +{0, D16OP, 0303, "jmp"}, +{0, D16OP, 0332, "jc"}, +{0, D16OP, 0322, "jnc"}, +{0, D16OP, 0312, "jz"}, +{0, D16OP, 0302, "jnz"}, +{0, D16OP, 0362, "jp"}, +{0, D16OP, 0372, "jm"}, +{0, D16OP, 0352, "jpe"}, +{0, D16OP, 0342, "jpo"}, +{0, R16OP, 0013, "dcx"}, +{0, NOOPOP, 0057, "cma"}, +{0, NOOPOP, 0067, "stc"}, +{0, NOOPOP, 0077, "cmc"}, +{0, NOOPOP, 0047, "daa"}, +{0, D16OP, 0042, "shld"}, +{0, D16OP, 0052, "lhld"}, +{0, NOOPOP, 0373, "ei"}, +{0, NOOPOP, 0363, "di"}, +{0, NOOPOP, 0000, "nop"}, +{0, NOOPOP, 0040, "rim"}, /* 8085 */ +{0, NOOPOP, 0060, "sim"}, /* 8085 */ /* * The Intel 8085 has a set of instructions for high level language * support that were not originally documented. @@ -114,14 +114,14 @@ * check via A. RSTV is useful for runtimes where signed overflow is a * fault. */ -0, NOOPOP, 0010, "dsub", /* 8085 undoc HL = HL - BC */ -0, NOOPOP, 0020, "arhl", /* 8085 undoc HL arith right shift */ -0, NOOPOP, 0030, "rld", /* 8085 undoc rotate DE left thru carry */ +{0, NOOPOP, 0010, "dsub"}, /* 8085 undoc HL = HL - BC */ +{0, NOOPOP, 0020, "arhl"}, /* 8085 undoc HL arith right shift */ +{0, NOOPOP, 0030, "rld"}, /* 8085 undoc rotate DE left thru carry */ /* in effect ADC DE,DE */ -0, D8OP, 0050, "ldhi", /* DE = HL + imm8 */ -0, D8OP, 0070, "ldsi", /* DE = SP + imm8 */ -0, NOOPOP, 0313, "rstv", /* RST8 if V set */ -0, NOOPOP, 0331, "shlx", /* (DE) = HL */ -0, NOOPOP, 0355, "lhlx", /* HL = (DE) */ -0, D16OP, 0335, "jnk", /* Jump K clear */ -0, D16OP, 0375, "jk", /* Jump K set */ +{0, D8OP, 0050, "ldhi"}, /* DE = HL + imm8 */ +{0, D8OP, 0070, "ldsi"}, /* DE = SP + imm8 */ +{0, NOOPOP, 0313, "rstv"}, /* RST8 if V set */ +{0, NOOPOP, 0331, "shlx"}, /* (DE) = HL */ +{0, NOOPOP, 0355, "lhlx"}, /* HL = (DE) */ +{0, D16OP, 0335, "jnk"}, /* Jump K clear */ +{0, D16OP, 0375, "jk"}, /* Jump K set */ diff --git a/mach/i86/as/mach3.c b/mach/i86/as/mach3.c index 46f0f4855..6c54daa8b 100644 --- a/mach/i86/as/mach3.c +++ b/mach/i86/as/mach3.c @@ -8,330 +8,330 @@ * INTEL 8086 keywords */ -0, R16, 0, "ax", -0, R16, 1, "cx", -0, R16, 2, "dx", -0, R16, 3, "bx", -0, R16, 4, "sp", -0, R16, 5, "bp", -0, R16, 6, "si", -0, R16, 7, "di", -0, R8, 0, "al", -0, R8, 1, "cl", -0, R8, 2, "dl", -0, R8, 3, "bl", -0, R8, 4, "ah", -0, R8, 5, "ch", -0, R8, 6, "dh", -0, R8, 7, "bh", -0, RSEG, 0, "es", -0, RSEG, 1, "cs", -0, RSEG, 2, "ss", -0, RSEG, 3, "ds", -0, PREFIX, 046, "eseg", -0, PREFIX, 056, "cseg", -0, PREFIX, 066, "sseg", -0, PREFIX, 076, "dseg", -0, PREFIX, 0360, "lock", -0, PREFIX, 0363, "rep", -0, PREFIX, 0362, "repne", -0, PREFIX, 0362, "repnz", -0, PREFIX, 0363, "repe", -0, PREFIX, 0363, "repz", -0, NOOP_1, 047, "daa", -0, NOOP_1, 057, "das", -0, NOOP_1, 067, "aaa", -0, NOOP_1, 077, "aas", -0, NOOP_1, 0220, "nop", -0, NOOP_1, 0230, "cbw", -0, NOOP_1, 0231, "cwd", -0, NOOP_1, 0233, "wait", -0, NOOP_1, 0234, "pushf", -0, NOOP_1, 0235, "popf", -0, NOOP_1, 0236, "sahf", -0, NOOP_1, 0237, "lahf", -0, NOOP_1, 0244, "movsb", -0, NOOP_1, 0245, "movs", -0, NOOP_1, 0245, "movsw", -0, NOOP_1, 0246, "cmpsb", -0, NOOP_1, 0247, "cmps", -0, NOOP_1, 0247, "cmpsw", -0, NOOP_1, 0252, "stosb", -0, NOOP_1, 0253, "stos", -0, NOOP_1, 0253, "stosw", -0, NOOP_1, 0254, "lodsb", -0, NOOP_1, 0255, "lods", -0, NOOP_1, 0255, "lodsw", -0, NOOP_1, 0256, "scasb", -0, NOOP_1, 0257, "scas", -0, NOOP_1, 0257, "scasw", -0, NOOP_1, 0316, "into", -0, NOOP_1, 0317, "iret", -0, NOOP_1, 0327, "xlat", -0, NOOP_1, 0364, "hlt", -0, NOOP_1, 0365, "cmc", -0, NOOP_1, 0370, "clc", -0, NOOP_1, 0371, "stc", -0, NOOP_1, 0372, "cli", -0, NOOP_1, 0373, "sti", -0, NOOP_1, 0374, "cld", -0, NOOP_1, 0375, "std", -0, NOOP_2, 0324+012<<8, "aam", -0, NOOP_2, 0325+012<<8, "aad", -0, JOP, 0340, "loopne", -0, JOP, 0340, "loopnz", -0, JOP, 0341, "loope", -0, JOP, 0341, "loopz", -0, JOP, 0342, "loop", -0, JOP, 0343, "jcxz", -0, JOP, 0160, "jo", -0, JOP, 0161, "jno", -0, JOP, 0162, "jb", -0, JOP, 0162, "jc", -0, JOP, 0162, "jnae", -0, JOP, 0163, "jae", -0, JOP, 0163, "jnb", -0, JOP, 0163, "jnc", -0, JOP, 0164, "je", -0, JOP, 0164, "jz", -0, JOP, 0165, "jne", -0, JOP, 0165, "jnz", -0, JOP, 0166, "jbe", -0, JOP, 0166, "jna", -0, JOP, 0167, "ja", -0, JOP, 0167, "jnbe", -0, JOP, 0170, "js", -0, JOP, 0171, "jns", -0, JOP, 0172, "jp", -0, JOP, 0172, "jpe", -0, JOP, 0173, "jnp", -0, JOP, 0173, "jpo", -0, JOP, 0174, "jl", -0, JOP, 0174, "jnge", -0, JOP, 0175, "jge", -0, JOP, 0175, "jnl", -0, JOP, 0176, "jle", -0, JOP, 0176, "jng", -0, JOP, 0177, "jg", -0, JOP, 0177, "jnle", -0, PUSHOP, 0, "push", -0, PUSHOP, 1, "pop", -0, IOOP, 0344, "inb", -0, IOOP, 0345, "in", -0, IOOP, 0345, "inw", -0, IOOP, 0346, "outb", -0, IOOP, 0347, "out", -0, IOOP, 0347, "outw", -0, ADDOP, 000, "addb", -0, ADDOP, 001, "add", -0, ADDOP, 010, "orb", -0, ADDOP, 011, "or", -0, ADDOP, 020, "adcb", -0, ADDOP, 021, "adc", -0, ADDOP, 030, "sbbb", -0, ADDOP, 031, "sbb", -0, ADDOP, 040, "andb", -0, ADDOP, 041, "and", -0, ADDOP, 050, "subb", -0, ADDOP, 051, "sub", -0, ADDOP, 060, "xorb", -0, ADDOP, 061, "xor", -0, ADDOP, 070, "cmpb", -0, ADDOP, 071, "cmp", -0, ROLOP, 000, "rolb", -0, ROLOP, 001, "rol", -0, ROLOP, 010, "rorb", -0, ROLOP, 011, "ror", -0, ROLOP, 020, "rclb", -0, ROLOP, 021, "rcl", -0, ROLOP, 030, "rcrb", -0, ROLOP, 031, "rcr", -0, ROLOP, 040, "salb", -0, ROLOP, 040, "shlb", -0, ROLOP, 041, "sal", -0, ROLOP, 041, "shl", -0, ROLOP, 050, "shrb", -0, ROLOP, 051, "shr", -0, ROLOP, 070, "sarb", -0, ROLOP, 071, "sar", -0, INCOP, 000, "incb", -0, INCOP, 001, "inc", -0, INCOP, 010, "decb", -0, INCOP, 011, "dec", -0, NOTOP, 020, "notb", -0, NOTOP, 021, "not", -0, NOTOP, 030, "negb", -0, NOTOP, 031, "neg", -0, NOTOP, 040, "mulb", -0, NOTOP, 041, "mul", -0, NOTOP, 050, "imulb", -0, IMUL, 051, "imul", /* for 80286 */ -0, NOTOP, 060, "divb", -0, NOTOP, 061, "div", -0, NOTOP, 070, "idivb", -0, NOTOP, 071, "idiv", -0, CALLOP, 020+(0350<<8), "call", -0, CALLOP, 040+(0351<<8), "jmp", -0, CALFOP, 030+(0232<<8), "callf", -0, CALFOP, 050+(0352<<8), "jmpf", -0, LEAOP, 0215, "lea", -0, LEAOP, 0304, "les", -0, LEAOP, 0305, "lds", -0, ESC, 0, "esc", -0, INT, 0, "int", -0, RET, 0303, "ret", -0, RET, 0313, "retf", -0, XCHG, 0, "xchgb", -0, XCHG, 1, "xchg", -0, TEST, 0, "testb", -0, TEST, 1, "test", -0, MOV, 0, "movb", -0, MOV, 1, "mov", -0, MOV, 1, "movw", +{0, R16, 0, "ax"}, +{0, R16, 1, "cx"}, +{0, R16, 2, "dx"}, +{0, R16, 3, "bx"}, +{0, R16, 4, "sp"}, +{0, R16, 5, "bp"}, +{0, R16, 6, "si"}, +{0, R16, 7, "di"}, +{0, R8, 0, "al"}, +{0, R8, 1, "cl"}, +{0, R8, 2, "dl"}, +{0, R8, 3, "bl"}, +{0, R8, 4, "ah"}, +{0, R8, 5, "ch"}, +{0, R8, 6, "dh"}, +{0, R8, 7, "bh"}, +{0, RSEG, 0, "es"}, +{0, RSEG, 1, "cs"}, +{0, RSEG, 2, "ss"}, +{0, RSEG, 3, "ds"}, +{0, PREFIX, 046, "eseg"}, +{0, PREFIX, 056, "cseg"}, +{0, PREFIX, 066, "sseg"}, +{0, PREFIX, 076, "dseg"}, +{0, PREFIX, 0360, "lock"}, +{0, PREFIX, 0363, "rep"}, +{0, PREFIX, 0362, "repne"}, +{0, PREFIX, 0362, "repnz"}, +{0, PREFIX, 0363, "repe"}, +{0, PREFIX, 0363, "repz"}, +{0, NOOP_1, 047, "daa"}, +{0, NOOP_1, 057, "das"}, +{0, NOOP_1, 067, "aaa"}, +{0, NOOP_1, 077, "aas"}, +{0, NOOP_1, 0220, "nop"}, +{0, NOOP_1, 0230, "cbw"}, +{0, NOOP_1, 0231, "cwd"}, +{0, NOOP_1, 0233, "wait"}, +{0, NOOP_1, 0234, "pushf"}, +{0, NOOP_1, 0235, "popf"}, +{0, NOOP_1, 0236, "sahf"}, +{0, NOOP_1, 0237, "lahf"}, +{0, NOOP_1, 0244, "movsb"}, +{0, NOOP_1, 0245, "movs"}, +{0, NOOP_1, 0245, "movsw"}, +{0, NOOP_1, 0246, "cmpsb"}, +{0, NOOP_1, 0247, "cmps"}, +{0, NOOP_1, 0247, "cmpsw"}, +{0, NOOP_1, 0252, "stosb"}, +{0, NOOP_1, 0253, "stos"}, +{0, NOOP_1, 0253, "stosw"}, +{0, NOOP_1, 0254, "lodsb"}, +{0, NOOP_1, 0255, "lods"}, +{0, NOOP_1, 0255, "lodsw"}, +{0, NOOP_1, 0256, "scasb"}, +{0, NOOP_1, 0257, "scas"}, +{0, NOOP_1, 0257, "scasw"}, +{0, NOOP_1, 0316, "into"}, +{0, NOOP_1, 0317, "iret"}, +{0, NOOP_1, 0327, "xlat"}, +{0, NOOP_1, 0364, "hlt"}, +{0, NOOP_1, 0365, "cmc"}, +{0, NOOP_1, 0370, "clc"}, +{0, NOOP_1, 0371, "stc"}, +{0, NOOP_1, 0372, "cli"}, +{0, NOOP_1, 0373, "sti"}, +{0, NOOP_1, 0374, "cld"}, +{0, NOOP_1, 0375, "std"}, +{0, NOOP_2, 0324+012<<8, "aam"}, +{0, NOOP_2, 0325+012<<8, "aad"}, +{0, JOP, 0340, "loopne"}, +{0, JOP, 0340, "loopnz"}, +{0, JOP, 0341, "loope"}, +{0, JOP, 0341, "loopz"}, +{0, JOP, 0342, "loop"}, +{0, JOP, 0343, "jcxz"}, +{0, JOP, 0160, "jo"}, +{0, JOP, 0161, "jno"}, +{0, JOP, 0162, "jb"}, +{0, JOP, 0162, "jc"}, +{0, JOP, 0162, "jnae"}, +{0, JOP, 0163, "jae"}, +{0, JOP, 0163, "jnb"}, +{0, JOP, 0163, "jnc"}, +{0, JOP, 0164, "je"}, +{0, JOP, 0164, "jz"}, +{0, JOP, 0165, "jne"}, +{0, JOP, 0165, "jnz"}, +{0, JOP, 0166, "jbe"}, +{0, JOP, 0166, "jna"}, +{0, JOP, 0167, "ja"}, +{0, JOP, 0167, "jnbe"}, +{0, JOP, 0170, "js"}, +{0, JOP, 0171, "jns"}, +{0, JOP, 0172, "jp"}, +{0, JOP, 0172, "jpe"}, +{0, JOP, 0173, "jnp"}, +{0, JOP, 0173, "jpo"}, +{0, JOP, 0174, "jl"}, +{0, JOP, 0174, "jnge"}, +{0, JOP, 0175, "jge"}, +{0, JOP, 0175, "jnl"}, +{0, JOP, 0176, "jle"}, +{0, JOP, 0176, "jng"}, +{0, JOP, 0177, "jg"}, +{0, JOP, 0177, "jnle"}, +{0, PUSHOP, 0, "push"}, +{0, PUSHOP, 1, "pop"}, +{0, IOOP, 0344, "inb"}, +{0, IOOP, 0345, "in"}, +{0, IOOP, 0345, "inw"}, +{0, IOOP, 0346, "outb"}, +{0, IOOP, 0347, "out"}, +{0, IOOP, 0347, "outw"}, +{0, ADDOP, 000, "addb"}, +{0, ADDOP, 001, "add"}, +{0, ADDOP, 010, "orb"}, +{0, ADDOP, 011, "or"}, +{0, ADDOP, 020, "adcb"}, +{0, ADDOP, 021, "adc"}, +{0, ADDOP, 030, "sbbb"}, +{0, ADDOP, 031, "sbb"}, +{0, ADDOP, 040, "andb"}, +{0, ADDOP, 041, "and"}, +{0, ADDOP, 050, "subb"}, +{0, ADDOP, 051, "sub"}, +{0, ADDOP, 060, "xorb"}, +{0, ADDOP, 061, "xor"}, +{0, ADDOP, 070, "cmpb"}, +{0, ADDOP, 071, "cmp"}, +{0, ROLOP, 000, "rolb"}, +{0, ROLOP, 001, "rol"}, +{0, ROLOP, 010, "rorb"}, +{0, ROLOP, 011, "ror"}, +{0, ROLOP, 020, "rclb"}, +{0, ROLOP, 021, "rcl"}, +{0, ROLOP, 030, "rcrb"}, +{0, ROLOP, 031, "rcr"}, +{0, ROLOP, 040, "salb"}, +{0, ROLOP, 040, "shlb"}, +{0, ROLOP, 041, "sal"}, +{0, ROLOP, 041, "shl"}, +{0, ROLOP, 050, "shrb"}, +{0, ROLOP, 051, "shr"}, +{0, ROLOP, 070, "sarb"}, +{0, ROLOP, 071, "sar"}, +{0, INCOP, 000, "incb"}, +{0, INCOP, 001, "inc"}, +{0, INCOP, 010, "decb"}, +{0, INCOP, 011, "dec"}, +{0, NOTOP, 020, "notb"}, +{0, NOTOP, 021, "not"}, +{0, NOTOP, 030, "negb"}, +{0, NOTOP, 031, "neg"}, +{0, NOTOP, 040, "mulb"}, +{0, NOTOP, 041, "mul"}, +{0, NOTOP, 050, "imulb"}, +{0, IMUL, 051, "imul"}, /* for 80286 */ +{0, NOTOP, 060, "divb"}, +{0, NOTOP, 061, "div"}, +{0, NOTOP, 070, "idivb"}, +{0, NOTOP, 071, "idiv"}, +{0, CALLOP, 020+(0350<<8), "call"}, +{0, CALLOP, 040+(0351<<8), "jmp"}, +{0, CALFOP, 030+(0232<<8), "callf"}, +{0, CALFOP, 050+(0352<<8), "jmpf"}, +{0, LEAOP, 0215, "lea"}, +{0, LEAOP, 0304, "les"}, +{0, LEAOP, 0305, "lds"}, +{0, ESC, 0, "esc"}, +{0, INT, 0, "int"}, +{0, RET, 0303, "ret"}, +{0, RET, 0313, "retf"}, +{0, XCHG, 0, "xchgb"}, +{0, XCHG, 1, "xchg"}, +{0, TEST, 0, "testb"}, +{0, TEST, 1, "test"}, +{0, MOV, 0, "movb"}, +{0, MOV, 1, "mov"}, +{0, MOV, 1, "movw"}, /* Intel 8087 coprocessor keywords */ -0, ST, 0, "st", +{0, ST, 0, "st"}, -0, FNOOP, FESC+1+(0xF0<<8), "f2xm1", -0, FNOOP, FESC+1+(0xE1<<8), "fabs", -0, FNOOP, FESC+1+(0xE0<<8), "fchs", -0, FNOOP, FESC+3+(0xE2<<8), "fclex", -0, FNOOP, FESC+6+(0xD9<<8), "fcompp", -0, FNOOP, FESC+1+(0xF6<<8), "fdecstp", -0, FNOOP, FESC+3+(0xE1<<8), "fdisi", -0, FNOOP, FESC+3+(0xE0<<8), "feni", -0, FNOOP, FESC+1+(0xF7<<8), "fincstp", -0, FNOOP, FESC+3+(0xE3<<8), "finit", -0, FNOOP, FESC+1+(0xE8<<8), "fld1", -0, FNOOP, FESC+1+(0xEA<<8), "fldl2e", -0, FNOOP, FESC+1+(0xE9<<8), "fldl2t", -0, FNOOP, FESC+1+(0xEC<<8), "fldlg2", -0, FNOOP, FESC+1+(0xED<<8), "fldln2", -0, FNOOP, FESC+1+(0xEB<<8), "fldpi", -0, FNOOP, FESC+1+(0xEE<<8), "fldz", -0, FNOOP, FESC+1+(0xD0<<8), "fnop", -0, FNOOP, FESC+1+(0xF3<<8), "fpatan", -0, FNOOP, FESC+1+(0xF8<<8), "fprem", -0, FNOOP, FESC+1+(0xF2<<8), "fptan", -0, FNOOP, FESC+1+(0xFC<<8), "frndint", -0, FNOOP, FESC+1+(0xFD<<8), "fscale", -0, FNOOP, FESC+1+(0xFA<<8), "fsqrt", -0, FNOOP, FESC+7+(0xE0<<8), "fstswax", /* 80287 */ -0, FNOOP, FESC+1+(0xE4<<8), "ftst", -0, FNOOP, FESC+1+(0xE5<<8), "fxam", -0, FNOOP, FESC+1+(0xF4<<8), "fxtract", -0, FNOOP, FESC+1+(0xF1<<8), "fyl2x", -0, FNOOP, FESC+1+(0xF9<<8), "fyl2pi", +{0, FNOOP, FESC+1+(0xF0<<8), "f2xm1"}, +{0, FNOOP, FESC+1+(0xE1<<8), "fabs"}, +{0, FNOOP, FESC+1+(0xE0<<8), "fchs"}, +{0, FNOOP, FESC+3+(0xE2<<8), "fclex"}, +{0, FNOOP, FESC+6+(0xD9<<8), "fcompp"}, +{0, FNOOP, FESC+1+(0xF6<<8), "fdecstp"}, +{0, FNOOP, FESC+3+(0xE1<<8), "fdisi"}, +{0, FNOOP, FESC+3+(0xE0<<8), "feni"}, +{0, FNOOP, FESC+1+(0xF7<<8), "fincstp"}, +{0, FNOOP, FESC+3+(0xE3<<8), "finit"}, +{0, FNOOP, FESC+1+(0xE8<<8), "fld1"}, +{0, FNOOP, FESC+1+(0xEA<<8), "fldl2e"}, +{0, FNOOP, FESC+1+(0xE9<<8), "fldl2t"}, +{0, FNOOP, FESC+1+(0xEC<<8), "fldlg2"}, +{0, FNOOP, FESC+1+(0xED<<8), "fldln2"}, +{0, FNOOP, FESC+1+(0xEB<<8), "fldpi"}, +{0, FNOOP, FESC+1+(0xEE<<8), "fldz"}, +{0, FNOOP, FESC+1+(0xD0<<8), "fnop"}, +{0, FNOOP, FESC+1+(0xF3<<8), "fpatan"}, +{0, FNOOP, FESC+1+(0xF8<<8), "fprem"}, +{0, FNOOP, FESC+1+(0xF2<<8), "fptan"}, +{0, FNOOP, FESC+1+(0xFC<<8), "frndint"}, +{0, FNOOP, FESC+1+(0xFD<<8), "fscale"}, +{0, FNOOP, FESC+1+(0xFA<<8), "fsqrt"}, +{0, FNOOP, FESC+7+(0xE0<<8), "fstswax"}, /* 80287 */ +{0, FNOOP, FESC+1+(0xE4<<8), "ftst"}, +{0, FNOOP, FESC+1+(0xE5<<8), "fxam"}, +{0, FNOOP, FESC+1+(0xF4<<8), "fxtract"}, +{0, FNOOP, FESC+1+(0xF1<<8), "fyl2x"}, +{0, FNOOP, FESC+1+(0xF9<<8), "fyl2pi"}, -0, FMEM, FESC+6+(0<<11), "fiadds", -0, FMEM, FESC+2+(0<<11), "fiaddl", -0, FMEM, FESC+0+(0<<11), "fadds", -0, FMEM, FESC+4+(0<<11), "faddd", -0, FMEM, FESC+7+(4<<11), "fbld", -0, FMEM, FESC+7+(6<<11), "fbstp", -0, FMEM, FESC+6+(2<<11), "ficoms", -0, FMEM, FESC+2+(2<<11), "ficoml", -0, FMEM, FESC+0+(2<<11), "fcoms", -0, FMEM, FESC+4+(2<<11), "fcomd", -0, FMEM, FESC+6+(3<<11), "ficomps", -0, FMEM, FESC+2+(3<<11), "ficompl", -0, FMEM, FESC+0+(3<<11), "fcomps", -0, FMEM, FESC+4+(3<<11), "fcompd", -0, FMEM, FESC+6+(6<<11), "fidivs", -0, FMEM, FESC+2+(6<<11), "fidivl", -0, FMEM, FESC+0+(6<<11), "fdivs", -0, FMEM, FESC+4+(6<<11), "fdivd", -0, FMEM, FESC+6+(7<<11), "fidivrs", -0, FMEM, FESC+2+(7<<11), "fidivrl", -0, FMEM, FESC+0+(7<<11), "fdivrs", -0, FMEM, FESC+4+(7<<11), "fdivrd", -0, FMEM, FESC+7+(5<<11), "fildq", -0, FMEM, FESC+7+(0<<11), "filds", -0, FMEM, FESC+3+(0<<11), "fildl", -0, FMEM, FESC+1+(0<<11), "flds", -0, FMEM, FESC+5+(0<<11), "fldd", -0, FMEM, FESC+3+(5<<11), "fldx", -0, FMEM, FESC+1+(5<<11), "fldcw", -0, FMEM, FESC+1+(4<<11), "fldenv", -0, FMEM, FESC+6+(1<<11), "fimuls", -0, FMEM, FESC+2+(1<<11), "fimull", -0, FMEM, FESC+0+(1<<11), "fmuls", -0, FMEM, FESC+4+(1<<11), "fmuld", -0, FMEM, FESC+5+(4<<11), "frstor", -0, FMEM, FESC+5+(6<<11), "fsave", -0, FMEM, FESC+7+(2<<11), "fists", -0, FMEM, FESC+3+(2<<11), "fistl", -0, FMEM, FESC+1+(2<<11), "fsts", -0, FMEM, FESC+5+(2<<11), "fstd", -0, FMEM, FESC+7+(7<<11), "fistpq", -0, FMEM, FESC+7+(3<<11), "fistps", -0, FMEM, FESC+3+(3<<11), "fistpl", -0, FMEM, FESC+1+(3<<11), "fstps", -0, FMEM, FESC+5+(3<<11), "fstpd", -0, FMEM, FESC+3+(7<<11), "fstpx", -0, FMEM, FESC+1+(7<<11), "fstcw", -0, FMEM, FESC+1+(6<<11), "fstenv", -0, FMEM, FESC+5+(7<<11), "fstsw", -0, FMEM, FESC+6+(4<<11), "fisubs", -0, FMEM, FESC+2+(4<<11), "fisubl", -0, FMEM, FESC+0+(4<<11), "fsubs", -0, FMEM, FESC+4+(4<<11), "fsubd", -0, FMEM, FESC+6+(5<<11), "fisubrs", -0, FMEM, FESC+2+(5<<11), "fisubrl", -0, FMEM, FESC+0+(5<<11), "fsubrs", -0, FMEM, FESC+4+(5<<11), "fsubrd", +{0, FMEM, FESC+6+(0<<11), "fiadds"}, +{0, FMEM, FESC+2+(0<<11), "fiaddl"}, +{0, FMEM, FESC+0+(0<<11), "fadds"}, +{0, FMEM, FESC+4+(0<<11), "faddd"}, +{0, FMEM, FESC+7+(4<<11), "fbld"}, +{0, FMEM, FESC+7+(6<<11), "fbstp"}, +{0, FMEM, FESC+6+(2<<11), "ficoms"}, +{0, FMEM, FESC+2+(2<<11), "ficoml"}, +{0, FMEM, FESC+0+(2<<11), "fcoms"}, +{0, FMEM, FESC+4+(2<<11), "fcomd"}, +{0, FMEM, FESC+6+(3<<11), "ficomps"}, +{0, FMEM, FESC+2+(3<<11), "ficompl"}, +{0, FMEM, FESC+0+(3<<11), "fcomps"}, +{0, FMEM, FESC+4+(3<<11), "fcompd"}, +{0, FMEM, FESC+6+(6<<11), "fidivs"}, +{0, FMEM, FESC+2+(6<<11), "fidivl"}, +{0, FMEM, FESC+0+(6<<11), "fdivs"}, +{0, FMEM, FESC+4+(6<<11), "fdivd"}, +{0, FMEM, FESC+6+(7<<11), "fidivrs"}, +{0, FMEM, FESC+2+(7<<11), "fidivrl"}, +{0, FMEM, FESC+0+(7<<11), "fdivrs"}, +{0, FMEM, FESC+4+(7<<11), "fdivrd"}, +{0, FMEM, FESC+7+(5<<11), "fildq"}, +{0, FMEM, FESC+7+(0<<11), "filds"}, +{0, FMEM, FESC+3+(0<<11), "fildl"}, +{0, FMEM, FESC+1+(0<<11), "flds"}, +{0, FMEM, FESC+5+(0<<11), "fldd"}, +{0, FMEM, FESC+3+(5<<11), "fldx"}, +{0, FMEM, FESC+1+(5<<11), "fldcw"}, +{0, FMEM, FESC+1+(4<<11), "fldenv"}, +{0, FMEM, FESC+6+(1<<11), "fimuls"}, +{0, FMEM, FESC+2+(1<<11), "fimull"}, +{0, FMEM, FESC+0+(1<<11), "fmuls"}, +{0, FMEM, FESC+4+(1<<11), "fmuld"}, +{0, FMEM, FESC+5+(4<<11), "frstor"}, +{0, FMEM, FESC+5+(6<<11), "fsave"}, +{0, FMEM, FESC+7+(2<<11), "fists"}, +{0, FMEM, FESC+3+(2<<11), "fistl"}, +{0, FMEM, FESC+1+(2<<11), "fsts"}, +{0, FMEM, FESC+5+(2<<11), "fstd"}, +{0, FMEM, FESC+7+(7<<11), "fistpq"}, +{0, FMEM, FESC+7+(3<<11), "fistps"}, +{0, FMEM, FESC+3+(3<<11), "fistpl"}, +{0, FMEM, FESC+1+(3<<11), "fstps"}, +{0, FMEM, FESC+5+(3<<11), "fstpd"}, +{0, FMEM, FESC+3+(7<<11), "fstpx"}, +{0, FMEM, FESC+1+(7<<11), "fstcw"}, +{0, FMEM, FESC+1+(6<<11), "fstenv"}, +{0, FMEM, FESC+5+(7<<11), "fstsw"}, +{0, FMEM, FESC+6+(4<<11), "fisubs"}, +{0, FMEM, FESC+2+(4<<11), "fisubl"}, +{0, FMEM, FESC+0+(4<<11), "fsubs"}, +{0, FMEM, FESC+4+(4<<11), "fsubd"}, +{0, FMEM, FESC+6+(5<<11), "fisubrs"}, +{0, FMEM, FESC+2+(5<<11), "fisubrl"}, +{0, FMEM, FESC+0+(5<<11), "fsubrs"}, +{0, FMEM, FESC+4+(5<<11), "fsubrd"}, -0, FST_I, FESC+1+(0xC0<<8), "fld", -0, FST_I, FESC+5+(0xD0<<8), "fst", -0, FST_I, FESC+5+(0xC8<<8), "fstp", -0, FST_I, FESC+1+(0xC8<<8), "fxch", -0, FST_I, FESC+0+(0xD0<<8), "fcom", -0, FST_I, FESC+0+(0xD8<<8), "fcomp", -0, FST_I, FESC+5+(0xC0<<8), "ffree", +{0, FST_I, FESC+1+(0xC0<<8), "fld"}, +{0, FST_I, FESC+5+(0xD0<<8), "fst"}, +{0, FST_I, FESC+5+(0xC8<<8), "fstp"}, +{0, FST_I, FESC+1+(0xC8<<8), "fxch"}, +{0, FST_I, FESC+0+(0xD0<<8), "fcom"}, +{0, FST_I, FESC+0+(0xD8<<8), "fcomp"}, +{0, FST_I, FESC+5+(0xC0<<8), "ffree"}, -0, FST_ST, FESC+0+(0xC0<<8), "fadd", -0, FST_ST, FESC+2+(0xC0<<8), "faddp", -0, FST_ST2, FESC+0+(0xF0<<8), "fdiv", -0, FST_ST2, FESC+2+(0xF0<<8), "fdivp", -0, FST_ST2, FESC+0+(0xF8<<8), "fdivr", -0, FST_ST2, FESC+2+(0xF8<<8), "fdivrp", -0, FST_ST, FESC+0+(0xC8<<8), "fmul", -0, FST_ST, FESC+2+(0xC8<<8), "fmulp", -0, FST_ST2, FESC+0+(0xE0<<8), "fsub", -0, FST_ST2, FESC+2+(0xE0<<8), "fsubp", -0, FST_ST2, FESC+0+(0xE8<<8), "fsubr", -0, FST_ST2, FESC+2+(0xE8<<8), "fsubrp", +{0, FST_ST, FESC+0+(0xC0<<8), "fadd"}, +{0, FST_ST, FESC+2+(0xC0<<8), "faddp"}, +{0, FST_ST2, FESC+0+(0xF0<<8), "fdiv"}, +{0, FST_ST2, FESC+2+(0xF0<<8), "fdivp"}, +{0, FST_ST2, FESC+0+(0xF8<<8), "fdivr"}, +{0, FST_ST2, FESC+2+(0xF8<<8), "fdivrp"}, +{0, FST_ST, FESC+0+(0xC8<<8), "fmul"}, +{0, FST_ST, FESC+2+(0xC8<<8), "fmulp"}, +{0, FST_ST2, FESC+0+(0xE0<<8), "fsub"}, +{0, FST_ST2, FESC+2+(0xE0<<8), "fsubp"}, +{0, FST_ST2, FESC+0+(0xE8<<8), "fsubr"}, +{0, FST_ST2, FESC+2+(0xE8<<8), "fsubrp"}, /* 80286 keywords */ -0, NOOP_1, 0140, "pusha", -0, NOOP_1, 0141, "popa", -0, NOOP_1, 0154, "insb", -0, NOOP_1, 0155, "ins", -0, NOOP_1, 0155, "insw", -0, NOOP_1, 0156, "outsb", -0, NOOP_1, 0157, "outs", -0, NOOP_1, 0157, "outsw", +{0, NOOP_1, 0140, "pusha"}, +{0, NOOP_1, 0141, "popa"}, +{0, NOOP_1, 0154, "insb"}, +{0, NOOP_1, 0155, "ins"}, +{0, NOOP_1, 0155, "insw"}, +{0, NOOP_1, 0156, "outsb"}, +{0, NOOP_1, 0157, "outs"}, +{0, NOOP_1, 0157, "outsw"}, -0, ARPLOP, 0143, "arpl", -0, ENTER, 0310, "enter", -0, NOOP_1, 0311, "leave", -0, LEAOP, 0142, "bound", +{0, ARPLOP, 0143, "arpl"}, +{0, ENTER, 0310, "enter"}, +{0, NOOP_1, 0311, "leave"}, +{0, LEAOP, 0142, "bound"}, -0, NOOP_2, 017+06<<8, "clts", +{0, NOOP_2, 017+06<<8, "clts"}, -0, EXTOP, 0002, "lar", -0, EXTOP, 0003, "lsl", +{0, EXTOP, 0002, "lar"}, +{0, EXTOP, 0003, "lsl"}, -0, EXTOP1, 0021, "lgdt", -0, EXTOP1, 0001, "sgdt", -0, EXTOP1, 0031, "lidt", -0, EXTOP1, 0011, "sidt", -0, EXTOP1, 0020, "lldt", -0, EXTOP1, 0000, "sldt", -0, EXTOP1, 0030, "ltr", -0, EXTOP1, 0010, "str", -0, EXTOP1, 0061, "lmsw", -0, EXTOP1, 0041, "smsw", -0, EXTOP1, 0050, "verw", -0, EXTOP1, 0040, "verr", +{0, EXTOP1, 0021, "lgdt"}, +{0, EXTOP1, 0001, "sgdt"}, +{0, EXTOP1, 0031, "lidt"}, +{0, EXTOP1, 0011, "sidt"}, +{0, EXTOP1, 0020, "lldt"}, +{0, EXTOP1, 0000, "sldt"}, +{0, EXTOP1, 0030, "ltr"}, +{0, EXTOP1, 0010, "str"}, +{0, EXTOP1, 0061, "lmsw"}, +{0, EXTOP1, 0041, "smsw"}, +{0, EXTOP1, 0050, "verw"}, +{0, EXTOP1, 0040, "verr"}, diff --git a/mach/m68020/as/mach3.c b/mach/m68020/as/mach3.c index 96f52d228..e77745707 100644 --- a/mach/m68020/as/mach3.c +++ b/mach/m68020/as/mach3.c @@ -7,460 +7,460 @@ * Motorola 68020 keywords */ -0, SIZE, SIZE_B, ".b", -0, SIZE, SIZE_W, ".w", -0, SIZE, SIZE_L, ".l", +{0, SIZE, SIZE_B, ".b"}, +{0, SIZE, SIZE_W, ".w"}, +{0, SIZE, SIZE_L, ".l"}, -0, DREG, 00, "d0", -0, DREG, 01, "d1", -0, DREG, 02, "d2", -0, DREG, 03, "d3", -0, DREG, 04, "d4", -0, DREG, 05, "d5", -0, DREG, 06, "d6", -0, DREG, 07, "d7", +{0, DREG, 00, "d0"}, +{0, DREG, 01, "d1"}, +{0, DREG, 02, "d2"}, +{0, DREG, 03, "d3"}, +{0, DREG, 04, "d4"}, +{0, DREG, 05, "d5"}, +{0, DREG, 06, "d6"}, +{0, DREG, 07, "d7"}, -0, AREG, 00, "a0", -0, AREG, 01, "a1", -0, AREG, 02, "a2", -0, AREG, 03, "a3", -0, AREG, 04, "a4", -0, AREG, 05, "a5", -0, AREG, 06, "a6", -0, AREG, 07, "a7", -0, AREG, 07, "sp", +{0, AREG, 00, "a0"}, +{0, AREG, 01, "a1"}, +{0, AREG, 02, "a2"}, +{0, AREG, 03, "a3"}, +{0, AREG, 04, "a4"}, +{0, AREG, 05, "a5"}, +{0, AREG, 06, "a6"}, +{0, AREG, 07, "a7"}, +{0, AREG, 07, "sp"}, -0, PC, 0, "pc", -0, PC, 0200, "zpc", +{0, PC, 0, "pc"}, +{0, PC, 0200, "zpc"}, -0, CREG, 04001, "vbr", -0, CREG, 0, "sfc", -0, CREG, 00001, "dfc", -0, CREG, 00002, "cacr", -0, CREG, 04002, "caar", -0, CREG, 04003, "msp", -0, CREG, 04004, "isp", +{0, CREG, 04001, "vbr"}, +{0, CREG, 0, "sfc"}, +{0, CREG, 00001, "dfc"}, +{0, CREG, 00002, "cacr"}, +{0, CREG, 04002, "caar"}, +{0, CREG, 04003, "msp"}, +{0, CREG, 04004, "isp"}, -0, SPEC, 075, "usp", -0, SPEC, 076, "ccr", -0, SPEC, 077, "sr", +{0, SPEC, 075, "usp"}, +{0, SPEC, 076, "ccr"}, +{0, SPEC, 077, "sr"}, -0, ABCD, 0140400, "abcd", -0, ABCD, 0100400, "sbcd", +{0, ABCD, 0140400, "abcd"}, +{0, ABCD, 0100400, "sbcd"}, -0, ADDX, 0150400, "addx", -0, ADDX, 0110400, "subx", +{0, ADDX, 0150400, "addx"}, +{0, ADDX, 0110400, "subx"}, -0, ADD, 0153300, "add", -0, ADD, 0112700, "sub", +{0, ADD, 0153300, "add"}, +{0, ADD, 0112700, "sub"}, -0, AND, 0141000, "and", -0, AND, 0135000, "eor", -0, AND, 0100000, "or", +{0, AND, 0141000, "and"}, +{0, AND, 0135000, "eor"}, +{0, AND, 0100000, "or"}, -0, BITOP, 0000, "btst", -0, BITOP, 0100, "bchg", -0, BITOP, 0200, "bclr", -0, BITOP, 0300, "bset", +{0, BITOP, 0000, "btst"}, +{0, BITOP, 0100, "bchg"}, +{0, BITOP, 0200, "bclr"}, +{0, BITOP, 0300, "bset"}, -0, BITFIELD, 0164300, "bftst", -0, BITFIELD, 0165300, "bfchg", -0, BITFIELD, 0166300, "bfclr", -0, BITFIELD, 0167300, "bfset", -0, BF_TO_D, 0164700, "bfextu", -0, BF_TO_D, 0164700, "bfexts", -0, BF_TO_D, 0164700, "bfffo", -0, BFINS, 0167700, "bfins", +{0, BITFIELD, 0164300, "bftst"}, +{0, BITFIELD, 0165300, "bfchg"}, +{0, BITFIELD, 0166300, "bfclr"}, +{0, BITFIELD, 0167300, "bfset"}, +{0, BF_TO_D, 0164700, "bfextu"}, +{0, BF_TO_D, 0164700, "bfexts"}, +{0, BF_TO_D, 0164700, "bfffo"}, +{0, BFINS, 0167700, "bfins"}, -0, SHIFT, 0160340, "asr", -0, SHIFT, 0160740, "asl", -0, SHIFT, 0161350, "lsr", -0, SHIFT, 0161750, "lsl", -0, SHIFT, 0162360, "roxr", -0, SHIFT, 0162760, "roxl", -0, SHIFT, 0163370, "ror", -0, SHIFT, 0163770, "rol", +{0, SHIFT, 0160340, "asr"}, +{0, SHIFT, 0160740, "asl"}, +{0, SHIFT, 0161350, "lsr"}, +{0, SHIFT, 0161750, "lsl"}, +{0, SHIFT, 0162360, "roxr"}, +{0, SHIFT, 0162760, "roxl"}, +{0, SHIFT, 0163370, "ror"}, +{0, SHIFT, 0163770, "rol"}, -0, SZ_EA, 041000|DTA|ALT, "clr", -0, SZ_EA, 042000|DTA|ALT, "neg", -0, SZ_EA, 040000|DTA|ALT, "negx", -0, SZ_EA, 043000|DTA|ALT, "not", -0, SZ_EA, 045000, "tst", +{0, SZ_EA, 041000|DTA|ALT, "clr"}, +{0, SZ_EA, 042000|DTA|ALT, "neg"}, +{0, SZ_EA, 040000|DTA|ALT, "negx"}, +{0, SZ_EA, 043000|DTA|ALT, "not"}, +{0, SZ_EA, 045000, "tst"}, -0, OP_EA, 044000|DTA|ALT, "nbcd", -0, OP_EA, 045300|DTA|ALT, "tas", -0, OP_EA, 047200|CTR, "jsr", -0, OP_EA, 047300|CTR, "jmp", -0, OP_EA, 044100|CTR, "pea", +{0, OP_EA, 044000|DTA|ALT, "nbcd"}, +{0, OP_EA, 045300|DTA|ALT, "tas"}, +{0, OP_EA, 047200|CTR, "jsr"}, +{0, OP_EA, 047300|CTR, "jmp"}, +{0, OP_EA, 044100|CTR, "pea"}, -0, OP_EA, 050300, "st", -0, OP_EA, 050700, "sf", -0, OP_EA, 051300, "shi", -0, OP_EA, 051700, "sls", -0, OP_EA, 052300, "scc", -0, OP_EA, 052700, "scs", -0, OP_EA, 053300, "sne", -0, OP_EA, 053700, "seq", -0, OP_EA, 054300, "svc", -0, OP_EA, 054700, "svs", -0, OP_EA, 055300, "spl", -0, OP_EA, 055700, "smi", -0, OP_EA, 056300, "sge", -0, OP_EA, 056700, "slt", -0, OP_EA, 057300, "sgt", -0, OP_EA, 057700, "sle", +{0, OP_EA, 050300, "st"}, +{0, OP_EA, 050700, "sf"}, +{0, OP_EA, 051300, "shi"}, +{0, OP_EA, 051700, "sls"}, +{0, OP_EA, 052300, "scc"}, +{0, OP_EA, 052700, "scs"}, +{0, OP_EA, 053300, "sne"}, +{0, OP_EA, 053700, "seq"}, +{0, OP_EA, 054300, "svc"}, +{0, OP_EA, 054700, "svs"}, +{0, OP_EA, 055300, "spl"}, +{0, OP_EA, 055700, "smi"}, +{0, OP_EA, 056300, "sge"}, +{0, OP_EA, 056700, "slt"}, +{0, OP_EA, 057300, "sgt"}, +{0, OP_EA, 057700, "sle"}, -0, OP_NOOP, 047160, "reset", -0, OP_NOOP, 047161, "nop", -0, OP_NOOP, 047163, "rte", -0, OP_NOOP, 047165, "rts", -0, OP_NOOP, 047166, "trapv", -0, OP_NOOP, 047167, "rtr", -0, OP_NOOP, 045374, "illegal", +{0, OP_NOOP, 047160, "reset"}, +{0, OP_NOOP, 047161, "nop"}, +{0, OP_NOOP, 047163, "rte"}, +{0, OP_NOOP, 047165, "rts"}, +{0, OP_NOOP, 047166, "trapv"}, +{0, OP_NOOP, 047167, "rtr"}, +{0, OP_NOOP, 045374, "illegal"}, -0, PACK, 0100500, "pack", -0, PACK, 0100600, "unpk", +{0, PACK, 0100500, "pack"}, +{0, PACK, 0100600, "unpk"}, -0, DIVMUL, 0100, "divu", -0, DIVMUL, 0101, "divs", -0, DIVMUL, 0000, "mulu", -0, DIVMUL, 0001, "muls", +{0, DIVMUL, 0100, "divu"}, +{0, DIVMUL, 0101, "divs"}, +{0, DIVMUL, 0000, "mulu"}, +{0, DIVMUL, 0001, "muls"}, -0, DIVL, 046100, "divul", -0, DIVL, 046101, "divsl", +{0, DIVL, 046100, "divul"}, +{0, DIVL, 046101, "divsl"}, -0, BR, 060000, "bra", -0, BR, 060400, "bsr", -0, BR, 061000, "bhi", -0, BR, 061400, "bls", -0, BR, 062000, "bcc", -0, BR, 062400, "bcs", -0, BR, 063000, "bne", -0, BR, 063400, "beq", -0, BR, 064000, "bvc", -0, BR, 064400, "bvs", -0, BR, 065000, "bpl", -0, BR, 065400, "bmi", -0, BR, 066000, "bge", -0, BR, 066400, "blt", -0, BR, 067000, "bgt", -0, BR, 067400, "ble", +{0, BR, 060000, "bra"}, +{0, BR, 060400, "bsr"}, +{0, BR, 061000, "bhi"}, +{0, BR, 061400, "bls"}, +{0, BR, 062000, "bcc"}, +{0, BR, 062400, "bcs"}, +{0, BR, 063000, "bne"}, +{0, BR, 063400, "beq"}, +{0, BR, 064000, "bvc"}, +{0, BR, 064400, "bvs"}, +{0, BR, 065000, "bpl"}, +{0, BR, 065400, "bmi"}, +{0, BR, 066000, "bge"}, +{0, BR, 066400, "blt"}, +{0, BR, 067000, "bgt"}, +{0, BR, 067400, "ble"}, -0, DBR, 050310, "dbt", -0, DBR, 050710, "dbf", -0, DBR, 050710, "dbra", -0, DBR, 051310, "dbhi", -0, DBR, 051710, "dbls", -0, DBR, 052310, "dbcc", -0, DBR, 052710, "dbcs", -0, DBR, 053310, "dbne", -0, DBR, 053710, "dbeq", -0, DBR, 054310, "dbvc", -0, DBR, 054710, "dbvs", -0, DBR, 055310, "dbpl", -0, DBR, 055710, "dbmi", -0, DBR, 056310, "dbge", -0, DBR, 056710, "dblt", -0, DBR, 057310, "dbgt", -0, DBR, 057710, "dble", +{0, DBR, 050310, "dbt"}, +{0, DBR, 050710, "dbf"}, +{0, DBR, 050710, "dbra"}, +{0, DBR, 051310, "dbhi"}, +{0, DBR, 051710, "dbls"}, +{0, DBR, 052310, "dbcc"}, +{0, DBR, 052710, "dbcs"}, +{0, DBR, 053310, "dbne"}, +{0, DBR, 053710, "dbeq"}, +{0, DBR, 054310, "dbvc"}, +{0, DBR, 054710, "dbvs"}, +{0, DBR, 055310, "dbpl"}, +{0, DBR, 055710, "dbmi"}, +{0, DBR, 056310, "dbge"}, +{0, DBR, 056710, "dblt"}, +{0, DBR, 057310, "dbgt"}, +{0, DBR, 057710, "dble"}, -0, OP_EXT, 044000, "ext", -0, OP_EXT, 044400, "extb", +{0, OP_EXT, 044000, "ext"}, +{0, OP_EXT, 044400, "extb"}, -0, OP_RANGE, 04000, "chk2", -0, OP_RANGE, 0, "cmp2", +{0, OP_RANGE, 04000, "chk2"}, +{0, OP_RANGE, 0, "cmp2"}, -0, TRAPCC, 050370, "trapt", -0, TRAPCC, 050770, "trapf", -0, TRAPCC, 051370, "traphi", -0, TRAPCC, 051770, "trapls", -0, TRAPCC, 052370, "trapcc", -0, TRAPCC, 052770, "trapcs", -0, TRAPCC, 053370, "trapeq", -0, TRAPCC, 053770, "trapvc", -0, TRAPCC, 054370, "trapvs", -0, TRAPCC, 054770, "trappl", -0, TRAPCC, 055370, "trapmi", -0, TRAPCC, 055770, "trapge", -0, TRAPCC, 056370, "traplt", -0, TRAPCC, 056770, "trapgt", -0, TRAPCC, 057370, "traple", -0, TRAPCC, 057770, "trapne", +{0, TRAPCC, 050370, "trapt"}, +{0, TRAPCC, 050770, "trapf"}, +{0, TRAPCC, 051370, "traphi"}, +{0, TRAPCC, 051770, "trapls"}, +{0, TRAPCC, 052370, "trapcc"}, +{0, TRAPCC, 052770, "trapcs"}, +{0, TRAPCC, 053370, "trapeq"}, +{0, TRAPCC, 053770, "trapvc"}, +{0, TRAPCC, 054370, "trapvs"}, +{0, TRAPCC, 054770, "trappl"}, +{0, TRAPCC, 055370, "trapmi"}, +{0, TRAPCC, 055770, "trapge"}, +{0, TRAPCC, 056370, "traplt"}, +{0, TRAPCC, 056770, "trapgt"}, +{0, TRAPCC, 057370, "traple"}, +{0, TRAPCC, 057770, "trapne"}, -0, CMP, 0, "cmp", +{0, CMP, 0, "cmp"}, -0, MOVE, 0, "move", -0, MOVESP, 0, "movep", -0, MOVEM, 0, "movem", -0, MOVESP, 1, "moves", -0, MOVEC, 0, "movec", +{0, MOVE, 0, "move"}, +{0, MOVESP, 0, "movep"}, +{0, MOVEM, 0, "movem"}, +{0, MOVESP, 1, "moves"}, +{0, MOVEC, 0, "movec"}, -0, SWAP, 0, "swap", +{0, SWAP, 0, "swap"}, -0, LINK, 0, "link", +{0, LINK, 0, "link"}, -0, UNLK, 0, "unlk", +{0, UNLK, 0, "unlk"}, -0, TRAP, 0, "trap", +{0, TRAP, 0, "trap"}, -0, OP_IMM, 047162, "stop", +{0, OP_IMM, 047162, "stop"}, -0, CHK, 0, "chk", +{0, CHK, 0, "chk"}, -0, RTM, 0, "rtm", +{0, RTM, 0, "rtm"}, -0, EXG, 0, "exg", +{0, EXG, 0, "exg"}, -0, LEA, 0, "lea", +{0, LEA, 0, "lea"}, -0, OP_IMM, 047164, "rtd", +{0, OP_IMM, 047164, "rtd"}, -0, BKPT, 0, "bkpt", +{0, BKPT, 0, "bkpt"}, -0, CALLM, 0, "callm", +{0, CALLM, 0, "callm"}, -0, CAS, 0, "cas", +{0, CAS, 0, "cas"}, -0, CAS2, 0, "cas2", +{0, CAS2, 0, "cas2"}, -0, CP, 00000, "c0", -0, CP, 01000, "c1", -0, CP, 02000, "c2", -0, CP, 03000, "c3", -0, CP, 04000, "c4", -0, CP, 05000, "c5", -0, CP, 06000, "c6", -0, CP, 07000, "c7", +{0, CP, 00000, "c0"}, +{0, CP, 01000, "c1"}, +{0, CP, 02000, "c2"}, +{0, CP, 03000, "c3"}, +{0, CP, 04000, "c4"}, +{0, CP, 05000, "c5"}, +{0, CP, 06000, "c6"}, +{0, CP, 07000, "c7"}, /* ???? what is this ???? */ -0, CPGEN, 0170000, ".gen", -0, CPSCC, 0170100, ".s", -0, CPDBCC, 0170110, ".db", -0, CPTRAPCC, 0170170, ".trap", -0, CPBCC, 0170200, ".br", /* 'r' to distinguish from SIZE_B +{0, CPGEN, 0170000, ".gen"}, +{0, CPSCC, 0170100, ".s"}, +{0, CPDBCC, 0170110, ".db"}, +{0, CPTRAPCC, 0170170, ".trap"}, +{0, CPBCC, 0170200, ".br"}, /* 'r' to distinguish from SIZE_B */ -0, CPSAVREST, 0170400, ".save", -0, CPSAVREST, 0170500, ".restore", +{0, CPSAVREST, 0170400, ".save"}, +{0, CPSAVREST, 0170500, ".restore"}, /* ???? end of what is this ???? */ /* M68030 MMU registers */ -0, MREG, 0040000, "tc", -0, MREG, 0044000, "srp", -0, MREG, 0046000, "crp", -0, MREG, 0060000, "mmusr", -0, MREG, 0060000, "psr", -0, MREG, 0004000, "tt0", -0, MREG, 0006000, "tt1", +{0, MREG, 0040000, "tc"}, +{0, MREG, 0044000, "srp"}, +{0, MREG, 0046000, "crp"}, +{0, MREG, 0060000, "mmusr"}, +{0, MREG, 0060000, "psr"}, +{0, MREG, 0004000, "tt0"}, +{0, MREG, 0006000, "tt1"}, /* M68030 MMU instructions */ -0, PFLUSHA, 0022000, "pflusha", -0, PFLUSH, 0020000, "pflush", -0, PLOAD, 0021000, "ploadr", -0, PLOAD, 0020000, "ploadw", -0, PTEST, 0101000, "ptestr", -0, PTEST, 0100000, "ptestw", -0, PMOVE, 0000000, "pmove", -0, PMOVE, 0000400, "pmovefd", +{0, PFLUSHA, 0022000, "pflusha"}, +{0, PFLUSH, 0020000, "pflush"}, +{0, PLOAD, 0021000, "ploadr"}, +{0, PLOAD, 0020000, "ploadw"}, +{0, PTEST, 0101000, "ptestr"}, +{0, PTEST, 0100000, "ptestw"}, +{0, PMOVE, 0000000, "pmove"}, +{0, PMOVE, 0000400, "pmovefd"}, /* floating point coprocessor ... */ -0, FSIZE, FSIZE_S, ".s", -0, FSIZE, FSIZE_X, ".x", -0, FSIZE, FSIZE_P, ".p", -0, FSIZE, FSIZE_D, ".d", +{0, FSIZE, FSIZE_S, ".s"}, +{0, FSIZE, FSIZE_X, ".x"}, +{0, FSIZE, FSIZE_P, ".p"}, +{0, FSIZE, FSIZE_D, ".d"}, -0, FPREG, 0, "fp0", -0, FPREG, 1, "fp1", -0, FPREG, 2, "fp2", -0, FPREG, 3, "fp3", -0, FPREG, 4, "fp4", -0, FPREG, 5, "fp5", -0, FPREG, 6, "fp6", -0, FPREG, 7, "fp7", +{0, FPREG, 0, "fp0"}, +{0, FPREG, 1, "fp1"}, +{0, FPREG, 2, "fp2"}, +{0, FPREG, 3, "fp3"}, +{0, FPREG, 4, "fp4"}, +{0, FPREG, 5, "fp5"}, +{0, FPREG, 6, "fp6"}, +{0, FPREG, 7, "fp7"}, -0, FPCR, 1, "fpiar", -0, FPCR, 2, "fpsr", -0, FPCR, 4, "fpcr", +{0, FPCR, 1, "fpiar"}, +{0, FPCR, 2, "fpsr"}, +{0, FPCR, 4, "fpcr"}, -0, FMOVE, 0, "fmove", -0, FMOVECR, 0, "fmovecr", -0, FMOVEM, 0, "fmovem", +{0, FMOVE, 0, "fmove"}, +{0, FMOVECR, 0, "fmovecr"}, +{0, FMOVEM, 0, "fmovem"}, -0, FDYADIC, 042, "fadd", -0, FDYADIC, 070, "fcmp", -0, FDYADIC, 040, "fdiv", -0, FDYADIC, 041, "fmod", -0, FDYADIC, 043, "fmul", -0, FDYADIC, 045, "frem", -0, FDYADIC, 046, "fscale", -0, FDYADIC, 044, "fsgldiv", -0, FDYADIC, 047, "fsglmul", -0, FDYADIC, 050, "fsub", +{0, FDYADIC, 042, "fadd"}, +{0, FDYADIC, 070, "fcmp"}, +{0, FDYADIC, 040, "fdiv"}, +{0, FDYADIC, 041, "fmod"}, +{0, FDYADIC, 043, "fmul"}, +{0, FDYADIC, 045, "frem"}, +{0, FDYADIC, 046, "fscale"}, +{0, FDYADIC, 044, "fsgldiv"}, +{0, FDYADIC, 047, "fsglmul"}, +{0, FDYADIC, 050, "fsub"}, -0, FMONADIC, 030, "fabs", -0, FMONADIC, 034, "facos", -0, FMONADIC, 014, "fasin", -0, FMONADIC, 012, "fatan", -0, FMONADIC, 015, "fatanh", -0, FMONADIC, 035, "fcos", -0, FMONADIC, 031, "fcosh", -0, FMONADIC, 020, "fetox", -0, FMONADIC, 010, "fetoxm1", -0, FMONADIC, 036, "fgetexp", -0, FMONADIC, 037, "fgetman", -0, FMONADIC, 001, "fint", -0, FMONADIC, 003, "fintrz", -0, FMONADIC, 024, "flogn", -0, FMONADIC, 006, "flognp1", -0, FMONADIC, 025, "flog10", -0, FMONADIC, 026, "flog2", -0, FMONADIC, 032, "fneg", -0, FMONADIC, 016, "fsin", -0, FMONADIC, 002, "fsinh", -0, FMONADIC, 004, "fsqrt", -0, FMONADIC, 017, "ftan", -0, FMONADIC, 011, "ftanh", -0, FMONADIC, 022, "ftentox", -0, FMONADIC, 021, "ftwotox", +{0, FMONADIC, 030, "fabs"}, +{0, FMONADIC, 034, "facos"}, +{0, FMONADIC, 014, "fasin"}, +{0, FMONADIC, 012, "fatan"}, +{0, FMONADIC, 015, "fatanh"}, +{0, FMONADIC, 035, "fcos"}, +{0, FMONADIC, 031, "fcosh"}, +{0, FMONADIC, 020, "fetox"}, +{0, FMONADIC, 010, "fetoxm1"}, +{0, FMONADIC, 036, "fgetexp"}, +{0, FMONADIC, 037, "fgetman"}, +{0, FMONADIC, 001, "fint"}, +{0, FMONADIC, 003, "fintrz"}, +{0, FMONADIC, 024, "flogn"}, +{0, FMONADIC, 006, "flognp1"}, +{0, FMONADIC, 025, "flog10"}, +{0, FMONADIC, 026, "flog2"}, +{0, FMONADIC, 032, "fneg"}, +{0, FMONADIC, 016, "fsin"}, +{0, FMONADIC, 002, "fsinh"}, +{0, FMONADIC, 004, "fsqrt"}, +{0, FMONADIC, 017, "ftan"}, +{0, FMONADIC, 011, "ftanh"}, +{0, FMONADIC, 022, "ftentox"}, +{0, FMONADIC, 021, "ftwotox"}, -0, FSINCOS, 060, "fsincos", +{0, FSINCOS, 060, "fsincos"}, -0, FBCC, 001, "fbeq", -0, FBCC, 016, "fbne", -0, FBCC, 022, "fbgt", -0, FBCC, 035, "fbngt", -0, FBCC, 023, "fbge", -0, FBCC, 034, "fbnge", -0, FBCC, 024, "fblt", -0, FBCC, 033, "fbnlt", -0, FBCC, 025, "fble", -0, FBCC, 032, "fbnle", -0, FBCC, 026, "fbgl", -0, FBCC, 031, "fbngl", -0, FBCC, 027, "fbgle", -0, FBCC, 030, "fbngle", -0, FBCC, 002, "fbogt", -0, FBCC, 015, "fbule", -0, FBCC, 003, "fboge", -0, FBCC, 014, "fbult", -0, FBCC, 004, "fbolt", -0, FBCC, 013, "fbuge", -0, FBCC, 005, "fbole", -0, FBCC, 012, "fbugt", -0, FBCC, 006, "fbogl", -0, FBCC, 011, "fbueq", -0, FBCC, 007, "fbor", -0, FBCC, 010, "fbun", -0, FBCC, 000, "fbf", -0, FBCC, 017, "fbt", -0, FBCC, 020, "fbsf", -0, FBCC, 037, "fbst", -0, FBCC, 021, "fbseq", -0, FBCC, 036, "fbsne", +{0, FBCC, 001, "fbeq"}, +{0, FBCC, 016, "fbne"}, +{0, FBCC, 022, "fbgt"}, +{0, FBCC, 035, "fbngt"}, +{0, FBCC, 023, "fbge"}, +{0, FBCC, 034, "fbnge"}, +{0, FBCC, 024, "fblt"}, +{0, FBCC, 033, "fbnlt"}, +{0, FBCC, 025, "fble"}, +{0, FBCC, 032, "fbnle"}, +{0, FBCC, 026, "fbgl"}, +{0, FBCC, 031, "fbngl"}, +{0, FBCC, 027, "fbgle"}, +{0, FBCC, 030, "fbngle"}, +{0, FBCC, 002, "fbogt"}, +{0, FBCC, 015, "fbule"}, +{0, FBCC, 003, "fboge"}, +{0, FBCC, 014, "fbult"}, +{0, FBCC, 004, "fbolt"}, +{0, FBCC, 013, "fbuge"}, +{0, FBCC, 005, "fbole"}, +{0, FBCC, 012, "fbugt"}, +{0, FBCC, 006, "fbogl"}, +{0, FBCC, 011, "fbueq"}, +{0, FBCC, 007, "fbor"}, +{0, FBCC, 010, "fbun"}, +{0, FBCC, 000, "fbf"}, +{0, FBCC, 017, "fbt"}, +{0, FBCC, 020, "fbsf"}, +{0, FBCC, 037, "fbst"}, +{0, FBCC, 021, "fbseq"}, +{0, FBCC, 036, "fbsne"}, -0, FDBCC, 001, "fdbeq", -0, FDBCC, 016, "fdbne", -0, FDBCC, 022, "fdbgt", -0, FDBCC, 035, "fdbngt", -0, FDBCC, 023, "fdbge", -0, FDBCC, 034, "fdbnge", -0, FDBCC, 024, "fdblt", -0, FDBCC, 033, "fdbnlt", -0, FDBCC, 025, "fdble", -0, FDBCC, 032, "fdbnle", -0, FDBCC, 026, "fdbgl", -0, FDBCC, 031, "fdbngl", -0, FDBCC, 027, "fdbgle", -0, FDBCC, 030, "fdbngle", -0, FDBCC, 002, "fdbogt", -0, FDBCC, 015, "fdbule", -0, FDBCC, 003, "fdboge", -0, FDBCC, 014, "fdbult", -0, FDBCC, 004, "fdbolt", -0, FDBCC, 013, "fdbuge", -0, FDBCC, 005, "fdbole", -0, FDBCC, 012, "fdbugt", -0, FDBCC, 006, "fdbogl", -0, FDBCC, 011, "fdbueq", -0, FDBCC, 007, "fdbor", -0, FDBCC, 010, "fdbun", -0, FDBCC, 000, "fdbf", -0, FDBCC, 017, "fdbt", -0, FDBCC, 020, "fdbsf", -0, FDBCC, 037, "fdbst", -0, FDBCC, 021, "fdbseq", -0, FDBCC, 036, "fdbsne", +{0, FDBCC, 001, "fdbeq"}, +{0, FDBCC, 016, "fdbne"}, +{0, FDBCC, 022, "fdbgt"}, +{0, FDBCC, 035, "fdbngt"}, +{0, FDBCC, 023, "fdbge"}, +{0, FDBCC, 034, "fdbnge"}, +{0, FDBCC, 024, "fdblt"}, +{0, FDBCC, 033, "fdbnlt"}, +{0, FDBCC, 025, "fdble"}, +{0, FDBCC, 032, "fdbnle"}, +{0, FDBCC, 026, "fdbgl"}, +{0, FDBCC, 031, "fdbngl"}, +{0, FDBCC, 027, "fdbgle"}, +{0, FDBCC, 030, "fdbngle"}, +{0, FDBCC, 002, "fdbogt"}, +{0, FDBCC, 015, "fdbule"}, +{0, FDBCC, 003, "fdboge"}, +{0, FDBCC, 014, "fdbult"}, +{0, FDBCC, 004, "fdbolt"}, +{0, FDBCC, 013, "fdbuge"}, +{0, FDBCC, 005, "fdbole"}, +{0, FDBCC, 012, "fdbugt"}, +{0, FDBCC, 006, "fdbogl"}, +{0, FDBCC, 011, "fdbueq"}, +{0, FDBCC, 007, "fdbor"}, +{0, FDBCC, 010, "fdbun"}, +{0, FDBCC, 000, "fdbf"}, +{0, FDBCC, 017, "fdbt"}, +{0, FDBCC, 020, "fdbsf"}, +{0, FDBCC, 037, "fdbst"}, +{0, FDBCC, 021, "fdbseq"}, +{0, FDBCC, 036, "fdbsne"}, -0, FNOP, 0, "fnop", +{0, FNOP, 0, "fnop"}, -0, FSCC, 001, "fseq", -0, FSCC, 016, "fsne", -0, FSCC, 022, "fsgt", -0, FSCC, 035, "fsngt", -0, FSCC, 023, "fsge", -0, FSCC, 034, "fsnge", -0, FSCC, 024, "fslt", -0, FSCC, 033, "fsnlt", -0, FSCC, 025, "fsle", -0, FSCC, 032, "fsnle", -0, FSCC, 026, "fsgl", -0, FSCC, 031, "fsngl", -0, FSCC, 027, "fsgle", -0, FSCC, 030, "fsngle", -0, FSCC, 002, "fsogt", -0, FSCC, 015, "fsule", -0, FSCC, 003, "fsoge", -0, FSCC, 014, "fsult", -0, FSCC, 004, "fsolt", -0, FSCC, 013, "fsuge", -0, FSCC, 005, "fsole", -0, FSCC, 012, "fsugt", -0, FSCC, 006, "fsogl", -0, FSCC, 011, "fsueq", -0, FSCC, 007, "fsor", -0, FSCC, 010, "fsun", -0, FSCC, 000, "fsf", -0, FSCC, 017, "fst", -0, FSCC, 020, "fssf", -0, FSCC, 037, "fsst", -0, FSCC, 021, "fsseq", -0, FSCC, 036, "fssne", +{0, FSCC, 001, "fseq"}, +{0, FSCC, 016, "fsne"}, +{0, FSCC, 022, "fsgt"}, +{0, FSCC, 035, "fsngt"}, +{0, FSCC, 023, "fsge"}, +{0, FSCC, 034, "fsnge"}, +{0, FSCC, 024, "fslt"}, +{0, FSCC, 033, "fsnlt"}, +{0, FSCC, 025, "fsle"}, +{0, FSCC, 032, "fsnle"}, +{0, FSCC, 026, "fsgl"}, +{0, FSCC, 031, "fsngl"}, +{0, FSCC, 027, "fsgle"}, +{0, FSCC, 030, "fsngle"}, +{0, FSCC, 002, "fsogt"}, +{0, FSCC, 015, "fsule"}, +{0, FSCC, 003, "fsoge"}, +{0, FSCC, 014, "fsult"}, +{0, FSCC, 004, "fsolt"}, +{0, FSCC, 013, "fsuge"}, +{0, FSCC, 005, "fsole"}, +{0, FSCC, 012, "fsugt"}, +{0, FSCC, 006, "fsogl"}, +{0, FSCC, 011, "fsueq"}, +{0, FSCC, 007, "fsor"}, +{0, FSCC, 010, "fsun"}, +{0, FSCC, 000, "fsf"}, +{0, FSCC, 017, "fst"}, +{0, FSCC, 020, "fssf"}, +{0, FSCC, 037, "fsst"}, +{0, FSCC, 021, "fsseq"}, +{0, FSCC, 036, "fssne"}, -0, FTST, 0, "ftst", +{0, FTST, 0, "ftst"}, -0, FSAVRES, MEM|ALT|0430, "fsave", -0, FSAVRES, MEM|0540, "frestore", +{0, FSAVRES, MEM|ALT|0430, "fsave"}, +{0, FSAVRES, MEM|0540, "frestore"}, -0, FTRAPCC, 001, "ftrapeq", -0, FTRAPCC, 016, "ftrapne", -0, FTRAPCC, 022, "ftrapgt", -0, FTRAPCC, 035, "ftrapngt", -0, FTRAPCC, 023, "ftrapge", -0, FTRAPCC, 034, "ftrapnge", -0, FTRAPCC, 024, "ftraplt", -0, FTRAPCC, 033, "ftrapnlt", -0, FTRAPCC, 025, "ftraple", -0, FTRAPCC, 032, "ftrapnle", -0, FTRAPCC, 026, "ftrapgl", -0, FTRAPCC, 031, "ftrapngl", -0, FTRAPCC, 027, "ftrapgle", -0, FTRAPCC, 030, "ftrapngle", -0, FTRAPCC, 002, "ftrapogt", -0, FTRAPCC, 015, "ftrapule", -0, FTRAPCC, 003, "ftrapoge", -0, FTRAPCC, 014, "ftrapult", -0, FTRAPCC, 004, "ftrapolt", -0, FTRAPCC, 013, "ftrapuge", -0, FTRAPCC, 005, "ftrapole", -0, FTRAPCC, 012, "ftrapugt", -0, FTRAPCC, 006, "ftrapogl", -0, FTRAPCC, 011, "ftrapueq", -0, FTRAPCC, 007, "ftrapor", -0, FTRAPCC, 010, "ftrapun", -0, FTRAPCC, 000, "ftrapf", -0, FTRAPCC, 017, "ftrapt", -0, FTRAPCC, 020, "ftrapsf", -0, FTRAPCC, 037, "ftrapst", -0, FTRAPCC, 021, "ftrapseq", -0, FTRAPCC, 036, "ftrapsne", +{0, FTRAPCC, 001, "ftrapeq"}, +{0, FTRAPCC, 016, "ftrapne"}, +{0, FTRAPCC, 022, "ftrapgt"}, +{0, FTRAPCC, 035, "ftrapngt"}, +{0, FTRAPCC, 023, "ftrapge"}, +{0, FTRAPCC, 034, "ftrapnge"}, +{0, FTRAPCC, 024, "ftraplt"}, +{0, FTRAPCC, 033, "ftrapnlt"}, +{0, FTRAPCC, 025, "ftraple"}, +{0, FTRAPCC, 032, "ftrapnle"}, +{0, FTRAPCC, 026, "ftrapgl"}, +{0, FTRAPCC, 031, "ftrapngl"}, +{0, FTRAPCC, 027, "ftrapgle"}, +{0, FTRAPCC, 030, "ftrapngle"}, +{0, FTRAPCC, 002, "ftrapogt"}, +{0, FTRAPCC, 015, "ftrapule"}, +{0, FTRAPCC, 003, "ftrapoge"}, +{0, FTRAPCC, 014, "ftrapult"}, +{0, FTRAPCC, 004, "ftrapolt"}, +{0, FTRAPCC, 013, "ftrapuge"}, +{0, FTRAPCC, 005, "ftrapole"}, +{0, FTRAPCC, 012, "ftrapugt"}, +{0, FTRAPCC, 006, "ftrapogl"}, +{0, FTRAPCC, 011, "ftrapueq"}, +{0, FTRAPCC, 007, "ftrapor"}, +{0, FTRAPCC, 010, "ftrapun"}, +{0, FTRAPCC, 000, "ftrapf"}, +{0, FTRAPCC, 017, "ftrapt"}, +{0, FTRAPCC, 020, "ftrapsf"}, +{0, FTRAPCC, 037, "ftrapst"}, +{0, FTRAPCC, 021, "ftrapseq"}, +{0, FTRAPCC, 036, "ftrapsne"}, diff --git a/mach/m68k2/as/mach3.c b/mach/m68k2/as/mach3.c index 81b4d270f..dc5bc503c 100644 --- a/mach/m68k2/as/mach3.c +++ b/mach/m68k2/as/mach3.c @@ -8,382 +8,382 @@ * Motorola 68000/68010 keywords */ -0, EXTERN, 0, ".globl", +{0, EXTERN, 0, ".globl"}, -0, SIZE, SIZE_B, ".b", -0, SIZE, SIZE_W, ".w", -0, SIZE, SIZE_L, ".l", +{0, SIZE, SIZE_B, ".b"}, +{0, SIZE, SIZE_W, ".w"}, +{0, SIZE, SIZE_L, ".l"}, -0, DREG, 00, "d0", -0, DREG, 01, "d1", -0, DREG, 02, "d2", -0, DREG, 03, "d3", -0, DREG, 04, "d4", -0, DREG, 05, "d5", -0, DREG, 06, "d6", -0, DREG, 07, "d7", +{0, DREG, 00, "d0"}, +{0, DREG, 01, "d1"}, +{0, DREG, 02, "d2"}, +{0, DREG, 03, "d3"}, +{0, DREG, 04, "d4"}, +{0, DREG, 05, "d5"}, +{0, DREG, 06, "d6"}, +{0, DREG, 07, "d7"}, -0, AREG, 00, "a0", -0, AREG, 01, "a1", -0, AREG, 02, "a2", -0, AREG, 03, "a3", -0, AREG, 04, "a4", -0, AREG, 05, "a5", -0, AREG, 06, "a6", -0, AREG, 07, "a7", -0, AREG, 07, "sp", +{0, AREG, 00, "a0"}, +{0, AREG, 01, "a1"}, +{0, AREG, 02, "a2"}, +{0, AREG, 03, "a3"}, +{0, AREG, 04, "a4"}, +{0, AREG, 05, "a5"}, +{0, AREG, 06, "a6"}, +{0, AREG, 07, "a7"}, +{0, AREG, 07, "sp"}, -0, PC, 8, "pc", +{0, PC, 8, "pc"}, -0, MODEL, 0, ".68000", -0, MODEL, 1, ".68010", +{0, MODEL, 0, ".68000"}, +{0, MODEL, 1, ".68010"}, -0, CREG, 04001, "vbr", -0, CREG, 0, "sfc", -0, CREG, 00001, "dfc", +{0, CREG, 04001, "vbr"}, +{0, CREG, 0, "sfc"}, +{0, CREG, 00001, "dfc"}, -0, SPEC, 075, "usp", -0, SPEC, 076, "ccr", -0, SPEC, 077, "sr", +{0, SPEC, 075, "usp"}, +{0, SPEC, 076, "ccr"}, +{0, SPEC, 077, "sr"}, -0, ABCD, 0140400, "abcd", -0, ABCD, 0100400, "sbcd", +{0, ABCD, 0140400, "abcd"}, +{0, ABCD, 0100400, "sbcd"}, -0, ADDX, 0150400, "addx", -0, ADDX, 0110400, "subx", +{0, ADDX, 0150400, "addx"}, +{0, ADDX, 0110400, "subx"}, -0, ADD, 0153300, "add", -0, ADD, 0112700, "sub", +{0, ADD, 0153300, "add"}, +{0, ADD, 0112700, "sub"}, -0, AND, 0141000, "and", -0, AND, 0135000, "eor", -0, AND, 0100000, "or", +{0, AND, 0141000, "and"}, +{0, AND, 0135000, "eor"}, +{0, AND, 0100000, "or"}, -0, BITOP, 0000, "btst", -0, BITOP, 0100, "bchg", -0, BITOP, 0200, "bclr", -0, BITOP, 0300, "bset", +{0, BITOP, 0000, "btst"}, +{0, BITOP, 0100, "bchg"}, +{0, BITOP, 0200, "bclr"}, +{0, BITOP, 0300, "bset"}, -0, SHIFT, 0160340, "asr", -0, SHIFT, 0160740, "asl", -0, SHIFT, 0161350, "lsr", -0, SHIFT, 0161750, "lsl", -0, SHIFT, 0162360, "roxr", -0, SHIFT, 0162760, "roxl", -0, SHIFT, 0163370, "ror", -0, SHIFT, 0163770, "rol", +{0, SHIFT, 0160340, "asr"}, +{0, SHIFT, 0160740, "asl"}, +{0, SHIFT, 0161350, "lsr"}, +{0, SHIFT, 0161750, "lsl"}, +{0, SHIFT, 0162360, "roxr"}, +{0, SHIFT, 0162760, "roxl"}, +{0, SHIFT, 0163370, "ror"}, +{0, SHIFT, 0163770, "rol"}, -0, SZ_EA, 041000|DTA|ALT, "clr", -0, SZ_EA, 042000|DTA|ALT, "neg", -0, SZ_EA, 040000|DTA|ALT, "negx", -0, SZ_EA, 043000|DTA|ALT, "not", -0, SZ_EA, 045000|DTA|ALT, "tst", +{0, SZ_EA, 041000|DTA|ALT, "clr"}, +{0, SZ_EA, 042000|DTA|ALT, "neg"}, +{0, SZ_EA, 040000|DTA|ALT, "negx"}, +{0, SZ_EA, 043000|DTA|ALT, "not"}, +{0, SZ_EA, 045000|DTA|ALT, "tst"}, -0, OP_EA, 044000|DTA|ALT, "nbcd", -0, OP_EA, 045300|DTA|ALT, "tas", -0, OP_EA, 047200|CTR, "jsr", -0, OP_EA, 047300|CTR, "jmp", -0, OP_EA, 044100|CTR, "pea", +{0, OP_EA, 044000|DTA|ALT, "nbcd"}, +{0, OP_EA, 045300|DTA|ALT, "tas"}, +{0, OP_EA, 047200|CTR, "jsr"}, +{0, OP_EA, 047300|CTR, "jmp"}, +{0, OP_EA, 044100|CTR, "pea"}, -0, OP_EA, 050300, "st", -0, OP_EA, 050700, "sf", -0, OP_EA, 051300, "shi", -0, OP_EA, 051700, "sls", -0, OP_EA, 052300, "scc", -0, OP_EA, 052700, "scs", -0, OP_EA, 053300, "sne", -0, OP_EA, 053700, "seq", -0, OP_EA, 054300, "svc", -0, OP_EA, 054700, "svs", -0, OP_EA, 055300, "spl", -0, OP_EA, 055700, "smi", -0, OP_EA, 056300, "sge", -0, OP_EA, 056700, "slt", -0, OP_EA, 057300, "sgt", -0, OP_EA, 057700, "sle", +{0, OP_EA, 050300, "st"}, +{0, OP_EA, 050700, "sf"}, +{0, OP_EA, 051300, "shi"}, +{0, OP_EA, 051700, "sls"}, +{0, OP_EA, 052300, "scc"}, +{0, OP_EA, 052700, "scs"}, +{0, OP_EA, 053300, "sne"}, +{0, OP_EA, 053700, "seq"}, +{0, OP_EA, 054300, "svc"}, +{0, OP_EA, 054700, "svs"}, +{0, OP_EA, 055300, "spl"}, +{0, OP_EA, 055700, "smi"}, +{0, OP_EA, 056300, "sge"}, +{0, OP_EA, 056700, "slt"}, +{0, OP_EA, 057300, "sgt"}, +{0, OP_EA, 057700, "sle"}, -0, OP_NOOP, 047160, "reset", -0, OP_NOOP, 047161, "nop", -0, OP_NOOP, 047163, "rte", -0, OP_NOOP, 047165, "rts", -0, OP_NOOP, 047166, "trapv", -0, OP_NOOP, 047167, "rtr", -0, OP_NOOP, 045374, "illegal", +{0, OP_NOOP, 047160, "reset"}, +{0, OP_NOOP, 047161, "nop"}, +{0, OP_NOOP, 047163, "rte"}, +{0, OP_NOOP, 047165, "rts"}, +{0, OP_NOOP, 047166, "trapv"}, +{0, OP_NOOP, 047167, "rtr"}, +{0, OP_NOOP, 045374, "illegal"}, -0, OP_EA_D, 040600, "chk", -0, OP_EA_D, 0100300, "divu", -0, OP_EA_D, 0100700, "divs", -0, OP_EA_D, 0140300, "mulu", -0, OP_EA_D, 0140700, "muls", +{0, OP_EA_D, 040600, "chk"}, +{0, OP_EA_D, 0100300, "divu"}, +{0, OP_EA_D, 0100700, "divs"}, +{0, OP_EA_D, 0140300, "mulu"}, +{0, OP_EA_D, 0140700, "muls"}, -0, BR, 060000, "bra", -0, BR, 060400, "bsr", -0, BR, 061000, "bhi", -0, BR, 061400, "bls", -0, BR, 062000, "bcc", -0, BR, 062400, "bcs", -0, BR, 063000, "bne", -0, BR, 063400, "beq", -0, BR, 064000, "bvc", -0, BR, 064400, "bvs", -0, BR, 065000, "bpl", -0, BR, 065400, "bmi", -0, BR, 066000, "bge", -0, BR, 066400, "blt", -0, BR, 067000, "bgt", -0, BR, 067400, "ble", +{0, BR, 060000, "bra"}, +{0, BR, 060400, "bsr"}, +{0, BR, 061000, "bhi"}, +{0, BR, 061400, "bls"}, +{0, BR, 062000, "bcc"}, +{0, BR, 062400, "bcs"}, +{0, BR, 063000, "bne"}, +{0, BR, 063400, "beq"}, +{0, BR, 064000, "bvc"}, +{0, BR, 064400, "bvs"}, +{0, BR, 065000, "bpl"}, +{0, BR, 065400, "bmi"}, +{0, BR, 066000, "bge"}, +{0, BR, 066400, "blt"}, +{0, BR, 067000, "bgt"}, +{0, BR, 067400, "ble"}, -0, DBR, 050310, "dbt", -0, DBR, 050710, "dbf", -0, DBR, 050710, "dbra", -0, DBR, 051310, "dbhi", -0, DBR, 051710, "dbls", -0, DBR, 052310, "dbcc", -0, DBR, 052710, "dbcs", -0, DBR, 053310, "dbne", -0, DBR, 053710, "dbeq", -0, DBR, 054310, "dbvc", -0, DBR, 054710, "dbvs", -0, DBR, 055310, "dbpl", -0, DBR, 055710, "dbmi", -0, DBR, 056310, "dbge", -0, DBR, 056710, "dblt", -0, DBR, 057310, "dbgt", -0, DBR, 057710, "dble", +{0, DBR, 050310, "dbt"}, +{0, DBR, 050710, "dbf"}, +{0, DBR, 050710, "dbra"}, +{0, DBR, 051310, "dbhi"}, +{0, DBR, 051710, "dbls"}, +{0, DBR, 052310, "dbcc"}, +{0, DBR, 052710, "dbcs"}, +{0, DBR, 053310, "dbne"}, +{0, DBR, 053710, "dbeq"}, +{0, DBR, 054310, "dbvc"}, +{0, DBR, 054710, "dbvs"}, +{0, DBR, 055310, "dbpl"}, +{0, DBR, 055710, "dbmi"}, +{0, DBR, 056310, "dbge"}, +{0, DBR, 056710, "dblt"}, +{0, DBR, 057310, "dbgt"}, +{0, DBR, 057710, "dble"}, -0, CMP, 0, "cmp", +{0, CMP, 0, "cmp"}, -0, MOVE, 0, "move", -0, MOVEP, 0, "movep", -0, MOVEM, 0, "movem", -0, MOVES, 0, "moves", -0, MOVEC, 0, "movec", +{0, MOVE, 0, "move"}, +{0, MOVEP, 0, "movep"}, +{0, MOVEM, 0, "movem"}, +{0, MOVES, 0, "moves"}, +{0, MOVEC, 0, "movec"}, -0, SWAP, 0, "swap", +{0, SWAP, 0, "swap"}, -0, LINK, 0, "link", +{0, LINK, 0, "link"}, -0, UNLK, 0, "unlk", +{0, UNLK, 0, "unlk"}, -0, TRAP, 0, "trap", +{0, TRAP, 0, "trap"}, -0, STOP, 047162, "stop", +{0, STOP, 047162, "stop"}, -0, EXG, 0, "exg", +{0, EXG, 0, "exg"}, -0, OP_EXT, 0, "ext", +{0, OP_EXT, 0, "ext"}, -0, LEA, 0, "lea", +{0, LEA, 0, "lea"}, -0, RTD, 0, "rtd", +{0, RTD, 0, "rtd"}, /* floating point coprocessor ... */ -0, FSIZE, FSIZE_S, ".s", -0, FSIZE, FSIZE_X, ".x", -0, FSIZE, FSIZE_P, ".p", -0, FSIZE, FSIZE_D, ".d", +{0, FSIZE, FSIZE_S, ".s"}, +{0, FSIZE, FSIZE_X, ".x"}, +{0, FSIZE, FSIZE_P, ".p"}, +{0, FSIZE, FSIZE_D, ".d"}, -0, FPREG, 0, "fp0", -0, FPREG, 1, "fp1", -0, FPREG, 2, "fp2", -0, FPREG, 3, "fp3", -0, FPREG, 4, "fp4", -0, FPREG, 5, "fp5", -0, FPREG, 6, "fp6", -0, FPREG, 7, "fp7", +{0, FPREG, 0, "fp0"}, +{0, FPREG, 1, "fp1"}, +{0, FPREG, 2, "fp2"}, +{0, FPREG, 3, "fp3"}, +{0, FPREG, 4, "fp4"}, +{0, FPREG, 5, "fp5"}, +{0, FPREG, 6, "fp6"}, +{0, FPREG, 7, "fp7"}, -0, FPCR, 1, "fpiar", -0, FPCR, 2, "fpsr", -0, FPCR, 4, "fpcr", +{0, FPCR, 1, "fpiar"}, +{0, FPCR, 2, "fpsr"}, +{0, FPCR, 4, "fpcr"}, -0, FMOVE, 0, "fmove", -0, FMOVECR, 0, "fmovecr", -0, FMOVEM, 0, "fmovem", +{0, FMOVE, 0, "fmove"}, +{0, FMOVECR, 0, "fmovecr"}, +{0, FMOVEM, 0, "fmovem"}, -0, FDYADIC, 042, "fadd", -0, FDYADIC, 070, "fcmp", -0, FDYADIC, 040, "fdiv", -0, FDYADIC, 041, "fmod", -0, FDYADIC, 043, "fmul", -0, FDYADIC, 045, "frem", -0, FDYADIC, 046, "fscale", -0, FDYADIC, 044, "fsgldiv", -0, FDYADIC, 047, "fsglmul", -0, FDYADIC, 050, "fsub", +{0, FDYADIC, 042, "fadd"}, +{0, FDYADIC, 070, "fcmp"}, +{0, FDYADIC, 040, "fdiv"}, +{0, FDYADIC, 041, "fmod"}, +{0, FDYADIC, 043, "fmul"}, +{0, FDYADIC, 045, "frem"}, +{0, FDYADIC, 046, "fscale"}, +{0, FDYADIC, 044, "fsgldiv"}, +{0, FDYADIC, 047, "fsglmul"}, +{0, FDYADIC, 050, "fsub"}, -0, FMONADIC, 030, "fabs", -0, FMONADIC, 034, "facos", -0, FMONADIC, 014, "fasin", -0, FMONADIC, 012, "fatan", -0, FMONADIC, 015, "fatanh", -0, FMONADIC, 035, "fcos", -0, FMONADIC, 031, "fcosh", -0, FMONADIC, 020, "fetox", -0, FMONADIC, 010, "fetoxm1", -0, FMONADIC, 036, "fgetexp", -0, FMONADIC, 037, "fgetman", -0, FMONADIC, 001, "fint", -0, FMONADIC, 003, "fintrz", -0, FMONADIC, 024, "flogn", -0, FMONADIC, 006, "flognp1", -0, FMONADIC, 025, "flog10", -0, FMONADIC, 026, "flog2", -0, FMONADIC, 032, "fneg", -0, FMONADIC, 016, "fsin", -0, FMONADIC, 002, "fsinh", -0, FMONADIC, 004, "fsqrt", -0, FMONADIC, 017, "ftan", -0, FMONADIC, 011, "ftanh", -0, FMONADIC, 022, "ftentox", -0, FMONADIC, 021, "ftwotox", +{0, FMONADIC, 030, "fabs"}, +{0, FMONADIC, 034, "facos"}, +{0, FMONADIC, 014, "fasin"}, +{0, FMONADIC, 012, "fatan"}, +{0, FMONADIC, 015, "fatanh"}, +{0, FMONADIC, 035, "fcos"}, +{0, FMONADIC, 031, "fcosh"}, +{0, FMONADIC, 020, "fetox"}, +{0, FMONADIC, 010, "fetoxm1"}, +{0, FMONADIC, 036, "fgetexp"}, +{0, FMONADIC, 037, "fgetman"}, +{0, FMONADIC, 001, "fint"}, +{0, FMONADIC, 003, "fintrz"}, +{0, FMONADIC, 024, "flogn"}, +{0, FMONADIC, 006, "flognp1"}, +{0, FMONADIC, 025, "flog10"}, +{0, FMONADIC, 026, "flog2"}, +{0, FMONADIC, 032, "fneg"}, +{0, FMONADIC, 016, "fsin"}, +{0, FMONADIC, 002, "fsinh"}, +{0, FMONADIC, 004, "fsqrt"}, +{0, FMONADIC, 017, "ftan"}, +{0, FMONADIC, 011, "ftanh"}, +{0, FMONADIC, 022, "ftentox"}, +{0, FMONADIC, 021, "ftwotox"}, -0, FSINCOS, 060, "fsincos", +{0, FSINCOS, 060, "fsincos"}, -0, FBCC, 001, "fbeq", -0, FBCC, 016, "fbne", -0, FBCC, 022, "fbgt", -0, FBCC, 035, "fbngt", -0, FBCC, 023, "fbge", -0, FBCC, 034, "fbnge", -0, FBCC, 024, "fblt", -0, FBCC, 033, "fbnlt", -0, FBCC, 025, "fble", -0, FBCC, 032, "fbnle", -0, FBCC, 026, "fbgl", -0, FBCC, 031, "fbngl", -0, FBCC, 027, "fbgle", -0, FBCC, 030, "fbngle", -0, FBCC, 002, "fbogt", -0, FBCC, 015, "fbule", -0, FBCC, 003, "fboge", -0, FBCC, 014, "fbult", -0, FBCC, 004, "fbolt", -0, FBCC, 013, "fbuge", -0, FBCC, 005, "fbole", -0, FBCC, 012, "fbugt", -0, FBCC, 006, "fbogl", -0, FBCC, 011, "fbueq", -0, FBCC, 007, "fbor", -0, FBCC, 010, "fbun", -0, FBCC, 000, "fbf", -0, FBCC, 017, "fbt", -0, FBCC, 020, "fbsf", -0, FBCC, 037, "fbst", -0, FBCC, 021, "fbseq", -0, FBCC, 036, "fbsne", +{0, FBCC, 001, "fbeq"}, +{0, FBCC, 016, "fbne"}, +{0, FBCC, 022, "fbgt"}, +{0, FBCC, 035, "fbngt"}, +{0, FBCC, 023, "fbge"}, +{0, FBCC, 034, "fbnge"}, +{0, FBCC, 024, "fblt"}, +{0, FBCC, 033, "fbnlt"}, +{0, FBCC, 025, "fble"}, +{0, FBCC, 032, "fbnle"}, +{0, FBCC, 026, "fbgl"}, +{0, FBCC, 031, "fbngl"}, +{0, FBCC, 027, "fbgle"}, +{0, FBCC, 030, "fbngle"}, +{0, FBCC, 002, "fbogt"}, +{0, FBCC, 015, "fbule"}, +{0, FBCC, 003, "fboge"}, +{0, FBCC, 014, "fbult"}, +{0, FBCC, 004, "fbolt"}, +{0, FBCC, 013, "fbuge"}, +{0, FBCC, 005, "fbole"}, +{0, FBCC, 012, "fbugt"}, +{0, FBCC, 006, "fbogl"}, +{0, FBCC, 011, "fbueq"}, +{0, FBCC, 007, "fbor"}, +{0, FBCC, 010, "fbun"}, +{0, FBCC, 000, "fbf"}, +{0, FBCC, 017, "fbt"}, +{0, FBCC, 020, "fbsf"}, +{0, FBCC, 037, "fbst"}, +{0, FBCC, 021, "fbseq"}, +{0, FBCC, 036, "fbsne"}, -0, FDBCC, 001, "fdbeq", -0, FDBCC, 016, "fdbne", -0, FDBCC, 022, "fdbgt", -0, FDBCC, 035, "fdbngt", -0, FDBCC, 023, "fdbge", -0, FDBCC, 034, "fdbnge", -0, FDBCC, 024, "fdblt", -0, FDBCC, 033, "fdbnlt", -0, FDBCC, 025, "fdble", -0, FDBCC, 032, "fdbnle", -0, FDBCC, 026, "fdbgl", -0, FDBCC, 031, "fdbngl", -0, FDBCC, 027, "fdbgle", -0, FDBCC, 030, "fdbngle", -0, FDBCC, 002, "fdbogt", -0, FDBCC, 015, "fdbule", -0, FDBCC, 003, "fdboge", -0, FDBCC, 014, "fdbult", -0, FDBCC, 004, "fdbolt", -0, FDBCC, 013, "fdbuge", -0, FDBCC, 005, "fdbole", -0, FDBCC, 012, "fdbugt", -0, FDBCC, 006, "fdbogl", -0, FDBCC, 011, "fdbueq", -0, FDBCC, 007, "fdbor", -0, FDBCC, 010, "fdbun", -0, FDBCC, 000, "fdbf", -0, FDBCC, 017, "fdbt", -0, FDBCC, 020, "fdbsf", -0, FDBCC, 037, "fdbst", -0, FDBCC, 021, "fdbseq", -0, FDBCC, 036, "fdbsne", +{0, FDBCC, 001, "fdbeq"}, +{0, FDBCC, 016, "fdbne"}, +{0, FDBCC, 022, "fdbgt"}, +{0, FDBCC, 035, "fdbngt"}, +{0, FDBCC, 023, "fdbge"}, +{0, FDBCC, 034, "fdbnge"}, +{0, FDBCC, 024, "fdblt"}, +{0, FDBCC, 033, "fdbnlt"}, +{0, FDBCC, 025, "fdble"}, +{0, FDBCC, 032, "fdbnle"}, +{0, FDBCC, 026, "fdbgl"}, +{0, FDBCC, 031, "fdbngl"}, +{0, FDBCC, 027, "fdbgle"}, +{0, FDBCC, 030, "fdbngle"}, +{0, FDBCC, 002, "fdbogt"}, +{0, FDBCC, 015, "fdbule"}, +{0, FDBCC, 003, "fdboge"}, +{0, FDBCC, 014, "fdbult"}, +{0, FDBCC, 004, "fdbolt"}, +{0, FDBCC, 013, "fdbuge"}, +{0, FDBCC, 005, "fdbole"}, +{0, FDBCC, 012, "fdbugt"}, +{0, FDBCC, 006, "fdbogl"}, +{0, FDBCC, 011, "fdbueq"}, +{0, FDBCC, 007, "fdbor"}, +{0, FDBCC, 010, "fdbun"}, +{0, FDBCC, 000, "fdbf"}, +{0, FDBCC, 017, "fdbt"}, +{0, FDBCC, 020, "fdbsf"}, +{0, FDBCC, 037, "fdbst"}, +{0, FDBCC, 021, "fdbseq"}, +{0, FDBCC, 036, "fdbsne"}, -0, FNOP, 0, "fnop", +{0, FNOP, 0, "fnop"}, -0, FSCC, 001, "fseq", -0, FSCC, 016, "fsne", -0, FSCC, 022, "fsgt", -0, FSCC, 035, "fsngt", -0, FSCC, 023, "fsge", -0, FSCC, 034, "fsnge", -0, FSCC, 024, "fslt", -0, FSCC, 033, "fsnlt", -0, FSCC, 025, "fsle", -0, FSCC, 032, "fsnle", -0, FSCC, 026, "fsgl", -0, FSCC, 031, "fsngl", -0, FSCC, 027, "fsgle", -0, FSCC, 030, "fsngle", -0, FSCC, 002, "fsogt", -0, FSCC, 015, "fsule", -0, FSCC, 003, "fsoge", -0, FSCC, 014, "fsult", -0, FSCC, 004, "fsolt", -0, FSCC, 013, "fsuge", -0, FSCC, 005, "fsole", -0, FSCC, 012, "fsugt", -0, FSCC, 006, "fsogl", -0, FSCC, 011, "fsueq", -0, FSCC, 007, "fsor", -0, FSCC, 010, "fsun", -0, FSCC, 000, "fsf", -0, FSCC, 017, "fst", -0, FSCC, 020, "fssf", -0, FSCC, 037, "fsst", -0, FSCC, 021, "fsseq", -0, FSCC, 036, "fssne", +{0, FSCC, 001, "fseq"}, +{0, FSCC, 016, "fsne"}, +{0, FSCC, 022, "fsgt"}, +{0, FSCC, 035, "fsngt"}, +{0, FSCC, 023, "fsge"}, +{0, FSCC, 034, "fsnge"}, +{0, FSCC, 024, "fslt"}, +{0, FSCC, 033, "fsnlt"}, +{0, FSCC, 025, "fsle"}, +{0, FSCC, 032, "fsnle"}, +{0, FSCC, 026, "fsgl"}, +{0, FSCC, 031, "fsngl"}, +{0, FSCC, 027, "fsgle"}, +{0, FSCC, 030, "fsngle"}, +{0, FSCC, 002, "fsogt"}, +{0, FSCC, 015, "fsule"}, +{0, FSCC, 003, "fsoge"}, +{0, FSCC, 014, "fsult"}, +{0, FSCC, 004, "fsolt"}, +{0, FSCC, 013, "fsuge"}, +{0, FSCC, 005, "fsole"}, +{0, FSCC, 012, "fsugt"}, +{0, FSCC, 006, "fsogl"}, +{0, FSCC, 011, "fsueq"}, +{0, FSCC, 007, "fsor"}, +{0, FSCC, 010, "fsun"}, +{0, FSCC, 000, "fsf"}, +{0, FSCC, 017, "fst"}, +{0, FSCC, 020, "fssf"}, +{0, FSCC, 037, "fsst"}, +{0, FSCC, 021, "fsseq"}, +{0, FSCC, 036, "fssne"}, -0, FTST, 0, "ftst", +{0, FTST, 0, "ftst"}, -0, FSAVRES, MEM|ALT|0430, "fsave", -0, FSAVRES, MEM|0540, "frestore", +{0, FSAVRES, MEM|ALT|0430, "fsave"}, +{0, FSAVRES, MEM|0540, "frestore"}, -0, FTRAPCC, 001, "ftrapeq", -0, FTRAPCC, 016, "ftrapne", -0, FTRAPCC, 022, "ftrapgt", -0, FTRAPCC, 035, "ftrapngt", -0, FTRAPCC, 023, "ftrapge", -0, FTRAPCC, 034, "ftrapnge", -0, FTRAPCC, 024, "ftraplt", -0, FTRAPCC, 033, "ftrapnlt", -0, FTRAPCC, 025, "ftraple", -0, FTRAPCC, 032, "ftrapnle", -0, FTRAPCC, 026, "ftrapgl", -0, FTRAPCC, 031, "ftrapngl", -0, FTRAPCC, 027, "ftrapgle", -0, FTRAPCC, 030, "ftrapngle", -0, FTRAPCC, 002, "ftrapogt", -0, FTRAPCC, 015, "ftrapule", -0, FTRAPCC, 003, "ftrapoge", -0, FTRAPCC, 014, "ftrapult", -0, FTRAPCC, 004, "ftrapolt", -0, FTRAPCC, 013, "ftrapuge", -0, FTRAPCC, 005, "ftrapole", -0, FTRAPCC, 012, "ftrapugt", -0, FTRAPCC, 006, "ftrapogl", -0, FTRAPCC, 011, "ftrapueq", -0, FTRAPCC, 007, "ftrapor", -0, FTRAPCC, 010, "ftrapun", -0, FTRAPCC, 000, "ftrapf", -0, FTRAPCC, 017, "ftrapt", -0, FTRAPCC, 020, "ftrapsf", -0, FTRAPCC, 037, "ftrapst", -0, FTRAPCC, 021, "ftrapseq", -0, FTRAPCC, 036, "ftrapsne", +{0, FTRAPCC, 001, "ftrapeq"}, +{0, FTRAPCC, 016, "ftrapne"}, +{0, FTRAPCC, 022, "ftrapgt"}, +{0, FTRAPCC, 035, "ftrapngt"}, +{0, FTRAPCC, 023, "ftrapge"}, +{0, FTRAPCC, 034, "ftrapnge"}, +{0, FTRAPCC, 024, "ftraplt"}, +{0, FTRAPCC, 033, "ftrapnlt"}, +{0, FTRAPCC, 025, "ftraple"}, +{0, FTRAPCC, 032, "ftrapnle"}, +{0, FTRAPCC, 026, "ftrapgl"}, +{0, FTRAPCC, 031, "ftrapngl"}, +{0, FTRAPCC, 027, "ftrapgle"}, +{0, FTRAPCC, 030, "ftrapngle"}, +{0, FTRAPCC, 002, "ftrapogt"}, +{0, FTRAPCC, 015, "ftrapule"}, +{0, FTRAPCC, 003, "ftrapoge"}, +{0, FTRAPCC, 014, "ftrapult"}, +{0, FTRAPCC, 004, "ftrapolt"}, +{0, FTRAPCC, 013, "ftrapuge"}, +{0, FTRAPCC, 005, "ftrapole"}, +{0, FTRAPCC, 012, "ftrapugt"}, +{0, FTRAPCC, 006, "ftrapogl"}, +{0, FTRAPCC, 011, "ftrapueq"}, +{0, FTRAPCC, 007, "ftrapor"}, +{0, FTRAPCC, 010, "ftrapun"}, +{0, FTRAPCC, 000, "ftrapf"}, +{0, FTRAPCC, 017, "ftrapt"}, +{0, FTRAPCC, 020, "ftrapsf"}, +{0, FTRAPCC, 037, "ftrapst"}, +{0, FTRAPCC, 021, "ftrapseq"}, +{0, FTRAPCC, 036, "ftrapsne"}, -0, CP, 00000, "c0", -0, CP, 01000, "c1", -0, CP, 02000, "c2", -0, CP, 03000, "c3", -0, CP, 04000, "c4", -0, CP, 05000, "c5", -0, CP, 06000, "c6", -0, CP, 07000, "c7", +{0, CP, 00000, "c0"}, +{0, CP, 01000, "c1"}, +{0, CP, 02000, "c2"}, +{0, CP, 03000, "c3"}, +{0, CP, 04000, "c4"}, +{0, CP, 05000, "c5"}, +{0, CP, 06000, "c6"}, +{0, CP, 07000, "c7"}, diff --git a/mach/ns/as/mach3.c b/mach/ns/as/mach3.c index 4b072ad8b..b4b5435f7 100644 --- a/mach/ns/as/mach3.c +++ b/mach/ns/as/mach3.c @@ -9,449 +9,449 @@ */ /* Registers */ -0, REG, 0, "r0", -0, REG, 1, "r1", -0, REG, 2, "r2", -0, REG, 3, "r3", -0, REG, 4, "r4", -0, REG, 5, "r5", -0, REG, 6, "r6", -0, REG, 7, "r7", -0, FREG, 0, "f0", -0, FREG, 1, "f1", -0, FREG, 2, "f2", -0, FREG, 3, "f3", -0, FREG, 4, "f4", -0, FREG, 5, "f5", -0, FREG, 6, "f6", -0, FREG, 7, "f7", +{0, REG, 0, "r0"}, +{0, REG, 1, "r1"}, +{0, REG, 2, "r2"}, +{0, REG, 3, "r3"}, +{0, REG, 4, "r4"}, +{0, REG, 5, "r5"}, +{0, REG, 6, "r6"}, +{0, REG, 7, "r7"}, +{0, FREG, 0, "f0"}, +{0, FREG, 1, "f1"}, +{0, FREG, 2, "f2"}, +{0, FREG, 3, "f3"}, +{0, FREG, 4, "f4"}, +{0, FREG, 5, "f5"}, +{0, FREG, 6, "f6"}, +{0, FREG, 7, "f7"}, /* CPU dedicated registers */ -0, AREG, 0x0, "us", -0, AREG, 0x8, "fp", -0, AREG, 0x9, "sp", -0, AREG, 0xA, "sb", -0, AREG, 0xD, "psr", -0, AREG, 0xE, "intbase", -0, AREG, 0xF, "mod", +{0, AREG, 0x0, "us"}, +{0, AREG, 0x8, "fp"}, +{0, AREG, 0x9, "sp"}, +{0, AREG, 0xA, "sb"}, +{0, AREG, 0xD, "psr"}, +{0, AREG, 0xE, "intbase"}, +{0, AREG, 0xF, "mod"}, /* Tokens dedicated to addressing modes */ -0, TOS, 0x17, "tos", -0, EXTERNAL, 0x16, "external", -0, PC, 0, "pc", -0, INDICATOR, 'b', "b", -0, INDICATOR, 'c', "c", -0, INDICATOR, 'd', "d", -0, INDICATOR, 'f', "f", -0, INDICATOR, 'i', "i", -0, INDICATOR, 'm', "m", -0, INDICATOR, 'q', "q", -0, INDICATOR, 'u', "u", -0, INDICATOR, 'w', "w", +{0, TOS, 0x17, "tos"}, +{0, EXTERNAL, 0x16, "external"}, +{0, PC, 0, "pc"}, +{0, INDICATOR, 'b', "b"}, +{0, INDICATOR, 'c', "c"}, +{0, INDICATOR, 'd', "d"}, +{0, INDICATOR, 'f', "f"}, +{0, INDICATOR, 'i', "i"}, +{0, INDICATOR, 'm', "m"}, +{0, INDICATOR, 'q', "q"}, +{0, INDICATOR, 'u', "u"}, +{0, INDICATOR, 'w', "w"}, /* Memory management registers */ -0, MREG, 0x0, "bpr0", -0, MREG, 0x1, "bpr1", -0, MREG, 0x4, "pf0", -0, MREG, 0x5, "pf1", -0, MREG, 0x8, "sc", -0, MREG, 0xA, "msr", -0, MREG, 0xB, "bcnt", -0, MREG, 0xC, "ptb0", -0, MREG, 0xD, "ptb1", -0, MREG, 0xF, "eia", +{0, MREG, 0x0, "bpr0"}, +{0, MREG, 0x1, "bpr1"}, +{0, MREG, 0x4, "pf0"}, +{0, MREG, 0x5, "pf1"}, +{0, MREG, 0x8, "sc"}, +{0, MREG, 0xA, "msr"}, +{0, MREG, 0xB, "bcnt"}, +{0, MREG, 0xC, "ptb0"}, +{0, MREG, 0xD, "ptb1"}, +{0, MREG, 0xF, "eia"}, /* Instruction types */ /* Integer instructions */ -0, ADD_I, mk_op2(0x5,I_BYTE,I_BYTE), "movb", -0, ADD_I, mk_op2(0x5,I_WORD,I_WORD), "movw", -0, ADD_I, mk_op2(0x5,I_DOUBLE,I_DOUBLE), "movd", -0, ADD_I, mk_op2(0x1,I_BYTE,I_BYTE), "cmpb", -0, ADD_I, mk_op2(0x1,I_WORD,I_WORD), "cmpw", -0, ADD_I, mk_op2(0x1,I_DOUBLE,I_DOUBLE), "cmpd", -0, ADD_I, mk_op2(0x0,I_BYTE,I_BYTE), "addb", -0, ADD_I, mk_op2(0x0,I_WORD,I_WORD), "addw", -0, ADD_I, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "addd", -0, ADD_I, mk_op2(0x4,I_BYTE,I_BYTE), "addcb", -0, ADD_I, mk_op2(0x4,I_WORD,I_WORD), "addcw", -0, ADD_I, mk_op2(0x4,I_DOUBLE,I_DOUBLE), "addcd", -0, ADD_I, mk_op2(0x8,I_BYTE,I_BYTE), "subb", -0, ADD_I, mk_op2(0x8,I_WORD,I_WORD), "subw", -0, ADD_I, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "subd", -0, ADD_I, mk_op2(0xC,I_BYTE,I_BYTE), "subcb", -0, ADD_I, mk_op2(0xC,I_WORD,I_WORD), "subcw", -0, ADD_I, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "subcd", -0, COM, mk_op2(0x8,I_BYTE,I_BYTE), "negb", -0, COM, mk_op2(0x8,I_WORD,I_WORD), "negw", -0, COM, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "negd", -0, COM, mk_op2(0xC,I_BYTE,I_BYTE), "absb", -0, COM, mk_op2(0xC,I_WORD,I_WORD), "absw", -0, COM, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "absd", -0, MUL_I, mk_op2(0x8,I_BYTE,I_BYTE), "mulb", -0, MUL_I, mk_op2(0x8,I_WORD,I_WORD), "mulw", -0, MUL_I, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "muld", -0, MUL_I, mk_op2(0xF,I_BYTE,I_BYTE), "divb", -0, MUL_I, mk_op2(0xF,I_WORD,I_WORD), "divw", -0, MUL_I, mk_op2(0xF,I_DOUBLE,I_DOUBLE), "divd", -0, MUL_I, mk_op2(0xE,I_BYTE,I_BYTE), "modb", -0, MUL_I, mk_op2(0xE,I_WORD,I_WORD), "modw", -0, MUL_I, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "modd", -0, MUL_I, mk_op2(0xC,I_BYTE,I_BYTE), "quob", -0, MUL_I, mk_op2(0xC,I_WORD,I_WORD), "quow", -0, MUL_I, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "quod", -0, MUL_I, mk_op2(0xD,I_BYTE,I_BYTE), "remb", -0, MUL_I, mk_op2(0xD,I_WORD,I_WORD), "remw", -0, MUL_I, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "remd", -0, ADD_I, mk_op2(0xA,I_BYTE,I_BYTE), "andb", -0, ADD_I, mk_op2(0xA,I_WORD,I_WORD), "andw", -0, ADD_I, mk_op2(0xA,I_DOUBLE,I_DOUBLE), "andd", -0, ADD_I, mk_op2(0x6,I_BYTE,I_BYTE), "orb", -0, ADD_I, mk_op2(0x6,I_WORD,I_WORD), "orw", -0, ADD_I, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "ord", -0, ADD_I, mk_op2(0x2,I_BYTE,I_BYTE), "bicb", -0, ADD_I, mk_op2(0x2,I_WORD,I_WORD), "bicw", -0, ADD_I, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "bicd", -0, ADD_I, mk_op2(0xE,I_BYTE,I_BYTE), "xorb", -0, ADD_I, mk_op2(0xE,I_WORD,I_WORD), "xorw", -0, ADD_I, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "xord", -0, COM, mk_op2(0xD,I_BYTE,I_BYTE), "comb", -0, COM, mk_op2(0xD,I_WORD,I_WORD), "comw", -0, COM, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "comd", -0, COM, mk_op2(0x1,I_BYTE,I_BYTE), "ashb", -0, COM, mk_op2(0x1,I_BYTE,I_WORD), "ashw", -0, COM, mk_op2(0x1,I_BYTE,I_DOUBLE), "ashd", -0, COM, mk_op2(0x5,I_BYTE,I_BYTE), "lshb", -0, COM, mk_op2(0x5,I_BYTE,I_WORD), "lshw", -0, COM, mk_op2(0x5,I_BYTE,I_DOUBLE), "lshd", -0, COM, mk_op2(0x0,I_BYTE,I_BYTE), "rotb", -0, COM, mk_op2(0x0,I_BYTE,I_WORD), "rotw", -0, COM, mk_op2(0x0,I_BYTE,I_DOUBLE), "rotd", -0, MOVID, mk_op2(0x4,I_BYTE,I_WORD), "movxbw", -0, MOVID, mk_op2(0x7,I_BYTE,I_DOUBLE), "movxbd", -0, MOVID, mk_op2(0x7,I_WORD,I_DOUBLE), "movxwd", -0, MOVID, mk_op2(0x5,I_BYTE,I_WORD), "movzbw", -0, MOVID, mk_op2(0x6,I_BYTE,I_DOUBLE), "movzbd", -0, MOVID, mk_op2(0x6,I_WORD,I_DOUBLE), "movzwd", +{0, ADD_I, mk_op2(0x5,I_BYTE,I_BYTE), "movb"}, +{0, ADD_I, mk_op2(0x5,I_WORD,I_WORD), "movw"}, +{0, ADD_I, mk_op2(0x5,I_DOUBLE,I_DOUBLE), "movd"}, +{0, ADD_I, mk_op2(0x1,I_BYTE,I_BYTE), "cmpb"}, +{0, ADD_I, mk_op2(0x1,I_WORD,I_WORD), "cmpw"}, +{0, ADD_I, mk_op2(0x1,I_DOUBLE,I_DOUBLE), "cmpd"}, +{0, ADD_I, mk_op2(0x0,I_BYTE,I_BYTE), "addb"}, +{0, ADD_I, mk_op2(0x0,I_WORD,I_WORD), "addw"}, +{0, ADD_I, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "addd"}, +{0, ADD_I, mk_op2(0x4,I_BYTE,I_BYTE), "addcb"}, +{0, ADD_I, mk_op2(0x4,I_WORD,I_WORD), "addcw"}, +{0, ADD_I, mk_op2(0x4,I_DOUBLE,I_DOUBLE), "addcd"}, +{0, ADD_I, mk_op2(0x8,I_BYTE,I_BYTE), "subb"}, +{0, ADD_I, mk_op2(0x8,I_WORD,I_WORD), "subw"}, +{0, ADD_I, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "subd"}, +{0, ADD_I, mk_op2(0xC,I_BYTE,I_BYTE), "subcb"}, +{0, ADD_I, mk_op2(0xC,I_WORD,I_WORD), "subcw"}, +{0, ADD_I, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "subcd"}, +{0, COM, mk_op2(0x8,I_BYTE,I_BYTE), "negb"}, +{0, COM, mk_op2(0x8,I_WORD,I_WORD), "negw"}, +{0, COM, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "negd"}, +{0, COM, mk_op2(0xC,I_BYTE,I_BYTE), "absb"}, +{0, COM, mk_op2(0xC,I_WORD,I_WORD), "absw"}, +{0, COM, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "absd"}, +{0, MUL_I, mk_op2(0x8,I_BYTE,I_BYTE), "mulb"}, +{0, MUL_I, mk_op2(0x8,I_WORD,I_WORD), "mulw"}, +{0, MUL_I, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "muld"}, +{0, MUL_I, mk_op2(0xF,I_BYTE,I_BYTE), "divb"}, +{0, MUL_I, mk_op2(0xF,I_WORD,I_WORD), "divw"}, +{0, MUL_I, mk_op2(0xF,I_DOUBLE,I_DOUBLE), "divd"}, +{0, MUL_I, mk_op2(0xE,I_BYTE,I_BYTE), "modb"}, +{0, MUL_I, mk_op2(0xE,I_WORD,I_WORD), "modw"}, +{0, MUL_I, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "modd"}, +{0, MUL_I, mk_op2(0xC,I_BYTE,I_BYTE), "quob"}, +{0, MUL_I, mk_op2(0xC,I_WORD,I_WORD), "quow"}, +{0, MUL_I, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "quod"}, +{0, MUL_I, mk_op2(0xD,I_BYTE,I_BYTE), "remb"}, +{0, MUL_I, mk_op2(0xD,I_WORD,I_WORD), "remw"}, +{0, MUL_I, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "remd"}, +{0, ADD_I, mk_op2(0xA,I_BYTE,I_BYTE), "andb"}, +{0, ADD_I, mk_op2(0xA,I_WORD,I_WORD), "andw"}, +{0, ADD_I, mk_op2(0xA,I_DOUBLE,I_DOUBLE), "andd"}, +{0, ADD_I, mk_op2(0x6,I_BYTE,I_BYTE), "orb"}, +{0, ADD_I, mk_op2(0x6,I_WORD,I_WORD), "orw"}, +{0, ADD_I, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "ord"}, +{0, ADD_I, mk_op2(0x2,I_BYTE,I_BYTE), "bicb"}, +{0, ADD_I, mk_op2(0x2,I_WORD,I_WORD), "bicw"}, +{0, ADD_I, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "bicd"}, +{0, ADD_I, mk_op2(0xE,I_BYTE,I_BYTE), "xorb"}, +{0, ADD_I, mk_op2(0xE,I_WORD,I_WORD), "xorw"}, +{0, ADD_I, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "xord"}, +{0, COM, mk_op2(0xD,I_BYTE,I_BYTE), "comb"}, +{0, COM, mk_op2(0xD,I_WORD,I_WORD), "comw"}, +{0, COM, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "comd"}, +{0, COM, mk_op2(0x1,I_BYTE,I_BYTE), "ashb"}, +{0, COM, mk_op2(0x1,I_BYTE,I_WORD), "ashw"}, +{0, COM, mk_op2(0x1,I_BYTE,I_DOUBLE), "ashd"}, +{0, COM, mk_op2(0x5,I_BYTE,I_BYTE), "lshb"}, +{0, COM, mk_op2(0x5,I_BYTE,I_WORD), "lshw"}, +{0, COM, mk_op2(0x5,I_BYTE,I_DOUBLE), "lshd"}, +{0, COM, mk_op2(0x0,I_BYTE,I_BYTE), "rotb"}, +{0, COM, mk_op2(0x0,I_BYTE,I_WORD), "rotw"}, +{0, COM, mk_op2(0x0,I_BYTE,I_DOUBLE), "rotd"}, +{0, MOVID, mk_op2(0x4,I_BYTE,I_WORD), "movxbw"}, +{0, MOVID, mk_op2(0x7,I_BYTE,I_DOUBLE), "movxbd"}, +{0, MOVID, mk_op2(0x7,I_WORD,I_DOUBLE), "movxwd"}, +{0, MOVID, mk_op2(0x5,I_BYTE,I_WORD), "movzbw"}, +{0, MOVID, mk_op2(0x6,I_BYTE,I_DOUBLE), "movzbd"}, +{0, MOVID, mk_op2(0x6,I_WORD,I_DOUBLE), "movzwd"}, #ifdef UNUSED -0, MOVID, mk_op2(0x7,I_DOUBLE,I_DOUBLE), "movxdd", -0, MOVID, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "movzdd", +{0, MOVID, mk_op2(0x7,I_DOUBLE,I_DOUBLE), "movxdd"}, +{0, MOVID, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "movzdd"}, #endif -0, ADD_I, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "addr", +{0, ADD_I, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "addr"}, /* Quick integer instructions */ -0, MOVQ, mk_op1(0x5,I_BYTE), "movqb", -0, MOVQ, mk_op1(0x5,I_WORD), "movqw", -0, MOVQ, mk_op1(0x5,I_DOUBLE), "movqd", -0, MOVQ, mk_op1(0x1,I_BYTE), "cmpqb", -0, MOVQ, mk_op1(0x1,I_WORD), "cmpqw", -0, MOVQ, mk_op1(0x1,I_DOUBLE), "cmpqd", -0, MOVQ, mk_op1(0x0,I_BYTE), "addqb", -0, MOVQ, mk_op1(0x0,I_WORD), "addqw", -0, MOVQ, mk_op1(0x0,I_DOUBLE), "addqd", +{0, MOVQ, mk_op1(0x5,I_BYTE), "movqb"}, +{0, MOVQ, mk_op1(0x5,I_WORD), "movqw"}, +{0, MOVQ, mk_op1(0x5,I_DOUBLE), "movqd"}, +{0, MOVQ, mk_op1(0x1,I_BYTE), "cmpqb"}, +{0, MOVQ, mk_op1(0x1,I_WORD), "cmpqw"}, +{0, MOVQ, mk_op1(0x1,I_DOUBLE), "cmpqd"}, +{0, MOVQ, mk_op1(0x0,I_BYTE), "addqb"}, +{0, MOVQ, mk_op1(0x0,I_WORD), "addqw"}, +{0, MOVQ, mk_op1(0x0,I_DOUBLE), "addqd"}, /* Extended integer instructions */ -0, MUL_I, mk_op2(0x9,I_BYTE,I_BYTE), "meib", -0, MUL_I, mk_op2(0x9,I_WORD,I_WORD), "meiw", -0, MUL_I, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "meid", -0, MUL_I, mk_op2(0xB,I_BYTE,I_BYTE), "deib", -0, MUL_I, mk_op2(0xB,I_WORD,I_WORD), "deiw", -0, MUL_I, mk_op2(0xB,I_DOUBLE,I_DOUBLE), "deid", +{0, MUL_I, mk_op2(0x9,I_BYTE,I_BYTE), "meib"}, +{0, MUL_I, mk_op2(0x9,I_WORD,I_WORD), "meiw"}, +{0, MUL_I, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "meid"}, +{0, MUL_I, mk_op2(0xB,I_BYTE,I_BYTE), "deib"}, +{0, MUL_I, mk_op2(0xB,I_WORD,I_WORD), "deiw"}, +{0, MUL_I, mk_op2(0xB,I_DOUBLE,I_DOUBLE), "deid"}, /* Boolean instructions */ -0, COM, mk_op2(0x9,I_BYTE,I_BYTE), "notb", -0, COM, mk_op2(0x9,I_WORD,I_WORD), "notw", -0, COM, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "notd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_EQ), "seqb", -0, SEQ, mk_op1c(0x3,I_WORD,B_EQ), "seqw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_EQ), "seqd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_NE), "sneb", -0, SEQ, mk_op1c(0x3,I_WORD,B_NE), "snew", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_NE), "sned", -0, SEQ, mk_op1c(0x3,I_BYTE,B_CS), "scsb", -0, SEQ, mk_op1c(0x3,I_WORD,B_CS), "scsw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_CS), "scsd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_CC), "sccb", -0, SEQ, mk_op1c(0x3,I_WORD,B_CC), "sccw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_CC), "sccd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_HI), "shib", -0, SEQ, mk_op1c(0x3,I_WORD,B_HI), "shiw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_HI), "shid", -0, SEQ, mk_op1c(0x3,I_BYTE,B_LS), "slsb", -0, SEQ, mk_op1c(0x3,I_WORD,B_LS), "slsw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LS), "slsd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_GT), "sgtb", -0, SEQ, mk_op1c(0x3,I_WORD,B_GT), "sgtw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_GT), "sgtd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_LE), "sleb", -0, SEQ, mk_op1c(0x3,I_WORD,B_LE), "slew", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LE), "sled", -0, SEQ, mk_op1c(0x3,I_BYTE,B_FS), "sfsb", -0, SEQ, mk_op1c(0x3,I_WORD,B_FS), "sfsw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FS), "sfsd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_FC), "sfcb", -0, SEQ, mk_op1c(0x3,I_WORD,B_FC), "sfcw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FC), "sfcd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_LO), "slob", -0, SEQ, mk_op1c(0x3,I_WORD,B_LO), "slow", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LO), "slod", -0, SEQ, mk_op1c(0x3,I_BYTE,B_HS), "shsb", -0, SEQ, mk_op1c(0x3,I_WORD,B_HS), "shsw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_HS), "shsd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_LT), "sltb", -0, SEQ, mk_op1c(0x3,I_WORD,B_LT), "sltw", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LT), "sltd", -0, SEQ, mk_op1c(0x3,I_BYTE,B_GE), "sgeb", -0, SEQ, mk_op1c(0x3,I_WORD,B_GE), "sgew", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_GE), "sged", +{0, COM, mk_op2(0x9,I_BYTE,I_BYTE), "notb"}, +{0, COM, mk_op2(0x9,I_WORD,I_WORD), "notw"}, +{0, COM, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "notd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_EQ), "seqb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_EQ), "seqw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_EQ), "seqd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_NE), "sneb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_NE), "snew"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_NE), "sned"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_CS), "scsb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_CS), "scsw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_CS), "scsd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_CC), "sccb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_CC), "sccw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_CC), "sccd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_HI), "shib"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_HI), "shiw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_HI), "shid"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_LS), "slsb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_LS), "slsw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LS), "slsd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_GT), "sgtb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_GT), "sgtw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_GT), "sgtd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_LE), "sleb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_LE), "slew"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LE), "sled"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_FS), "sfsb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_FS), "sfsw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FS), "sfsd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_FC), "sfcb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_FC), "sfcw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FC), "sfcd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_LO), "slob"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_LO), "slow"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LO), "slod"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_HS), "shsb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_HS), "shsw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_HS), "shsd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_LT), "sltb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_LT), "sltw"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LT), "sltd"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_GE), "sgeb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_GE), "sgew"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_GE), "sged"}, #ifdef UNUSED -0, SEQ, mk_op1c(0x3,I_BYTE,B_TRUE), "strueb", -0, SEQ, mk_op1c(0x3,I_WORD,B_TRUE), "struew", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_TRUE), "strued", -0, SEQ, mk_op1c(0x3,I_BYTE,B_FALSE), "sfalseb", -0, SEQ, mk_op1c(0x3,I_WORD,B_FALSE), "sfalsew", -0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FALSE), "sfalsed", +{0, SEQ, mk_op1c(0x3,I_BYTE,B_TRUE), "strueb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_TRUE), "struew"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_TRUE), "strued"}, +{0, SEQ, mk_op1c(0x3,I_BYTE,B_FALSE), "sfalseb"}, +{0, SEQ, mk_op1c(0x3,I_WORD,B_FALSE), "sfalsew"}, +{0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FALSE), "sfalsed"}, #endif /* Bit instructions */ -0, ADD_I, mk_op2(0xD,I_BYTE,I_BYTE), "tbitb", -0, ADD_I, mk_op2(0xD,I_WORD,I_WORD), "tbitw", -0, ADD_I, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "tbitd", -0, COM, mk_op2(0x6,I_BYTE,I_BYTE), "sbitb", -0, COM, mk_op2(0x6,I_WORD,I_WORD), "sbitw", -0, COM, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "sbitd", -0, COM, mk_op2(0x7,I_BYTE,I_BYTE), "sbitib", -0, COM, mk_op2(0x7,I_WORD,I_WORD), "sbitiw", -0, COM, mk_op2(0x7,I_DOUBLE,I_DOUBLE), "sbitid", -0, COM, mk_op2(0x2,I_BYTE,I_BYTE), "cbitb", -0, COM, mk_op2(0x2,I_WORD,I_WORD), "cbitw", -0, COM, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "cbitd", -0, COM, mk_op2(0x3,I_BYTE,I_BYTE), "cbitib", -0, COM, mk_op2(0x3,I_WORD,I_WORD), "cbitiw", -0, COM, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "cbitid", -0, COM, mk_op2(0xE,I_BYTE,I_BYTE), "ibitb", -0, COM, mk_op2(0xE,I_WORD,I_WORD), "ibitw", -0, COM, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "ibitd", -0, CHECK, mk_op1(0x1,I_DOUBLE), "cvtp", -0, FFS, mk_op2c(0x5,I_BYTE,I_BYTE,0), "ffsb", -0, FFS, mk_op2c(0x5,I_WORD,I_BYTE,0), "ffsw", -0, FFS, mk_op2c(0x5,I_DOUBLE,I_BYTE,0), "ffsd", +{0, ADD_I, mk_op2(0xD,I_BYTE,I_BYTE), "tbitb"}, +{0, ADD_I, mk_op2(0xD,I_WORD,I_WORD), "tbitw"}, +{0, ADD_I, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "tbitd"}, +{0, COM, mk_op2(0x6,I_BYTE,I_BYTE), "sbitb"}, +{0, COM, mk_op2(0x6,I_WORD,I_WORD), "sbitw"}, +{0, COM, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "sbitd"}, +{0, COM, mk_op2(0x7,I_BYTE,I_BYTE), "sbitib"}, +{0, COM, mk_op2(0x7,I_WORD,I_WORD), "sbitiw"}, +{0, COM, mk_op2(0x7,I_DOUBLE,I_DOUBLE), "sbitid"}, +{0, COM, mk_op2(0x2,I_BYTE,I_BYTE), "cbitb"}, +{0, COM, mk_op2(0x2,I_WORD,I_WORD), "cbitw"}, +{0, COM, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "cbitd"}, +{0, COM, mk_op2(0x3,I_BYTE,I_BYTE), "cbitib"}, +{0, COM, mk_op2(0x3,I_WORD,I_WORD), "cbitiw"}, +{0, COM, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "cbitid"}, +{0, COM, mk_op2(0xE,I_BYTE,I_BYTE), "ibitb"}, +{0, COM, mk_op2(0xE,I_WORD,I_WORD), "ibitw"}, +{0, COM, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "ibitd"}, +{0, CHECK, mk_op1(0x1,I_DOUBLE), "cvtp"}, +{0, FFS, mk_op2c(0x5,I_BYTE,I_BYTE,0), "ffsb"}, +{0, FFS, mk_op2c(0x5,I_WORD,I_BYTE,0), "ffsw"}, +{0, FFS, mk_op2c(0x5,I_DOUBLE,I_BYTE,0), "ffsd"}, /* Field instructions */ -0, INS, mk_op2(0x0,I_BYTE,I_BYTE), "extb", -0, INS, mk_op2(0x0,I_WORD,I_WORD), "extw", -0, INS, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "extd", -0, INSS, mk_op2(0x3,I_BYTE,I_BYTE), "extsb", -0, INSS, mk_op2(0x3,I_WORD,I_WORD), "extsw", -0, INSS, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "extsd", -0, INS, mk_op2(0x2,I_BYTE,I_BYTE), "insb", -0, INS, mk_op2(0x2,I_WORD,I_WORD), "insw", -0, INS, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "insd", -0, INSS, mk_op2(0x2,I_BYTE,I_BYTE), "inssb", -0, INSS, mk_op2(0x2,I_WORD,I_WORD), "inssw", -0, INSS, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "inssd", +{0, INS, mk_op2(0x0,I_BYTE,I_BYTE), "extb"}, +{0, INS, mk_op2(0x0,I_WORD,I_WORD), "extw"}, +{0, INS, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "extd"}, +{0, INSS, mk_op2(0x3,I_BYTE,I_BYTE), "extsb"}, +{0, INSS, mk_op2(0x3,I_WORD,I_WORD), "extsw"}, +{0, INSS, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "extsd"}, +{0, INS, mk_op2(0x2,I_BYTE,I_BYTE), "insb"}, +{0, INS, mk_op2(0x2,I_WORD,I_WORD), "insw"}, +{0, INS, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "insd"}, +{0, INSS, mk_op2(0x2,I_BYTE,I_BYTE), "inssb"}, +{0, INSS, mk_op2(0x2,I_WORD,I_WORD), "inssw"}, +{0, INSS, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "inssd"}, /* String instructions */ -0, MOVS, mk_op1c(0x0,I_BYTE,0), "movsb", -0, MOVS, mk_op1c(0x0,I_WORD,0), "movsw", -0, MOVS, mk_op1c(0x0,I_DOUBLE,0), "movsd", -0, MOVS, mk_op1c(0x0,I_BYTE,SO_TRANS), "movst", -0, MOVS, mk_op1c(0x1,I_BYTE,0), "cmpsb", -0, MOVS, mk_op1c(0x1,I_WORD,0), "cmpsw", -0, MOVS, mk_op1c(0x1,I_DOUBLE,0), "cmpsd", -0, MOVS, mk_op1c(0x1,I_BYTE,SO_TRANS), "cmpst", -0, MOVS, mk_op1c(0x3,I_BYTE,0), "skpsb", -0, MOVS, mk_op1c(0x3,I_WORD,0), "skpsw", -0, MOVS, mk_op1c(0x3,I_DOUBLE,0), "skpsd", -0, MOVS, mk_op1c(0x3,I_BYTE,SO_TRANS), "skpst", +{0, MOVS, mk_op1c(0x0,I_BYTE,0), "movsb"}, +{0, MOVS, mk_op1c(0x0,I_WORD,0), "movsw"}, +{0, MOVS, mk_op1c(0x0,I_DOUBLE,0), "movsd"}, +{0, MOVS, mk_op1c(0x0,I_BYTE,SO_TRANS), "movst"}, +{0, MOVS, mk_op1c(0x1,I_BYTE,0), "cmpsb"}, +{0, MOVS, mk_op1c(0x1,I_WORD,0), "cmpsw"}, +{0, MOVS, mk_op1c(0x1,I_DOUBLE,0), "cmpsd"}, +{0, MOVS, mk_op1c(0x1,I_BYTE,SO_TRANS), "cmpst"}, +{0, MOVS, mk_op1c(0x3,I_BYTE,0), "skpsb"}, +{0, MOVS, mk_op1c(0x3,I_WORD,0), "skpsw"}, +{0, MOVS, mk_op1c(0x3,I_DOUBLE,0), "skpsd"}, +{0, MOVS, mk_op1c(0x3,I_BYTE,SO_TRANS), "skpst"}, /* Block instructions */ -0, MOVM, mk_op2(0x0,I_BYTE,I_BYTE), "movmb", -0, MOVM, mk_op2(0x0,I_WORD,I_WORD), "movmw", -0, MOVM, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "movmd", -0, MOVM, mk_op2(0x1,I_BYTE,I_BYTE), "cmpmb", -0, MOVM, mk_op2(0x1,I_WORD,I_WORD), "cmpmw", -0, MOVM, mk_op2(0x1,I_DOUBLE,I_DOUBLE), "cmpmd", +{0, MOVM, mk_op2(0x0,I_BYTE,I_BYTE), "movmb"}, +{0, MOVM, mk_op2(0x0,I_WORD,I_WORD), "movmw"}, +{0, MOVM, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "movmd"}, +{0, MOVM, mk_op2(0x1,I_BYTE,I_BYTE), "cmpmb"}, +{0, MOVM, mk_op2(0x1,I_WORD,I_WORD), "cmpmw"}, +{0, MOVM, mk_op2(0x1,I_DOUBLE,I_DOUBLE), "cmpmd"}, /* Packed decimal instructions */ -0, COM, mk_op2(0xF,I_BYTE,I_BYTE), "addpb", -0, COM, mk_op2(0xF,I_WORD,I_WORD), "addpw", -0, COM, mk_op2(0xF,I_DOUBLE,I_DOUBLE), "addpd", -0, COM, mk_op2(0xB,I_BYTE,I_BYTE), "subpb", -0, COM, mk_op2(0xB,I_WORD,I_WORD), "subpw", -0, COM, mk_op2(0xB,I_DOUBLE,I_DOUBLE), "subpd", +{0, COM, mk_op2(0xF,I_BYTE,I_BYTE), "addpb"}, +{0, COM, mk_op2(0xF,I_WORD,I_WORD), "addpw"}, +{0, COM, mk_op2(0xF,I_DOUBLE,I_DOUBLE), "addpd"}, +{0, COM, mk_op2(0xB,I_BYTE,I_BYTE), "subpb"}, +{0, COM, mk_op2(0xB,I_WORD,I_WORD), "subpw"}, +{0, COM, mk_op2(0xB,I_DOUBLE,I_DOUBLE), "subpd"}, /* Array instructions */ -0, CHECK, mk_op2(0x4,I_BYTE,I_BYTE), "indexb", -0, CHECK, mk_op2(0x4,I_WORD,I_WORD), "indexw", -0, CHECK, mk_op2(0x4,I_DOUBLE,I_DOUBLE), "indexd", -0, CHECK, mk_op2(0x3,I_BYTE,I_BYTE), "checkb", -0, CHECK, mk_op2(0x3,I_WORD,I_WORD), "checkw", -0, CHECK, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "checkd", +{0, CHECK, mk_op2(0x4,I_BYTE,I_BYTE), "indexb"}, +{0, CHECK, mk_op2(0x4,I_WORD,I_WORD), "indexw"}, +{0, CHECK, mk_op2(0x4,I_DOUBLE,I_DOUBLE), "indexd"}, +{0, CHECK, mk_op2(0x3,I_BYTE,I_BYTE), "checkb"}, +{0, CHECK, mk_op2(0x3,I_WORD,I_WORD), "checkw"}, +{0, CHECK, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "checkd"}, /* Processor control instructions */ -0, JUMP, mk_op1(0x4,I_DOUBLE), "jump", -0, BR, mk_c(B_EQ), "beq", -0, BR, mk_c(B_NE), "bne", -0, BR, mk_c(B_CS), "bcs", -0, BR, mk_c(B_CC), "bcc", -0, BR, mk_c(B_HI), "bhi", -0, BR, mk_c(B_LS), "bls", -0, BR, mk_c(B_GT), "bgt", -0, BR, mk_c(B_LE), "ble", -0, BR, mk_c(B_FS), "bfs", -0, BR, mk_c(B_FC), "bfc", -0, BR, mk_c(B_LO), "blo", -0, BR, mk_c(B_HS), "bhs", -0, BR, mk_c(B_LT), "blt", -0, BR, mk_c(B_GE), "bge", -0, BR, mk_c(B_TRUE), "br", +{0, JUMP, mk_op1(0x4,I_DOUBLE), "jump"}, +{0, BR, mk_c(B_EQ), "beq"}, +{0, BR, mk_c(B_NE), "bne"}, +{0, BR, mk_c(B_CS), "bcs"}, +{0, BR, mk_c(B_CC), "bcc"}, +{0, BR, mk_c(B_HI), "bhi"}, +{0, BR, mk_c(B_LS), "bls"}, +{0, BR, mk_c(B_GT), "bgt"}, +{0, BR, mk_c(B_LE), "ble"}, +{0, BR, mk_c(B_FS), "bfs"}, +{0, BR, mk_c(B_FC), "bfc"}, +{0, BR, mk_c(B_LO), "blo"}, +{0, BR, mk_c(B_HS), "bhs"}, +{0, BR, mk_c(B_LT), "blt"}, +{0, BR, mk_c(B_GE), "bge"}, +{0, BR, mk_c(B_TRUE), "br"}, #ifdef UNUSED -0, BR, mk_c(B_FALSE), "bfalse", +{0, BR, mk_c(B_FALSE), "bfalse"}, #endif -0, ADJSP, mk_op1(0xE,I_BYTE), "caseb", -0, ADJSP, mk_op1(0xE,I_WORD), "casew", -0, ADJSP, mk_op1(0xE,I_DOUBLE), "cased", -0, ACB, mk_op1(0x4,I_BYTE), "acbb", -0, ACB, mk_op1(0x4,I_WORD), "acbw", -0, ACB, mk_op1(0x4,I_DOUBLE), "acbd", -0, JSR, mk_op1(0xC,I_DOUBLE), "jsr", -0, BSR, mk_op(0x0), "bsr", -0, RET, mk_op(0x1), "ret", -0, RET, mk_op(0x2), "cxp", -0, ADJSP, mk_op1(0x0,I_DOUBLE), "cxpd", -0, RET, mk_op(0x3), "rxp", -0, RET, mk_op(0x4), "rett", -0, WAIT, mk_op(0x5), "reti", -0, WAIT, mk_op(0xC), "dia", +{0, ADJSP, mk_op1(0xE,I_BYTE), "caseb"}, +{0, ADJSP, mk_op1(0xE,I_WORD), "casew"}, +{0, ADJSP, mk_op1(0xE,I_DOUBLE), "cased"}, +{0, ACB, mk_op1(0x4,I_BYTE), "acbb"}, +{0, ACB, mk_op1(0x4,I_WORD), "acbw"}, +{0, ACB, mk_op1(0x4,I_DOUBLE), "acbd"}, +{0, JSR, mk_op1(0xC,I_DOUBLE), "jsr"}, +{0, BSR, mk_op(0x0), "bsr"}, +{0, RET, mk_op(0x1), "ret"}, +{0, RET, mk_op(0x2), "cxp"}, +{0, ADJSP, mk_op1(0x0,I_DOUBLE), "cxpd"}, +{0, RET, mk_op(0x3), "rxp"}, +{0, RET, mk_op(0x4), "rett"}, +{0, WAIT, mk_op(0x5), "reti"}, +{0, WAIT, mk_op(0xC), "dia"}, /* Processor service instructions */ -0, ADJSP, mk_op1(0xA,I_BYTE), "adjspb", -0, ADJSP, mk_op1(0xA,I_WORD), "adjspw", -0, ADJSP, mk_op1(0xA,I_DOUBLE), "adjspd", -0, ADJSP, mk_op1(0x2,I_BYTE), "bicpsrb", -0, ADJSP, mk_op1(0x2,I_WORD), "bicpsrw", -0, ADJSP, mk_op1(0x6,I_BYTE), "bispsrb", -0, ADJSP, mk_op1(0x6,I_WORD), "bispsrw", +{0, ADJSP, mk_op1(0xA,I_BYTE), "adjspb"}, +{0, ADJSP, mk_op1(0xA,I_WORD), "adjspw"}, +{0, ADJSP, mk_op1(0xA,I_DOUBLE), "adjspd"}, +{0, ADJSP, mk_op1(0x2,I_BYTE), "bicpsrb"}, +{0, ADJSP, mk_op1(0x2,I_WORD), "bicpsrw"}, +{0, ADJSP, mk_op1(0x6,I_BYTE), "bispsrb"}, +{0, ADJSP, mk_op1(0x6,I_WORD), "bispsrw"}, #ifdef UNUSED -0, ADJSP, mk_op1(0x2,I_DOUBLE), "bicpsrd", -0, ADJSP, mk_op1(0x6,I_DOUBLE), "bispsrd", +{0, ADJSP, mk_op1(0x2,I_DOUBLE), "bicpsrd"}, +{0, ADJSP, mk_op1(0x6,I_DOUBLE), "bispsrd"}, #endif -0, SAVE, mk_op(0x6), "save", -0, SAVE, mk_op(0x7), "restore", -0, ENTER, mk_op(0x8), "enter", -0, SAVE, mk_op(0x9), "exit", -0, LPR, mk_op1(0x6,I_BYTE), "lprb", -0, LPR, mk_op1(0x6,I_WORD), "lprw", -0, LPR, mk_op1(0x6,I_DOUBLE), "lprd", -0, LPR, mk_op1(0x2,I_BYTE), "sprb", -0, LPR, mk_op1(0x2,I_WORD), "sprw", -0, LPR, mk_op1(0x2,I_DOUBLE), "sprd", -0, SETCFG, mk_op1(0x2,I_DOUBLE), "setcfg", -0, WAIT, mk_op(0xF), "bpt", -0, WAIT, mk_op(0xD), "flag", -0, WAIT, mk_op(0xE), "svc", -0, WAIT, mk_op(0xA), "nop", -0, WAIT, mk_op(0xB), "wait", +{0, SAVE, mk_op(0x6), "save"}, +{0, SAVE, mk_op(0x7), "restore"}, +{0, ENTER, mk_op(0x8), "enter"}, +{0, SAVE, mk_op(0x9), "exit"}, +{0, LPR, mk_op1(0x6,I_BYTE), "lprb"}, +{0, LPR, mk_op1(0x6,I_WORD), "lprw"}, +{0, LPR, mk_op1(0x6,I_DOUBLE), "lprd"}, +{0, LPR, mk_op1(0x2,I_BYTE), "sprb"}, +{0, LPR, mk_op1(0x2,I_WORD), "sprw"}, +{0, LPR, mk_op1(0x2,I_DOUBLE), "sprd"}, +{0, SETCFG, mk_op1(0x2,I_DOUBLE), "setcfg"}, +{0, WAIT, mk_op(0xF), "bpt"}, +{0, WAIT, mk_op(0xD), "flag"}, +{0, WAIT, mk_op(0xE), "svc"}, +{0, WAIT, mk_op(0xA), "nop"}, +{0, WAIT, mk_op(0xB), "wait"}, /* Memory management instructions */ -0, LMR, mk_op1(0x2,I_DOUBLE), "lmr", -0, LMR, mk_op1(0x3,I_DOUBLE), "smr", -0, RDVAL, mk_op1(0x0,I_DOUBLE), "rdval", -0, RDVAL, mk_op1(0x1,I_DOUBLE), "wrval", +{0, LMR, mk_op1(0x2,I_DOUBLE), "lmr"}, +{0, LMR, mk_op1(0x3,I_DOUBLE), "smr"}, +{0, RDVAL, mk_op1(0x0,I_DOUBLE), "rdval"}, +{0, RDVAL, mk_op1(0x1,I_DOUBLE), "wrval"}, #ifdef SU_ASSEM /* The assembler ref. man and the CPU description booklet differ in the encoding of these instructions */ -0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,1), "movsub", -0, FFS, mk_op2c(0x6,I_WORD,I_WORD,1), "movsuw", -0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,1),"movsud", -0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,3), "movusb", -0, FFS, mk_op2c(0x6,I_WORD,I_WORD,3), "movusw", -0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,3),"movusd", +{0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,1), "movsub"}, +{0, FFS, mk_op2c(0x6,I_WORD,I_WORD,1), "movsuw"}, +{0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,1),"movsud"}, +{0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,3), "movusb"}, +{0, FFS, mk_op2c(0x6,I_WORD,I_WORD,3), "movusw"}, +{0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,3),"movusd"}, #else /* assembler reference manual version */ -0, FFS, mk_op2c(0x7,I_BYTE,I_BYTE,0), "movsub", -0, FFS, mk_op2c(0x7,I_WORD,I_WORD,0), "movsuw", -0, FFS, mk_op2c(0x7,I_DOUBLE,I_DOUBLE,0),"movsud", -0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,0), "movusb", -0, FFS, mk_op2c(0x6,I_WORD,I_WORD,0), "movusw", -0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,0),"movusd", +{0, FFS, mk_op2c(0x7,I_BYTE,I_BYTE,0), "movsub"}, +{0, FFS, mk_op2c(0x7,I_WORD,I_WORD,0), "movsuw"}, +{0, FFS, mk_op2c(0x7,I_DOUBLE,I_DOUBLE,0),"movsud"}, +{0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,0), "movusb"}, +{0, FFS, mk_op2c(0x6,I_WORD,I_WORD,0), "movusw"}, +{0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,0),"movusd"}, #endif /* Floating point instructions */ -0, ADD_F, mk_op2(0xD,F_FLOAT,F_FLOAT), "absf", -0, ADD_F, mk_op2(0xD,F_LONG,F_LONG), "absl", -0, ADD_F, mk_op2(0x0,F_FLOAT,F_FLOAT), "addf", -0, ADD_F, mk_op2(0x0,F_LONG,F_LONG), "addl", -0, ADD_F, mk_op2(0x2,F_FLOAT,F_FLOAT), "cmpf", -0, ADD_F, mk_op2(0x2,F_LONG,F_LONG), "cmpl", -0, ADD_F, mk_op2(0x8,F_FLOAT,F_FLOAT), "divf", -0, ADD_F, mk_op2(0x8,F_LONG,F_LONG), "divl", -0, ADD_F, mk_op2(0xC,F_FLOAT,F_FLOAT), "mulf", -0, ADD_F, mk_op2(0xC,F_LONG,F_LONG), "mull", -0, ADD_F, mk_op2(0x4,F_FLOAT,F_FLOAT), "subf", -0, ADD_F, mk_op2(0x4,F_LONG,F_LONG), "subl", -0, ADD_F, mk_op2(0x5,F_FLOAT,F_FLOAT), "negf", -0, ADD_F, mk_op2(0x5,F_LONG,F_LONG), "negl", -0, ADD_F, mk_op2(0x1,F_FLOAT,F_FLOAT), "movf", -0, ADD_F, mk_op2(0x1,F_LONG,F_LONG), "movl", -0, MOVIF, mk_op2(0x0,I_BYTE,F_FLOAT), "movbf", -0, MOVIF, mk_op2(0x0,I_WORD,F_FLOAT), "movwf", -0, MOVIF, mk_op2(0x0,I_DOUBLE,F_FLOAT), "movdf", -0, MOVIF, mk_op2(0x0,I_BYTE,F_LONG), "movbl", -0, MOVIF, mk_op2(0x0,I_WORD,F_LONG), "movwl", -0, MOVIF, mk_op2(0x0,I_DOUBLE,F_LONG), "movdl", -0, MOVFL, mk_op2(0x3,F_FLOAT,F_LONG), "movfl", -0, MOVFL, mk_op2(0x2,F_LONG,F_FLOAT), "movlf", -0, TRUNC, mk_op2(0x7,F_FLOAT,I_BYTE), "floorfb", -0, TRUNC, mk_op2(0x7,F_FLOAT,I_WORD), "floorfw", -0, TRUNC, mk_op2(0x7,F_FLOAT,I_DOUBLE), "floorfd", -0, TRUNC, mk_op2(0x7,F_LONG,I_BYTE), "floorlb", -0, TRUNC, mk_op2(0x7,F_LONG,I_WORD), "floorlw", -0, TRUNC, mk_op2(0x7,F_LONG,I_DOUBLE), "floorld", -0, TRUNC, mk_op2(0x4,F_FLOAT,I_BYTE), "roundfb", -0, TRUNC, mk_op2(0x4,F_FLOAT,I_WORD), "roundfw", -0, TRUNC, mk_op2(0x4,F_FLOAT,I_DOUBLE), "roundfd", -0, TRUNC, mk_op2(0x4,F_LONG,I_BYTE), "roundlb", -0, TRUNC, mk_op2(0x4,F_LONG,I_WORD), "roundlw", -0, TRUNC, mk_op2(0x4,F_LONG,I_DOUBLE), "roundld", -0, TRUNC, mk_op2(0x5,F_FLOAT,I_BYTE), "truncfb", -0, TRUNC, mk_op2(0x5,F_FLOAT,I_WORD), "truncfw", -0, TRUNC, mk_op2(0x5,F_FLOAT,I_DOUBLE), "truncfd", -0, TRUNC, mk_op2(0x5,F_LONG,I_BYTE), "trunclb", -0, TRUNC, mk_op2(0x5,F_LONG,I_WORD), "trunclw", -0, TRUNC, mk_op2(0x5,F_LONG,I_DOUBLE), "truncld", -0, LFSR, mk_op(0x1), "lfsr", -0, LFSR, mk_op(0x6), "sfsr", +{0, ADD_F, mk_op2(0xD,F_FLOAT,F_FLOAT), "absf"}, +{0, ADD_F, mk_op2(0xD,F_LONG,F_LONG), "absl"}, +{0, ADD_F, mk_op2(0x0,F_FLOAT,F_FLOAT), "addf"}, +{0, ADD_F, mk_op2(0x0,F_LONG,F_LONG), "addl"}, +{0, ADD_F, mk_op2(0x2,F_FLOAT,F_FLOAT), "cmpf"}, +{0, ADD_F, mk_op2(0x2,F_LONG,F_LONG), "cmpl"}, +{0, ADD_F, mk_op2(0x8,F_FLOAT,F_FLOAT), "divf"}, +{0, ADD_F, mk_op2(0x8,F_LONG,F_LONG), "divl"}, +{0, ADD_F, mk_op2(0xC,F_FLOAT,F_FLOAT), "mulf"}, +{0, ADD_F, mk_op2(0xC,F_LONG,F_LONG), "mull"}, +{0, ADD_F, mk_op2(0x4,F_FLOAT,F_FLOAT), "subf"}, +{0, ADD_F, mk_op2(0x4,F_LONG,F_LONG), "subl"}, +{0, ADD_F, mk_op2(0x5,F_FLOAT,F_FLOAT), "negf"}, +{0, ADD_F, mk_op2(0x5,F_LONG,F_LONG), "negl"}, +{0, ADD_F, mk_op2(0x1,F_FLOAT,F_FLOAT), "movf"}, +{0, ADD_F, mk_op2(0x1,F_LONG,F_LONG), "movl"}, +{0, MOVIF, mk_op2(0x0,I_BYTE,F_FLOAT), "movbf"}, +{0, MOVIF, mk_op2(0x0,I_WORD,F_FLOAT), "movwf"}, +{0, MOVIF, mk_op2(0x0,I_DOUBLE,F_FLOAT), "movdf"}, +{0, MOVIF, mk_op2(0x0,I_BYTE,F_LONG), "movbl"}, +{0, MOVIF, mk_op2(0x0,I_WORD,F_LONG), "movwl"}, +{0, MOVIF, mk_op2(0x0,I_DOUBLE,F_LONG), "movdl"}, +{0, MOVFL, mk_op2(0x3,F_FLOAT,F_LONG), "movfl"}, +{0, MOVFL, mk_op2(0x2,F_LONG,F_FLOAT), "movlf"}, +{0, TRUNC, mk_op2(0x7,F_FLOAT,I_BYTE), "floorfb"}, +{0, TRUNC, mk_op2(0x7,F_FLOAT,I_WORD), "floorfw"}, +{0, TRUNC, mk_op2(0x7,F_FLOAT,I_DOUBLE), "floorfd"}, +{0, TRUNC, mk_op2(0x7,F_LONG,I_BYTE), "floorlb"}, +{0, TRUNC, mk_op2(0x7,F_LONG,I_WORD), "floorlw"}, +{0, TRUNC, mk_op2(0x7,F_LONG,I_DOUBLE), "floorld"}, +{0, TRUNC, mk_op2(0x4,F_FLOAT,I_BYTE), "roundfb"}, +{0, TRUNC, mk_op2(0x4,F_FLOAT,I_WORD), "roundfw"}, +{0, TRUNC, mk_op2(0x4,F_FLOAT,I_DOUBLE), "roundfd"}, +{0, TRUNC, mk_op2(0x4,F_LONG,I_BYTE), "roundlb"}, +{0, TRUNC, mk_op2(0x4,F_LONG,I_WORD), "roundlw"}, +{0, TRUNC, mk_op2(0x4,F_LONG,I_DOUBLE), "roundld"}, +{0, TRUNC, mk_op2(0x5,F_FLOAT,I_BYTE), "truncfb"}, +{0, TRUNC, mk_op2(0x5,F_FLOAT,I_WORD), "truncfw"}, +{0, TRUNC, mk_op2(0x5,F_FLOAT,I_DOUBLE), "truncfd"}, +{0, TRUNC, mk_op2(0x5,F_LONG,I_BYTE), "trunclb"}, +{0, TRUNC, mk_op2(0x5,F_LONG,I_WORD), "trunclw"}, +{0, TRUNC, mk_op2(0x5,F_LONG,I_DOUBLE), "truncld"}, +{0, LFSR, mk_op(0x1), "lfsr"}, +{0, LFSR, mk_op(0x6), "sfsr"}, /* Slave processor instructions */ -0, LCR, mk_op1(0x2,I_DOUBLE), "lcr", /* Sure ? */ -0, LCR, mk_op1(0x3,I_DOUBLE), "scr", /* Sure ? */ -0, CATST, mk_op1(0x0,I_DOUBLE), "catst0",/* Sure ? */ -0, CATST, mk_op1(0x1,I_DOUBLE), "catst1",/* Sure ? */ -0, LCSR, mk_op1(0x1,S_DOUBLE), "lcsr", /* Sure ? */ -0, LCSR, mk_op1(0x6,S_DOUBLE), "scsr", /* Sure ? */ -0, CCVSI, mk_op2(0x7,S_DOUBLE,I_BYTE), "ccv0db", -0, CCVSI, mk_op2(0x7,S_DOUBLE,I_WORD), "ccv0dw", -0, CCVSI, mk_op2(0x7,S_DOUBLE,I_DOUBLE), "ccv0dd", -0, CCVSI, mk_op2(0x7,S_QUAD,I_BYTE), "ccv0qb", -0, CCVSI, mk_op2(0x7,S_QUAD,I_WORD), "ccv0qw", -0, CCVSI, mk_op2(0x7,S_QUAD,I_DOUBLE), "ccv0qd", -0, CCVSI, mk_op2(0x5,S_DOUBLE,I_BYTE), "ccv1db", -0, CCVSI, mk_op2(0x5,S_DOUBLE,I_WORD), "ccv1dw", -0, CCVSI, mk_op2(0x5,S_DOUBLE,I_DOUBLE), "ccv1dd", -0, CCVSI, mk_op2(0x5,S_QUAD,I_BYTE), "ccv1qb", -0, CCVSI, mk_op2(0x5,S_QUAD,I_WORD), "ccv1qw", -0, CCVSI, mk_op2(0x5,S_QUAD,I_DOUBLE), "ccv1qd", -0, CCVSI, mk_op2(0x4,S_DOUBLE,I_BYTE), "ccv2db", -0, CCVSI, mk_op2(0x4,S_DOUBLE,I_WORD), "ccv2dw", -0, CCVSI, mk_op2(0x4,S_DOUBLE,I_DOUBLE), "ccv2dd", -0, CCVSI, mk_op2(0x4,S_QUAD,I_BYTE), "ccv2qb", -0, CCVSI, mk_op2(0x4,S_QUAD,I_WORD), "ccv2qw", -0, CCVSI, mk_op2(0x4,S_QUAD,I_DOUBLE), "ccv2qd", -0, CCVIS, mk_op2(0x0,I_BYTE,S_DOUBLE), "ccv3bd", -0, CCVIS, mk_op2(0x0,I_WORD,S_DOUBLE), "ccv3wd", -0, CCVIS, mk_op2(0x0,I_DOUBLE,S_DOUBLE), "ccv3dd", -0, CCVIS, mk_op2(0x0,I_BYTE,S_QUAD), "ccv3bq", -0, CCVIS, mk_op2(0x0,I_WORD,S_QUAD), "ccv3wq", -0, CCVIS, mk_op2(0x0,I_DOUBLE,S_QUAD), "ccv3dq", -0, CCVSS, mk_op2(0x3,S_DOUBLE,S_QUAD), "ccv4dq", -0, CCVSS, mk_op2(0x2,S_QUAD,S_DOUBLE), "ccv5qd", -0, CMOV, mk_op2(0x0,S_DOUBLE,S_DOUBLE), "ccal0d", -0, CMOV, mk_op2(0x0,S_QUAD,S_QUAD), "ccal0q", -0, CMOV, mk_op2(0x4,S_DOUBLE,S_DOUBLE), "ccal1d", -0, CMOV, mk_op2(0x4,S_QUAD,S_QUAD), "ccal1q", -0, CMOV, mk_op2(0xC,S_DOUBLE,S_DOUBLE), "ccal2d", -0, CMOV, mk_op2(0xC,S_QUAD,S_QUAD), "ccal2q", -0, CMOV, mk_op2(0x8,S_DOUBLE,S_DOUBLE), "ccal3d", -0, CMOV, mk_op2(0x8,S_QUAD,S_QUAD), "ccal3q", -0, CMOV, mk_op2(0x2,S_DOUBLE,S_DOUBLE), "ccmpd", -0, CMOV, mk_op2(0x2,S_QUAD,S_QUAD), "ccmpq", -0, CMOV, mk_op2(0x1,S_DOUBLE,S_DOUBLE), "cmov0d", -0, CMOV, mk_op2(0x1,S_QUAD,S_QUAD), "cmov0q", -0, CMOV, mk_op2(0xD,S_DOUBLE,S_DOUBLE), "cmov1d", -0, CMOV, mk_op2(0xD,S_QUAD,S_QUAD), "cmov1q", -0, CMOV, mk_op2(0x5,S_DOUBLE,S_DOUBLE), "cmov2d", -0, CMOV, mk_op2(0x5,S_QUAD,S_QUAD), "cmov2q", +{0, LCR, mk_op1(0x2,I_DOUBLE), "lcr"}, /* Sure ? */ +{0, LCR, mk_op1(0x3,I_DOUBLE), "scr"}, /* Sure ? */ +{0, CATST, mk_op1(0x0,I_DOUBLE), "catst0"},/* Sure ? */ +{0, CATST, mk_op1(0x1,I_DOUBLE), "catst1"},/* Sure ? */ +{0, LCSR, mk_op1(0x1,S_DOUBLE), "lcsr"}, /* Sure ? */ +{0, LCSR, mk_op1(0x6,S_DOUBLE), "scsr"}, /* Sure ? */ +{0, CCVSI, mk_op2(0x7,S_DOUBLE,I_BYTE), "ccv0db"}, +{0, CCVSI, mk_op2(0x7,S_DOUBLE,I_WORD), "ccv0dw"}, +{0, CCVSI, mk_op2(0x7,S_DOUBLE,I_DOUBLE), "ccv0dd"}, +{0, CCVSI, mk_op2(0x7,S_QUAD,I_BYTE), "ccv0qb"}, +{0, CCVSI, mk_op2(0x7,S_QUAD,I_WORD), "ccv0qw"}, +{0, CCVSI, mk_op2(0x7,S_QUAD,I_DOUBLE), "ccv0qd"}, +{0, CCVSI, mk_op2(0x5,S_DOUBLE,I_BYTE), "ccv1db"}, +{0, CCVSI, mk_op2(0x5,S_DOUBLE,I_WORD), "ccv1dw"}, +{0, CCVSI, mk_op2(0x5,S_DOUBLE,I_DOUBLE), "ccv1dd"}, +{0, CCVSI, mk_op2(0x5,S_QUAD,I_BYTE), "ccv1qb"}, +{0, CCVSI, mk_op2(0x5,S_QUAD,I_WORD), "ccv1qw"}, +{0, CCVSI, mk_op2(0x5,S_QUAD,I_DOUBLE), "ccv1qd"}, +{0, CCVSI, mk_op2(0x4,S_DOUBLE,I_BYTE), "ccv2db"}, +{0, CCVSI, mk_op2(0x4,S_DOUBLE,I_WORD), "ccv2dw"}, +{0, CCVSI, mk_op2(0x4,S_DOUBLE,I_DOUBLE), "ccv2dd"}, +{0, CCVSI, mk_op2(0x4,S_QUAD,I_BYTE), "ccv2qb"}, +{0, CCVSI, mk_op2(0x4,S_QUAD,I_WORD), "ccv2qw"}, +{0, CCVSI, mk_op2(0x4,S_QUAD,I_DOUBLE), "ccv2qd"}, +{0, CCVIS, mk_op2(0x0,I_BYTE,S_DOUBLE), "ccv3bd"}, +{0, CCVIS, mk_op2(0x0,I_WORD,S_DOUBLE), "ccv3wd"}, +{0, CCVIS, mk_op2(0x0,I_DOUBLE,S_DOUBLE), "ccv3dd"}, +{0, CCVIS, mk_op2(0x0,I_BYTE,S_QUAD), "ccv3bq"}, +{0, CCVIS, mk_op2(0x0,I_WORD,S_QUAD), "ccv3wq"}, +{0, CCVIS, mk_op2(0x0,I_DOUBLE,S_QUAD), "ccv3dq"}, +{0, CCVSS, mk_op2(0x3,S_DOUBLE,S_QUAD), "ccv4dq"}, +{0, CCVSS, mk_op2(0x2,S_QUAD,S_DOUBLE), "ccv5qd"}, +{0, CMOV, mk_op2(0x0,S_DOUBLE,S_DOUBLE), "ccal0d"}, +{0, CMOV, mk_op2(0x0,S_QUAD,S_QUAD), "ccal0q"}, +{0, CMOV, mk_op2(0x4,S_DOUBLE,S_DOUBLE), "ccal1d"}, +{0, CMOV, mk_op2(0x4,S_QUAD,S_QUAD), "ccal1q"}, +{0, CMOV, mk_op2(0xC,S_DOUBLE,S_DOUBLE), "ccal2d"}, +{0, CMOV, mk_op2(0xC,S_QUAD,S_QUAD), "ccal2q"}, +{0, CMOV, mk_op2(0x8,S_DOUBLE,S_DOUBLE), "ccal3d"}, +{0, CMOV, mk_op2(0x8,S_QUAD,S_QUAD), "ccal3q"}, +{0, CMOV, mk_op2(0x2,S_DOUBLE,S_DOUBLE), "ccmpd"}, +{0, CMOV, mk_op2(0x2,S_QUAD,S_QUAD), "ccmpq"}, +{0, CMOV, mk_op2(0x1,S_DOUBLE,S_DOUBLE), "cmov0d"}, +{0, CMOV, mk_op2(0x1,S_QUAD,S_QUAD), "cmov0q"}, +{0, CMOV, mk_op2(0xD,S_DOUBLE,S_DOUBLE), "cmov1d"}, +{0, CMOV, mk_op2(0xD,S_QUAD,S_QUAD), "cmov1q"}, +{0, CMOV, mk_op2(0x5,S_DOUBLE,S_DOUBLE), "cmov2d"}, +{0, CMOV, mk_op2(0x5,S_QUAD,S_QUAD), "cmov2q"}, diff --git a/mach/pdp/as/mach3.c b/mach/pdp/as/mach3.c index 10abfa399..42c5cdf26 100644 --- a/mach/pdp/as/mach3.c +++ b/mach/pdp/as/mach3.c @@ -7,149 +7,149 @@ /*, * PDP 11 keywords, */ -0, REG, 00, "r0", -0, REG, 01, "r1", -0, REG, 02, "r2", -0, REG, 03, "r3", -0, REG, 04, "r4", -0, REG, 05, "r5", -0, REG, 06, "r6", -0, REG, 06, "sp", -0, REG, 07, "r7", -0, REG, 07, "pc", -0, FREG, 00, "fr0", -0, FREG, 01, "fr1", -0, FREG, 02, "fr2", -0, FREG, 03, "fr3", -0, FRSP, 04, "fr4", -0, FRSP, 05, "fr5", -0, OP_SO, 05000, "clr", -0, OP_SO, 0105000, "clrb", -0, OP_SO, 05100, "com", -0, OP_SO, 0105100, "comb", -0, OP_SO, 005200, "inc", -0, OP_SO, 0105200, "incb", -0, OP_SO, 005300, "dec", -0, OP_SO, 0105300, "decb", -0, OP_SO, 005400, "neg", -0, OP_SO, 0105400, "negb", -0, OP_SO, 005700, "tst", -0, OP_SO, 0105700, "tstb", -0, OP_SO, 006200, "asr", -0, OP_SO, 0106200, "asrb", -0, OP_SO, 006300, "asl", -0, OP_SO, 0106300, "aslb", -0, OP_SO, 006000, "ror", -0, OP_SO, 0106000, "rorb", -0, OP_SO, 006100, "rol", -0, OP_SO, 0106100, "rolb", -0, OP_SO, 000300, "swab", -0, OP_SO, 005500, "adc", -0, OP_SO, 0105500, "adcb", -0, OP_SO, 005600, "sbc", -0, OP_SO, 0105600, "sbcb", -0, OP_SO, 006700, "sxt", -0, OP_DO, 010000, "mov", -0, OP_DO, 0110000, "movb", -0, OP_DO, 020000, "cmp", -0, OP_DO, 0120000, "cmpb", -0, OP_DO, 060000, "add", -0, OP_DO, 0160000, "sub", -0, OP_DO, 030000, "bit", -0, OP_DO, 0130000, "bitb", -0, OP_DO, 040000, "bic", -0, OP_DO, 0140000, "bicb", -0, OP_DO, 050000, "bis", -0, OP_DO, 0150000, "bisb", -0, OP_R_SO, 074000, "xor", -0, JMP, 0100, "jmp", -0, BR, 0400, "br", -0, BR, 01000, "bne", -0, BR, 01400, "beq", -0, BR, 0100000, "bpl", -0, BR, 0100400, "bmi", -0, BR, 0102000, "bvc", -0, BR, 0102400, "bvs", -0, BR, 0103000, "bcc", -0, BR, 0103400, "bcs", -0, BR, 002000, "bge", -0, BR, 002400, "blt", -0, BR, 003000, "bgt", -0, BR, 003400, "ble", -0, BR, 0101000, "bhi", -0, BR, 0101400, "blos", -0, BR, 0103000, "bhis", -0, BR, 0103400, "blo", -0, EJMP, 0400, "jbr", -0, EJMP, 01000, "jne", -0, EJMP, 01400, "jeq", -0, EJMP, 0100000, "jpl", -0, EJMP, 0100400, "jmi", -0, EJMP, 0102000, "jvc", -0, EJMP, 0102400, "jvs", -0, EJMP, 0103000, "jcc", -0, EJMP, 0103400, "jcs", -0, EJMP, 02000, "jge", -0, EJMP, 02400, "jlt", -0, EJMP, 03000, "jgt", -0, EJMP, 03400, "jle", -0, EJMP, 0101000, "jhi", -0, EJMP, 0101400, "jlos", -0, EJMP, 0103000, "jhis", -0, EJMP, 0103400, "jlo", -0, JSR, 004000, "jsr", -0, RTS, 000200, "rts", -0, MARK, 006400, "mark", -0, SOB, 077000, "sob", -0, SPL, 0230, "spl", -0, TRAP, 0104000, "emt", -0, TRAP, 0104400, "trap", -0, TRAP, 0104400, "sys", -0, OP_NO, 03, "bpt", -0, OP_NO, 04, "iot", -0, OP_NO, 02, "rti", -0, OP_NO, 06, "rtt", -0, OP_NO, 0, "halt", -0, OP_NO, 01, "wait", -0, OP_NO, 05, "reset", -0, OP_NO, 0170000, "cfcc", -0, OP_NO, 0170002, "seti", -0, OP_NO, 0170012, "setl", -0, OP_NO, 0170001, "setf", -0, OP_NO, 0170011, "setd", -0, CLEARCC, 0241, "clc", -0, CLEARCC, 0242, "clv", -0, CLEARCC, 0244, "clz", -0, CLEARCC, 0250, "cln", -0, SETCC, 0261, "sec", -0, SETCC, 0262, "sev", -0, SETCC, 0264, "sez", -0, SETCC, 0270, "sen", -0, OP_SO_R, 070000, "mul", -0, OP_SO_R, 071000, "div", -0, OP_SO_R, 072000, "ash", -0, OP_SO_R, 073000, "ashc", -0, MFP, 006500, "mfpi", -0, MFP, 0106500, "mfpd", -0, MFP, 006600, "mtpi", -0, MFP, 0106600, "mtpd", -0, FOP_FSO_FR, 0172000, "addf", -0, FOP_FSO_FR, 0173000, "subf", -0, FOP_FSO_FR, 0171000, "mulf", -0, FOP_FSO_FR, 0174400, "divf", -0, FOP_FSO_FR, 0173400, "cmpf", -0, FOP_FSO_FR, 0171400, "modf", -0, FOP_FSO, 0170400, "clrf", -0, FOP_FSO, 0170700, "negf", -0, FOP_FSO, 0170600, "absf", -0, FOP_FSO, 0170500, "tstf", -0, FOP_SO, 0170100, "ldfps", -0, FOP_SO, 0170200, "stfps", -0, FOP_SO, 0170300, "stst", -0, MOVF, 0, "movf", -0, FOP_SO_FR, 0177000, "movif", -0, FOP_SO_FR, 0176400, "movie", -0, FOP_FR_SO, 0175400, "movfi", -0, FOP_FR_SO, 0175000, "movei", -0, FOP_FSO_FR, 0177400, "movof", -0, FOP_FR_FSO, 0176000, "movfo", +{0, REG, 00, "r0"}, +{0, REG, 01, "r1"}, +{0, REG, 02, "r2"}, +{0, REG, 03, "r3"}, +{0, REG, 04, "r4"}, +{0, REG, 05, "r5"}, +{0, REG, 06, "r6"}, +{0, REG, 06, "sp"}, +{0, REG, 07, "r7"}, +{0, REG, 07, "pc"}, +{0, FREG, 00, "fr0"}, +{0, FREG, 01, "fr1"}, +{0, FREG, 02, "fr2"}, +{0, FREG, 03, "fr3"}, +{0, FRSP, 04, "fr4"}, +{0, FRSP, 05, "fr5"}, +{0, OP_SO, 05000, "clr"}, +{0, OP_SO, 0105000, "clrb"}, +{0, OP_SO, 05100, "com"}, +{0, OP_SO, 0105100, "comb"}, +{0, OP_SO, 005200, "inc"}, +{0, OP_SO, 0105200, "incb"}, +{0, OP_SO, 005300, "dec"}, +{0, OP_SO, 0105300, "decb"}, +{0, OP_SO, 005400, "neg"}, +{0, OP_SO, 0105400, "negb"}, +{0, OP_SO, 005700, "tst"}, +{0, OP_SO, 0105700, "tstb"}, +{0, OP_SO, 006200, "asr"}, +{0, OP_SO, 0106200, "asrb"}, +{0, OP_SO, 006300, "asl"}, +{0, OP_SO, 0106300, "aslb"}, +{0, OP_SO, 006000, "ror"}, +{0, OP_SO, 0106000, "rorb"}, +{0, OP_SO, 006100, "rol"}, +{0, OP_SO, 0106100, "rolb"}, +{0, OP_SO, 000300, "swab"}, +{0, OP_SO, 005500, "adc"}, +{0, OP_SO, 0105500, "adcb"}, +{0, OP_SO, 005600, "sbc"}, +{0, OP_SO, 0105600, "sbcb"}, +{0, OP_SO, 006700, "sxt"}, +{0, OP_DO, 010000, "mov"}, +{0, OP_DO, 0110000, "movb"}, +{0, OP_DO, 020000, "cmp"}, +{0, OP_DO, 0120000, "cmpb"}, +{0, OP_DO, 060000, "add"}, +{0, OP_DO, 0160000, "sub"}, +{0, OP_DO, 030000, "bit"}, +{0, OP_DO, 0130000, "bitb"}, +{0, OP_DO, 040000, "bic"}, +{0, OP_DO, 0140000, "bicb"}, +{0, OP_DO, 050000, "bis"}, +{0, OP_DO, 0150000, "bisb"}, +{0, OP_R_SO, 074000, "xor"}, +{0, JMP, 0100, "jmp"}, +{0, BR, 0400, "br"}, +{0, BR, 01000, "bne"}, +{0, BR, 01400, "beq"}, +{0, BR, 0100000, "bpl"}, +{0, BR, 0100400, "bmi"}, +{0, BR, 0102000, "bvc"}, +{0, BR, 0102400, "bvs"}, +{0, BR, 0103000, "bcc"}, +{0, BR, 0103400, "bcs"}, +{0, BR, 002000, "bge"}, +{0, BR, 002400, "blt"}, +{0, BR, 003000, "bgt"}, +{0, BR, 003400, "ble"}, +{0, BR, 0101000, "bhi"}, +{0, BR, 0101400, "blos"}, +{0, BR, 0103000, "bhis"}, +{0, BR, 0103400, "blo"}, +{0, EJMP, 0400, "jbr"}, +{0, EJMP, 01000, "jne"}, +{0, EJMP, 01400, "jeq"}, +{0, EJMP, 0100000, "jpl"}, +{0, EJMP, 0100400, "jmi"}, +{0, EJMP, 0102000, "jvc"}, +{0, EJMP, 0102400, "jvs"}, +{0, EJMP, 0103000, "jcc"}, +{0, EJMP, 0103400, "jcs"}, +{0, EJMP, 02000, "jge"}, +{0, EJMP, 02400, "jlt"}, +{0, EJMP, 03000, "jgt"}, +{0, EJMP, 03400, "jle"}, +{0, EJMP, 0101000, "jhi"}, +{0, EJMP, 0101400, "jlos"}, +{0, EJMP, 0103000, "jhis"}, +{0, EJMP, 0103400, "jlo"}, +{0, JSR, 004000, "jsr"}, +{0, RTS, 000200, "rts"}, +{0, MARK, 006400, "mark"}, +{0, SOB, 077000, "sob"}, +{0, SPL, 0230, "spl"}, +{0, TRAP, 0104000, "emt"}, +{0, TRAP, 0104400, "trap"}, +{0, TRAP, 0104400, "sys"}, +{0, OP_NO, 03, "bpt"}, +{0, OP_NO, 04, "iot"}, +{0, OP_NO, 02, "rti"}, +{0, OP_NO, 06, "rtt"}, +{0, OP_NO, 0, "halt"}, +{0, OP_NO, 01, "wait"}, +{0, OP_NO, 05, "reset"}, +{0, OP_NO, 0170000, "cfcc"}, +{0, OP_NO, 0170002, "seti"}, +{0, OP_NO, 0170012, "setl"}, +{0, OP_NO, 0170001, "setf"}, +{0, OP_NO, 0170011, "setd"}, +{0, CLEARCC, 0241, "clc"}, +{0, CLEARCC, 0242, "clv"}, +{0, CLEARCC, 0244, "clz"}, +{0, CLEARCC, 0250, "cln"}, +{0, SETCC, 0261, "sec"}, +{0, SETCC, 0262, "sev"}, +{0, SETCC, 0264, "sez"}, +{0, SETCC, 0270, "sen"}, +{0, OP_SO_R, 070000, "mul"}, +{0, OP_SO_R, 071000, "div"}, +{0, OP_SO_R, 072000, "ash"}, +{0, OP_SO_R, 073000, "ashc"}, +{0, MFP, 006500, "mfpi"}, +{0, MFP, 0106500, "mfpd"}, +{0, MFP, 006600, "mtpi"}, +{0, MFP, 0106600, "mtpd"}, +{0, FOP_FSO_FR, 0172000, "addf"}, +{0, FOP_FSO_FR, 0173000, "subf"}, +{0, FOP_FSO_FR, 0171000, "mulf"}, +{0, FOP_FSO_FR, 0174400, "divf"}, +{0, FOP_FSO_FR, 0173400, "cmpf"}, +{0, FOP_FSO_FR, 0171400, "modf"}, +{0, FOP_FSO, 0170400, "clrf"}, +{0, FOP_FSO, 0170700, "negf"}, +{0, FOP_FSO, 0170600, "absf"}, +{0, FOP_FSO, 0170500, "tstf"}, +{0, FOP_SO, 0170100, "ldfps"}, +{0, FOP_SO, 0170200, "stfps"}, +{0, FOP_SO, 0170300, "stst"}, +{0, MOVF, 0, "movf"}, +{0, FOP_SO_FR, 0177000, "movif"}, +{0, FOP_SO_FR, 0176400, "movie"}, +{0, FOP_FR_SO, 0175400, "movfi"}, +{0, FOP_FR_SO, 0175000, "movei"}, +{0, FOP_FSO_FR, 0177400, "movof"}, +{0, FOP_FR_FSO, 0176000, "movfo"}, diff --git a/mach/powerpc/as/mach3.c b/mach/powerpc/as/mach3.c index 99507087d..35124e09a 100644 --- a/mach/powerpc/as/mach3.c +++ b/mach/powerpc/as/mach3.c @@ -5,103 +5,103 @@ /* Integer registers */ -0, GPR, 0, "r0", -0, GPR, 1, "r1", -0, GPR, 1, "sp", -0, GPR, 2, "r2", -0, GPR, 2, "fp", -0, GPR, 3, "r3", -0, GPR, 4, "r4", -0, GPR, 5, "r5", -0, GPR, 6, "r6", -0, GPR, 7, "r7", -0, GPR, 8, "r8", -0, GPR, 9, "r9", -0, GPR, 10, "r10", -0, GPR, 11, "r11", -0, GPR, 12, "r12", -0, GPR, 13, "r13", -0, GPR, 14, "r14", -0, GPR, 15, "r15", -0, GPR, 16, "r16", -0, GPR, 17, "r17", -0, GPR, 18, "r18", -0, GPR, 19, "r19", -0, GPR, 20, "r20", -0, GPR, 21, "r21", -0, GPR, 22, "r22", -0, GPR, 23, "r23", -0, GPR, 24, "r24", -0, GPR, 25, "r25", -0, GPR, 26, "r26", -0, GPR, 27, "r27", -0, GPR, 28, "r28", -0, GPR, 29, "r29", -0, GPR, 30, "r30", -0, GPR, 31, "r31", +{0, GPR, 0, "r0"}, +{0, GPR, 1, "r1"}, +{0, GPR, 1, "sp"}, +{0, GPR, 2, "r2"}, +{0, GPR, 2, "fp"}, +{0, GPR, 3, "r3"}, +{0, GPR, 4, "r4"}, +{0, GPR, 5, "r5"}, +{0, GPR, 6, "r6"}, +{0, GPR, 7, "r7"}, +{0, GPR, 8, "r8"}, +{0, GPR, 9, "r9"}, +{0, GPR, 10, "r10"}, +{0, GPR, 11, "r11"}, +{0, GPR, 12, "r12"}, +{0, GPR, 13, "r13"}, +{0, GPR, 14, "r14"}, +{0, GPR, 15, "r15"}, +{0, GPR, 16, "r16"}, +{0, GPR, 17, "r17"}, +{0, GPR, 18, "r18"}, +{0, GPR, 19, "r19"}, +{0, GPR, 20, "r20"}, +{0, GPR, 21, "r21"}, +{0, GPR, 22, "r22"}, +{0, GPR, 23, "r23"}, +{0, GPR, 24, "r24"}, +{0, GPR, 25, "r25"}, +{0, GPR, 26, "r26"}, +{0, GPR, 27, "r27"}, +{0, GPR, 28, "r28"}, +{0, GPR, 29, "r29"}, +{0, GPR, 30, "r30"}, +{0, GPR, 31, "r31"}, /* Floating-point registers */ -0, FPR, 0, "f0", -0, FPR, 1, "f1", -0, FPR, 2, "f2", -0, FPR, 3, "f3", -0, FPR, 4, "f4", -0, FPR, 5, "f5", -0, FPR, 6, "f6", -0, FPR, 7, "f7", -0, FPR, 8, "f8", -0, FPR, 9, "f9", -0, FPR, 10, "f10", -0, FPR, 11, "f11", -0, FPR, 12, "f12", -0, FPR, 13, "f13", -0, FPR, 14, "f14", -0, FPR, 15, "f15", -0, FPR, 16, "f16", -0, FPR, 17, "f17", -0, FPR, 18, "f18", -0, FPR, 19, "f19", -0, FPR, 20, "f20", -0, FPR, 21, "f21", -0, FPR, 22, "f22", -0, FPR, 23, "f23", -0, FPR, 24, "f24", -0, FPR, 25, "f25", -0, FPR, 26, "f26", -0, FPR, 27, "f27", -0, FPR, 28, "f28", -0, FPR, 29, "f29", -0, FPR, 30, "f30", -0, FPR, 31, "f31", +{0, FPR, 0, "f0"}, +{0, FPR, 1, "f1"}, +{0, FPR, 2, "f2"}, +{0, FPR, 3, "f3"}, +{0, FPR, 4, "f4"}, +{0, FPR, 5, "f5"}, +{0, FPR, 6, "f6"}, +{0, FPR, 7, "f7"}, +{0, FPR, 8, "f8"}, +{0, FPR, 9, "f9"}, +{0, FPR, 10, "f10"}, +{0, FPR, 11, "f11"}, +{0, FPR, 12, "f12"}, +{0, FPR, 13, "f13"}, +{0, FPR, 14, "f14"}, +{0, FPR, 15, "f15"}, +{0, FPR, 16, "f16"}, +{0, FPR, 17, "f17"}, +{0, FPR, 18, "f18"}, +{0, FPR, 19, "f19"}, +{0, FPR, 20, "f20"}, +{0, FPR, 21, "f21"}, +{0, FPR, 22, "f22"}, +{0, FPR, 23, "f23"}, +{0, FPR, 24, "f24"}, +{0, FPR, 25, "f25"}, +{0, FPR, 26, "f26"}, +{0, FPR, 27, "f27"}, +{0, FPR, 28, "f28"}, +{0, FPR, 29, "f29"}, +{0, FPR, 30, "f30"}, +{0, FPR, 31, "f31"}, /* Special registers */ -0, SPR, 32, "xer", -0, SPR, 256, "lr", -0, SPR, 288, "ctr", +{0, SPR, 32, "xer"}, +{0, SPR, 256, "lr"}, +{0, SPR, 288, "ctr"}, /* Condition registers */ -0, CR, 0, "cr0", -0, CR, 1, "cr1", -0, CR, 2, "cr2", -0, CR, 3, "cr3", -0, CR, 4, "cr4", -0, CR, 5, "cr5", -0, CR, 6, "cr6", -0, CR, 7, "cr7", +{0, CR, 0, "cr0"}, +{0, CR, 1, "cr1"}, +{0, CR, 2, "cr2"}, +{0, CR, 3, "cr3"}, +{0, CR, 4, "cr4"}, +{0, CR, 5, "cr5"}, +{0, CR, 6, "cr6"}, +{0, CR, 7, "cr7"}, /* Condition code flag */ -0, C, 0, ".", +{0, C, 0, "."}, /* Special instructions */ -0, OP_LI32, 0, "li32", -0, OP_HI, 0, "hi16", -0, OP_HA, 0, "ha16", -0, OP_LO, 0, "lo16", +{0, OP_LI32, 0, "li32"}, +{0, OP_HI, 0, "hi16"}, +{0, OP_HA, 0, "ha16"}, +{0, OP_LO, 0, "lo16"}, /* The next page numbers are from PowerPC User Instruction Set * Architecture, Book I, Version 2.01. @@ -109,583 +109,583 @@ /* Branch processor instructions (page 20) */ -0, OP_LIL, 18<<26 | 0<<1 | 0<<0, "b", -0, OP_LIA, 18<<26 | 1<<1 | 0<<0, "ba", -0, OP_LIL, 18<<26 | 0<<1 | 1<<0, "bl", -0, OP_LIA, 18<<26 | 1<<1 | 1<<0, "bla", -0, OP_BO_BI_BDL, 16<<26 | 0<<1 | 0<<0, "bc", -0, OP_BO_BI_BDA, 16<<26 | 1<<1 | 0<<0, "bca", -0, OP_BO_BI_BDL, 16<<26 | 0<<1 | 1<<0, "bcl", -0, OP_BO_BI_BDA, 16<<26 | 1<<1 | 1<<0, "bcla", -0, OP_BO_BI_BH, 19<<26 | 16<<1 | 0<<0, "bclr", -0, OP_BO_BI_BH, 19<<26 | 16<<1 | 1<<0, "bclrl", -0, OP_BO_BI_BH, 19<<26 | 528<<1 | 0<<0, "bcctr", -0, OP_BO_BI_BH, 19<<26 | 528<<1 | 1<<0, "bcctrl", -0, OP_LEV, 17<<26 | 1<<1, "sc", -0, OP_BT_BA_BB, 19<<26 | 257<<1, "crand", -0, OP_BT_BA_BB, 19<<26 | 449<<1, "cror", -0, OP_BT_BA_BB, 19<<26 | 193<<1, "crxor", -0, OP_BT_BA_BB, 19<<26 | 225<<1, "crnand", -0, OP_BT_BA_BB, 19<<26 | 33<<1, "crnor", -0, OP_BT_BA_BB, 19<<26 | 289<<1, "creqv", -0, OP_BT_BA_BB, 19<<26 | 129<<1, "crandc", -0, OP_BT_BA_BB, 19<<26 | 417<<1, "crorc", -0, OP_BF_BFA, 19<<26 | 0<<1, "mcrf", +{0, OP_LIL, 18<<26 | 0<<1 | 0<<0, "b"}, +{0, OP_LIA, 18<<26 | 1<<1 | 0<<0, "ba"}, +{0, OP_LIL, 18<<26 | 0<<1 | 1<<0, "bl"}, +{0, OP_LIA, 18<<26 | 1<<1 | 1<<0, "bla"}, +{0, OP_BO_BI_BDL, 16<<26 | 0<<1 | 0<<0, "bc"}, +{0, OP_BO_BI_BDA, 16<<26 | 1<<1 | 0<<0, "bca"}, +{0, OP_BO_BI_BDL, 16<<26 | 0<<1 | 1<<0, "bcl"}, +{0, OP_BO_BI_BDA, 16<<26 | 1<<1 | 1<<0, "bcla"}, +{0, OP_BO_BI_BH, 19<<26 | 16<<1 | 0<<0, "bclr"}, +{0, OP_BO_BI_BH, 19<<26 | 16<<1 | 1<<0, "bclrl"}, +{0, OP_BO_BI_BH, 19<<26 | 528<<1 | 0<<0, "bcctr"}, +{0, OP_BO_BI_BH, 19<<26 | 528<<1 | 1<<0, "bcctrl"}, +{0, OP_LEV, 17<<26 | 1<<1, "sc"}, +{0, OP_BT_BA_BB, 19<<26 | 257<<1, "crand"}, +{0, OP_BT_BA_BB, 19<<26 | 449<<1, "cror"}, +{0, OP_BT_BA_BB, 19<<26 | 193<<1, "crxor"}, +{0, OP_BT_BA_BB, 19<<26 | 225<<1, "crnand"}, +{0, OP_BT_BA_BB, 19<<26 | 33<<1, "crnor"}, +{0, OP_BT_BA_BB, 19<<26 | 289<<1, "creqv"}, +{0, OP_BT_BA_BB, 19<<26 | 129<<1, "crandc"}, +{0, OP_BT_BA_BB, 19<<26 | 417<<1, "crorc"}, +{0, OP_BF_BFA, 19<<26 | 0<<1, "mcrf"}, /* extended mnemonics for bc, bcctr, bclr (page 144) */ -0, OP_BH, 19<<26 | 20<<21 | 528<<1 | 0<<0, "bctr", -0, OP_BH, 19<<26 | 20<<21 | 528<<1 | 1<<0, "bctrl", -0, OP_BDL, 16<<26 | 16<<21 | 0<<1 | 0<<0, "bdnz", -0, OP_BDA, 16<<26 | 16<<21 | 1<<1 | 0<<0, "bdnza", -0, OP_BH, 19<<26 | 16<<21 | 16<<1 | 0<<0, "bdnzlr", -0, OP_BDL, 16<<26 | 16<<21 | 0<<1 | 1<<0, "bdnzl", -0, OP_BDA, 16<<26 | 16<<21 | 1<<1 | 1<<0, "bdnzla", -0, OP_BH, 19<<26 | 16<<21 | 16<<1 | 1<<0, "bdnzlrl", -0, OP_BI_BDL, 16<<26 | 0<<21 | 0<<1 | 0<<0, "bdnzf", -0, OP_BI_BDA, 16<<26 | 0<<21 | 1<<1 | 0<<0, "bdnzfa", -0, OP_BI_BH, 19<<26 | 0<<21 | 16<<1 | 0<<0, "bdnzflr", -0, OP_BI_BDL, 16<<26 | 0<<21 | 0<<1 | 1<<0, "bdnzfl", -0, OP_BI_BDA, 16<<26 | 0<<21 | 1<<1 | 1<<0, "bdnzfla", -0, OP_BI_BH, 19<<26 | 0<<21 | 16<<1 | 1<<0, "bdnzflrl", -0, OP_BI_BDL, 16<<26 | 8<<21 | 0<<1 | 0<<0, "bdnzt", -0, OP_BI_BDA, 16<<26 | 8<<21 | 1<<1 | 0<<0, "bdnzta", -0, OP_BI_BH, 19<<26 | 8<<21 | 16<<1 | 0<<0, "bdnztlr", -0, OP_BI_BDL, 16<<26 | 8<<21 | 0<<1 | 1<<0, "bdnztl", -0, OP_BI_BDA, 16<<26 | 8<<21 | 1<<1 | 1<<0, "bdnztla", -0, OP_BI_BH, 19<<26 | 8<<21 | 16<<1 | 1<<0, "bdnztlrl", -0, OP_BDL, 16<<26 | 18<<21 | 0<<1 | 0<<0, "bdz", -0, OP_BDA, 16<<26 | 18<<21 | 1<<1 | 0<<0, "bdza", -0, OP_BH, 19<<26 | 18<<21 | 16<<1 | 0<<0, "bdzlr", -0, OP_BDL, 16<<26 | 18<<21 | 0<<1 | 1<<0, "bdzl", -0, OP_BDA, 16<<26 | 18<<21 | 1<<1 | 1<<0, "bdzla", -0, OP_BH, 19<<26 | 18<<21 | 16<<1 | 1<<0, "bdzlrl", -0, OP_BI_BDL, 16<<26 | 2<<21 | 0<<1 | 0<<0, "bdzf", -0, OP_BI_BDA, 16<<26 | 2<<21 | 1<<1 | 0<<0, "bdzfa", -0, OP_BI_BH, 19<<26 | 2<<21 | 16<<1 | 0<<0, "bdzflr", -0, OP_BI_BDL, 16<<26 | 2<<21 | 0<<1 | 1<<0, "bdzfl", -0, OP_BI_BDA, 16<<26 | 2<<21 | 1<<1 | 1<<0, "bdzfla", -0, OP_BI_BH, 19<<26 | 2<<21 | 16<<1 | 1<<0, "bdzflrl", -0, OP_BI_BDL, 16<<26 | 10<<21 | 0<<1 | 0<<0, "bdzt", -0, OP_BI_BDA, 16<<26 | 10<<21 | 1<<1 | 0<<0, "bdzta", -0, OP_BI_BH, 19<<26 | 10<<21 | 16<<1 | 0<<0, "bdztlr", -0, OP_BI_BDL, 16<<26 | 10<<21 | 0<<1 | 1<<0, "bdztl", -0, OP_BI_BDA, 16<<26 | 10<<21 | 1<<1 | 1<<0, "bdztla", -0, OP_BI_BH, 19<<26 | 10<<21 | 16<<1 | 1<<0, "bdztlrl", -0, OP_BI_BDL, 16<<26 | 4<<21 | 0<<1 | 0<<0, "bf", -0, OP_BI_BDA, 16<<26 | 4<<21 | 1<<1 | 0<<0, "bfa", -0, OP_BI_BH, 19<<26 | 4<<21 | 528<<1 | 0<<0, "bfctr", -0, OP_BI_BH, 19<<26 | 4<<21 | 528<<1 | 1<<0, "bfctrl", -0, OP_BI_BDL, 16<<26 | 4<<21 | 0<<1 | 1<<0, "bfl", -0, OP_BI_BDA, 16<<26 | 4<<21 | 0<<1 | 1<<0, "bfla", -0, OP_BI_BH, 19<<26 | 4<<21 | 16<<1 | 0<<0, "bflr", -0, OP_BI_BH, 19<<26 | 4<<21 | 16<<1 | 1<<0, "bflrl", -0, OP_BH, 19<<26 | 20<<21 | 16<<1 | 0<<0, "blr", -0, OP_BH, 19<<26 | 20<<21 | 16<<1 | 1<<0, "blrl", -0, OP_BI_BDL, 16<<26 | 12<<21 | 0<<1 | 0<<0, "bt", -0, OP_BI_BDA, 16<<26 | 12<<21 | 1<<1 | 0<<0, "bta", -0, OP_BI_BH, 19<<26 | 12<<21 | 528<<1 | 0<<0, "btctr", -0, OP_BI_BH, 19<<26 | 12<<21 | 528<<1 | 1<<0, "btctrl", -0, OP_BI_BDL, 16<<26 | 12<<21 | 0<<1 | 1<<0, "btl", -0, OP_BI_BDA, 16<<26 | 12<<21 | 0<<1 | 1<<0, "btla", -0, OP_BI_BH, 19<<26 | 12<<21 | 16<<1 | 0<<0, "btlr", -0, OP_BI_BH, 19<<26 | 12<<21 | 16<<1 | 1<<0, "btlrl", +{0, OP_BH, 19<<26 | 20<<21 | 528<<1 | 0<<0, "bctr"}, +{0, OP_BH, 19<<26 | 20<<21 | 528<<1 | 1<<0, "bctrl"}, +{0, OP_BDL, 16<<26 | 16<<21 | 0<<1 | 0<<0, "bdnz"}, +{0, OP_BDA, 16<<26 | 16<<21 | 1<<1 | 0<<0, "bdnza"}, +{0, OP_BH, 19<<26 | 16<<21 | 16<<1 | 0<<0, "bdnzlr"}, +{0, OP_BDL, 16<<26 | 16<<21 | 0<<1 | 1<<0, "bdnzl"}, +{0, OP_BDA, 16<<26 | 16<<21 | 1<<1 | 1<<0, "bdnzla"}, +{0, OP_BH, 19<<26 | 16<<21 | 16<<1 | 1<<0, "bdnzlrl"}, +{0, OP_BI_BDL, 16<<26 | 0<<21 | 0<<1 | 0<<0, "bdnzf"}, +{0, OP_BI_BDA, 16<<26 | 0<<21 | 1<<1 | 0<<0, "bdnzfa"}, +{0, OP_BI_BH, 19<<26 | 0<<21 | 16<<1 | 0<<0, "bdnzflr"}, +{0, OP_BI_BDL, 16<<26 | 0<<21 | 0<<1 | 1<<0, "bdnzfl"}, +{0, OP_BI_BDA, 16<<26 | 0<<21 | 1<<1 | 1<<0, "bdnzfla"}, +{0, OP_BI_BH, 19<<26 | 0<<21 | 16<<1 | 1<<0, "bdnzflrl"}, +{0, OP_BI_BDL, 16<<26 | 8<<21 | 0<<1 | 0<<0, "bdnzt"}, +{0, OP_BI_BDA, 16<<26 | 8<<21 | 1<<1 | 0<<0, "bdnzta"}, +{0, OP_BI_BH, 19<<26 | 8<<21 | 16<<1 | 0<<0, "bdnztlr"}, +{0, OP_BI_BDL, 16<<26 | 8<<21 | 0<<1 | 1<<0, "bdnztl"}, +{0, OP_BI_BDA, 16<<26 | 8<<21 | 1<<1 | 1<<0, "bdnztla"}, +{0, OP_BI_BH, 19<<26 | 8<<21 | 16<<1 | 1<<0, "bdnztlrl"}, +{0, OP_BDL, 16<<26 | 18<<21 | 0<<1 | 0<<0, "bdz"}, +{0, OP_BDA, 16<<26 | 18<<21 | 1<<1 | 0<<0, "bdza"}, +{0, OP_BH, 19<<26 | 18<<21 | 16<<1 | 0<<0, "bdzlr"}, +{0, OP_BDL, 16<<26 | 18<<21 | 0<<1 | 1<<0, "bdzl"}, +{0, OP_BDA, 16<<26 | 18<<21 | 1<<1 | 1<<0, "bdzla"}, +{0, OP_BH, 19<<26 | 18<<21 | 16<<1 | 1<<0, "bdzlrl"}, +{0, OP_BI_BDL, 16<<26 | 2<<21 | 0<<1 | 0<<0, "bdzf"}, +{0, OP_BI_BDA, 16<<26 | 2<<21 | 1<<1 | 0<<0, "bdzfa"}, +{0, OP_BI_BH, 19<<26 | 2<<21 | 16<<1 | 0<<0, "bdzflr"}, +{0, OP_BI_BDL, 16<<26 | 2<<21 | 0<<1 | 1<<0, "bdzfl"}, +{0, OP_BI_BDA, 16<<26 | 2<<21 | 1<<1 | 1<<0, "bdzfla"}, +{0, OP_BI_BH, 19<<26 | 2<<21 | 16<<1 | 1<<0, "bdzflrl"}, +{0, OP_BI_BDL, 16<<26 | 10<<21 | 0<<1 | 0<<0, "bdzt"}, +{0, OP_BI_BDA, 16<<26 | 10<<21 | 1<<1 | 0<<0, "bdzta"}, +{0, OP_BI_BH, 19<<26 | 10<<21 | 16<<1 | 0<<0, "bdztlr"}, +{0, OP_BI_BDL, 16<<26 | 10<<21 | 0<<1 | 1<<0, "bdztl"}, +{0, OP_BI_BDA, 16<<26 | 10<<21 | 1<<1 | 1<<0, "bdztla"}, +{0, OP_BI_BH, 19<<26 | 10<<21 | 16<<1 | 1<<0, "bdztlrl"}, +{0, OP_BI_BDL, 16<<26 | 4<<21 | 0<<1 | 0<<0, "bf"}, +{0, OP_BI_BDA, 16<<26 | 4<<21 | 1<<1 | 0<<0, "bfa"}, +{0, OP_BI_BH, 19<<26 | 4<<21 | 528<<1 | 0<<0, "bfctr"}, +{0, OP_BI_BH, 19<<26 | 4<<21 | 528<<1 | 1<<0, "bfctrl"}, +{0, OP_BI_BDL, 16<<26 | 4<<21 | 0<<1 | 1<<0, "bfl"}, +{0, OP_BI_BDA, 16<<26 | 4<<21 | 0<<1 | 1<<0, "bfla"}, +{0, OP_BI_BH, 19<<26 | 4<<21 | 16<<1 | 0<<0, "bflr"}, +{0, OP_BI_BH, 19<<26 | 4<<21 | 16<<1 | 1<<0, "bflrl"}, +{0, OP_BH, 19<<26 | 20<<21 | 16<<1 | 0<<0, "blr"}, +{0, OP_BH, 19<<26 | 20<<21 | 16<<1 | 1<<0, "blrl"}, +{0, OP_BI_BDL, 16<<26 | 12<<21 | 0<<1 | 0<<0, "bt"}, +{0, OP_BI_BDA, 16<<26 | 12<<21 | 1<<1 | 0<<0, "bta"}, +{0, OP_BI_BH, 19<<26 | 12<<21 | 528<<1 | 0<<0, "btctr"}, +{0, OP_BI_BH, 19<<26 | 12<<21 | 528<<1 | 1<<0, "btctrl"}, +{0, OP_BI_BDL, 16<<26 | 12<<21 | 0<<1 | 1<<0, "btl"}, +{0, OP_BI_BDA, 16<<26 | 12<<21 | 0<<1 | 1<<0, "btla"}, +{0, OP_BI_BH, 19<<26 | 12<<21 | 16<<1 | 0<<0, "btlr"}, +{0, OP_BI_BH, 19<<26 | 12<<21 | 16<<1 | 1<<0, "btlrl"}, /* extended m with condition in BI (page 146) */ -0, OP_BICR_BDL, 16<<26 | 12<<21 | 2<<16 | 0<<1 | 0<<0, "beq", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 2<<16 | 1<<1 | 0<<0, "beqa", -0, OP_BICR_BH, 19<<26 | 12<<21 | 2<<16 | 528<<1 | 0<<0, "beqctr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 2<<16 | 528<<1 | 1<<0, "beqctrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 2<<16 | 0<<1 | 1<<0, "beql", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 2<<16 | 1<<1 | 1<<0, "beqla", -0, OP_BICR_BH, 19<<26 | 12<<21 | 2<<16 | 16<<1 | 0<<0, "beqlr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 2<<16 | 16<<1 | 1<<0, "beqlrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 0<<16 | 0<<1 | 0<<0, "bge", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 0<<16 | 1<<1 | 0<<0, "bgea", -0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 528<<1 | 0<<0, "bgectr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 528<<1 | 1<<0, "bgectrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 0<<16 | 0<<1 | 1<<0, "bgel", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 0<<16 | 1<<1 | 1<<0, "bgela", -0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 16<<1 | 0<<0, "bgelr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 16<<1 | 1<<0, "bgelrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 1<<16 | 0<<1 | 0<<0, "bgt", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 1<<16 | 1<<1 | 0<<0, "bgta", -0, OP_BICR_BH, 19<<26 | 12<<21 | 1<<16 | 528<<1 | 0<<0, "bgtctr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 1<<16 | 528<<1 | 1<<0, "bgtctrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 1<<16 | 0<<1 | 1<<0, "bgtl", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 1<<16 | 1<<1 | 1<<0, "bgtla", -0, OP_BICR_BH, 19<<26 | 12<<21 | 1<<16 | 16<<1 | 0<<0, "bgtlr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 1<<16 | 16<<1 | 1<<0, "bgtlrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 1<<16 | 0<<1 | 0<<0, "ble", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 1<<16 | 1<<1 | 0<<0, "blea", -0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 528<<1 | 0<<0, "blectr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 528<<1 | 1<<0, "blectrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 1<<16 | 0<<1 | 1<<0, "blel", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 1<<16 | 1<<1 | 1<<0, "blela", -0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 16<<1 | 0<<0, "blelr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 16<<1 | 1<<0, "blelrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 0<<16 | 0<<1 | 0<<0, "blt", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 0<<16 | 1<<1 | 0<<0, "blta", -0, OP_BICR_BH, 19<<26 | 12<<21 | 0<<16 | 528<<1 | 0<<0, "bltctr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 0<<16 | 528<<1 | 1<<0, "bltctrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 0<<16 | 0<<1 | 1<<0, "bltl", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 0<<16 | 1<<1 | 1<<0, "bltla", -0, OP_BICR_BH, 19<<26 | 12<<21 | 0<<16 | 16<<1 | 0<<0, "bltlr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 0<<16 | 16<<1 | 1<<0, "bltlrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 2<<16 | 0<<1 | 0<<0, "bne", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 2<<16 | 1<<1 | 0<<0, "bnea", -0, OP_BICR_BH, 19<<26 | 4<<21 | 2<<16 | 528<<1 | 0<<0, "bnectr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 2<<16 | 528<<1 | 1<<0, "bnectrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 2<<16 | 0<<1 | 1<<0, "bnel", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 2<<16 | 1<<1 | 1<<0, "bnela", -0, OP_BICR_BH, 19<<26 | 4<<21 | 2<<16 | 16<<1 | 0<<0, "bnelr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 2<<16 | 16<<1 | 1<<0, "bnelrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 1<<16 | 0<<1 | 0<<0, "bng", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 1<<16 | 1<<1 | 0<<0, "bnga", -0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 528<<1 | 0<<0, "bngctr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 528<<1 | 1<<0, "bngctrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 1<<16 | 0<<1 | 1<<0, "bngl", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 1<<16 | 1<<1 | 1<<0, "bngla", -0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 16<<1 | 0<<0, "bnglr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 16<<1 | 1<<0, "bnglrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 0<<16 | 0<<1 | 0<<0, "bnl", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 0<<16 | 1<<1 | 0<<0, "bnla", -0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 528<<1 | 0<<0, "bnlctr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 528<<1 | 1<<0, "bnlctrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 0<<16 | 0<<1 | 1<<0, "bnll", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 0<<16 | 1<<1 | 1<<0, "bnlla", -0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 16<<1 | 0<<0, "bnllr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 16<<1 | 1<<0, "bnllrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 3<<16 | 0<<1 | 0<<0, "bns", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 3<<16 | 1<<1 | 0<<0, "bnsa", -0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 528<<1 | 0<<0, "bnsctr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 528<<1 | 1<<0, "bnsctrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 3<<16 | 0<<1 | 1<<0, "bnsl", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 3<<16 | 1<<1 | 1<<0, "bnsla", -0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 16<<1 | 0<<0, "bnslr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 16<<1 | 1<<0, "bnslrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 3<<16 | 0<<1 | 0<<0, "bnu", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 3<<16 | 1<<1 | 0<<0, "bnua", -0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 528<<1 | 0<<0, "bnuctr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 528<<1 | 1<<0, "bnuctrl", -0, OP_BICR_BDL, 16<<26 | 4<<21 | 3<<16 | 0<<1 | 1<<0, "bnul", -0, OP_BICR_BDA, 16<<26 | 4<<21 | 3<<16 | 1<<1 | 1<<0, "bnula", -0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 16<<1 | 0<<0, "bnulr", -0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 16<<1 | 1<<0, "bnulrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 3<<16 | 0<<1 | 0<<0, "bso", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 3<<16 | 1<<1 | 0<<0, "bsoa", -0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 528<<1 | 0<<0, "bsoctr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 528<<1 | 1<<0, "bsoctrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 3<<16 | 0<<1 | 1<<0, "bsol", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 3<<16 | 1<<1 | 1<<0, "bsola", -0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 16<<1 | 0<<0, "bsolr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 16<<1 | 1<<0, "bsolrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 3<<16 | 0<<1 | 0<<0, "bun", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 3<<16 | 1<<1 | 0<<0, "buna", -0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 528<<1 | 0<<0, "bunctr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 528<<1 | 1<<0, "bunctrl", -0, OP_BICR_BDL, 16<<26 | 12<<21 | 3<<16 | 0<<1 | 1<<0, "bunl", -0, OP_BICR_BDA, 16<<26 | 12<<21 | 3<<16 | 1<<1 | 1<<0, "bunla", -0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 16<<1 | 0<<0, "bunlr", -0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 16<<1 | 1<<0, "bunlrl", +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 2<<16 | 0<<1 | 0<<0, "beq"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 2<<16 | 1<<1 | 0<<0, "beqa"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 2<<16 | 528<<1 | 0<<0, "beqctr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 2<<16 | 528<<1 | 1<<0, "beqctrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 2<<16 | 0<<1 | 1<<0, "beql"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 2<<16 | 1<<1 | 1<<0, "beqla"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 2<<16 | 16<<1 | 0<<0, "beqlr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 2<<16 | 16<<1 | 1<<0, "beqlrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 0<<16 | 0<<1 | 0<<0, "bge"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 0<<16 | 1<<1 | 0<<0, "bgea"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 528<<1 | 0<<0, "bgectr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 528<<1 | 1<<0, "bgectrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 0<<16 | 0<<1 | 1<<0, "bgel"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 0<<16 | 1<<1 | 1<<0, "bgela"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 16<<1 | 0<<0, "bgelr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 16<<1 | 1<<0, "bgelrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 1<<16 | 0<<1 | 0<<0, "bgt"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 1<<16 | 1<<1 | 0<<0, "bgta"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 1<<16 | 528<<1 | 0<<0, "bgtctr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 1<<16 | 528<<1 | 1<<0, "bgtctrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 1<<16 | 0<<1 | 1<<0, "bgtl"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 1<<16 | 1<<1 | 1<<0, "bgtla"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 1<<16 | 16<<1 | 0<<0, "bgtlr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 1<<16 | 16<<1 | 1<<0, "bgtlrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 1<<16 | 0<<1 | 0<<0, "ble"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 1<<16 | 1<<1 | 0<<0, "blea"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 528<<1 | 0<<0, "blectr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 528<<1 | 1<<0, "blectrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 1<<16 | 0<<1 | 1<<0, "blel"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 1<<16 | 1<<1 | 1<<0, "blela"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 16<<1 | 0<<0, "blelr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 16<<1 | 1<<0, "blelrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 0<<16 | 0<<1 | 0<<0, "blt"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 0<<16 | 1<<1 | 0<<0, "blta"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 0<<16 | 528<<1 | 0<<0, "bltctr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 0<<16 | 528<<1 | 1<<0, "bltctrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 0<<16 | 0<<1 | 1<<0, "bltl"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 0<<16 | 1<<1 | 1<<0, "bltla"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 0<<16 | 16<<1 | 0<<0, "bltlr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 0<<16 | 16<<1 | 1<<0, "bltlrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 2<<16 | 0<<1 | 0<<0, "bne"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 2<<16 | 1<<1 | 0<<0, "bnea"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 2<<16 | 528<<1 | 0<<0, "bnectr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 2<<16 | 528<<1 | 1<<0, "bnectrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 2<<16 | 0<<1 | 1<<0, "bnel"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 2<<16 | 1<<1 | 1<<0, "bnela"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 2<<16 | 16<<1 | 0<<0, "bnelr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 2<<16 | 16<<1 | 1<<0, "bnelrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 1<<16 | 0<<1 | 0<<0, "bng"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 1<<16 | 1<<1 | 0<<0, "bnga"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 528<<1 | 0<<0, "bngctr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 528<<1 | 1<<0, "bngctrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 1<<16 | 0<<1 | 1<<0, "bngl"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 1<<16 | 1<<1 | 1<<0, "bngla"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 16<<1 | 0<<0, "bnglr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 1<<16 | 16<<1 | 1<<0, "bnglrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 0<<16 | 0<<1 | 0<<0, "bnl"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 0<<16 | 1<<1 | 0<<0, "bnla"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 528<<1 | 0<<0, "bnlctr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 528<<1 | 1<<0, "bnlctrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 0<<16 | 0<<1 | 1<<0, "bnll"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 0<<16 | 1<<1 | 1<<0, "bnlla"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 16<<1 | 0<<0, "bnllr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 0<<16 | 16<<1 | 1<<0, "bnllrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 3<<16 | 0<<1 | 0<<0, "bns"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 3<<16 | 1<<1 | 0<<0, "bnsa"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 528<<1 | 0<<0, "bnsctr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 528<<1 | 1<<0, "bnsctrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 3<<16 | 0<<1 | 1<<0, "bnsl"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 3<<16 | 1<<1 | 1<<0, "bnsla"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 16<<1 | 0<<0, "bnslr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 16<<1 | 1<<0, "bnslrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 3<<16 | 0<<1 | 0<<0, "bnu"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 3<<16 | 1<<1 | 0<<0, "bnua"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 528<<1 | 0<<0, "bnuctr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 528<<1 | 1<<0, "bnuctrl"}, +{0, OP_BICR_BDL, 16<<26 | 4<<21 | 3<<16 | 0<<1 | 1<<0, "bnul"}, +{0, OP_BICR_BDA, 16<<26 | 4<<21 | 3<<16 | 1<<1 | 1<<0, "bnula"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 16<<1 | 0<<0, "bnulr"}, +{0, OP_BICR_BH, 19<<26 | 4<<21 | 3<<16 | 16<<1 | 1<<0, "bnulrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 3<<16 | 0<<1 | 0<<0, "bso"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 3<<16 | 1<<1 | 0<<0, "bsoa"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 528<<1 | 0<<0, "bsoctr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 528<<1 | 1<<0, "bsoctrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 3<<16 | 0<<1 | 1<<0, "bsol"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 3<<16 | 1<<1 | 1<<0, "bsola"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 16<<1 | 0<<0, "bsolr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 16<<1 | 1<<0, "bsolrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 3<<16 | 0<<1 | 0<<0, "bun"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 3<<16 | 1<<1 | 0<<0, "buna"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 528<<1 | 0<<0, "bunctr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 528<<1 | 1<<0, "bunctrl"}, +{0, OP_BICR_BDL, 16<<26 | 12<<21 | 3<<16 | 0<<1 | 1<<0, "bunl"}, +{0, OP_BICR_BDA, 16<<26 | 12<<21 | 3<<16 | 1<<1 | 1<<0, "bunla"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 16<<1 | 0<<0, "bunlr"}, +{0, OP_BICR_BH, 19<<26 | 12<<21 | 3<<16 | 16<<1 | 1<<0, "bunlrl"}, /* extended m for cr logic (page 147) */ -0, OP_BT_BT_BT, 19<<26 | 289<<1, "crset", -0, OP_BT_BT_BT, 19<<26 | 193<<1, "crclr", -0, OP_BT_BA_BA, 19<<26 | 449<<1, "crmove", -0, OP_BT_BA_BA, 19<<26 | 33<<1, "crnot", +{0, OP_BT_BT_BT, 19<<26 | 289<<1, "crset"}, +{0, OP_BT_BT_BT, 19<<26 | 193<<1, "crclr"}, +{0, OP_BT_BA_BA, 19<<26 | 449<<1, "crmove"}, +{0, OP_BT_BA_BA, 19<<26 | 33<<1, "crnot"}, /* Fixed point instructions (page 29) */ -0, OP_RT_RA_D, 34<<26, "lbz", -0, OP_RT_RA_RB, 31<<26 | 87<<1, "lbzx", -0, OP_RT_RA_D, 35<<26, "lbzu", -0, OP_RT_RA_RB, 31<<26 | 119<<1, "lbzux", -0, OP_RT_RA_D, 40<<26, "lhz", -0, OP_RT_RA_RB, 31<<26 | 279<<1, "lhzx", -0, OP_RT_RA_D, 41<<26, "lhzu", -0, OP_RT_RA_RB, 31<<26 | 311<<1, "lhzux", -0, OP_RT_RA_D, 42<<26, "lha", -0, OP_RT_RA_RB, 31<<26 | 343<<1, "lhax", -0, OP_RT_RA_D, 43<<26, "lhau", -0, OP_RT_RA_RB, 31<<26 | 375<<1, "lhaux", -0, OP_RT_RA_D, 32<<26, "lwz", -0, OP_RT_RA_RB, 31<<26 | 23<<1, "lwzx", -0, OP_RT_RA_D, 33<<26, "lwzu", -0, OP_RT_RA_RB, 31<<26 | 55<<1, "lwzux", -0, OP_RT_RA_DS, 58<<26 | 2<<0, "lwa", -0, OP_RT_RA_RB, 31<<26 | 341<<1, "lwax", -0, OP_RT_RA_RB, 31<<26 | 363<<1, "lwaux", -0, OP_RT_RA_DS, 58<<26, "ld", -0, OP_RT_RA_RB, 31<<26 | 21<<1, "ldx", -0, OP_RT_RA_DS, 58<<26 | 1<<0, "ldu", -0, OP_RT_RA_RB, 31<<26 | 53<<1, "ldux", +{0, OP_RT_RA_D, 34<<26, "lbz"}, +{0, OP_RT_RA_RB, 31<<26 | 87<<1, "lbzx"}, +{0, OP_RT_RA_D, 35<<26, "lbzu"}, +{0, OP_RT_RA_RB, 31<<26 | 119<<1, "lbzux"}, +{0, OP_RT_RA_D, 40<<26, "lhz"}, +{0, OP_RT_RA_RB, 31<<26 | 279<<1, "lhzx"}, +{0, OP_RT_RA_D, 41<<26, "lhzu"}, +{0, OP_RT_RA_RB, 31<<26 | 311<<1, "lhzux"}, +{0, OP_RT_RA_D, 42<<26, "lha"}, +{0, OP_RT_RA_RB, 31<<26 | 343<<1, "lhax"}, +{0, OP_RT_RA_D, 43<<26, "lhau"}, +{0, OP_RT_RA_RB, 31<<26 | 375<<1, "lhaux"}, +{0, OP_RT_RA_D, 32<<26, "lwz"}, +{0, OP_RT_RA_RB, 31<<26 | 23<<1, "lwzx"}, +{0, OP_RT_RA_D, 33<<26, "lwzu"}, +{0, OP_RT_RA_RB, 31<<26 | 55<<1, "lwzux"}, +{0, OP_RT_RA_DS, 58<<26 | 2<<0, "lwa"}, +{0, OP_RT_RA_RB, 31<<26 | 341<<1, "lwax"}, +{0, OP_RT_RA_RB, 31<<26 | 363<<1, "lwaux"}, +{0, OP_RT_RA_DS, 58<<26, "ld"}, +{0, OP_RT_RA_RB, 31<<26 | 21<<1, "ldx"}, +{0, OP_RT_RA_DS, 58<<26 | 1<<0, "ldu"}, +{0, OP_RT_RA_RB, 31<<26 | 53<<1, "ldux"}, -0, OP_RS_RA_D, 38<<26, "stb", -0, OP_RS_RA_RB, 31<<26 | 215<<1, "stbx", -0, OP_RS_RA_D, 39<<26, "stbu", -0, OP_RS_RA_RB, 31<<26 | 247<<1, "stbux", -0, OP_RS_RA_D, 44<<26, "sth", -0, OP_RS_RA_RB, 31<<26 | 407<<1, "sthx", -0, OP_RS_RA_D, 45<<26, "sthu", -0, OP_RS_RA_RB, 31<<26 | 439<<1, "sthux", -0, OP_RS_RA_D, 36<<26, "stw", -0, OP_RS_RA_RB, 31<<26 | 151<<1, "stwx", -0, OP_RS_RA_D, 37<<26, "stwu", -0, OP_RS_RA_RB, 31<<26 | 183<<1, "stwux", -0, OP_RS_RA_DS, 62<<26, "std", -0, OP_RS_RA_RB, 31<<26 | 149<<1, "stdx", -0, OP_RS_RA_DS, 62<<26 | 1<<0, "stdu", -0, OP_RS_RA_RB, 31<<26 | 181<<1, "stdux", +{0, OP_RS_RA_D, 38<<26, "stb"}, +{0, OP_RS_RA_RB, 31<<26 | 215<<1, "stbx"}, +{0, OP_RS_RA_D, 39<<26, "stbu"}, +{0, OP_RS_RA_RB, 31<<26 | 247<<1, "stbux"}, +{0, OP_RS_RA_D, 44<<26, "sth"}, +{0, OP_RS_RA_RB, 31<<26 | 407<<1, "sthx"}, +{0, OP_RS_RA_D, 45<<26, "sthu"}, +{0, OP_RS_RA_RB, 31<<26 | 439<<1, "sthux"}, +{0, OP_RS_RA_D, 36<<26, "stw"}, +{0, OP_RS_RA_RB, 31<<26 | 151<<1, "stwx"}, +{0, OP_RS_RA_D, 37<<26, "stwu"}, +{0, OP_RS_RA_RB, 31<<26 | 183<<1, "stwux"}, +{0, OP_RS_RA_DS, 62<<26, "std"}, +{0, OP_RS_RA_RB, 31<<26 | 149<<1, "stdx"}, +{0, OP_RS_RA_DS, 62<<26 | 1<<0, "stdu"}, +{0, OP_RS_RA_RB, 31<<26 | 181<<1, "stdux"}, /* page 42 */ -0, OP_RT_RA_RB, 31<<26 | 790<<1, "lhbrx", -0, OP_RT_RA_RB, 31<<26 | 534<<1, "lwbrx", -0, OP_RS_RA_RB, 31<<26 | 918<<1, "sthbrx", -0, OP_RS_RA_RB, 31<<26 | 662<<1, "stwbrx", +{0, OP_RT_RA_RB, 31<<26 | 790<<1, "lhbrx"}, +{0, OP_RT_RA_RB, 31<<26 | 534<<1, "lwbrx"}, +{0, OP_RS_RA_RB, 31<<26 | 918<<1, "sthbrx"}, +{0, OP_RS_RA_RB, 31<<26 | 662<<1, "stwbrx"}, /* page 44 */ -0, OP_RT_RA_D, 46<<26, "lmw", -0, OP_RS_RA_D, 47<<26, "stmw", +{0, OP_RT_RA_D, 46<<26, "lmw"}, +{0, OP_RS_RA_D, 47<<26, "stmw"}, /* page 45 */ -0, OP_RT_RA_NB, 31<<26 | 597<<1, "lswi", -0, OP_RT_RA_RB, 31<<26 | 533<<1, "lswx", -0, OP_RS_RA_NB, 31<<26 | 725<<1, "stswi", -0, OP_RS_RA_RB, 31<<26 | 661<<1, "stswx", +{0, OP_RT_RA_NB, 31<<26 | 597<<1, "lswi"}, +{0, OP_RT_RA_RB, 31<<26 | 533<<1, "lswx"}, +{0, OP_RS_RA_NB, 31<<26 | 725<<1, "stswi"}, +{0, OP_RS_RA_RB, 31<<26 | 661<<1, "stswx"}, /* page 49 */ -0, OP_RT_RA_SI, 14<<26, "addi", -0, OP_RT_RA_SI, 15<<26, "addis", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 266<<1, "add", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 266<<1, "addo", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 40<<1, "subf", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 40<<1, "subfo", -0, OP_RT_RA_SI_addic, 12<<26, "addic", /* special case C */ -0, OP_RT_RA_SI, 8<<26, "subfic", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 10<<1, "addc", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 10<<1, "addco", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 8<<1, "subfc", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 8<<1, "subfco", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 138<<1, "adde", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 138<<1, "addeo", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 136<<1, "subfe", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 136<<1, "subfeo", -0, OP_RT_RA_C, 31<<26 | 0<<10 | 234<<1, "addme", -0, OP_RT_RA_C, 31<<26 | 1<<10 | 234<<1, "addmeo", -0, OP_RT_RA_C, 31<<26 | 0<<10 | 232<<1, "subfme", -0, OP_RT_RA_C, 31<<26 | 1<<10 | 232<<1, "subfmeo", -0, OP_RT_RA_C, 31<<26 | 0<<10 | 202<<1, "addze", -0, OP_RT_RA_C, 31<<26 | 1<<10 | 202<<1, "addzeo", -0, OP_RT_RA_C, 31<<26 | 0<<10 | 200<<1, "subfze", -0, OP_RT_RA_C, 31<<26 | 1<<10 | 200<<1, "subfzeo", -0, OP_RT_RA_C, 31<<26 | 0<<10 | 104<<1, "neg", -0, OP_RT_RA_C, 31<<26 | 1<<10 | 104<<1, "nego", +{0, OP_RT_RA_SI, 14<<26, "addi"}, +{0, OP_RT_RA_SI, 15<<26, "addis"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 266<<1, "add"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 266<<1, "addo"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 40<<1, "subf"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 40<<1, "subfo"}, +{0, OP_RT_RA_SI_addic, 12<<26, "addic"}, /* special case C */ +{0, OP_RT_RA_SI, 8<<26, "subfic"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 10<<1, "addc"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 10<<1, "addco"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 8<<1, "subfc"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 8<<1, "subfco"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 138<<1, "adde"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 138<<1, "addeo"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 136<<1, "subfe"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 136<<1, "subfeo"}, +{0, OP_RT_RA_C, 31<<26 | 0<<10 | 234<<1, "addme"}, +{0, OP_RT_RA_C, 31<<26 | 1<<10 | 234<<1, "addmeo"}, +{0, OP_RT_RA_C, 31<<26 | 0<<10 | 232<<1, "subfme"}, +{0, OP_RT_RA_C, 31<<26 | 1<<10 | 232<<1, "subfmeo"}, +{0, OP_RT_RA_C, 31<<26 | 0<<10 | 202<<1, "addze"}, +{0, OP_RT_RA_C, 31<<26 | 1<<10 | 202<<1, "addzeo"}, +{0, OP_RT_RA_C, 31<<26 | 0<<10 | 200<<1, "subfze"}, +{0, OP_RT_RA_C, 31<<26 | 1<<10 | 200<<1, "subfzeo"}, +{0, OP_RT_RA_C, 31<<26 | 0<<10 | 104<<1, "neg"}, +{0, OP_RT_RA_C, 31<<26 | 1<<10 | 104<<1, "nego"}, /* extended m for addition (pages 153, 154) */ -0, OP_RT_RA_D, 14<<26, "la", -0, OP_RT_SI, 14<<26 | 0<<16, "li", -0, OP_RT_SI, 15<<26 | 0<<16, "lis", +{0, OP_RT_RA_D, 14<<26, "la"}, +{0, OP_RT_SI, 14<<26 | 0<<16, "li"}, +{0, OP_RT_SI, 15<<26 | 0<<16, "lis"}, /* extended m for subtraction (pages 147, 148) */ -0, OP_RT_RB_RA_C, 31<<26 | 0<<10 | 40<<1, "sub", -0, OP_RT_RB_RA_C, 31<<26 | 1<<10 | 40<<1, "subo", -0, OP_RT_RB_RA_C, 31<<26 | 0<<10 | 8<<1, "subc", -0, OP_RT_RB_RA_C, 31<<26 | 0<<10 | 8<<1, "subco", -0, OP_RT_RA_SI_subi, 14<<26, "subi", -0, OP_RT_RA_SI_subi, 15<<26, "subis", -0, OP_RT_RA_SI_subic, 12<<26, "subic", +{0, OP_RT_RB_RA_C, 31<<26 | 0<<10 | 40<<1, "sub"}, +{0, OP_RT_RB_RA_C, 31<<26 | 1<<10 | 40<<1, "subo"}, +{0, OP_RT_RB_RA_C, 31<<26 | 0<<10 | 8<<1, "subc"}, +{0, OP_RT_RB_RA_C, 31<<26 | 0<<10 | 8<<1, "subco"}, +{0, OP_RT_RA_SI_subi, 14<<26, "subi"}, +{0, OP_RT_RA_SI_subi, 15<<26, "subis"}, +{0, OP_RT_RA_SI_subic, 12<<26, "subic"}, /* page 54 */ -0, OP_RT_RA_SI, 7<<26, "mulli", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 233<<1, "mulld", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 233<<1, "mulldo", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 235<<1, "mullw", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 235<<1, "mullwo", -0, OP_RT_RA_RB_C, 31<<26 | 73<<1, "mulhd", -0, OP_RT_RA_RB_C, 31<<26 | 75<<1, "mulhw", -0, OP_RT_RA_RB_C, 31<<26 | 9<<1, "mulhdu", -0, OP_RT_RA_RB_C, 31<<26 | 11<<1, "mulhwu", +{0, OP_RT_RA_SI, 7<<26, "mulli"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 233<<1, "mulld"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 233<<1, "mulldo"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 235<<1, "mullw"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 235<<1, "mullwo"}, +{0, OP_RT_RA_RB_C, 31<<26 | 73<<1, "mulhd"}, +{0, OP_RT_RA_RB_C, 31<<26 | 75<<1, "mulhw"}, +{0, OP_RT_RA_RB_C, 31<<26 | 9<<1, "mulhdu"}, +{0, OP_RT_RA_RB_C, 31<<26 | 11<<1, "mulhwu"}, /* page 56 */ -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 489<<1, "divd", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 489<<1, "divdo", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 491<<1, "divw", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 491<<1, "divwo", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 457<<1, "divdu", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 457<<1, "divduo", -0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 459<<1, "divwu", -0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 459<<1, "divwuo", +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 489<<1, "divd"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 489<<1, "divdo"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 491<<1, "divw"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 491<<1, "divwo"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 457<<1, "divdu"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 457<<1, "divduo"}, +{0, OP_RT_RA_RB_C, 31<<26 | 0<<10 | 459<<1, "divwu"}, +{0, OP_RT_RA_RB_C, 31<<26 | 1<<10 | 459<<1, "divwuo"}, /* page 58 */ -0, OP_BF_L_RA_SI, 11<<26, "cmpi", -0, OP_BF_L_RA_RB, 31<<26 | 0<<1, "cmp", -0, OP_BF_L_RA_UI, 10<<26, "cmpli", -0, OP_BF_L_RA_RB, 31<<26 | 32<<1, "cmpl", +{0, OP_BF_L_RA_SI, 11<<26, "cmpi"}, +{0, OP_BF_L_RA_RB, 31<<26 | 0<<1, "cmp"}, +{0, OP_BF_L_RA_UI, 10<<26, "cmpli"}, +{0, OP_BF_L_RA_RB, 31<<26 | 32<<1, "cmpl"}, /* extended m for comparison (page 149) */ -0, OP_BF_RA_SI, 11<<26 | 1<<21, "cmpdi", -0, OP_BF_RA_RB, 31<<26 | 1<<21 | 0<<1, "cmpd", -0, OP_BF_RA_UI, 10<<26 | 1<<21, "cmpldi", -0, OP_BF_RA_RB, 31<<26 | 1<<21 | 32<<1, "cmpld", -0, OP_BF_RA_SI, 11<<26 | 0<<21, "cmpwi", -0, OP_BF_RA_RB, 31<<26 | 0<<21 | 0<<1, "cmpw", -0, OP_BF_RA_UI, 10<<26 | 0<<21, "cmplwi", -0, OP_BF_RA_RB, 31<<26 | 0<<21 | 32<<1, "cmplw", +{0, OP_BF_RA_SI, 11<<26 | 1<<21, "cmpdi"}, +{0, OP_BF_RA_RB, 31<<26 | 1<<21 | 0<<1, "cmpd"}, +{0, OP_BF_RA_UI, 10<<26 | 1<<21, "cmpldi"}, +{0, OP_BF_RA_RB, 31<<26 | 1<<21 | 32<<1, "cmpld"}, +{0, OP_BF_RA_SI, 11<<26 | 0<<21, "cmpwi"}, +{0, OP_BF_RA_RB, 31<<26 | 0<<21 | 0<<1, "cmpw"}, +{0, OP_BF_RA_UI, 10<<26 | 0<<21, "cmplwi"}, +{0, OP_BF_RA_RB, 31<<26 | 0<<21 | 32<<1, "cmplw"}, /* page 60 */ -0, OP_TO_RA_SI, 2<<26, "tdi", -0, OP_TO_RA_SI, 3<<26, "twi", -0, OP_TO_RA_RB, 31<<26 | 68<<1, "td", -0, OP_TO_RA_RB, 31<<26 | 4<<1, "tw", +{0, OP_TO_RA_SI, 2<<26, "tdi"}, +{0, OP_TO_RA_SI, 3<<26, "twi"}, +{0, OP_TO_RA_RB, 31<<26 | 68<<1, "td"}, +{0, OP_TO_RA_RB, 31<<26 | 4<<1, "tw"}, /* extended m for traps (page 150) */ -0, OP_TOX_RA_RB, 31<<26 | 4<<21 | 68<<1, "tdeq", -0, OP_TOX_RA_SI, 2<<26 | 4<<21, "tdeqi", -0, OP_TOX_RA_RB, 31<<26 | 12<<21 | 68<<1, "tdge", -0, OP_TOX_RA_SI, 2<<26 | 12<<21, "tdgei", -0, OP_TOX_RA_RB, 31<<26 | 8<<21 | 68<<1, "tdgt", -0, OP_TOX_RA_SI, 2<<26 | 8<<21, "tdgti", -0, OP_TOX_RA_RB, 31<<26 | 20<<21 | 68<<1, "tdle", -0, OP_TOX_RA_SI, 2<<26 | 20<<21, "tdlei", -0, OP_TOX_RA_RB, 31<<26 | 5<<21 | 68<<1, "tdlge", -0, OP_TOX_RA_SI, 2<<26 | 5<<21, "tdlgei", -0, OP_TOX_RA_RB, 31<<26 | 1<<21 | 68<<1, "tdlgt", -0, OP_TOX_RA_SI, 2<<26 | 1<<21, "tdlgti", -0, OP_TOX_RA_RB, 31<<26 | 6<<21 | 68<<1, "tdlle", -0, OP_TOX_RA_SI, 2<<26 | 6<<21, "tdllei", -0, OP_TOX_RA_RB, 31<<26 | 2<<21 | 68<<1, "tdllt", -0, OP_TOX_RA_SI, 2<<26 | 2<<21, "tdllti", -0, OP_TOX_RA_RB, 31<<26 | 6<<21 | 68<<1, "tdlng", -0, OP_TOX_RA_SI, 2<<26 | 6<<21, "tdlngi", -0, OP_TOX_RA_RB, 31<<26 | 5<<21 | 68<<1, "tdlnl", -0, OP_TOX_RA_SI, 2<<26 | 5<<21, "tdlnli", -0, OP_TOX_RA_RB, 31<<26 | 16<<21 | 68<<1, "tdlt", -0, OP_TOX_RA_SI, 2<<26 | 16<<21, "tdlti", -0, OP_TOX_RA_RB, 31<<26 | 24<<21 | 68<<1, "tdne", -0, OP_TOX_RA_SI, 2<<26 | 24<<21, "tdnei", -0, OP_TOX_RA_RB, 31<<26 | 20<<21 | 68<<1, "tdng", -0, OP_TOX_RA_SI, 2<<26 | 20<<21, "tdngi", -0, OP_TOX_RA_RB, 31<<26 | 12<<21 | 68<<1, "tdnl", -0, OP_TOX_RA_SI, 2<<26 | 12<<21, "tdnli", -0, OP_TOX_RA_RB, 31<<26 | 31<<21 | 68<<1, "tdu", -0, OP_TOX_RA_SI, 2<<26 | 31<<21, "tdui", -0, OP, 31<<26 | 31<<21 | 4<<1, "trap", -0, OP_TOX_RA_RB, 31<<26 | 4<<21 | 4<<1, "tweq", -0, OP_TOX_RA_SI, 3<<26 | 4<<21, "tweqi", -0, OP_TOX_RA_RB, 31<<26 | 12<<21 | 4<<1, "twge", -0, OP_TOX_RA_SI, 3<<26 | 12<<21, "twgei", -0, OP_TOX_RA_RB, 31<<26 | 8<<21 | 4<<1, "twgt", -0, OP_TOX_RA_SI, 3<<26 | 8<<21, "twgti", -0, OP_TOX_RA_RB, 31<<26 | 20<<21 | 4<<1, "twle", -0, OP_TOX_RA_SI, 3<<26 | 20<<21, "twlei", -0, OP_TOX_RA_RB, 31<<26 | 5<<21 | 4<<1, "twlge", -0, OP_TOX_RA_SI, 3<<26 | 5<<21, "twlgei", -0, OP_TOX_RA_RB, 31<<26 | 1<<21 | 4<<1, "twlgt", -0, OP_TOX_RA_SI, 3<<26 | 1<<21, "twlgti", -0, OP_TOX_RA_RB, 31<<26 | 6<<21 | 4<<1, "twlle", -0, OP_TOX_RA_SI, 3<<26 | 6<<21, "twllei", -0, OP_TOX_RA_RB, 31<<26 | 2<<21 | 4<<1, "twllt", -0, OP_TOX_RA_SI, 3<<26 | 2<<21, "twllti", -0, OP_TOX_RA_RB, 31<<26 | 6<<21 | 4<<1, "twlng", -0, OP_TOX_RA_SI, 3<<26 | 6<<21, "twlngi", -0, OP_TOX_RA_RB, 31<<26 | 5<<21 | 4<<1, "twlnl", -0, OP_TOX_RA_SI, 3<<26 | 5<<21, "twlnli", -0, OP_TOX_RA_RB, 31<<26 | 16<<21 | 4<<1, "twlt", -0, OP_TOX_RA_SI, 3<<26 | 16<<21, "twlti", -0, OP_TOX_RA_RB, 31<<26 | 24<<21 | 4<<1, "twne", -0, OP_TOX_RA_SI, 3<<26 | 24<<21, "twnei", -0, OP_TOX_RA_RB, 31<<26 | 20<<21 | 4<<1, "twng", -0, OP_TOX_RA_SI, 3<<26 | 20<<21, "twngi", -0, OP_TOX_RA_RB, 31<<26 | 12<<21 | 4<<1, "twnl", -0, OP_TOX_RA_SI, 3<<26 | 12<<21, "twnli", -0, OP_TOX_RA_RB, 31<<26 | 31<<21 | 4<<1, "twu", -0, OP_TOX_RA_SI, 3<<26 | 31<<21, "twui", +{0, OP_TOX_RA_RB, 31<<26 | 4<<21 | 68<<1, "tdeq"}, +{0, OP_TOX_RA_SI, 2<<26 | 4<<21, "tdeqi"}, +{0, OP_TOX_RA_RB, 31<<26 | 12<<21 | 68<<1, "tdge"}, +{0, OP_TOX_RA_SI, 2<<26 | 12<<21, "tdgei"}, +{0, OP_TOX_RA_RB, 31<<26 | 8<<21 | 68<<1, "tdgt"}, +{0, OP_TOX_RA_SI, 2<<26 | 8<<21, "tdgti"}, +{0, OP_TOX_RA_RB, 31<<26 | 20<<21 | 68<<1, "tdle"}, +{0, OP_TOX_RA_SI, 2<<26 | 20<<21, "tdlei"}, +{0, OP_TOX_RA_RB, 31<<26 | 5<<21 | 68<<1, "tdlge"}, +{0, OP_TOX_RA_SI, 2<<26 | 5<<21, "tdlgei"}, +{0, OP_TOX_RA_RB, 31<<26 | 1<<21 | 68<<1, "tdlgt"}, +{0, OP_TOX_RA_SI, 2<<26 | 1<<21, "tdlgti"}, +{0, OP_TOX_RA_RB, 31<<26 | 6<<21 | 68<<1, "tdlle"}, +{0, OP_TOX_RA_SI, 2<<26 | 6<<21, "tdllei"}, +{0, OP_TOX_RA_RB, 31<<26 | 2<<21 | 68<<1, "tdllt"}, +{0, OP_TOX_RA_SI, 2<<26 | 2<<21, "tdllti"}, +{0, OP_TOX_RA_RB, 31<<26 | 6<<21 | 68<<1, "tdlng"}, +{0, OP_TOX_RA_SI, 2<<26 | 6<<21, "tdlngi"}, +{0, OP_TOX_RA_RB, 31<<26 | 5<<21 | 68<<1, "tdlnl"}, +{0, OP_TOX_RA_SI, 2<<26 | 5<<21, "tdlnli"}, +{0, OP_TOX_RA_RB, 31<<26 | 16<<21 | 68<<1, "tdlt"}, +{0, OP_TOX_RA_SI, 2<<26 | 16<<21, "tdlti"}, +{0, OP_TOX_RA_RB, 31<<26 | 24<<21 | 68<<1, "tdne"}, +{0, OP_TOX_RA_SI, 2<<26 | 24<<21, "tdnei"}, +{0, OP_TOX_RA_RB, 31<<26 | 20<<21 | 68<<1, "tdng"}, +{0, OP_TOX_RA_SI, 2<<26 | 20<<21, "tdngi"}, +{0, OP_TOX_RA_RB, 31<<26 | 12<<21 | 68<<1, "tdnl"}, +{0, OP_TOX_RA_SI, 2<<26 | 12<<21, "tdnli"}, +{0, OP_TOX_RA_RB, 31<<26 | 31<<21 | 68<<1, "tdu"}, +{0, OP_TOX_RA_SI, 2<<26 | 31<<21, "tdui"}, +{0, OP, 31<<26 | 31<<21 | 4<<1, "trap"}, +{0, OP_TOX_RA_RB, 31<<26 | 4<<21 | 4<<1, "tweq"}, +{0, OP_TOX_RA_SI, 3<<26 | 4<<21, "tweqi"}, +{0, OP_TOX_RA_RB, 31<<26 | 12<<21 | 4<<1, "twge"}, +{0, OP_TOX_RA_SI, 3<<26 | 12<<21, "twgei"}, +{0, OP_TOX_RA_RB, 31<<26 | 8<<21 | 4<<1, "twgt"}, +{0, OP_TOX_RA_SI, 3<<26 | 8<<21, "twgti"}, +{0, OP_TOX_RA_RB, 31<<26 | 20<<21 | 4<<1, "twle"}, +{0, OP_TOX_RA_SI, 3<<26 | 20<<21, "twlei"}, +{0, OP_TOX_RA_RB, 31<<26 | 5<<21 | 4<<1, "twlge"}, +{0, OP_TOX_RA_SI, 3<<26 | 5<<21, "twlgei"}, +{0, OP_TOX_RA_RB, 31<<26 | 1<<21 | 4<<1, "twlgt"}, +{0, OP_TOX_RA_SI, 3<<26 | 1<<21, "twlgti"}, +{0, OP_TOX_RA_RB, 31<<26 | 6<<21 | 4<<1, "twlle"}, +{0, OP_TOX_RA_SI, 3<<26 | 6<<21, "twllei"}, +{0, OP_TOX_RA_RB, 31<<26 | 2<<21 | 4<<1, "twllt"}, +{0, OP_TOX_RA_SI, 3<<26 | 2<<21, "twllti"}, +{0, OP_TOX_RA_RB, 31<<26 | 6<<21 | 4<<1, "twlng"}, +{0, OP_TOX_RA_SI, 3<<26 | 6<<21, "twlngi"}, +{0, OP_TOX_RA_RB, 31<<26 | 5<<21 | 4<<1, "twlnl"}, +{0, OP_TOX_RA_SI, 3<<26 | 5<<21, "twlnli"}, +{0, OP_TOX_RA_RB, 31<<26 | 16<<21 | 4<<1, "twlt"}, +{0, OP_TOX_RA_SI, 3<<26 | 16<<21, "twlti"}, +{0, OP_TOX_RA_RB, 31<<26 | 24<<21 | 4<<1, "twne"}, +{0, OP_TOX_RA_SI, 3<<26 | 24<<21, "twnei"}, +{0, OP_TOX_RA_RB, 31<<26 | 20<<21 | 4<<1, "twng"}, +{0, OP_TOX_RA_SI, 3<<26 | 20<<21, "twngi"}, +{0, OP_TOX_RA_RB, 31<<26 | 12<<21 | 4<<1, "twnl"}, +{0, OP_TOX_RA_SI, 3<<26 | 12<<21, "twnli"}, +{0, OP_TOX_RA_RB, 31<<26 | 31<<21 | 4<<1, "twu"}, +{0, OP_TOX_RA_SI, 3<<26 | 31<<21, "twui"}, /* page 62 */ -0, OP_RA_RS_UI_CC, 28<<26, "andi", /* C compulsory */ -0, OP_RA_RS_UI_CC, 29<<26, "andis", /* C compulsory */ -0, OP_RA_RS_UI, 24<<26, "ori", -0, OP_RA_RS_UI, 25<<26, "oris", -0, OP_RA_RS_UI, 26<<26, "xori", -0, OP_RA_RS_UI, 27<<26, "xoris", -0, OP_RA_RS_RB_C, 31<<26 | 28<<1, "and", -0, OP_RA_RS_RB_C, 31<<26 | 444<<1, "or", -0, OP_RA_RS_RB_C, 31<<26 | 316<<1, "xor", -0, OP_RA_RS_RB_C, 31<<26 | 476<<1, "nand", -0, OP_RA_RS_RB_C, 31<<26 | 124<<1, "nor", -0, OP_RA_RS_RB_C, 31<<26 | 284<<1, "eqv", -0, OP_RA_RS_RB_C, 31<<26 | 60<<1, "andc", -0, OP_RA_RS_RB_C, 31<<26 | 412<<1, "orc", -0, OP_RA_RS_C, 31<<26 | 954<<1, "extsb", -0, OP_RA_RS_C, 31<<26 | 922<<1, "extsh", -0, OP_RA_RS_C, 31<<26 | 986<<1, "extsw", -0, OP_RA_RS_C, 31<<26 | 58<<1, "cntlzd", -0, OP_RA_RS_C, 31<<26 | 26<<1, "cntlzw", +{0, OP_RA_RS_UI_CC, 28<<26, "andi"}, /* C compulsory */ +{0, OP_RA_RS_UI_CC, 29<<26, "andis"}, /* C compulsory */ +{0, OP_RA_RS_UI, 24<<26, "ori"}, +{0, OP_RA_RS_UI, 25<<26, "oris"}, +{0, OP_RA_RS_UI, 26<<26, "xori"}, +{0, OP_RA_RS_UI, 27<<26, "xoris"}, +{0, OP_RA_RS_RB_C, 31<<26 | 28<<1, "and"}, +{0, OP_RA_RS_RB_C, 31<<26 | 444<<1, "or"}, +{0, OP_RA_RS_RB_C, 31<<26 | 316<<1, "xor"}, +{0, OP_RA_RS_RB_C, 31<<26 | 476<<1, "nand"}, +{0, OP_RA_RS_RB_C, 31<<26 | 124<<1, "nor"}, +{0, OP_RA_RS_RB_C, 31<<26 | 284<<1, "eqv"}, +{0, OP_RA_RS_RB_C, 31<<26 | 60<<1, "andc"}, +{0, OP_RA_RS_RB_C, 31<<26 | 412<<1, "orc"}, +{0, OP_RA_RS_C, 31<<26 | 954<<1, "extsb"}, +{0, OP_RA_RS_C, 31<<26 | 922<<1, "extsh"}, +{0, OP_RA_RS_C, 31<<26 | 986<<1, "extsw"}, +{0, OP_RA_RS_C, 31<<26 | 58<<1, "cntlzd"}, +{0, OP_RA_RS_C, 31<<26 | 26<<1, "cntlzw"}, /* extended m using logic (pages 153, 154) */ -0, OP_RA_RS_RA_C, 31<<26 | 444<<1, "mr", -0, OP, 24<<26, "nop", -0, OP_RA_RS_RA_C, 31<<26 | 124<<1, "not", +{0, OP_RA_RS_RA_C, 31<<26 | 444<<1, "mr"}, +{0, OP, 24<<26, "nop"}, +{0, OP_RA_RS_RA_C, 31<<26 | 124<<1, "not"}, /* page 69 */ -0, OP_RA_RS_SH6_MB6_C, 30<<26 | 0<<2, "rldicl", -0, OP_RA_RS_SH6_MB6_C, 30<<26 | 1<<2, "rldicr", -0, OP_RA_RS_SH6_MB6_C, 30<<26 | 2<<2, "rldic", -0, OP_RA_RS_SH5_MB5_ME5_C, 21<<26, "rlwinm", -0, OP_RA_RS_RB_MB6_C, 30<<26 | 8<<1, "rldcl", -0, OP_RA_RS_RB_MB6_C, 30<<26 | 9<<1, "rldcr", -0, OP_RA_RS_RB_MB5_ME5_C, 23<<26, "rlwnm", -0, OP_RA_RS_SH6_MB6_C, 30<<26 | 3<<2, "rldimi", -0, OP_RA_RS_SH5_MB5_ME5_C, 20<<26, "rlwimi", +{0, OP_RA_RS_SH6_MB6_C, 30<<26 | 0<<2, "rldicl"}, +{0, OP_RA_RS_SH6_MB6_C, 30<<26 | 1<<2, "rldicr"}, +{0, OP_RA_RS_SH6_MB6_C, 30<<26 | 2<<2, "rldic"}, +{0, OP_RA_RS_SH5_MB5_ME5_C, 21<<26, "rlwinm"}, +{0, OP_RA_RS_RB_MB6_C, 30<<26 | 8<<1, "rldcl"}, +{0, OP_RA_RS_RB_MB6_C, 30<<26 | 9<<1, "rldcr"}, +{0, OP_RA_RS_RB_MB5_ME5_C, 23<<26, "rlwnm"}, +{0, OP_RA_RS_SH6_MB6_C, 30<<26 | 3<<2, "rldimi"}, +{0, OP_RA_RS_SH5_MB5_ME5_C, 20<<26, "rlwimi"}, /* extended m for doubleword rotation (page 151) */ -0, OP_clrlsldi, 30<<26 | 2<<2, "clrlsldi", -0, OP_clrldi, 30<<26 | 0<<2, "clrldi", -0, OP_clrrdi, 30<<26 | 1<<2, "clrrdi", -0, OP_extldi, 30<<26 | 0<<2, "extldi", -0, OP_extrdi, 30<<26 | 1<<2, "extrdi", -0, OP_insrdi, 30<<26 | 3<<2, "insrdi", -0, OP_RA_RS_RB_C, 30<<26 | MB6(0) | 8<<1, "rotld", -0, OP_RA_RS_SH6_C, 30<<26 | MB6(0) | 0<<2, "rotldi", -0, OP_rotrdi, 30<<26 | 0<<2, "rotrdi", -0, OP_sldi, 30<<26 | 1<<2, "sldi", -0, OP_srdi, 30<<26 | 0<<2, "srdi", +{0, OP_clrlsldi, 30<<26 | 2<<2, "clrlsldi"}, +{0, OP_clrldi, 30<<26 | 0<<2, "clrldi"}, +{0, OP_clrrdi, 30<<26 | 1<<2, "clrrdi"}, +{0, OP_extldi, 30<<26 | 0<<2, "extldi"}, +{0, OP_extrdi, 30<<26 | 1<<2, "extrdi"}, +{0, OP_insrdi, 30<<26 | 3<<2, "insrdi"}, +{0, OP_RA_RS_RB_C, 30<<26 | MB6(0) | 8<<1, "rotld"}, +{0, OP_RA_RS_SH6_C, 30<<26 | MB6(0) | 0<<2, "rotldi"}, +{0, OP_rotrdi, 30<<26 | 0<<2, "rotrdi"}, +{0, OP_sldi, 30<<26 | 1<<2, "sldi"}, +{0, OP_srdi, 30<<26 | 0<<2, "srdi"}, /* extended m for word rotation (page 152) */ -0, OP_clrlslwi, 21<<26, "clrlslwi", -0, OP_clrlwi, 21<<26, "clrlwi", -0, OP_clrrwi, 21<<26, "clrrwi", -0, OP_extlwi, 21<<26, "extlwi", -0, OP_extrwi, 21<<26, "extrwi", -0, OP_inslwi, 20<<26, "inslwi", -0, OP_insrwi, 20<<26, "insrwi", -0, OP_RA_RS_RB_C, 23<<26 | 0<<6 | 31<<1, "rotlw", -0, OP_RA_RS_SH5_C, 21<<26 | 0<<6 | 31<<1, "rotlwi", -0, OP_rotrwi, 21<<26, "rotrwi", -0, OP_slwi, 21<<26, "slwi", -0, OP_srwi, 21<<26, "srwi", +{0, OP_clrlslwi, 21<<26, "clrlslwi"}, +{0, OP_clrlwi, 21<<26, "clrlwi"}, +{0, OP_clrrwi, 21<<26, "clrrwi"}, +{0, OP_extlwi, 21<<26, "extlwi"}, +{0, OP_extrwi, 21<<26, "extrwi"}, +{0, OP_inslwi, 20<<26, "inslwi"}, +{0, OP_insrwi, 20<<26, "insrwi"}, +{0, OP_RA_RS_RB_C, 23<<26 | 0<<6 | 31<<1, "rotlw"}, +{0, OP_RA_RS_SH5_C, 21<<26 | 0<<6 | 31<<1, "rotlwi"}, +{0, OP_rotrwi, 21<<26, "rotrwi"}, +{0, OP_slwi, 21<<26, "slwi"}, +{0, OP_srwi, 21<<26, "srwi"}, /* page 74 */ -0, OP_RA_RS_RB_C, 31<<26 | 27<<1, "sld", -0, OP_RA_RS_RB_C, 31<<26 | 24<<1, "slw", -0, OP_RA_RS_RB_C, 31<<26 | 539<<1, "srd", -0, OP_RA_RS_RB_C, 31<<26 | 536<<1, "srw", -0, OP_RA_RS_SH6_C, 31<<26 | 413<<2, "sradi", -0, OP_RA_RS_SH5_C, 31<<26 | 824<<1, "srawi", -0, OP_RA_RS_RB_C, 31<<26 | 794<<1, "srad", -0, OP_RA_RS_RB_C, 31<<26 | 792<<1, "sraw", +{0, OP_RA_RS_RB_C, 31<<26 | 27<<1, "sld"}, +{0, OP_RA_RS_RB_C, 31<<26 | 24<<1, "slw"}, +{0, OP_RA_RS_RB_C, 31<<26 | 539<<1, "srd"}, +{0, OP_RA_RS_RB_C, 31<<26 | 536<<1, "srw"}, +{0, OP_RA_RS_SH6_C, 31<<26 | 413<<2, "sradi"}, +{0, OP_RA_RS_SH5_C, 31<<26 | 824<<1, "srawi"}, +{0, OP_RA_RS_RB_C, 31<<26 | 794<<1, "srad"}, +{0, OP_RA_RS_RB_C, 31<<26 | 792<<1, "sraw"}, /* page 78 */ -0, OP_RS_SPR, 31<<26 | 467<<1, "mtspr", -0, OP_RT_SPR, 31<<26 | 339<<1, "mfspr", -0, OP_RS_FXM, 31<<26 | 0<<20 | 144<<1, "mtcrf", -0, OP_RT, 31<<26 | 0<<20 | 19<<1, "mfcr", +{0, OP_RS_SPR, 31<<26 | 467<<1, "mtspr"}, +{0, OP_RT_SPR, 31<<26 | 339<<1, "mfspr"}, +{0, OP_RS_FXM, 31<<26 | 0<<20 | 144<<1, "mtcrf"}, +{0, OP_RT, 31<<26 | 0<<20 | 19<<1, "mfcr"}, /* extended m for special purpose registers (page 153) */ -0, OP_RT, 31<<26 | 9<<16 | 0<<11 | 339<<1, "mfctr", -0, OP_RT, 31<<26 | 8<<16 | 0<<11 | 339<<1, "mflr", -0, OP_RT, 31<<26 | 1<<16 | 0<<11 | 339<<1, "mfxer", -0, OP_RS, 31<<26 | 9<<16 | 0<<11 | 467<<1, "mtctr", -0, OP_RS, 31<<26 | 8<<16 | 0<<11 | 467<<1, "mtlr", -0, OP_RS, 31<<26 | 1<<16 | 0<<11 | 467<<1, "mtxer", +{0, OP_RT, 31<<26 | 9<<16 | 0<<11 | 339<<1, "mfctr"}, +{0, OP_RT, 31<<26 | 8<<16 | 0<<11 | 339<<1, "mflr"}, +{0, OP_RT, 31<<26 | 1<<16 | 0<<11 | 339<<1, "mfxer"}, +{0, OP_RS, 31<<26 | 9<<16 | 0<<11 | 467<<1, "mtctr"}, +{0, OP_RS, 31<<26 | 8<<16 | 0<<11 | 467<<1, "mtlr"}, +{0, OP_RS, 31<<26 | 1<<16 | 0<<11 | 467<<1, "mtxer"}, /* extended m for condition register (page 154) */ -0, OP_RS, 31<<26 | 0<<20 | 255<<12 | 144<<1, "mtcr", +{0, OP_RS, 31<<26 | 0<<20 | 255<<12 | 144<<1, "mtcr"}, /* Floating point instructions (page 83) */ /* page 98 */ -0, OP_FRT_RA_D, 48<<26, "lfs", -0, OP_FRT_RA_RB, 31<<26 | 535<<1, "lfsx", -0, OP_FRT_RA_D, 49<<26, "lfsu", -0, OP_FRT_RA_RB, 31<<26 | 567<<1, "lfsux", -0, OP_FRT_RA_D, 50<<26, "lfd", -0, OP_FRT_RA_RB, 31<<26 | 599<<1, "lfdx", -0, OP_FRT_RA_D, 51<<26, "lfdu", -0, OP_FRT_RA_RB, 31<<26 | 631<<1, "lfdux", -0, OP_FRS_RA_D, 52<<26, "stfs", -0, OP_FRS_RA_RB, 31<<26 | 663<<1, "stfsx", -0, OP_FRS_RA_D, 53<<26, "stfsu", -0, OP_FRS_RA_RB, 31<<26 | 695<<1, "stfsux", -0, OP_FRS_RA_D, 54<<26, "stfd", -0, OP_FRS_RA_RB, 31<<26 | 727<<1, "stfdx", -0, OP_FRS_RA_D, 55<<26, "stfdu", -0, OP_FRS_RA_RB, 31<<26 | 759<<1, "stfdux", -0, OP_FRS_RA_RB, 31<<26 | 983<<1, "stfiwx", +{0, OP_FRT_RA_D, 48<<26, "lfs"}, +{0, OP_FRT_RA_RB, 31<<26 | 535<<1, "lfsx"}, +{0, OP_FRT_RA_D, 49<<26, "lfsu"}, +{0, OP_FRT_RA_RB, 31<<26 | 567<<1, "lfsux"}, +{0, OP_FRT_RA_D, 50<<26, "lfd"}, +{0, OP_FRT_RA_RB, 31<<26 | 599<<1, "lfdx"}, +{0, OP_FRT_RA_D, 51<<26, "lfdu"}, +{0, OP_FRT_RA_RB, 31<<26 | 631<<1, "lfdux"}, +{0, OP_FRS_RA_D, 52<<26, "stfs"}, +{0, OP_FRS_RA_RB, 31<<26 | 663<<1, "stfsx"}, +{0, OP_FRS_RA_D, 53<<26, "stfsu"}, +{0, OP_FRS_RA_RB, 31<<26 | 695<<1, "stfsux"}, +{0, OP_FRS_RA_D, 54<<26, "stfd"}, +{0, OP_FRS_RA_RB, 31<<26 | 727<<1, "stfdx"}, +{0, OP_FRS_RA_D, 55<<26, "stfdu"}, +{0, OP_FRS_RA_RB, 31<<26 | 759<<1, "stfdux"}, +{0, OP_FRS_RA_RB, 31<<26 | 983<<1, "stfiwx"}, /* page 104 */ -0, OP_FRT_FRB_C, 63<<26 | 72<<1, "fmr", -0, OP_FRT_FRB_C, 63<<26 | 40<<1, "fneg", -0, OP_FRT_FRB_C, 63<<26 | 264<<1, "fabs", -0, OP_FRT_FRB_C, 63<<26 | 136<<1, "fnabs", +{0, OP_FRT_FRB_C, 63<<26 | 72<<1, "fmr"}, +{0, OP_FRT_FRB_C, 63<<26 | 40<<1, "fneg"}, +{0, OP_FRT_FRB_C, 63<<26 | 264<<1, "fabs"}, +{0, OP_FRT_FRB_C, 63<<26 | 136<<1, "fnabs"}, -0, OP_FRT_FRA_FRB_C, 63<<26 | 21<<1, "fadd", -0, OP_FRT_FRA_FRB_C, 59<<26 | 21<<1, "fadds", -0, OP_FRT_FRA_FRB_C, 63<<26 | 20<<1, "fsub", -0, OP_FRT_FRA_FRB_C, 59<<26 | 20<<1, "fsubs", -0, OP_FRT_FRA_FRC_C, 63<<26 | 25<<1, "fmul", -0, OP_FRT_FRA_FRC_C, 59<<26 | 25<<1, "fmuls", -0, OP_FRT_FRA_FRB_C, 63<<26 | 18<<1, "fdiv", -0, OP_FRT_FRA_FRB_C, 59<<26 | 18<<1, "fdivs", +{0, OP_FRT_FRA_FRB_C, 63<<26 | 21<<1, "fadd"}, +{0, OP_FRT_FRA_FRB_C, 59<<26 | 21<<1, "fadds"}, +{0, OP_FRT_FRA_FRB_C, 63<<26 | 20<<1, "fsub"}, +{0, OP_FRT_FRA_FRB_C, 59<<26 | 20<<1, "fsubs"}, +{0, OP_FRT_FRA_FRC_C, 63<<26 | 25<<1, "fmul"}, +{0, OP_FRT_FRA_FRC_C, 59<<26 | 25<<1, "fmuls"}, +{0, OP_FRT_FRA_FRB_C, 63<<26 | 18<<1, "fdiv"}, +{0, OP_FRT_FRA_FRB_C, 59<<26 | 18<<1, "fdivs"}, -0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 29<<1, "fmadd", -0, OP_FRT_FRA_FRC_FRB_C, 59<<26 | 29<<1, "fmadds", -0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 28<<1, "fmsub", -0, OP_FRT_FRA_FRC_FRB_C, 59<<26 | 28<<1, "fmsubs", -0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 31<<1, "fnmadd", -0, OP_FRT_FRA_FRC_FRB_C, 59<<26 | 31<<1, "fnmadds", -0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 30<<1, "fnmsub", -0, OP_FRT_FRA_FRC_FRB_C, 59<<26 | 30<<1, "fnmsubs", +{0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 29<<1, "fmadd"}, +{0, OP_FRT_FRA_FRC_FRB_C, 59<<26 | 29<<1, "fmadds"}, +{0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 28<<1, "fmsub"}, +{0, OP_FRT_FRA_FRC_FRB_C, 59<<26 | 28<<1, "fmsubs"}, +{0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 31<<1, "fnmadd"}, +{0, OP_FRT_FRA_FRC_FRB_C, 59<<26 | 31<<1, "fnmadds"}, +{0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 30<<1, "fnmsub"}, +{0, OP_FRT_FRA_FRC_FRB_C, 59<<26 | 30<<1, "fnmsubs"}, /* page 109 */ -0, OP_FRT_FRB_C, 63<<26 | 12<<1, "frsp", -0, OP_FRT_FRB_C, 63<<26 | 814<<1, "fctid", -0, OP_FRT_FRB_C, 63<<26 | 815<<1, "fctidz", -0, OP_FRT_FRB_C, 63<<26 | 14<<1, "fctiw", -0, OP_FRT_FRB_C, 63<<26 | 15<<1, "fctiwz", -0, OP_FRT_FRB_C, 63<<26 | 846<<1, "fcfid", +{0, OP_FRT_FRB_C, 63<<26 | 12<<1, "frsp"}, +{0, OP_FRT_FRB_C, 63<<26 | 814<<1, "fctid"}, +{0, OP_FRT_FRB_C, 63<<26 | 815<<1, "fctidz"}, +{0, OP_FRT_FRB_C, 63<<26 | 14<<1, "fctiw"}, +{0, OP_FRT_FRB_C, 63<<26 | 15<<1, "fctiwz"}, +{0, OP_FRT_FRB_C, 63<<26 | 846<<1, "fcfid"}, -0, OP_BF_FRA_FRB, 63<<26 | 0<<1, "fcmpu", -0, OP_BF_FRA_FRB, 63<<26 | 32<<1, "fcmpo", +{0, OP_BF_FRA_FRB, 63<<26 | 0<<1, "fcmpu"}, +{0, OP_BF_FRA_FRB, 63<<26 | 32<<1, "fcmpo"}, -0, OP_FRT_C, 63<<26 | 583<<1, "mffs", -0, OP_BF_BFA, 63<<26 | 64<<1, "mcrfs", -0, OP_BF_U_C, 63<<26 | 134<<1, "mtfsfi", -0, OP_FLM_FRB_C, 63<<26 | 711<<1, "mtfsf", -0, OP_BT_C, 63<<26 | 70<<1, "mtfsb0", -0, OP_BT_C, 63<<26 | 38<<1, "mtfsb1", +{0, OP_FRT_C, 63<<26 | 583<<1, "mffs"}, +{0, OP_BF_BFA, 63<<26 | 64<<1, "mcrfs"}, +{0, OP_BF_U_C, 63<<26 | 134<<1, "mtfsfi"}, +{0, OP_FLM_FRB_C, 63<<26 | 711<<1, "mtfsf"}, +{0, OP_BT_C, 63<<26 | 70<<1, "mtfsb0"}, +{0, OP_BT_C, 63<<26 | 38<<1, "mtfsb1"}, -0, OP_FRT_FRB_C, 63<<26 | 22<<1, "fsqrt", -0, OP_FRT_FRB_C, 59<<26 | 22<<1, "fsqrts", -0, OP_FRT_FRB_C, 59<<26 | 24<<1, "fres", -0, OP_FRT_FRB_C, 63<<26 | 26<<1, "frsqrte", -0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 23<<1, "fsel", +{0, OP_FRT_FRB_C, 63<<26 | 22<<1, "fsqrt"}, +{0, OP_FRT_FRB_C, 59<<26 | 22<<1, "fsqrts"}, +{0, OP_FRT_FRB_C, 59<<26 | 24<<1, "fres"}, +{0, OP_FRT_FRB_C, 63<<26 | 26<<1, "frsqrte"}, +{0, OP_FRT_FRA_FRC_FRB_C, 63<<26 | 23<<1, "fsel"}, /* Storage control instructions (Book II, page 15) */ /* Book II, page 17 */ -0, OP_RA_RB, 31<<26 | 982<<1, "icbi", -0, OP_RA_RB_TH /* page 35 */, 31<<26 | 278<<1, "dcbt", -0, OP_RA_RB, 31<<26 | 246<<1, "dcbtst", -0, OP_RA_RB, 31<<26 | 1014<<1, "dcbz", -0, OP_RA_RB, 31<<26 | 54<<1, "dcbst", -0, OP_RA_RB, 31<<26 | 86<<1, "dcbf", -0, OP, 19<<26 | 150<<1, "isync", -0, OP_RT_RA_RB, 31<<26 | 20<<1, "lwarx", -0, OP_RT_RA_RB, 31<<26 | 84<<1, "ldarx", -0, OP_RS_RA_RB_CC, 31<<26 | 150<<1 | 1<<0, "stwcx", -0, OP_RS_RA_RB_CC, 31<<26 | 150<<1 | 1<<0, "stdcx", -0, OP_L, 31<<26 | 598<<1, "sync", -0, OP, 31<<26 | 1<<21 | 598<<1, "lwsync", -0, OP, 31<<26 | 2<<21 | 598<<1, "ptesync", -0, OP, 31<<26 | 854<<1, "eieio", +{0, OP_RA_RB, 31<<26 | 982<<1, "icbi"}, +{0, OP_RA_RB_TH /* page 35 */, 31<<26 | 278<<1, "dcbt"}, +{0, OP_RA_RB, 31<<26 | 246<<1, "dcbtst"}, +{0, OP_RA_RB, 31<<26 | 1014<<1, "dcbz"}, +{0, OP_RA_RB, 31<<26 | 54<<1, "dcbst"}, +{0, OP_RA_RB, 31<<26 | 86<<1, "dcbf"}, +{0, OP, 19<<26 | 150<<1, "isync"}, +{0, OP_RT_RA_RB, 31<<26 | 20<<1, "lwarx"}, +{0, OP_RT_RA_RB, 31<<26 | 84<<1, "ldarx"}, +{0, OP_RS_RA_RB_CC, 31<<26 | 150<<1 | 1<<0, "stwcx"}, +{0, OP_RS_RA_RB_CC, 31<<26 | 150<<1 | 1<<0, "stdcx"}, +{0, OP_L, 31<<26 | 598<<1, "sync"}, +{0, OP, 31<<26 | 1<<21 | 598<<1, "lwsync"}, +{0, OP, 31<<26 | 2<<21 | 598<<1, "ptesync"}, +{0, OP, 31<<26 | 854<<1, "eieio"}, /* Time base (Book II, page 30) */ -0, OP_RT_TBR, 31<<26 | 371<<1, "mftb", -0, OP_RT, 31<<26 | 8<<11 | 13<<16 | 371<<1, "mftbu", +{0, OP_RT_TBR, 31<<26 | 371<<1, "mftb"}, +{0, OP_RT, 31<<26 | 8<<11 | 13<<16 | 371<<1, "mftbu"}, /* External control (Book II, page 33) */ -0, OP_RT_RA_RB, 31<<26 | 310<<1, "eciwx", -0, OP_RS_RA_RB, 31<<26 | 438<<1, "ecowx", +{0, OP_RT_RA_RB, 31<<26 | 310<<1, "eciwx"}, +{0, OP_RS_RA_RB, 31<<26 | 438<<1, "ecowx"}, diff --git a/mach/proto/as/comm3.c b/mach/proto/as/comm3.c index 2a24a0878..2b3afaba5 100644 --- a/mach/proto/as/comm3.c +++ b/mach/proto/as/comm3.c @@ -23,30 +23,30 @@ struct outhead outhead = { #include "y.tab.h" item_t keytab[] = { - 0, EXTERN, 0, ".define", - 0, EXTERN, 0, ".extern", - 0, DOT, 0, ".", - 0, DATA, RELO1, ".data1", - 0, DATA, RELO2, ".data2", - 0, DATA, RELO4, ".data4", - 0, DATAF, 4, ".dataf4", - 0, DATAF, 8, ".dataf8", - 0, ASCII, 0, ".ascii", - 0, ASCII, 1, ".asciz", - 0, ALIGN, 0, ".align", - 0, ASSERT, 0, ".assert", - 0, SPACE, 0, ".space", - 0, COMMON, 0, ".comm", - 0, SECTION, 0, ".sect", - 0, BASE, 0, ".base", - 0, SYMB, 0, ".symb", - 0, SYMD, 0, ".symd", - 0, LINE, 0, ".line", - 0, FILe, 0, ".file", + {0, EXTERN, 0, ".define"}, + {0, EXTERN, 0, ".extern"}, + {0, DOT, 0, "."}, + {0, DATA, RELO1, ".data1"}, + {0, DATA, RELO2, ".data2"}, + {0, DATA, RELO4, ".data4"}, + {0, DATAF, 4, ".dataf4"}, + {0, DATAF, 8, ".dataf8"}, + {0, ASCII, 0, ".ascii"}, + {0, ASCII, 1, ".asciz"}, + {0, ALIGN, 0, ".align"}, + {0, ASSERT, 0, ".assert"}, + {0, SPACE, 0, ".space"}, + {0, COMMON, 0, ".comm"}, + {0, SECTION, 0, ".sect"}, + {0, BASE, 0, ".base"}, + {0, SYMB, 0, ".symb"}, + {0, SYMD, 0, ".symd"}, + {0, LINE, 0, ".line"}, + {0, FILe, 0, ".file"}, #ifdef LISTING - 0, LIST, 0, ".nolist", - 0, LIST, 1, ".list", + {0, LIST, 0, ".nolist"}, + {0, LIST, 1, ".list"}, #endif #include "mach3.c" - 0, 0, 0, 0 + {0, 0, 0, 0} }; diff --git a/mach/s2650/as/mach3.c b/mach/s2650/as/mach3.c index e34628b66..b8ba6df9f 100644 --- a/mach/s2650/as/mach3.c +++ b/mach/s2650/as/mach3.c @@ -7,88 +7,88 @@ /* * Signetics 2650 keywords */ -0, REG, R0, "r0", -0, REG, R1, "r1", -0, REG, R2, "r2", -0, REG, R3, "r3", -0, CC, 0, "eq", -0, CC, 0, "z", -0, CC, 1, "gt", -0, CC, 2, "lt", -0, CC, 3, "un", -0, INDE, 0x6000, "i", -0, ZERO, 0x0, "lodz", -0, ZERO, 0x80, "addz", -0, ZERO, 0xA0, "subz", -0, ZERO, 0x94, "dar", -0, ZEROX, 0x40, "andz", -0, ZERO, 0x60, "iorz", -0, ZERO, 0x20, "eorz", -0, ZERO, 0xE0, "comz", -0, ZERO, 0xF0, "wrtd", -0, ZERO, 0x70, "redd", -0, ZERO, 0xB0, "wrtc", -0, ZERO, 0x30, "redc", -0, ZERO, 0x50, "rrr", -0, ZERO, 0xD0, "rrl", -0, ZEROX, 0xC0, "strz", -0, IMMED, 0x04, "lodi", -0, IMMED, 0x84, "addi", -0, IMMED, 0xA4, "subi", -0, IMMED, 0x44, "andi", -0, IMMED, 0x64, "iori", -0, IMMED, 0x24, "eori", -0, IMMED, 0xE4, "comi", -0, IMMED, 0xD4, "wrte", -0, IMMED, 0x54, "rede", -0, IMMED, 0xF4, "tmi", -0, NOOP, 0x1E, "halt", -0, NOOP, 0xC0, "nop", -0, NOOP, 0x92, "lpsu", -0, NOOP, 0x93, "lpsl", -0, NOOP, 0x12, "spsu", -0, NOOP, 0x13, "spsl", -0, REL, 0x08, "lodr", -0, REL, 0xC8, "strr", -0, REL, 0x98, "addr", -0, REL, 0xA8, "subr", -0, REL, 0x48, "andr", -0, REL, 0x68, "iorr", -0, REL, 0x28, "eorr", -0, REL, 0xE8, "comr", -0, ABSO, 0x0C, "loda", -0, ABSO, 0xCC, "stra", -0, ABSO, 0x8C, "adda", -0, ABSO, 0xAC, "suba", -0, ABSO, 0x4C, "anda", -0, ABSO, 0x6C, "iora", -0, ABSO, 0x2C, "eora", -0, ABSO, 0xEC, "coma", -0, PSWM, 0x74, "cpsu", -0, PSWM, 0x75, "cpsl", -0, PSWM, 0x76, "ppsu", -0, PSWM, 0x77, "ppsl", -0, PSWM, 0xB4, "tpsu", -0, PSWM, 0xB5, "tpsl", -0, RET, 0x14, "retc", -0, RET, 0x34, "rete", -0, BRANCR, 0x18, "bctr", -0, BRANCRX, 0x98, "bcfr", -0, REL, 0x58, "brnr", -0, REL, 0xD8, "birr", -0, REL, 0xF8, "bdrr", -0, BRANCR, 0x38, "bstr", -0, BRANCRX, 0xB8, "bsfr", -0, REL, 0x78, "bsnr", -0, BRANCA, 0x1E, "bcta", -0, BRANCAX, 0x9E, "bcfa", -0, BRANRA, 0x5E, "brna", -0, BRANRA, 0xDE, "bira", -0, BRANRA, 0xFE, "bdra", -0, BRANCA, 0x3E, "bsta", -0, BRANCAX, 0xBE, "bsfa", -0, BRANRA, 0x7E, "bsna", -0, ZBRR, 0x9B, "zbrr", -0, ZBRR, 0xBB, "zbsr", -0, BXSA, 0x9F, "bxa", -0, BXSA, 0xBF, "bsxa", +{0, REG, R0, "r0"}, +{0, REG, R1, "r1"}, +{0, REG, R2, "r2"}, +{0, REG, R3, "r3"}, +{0, CC, 0, "eq"}, +{0, CC, 0, "z"}, +{0, CC, 1, "gt"}, +{0, CC, 2, "lt"}, +{0, CC, 3, "un"}, +{0, INDE, 0x6000, "i"}, +{0, ZERO, 0x0, "lodz"}, +{0, ZERO, 0x80, "addz"}, +{0, ZERO, 0xA0, "subz"}, +{0, ZERO, 0x94, "dar"}, +{0, ZEROX, 0x40, "andz"}, +{0, ZERO, 0x60, "iorz"}, +{0, ZERO, 0x20, "eorz"}, +{0, ZERO, 0xE0, "comz"}, +{0, ZERO, 0xF0, "wrtd"}, +{0, ZERO, 0x70, "redd"}, +{0, ZERO, 0xB0, "wrtc"}, +{0, ZERO, 0x30, "redc"}, +{0, ZERO, 0x50, "rrr"}, +{0, ZERO, 0xD0, "rrl"}, +{0, ZEROX, 0xC0, "strz"}, +{0, IMMED, 0x04, "lodi"}, +{0, IMMED, 0x84, "addi"}, +{0, IMMED, 0xA4, "subi"}, +{0, IMMED, 0x44, "andi"}, +{0, IMMED, 0x64, "iori"}, +{0, IMMED, 0x24, "eori"}, +{0, IMMED, 0xE4, "comi"}, +{0, IMMED, 0xD4, "wrte"}, +{0, IMMED, 0x54, "rede"}, +{0, IMMED, 0xF4, "tmi"}, +{0, NOOP, 0x1E, "halt"}, +{0, NOOP, 0xC0, "nop"}, +{0, NOOP, 0x92, "lpsu"}, +{0, NOOP, 0x93, "lpsl"}, +{0, NOOP, 0x12, "spsu"}, +{0, NOOP, 0x13, "spsl"}, +{0, REL, 0x08, "lodr"}, +{0, REL, 0xC8, "strr"}, +{0, REL, 0x98, "addr"}, +{0, REL, 0xA8, "subr"}, +{0, REL, 0x48, "andr"}, +{0, REL, 0x68, "iorr"}, +{0, REL, 0x28, "eorr"}, +{0, REL, 0xE8, "comr"}, +{0, ABSO, 0x0C, "loda"}, +{0, ABSO, 0xCC, "stra"}, +{0, ABSO, 0x8C, "adda"}, +{0, ABSO, 0xAC, "suba"}, +{0, ABSO, 0x4C, "anda"}, +{0, ABSO, 0x6C, "iora"}, +{0, ABSO, 0x2C, "eora"}, +{0, ABSO, 0xEC, "coma"}, +{0, PSWM, 0x74, "cpsu"}, +{0, PSWM, 0x75, "cpsl"}, +{0, PSWM, 0x76, "ppsu"}, +{0, PSWM, 0x77, "ppsl"}, +{0, PSWM, 0xB4, "tpsu"}, +{0, PSWM, 0xB5, "tpsl"}, +{0, RET, 0x14, "retc"}, +{0, RET, 0x34, "rete"}, +{0, BRANCR, 0x18, "bctr"}, +{0, BRANCRX, 0x98, "bcfr"}, +{0, REL, 0x58, "brnr"}, +{0, REL, 0xD8, "birr"}, +{0, REL, 0xF8, "bdrr"}, +{0, BRANCR, 0x38, "bstr"}, +{0, BRANCRX, 0xB8, "bsfr"}, +{0, REL, 0x78, "bsnr"}, +{0, BRANCA, 0x1E, "bcta"}, +{0, BRANCAX, 0x9E, "bcfa"}, +{0, BRANRA, 0x5E, "brna"}, +{0, BRANRA, 0xDE, "bira"}, +{0, BRANRA, 0xFE, "bdra"}, +{0, BRANCA, 0x3E, "bsta"}, +{0, BRANCAX, 0xBE, "bsfa"}, +{0, BRANRA, 0x7E, "bsna"}, +{0, ZBRR, 0x9B, "zbrr"}, +{0, ZBRR, 0xBB, "zbsr"}, +{0, BXSA, 0x9F, "bxa"}, +{0, BXSA, 0xBF, "bsxa"}, diff --git a/mach/vax4/as/mach3.c b/mach/vax4/as/mach3.c index 93bce6faa..30ae7f831 100644 --- a/mach/vax4/as/mach3.c +++ b/mach/vax4/as/mach3.c @@ -8,26 +8,26 @@ * VAX-11 keywords */ -0, REG, 0, "r0", -0, REG, 1, "r1", -0, REG, 2, "r2", -0, REG, 3, "r3", -0, REG, 4, "r4", -0, REG, 5, "r5", -0, REG, 6, "r6", -0, REG, 7, "r7", -0, REG, 8, "r8", -0, REG, 9, "r9", -0, REG, 10, "r10", -0, REG, 11, "r11", -0, REG, 12, "r12", -0, REG, 12, "ap", -0, REG, 13, "r13", -0, REG, 13, "fp", -0, REG, 14, "r14", -0, REG, 14, "sp", -0, REG, 15, "r15", -0, REG, 15, "pc", +{0, REG, 0, "r0"}, +{0, REG, 1, "r1"}, +{0, REG, 2, "r2"}, +{0, REG, 3, "r3"}, +{0, REG, 4, "r4"}, +{0, REG, 5, "r5"}, +{0, REG, 6, "r6"}, +{0, REG, 7, "r7"}, +{0, REG, 8, "r8"}, +{0, REG, 9, "r9"}, +{0, REG, 10, "r10"}, +{0, REG, 11, "r11"}, +{0, REG, 12, "r12"}, +{0, REG, 12, "ap"}, +{0, REG, 13, "r13"}, +{0, REG, 13, "fp"}, +{0, REG, 14, "r14"}, +{0, REG, 14, "sp"}, +{0, REG, 15, "r15"}, +{0, REG, 15, "pc"}, /* For immediate mode, we need the size as specified by the instruction. Ordinary operands are therefore encoded as _w, _b, and _l to indicate @@ -40,377 +40,377 @@ /* integer arithmetic and logical instructions */ -0, OP2_w_w, 0x58, "adawi", -0, OP2_b_b, 0x80, "addb2", -0, OP3_b_b_b, 0x81, "addb3", -0, OP2_w_w, 0xa0, "addw2", -0, OP3_w_w_w, 0xa1, "addw3", -0, OP2_l_l, 0xc0, "addl2", -0, OP3_l_l_l, 0xc1, "addl3", -0, OP2_l_l, 0xd8, "adwc", -0, OP3_b_l_l, 0x78, "ashl", -0, OP3_b_u_u, 0x79, "ashq", -0, OP2_b_b, 0x8a, "bicb2", -0, OP3_b_b_b, 0x8b, "bicb3", -0, OP2_w_w, 0xaa, "bicw2", -0, OP3_w_w_w, 0xab, "bicw3", -0, OP2_l_l, 0xca, "bicl2", -0, OP3_l_l_l, 0xcb, "bicl3", -0, OP2_b_b, 0x88, "bisb2", -0, OP3_b_b_b, 0x89, "bisb3", -0, OP2_w_w, 0xa8, "bisw2", -0, OP3_w_w_w, 0xa9, "bisw3", -0, OP2_l_l, 0xc8, "bisl2", -0, OP3_l_l_l, 0xc9, "bisl3", -0, OP2_b_b, 0x93, "bitb", -0, OP2_w_w, 0xb3, "bitw", -0, OP2_l_l, 0xd3, "bitl", -0, OP1_X, 0x94|(1L<<16), "clrb", -0, OP1_X, 0xb4|(2L<<16), "clrw", -0, OP1_X, 0xd4|(4L<<16), "clrl", -0, OP1_u, 0x7c, "clrq", -0, OP1_u, 0x7cfd, "clro", -0, OP2_b_b, 0x91, "cmpb", -0, OP2_w_w, 0xb1, "cmpw", -0, OP2_l_l, 0xd1, "cmpl", -0, OP2_b_w, 0x99, "cvtbw", -0, OP2_b_l, 0x98, "cvtbl", -0, OP2_w_b, 0x33, "cvtwb", -0, OP2_w_l, 0x32, "cvtwl", -0, OP2_l_b, 0xf6, "cvtlb", -0, OP2_l_w, 0xf7, "cvtlw", -0, OP1_X, 0x97|(1L<<16), "decb", -0, OP1_X, 0xb7|(2L<<16), "decw", -0, OP1_X, 0xd7|(4L<<16), "decl", -0, OP2_b_b, 0x86, "divb2", -0, OP3_b_b_b, 0x87, "divb3", -0, OP2_w_w, 0xa6, "divw2", -0, OP3_w_w_w, 0xa7, "divw3", -0, OP2_l_l, 0xc6, "divl2", -0, OP3_l_l_l, 0xc7, "divl3", -0, OP4_l_u_l_l, 0x7b, "ediv", -0, OP4_l_l_l_u, 0x7a, "emul", -0, OP1_X, 0x96|(1L<<16), "incb", -0, OP1_X, 0xb6|(2L<<16), "incw", -0, OP1_X, 0xd6|(4L<<16), "incl", -0, OP2_b_b, 0x92, "mcomb", -0, OP2_w_w, 0xb2, "mcomw", -0, OP2_l_l, 0xd2, "mcoml", -0, OP2_b_b, 0x8e, "mnegb", -0, OP2_w_w, 0xae, "mnegw", -0, OP2_l_l, 0xce, "mnegl", -0, OP2_b_b, 0x90, "movb", -0, OP2_w_w, 0xb0, "movw", -0, OP2_l_l, 0xd0, "movl", -0, OP2_u_u, 0x7d, "movq", -0, OP2_u_u, 0x7dfd, "movo", -0, OP2_b_w, 0x9b, "movzbw", -0, OP2_b_l, 0x9a, "movzbl", -0, OP2_w_l, 0x3c, "movzwl", -0, OP2_b_b, 0x84, "mulb2", -0, OP3_b_b_b, 0x85, "mulb3", -0, OP2_w_w, 0xa4, "mulw2", -0, OP3_w_w_w, 0xa5, "mulw3", -0, OP2_l_l, 0xc4, "mull2", -0, OP3_l_l_l, 0xc5, "mull3", -0, OP1_X, 0xdd|(4L<<16), "pushl", -0, OP3_b_l_l, 0x9c, "rotl", -0, OP2_l_l, 0xd9, "sbwc", -0, OP2_b_b, 0x82, "subb2", -0, OP3_b_b_b, 0x83, "subb3", -0, OP2_w_w, 0xa2, "subw2", -0, OP3_w_w_w, 0xa3, "subw3", -0, OP2_l_l, 0xc2, "subl2", -0, OP3_l_l_l, 0xc3, "subl3", -0, OP1_X, 0x95|(1L<<16), "tstb", -0, OP1_X, 0xb5|(2L<<16), "tstw", -0, OP1_X, 0xd5|(4L<<16), "tstl", -0, OP2_b_b, 0x8c, "xorb2", -0, OP3_b_b_b, 0x8d, "xorb3", -0, OP2_w_w, 0xac, "xorw2", -0, OP3_w_w_w, 0xad, "xorw3", -0, OP2_l_l, 0xcc, "xorl2", -0, OP3_l_l_l, 0xcd, "xorl3", +{0, OP2_w_w, 0x58, "adawi"}, +{0, OP2_b_b, 0x80, "addb2"}, +{0, OP3_b_b_b, 0x81, "addb3"}, +{0, OP2_w_w, 0xa0, "addw2"}, +{0, OP3_w_w_w, 0xa1, "addw3"}, +{0, OP2_l_l, 0xc0, "addl2"}, +{0, OP3_l_l_l, 0xc1, "addl3"}, +{0, OP2_l_l, 0xd8, "adwc"}, +{0, OP3_b_l_l, 0x78, "ashl"}, +{0, OP3_b_u_u, 0x79, "ashq"}, +{0, OP2_b_b, 0x8a, "bicb2"}, +{0, OP3_b_b_b, 0x8b, "bicb3"}, +{0, OP2_w_w, 0xaa, "bicw2"}, +{0, OP3_w_w_w, 0xab, "bicw3"}, +{0, OP2_l_l, 0xca, "bicl2"}, +{0, OP3_l_l_l, 0xcb, "bicl3"}, +{0, OP2_b_b, 0x88, "bisb2"}, +{0, OP3_b_b_b, 0x89, "bisb3"}, +{0, OP2_w_w, 0xa8, "bisw2"}, +{0, OP3_w_w_w, 0xa9, "bisw3"}, +{0, OP2_l_l, 0xc8, "bisl2"}, +{0, OP3_l_l_l, 0xc9, "bisl3"}, +{0, OP2_b_b, 0x93, "bitb"}, +{0, OP2_w_w, 0xb3, "bitw"}, +{0, OP2_l_l, 0xd3, "bitl"}, +{0, OP1_X, 0x94|(1L<<16), "clrb"}, +{0, OP1_X, 0xb4|(2L<<16), "clrw"}, +{0, OP1_X, 0xd4|(4L<<16), "clrl"}, +{0, OP1_u, 0x7c, "clrq"}, +{0, OP1_u, 0x7cfd, "clro"}, +{0, OP2_b_b, 0x91, "cmpb"}, +{0, OP2_w_w, 0xb1, "cmpw"}, +{0, OP2_l_l, 0xd1, "cmpl"}, +{0, OP2_b_w, 0x99, "cvtbw"}, +{0, OP2_b_l, 0x98, "cvtbl"}, +{0, OP2_w_b, 0x33, "cvtwb"}, +{0, OP2_w_l, 0x32, "cvtwl"}, +{0, OP2_l_b, 0xf6, "cvtlb"}, +{0, OP2_l_w, 0xf7, "cvtlw"}, +{0, OP1_X, 0x97|(1L<<16), "decb"}, +{0, OP1_X, 0xb7|(2L<<16), "decw"}, +{0, OP1_X, 0xd7|(4L<<16), "decl"}, +{0, OP2_b_b, 0x86, "divb2"}, +{0, OP3_b_b_b, 0x87, "divb3"}, +{0, OP2_w_w, 0xa6, "divw2"}, +{0, OP3_w_w_w, 0xa7, "divw3"}, +{0, OP2_l_l, 0xc6, "divl2"}, +{0, OP3_l_l_l, 0xc7, "divl3"}, +{0, OP4_l_u_l_l, 0x7b, "ediv"}, +{0, OP4_l_l_l_u, 0x7a, "emul"}, +{0, OP1_X, 0x96|(1L<<16), "incb"}, +{0, OP1_X, 0xb6|(2L<<16), "incw"}, +{0, OP1_X, 0xd6|(4L<<16), "incl"}, +{0, OP2_b_b, 0x92, "mcomb"}, +{0, OP2_w_w, 0xb2, "mcomw"}, +{0, OP2_l_l, 0xd2, "mcoml"}, +{0, OP2_b_b, 0x8e, "mnegb"}, +{0, OP2_w_w, 0xae, "mnegw"}, +{0, OP2_l_l, 0xce, "mnegl"}, +{0, OP2_b_b, 0x90, "movb"}, +{0, OP2_w_w, 0xb0, "movw"}, +{0, OP2_l_l, 0xd0, "movl"}, +{0, OP2_u_u, 0x7d, "movq"}, +{0, OP2_u_u, 0x7dfd, "movo"}, +{0, OP2_b_w, 0x9b, "movzbw"}, +{0, OP2_b_l, 0x9a, "movzbl"}, +{0, OP2_w_l, 0x3c, "movzwl"}, +{0, OP2_b_b, 0x84, "mulb2"}, +{0, OP3_b_b_b, 0x85, "mulb3"}, +{0, OP2_w_w, 0xa4, "mulw2"}, +{0, OP3_w_w_w, 0xa5, "mulw3"}, +{0, OP2_l_l, 0xc4, "mull2"}, +{0, OP3_l_l_l, 0xc5, "mull3"}, +{0, OP1_X, 0xdd|(4L<<16), "pushl"}, +{0, OP3_b_l_l, 0x9c, "rotl"}, +{0, OP2_l_l, 0xd9, "sbwc"}, +{0, OP2_b_b, 0x82, "subb2"}, +{0, OP3_b_b_b, 0x83, "subb3"}, +{0, OP2_w_w, 0xa2, "subw2"}, +{0, OP3_w_w_w, 0xa3, "subw3"}, +{0, OP2_l_l, 0xc2, "subl2"}, +{0, OP3_l_l_l, 0xc3, "subl3"}, +{0, OP1_X, 0x95|(1L<<16), "tstb"}, +{0, OP1_X, 0xb5|(2L<<16), "tstw"}, +{0, OP1_X, 0xd5|(4L<<16), "tstl"}, +{0, OP2_b_b, 0x8c, "xorb2"}, +{0, OP3_b_b_b, 0x8d, "xorb3"}, +{0, OP2_w_w, 0xac, "xorw2"}, +{0, OP3_w_w_w, 0xad, "xorw3"}, +{0, OP2_l_l, 0xcc, "xorl2"}, +{0, OP3_l_l_l, 0xcd, "xorl3"}, /* Address instructions */ -0, OP2_A_l, 0x9e, "movab", -0, OP2_A_l, 0x3e, "movaw", -0, OP2_A_l, 0xde, "moval", -0, OP2_A_l, 0xde, "movaf", -0, OP2_A_l, 0x7e, "movaq", -0, OP2_A_l, 0x7e, "movad", -0, OP2_A_l, 0x7e, "movag", -0, OP2_A_l, 0x7efd, "movah", -0, OP2_A_l, 0x7efd, "movao", -0, OP1_A, 0x9f, "pushab", -0, OP1_A, 0x3f, "pushaw", -0, OP1_A, 0xdf, "pushal", -0, OP1_A, 0xdf, "pushaf", -0, OP1_A, 0x7f, "pushaq", -0, OP1_A, 0x7f, "pushad", -0, OP1_A, 0x7f, "pushag", -0, OP1_A, 0x7ffd, "pushah", -0, OP1_A, 0x7ffd, "pushao", +{0, OP2_A_l, 0x9e, "movab"}, +{0, OP2_A_l, 0x3e, "movaw"}, +{0, OP2_A_l, 0xde, "moval"}, +{0, OP2_A_l, 0xde, "movaf"}, +{0, OP2_A_l, 0x7e, "movaq"}, +{0, OP2_A_l, 0x7e, "movad"}, +{0, OP2_A_l, 0x7e, "movag"}, +{0, OP2_A_l, 0x7efd, "movah"}, +{0, OP2_A_l, 0x7efd, "movao"}, +{0, OP1_A, 0x9f, "pushab"}, +{0, OP1_A, 0x3f, "pushaw"}, +{0, OP1_A, 0xdf, "pushal"}, +{0, OP1_A, 0xdf, "pushaf"}, +{0, OP1_A, 0x7f, "pushaq"}, +{0, OP1_A, 0x7f, "pushad"}, +{0, OP1_A, 0x7f, "pushag"}, +{0, OP1_A, 0x7ffd, "pushah"}, +{0, OP1_A, 0x7ffd, "pushao"}, /* Variable length bit-field instructions */ -0, OP4_l_b_V_l, 0xec, "cmpv", -0, OP4_l_b_V_l, 0xed, "cmpzv", -0, OP4_l_b_V_l, 0xee, "extv", -0, OP4_l_b_V_l, 0xef, "extzv", -0, OP4_l_b_V_l, 0xeb, "ffc", -0, OP4_l_b_V_l, 0xea, "ffs", -0, OP4_l_l_b_V, 0xf0, "insv", +{0, OP4_l_b_V_l, 0xec, "cmpv"}, +{0, OP4_l_b_V_l, 0xed, "cmpzv"}, +{0, OP4_l_b_V_l, 0xee, "extv"}, +{0, OP4_l_b_V_l, 0xef, "extzv"}, +{0, OP4_l_b_V_l, 0xeb, "ffc"}, +{0, OP4_l_b_V_l, 0xea, "ffs"}, +{0, OP4_l_l_b_V, 0xf0, "insv"}, /* Control instructions */ -0, OP4_b_b_b_Bw, 0x9d, "acbb", -0, OP4_w_w_w_Bw, 0x3d, "acbw", -0, OP4_l_l_l_Bw, 0xf1, "acbl", -0, OP4_u_u_u_Bw, 0x4f, "acbf", -0, OP4_u_u_u_Bw, 0x6f, "acbd", -0, OP4_u_u_u_Bw, 0x4ffd, "acbg", -0, OP4_u_u_u_Bw, 0x6ffd, "acbh", -0, OP3_l_l_Bb, 0xf3, "aobleq", -0, OP3_l_l_Bb, 0xf2, "aoblss", -0, OP1_BX, 0x14|(1L<<16), "bgtr", -0, OP1_BX, 0x15|(1L<<16), "bleq", -0, OP1_BX, 0x12|(1L<<16), "bneq", -0, OP1_BX, 0x12|(1L<<16), "bnequ", -0, OP1_BX, 0x13|(1L<<16), "beql", -0, OP1_BX, 0x13|(1L<<16), "beqlu", -0, OP1_BX, 0x18|(1L<<16), "bgeq", -0, OP1_BX, 0x19|(1L<<16), "blss", -0, OP1_BX, 0x1a|(1L<<16), "bgtru", -0, OP1_BX, 0x1b|(1L<<16), "blequ", -0, OP1_BX, 0x1c|(1L<<16), "bvc", -0, OP1_BX, 0x1d|(1L<<16), "bvs", -0, OP1_BX, 0x1e|(1L<<16), "bgequ", -0, OP1_BX, 0x1e|(1L<<16), "bcc", -0, OP1_BX, 0x1f|(1L<<16), "blssu", -0, OP1_BX, 0x1f|(1L<<16), "bcs", -0, OP3_l_V_Bb, 0xe0, "bbs", -0, OP3_l_V_Bb, 0xe1, "bbc", -0, OP3_l_V_Bb, 0xe2, "bbss", -0, OP3_l_V_Bb, 0xe3, "bbcs", -0, OP3_l_V_Bb, 0xe4, "bbsc", -0, OP3_l_V_Bb, 0xe5, "bbcc", -0, OP3_l_V_Bb, 0xe6, "bbssi", -0, OP3_l_V_Bb, 0xe7, "bbcci", -0, OP2_l_Bb, 0xe8, "blbs", -0, OP2_l_Bb, 0xe9, "blbc", -0, OP1_Be, 0x14, "jgtr", -0, OP1_Be, 0x15, "jleq", -0, OP1_Be, 0x12, "jneq", -0, OP1_Be, 0x12, "jnequ", -0, OP1_Be, 0x13, "jeql", -0, OP1_Be, 0x13, "jeqlu", -0, OP1_Be, 0x18, "jgeq", -0, OP1_Be, 0x19, "jlss", -0, OP1_Be, 0x1a, "jgtru", -0, OP1_Be, 0x1b, "jlequ", -0, OP1_Be, 0x1c, "jvc", -0, OP1_Be, 0x1d, "jvs", -0, OP1_Be, 0x1e, "jgequ", -0, OP1_Be, 0x1e, "jcc", -0, OP1_Be, 0x1f, "jlssu", -0, OP1_Be, 0x1f, "jcs", -0, OP2_l_Be, 0xe8, "jlbs", -0, OP2_l_Be, 0xe9, "jlbc", -0, OP3_l_V_Be, 0xe0, "jbs", -0, OP3_l_V_Be, 0xe1, "jbc", -0, OP3_l_V_Be, 0xe2, "jbss", -0, OP3_l_V_Be, 0xe3, "jbcs", -0, OP3_l_V_Be, 0xe4, "jbsc", -0, OP3_l_V_Be, 0xe5, "jbcc", -0, OP3_l_V_Be, 0xe6, "jbssi", -0, OP3_l_V_Be, 0xe7, "jbcci", -0, OP1_Bx, 0x11, "br", -0, OP1_BX, 0x11|(1L<<16), "brb", -0, OP1_BX, 0x31|(2L<<16), "brw", -0, OP1_Be, 0x11, "jbr", -0, OP1_Bx, 0x10, "bsb", -0, OP1_BX, 0x10|(1L<<16), "bsbb", -0, OP1_BX, 0x30|(2L<<16), "bsbw", -0, CASE_X_X_X, 0x8f|(1L<<16), "caseb", -0, CASE_X_X_X, 0xaf|(2L<<16), "casew", -0, CASE_X_X_X, 0xcf|(4L<<16), "casel", -0, OP1_A, 0x17, "jmp", -0, OP1_A, 0x16, "jsb", -0, OP0, 0x05, "rsb", -0, OP2_l_Bb, 0xf4, "sobgeq", -0, OP2_l_Bb, 0xf5, "sobgtr", +{0, OP4_b_b_b_Bw, 0x9d, "acbb"}, +{0, OP4_w_w_w_Bw, 0x3d, "acbw"}, +{0, OP4_l_l_l_Bw, 0xf1, "acbl"}, +{0, OP4_u_u_u_Bw, 0x4f, "acbf"}, +{0, OP4_u_u_u_Bw, 0x6f, "acbd"}, +{0, OP4_u_u_u_Bw, 0x4ffd, "acbg"}, +{0, OP4_u_u_u_Bw, 0x6ffd, "acbh"}, +{0, OP3_l_l_Bb, 0xf3, "aobleq"}, +{0, OP3_l_l_Bb, 0xf2, "aoblss"}, +{0, OP1_BX, 0x14|(1L<<16), "bgtr"}, +{0, OP1_BX, 0x15|(1L<<16), "bleq"}, +{0, OP1_BX, 0x12|(1L<<16), "bneq"}, +{0, OP1_BX, 0x12|(1L<<16), "bnequ"}, +{0, OP1_BX, 0x13|(1L<<16), "beql"}, +{0, OP1_BX, 0x13|(1L<<16), "beqlu"}, +{0, OP1_BX, 0x18|(1L<<16), "bgeq"}, +{0, OP1_BX, 0x19|(1L<<16), "blss"}, +{0, OP1_BX, 0x1a|(1L<<16), "bgtru"}, +{0, OP1_BX, 0x1b|(1L<<16), "blequ"}, +{0, OP1_BX, 0x1c|(1L<<16), "bvc"}, +{0, OP1_BX, 0x1d|(1L<<16), "bvs"}, +{0, OP1_BX, 0x1e|(1L<<16), "bgequ"}, +{0, OP1_BX, 0x1e|(1L<<16), "bcc"}, +{0, OP1_BX, 0x1f|(1L<<16), "blssu"}, +{0, OP1_BX, 0x1f|(1L<<16), "bcs"}, +{0, OP3_l_V_Bb, 0xe0, "bbs"}, +{0, OP3_l_V_Bb, 0xe1, "bbc"}, +{0, OP3_l_V_Bb, 0xe2, "bbss"}, +{0, OP3_l_V_Bb, 0xe3, "bbcs"}, +{0, OP3_l_V_Bb, 0xe4, "bbsc"}, +{0, OP3_l_V_Bb, 0xe5, "bbcc"}, +{0, OP3_l_V_Bb, 0xe6, "bbssi"}, +{0, OP3_l_V_Bb, 0xe7, "bbcci"}, +{0, OP2_l_Bb, 0xe8, "blbs"}, +{0, OP2_l_Bb, 0xe9, "blbc"}, +{0, OP1_Be, 0x14, "jgtr"}, +{0, OP1_Be, 0x15, "jleq"}, +{0, OP1_Be, 0x12, "jneq"}, +{0, OP1_Be, 0x12, "jnequ"}, +{0, OP1_Be, 0x13, "jeql"}, +{0, OP1_Be, 0x13, "jeqlu"}, +{0, OP1_Be, 0x18, "jgeq"}, +{0, OP1_Be, 0x19, "jlss"}, +{0, OP1_Be, 0x1a, "jgtru"}, +{0, OP1_Be, 0x1b, "jlequ"}, +{0, OP1_Be, 0x1c, "jvc"}, +{0, OP1_Be, 0x1d, "jvs"}, +{0, OP1_Be, 0x1e, "jgequ"}, +{0, OP1_Be, 0x1e, "jcc"}, +{0, OP1_Be, 0x1f, "jlssu"}, +{0, OP1_Be, 0x1f, "jcs"}, +{0, OP2_l_Be, 0xe8, "jlbs"}, +{0, OP2_l_Be, 0xe9, "jlbc"}, +{0, OP3_l_V_Be, 0xe0, "jbs"}, +{0, OP3_l_V_Be, 0xe1, "jbc"}, +{0, OP3_l_V_Be, 0xe2, "jbss"}, +{0, OP3_l_V_Be, 0xe3, "jbcs"}, +{0, OP3_l_V_Be, 0xe4, "jbsc"}, +{0, OP3_l_V_Be, 0xe5, "jbcc"}, +{0, OP3_l_V_Be, 0xe6, "jbssi"}, +{0, OP3_l_V_Be, 0xe7, "jbcci"}, +{0, OP1_Bx, 0x11, "br"}, +{0, OP1_BX, 0x11|(1L<<16), "brb"}, +{0, OP1_BX, 0x31|(2L<<16), "brw"}, +{0, OP1_Be, 0x11, "jbr"}, +{0, OP1_Bx, 0x10, "bsb"}, +{0, OP1_BX, 0x10|(1L<<16), "bsbb"}, +{0, OP1_BX, 0x30|(2L<<16), "bsbw"}, +{0, CASE_X_X_X, 0x8f|(1L<<16), "caseb"}, +{0, CASE_X_X_X, 0xaf|(2L<<16), "casew"}, +{0, CASE_X_X_X, 0xcf|(4L<<16), "casel"}, +{0, OP1_A, 0x17, "jmp"}, +{0, OP1_A, 0x16, "jsb"}, +{0, OP0, 0x05, "rsb"}, +{0, OP2_l_Bb, 0xf4, "sobgeq"}, +{0, OP2_l_Bb, 0xf5, "sobgtr"}, /* Procedure call instructions */ -0, OP2_A_A, 0xfa, "callg", -0, OP2_l_A, 0xfb, "calls", -0, OP0, 0x04, "ret", +{0, OP2_A_A, 0xfa, "callg"}, +{0, OP2_l_A, 0xfb, "calls"}, +{0, OP0, 0x04, "ret"}, /* Miscellaneous instructions */ -0, OP1_X, 0xb9|(2L<<16), "bicpsw", -0, OP1_X, 0xb8|(2L<<16), "bispsw", -0, OP0, 0x03, "bpt", -0, OP0, 0x00, "halt", -0, OP6_l_l_l_l_l_l,0x0a, "index", -0, OP1_X, 0xdc|(4L<<16), "movpsl", -0, OP0, 0x01, "nop", -0, OP1_X, 0xba|(2L<<16), "popr", -0, OP1_X, 0xbb|(2L<<16), "pushr", -0, OP0, 0xfc, "xfc", +{0, OP1_X, 0xb9|(2L<<16), "bicpsw"}, +{0, OP1_X, 0xb8|(2L<<16), "bispsw"}, +{0, OP0, 0x03, "bpt"}, +{0, OP0, 0x00, "halt"}, +{0, OP6_l_l_l_l_l_l,0x0a, "index"}, +{0, OP1_X, 0xdc|(4L<<16), "movpsl"}, +{0, OP0, 0x01, "nop"}, +{0, OP1_X, 0xba|(2L<<16), "popr"}, +{0, OP1_X, 0xbb|(2L<<16), "pushr"}, +{0, OP0, 0xfc, "xfc"}, /* Queue instructions */ -0, OP2_A_A, 0x5c, "insqhi", -0, OP2_A_A, 0x5d, "insqti", -0, OP2_A_A, 0x0e, "insque", -0, OP2_A_l, 0x5e, "remqhi", -0, OP2_A_l, 0x5f, "remqti", -0, OP2_A_l, 0x0f, "remque", +{0, OP2_A_A, 0x5c, "insqhi"}, +{0, OP2_A_A, 0x5d, "insqti"}, +{0, OP2_A_A, 0x0e, "insque"}, +{0, OP2_A_l, 0x5e, "remqhi"}, +{0, OP2_A_l, 0x5f, "remqti"}, +{0, OP2_A_l, 0x0f, "remque"}, /* Floating point instructions */ -0, OP2_u_u, 0x40, "addf2", -0, OP3_u_u_u, 0x41, "addf3", -0, OP2_u_u, 0x60, "addd2", -0, OP3_u_u_u, 0x61, "addd3", -0, OP2_u_u, 0x40fd, "addg2", -0, OP3_u_u_u, 0x41fd, "addg3", -0, OP2_u_u, 0x60fd, "addh2", -0, OP3_u_u_u, 0x61fd, "addh3", -0, OP1_u, 0xd4, "clrf", -0, OP1_u, 0x7c, "clrd", -0, OP1_u, 0x7c, "clrg", -0, OP1_u, 0x7cfd, "clrh", -0, OP2_u_u, 0x51, "cmpf", -0, OP2_u_u, 0x71, "cmpd", -0, OP2_u_u, 0x51fd, "cmpg", -0, OP2_u_u, 0x71fd, "cmph", -0, OP2_b_u, 0x4c, "cvtbf", -0, OP2_b_u, 0x6c, "cvtbd", -0, OP2_b_u, 0x4cfd, "cvtbg", -0, OP2_b_u, 0x6cfd, "cvtbh", -0, OP2_w_u, 0x4d, "cvtwf", -0, OP2_w_u, 0x6d, "cvtwd", -0, OP2_w_u, 0x4dfd, "cvtwg", -0, OP2_w_u, 0x6dfd, "cvtwh", -0, OP2_l_u, 0x4e, "cvtlf", -0, OP2_l_u, 0x6e, "cvtld", -0, OP2_l_u, 0x4efd, "cvtlg", -0, OP2_l_u, 0x6efd, "cvtlh", -0, OP2_u_b, 0x48, "cvtfb", -0, OP2_u_b, 0x68, "cvtdb", -0, OP2_u_b, 0x48fd, "cvtgb", -0, OP2_u_b, 0x68fd, "cvthb", -0, OP2_u_w, 0x49, "cvtfw", -0, OP2_u_w, 0x69, "cvtdw", -0, OP2_u_w, 0x49fd, "cvtgw", -0, OP2_u_w, 0x69fd, "cvthw", -0, OP2_u_l, 0x4a, "cvtfl", -0, OP2_u_l, 0x6a, "cvtdl", -0, OP2_u_l, 0x4afd, "cvtgl", -0, OP2_u_l, 0x6afd, "cvthl", -0, OP2_u_l, 0x4b, "cvtrfl", -0, OP2_u_l, 0x6b, "cvtrdl", -0, OP2_u_l, 0x4bfd, "cvtrgl", -0, OP2_u_l, 0x6bfd, "cvtrhl", -0, OP2_u_u, 0x56, "cvtfd", -0, OP2_u_u, 0x99fd, "cvtfg", -0, OP2_u_u, 0x98fd, "cvtfh", -0, OP2_u_u, 0x76, "cvtdf", -0, OP2_u_u, 0x32fd, "cvtdh", -0, OP2_u_u, 0x33fd, "cvtgf", -0, OP2_u_u, 0x56fd, "cvtgh", -0, OP2_u_u, 0xf6fd, "cvthf", -0, OP2_u_u, 0xf7fd, "cvthd", -0, OP2_u_u, 0x76fd, "cvthg", -0, OP2_u_u, 0x46, "divf2", -0, OP3_u_u_u, 0x47, "divf3", -0, OP2_u_u, 0x66, "divd2", -0, OP3_u_u_u, 0x67, "divd3", -0, OP2_u_u, 0x46fd, "divg2", -0, OP3_u_u_u, 0x47fd, "divg3", -0, OP2_u_u, 0x66fd, "divh2", -0, OP3_u_u_u, 0x67fd, "divh3", -0, OP5_u_b_u_l_u, 0x54, "emodf", -0, OP5_u_b_u_l_u, 0x74, "emodd", -0, OP5_u_w_u_l_u, 0x54fd, "emodg", -0, OP5_u_w_u_l_u, 0x74fd, "emodh", -0, OP2_u_u, 0x52, "mnegf", -0, OP2_u_u, 0x72, "mnegd", -0, OP2_u_u, 0x52fd, "mnegg", -0, OP2_u_u, 0x72fd, "mnegh", -0, OP2_u_u, 0x50, "movf", -0, OP2_u_u, 0x70, "movd", -0, OP2_u_u, 0x50fd, "movg", -0, OP2_u_u, 0x70fd, "movh", -0, OP2_u_u, 0x44, "mulf2", -0, OP3_u_u_u, 0x45, "mulf3", -0, OP2_u_u, 0x64, "muld2", -0, OP3_u_u_u, 0x65, "muld3", -0, OP2_u_u, 0x44fd, "mulg2", -0, OP3_u_u_u, 0x45fd, "mulg3", -0, OP2_u_u, 0x64fd, "mulh2", -0, OP3_u_u_u, 0x65fd, "mulh3", -0, OP3_u_w_A, 0x55, "polyf", -0, OP3_u_w_A, 0x75, "polyd", -0, OP3_u_w_A, 0x55fd, "polyg", -0, OP3_u_w_A, 0x75fd, "polyh", -0, OP2_u_u, 0x42, "subf2", -0, OP3_u_u_u, 0x43, "subf3", -0, OP2_u_u, 0x62, "subd2", -0, OP3_u_u_u, 0x63, "subd3", -0, OP2_u_u, 0x42fd, "subg2", -0, OP3_u_u_u, 0x43fd, "subg3", -0, OP2_u_u, 0x62fd, "subh2", -0, OP3_u_u_u, 0x63fd, "subh3", -0, OP1_u, 0x53, "tstf", -0, OP1_u, 0x73, "tstd", -0, OP1_u, 0x53fd, "tstg", -0, OP1_u, 0x73fd, "tsth", +{0, OP2_u_u, 0x40, "addf2"}, +{0, OP3_u_u_u, 0x41, "addf3"}, +{0, OP2_u_u, 0x60, "addd2"}, +{0, OP3_u_u_u, 0x61, "addd3"}, +{0, OP2_u_u, 0x40fd, "addg2"}, +{0, OP3_u_u_u, 0x41fd, "addg3"}, +{0, OP2_u_u, 0x60fd, "addh2"}, +{0, OP3_u_u_u, 0x61fd, "addh3"}, +{0, OP1_u, 0xd4, "clrf"}, +{0, OP1_u, 0x7c, "clrd"}, +{0, OP1_u, 0x7c, "clrg"}, +{0, OP1_u, 0x7cfd, "clrh"}, +{0, OP2_u_u, 0x51, "cmpf"}, +{0, OP2_u_u, 0x71, "cmpd"}, +{0, OP2_u_u, 0x51fd, "cmpg"}, +{0, OP2_u_u, 0x71fd, "cmph"}, +{0, OP2_b_u, 0x4c, "cvtbf"}, +{0, OP2_b_u, 0x6c, "cvtbd"}, +{0, OP2_b_u, 0x4cfd, "cvtbg"}, +{0, OP2_b_u, 0x6cfd, "cvtbh"}, +{0, OP2_w_u, 0x4d, "cvtwf"}, +{0, OP2_w_u, 0x6d, "cvtwd"}, +{0, OP2_w_u, 0x4dfd, "cvtwg"}, +{0, OP2_w_u, 0x6dfd, "cvtwh"}, +{0, OP2_l_u, 0x4e, "cvtlf"}, +{0, OP2_l_u, 0x6e, "cvtld"}, +{0, OP2_l_u, 0x4efd, "cvtlg"}, +{0, OP2_l_u, 0x6efd, "cvtlh"}, +{0, OP2_u_b, 0x48, "cvtfb"}, +{0, OP2_u_b, 0x68, "cvtdb"}, +{0, OP2_u_b, 0x48fd, "cvtgb"}, +{0, OP2_u_b, 0x68fd, "cvthb"}, +{0, OP2_u_w, 0x49, "cvtfw"}, +{0, OP2_u_w, 0x69, "cvtdw"}, +{0, OP2_u_w, 0x49fd, "cvtgw"}, +{0, OP2_u_w, 0x69fd, "cvthw"}, +{0, OP2_u_l, 0x4a, "cvtfl"}, +{0, OP2_u_l, 0x6a, "cvtdl"}, +{0, OP2_u_l, 0x4afd, "cvtgl"}, +{0, OP2_u_l, 0x6afd, "cvthl"}, +{0, OP2_u_l, 0x4b, "cvtrfl"}, +{0, OP2_u_l, 0x6b, "cvtrdl"}, +{0, OP2_u_l, 0x4bfd, "cvtrgl"}, +{0, OP2_u_l, 0x6bfd, "cvtrhl"}, +{0, OP2_u_u, 0x56, "cvtfd"}, +{0, OP2_u_u, 0x99fd, "cvtfg"}, +{0, OP2_u_u, 0x98fd, "cvtfh"}, +{0, OP2_u_u, 0x76, "cvtdf"}, +{0, OP2_u_u, 0x32fd, "cvtdh"}, +{0, OP2_u_u, 0x33fd, "cvtgf"}, +{0, OP2_u_u, 0x56fd, "cvtgh"}, +{0, OP2_u_u, 0xf6fd, "cvthf"}, +{0, OP2_u_u, 0xf7fd, "cvthd"}, +{0, OP2_u_u, 0x76fd, "cvthg"}, +{0, OP2_u_u, 0x46, "divf2"}, +{0, OP3_u_u_u, 0x47, "divf3"}, +{0, OP2_u_u, 0x66, "divd2"}, +{0, OP3_u_u_u, 0x67, "divd3"}, +{0, OP2_u_u, 0x46fd, "divg2"}, +{0, OP3_u_u_u, 0x47fd, "divg3"}, +{0, OP2_u_u, 0x66fd, "divh2"}, +{0, OP3_u_u_u, 0x67fd, "divh3"}, +{0, OP5_u_b_u_l_u, 0x54, "emodf"}, +{0, OP5_u_b_u_l_u, 0x74, "emodd"}, +{0, OP5_u_w_u_l_u, 0x54fd, "emodg"}, +{0, OP5_u_w_u_l_u, 0x74fd, "emodh"}, +{0, OP2_u_u, 0x52, "mnegf"}, +{0, OP2_u_u, 0x72, "mnegd"}, +{0, OP2_u_u, 0x52fd, "mnegg"}, +{0, OP2_u_u, 0x72fd, "mnegh"}, +{0, OP2_u_u, 0x50, "movf"}, +{0, OP2_u_u, 0x70, "movd"}, +{0, OP2_u_u, 0x50fd, "movg"}, +{0, OP2_u_u, 0x70fd, "movh"}, +{0, OP2_u_u, 0x44, "mulf2"}, +{0, OP3_u_u_u, 0x45, "mulf3"}, +{0, OP2_u_u, 0x64, "muld2"}, +{0, OP3_u_u_u, 0x65, "muld3"}, +{0, OP2_u_u, 0x44fd, "mulg2"}, +{0, OP3_u_u_u, 0x45fd, "mulg3"}, +{0, OP2_u_u, 0x64fd, "mulh2"}, +{0, OP3_u_u_u, 0x65fd, "mulh3"}, +{0, OP3_u_w_A, 0x55, "polyf"}, +{0, OP3_u_w_A, 0x75, "polyd"}, +{0, OP3_u_w_A, 0x55fd, "polyg"}, +{0, OP3_u_w_A, 0x75fd, "polyh"}, +{0, OP2_u_u, 0x42, "subf2"}, +{0, OP3_u_u_u, 0x43, "subf3"}, +{0, OP2_u_u, 0x62, "subd2"}, +{0, OP3_u_u_u, 0x63, "subd3"}, +{0, OP2_u_u, 0x42fd, "subg2"}, +{0, OP3_u_u_u, 0x43fd, "subg3"}, +{0, OP2_u_u, 0x62fd, "subh2"}, +{0, OP3_u_u_u, 0x63fd, "subh3"}, +{0, OP1_u, 0x53, "tstf"}, +{0, OP1_u, 0x73, "tstd"}, +{0, OP1_u, 0x53fd, "tstg"}, +{0, OP1_u, 0x73fd, "tsth"}, /* Character string instructions */ -0, OP3_w_A_A, 0x29, "cmpc3", -0, OP5_w_A_b_w_A, 0x2d, "cmpc5", -0, OP3_b_w_A, 0x3a, "locc", -0, OP4_w_A_w_A, 0x39, "matchc", -0, OP3_w_A_A, 0x28, "movc3", -0, OP5_w_A_b_w_A, 0x2c, "movc5", -0, OP6_w_A_b_A_w_A,0x2e, "movtc", -0, OP6_w_A_b_A_w_A,0x2f, "movtuc", -0, OP4_w_A_A_b, 0x2a, "scanc", -0, OP3_b_w_A, 0x3b, "skpc", -0, OP4_w_A_A_b, 0x2b, "spanc", +{0, OP3_w_A_A, 0x29, "cmpc3"}, +{0, OP5_w_A_b_w_A, 0x2d, "cmpc5"}, +{0, OP3_b_w_A, 0x3a, "locc"}, +{0, OP4_w_A_w_A, 0x39, "matchc"}, +{0, OP3_w_A_A, 0x28, "movc3"}, +{0, OP5_w_A_b_w_A, 0x2c, "movc5"}, +{0, OP6_w_A_b_A_w_A,0x2e, "movtc"}, +{0, OP6_w_A_b_A_w_A,0x2f, "movtuc"}, +{0, OP4_w_A_A_b, 0x2a, "scanc"}, +{0, OP3_b_w_A, 0x3b, "skpc"}, +{0, OP4_w_A_A_b, 0x2b, "spanc"}, /* Cyclic redundancy check instructions */ -0, OP4_A_l_w_A, 0x0b, "crc", +{0, OP4_A_l_w_A, 0x0b, "crc"}, /* Decimal string instructions */ -0, OP4_w_A_w_A, 0x20, "addp4", -0, OP6_w_A_w_A_w_A,0x21, "addp6", -0, OP6_b_w_A_b_w_A,0xf8, "ashp", -0, OP3_w_A_A, 0x35, "cmpp3", -0, OP4_w_A_w_A, 0x37, "cmpp4", -0, OP3_l_w_A, 0xf9, "cvtlp", -0, OP3_w_A_l, 0x36, "cvtpl", -0, OP4_w_A_w_A, 0x08, "cvtps", -0, OP5_w_A_A_w_A, 0x24, "cvtpt", -0, OP4_w_A_w_A, 0x09, "cvtsp", -0, OP5_w_A_A_w_A, 0x26, "cvttp", -0, OP6_w_A_w_A_w_A,0x27, "divp", -0, OP3_w_A_A, 0x34, "movp", -0, OP6_w_A_w_A_w_A,0x25, "mulp", -0, OP4_w_A_w_A, 0x22, "subp4", -0, OP6_w_A_w_A_w_A,0x23, "subp6", +{0, OP4_w_A_w_A, 0x20, "addp4"}, +{0, OP6_w_A_w_A_w_A,0x21, "addp6"}, +{0, OP6_b_w_A_b_w_A,0xf8, "ashp"}, +{0, OP3_w_A_A, 0x35, "cmpp3"}, +{0, OP4_w_A_w_A, 0x37, "cmpp4"}, +{0, OP3_l_w_A, 0xf9, "cvtlp"}, +{0, OP3_w_A_l, 0x36, "cvtpl"}, +{0, OP4_w_A_w_A, 0x08, "cvtps"}, +{0, OP5_w_A_A_w_A, 0x24, "cvtpt"}, +{0, OP4_w_A_w_A, 0x09, "cvtsp"}, +{0, OP5_w_A_A_w_A, 0x26, "cvttp"}, +{0, OP6_w_A_w_A_w_A,0x27, "divp"}, +{0, OP3_w_A_A, 0x34, "movp"}, +{0, OP6_w_A_w_A_w_A,0x25, "mulp"}, +{0, OP4_w_A_w_A, 0x22, "subp4"}, +{0, OP6_w_A_w_A_w_A,0x23, "subp6"}, /* Edit instruction */ -0, OP4_w_A_A_A, 0x38, "editpc", +{0, OP4_w_A_A_A, 0x38, "editpc"}, /* Other VAX-11 instructions */ @@ -419,19 +419,19 @@ to the VAX-11 Architecture Reference Manual, Revision 6.1, 1982, the access type is b, which means that the operand is a branch displacement. */ -0, OP1_BX, 0xfeff|(2L<<16),"bugw", -0, OP1_BX, 0xfdff|(4L<<16),"bugl", +{0, OP1_BX, 0xfeff|(2L<<16),"bugw"}, +{0, OP1_BX, 0xfdff|(4L<<16),"bugl"}, -0, OP3_b_w_A, 0x0c, "prober", -0, OP3_b_w_A, 0x0d, "probew", +{0, OP3_b_w_A, 0x0c, "prober"}, +{0, OP3_b_w_A, 0x0d, "probew"}, -0, OP0, 0x02, "rei", -0, OP1_X, 0xbc|(2L<<16), "chmk", -0, OP1_X, 0xbd|(2L<<16), "chme", -0, OP1_X, 0xbe|(2L<<16), "chms", -0, OP1_X, 0xbf|(2L<<16), "chmu", +{0, OP0, 0x02, "rei"}, +{0, OP1_X, 0xbc|(2L<<16), "chmk"}, +{0, OP1_X, 0xbd|(2L<<16), "chme"}, +{0, OP1_X, 0xbe|(2L<<16), "chms"}, +{0, OP1_X, 0xbf|(2L<<16), "chmu"}, -0, OP0, 0x06, "ldpctx", -0, OP0, 0x07, "svpctx", -0, OP2_l_l, 0xda, "mtpr", -0, OP2_l_l, 0xdb, "mfpr", +{0, OP0, 0x06, "ldpctx"}, +{0, OP0, 0x07, "svpctx"}, +{0, OP2_l_l, 0xda, "mtpr"}, +{0, OP2_l_l, 0xdb, "mfpr"}, diff --git a/mach/vc4/as/mach3.c b/mach/vc4/as/mach3.c index 4ca73f4ed..b7b8d4792 100644 --- a/mach/vc4/as/mach3.c +++ b/mach/vc4/as/mach3.c @@ -7,147 +7,147 @@ /* Integer registers */ -0, GPR, 0, "r0", -0, GPR, 1, "r1", -0, GPR, 2, "r2", -0, GPR, 3, "r3", -0, GPR, 4, "r4", -0, GPR, 5, "r5", +{0, GPR, 0, "r0"}, +{0, GPR, 1, "r1"}, +{0, GPR, 2, "r2"}, +{0, GPR, 3, "r3"}, +{0, GPR, 4, "r4"}, +{0, GPR, 5, "r5"}, -0, GPR, 6, "r6", -0, GPR, 7, "r7", -0, GPR, 8, "r8", -0, GPR, 9, "r9", -0, GPR, 10, "r10", -0, GPR, 11, "r11", -0, GPR, 12, "r12", -0, GPR, 13, "r13", -0, GPR, 14, "r14", -0, GPR, 15, "r15", -0, GPR, 16, "r16", -0, GPR, 17, "r17", -0, GPR, 18, "r18", -0, GPR, 19, "r19", -0, GPR, 20, "r20", -0, GPR, 21, "r21", -0, GPR, 22, "r22", -0, GPR, 23, "r23", -0, GPR, 24, "r24", -0, GPR, 24, "fp", +{0, GPR, 6, "r6"}, +{0, GPR, 7, "r7"}, +{0, GPR, 8, "r8"}, +{0, GPR, 9, "r9"}, +{0, GPR, 10, "r10"}, +{0, GPR, 11, "r11"}, +{0, GPR, 12, "r12"}, +{0, GPR, 13, "r13"}, +{0, GPR, 14, "r14"}, +{0, GPR, 15, "r15"}, +{0, GPR, 16, "r16"}, +{0, GPR, 17, "r17"}, +{0, GPR, 18, "r18"}, +{0, GPR, 19, "r19"}, +{0, GPR, 20, "r20"}, +{0, GPR, 21, "r21"}, +{0, GPR, 22, "r22"}, +{0, GPR, 23, "r23"}, +{0, GPR, 24, "r24"}, +{0, GPR, 24, "fp"}, -0, GPR, 25, "r25", -0, GPR, 25, "sp", -0, GPR, 26, "r26", -0, GPR, 26, "lr", -0, GPR, 27, "r27", -0, GPR, 28, "r28", -0, GPR, 29, "r29", -0, GPR, 30, "r30", -0, GPR, 30, "sr", -0, GPR, 31, "r31", -0, GPR, 31, "pc", +{0, GPR, 25, "r25"}, +{0, GPR, 25, "sp"}, +{0, GPR, 26, "r26"}, +{0, GPR, 26, "lr"}, +{0, GPR, 27, "r27"}, +{0, GPR, 28, "r28"}, +{0, GPR, 29, "r29"}, +{0, GPR, 30, "r30"}, +{0, GPR, 30, "sr"}, +{0, GPR, 31, "r31"}, +{0, GPR, 31, "pc"}, /* Condition codes */ -0, CC, 0, ".eq", -0, CC, 1, ".ne", -0, CC, 2, ".cs", -0, CC, 2, ".lo", -0, CC, 3, ".cc", -0, CC, 3, ".hs", -0, CC, 4, ".mi", -0, CC, 5, ".pl", -0, CC, 6, ".vs", -0, CC, 7, ".vc", -0, CC, 8, ".hi", -0, CC, 9, ".ls", -0, CC, 10, ".ge", -0, CC, 11, ".lt", -0, CC, 12, ".gt", -0, CC, 13, ".le", -0, CC, 15, ".f", +{0, CC, 0, ".eq"}, +{0, CC, 1, ".ne"}, +{0, CC, 2, ".cs"}, +{0, CC, 2, ".lo"}, +{0, CC, 3, ".cc"}, +{0, CC, 3, ".hs"}, +{0, CC, 4, ".mi"}, +{0, CC, 5, ".pl"}, +{0, CC, 6, ".vs"}, +{0, CC, 7, ".vc"}, +{0, CC, 8, ".hi"}, +{0, CC, 9, ".ls"}, +{0, CC, 10, ".ge"}, +{0, CC, 11, ".lt"}, +{0, CC, 12, ".gt"}, +{0, CC, 13, ".le"}, +{0, CC, 15, ".f"}, /* Special instructions */ -0, OP, B16(00000000,00000001), "nop", -0, OP, B16(00000000,00001010), "rti", +{0, OP, B16(00000000,00000001), "nop"}, +{0, OP, B16(00000000,00001010), "rti"}, -0, OP_BRANCH, 0, "b", -0, OP_BRANCHLINK, 0, "bl", -0, OP_ADDCMPB, 0, "addcmpb", +{0, OP_BRANCH, 0, "b"}, +{0, OP_BRANCHLINK, 0, "bl"}, +{0, OP_ADDCMPB, 0, "addcmpb"}, -0, OP_ONELREG, B16(00000000,10000000), "tbb", -0, OP_ONELREG, B16(00000000,10100000), "tbs", +{0, OP_ONELREG, B16(00000000,10000000), "tbb"}, +{0, OP_ONELREG, B16(00000000,10100000), "tbs"}, -0, OP_ALU, B8(00000000), "mov", -0, OP_ALU, B8(00000001), "cmn", -0, OP_ALU, B8(00000010), "add", -0, OP_ALU, B8(00000011), "bic", -0, OP_ALU, B8(00000100), "mul", -0, OP_ALU, B8(00000101), "eor", -0, OP_ALU, B8(00000110), "sub", -0, OP_ALU, B8(00000111), "and", -0, OP_ALU, B8(00001000), "mvn", -0, OP_ALU, B8(00001001), "ror", -0, OP_ALU, B8(00001010), "cmp", -0, OP_ALU, B8(00001011), "rsb", -0, OP_ALU, B8(00001100), "btst", -0, OP_ALU, B8(00001101), "or", -0, OP_ALU, B8(00001110), "extu", -0, OP_ALU, B8(00001111), "max", -0, OP_ALU, B8(00010000), "bset", -0, OP_ALU, B8(00010001), "min", -0, OP_ALU, B8(00010010), "bclr", -0, OP_ALU, B8(00010011), "adds2", -0, OP_ALU, B8(00010100), "bchg", -0, OP_ALU, B8(00010101), "adds4", -0, OP_ALU, B8(00010110), "adds8", -0, OP_ALU, B8(00010111), "adds16", -0, OP_ALU, B8(00011000), "exts", -0, OP_ALU, B8(00011001), "neg", -0, OP_ALU, B8(00011010), "lsr", -0, OP_ALU, B8(00011011), "log2", -0, OP_ALU, B8(00011100), "lsl", -0, OP_ALU, B8(00011101), "brev", -0, OP_ALU, B8(00011110), "asr", -0, OP_ALU, B8(00011111), "abs", +{0, OP_ALU, B8(00000000), "mov"}, +{0, OP_ALU, B8(00000001), "cmn"}, +{0, OP_ALU, B8(00000010), "add"}, +{0, OP_ALU, B8(00000011), "bic"}, +{0, OP_ALU, B8(00000100), "mul"}, +{0, OP_ALU, B8(00000101), "eor"}, +{0, OP_ALU, B8(00000110), "sub"}, +{0, OP_ALU, B8(00000111), "and"}, +{0, OP_ALU, B8(00001000), "mvn"}, +{0, OP_ALU, B8(00001001), "ror"}, +{0, OP_ALU, B8(00001010), "cmp"}, +{0, OP_ALU, B8(00001011), "rsb"}, +{0, OP_ALU, B8(00001100), "btst"}, +{0, OP_ALU, B8(00001101), "or"}, +{0, OP_ALU, B8(00001110), "extu"}, +{0, OP_ALU, B8(00001111), "max"}, +{0, OP_ALU, B8(00010000), "bset"}, +{0, OP_ALU, B8(00010001), "min"}, +{0, OP_ALU, B8(00010010), "bclr"}, +{0, OP_ALU, B8(00010011), "adds2"}, +{0, OP_ALU, B8(00010100), "bchg"}, +{0, OP_ALU, B8(00010101), "adds4"}, +{0, OP_ALU, B8(00010110), "adds8"}, +{0, OP_ALU, B8(00010111), "adds16"}, +{0, OP_ALU, B8(00011000), "exts"}, +{0, OP_ALU, B8(00011001), "neg"}, +{0, OP_ALU, B8(00011010), "lsr"}, +{0, OP_ALU, B8(00011011), "log2"}, +{0, OP_ALU, B8(00011100), "lsl"}, +{0, OP_ALU, B8(00011101), "brev"}, +{0, OP_ALU, B8(00011110), "asr"}, +{0, OP_ALU, B8(00011111), "abs"}, -0, OP_MISC, B16(11001000,00000000), "fadd", -0, OP_MISC, B16(11001000,00100000), "fsub", -0, OP_MISC, B16(11001000,01000000), "fmul", -0, OP_MISC, B16(11001000,01100000), "fdiv", -0, OP_MISC, B16(11001000,10000000), "fcmp", -0, OP_MISC, B16(11001000,10100000), "fabs", -0, OP_MISC, B16(11001000,11000000), "frsb", -0, OP_MISC, B16(11001000,11100000), "fmax", -0, OP_MISC, B16(11001001,00000000), "frcp", -0, OP_MISC, B16(11001001,00100000), "frsqrt", -0, OP_MISC, B16(11001001,01000000), "fnmul", -0, OP_MISC, B16(11001001,01100000), "fmin", -0, OP_MISC, B16(11001001,10000000), "fld1", -0, OP_MISC, B16(11001001,10100000), "fld0", -0, OP_MISC, B16(11001001,11000000), "log2", -0, OP_MISC, B16(11001001,11100000), "exp2", -0, OP_MISC, B16(11000101,11100000), "adds256", +{0, OP_MISC, B16(11001000,00000000), "fadd"}, +{0, OP_MISC, B16(11001000,00100000), "fsub"}, +{0, OP_MISC, B16(11001000,01000000), "fmul"}, +{0, OP_MISC, B16(11001000,01100000), "fdiv"}, +{0, OP_MISC, B16(11001000,10000000), "fcmp"}, +{0, OP_MISC, B16(11001000,10100000), "fabs"}, +{0, OP_MISC, B16(11001000,11000000), "frsb"}, +{0, OP_MISC, B16(11001000,11100000), "fmax"}, +{0, OP_MISC, B16(11001001,00000000), "frcp"}, +{0, OP_MISC, B16(11001001,00100000), "frsqrt"}, +{0, OP_MISC, B16(11001001,01000000), "fnmul"}, +{0, OP_MISC, B16(11001001,01100000), "fmin"}, +{0, OP_MISC, B16(11001001,10000000), "fld1"}, +{0, OP_MISC, B16(11001001,10100000), "fld0"}, +{0, OP_MISC, B16(11001001,11000000), "log2"}, +{0, OP_MISC, B16(11001001,11100000), "exp2"}, +{0, OP_MISC, B16(11000101,11100000), "adds256"}, -0, OP_FLTCNV, B16(11001010,00000000), "ftrunc", -0, OP_FLTCNV, B16(11001010,00100000), "floor", -0, OP_FLTCNV, B16(11001010,01000000), "flts", -0, OP_FLTCNV, B16(11001010,01100000), "fltu", +{0, OP_FLTCNV, B16(11001010,00000000), "ftrunc"}, +{0, OP_FLTCNV, B16(11001010,00100000), "floor"}, +{0, OP_FLTCNV, B16(11001010,01000000), "flts"}, +{0, OP_FLTCNV, B16(11001010,01100000), "fltu"}, -0, OP_MISCL, B16(11000100,10000000), "divs", -0, OP_MISCL, B16(11000100,11100000), "divu", +{0, OP_MISCL, B16(11000100,10000000), "divs"}, +{0, OP_MISCL, B16(11000100,11100000), "divu"}, -0, OP_STACK, B16(00000010,10000000), "push", -0, OP_STACK, B16(00000010,00000000), "pop", +{0, OP_STACK, B16(00000010,10000000), "push"}, +{0, OP_STACK, B16(00000010,00000000), "pop"}, -0, OP_MEM, B8(00000000), "ld", -0, OP_MEM, B8(00000001), "st", -0, OP_MEM, B8(00000010), "ldh", -0, OP_MEM, B8(00000011), "sth", -0, OP_MEM, B8(00000100), "ldb", -0, OP_MEM, B8(00000101), "stb", -0, OP_MEM, B8(00000110), "ldhs", -0, OP_MEM, B8(00000111), "sths", +{0, OP_MEM, B8(00000000), "ld"}, +{0, OP_MEM, B8(00000001), "st"}, +{0, OP_MEM, B8(00000010), "ldh"}, +{0, OP_MEM, B8(00000011), "sth"}, +{0, OP_MEM, B8(00000100), "ldb"}, +{0, OP_MEM, B8(00000101), "stb"}, +{0, OP_MEM, B8(00000110), "ldhs"}, +{0, OP_MEM, B8(00000111), "sths"}, -0, OP_LEA, 0, "lea", +{0, OP_LEA, 0, "lea"}, diff --git a/mach/z80/as/mach3.c b/mach/z80/as/mach3.c index 528b36655..063a9fce6 100644 --- a/mach/z80/as/mach3.c +++ b/mach/z80/as/mach3.c @@ -8,95 +8,95 @@ * Zilog Z80 keywords */ -0, R8, B, "b", -0, R8, C, "c", -0, R8, D, "d", -0, R8, E, "e", -0, R8, H, "h", -0, R8, L, "l", -0, R8, F, "f", -0, R8, A, "a", -0, R8, I, "i", -0, R8, R, "r", -0, R16, BC, "bc", -0, R16, DE, "de", -0, R16, HL, "hl", -0, R16, SP, "sp", -0, R16, AF, "af", -0, R16, AF2, "af2", -0, R16, IX, "ix", -0, R16, IY, "iy", -0, CC, 0, "nz", -0, CC, 1, "z", -0, CC, 2, "nc", -0, CC, 4, "po", -0, CC, 5, "pe", -0, CC, 6, "p", -0, CC, 7, "m", -0, LDOP, 0, "ld", -0, PSHPOP, 0305, "push", -0, PSHPOP, 0301, "pop", -0, EXOP, 0343, "ex", -0, NOOPOP, 0331, "exx", -0, E_ED, 0240, "ldi", -0, E_ED, 0260, "ldir", -0, E_ED, 0250, "ldd", -0, E_ED, 0270, "lddr", -0, E_ED, 0241, "cpi", -0, E_ED, 0261, "cpir", -0, E_ED, 0251, "cpd", -0, E_ED, 0271, "cpdr", -0, ADDOP, 0200, "add", -0, ADCSBC, 0210, "adc", -0, ADCSBC, 0230, "sbc", -0, ARI8, 0220, "sub", -0, ARI8, 0240, "and", -0, ARI8, 0260, "or", -0, ARI8, 0250, "xor", -0, ARI8, 0270, "cp", -0, INCDEC, 04, "inc", -0, INCDEC, 05, "dec", -0, NOOPOP, 047, "daa", -0, NOOPOP, 057, "cpl", -0, E_ED, 0104, "neg", -0, NOOPOP, 077, "ccf", -0, NOOPOP, 067, "scf", -0, NOOPOP, 0, "nop", -0, NOOPOP, 0166, "halt", -0, NOOPOP, 0363, "di", -0, NOOPOP, 0373, "ei", -0, IMOP, 0106, "im", -0, NOOPOP, 07, "rlca", -0, NOOPOP, 027, "rla", -0, NOOPOP, 017, "rrca", -0, NOOPOP, 037, "rra", -0, ROTATE, 0, "rlc", -0, ROTATE, 020, "rl", -0, ROTATE, 010, "rrc", -0, ROTATE, 030, "rr", -0, ROTATE, 040, "sla", -0, ROTATE, 050, "sra", -0, ROTATE, 070, "srl", -0, E_ED, 0157, "rld", -0, E_ED, 0147, "rrd", -0, BITS, 0100, "bit", -0, BITS, 0200, "res", -0, BITS, 0300, "set", -0, JP, 0303, "jp", -0, JR, 030, "jr", -0, DJNZ, 020, "djnz", -0, CALL, 0315, "call", -0, RET, 0311, "ret", -0, E_ED, 0115, "reti", -0, E_ED, 0105, "retn", -0, RST, 0307, "rst", -0, IN, 0333, "in", -0, E_ED, 0242, "ini", -0, E_ED, 0262, "inir", -0, E_ED, 0252, "ind", -0, E_ED, 0272, "indr", -0, OUT, 0323, "out", -0, E_ED, 0243, "outi", -0, E_ED, 0263, "otir", -0, E_ED, 0253, "outd", -0, E_ED, 0273, "otdr", +{0, R8, B, "b"}, +{0, R8, C, "c"}, +{0, R8, D, "d"}, +{0, R8, E, "e"}, +{0, R8, H, "h"}, +{0, R8, L, "l"}, +{0, R8, F, "f"}, +{0, R8, A, "a"}, +{0, R8, I, "i"}, +{0, R8, R, "r"}, +{0, R16, BC, "bc"}, +{0, R16, DE, "de"}, +{0, R16, HL, "hl"}, +{0, R16, SP, "sp"}, +{0, R16, AF, "af"}, +{0, R16, AF2, "af2"}, +{0, R16, IX, "ix"}, +{0, R16, IY, "iy"}, +{0, CC, 0, "nz"}, +{0, CC, 1, "z"}, +{0, CC, 2, "nc"}, +{0, CC, 4, "po"}, +{0, CC, 5, "pe"}, +{0, CC, 6, "p"}, +{0, CC, 7, "m"}, +{0, LDOP, 0, "ld"}, +{0, PSHPOP, 0305, "push"}, +{0, PSHPOP, 0301, "pop"}, +{0, EXOP, 0343, "ex"}, +{0, NOOPOP, 0331, "exx"}, +{0, E_ED, 0240, "ldi"}, +{0, E_ED, 0260, "ldir"}, +{0, E_ED, 0250, "ldd"}, +{0, E_ED, 0270, "lddr"}, +{0, E_ED, 0241, "cpi"}, +{0, E_ED, 0261, "cpir"}, +{0, E_ED, 0251, "cpd"}, +{0, E_ED, 0271, "cpdr"}, +{0, ADDOP, 0200, "add"}, +{0, ADCSBC, 0210, "adc"}, +{0, ADCSBC, 0230, "sbc"}, +{0, ARI8, 0220, "sub"}, +{0, ARI8, 0240, "and"}, +{0, ARI8, 0260, "or"}, +{0, ARI8, 0250, "xor"}, +{0, ARI8, 0270, "cp"}, +{0, INCDEC, 04, "inc"}, +{0, INCDEC, 05, "dec"}, +{0, NOOPOP, 047, "daa"}, +{0, NOOPOP, 057, "cpl"}, +{0, E_ED, 0104, "neg"}, +{0, NOOPOP, 077, "ccf"}, +{0, NOOPOP, 067, "scf"}, +{0, NOOPOP, 0, "nop"}, +{0, NOOPOP, 0166, "halt"}, +{0, NOOPOP, 0363, "di"}, +{0, NOOPOP, 0373, "ei"}, +{0, IMOP, 0106, "im"}, +{0, NOOPOP, 07, "rlca"}, +{0, NOOPOP, 027, "rla"}, +{0, NOOPOP, 017, "rrca"}, +{0, NOOPOP, 037, "rra"}, +{0, ROTATE, 0, "rlc"}, +{0, ROTATE, 020, "rl"}, +{0, ROTATE, 010, "rrc"}, +{0, ROTATE, 030, "rr"}, +{0, ROTATE, 040, "sla"}, +{0, ROTATE, 050, "sra"}, +{0, ROTATE, 070, "srl"}, +{0, E_ED, 0157, "rld"}, +{0, E_ED, 0147, "rrd"}, +{0, BITS, 0100, "bit"}, +{0, BITS, 0200, "res"}, +{0, BITS, 0300, "set"}, +{0, JP, 0303, "jp"}, +{0, JR, 030, "jr"}, +{0, DJNZ, 020, "djnz"}, +{0, CALL, 0315, "call"}, +{0, RET, 0311, "ret"}, +{0, E_ED, 0115, "reti"}, +{0, E_ED, 0105, "retn"}, +{0, RST, 0307, "rst"}, +{0, IN, 0333, "in"}, +{0, E_ED, 0242, "ini"}, +{0, E_ED, 0262, "inir"}, +{0, E_ED, 0252, "ind"}, +{0, E_ED, 0272, "indr"}, +{0, OUT, 0323, "out"}, +{0, E_ED, 0243, "outi"}, +{0, E_ED, 0263, "otir"}, +{0, E_ED, 0253, "outd"}, +{0, E_ED, 0273, "otdr"}, diff --git a/mach/z8000/as/mach3.c b/mach/z8000/as/mach3.c index bba4a7ba9..34cac9a54 100644 --- a/mach/z8000/as/mach3.c +++ b/mach/z8000/as/mach3.c @@ -7,157 +7,157 @@ /* ** Zilog z8000 keywords */ -0, R8, 8, "RL0", -0, R8, 0, "RH0", -0, R8, 9, "RL1", -0, R8, 1, "RH1", -0, R8, 10, "RL2", -0, R8, 2, "RH2", -0, R8, 11, "RL3", -0, R8, 3, "RH3", -0, R8, 12, "RL4", -0, R8, 4, "RH4", -0, R8, 13, "RL5", -0, R8, 5, "RH5", -0, R8, 14, "RL6", -0, R8, 6, "RH6", -0, R8, 15, "RL7", -0, R8, 7, "RH7", +{0, R8, 8, "RL0"}, +{0, R8, 0, "RH0"}, +{0, R8, 9, "RL1"}, +{0, R8, 1, "RH1"}, +{0, R8, 10, "RL2"}, +{0, R8, 2, "RH2"}, +{0, R8, 11, "RL3"}, +{0, R8, 3, "RH3"}, +{0, R8, 12, "RL4"}, +{0, R8, 4, "RH4"}, +{0, R8, 13, "RL5"}, +{0, R8, 5, "RH5"}, +{0, R8, 14, "RL6"}, +{0, R8, 6, "RH6"}, +{0, R8, 15, "RL7"}, +{0, R8, 7, "RH7"}, /* Special format for some byte-registers. Not really available on ** the z8000 but designed to ease writing a z8000-backend-table. ** LR[0..7] are equivalent with RL[0..7]. */ -0, R8, 8, "LR0", -0, R8, 9, "LR1", -0, R8, 10, "LR2", -0, R8, 11, "LR3", -0, R8, 12, "LR4", -0, R8, 13, "LR5", -0, R8, 14, "LR6", -0, R8, 15, "LR7", -0, R16, 0, "R0", -0, R16, 1, "R1", -0, R16, 2, "R2", -0, R16, 3, "R3", -0, R16, 4, "R4", -0, R16, 5, "R5", -0, R16, 6, "R6", -0, R16, 7, "R7", -0, R16, 8, "R8", -0, R16, 9, "R9", -0, R16, 10, "R10", -0, R16, 11, "R11", -0, R16, 12, "R12", -0, R16, 13, "R13", -0, R16, 14, "R14", -0, R16, 15, "R15", -0, R32, 0, "RR0", -0, R32, 2, "RR2", -0, R32, 4, "RR4", -0, R32, 6, "RR6", -0, R32, 8, "RR8", -0, R32, 10, "RR10", -0, R32, 12, "RR12", -0, R32, 14, "RR14", -0, R64, 0, "RQ0", -0, R64, 4, "RQ4", -0, R64, 8, "RQ8", -0, R64, 12, "RQ12", -0, CC, 14, "NZ", -0, CC, 15, "NC", -0, CC, 13, "PL", -0, CC, 5, "MI", -0, CC, 14, "NE", -0, CC, 6, "EQ", -0, CC, 4, "OV", -0, CC, 12, "NOV", -0, CC, 4, "PE", -0, CC, 12, "PO", -0, CC, 9, "GE", -0, CC, 1, "LT", -0, CC, 10, "GT", -0, CC, 2, "LE", -0, CC, 15, "UGE", -0, CC, 7, "ULT", -0, CC, 11, "UGT", -0, CC, 3, "ULE", -0, FLAG, 0x80, "C", -0, FLAG, 0x40, "Z", -0, FLAG, 0x20, "S", -0, FLAG, 0x10, "P", -0, FLAG, 0x10, "V", -0, INTCB, 2, "VI", -0, INTCB, 1, "NVI", -0, CTLRFLAGS, 1, "FLAGS", -0, CTLR, 2, "FCW", -0, CTLR, 3, "REFRESH", -0, CTLR, 4, "PSAPSEG", -0, CTLR, 5, "PSAPOFF", -0, CTLR, 6, "NSPSEG", -0, CTLR, 7, "NSPOFF", -0, CTLR, 5, "PSAP", -0, CTLR, 7, "NSP", +{0, R8, 8, "LR0"}, +{0, R8, 9, "LR1"}, +{0, R8, 10, "LR2"}, +{0, R8, 11, "LR3"}, +{0, R8, 12, "LR4"}, +{0, R8, 13, "LR5"}, +{0, R8, 14, "LR6"}, +{0, R8, 15, "LR7"}, +{0, R16, 0, "R0"}, +{0, R16, 1, "R1"}, +{0, R16, 2, "R2"}, +{0, R16, 3, "R3"}, +{0, R16, 4, "R4"}, +{0, R16, 5, "R5"}, +{0, R16, 6, "R6"}, +{0, R16, 7, "R7"}, +{0, R16, 8, "R8"}, +{0, R16, 9, "R9"}, +{0, R16, 10, "R10"}, +{0, R16, 11, "R11"}, +{0, R16, 12, "R12"}, +{0, R16, 13, "R13"}, +{0, R16, 14, "R14"}, +{0, R16, 15, "R15"}, +{0, R32, 0, "RR0"}, +{0, R32, 2, "RR2"}, +{0, R32, 4, "RR4"}, +{0, R32, 6, "RR6"}, +{0, R32, 8, "RR8"}, +{0, R32, 10, "RR10"}, +{0, R32, 12, "RR12"}, +{0, R32, 14, "RR14"}, +{0, R64, 0, "RQ0"}, +{0, R64, 4, "RQ4"}, +{0, R64, 8, "RQ8"}, +{0, R64, 12, "RQ12"}, +{0, CC, 14, "NZ"}, +{0, CC, 15, "NC"}, +{0, CC, 13, "PL"}, +{0, CC, 5, "MI"}, +{0, CC, 14, "NE"}, +{0, CC, 6, "EQ"}, +{0, CC, 4, "OV"}, +{0, CC, 12, "NOV"}, +{0, CC, 4, "PE"}, +{0, CC, 12, "PO"}, +{0, CC, 9, "GE"}, +{0, CC, 1, "LT"}, +{0, CC, 10, "GT"}, +{0, CC, 2, "LE"}, +{0, CC, 15, "UGE"}, +{0, CC, 7, "ULT"}, +{0, CC, 11, "UGT"}, +{0, CC, 3, "ULE"}, +{0, FLAG, 0x80, "C"}, +{0, FLAG, 0x40, "Z"}, +{0, FLAG, 0x20, "S"}, +{0, FLAG, 0x10, "P"}, +{0, FLAG, 0x10, "V"}, +{0, INTCB, 2, "VI"}, +{0, INTCB, 1, "NVI"}, +{0, CTLRFLAGS, 1, "FLAGS"}, +{0, CTLR, 2, "FCW"}, +{0, CTLR, 3, "REFRESH"}, +{0, CTLR, 4, "PSAPSEG"}, +{0, CTLR, 5, "PSAPOFF"}, +{0, CTLR, 6, "NSPSEG"}, +{0, CTLR, 7, "NSPOFF"}, +{0, CTLR, 5, "PSAP"}, +{0, CTLR, 7, "NSP"}, /* TYPE_11a23 */ -0, F1_1F2_3, 0x1F00, "call", -0, F1_1F2_3, 0x3900, "ldps", +{0, F1_1F2_3, 0x1F00, "call"}, +{0, F1_1F2_3, 0x3900, "ldps"}, /* TYPE_11b23 */ -0, F1_1F2_3, 0x0D08, "clr", -0, F1_1F2_3, 0x0C08, "clrb", -0, F1_1F2_3, 0x0D00, "com", -0, F1_1F2_3, 0x0C00, "comb", -0, F1_1F2_3, 0x0D02, "neg", -0, F1_1F2_3, 0x0C02, "negb", -0, F1_1F2_3, 0x0D04, "test", -0, F1_1F2_3, 0x0C04, "testb", -0, F1_1F2_3, 0x1C08, "testl", -0, F1_1F2_3, 0x0D06, "tset", -0, F1_1F2_3, 0x0C06, "tsetb", +{0, F1_1F2_3, 0x0D08, "clr"}, +{0, F1_1F2_3, 0x0C08, "clrb"}, +{0, F1_1F2_3, 0x0D00, "com"}, +{0, F1_1F2_3, 0x0C00, "comb"}, +{0, F1_1F2_3, 0x0D02, "neg"}, +{0, F1_1F2_3, 0x0C02, "negb"}, +{0, F1_1F2_3, 0x0D04, "test"}, +{0, F1_1F2_3, 0x0C04, "testb"}, +{0, F1_1F2_3, 0x1C08, "testl"}, +{0, F1_1F2_3, 0x0D06, "tset"}, +{0, F1_1F2_3, 0x0C06, "tsetb"}, -0, F1_1a, 0xB000, "dab", -0, F1_1a, 0xB10A, "exts", -0, F1_1a, 0xB100, "extsb", -0, F1_1a, 0xB107, "extsl", +{0, F1_1a, 0xB000, "dab"}, +{0, F1_1a, 0xB10A, "exts"}, +{0, F1_1a, 0xB100, "extsb"}, +{0, F1_1a, 0xB107, "extsl"}, -0, F1_1b, 0xB300, "rl", -0, F1_1b, 0xB200, "rlb", -0, F1_1b, 0xB308, "rlc", -0, F1_1b, 0xB208, "rlcb", -0, F1_1b, 0xB304, "rr", -0, F1_1b, 0xB204, "rrb", -0, F1_1b, 0xB30C, "rrc", -0, F1_1b, 0xB20C, "rrcb", +{0, F1_1b, 0xB300, "rl"}, +{0, F1_1b, 0xB200, "rlb"}, +{0, F1_1b, 0xB308, "rlc"}, +{0, F1_1b, 0xB208, "rlcb"}, +{0, F1_1b, 0xB304, "rr"}, +{0, F1_1b, 0xB204, "rrb"}, +{0, F1_1b, 0xB30C, "rrc"}, +{0, F1_1b, 0xB20C, "rrcb"}, /* TYPE_12 */ -0, F1_2, 0x2B00, "dec", -0, F1_2, 0x2A00, "decb", -0, F1_2, 0x2900, "inc", -0, F1_2, 0x2800, "incb", -0, LDK, 0xBD00, "ldk", +{0, F1_2, 0x2B00, "dec"}, +{0, F1_2, 0x2A00, "decb"}, +{0, F1_2, 0x2900, "inc"}, +{0, F1_2, 0x2800, "incb"}, +{0, LDK, 0xBD00, "ldk"}, /* TYPE_1263 */ -0, F1_2F6_3, 0x2700, "bit", -0, F1_2F6_3, 0x2600, "bitb", -0, F1_2F6_3, 0x2300, "res", -0, F1_2F6_3, 0x2200, "resb", -0, F1_2F6_3, 0x2500, "set", -0, F1_2F6_3, 0x2400, "setb", +{0, F1_2F6_3, 0x2700, "bit"}, +{0, F1_2F6_3, 0x2600, "bitb"}, +{0, F1_2F6_3, 0x2300, "res"}, +{0, F1_2F6_3, 0x2200, "resb"}, +{0, F1_2F6_3, 0x2500, "set"}, +{0, F1_2F6_3, 0x2400, "setb"}, /* TYPE_jp */ -0, JP, 0x1E00, "jp", +{0, JP, 0x1E00, "jp"}, -0, TCC, 0xAF00, "tcc", -0, TCC, 0xAE00, "tccb", +{0, TCC, 0xAF00, "tcc"}, +{0, TCC, 0xAE00, "tccb"}, /* TYPE_21a */ -0, F2_1, 0x2D00, "ex", -0, F2_1, 0x2C00, "exb", +{0, F2_1, 0x2D00, "ex"}, +{0, F2_1, 0x2C00, "exb"}, /* TYPE_21b */ -0, F2_1, 0x3500, "adc", -0, F2_1, 0x3400, "adcb", -0, F2_1, 0x3E00, "rldb", -0, F2_1, 0x3C00, "rrdb", -0, F2_1, 0x3700, "sbc", -0, F2_1, 0x3600, "sbcb", +{0, F2_1, 0x3500, "adc"}, +{0, F2_1, 0x3400, "adcb"}, +{0, F2_1, 0x3E00, "rldb"}, +{0, F2_1, 0x3C00, "rrdb"}, +{0, F2_1, 0x3700, "sbc"}, +{0, F2_1, 0x3600, "sbcb"}, /* TYPE_2151. ** Depending on their operands the cp-instructions might ** have an opcode of 0x201 more then listed below. This is @@ -165,160 +165,160 @@ ** The difference in opcode between byte-,word- and long- ** instructions of the F2_1F5_1 group is as follows: ** If bit 8 is on it is a word instruction; If it is not a - ** word instruction and bit 12 is on it is a long instruction, + ** word instruction and bit 12 is on it is a long instruction}, ** else it is a byte instruction. This information is used ** when one of the operands is of type IM. */ -0, F2_1F5_1, 0x0100, "add", -0, F2_1F5_1, 0x0000, "addb", -0, F2_1F5_1, 0x1600, "addl", -0, F2_1F5_1, 0x0700, "and", -0, F2_1F5_1, 0x0600, "andb", -0, F2_1F5_1, 0x1B00, "div", -0, F2_1F5_1, 0x1A00, "divl", -0, F2_1F5_1, 0x1900, "mult", -0, F2_1F5_1, 0x1800, "multl", -0, F2_1F5_1, 0x0500, "or", -0, F2_1F5_1, 0x0400, "orb", -0, F2_1F5_1, 0x0300, "sub", -0, F2_1F5_1, 0x0200, "subb", -0, F2_1F5_1, 0x1200, "subl", -0, F2_1F5_1, 0x0900, "xor", -0, F2_1F5_1, 0x0800, "xorb", -0, F2_1F5_1, 0x0B00, "cp", -0, F2_1F5_1, 0x0A00, "cpb", -0, F2_1F5_1, 0x1000, "cpl", +{0, F2_1F5_1, 0x0100, "add"}, +{0, F2_1F5_1, 0x0000, "addb"}, +{0, F2_1F5_1, 0x1600, "addl"}, +{0, F2_1F5_1, 0x0700, "and"}, +{0, F2_1F5_1, 0x0600, "andb"}, +{0, F2_1F5_1, 0x1B00, "div"}, +{0, F2_1F5_1, 0x1A00, "divl"}, +{0, F2_1F5_1, 0x1900, "mult"}, +{0, F2_1F5_1, 0x1800, "multl"}, +{0, F2_1F5_1, 0x0500, "or"}, +{0, F2_1F5_1, 0x0400, "orb"}, +{0, F2_1F5_1, 0x0300, "sub"}, +{0, F2_1F5_1, 0x0200, "subb"}, +{0, F2_1F5_1, 0x1200, "subl"}, +{0, F2_1F5_1, 0x0900, "xor"}, +{0, F2_1F5_1, 0x0800, "xorb"}, +{0, F2_1F5_1, 0x0B00, "cp"}, +{0, F2_1F5_1, 0x0A00, "cpb"}, +{0, F2_1F5_1, 0x1000, "cpl"}, -0, LDA, 0, "lda", +{0, LDA, 0, "lda"}, /* TYPE_pop */ -0, POP, 0x1700, "pop", -0, POP, 0x1500, "popl", +{0, POP, 0x1700, "pop"}, +{0, POP, 0x1500, "popl"}, /* TYPE_push */ -0, PUSH, 0x1300, "push", -0, PUSH, 0x1100, "pushl", +{0, PUSH, 0x1300, "push"}, +{0, PUSH, 0x1100, "pushl"}, /* TYPE_ld */ -0, LD, 0x0100, "ld", -0, LD, 0, "ldb", -0, LDL, 0, "ldl", +{0, LD, 0x0100, "ld"}, +{0, LD, 0, "ldb"}, +{0, LDL, 0, "ldl"}, -0, DJNZ, 0xF080, "djnz", -0, DJNZ, 0xF000, "dbjnz", -0, JR, 0xE000, "jr", -0, CALR, 0xD000, "calr", +{0, DJNZ, 0xF080, "djnz"}, +{0, DJNZ, 0xF000, "dbjnz"}, +{0, JR, 0xE000, "jr"}, +{0, CALR, 0xD000, "calr"}, /* Depending on their operands the LDR-instructions might ** have an opcode of 0x200 more then listed below. This is ** or-ed in at the appropriate place. */ -0, LDR, 0x3100, "ldr", -0, LDR, 0x3000, "ldrb", -0, LDR, 0x3500, "ldrl", +{0, LDR, 0x3100, "ldr"}, +{0, LDR, 0x3000, "ldrb"}, +{0, LDR, 0x3500, "ldrl"}, -0, LDAR, 0x3400, "ldar", +{0, LDAR, 0x3400, "ldar"}, -0, F5_1L, 0xB309, "sla", -0, F5_1L, 0xB209, "slab", -0, F5_1L, 0xB30D, "slal", -0, F5_1L, 0xB301, "sll", -0, F5_1L, 0xB201, "sllb", -0, F5_1L, 0xB305, "slll", -0, F5_1R, 0xB309, "sra", -0, F5_1R, 0xB209, "srab", -0, F5_1R, 0xB30D, "sral", -0, F5_1R, 0xB301, "srl", -0, F5_1R, 0xB201, "srlb", -0, F5_1R, 0xB305, "srll", +{0, F5_1L, 0xB309, "sla"}, +{0, F5_1L, 0xB209, "slab"}, +{0, F5_1L, 0xB30D, "slal"}, +{0, F5_1L, 0xB301, "sll"}, +{0, F5_1L, 0xB201, "sllb"}, +{0, F5_1L, 0xB305, "slll"}, +{0, F5_1R, 0xB309, "sra"}, +{0, F5_1R, 0xB209, "srab"}, +{0, F5_1R, 0xB30D, "sral"}, +{0, F5_1R, 0xB301, "srl"}, +{0, F5_1R, 0xB201, "srlb"}, +{0, F5_1R, 0xB305, "srll"}, /* Depending on its operands the LDM-instruction might have ** an opcode of 8 more then listed below. This is added at the ** appropriate place. ** TYPE_ldm */ -0, LDM, 0x1C01, "ldm", +{0, LDM, 0x1C01, "ldm"}, /* For the F6.4 instructions below the yylval-column contains ** the opcode for the instruction. However the third hexa-digit ** should be 0; But this is the opcode which must be put into ** the second word of the instruction! */ -0, F6_4, 0x3B88, "ind", -0, F6_4, 0x3A88, "indb", -0, F6_4, 0x3B08, "indr", -0, F6_4, 0x3A08, "indrb", -0, F6_4, 0x3B80, "ini", -0, F6_4, 0x3A80, "inib", -0, F6_4, 0x3B00, "inir", -0, F6_4, 0x3A00, "inirb", -0, F6_4, 0xBB89, "ldd", -0, F6_4, 0xBA89, "lddb", -0, F6_4, 0xBB09, "lddr", -0, F6_4, 0xBA09, "lddrb", -0, F6_4, 0xBB81, "ldi", -0, F6_4, 0xBA81, "ldib", -0, F6_4, 0xBB01, "ldir", -0, F6_4, 0xBA01, "ldirb", -0, F6_4, 0x3B0A, "otdr", -0, F6_4, 0x3A0A, "otdrb", -0, F6_4, 0x3B02, "otir", -0, F6_4, 0x3A02, "otirb", -0, F6_4, 0x3B8A, "outd", -0, F6_4, 0x3A8A, "outdb", -0, F6_4, 0x3B82, "outi", -0, F6_4, 0x3A82, "outib", -0, F6_4, 0x3B89, "sind", -0, F6_4, 0x3A89, "sindb", -0, F6_4, 0x3B09, "sindr", -0, F6_4, 0x3A09, "sindrb", -0, F6_4, 0x3B81, "sini", -0, F6_4, 0x3A81, "sinib", -0, F6_4, 0x3B01, "sinir", -0, F6_4, 0x3A01, "sinirb", -0, F6_4, 0x3B0B, "sotdr", -0, F6_4, 0x3A0B, "sotdrb", -0, F6_4, 0x3B03, "sotir", -0, F6_4, 0x3A03, "sotirb", -0, F6_4, 0x3B8B, "soutd", -0, F6_4, 0x3A8B, "soutdb", -0, F6_4, 0x3B83, "souti", -0, F6_4, 0x3A83, "soutib", -0, F6_4, 0xB808, "trdb", -0, F6_4, 0xB80C, "trdrb", -0, F6_4, 0xB800, "trib", -0, F6_4, 0xB804, "trirb", -0, F6_4, 0xB80A, "trtdb", -0, F6_4, 0xB8EE, "trtdrb", -0, F6_4, 0xB802, "trtib", -0, F6_4, 0xB8E6, "trtirb", +{0, F6_4, 0x3B88, "ind"}, +{0, F6_4, 0x3A88, "indb"}, +{0, F6_4, 0x3B08, "indr"}, +{0, F6_4, 0x3A08, "indrb"}, +{0, F6_4, 0x3B80, "ini"}, +{0, F6_4, 0x3A80, "inib"}, +{0, F6_4, 0x3B00, "inir"}, +{0, F6_4, 0x3A00, "inirb"}, +{0, F6_4, 0xBB89, "ldd"}, +{0, F6_4, 0xBA89, "lddb"}, +{0, F6_4, 0xBB09, "lddr"}, +{0, F6_4, 0xBA09, "lddrb"}, +{0, F6_4, 0xBB81, "ldi"}, +{0, F6_4, 0xBA81, "ldib"}, +{0, F6_4, 0xBB01, "ldir"}, +{0, F6_4, 0xBA01, "ldirb"}, +{0, F6_4, 0x3B0A, "otdr"}, +{0, F6_4, 0x3A0A, "otdrb"}, +{0, F6_4, 0x3B02, "otir"}, +{0, F6_4, 0x3A02, "otirb"}, +{0, F6_4, 0x3B8A, "outd"}, +{0, F6_4, 0x3A8A, "outdb"}, +{0, F6_4, 0x3B82, "outi"}, +{0, F6_4, 0x3A82, "outib"}, +{0, F6_4, 0x3B89, "sind"}, +{0, F6_4, 0x3A89, "sindb"}, +{0, F6_4, 0x3B09, "sindr"}, +{0, F6_4, 0x3A09, "sindrb"}, +{0, F6_4, 0x3B81, "sini"}, +{0, F6_4, 0x3A81, "sinib"}, +{0, F6_4, 0x3B01, "sinir"}, +{0, F6_4, 0x3A01, "sinirb"}, +{0, F6_4, 0x3B0B, "sotdr"}, +{0, F6_4, 0x3A0B, "sotdrb"}, +{0, F6_4, 0x3B03, "sotir"}, +{0, F6_4, 0x3A03, "sotirb"}, +{0, F6_4, 0x3B8B, "soutd"}, +{0, F6_4, 0x3A8B, "soutdb"}, +{0, F6_4, 0x3B83, "souti"}, +{0, F6_4, 0x3A83, "soutib"}, +{0, F6_4, 0xB808, "trdb"}, +{0, F6_4, 0xB80C, "trdrb"}, +{0, F6_4, 0xB800, "trib"}, +{0, F6_4, 0xB804, "trirb"}, +{0, F6_4, 0xB80A, "trtdb"}, +{0, F6_4, 0xB8EE, "trtdrb"}, +{0, F6_4, 0xB802, "trtib"}, +{0, F6_4, 0xB8E6, "trtirb"}, /* From the F6.5 instructions below the last eight ('string'- ** instructions) want an 'ir' as operand; The others want a 'r'. ** In the opcode for the string-instructions bit 1 is on, which ** indicates the difference. */ -0, F6_5, 0xBB08, "cpd", -0, F6_5, 0xBA08, "cpdb", -0, F6_5, 0xBB0C, "cpdr", -0, F6_5, 0xBA0C, "cpdrb", -0, F6_5, 0xBB00, "cpi", -0, F6_5, 0xBA00, "cpib", -0, F6_5, 0xBB04, "cpir", -0, F6_5, 0xBA04, "cpirb", -0, F6_5, 0xBB0A, "cpsd", -0, F6_5, 0xBA0A, "cpsdb", -0, F6_5, 0xBB0E, "cpsdr", -0, F6_5, 0xBA0E, "cpsdrb", -0, F6_5, 0xBB02, "cpsi", -0, F6_5, 0xBA02, "cpsib", -0, F6_5, 0xBB06, "cpsir", -0, F6_5, 0xBA06, "cpsirb", +{0, F6_5, 0xBB08, "cpd"}, +{0, F6_5, 0xBA08, "cpdb"}, +{0, F6_5, 0xBB0C, "cpdr"}, +{0, F6_5, 0xBA0C, "cpdrb"}, +{0, F6_5, 0xBB00, "cpi"}, +{0, F6_5, 0xBA00, "cpib"}, +{0, F6_5, 0xBB04, "cpir"}, +{0, F6_5, 0xBA04, "cpirb"}, +{0, F6_5, 0xBB0A, "cpsd"}, +{0, F6_5, 0xBA0A, "cpsdb"}, +{0, F6_5, 0xBB0E, "cpsdr"}, +{0, F6_5, 0xBA0E, "cpsdrb"}, +{0, F6_5, 0xBB02, "cpsi"}, +{0, F6_5, 0xBA02, "cpsib"}, +{0, F6_5, 0xBB06, "cpsir"}, +{0, F6_5, 0xBA06, "cpsirb"}, -0, F6_6, 0xB30B, "sda", -0, F6_6, 0xB20B, "sdab", -0, F6_6, 0xB30F, "sdal", -0, F6_6, 0xB303, "sdl", -0, F6_6, 0xB203, "sdlb", -0, F6_6, 0xB307, "sdll", +{0, F6_6, 0xB30B, "sda"}, +{0, F6_6, 0xB20B, "sdab"}, +{0, F6_6, 0xB30F, "sdal"}, +{0, F6_6, 0xB303, "sdl"}, +{0, F6_6, 0xB203, "sdlb"}, +{0, F6_6, 0xB307, "sdll"}, /* The instructions in\b and out\b have two different opcodes ** depending on their operands (...). Therefore the opcodes @@ -332,38 +332,38 @@ ** as operand. In their opcode bit 0 is on, which indicates ** the difference with the other instructions of this group. */ -0, IN, 0x3100, "in", -0, IN, 0x3000, "inb", -0, IN, 0x3B05, "sin", -0, IN, 0x3A05, "sinb", -0, OUT, 0x3100, "out", -0, OUT, 0x3000, "outb", -0, OUT, 0x3B07, "sout", -0, OUT, 0x3A07, "soutb", +{0, IN, 0x3100, "in"}, +{0, IN, 0x3000, "inb"}, +{0, IN, 0x3B05, "sin"}, +{0, IN, 0x3A05, "sinb"}, +{0, OUT, 0x3100, "out"}, +{0, OUT, 0x3000, "outb"}, +{0, OUT, 0x3B07, "sout"}, +{0, OUT, 0x3A07, "soutb"}, /* Depending on their operands the LDCTL-instructions might ** have an opcode of 8 more then listed below. This is or-ed ** in at the appropriate place. */ -0, LDCTL, 0x7D00, "ldctl", -0, LDCTLB, 0x8C00, "ldctlb", -0, MREQ, 0x7B0D, "mreq", +{0, LDCTL, 0x7D00, "ldctl"}, +{0, LDCTLB, 0x8C00, "ldctlb"}, +{0, MREQ, 0x7B0D, "mreq"}, -0, F9_1, 0x8D05, "comflg", -0, F9_1, 0x8D03, "resflg", -0, F9_1, 0x8D01, "setflg", +{0, F9_1, 0x8D05, "comflg"}, +{0, F9_1, 0x8D03, "resflg"}, +{0, F9_1, 0x8D01, "setflg"}, -0, F9_2, 0x7C00, "di", -0, F9_2, 0x7C04, "ei", +{0, F9_2, 0x7C00, "di"}, +{0, F9_2, 0x7C04, "ei"}, -0, F9_3, 0x7A00, "halt", -0, F9_3, 0x7B00, "iret", -0, F9_3, 0x7B0A, "mbit", -0, F9_3, 0x7B09, "mres", -0, F9_3, 0x7B08, "mset", -0, F9_3, 0x8D07, "nop", +{0, F9_3, 0x7A00, "halt"}, +{0, F9_3, 0x7B00, "iret"}, +{0, F9_3, 0x7B0A, "mbit"}, +{0, F9_3, 0x7B09, "mres"}, +{0, F9_3, 0x7B08, "mset"}, +{0, F9_3, 0x8D07, "nop"}, /* Rest of the opcode-0x200 is or-ed in at the appropriate place */ -0, RET, 0x9E00, "ret", -0, SC, 0x7F00, "sc", +{0, RET, 0x9E00, "ret"}, +{0, SC, 0x7F00, "sc"}, From b1f6d5d8278b0889ba1d3aa8d6d971fcf5280593 Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 14 May 2019 23:22:38 +0800 Subject: [PATCH 71/84] ANSI C compilation fixes --- modules/src/em_opt/findworst.c | 80 ++- modules/src/em_opt/initlex.c | 11 +- modules/src/em_opt/makefuns.awk | 82 +-- modules/src/em_opt/mkstrct.c | 137 ++--- modules/src/em_opt/nopt.c | 326 +++++----- modules/src/em_opt/outcalls.c | 216 ++++--- modules/src/em_opt/outputdfa.c | 1019 +++++++++++++++++-------------- modules/src/em_opt/parser.g | 66 +- modules/src/em_opt/parser.h | 24 +- modules/src/em_opt/syntax.l | 8 +- modules/src/em_opt/utils.c | 119 ++-- 11 files changed, 1075 insertions(+), 1013 deletions(-) diff --git a/modules/src/em_opt/findworst.c b/modules/src/em_opt/findworst.c index 541a1297d..10b945120 100644 --- a/modules/src/em_opt/findworst.c +++ b/modules/src/em_opt/findworst.c @@ -6,30 +6,30 @@ static char rcsidp3[] = "$Id$"; #define UPDATEWORST(backups) if(backups>mostbackups) mostbackups = backups; -PRIVATE int leftmatch(); -PRIVATE int rightmatch(); +PRIVATE int rightmatch(struct mnems,struct mnems,int, int); +PRIVATE int leftmatch(struct mnems, struct mnems, int, int); -findworst(patt,repl) - struct mnems patt,repl; + +void findworst(struct mnems patt,struct mnems repl) { /* - /* Find the pattern that requires the most backup of output queue. - /* Let repl be r1 r2 ... rn. All these are already on the output queue. - /* Possibilities in order of most backup first are: - /* a) pattern of form: p1 .... pb r1 r2 .... rn pc ... pd - /* i.e. completely in pattern. - /* requires a backup of b+n instructions - /* and a goto to state 0. - /* b) pattern of form: p1 .... pb r1 r2 .... ri - /* i.e. a prefix of ends a pattern. - /* requires a backup of b+n instructions - /* and a goto to state 0. - /* c) pattern of form: ri ri+1 ... rn pc ... pd - /* i.e. a suffix of starts a pattern. - /* requires a backup of j-i+1 instructions and a goto to state 0. - /* d) pattern of the form: ri ri+1 ... rj - /* i.e. a substring of is a complete pattern - /* requires a backup of j-i+1 instructions and a goto to state 0. + / Find the pattern that requires the most backup of output queue. + / Let repl be r1 r2 ... rn. All these are already on the output queue. + / Possibilities in order of most backup first are: + / a) pattern of form: p1 .... pb r1 r2 .... rn pc ... pd + / i.e. completely in pattern. + / requires a backup of b+n instructions + / and a goto to state 0. + / b) pattern of form: p1 .... pb r1 r2 .... ri + / i.e. a prefix of ends a pattern. + / requires a backup of b+n instructions + / and a goto to state 0. + / c) pattern of form: ri ri+1 ... rn pc ... pd + / i.e. a suffix of starts a pattern. + / requires a backup of j-i+1 instructions and a goto to state 0. + / d) pattern of the form: ri ri+1 ... rj + / i.e. a substring of is a complete pattern + / requires a backup of j-i+1 instructions and a goto to state 0. */ int n = repl.m_len; int diff = patt.m_len - repl.m_len; @@ -45,7 +45,7 @@ findworst(patt,repl) if(actions[s]==(struct action *)NULL) continue; /* look for case a */ - if(first=rightmatch(patterns[s],repl,1,n)) { + if( (first=rightmatch(patterns[s],repl,1,n))) { UPDATEWORST(first-1+n); } /* look for case b */ @@ -76,16 +76,14 @@ findworst(patt,repl) fprintf(ofile,"\t\tOO_mkrepl(%d,%d,%d);\n",n,diff,mostbackups); } -findfail(state,resout,rescpy,resgto) - int state; - int *resout, *rescpy, *resgto; +void findfail(int state, int *resout, int *rescpy, int *resgto) { /* - /* If pattern matching fails in 'state', how many outputs and how many - /* push backs are requires. If pattern is of the form p1 p2 .... pn - /* look for patterns of the form p2 p3 ... pn; then p3 p4 ... pn; etc. - /* The first such match of the form pi pi+1 ... pn requires an output - /* of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi. + / If pattern matching fails in 'state', how many outputs and how many + / push backs are requires. If pattern is of the form p1 p2 .... pn + / look for patterns of the form p2 p3 ... pn; then p3 p4 ... pn; etc. + / The first such match of the form pi pi+1 ... pn requires an output + / of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi. */ int s,i; struct state *p; @@ -114,15 +112,12 @@ findfail(state,resout,rescpy,resgto) *resgto = 0; } -PRIVATE int -leftmatch(patt,repl,i,j) - struct mnems patt,repl; - int i,j; +PRIVATE int leftmatch(struct mnems patt,struct mnems repl,int i,int j) { /* - /* Return the first complete match of the mnems of - /* 'repl' in the mnems of 'patt'. Find the leftmost match. - /* Return 0 if fails. + / Return the first complete match of the mnems of + / 'repl' in the mnems of 'patt'. Find the leftmost match. + / Return 0 if fails. */ int lenrij = j-i+1; int lastpos = patt.m_len - lenrij + 1; @@ -139,15 +134,12 @@ leftmatch(patt,repl,i,j) return(0); } -PRIVATE int -rightmatch(patt,repl,i,j) - struct mnems patt,repl; - int i,j; +PRIVATE int rightmatch(struct mnems patt,struct mnems repl,int i,int j) { /* - /* Return the first complete match of the mnems of - /* 'repl' in the mnems of 'patt'. Find the rightmost match. - /* Return 0 if fails. + / Return the first complete match of the mnems of + / 'repl' in the mnems of 'patt'. Find the rightmost match. + / Return 0 if fails. */ int lenrij = j-i+1; int lastpos = patt.m_len - lenrij + 1; diff --git a/modules/src/em_opt/initlex.c b/modules/src/em_opt/initlex.c index 0233ac702..b5431bd9e 100644 --- a/modules/src/em_opt/initlex.c +++ b/modules/src/em_opt/initlex.c @@ -13,9 +13,9 @@ static char rcsidp2[] = "$Id$"; extern char em_flag[]; extern char em_mnem[][4]; -PRIVATE idinit(); +PRIVATE void idinit(char *, int, int); -initlex() +void initlex(void) { register int i,j; init_idf(); @@ -47,11 +47,8 @@ initlex() } } -PRIVATE -idinit(tag,opcode,argfmt) - char *tag; - int opcode; - int argfmt; + +PRIVATE void idinit(char *tag, int opcode, int argfmt) { struct idf *p; p = str2idf(tag,0); diff --git a/modules/src/em_opt/makefuns.awk b/modules/src/em_opt/makefuns.awk index 31d25f516..005026021 100644 --- a/modules/src/em_opt/makefuns.awk +++ b/modules/src/em_opt/makefuns.awk @@ -3,56 +3,73 @@ BEGIN { seenproc = 0; CC="${CMD}" if (prototypes == "") prototypes = "prototypes" + print "#include \"nopt.h\"" } /^%/ {} /^$/ {} /^[a-z]/ && $3 !~ /.*NOTIMPLEMENTED.*/ { if(seenproc) { print "}" - print "--EOF--" - printf "if %s O_%s.c\n",CC,nam - printf "then :\nelse exit 1\nfi\n" - printf "rm -f O_%s.c\n",nam - } + } seenproc = 1 $1 = substr($1,1,index($1,"\t")-1); nam = $1 - printf "cat > O_%s.c << '--EOF--'\n",$1 - print "#include \"nopt.h\"" + print "" printf "void O_%s(",$1 prototype = "_PROTOTYPE(void O_" $1 ", (" - nparms = split($2,parms,":"); - for(p=1;p 1) { - prototype = prototype parms[1] - printf "\t%s",parms[1] - } - else { - prototype = prototype "void" - } - for(p=1;p 0) + { + nparms = split(p2[i],params,":"); + if (nparms >0 ) + { + gsub(/^[ \t]+/,"",params[1]) + gsub(/[ \t]+$/,"",params[1]) + gsub(/^[ \t]+/,"",params[2]) + gsub(/[ \t]+$/,"",params[2]) + + paramstr = paramstr params[1] " " params[2] + printf "%s %s",params[1],params[2] + if(count!=i) + { + paramstr = paramstr ", " + printf ", " + } + } else + { + printf "void" + paramstr = paramstr "void" + } + } } } + prototype = prototype paramstr + print ")" print prototype "));" >> prototypes if($3) { printf "{\n\t%s\n",$3 } else { printf "{\n" - } + } } /^ / { print @@ -60,9 +77,6 @@ BEGIN { END { if(seenproc) { print "}" - print "--EOF--" - printf "if %s O_%s.c\n",CC,nam - printf "then :\nelse exit 1\nfi\n" - printf "rm -f O_%s.c\n",nam + print "" } } diff --git a/modules/src/em_opt/mkstrct.c b/modules/src/em_opt/mkstrct.c index 7d50b29eb..fd15948e1 100644 --- a/modules/src/em_opt/mkstrct.c +++ b/modules/src/em_opt/mkstrct.c @@ -4,20 +4,16 @@ static char rcsid3[] = "$Id$"; #include "nopt.h" -void -EM_mkop(p,opcode) - register p_instr p; - int opcode; +void EM_mkop(p, opcode) + register p_instr p;int opcode; { p->em_type = EM_MNEM; p->em_opcode = opcode; p->em_argtype = 0; } -void -EM_mknarg(p,opcode) - register p_instr p; - int opcode; +void EM_mknarg(p, opcode) + register p_instr p;int opcode; { p->em_type = EM_MNEM; p->em_opcode = opcode; @@ -25,11 +21,8 @@ EM_mknarg(p,opcode) p->em_cst = 0; } -void -EM_mkilb(p,opcode,lab) - register p_instr p; - int opcode; - label lab; +void EM_mkilb(p, opcode, lab) + register p_instr p;int opcode;label lab; { p->em_type = EM_MNEM; p->em_argtype = ilb_ptyp; @@ -37,11 +30,8 @@ EM_mkilb(p,opcode,lab) p->em_ilb = lab; } -void -EM_mknof(p,opcode,lab,off) - register p_instr p; - int opcode; - label lab; +void EM_mknof(p, opcode, lab, off) + register p_instr p;int opcode;label lab; arith off; { p->em_type = EM_MNEM; @@ -51,24 +41,19 @@ EM_mknof(p,opcode,lab,off) p->em_off = off; } -void -EM_mksof(p,opcode,name,off) - register p_instr p; - int opcode; - char *name; +void EM_mksof(p, opcode, name, off) + register p_instr p;int opcode;char *name; arith off; { p->em_type = EM_MNEM; p->em_argtype = sof_ptyp; p->em_opcode = opcode; - p->em_dnam = OO_freestr(name); + p->em_dnam = OO_freestr(name); p->em_off = off; } -void -EM_mkcst(p,opcode,cst) - register p_instr p; - int opcode; +void EM_mkcst(p, opcode, cst) + register p_instr p;int opcode; arith cst; { p->em_type = EM_MNEM; @@ -77,11 +62,8 @@ EM_mkcst(p,opcode,cst) p->em_cst = cst; } -void -EM_mkpro(p,opcode,pnam) - register p_instr p; - int opcode; - char *pnam; +void EM_mkpro(p, opcode, pnam) + register p_instr p;int opcode;char *pnam; { p->em_type = EM_MNEM; p->em_argtype = pro_ptyp; @@ -89,11 +71,8 @@ EM_mkpro(p,opcode,pnam) p->em_pnam = OO_freestr(pnam); } -void -EM_mkdefilb(p,opcode,deflb) - register p_instr p; - int opcode; - label deflb; +void EM_mkdefilb(p, opcode, deflb) + register p_instr p;int opcode;label deflb; { p->em_type = EM_DEFILB; p->em_opcode = opcode; @@ -101,8 +80,7 @@ EM_mkdefilb(p,opcode,deflb) p->em_ilb = deflb; } -void -EM_Nop(opcode) +void EM_Nop(opcode) int opcode; { register p_instr p = GETNXTPATT(); @@ -111,8 +89,7 @@ EM_Nop(opcode) p->em_argtype = 0; } -void -EM_Nnarg(opcode) +void EM_Nnarg(opcode) int opcode; { register p_instr p = GETNXTPATT(); @@ -122,10 +99,8 @@ EM_Nnarg(opcode) p->em_cst = 0; } -void -EM_Nilb(opcode,lab) - int opcode; - label lab; +void EM_Nilb(opcode, lab) + int opcode;label lab; { register p_instr p = GETNXTPATT(); p->em_type = EM_MNEM; @@ -134,10 +109,8 @@ EM_Nilb(opcode,lab) p->em_ilb = lab; } -void -EM_Nnof(opcode,lab,off) - int opcode; - label lab; +void EM_Nnof(opcode, lab, off) + int opcode;label lab; arith off; { register p_instr p = GETNXTPATT(); @@ -148,22 +121,19 @@ EM_Nnof(opcode,lab,off) p->em_off = off; } -void -EM_Nsof(opcode,name,off) - int opcode; - char *name; +void EM_Nsof(opcode, name, off) + int opcode;char *name; arith off; { register p_instr p = GETNXTPATT(); p->em_type = EM_MNEM; p->em_argtype = sof_ptyp; p->em_opcode = opcode; - p->em_dnam = OO_freestr(name); + p->em_dnam = OO_freestr(name); p->em_off = off; } -void -EM_Ncst(opcode,cst) +void EM_Ncst(opcode, cst) int opcode; arith cst; { @@ -174,10 +144,8 @@ EM_Ncst(opcode,cst) p->em_cst = cst; } -void -EM_Npro(opcode,pnam) - int opcode; - char *pnam; +void EM_Npro(opcode, pnam) + int opcode;char *pnam; { register p_instr p = GETNXTPATT(); p->em_type = EM_MNEM; @@ -186,10 +154,8 @@ EM_Npro(opcode,pnam) p->em_pnam = OO_freestr(pnam); } -void -EM_Ndefilb(opcode,deflb) - int opcode; - label deflb; +void EM_Ndefilb(opcode, deflb) + int opcode;label deflb; { register p_instr p = GETNXTPATT(); p->em_type = EM_DEFILB; @@ -198,8 +164,7 @@ EM_Ndefilb(opcode,deflb) p->em_ilb = deflb; } -void -EM_Rop(opcode) +void EM_Rop(opcode) int opcode; { register p_instr p = GETNXTREPL(); @@ -208,8 +173,7 @@ EM_Rop(opcode) p->em_argtype = 0; } -void -EM_Rnarg(opcode) +void EM_Rnarg(opcode) int opcode; { register p_instr p = GETNXTREPL(); @@ -219,10 +183,8 @@ EM_Rnarg(opcode) p->em_cst = 0; } -void -EM_Rilb(opcode,lab) - int opcode; - label lab; +void EM_Rilb(opcode, lab) + int opcode;label lab; { register p_instr p = GETNXTREPL(); p->em_type = EM_MNEM; @@ -231,10 +193,8 @@ EM_Rilb(opcode,lab) p->em_ilb = lab; } -void -EM_Rnof(opcode,lab,off) - int opcode; - label lab; +void EM_Rnof(opcode, lab, off) + int opcode;label lab; arith off; { register p_instr p = GETNXTREPL(); @@ -245,22 +205,19 @@ EM_Rnof(opcode,lab,off) p->em_off = off; } -void -EM_Rsof(opcode,name,off) - int opcode; - char *name; +void EM_Rsof(opcode, name, off) + int opcode;char *name; arith off; { register p_instr p = GETNXTREPL(); p->em_type = EM_MNEM; p->em_argtype = sof_ptyp; p->em_opcode = opcode; - p->em_dnam = OO_freestr(name); + p->em_dnam = OO_freestr(name); p->em_off = off; } -void -EM_Rcst(opcode,cst) +void EM_Rcst(opcode, cst) int opcode; arith cst; { @@ -271,10 +228,8 @@ EM_Rcst(opcode,cst) p->em_cst = cst; } -void -EM_Rpro(opcode,pnam) - int opcode; - char *pnam; +void EM_Rpro(opcode, pnam) + int opcode;char *pnam; { register p_instr p = GETNXTREPL(); p->em_type = EM_MNEM; @@ -283,10 +238,8 @@ EM_Rpro(opcode,pnam) p->em_pnam = OO_freestr(pnam); } -void -EM_Rdefilb(opcode,deflb) - int opcode; - label deflb; +void EM_Rdefilb(opcode, deflb) + int opcode;label deflb; { register p_instr p = GETNXTREPL(); p->em_type = EM_DEFILB; diff --git a/modules/src/em_opt/nopt.c b/modules/src/em_opt/nopt.c index f2e071f86..d10fd18cb 100644 --- a/modules/src/em_opt/nopt.c +++ b/modules/src/em_opt/nopt.c @@ -4,36 +4,36 @@ static char rcsid2[] = "$Id$"; #include "nopt.h" -extern struct dfa OO_checknext[]; /* Initialized in dfa.c */ -extern struct dfa *OO_base[]; /* Initialized in dfa.c */ -extern struct dodefault OO_default[]; /* Initialized in dfa.c */ -extern int OO_maxpattern; /* Initialized in dfa.c */ -extern int OO_maxreplacement; /* Initialized in dfa.c */ -extern int (*OO_ftrans[])(); /* Initialized in trans.c */ +extern struct dfa OO_checknext[]; /* Initialized in dfa.c */ +extern struct dfa *OO_base[]; /* Initialized in dfa.c */ +extern struct dodefault OO_default[]; /* Initialized in dfa.c */ +extern int OO_maxpattern; /* Initialized in dfa.c */ +extern int OO_maxreplacement; /* Initialized in dfa.c */ +extern int (*OO_ftrans[])(); /* Initialized in trans.c */ -extern char em_mnem[][4]; -extern char em_pseu[][4]; +extern char em_mnem[][4]; +extern char em_pseu[][4]; int OO_state = 0; -p_instr OO_buffer; -p_instr OO_patternqueue; -p_instr OO_nxtpatt; -p_instr OO_endbackup; -p_instr OO_nxtrepl; -static p_instr OO_replqueue; +p_instr OO_buffer; +p_instr OO_patternqueue; +p_instr OO_nxtpatt; +p_instr OO_endbackup; +p_instr OO_nxtrepl; +static p_instr OO_replqueue; -static char *filename; -static char *strqueue; -static char *nextstr; -static char *laststr; +static char *filename; +static char *strqueue; +static char *nextstr; +static char *laststr; -arith OO_WSIZE; /* wordlength */ -arith OO_DWSIZE; /* 2*wordlength */ -arith OO_PSIZE; /* pointer length */ +arith OO_WSIZE; /* wordlength */ +arith OO_DWSIZE; /* 2*wordlength */ +arith OO_PSIZE; /* pointer length */ #ifdef STATS -int OO_wrstats = 1; /* pattern statistics output */ +int OO_wrstats = 1; /* pattern statistics output */ #endif #ifdef DEBUG #define printstate(s) dumpstate(s) @@ -42,108 +42,103 @@ int OO_wrstats = 1; /* pattern statistics output */ #endif /* DEBUG */ /**** WHICH IS FASTER? **** -#define BTSCPY(pp,qq,i,p,q,n) btscpy(p,q,(n)*sizeof(struct e_instr)) + #define BTSCPY(pp,qq,i,p,q,n) btscpy(p,q,(n)*sizeof(struct e_instr)) **************************/ #define BTSCPY(pp,qq,i,p,q,n) for(pp=(p),qq=(q),i=(n);i--;*pp++ = *qq++) -PRIVATE void allocmem(); +PRIVATE void allocmem(void); -void -O_init(wsize,psize) - arith wsize, psize; +void O_init(arith wsize, arith psize) { allocmem(); - C_init(wsize,psize); + C_init(wsize, psize); OO_WSIZE = wsize; - OO_DWSIZE = 2*wsize; + OO_DWSIZE = 2 * wsize; OO_PSIZE = psize; } -int -O_open(fname) - char *fname; +int O_open(char *fname) { filename = fname; - return(C_open(fname)); + return (C_open(fname)); } -void -O_magic() +void O_magic(void) { C_magic(); } -void -O_close() +void O_close(void) { C_close(); } -void -OO_dfa(last) - register int last; +void OO_dfa(register int last) { register struct dfa *b; register struct dodefault *d; register int (*f)(); - for(;;) { + for (;;) + { printstate("OO_dfa"); - if((b=OO_base[OO_state]) && ((b += last)->check==OO_state)) { - if(f=OO_ftrans[OO_state = b->next]) (*f)(); + if ((b = OO_base[OO_state]) && ((b += last)->check == OO_state)) + { + if ((f = OO_ftrans[OO_state = b->next])) + (*f)(); } - else if (OO_state) { + else if (OO_state) + { /* consult default entry */ d = &OO_default[OO_state]; - if(!OO_endbackup) OO_endbackup = OO_nxtpatt; + if (!OO_endbackup) + OO_endbackup = OO_nxtpatt; OO_nxtpatt--; OO_patternqueue += d->numout; - if(f=OO_ftrans[OO_state = d->next]) (*f)(); + if ((f = OO_ftrans[OO_state = d->next])) + (*f)(); } - else OO_flush(); - if (!OO_endbackup) return; + else + OO_flush(); + if (!OO_endbackup) + return; last = (OO_nxtpatt++)->em_opcode; if (OO_nxtpatt >= OO_endbackup) OO_endbackup = 0; } } -PRIVATE void -fatal(s,a) - char *s; - int a; +PRIVATE void fatal(s, a) + char *s;int a; { fprint(STDERR, "%s: ", filename ? filename : "standard input"); - fprint(STDERR,s,a); - fprint(STDERR,"\n"); + fprint(STDERR, s, a); + fprint(STDERR, "\n"); sys_stop(S_EXIT); } -PRIVATE void -allocmem() +PRIVATE void allocmem(void) { /* Allocate memory for queues on heap */ - OO_buffer = (p_instr) - Malloc((unsigned)(MAXBUFFER*sizeof(struct e_instr))); + OO_buffer = (p_instr) Malloc( + (unsigned) (MAXBUFFER * sizeof(struct e_instr))); OO_patternqueue = OO_nxtpatt = OO_buffer; - OO_replqueue = (p_instr) - Malloc((unsigned)OO_maxreplacement*sizeof(struct e_instr)); + OO_replqueue = (p_instr) Malloc( + (unsigned) OO_maxreplacement * sizeof(struct e_instr)); OO_nxtrepl = OO_replqueue; - nextstr = strqueue = - (char *)Malloc(MAXSTRING*sizeof(char)); + nextstr = strqueue = (char *) Malloc(MAXSTRING * sizeof(char)); laststr = strqueue + MAXSTRING - 1; } -char * -OO_freestr(str) - char *str; +char * OO_freestr(char *str) { register char *s = str; register char *res; - while (*s++); - again: - if ((s-str) > (laststr-nextstr)) { - unsigned newsize = (laststr - strqueue + 1)*2; - res = Realloc(strqueue,newsize); + while (*s++) + ; + again: if ((s - str) > (laststr - nextstr)) + { + unsigned newsize = (laststr - strqueue + 1) * 2; + res = Realloc(strqueue, newsize); laststr = res + newsize - 1; nextstr = res + (nextstr - strqueue); strqueue = res; @@ -153,201 +148,202 @@ OO_freestr(str) #endif goto again; } - res=nextstr; - for(s=str;*nextstr++ = *s++;); - return(res); + res = nextstr; + for (s = str; (*nextstr++ = *s++);) + ; + return (res); } -void -OO_flush() +void OO_flush(void) { /* - /* Output all instructions waiting in the output queue and free their - /* storage including the saved strings. - */ - register p_instr p,q; - register int i,n; + Output all instructions waiting in the output queue and free their + storage including the saved strings. + */ + register p_instr p, q; + register int i, n; printstate("Flush"); - for(p=OO_buffer;pem_opcode!=OTHER) + if (p->em_opcode != OTHER) C_out(p); - if(OO_endbackup) { - n = OO_endbackup-OO_nxtpatt; - BTSCPY(p,q,i,OO_buffer,OO_nxtpatt,n); + if (OO_endbackup) + { + n = OO_endbackup - OO_nxtpatt; + BTSCPY(p, q, i, OO_buffer, OO_nxtpatt, n); OO_endbackup = OO_buffer + n; } - else nextstr = strqueue; + else + nextstr = strqueue; OO_patternqueue = OO_nxtpatt = OO_buffer; } -p_instr -OO_halfflush() +p_instr OO_halfflush(void) { /* - /* Called when buffer full, flush half the buffer and move the - /* the pattern pointers to the new positions. Return a pointer - /* to the new nxtpatt position and increment it. - /* Note that OO_endbackup is always NIL (i.e. there are no - /* instructions on the backup queue) when this is invoked. - */ - register int i,n; - register p_instr p,q; + Called when buffer full, flush half the buffer and move the + the pattern pointers to the new positions. Return a pointer + to the new nxtpatt position and increment it. + Note that OO_endbackup is always NIL (i.e. there are no + instructions on the backup queue) when this is invoked. + */ + register int i, n; + register p_instr p, q; printstate("Half flush"); n = MAXBUFFER / 2; - for(p=OO_buffer,i=n;i--;) + for (p = OO_buffer, i = n; i--;) C_out(p++); /* now copy the rest of buffer and pattern back */ - BTSCPY(p,q,i,OO_buffer,OO_buffer+n,(OO_nxtpatt-OO_buffer)-n); + BTSCPY(p, q, i, OO_buffer, OO_buffer + n, (OO_nxtpatt - OO_buffer) - n); OO_patternqueue -= n; OO_nxtpatt -= n; printstate("after Half flush"); return (OO_nxtpatt++); } -void -OO_mkext(p,opcode,arg,off) - register p_instr p; - int opcode; - p_instr arg; - arith off; +void OO_mkext(register p_instr p, int opcode, p_instr arg, arith off) { - switch(arg->em_argtype) { - case cst_ptyp: - EM_mkcst(p,opcode,off); - break; - case sof_ptyp: - EM_mksof(p,opcode,arg->em_dnam,off); - break; - case nof_ptyp: - EM_mknof(p,opcode,arg->em_dlb,off); - break; - default: - fatal("Unexpected type %d in outext",arg->em_argtype); + switch (arg->em_argtype) + { + case cst_ptyp: + EM_mkcst(p, opcode, off); + break; + case sof_ptyp: + EM_mksof(p, opcode, arg->em_dnam, off); + break; + case nof_ptyp: + EM_mknof(p, opcode, arg->em_dlb, off); + break; + default: + fatal("Unexpected type %d in outext", arg->em_argtype); } } -void -OO_mkrepl(lrepl,diff,numbkup) - int lrepl,diff,numbkup; +void OO_mkrepl(int lrepl, int diff, int numbkup) { /* copy the replacement queue into the buffer queue */ /* then move the pattern queue back n places */ - register p_instr p,q; + register p_instr p, q; register int i; printstate("Before backup"); - if(OO_endbackup) { + if (OO_endbackup) + { /* move the region between OO_nxtpatt and OO_endbackup */ - if (diff > 0) { + if (diff > 0) + { /* move left by diff */ - BTSCPY(p,q,i,OO_nxtpatt-diff,OO_nxtpatt,OO_endbackup-OO_nxtpatt); + BTSCPY(p, q, i, OO_nxtpatt - diff, OO_nxtpatt, + OO_endbackup - OO_nxtpatt); OO_nxtpatt -= diff; OO_endbackup -= diff; } - else if (diff < 0) { + else if (diff < 0) + { /* move right by diff */ /* careful of overflowing buffer!! */ - if ((OO_nxtpatt-diff)> (OO_buffer+MAXBUFFER) ) + if ((OO_nxtpatt - diff) > (OO_buffer + MAXBUFFER)) OO_halfflush(); /* cannot use btscpy as strings may overlap */ - p = (q=OO_endbackup-1) - diff; - while(q>=OO_nxtpatt) + p = (q = OO_endbackup - 1) - diff; + while (q >= OO_nxtpatt) *p-- = *q--; OO_nxtpatt -= diff; OO_endbackup -= diff; } } /* copy the replacement */ - if (lrepl) { - BTSCPY(p,q,i,OO_patternqueue,OO_replqueue,lrepl); + if (lrepl) + { + BTSCPY(p, q, i, OO_patternqueue, OO_replqueue, lrepl); OO_nxtrepl = OO_replqueue; OO_patternqueue += lrepl; } /* now move the position of interest back nunbkup instructions */ - if ((OO_patternqueue-OO_buffer) < numbkup) - numbkup = (OO_patternqueue-OO_buffer); + if ((OO_patternqueue - OO_buffer) < numbkup) + numbkup = (OO_patternqueue - OO_buffer); OO_nxtpatt = OO_patternqueue -= numbkup; - if(!OO_endbackup && numbkup) - OO_endbackup = OO_patternqueue+numbkup; + if (!OO_endbackup && numbkup) + OO_endbackup = OO_patternqueue + numbkup; OO_state = 0; printstate("After backup"); } #ifdef DEBUG void -dumpstate(mess) - char *mess; +dumpstate(char *mess) { - p_instr p; + p_instr p; fprintf(stderr,"%s - state(%d): ",mess,OO_state); p = OO_buffer; while(pem_type) { - case EM_MNEM: + switch(p->em_type) + { + case EM_MNEM: fprintf(stderr,"%s ",em_mnem[p->em_opcode-sp_fmnem]); break; - case EM_PSEU: + case EM_PSEU: fprintf(stderr,"%s ",em_pseu[p->em_opcode-sp_fpseu]); break; - case EM_STARTMES: - case EM_MESARG: - case EM_ENDMES: + case EM_STARTMES: + case EM_MESARG: + case EM_ENDMES: fprintf(stderr,"MES "); break; - case EM_DEFILB: + case EM_DEFILB: fprintf(stderr,"%ld ", (long)p->em_ilb); return; - case EM_DEFDLB: + case EM_DEFDLB: fprintf(stderr,"%ld ", (long)p->em_dlb); return; - case EM_DEFDNAM: + case EM_DEFDNAM: fprintf(stderr,"%d ", p->em_dnam); return; - case EM_ERROR: - case EM_FATAL: - case EM_EOF: + case EM_ERROR: + case EM_FATAL: + case EM_EOF: return; } - switch(p->em_argtype) { - case 0: + switch(p->em_argtype) + { + case 0: break; - case cst_ptyp: + case cst_ptyp: fprintf(stderr,"%d ",p->em_cst); break; - case nof_ptyp: + case nof_ptyp: fprintf(stderr,".%d+%d ",p->em_dlb,p->em_off); break; - case sof_ptyp: + case sof_ptyp: fprintf(stderr,"%s+%d ",p->em_dnam,p->em_off); break; - case ilb_ptyp: + case ilb_ptyp: fprintf(stderr,"*%d ",p->em_ilb); break; - case pro_ptyp: + case pro_ptyp: fprintf(stderr,"$%s ",p->em_pnam); break; - case str_ptyp: - case ico_ptyp: - case uco_ptyp: + case str_ptyp: + case ico_ptyp: + case uco_ptyp: fprintf(stderr,"\"%s\"",p->em_string); break; - default: + default: fatal(" prtinst - Unregognized arg %d ",p->em_argtype); } } diff --git a/modules/src/em_opt/outcalls.c b/modules/src/em_opt/outcalls.c index 97281a0b7..cb86ff6fb 100644 --- a/modules/src/em_opt/outcalls.c +++ b/modules/src/em_opt/outcalls.c @@ -4,108 +4,128 @@ static char rcsidp4[] = "$Id$"; #include "parser.h" -outputincalls() +void outputincalls(void) { struct idf *op; char *s; - for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { + for (op = ops; op != (struct idf *) NULL; op = op->id_nextidf) + { s = op->id_text; - switch(op->id_argfmt) { - case NOARG: - fprintf(ofile,"%s\t|\t|\n",s); - if(op->id_used) { - fprintf(ofile,"\tEM_Nop(op_%s);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_%s();\n",s); - } - break; - case CSTOPT: - fprintf(ofile,"%s_narg\t|\t|\n",s); - if(op->id_used) { - fprintf(ofile,"\tEM_Nnarg(op_%s);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_%s_narg();\n",s); - } - /* fall thru */ - case CST: - fprintf(ofile,"%s\t| arith:n\t|\n",s); - if(op->id_used) { - fprintf(ofile,"\tEM_Ncst(op_%s,n);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_%s(n);\n",s); - } - break; - case DEFILB: - fprintf(ofile,"df_ilb\t| label:l\t|\n"); - if(op->id_used) { - fprintf(ofile,"\tEM_Ndefilb(op_%s,l);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_df_ilb(l);\n",s); - } - break; - case PNAM: - fprintf(ofile,"%s\t| char *:s\t|\n",s); - if(op->id_used) { - fprintf(ofile,"\tEM_Npro(op_%s,s);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_%s(s);\n",s); - } - break; - case LAB: - fprintf(ofile,"%s\t| label:l\t|\n",s); - if(op->id_used) { - fprintf(ofile,"\tEM_Nilb(op_%s,l);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_%s(l);\n",s); - } - break; - case EXT: - fprintf(ofile,"%s\t| arith:n\t|\n",s); - if(op->id_used) { - fprintf(ofile,"\tEM_Ncst(op_%s,n);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_%s(n);\n",s); - } - fprintf(ofile,"%s_dnam\t| char *:s arith:n\t|\n",s); - if(op->id_used) { - fprintf(ofile,"\tEM_Nsof(op_%s,s,n);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_%s_dnam(s,n);\n",s); - } - fprintf(ofile,"%s_dlb\t| label:l arith:n\t|\n",s); - if(op->id_used) { - fprintf(ofile,"\tEM_Nnof(op_%s,l,n);\n",s); - fprintf(ofile,"\tOO_dfa(op_%s);\n",s); - } - else { - fprintf(ofile,"\tFLUSHDFA();\n"); - fprintf(ofile,"\tC_%s_dlb(l,n);\n",s); - } - break; + switch (op->id_argfmt) + { + case NOARG: + fprintf(ofile, "%s\t|\t|\n", s); + if (op->id_used) + { + fprintf(ofile, "\tEM_Nop(op_%s);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_%s();\n", s); + } + break; + case CSTOPT: + fprintf(ofile, "%s_narg\t|\t|\n", s); + if (op->id_used) + { + fprintf(ofile, "\tEM_Nnarg(op_%s);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_%s_narg();\n", s); + } + /* fall thru */ + case CST: + fprintf(ofile, "%s\t| arith:n\t|\n", s); + if (op->id_used) + { + fprintf(ofile, "\tEM_Ncst(op_%s,n);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_%s(n);\n", s); + } + break; + case DEFILB: + fprintf(ofile, "df_ilb\t| label:l\t|\n"); + if (op->id_used) + { + fprintf(ofile, "\tEM_Ndefilb(op_%s,l);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_df_ilb(l);\n", s); + } + break; + case PNAM: + fprintf(ofile, "%s\t| char *:s\t|\n", s); + if (op->id_used) + { + fprintf(ofile, "\tEM_Npro(op_%s,s);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_%s(s);\n", s); + } + break; + case LAB: + fprintf(ofile, "%s\t| label:l\t|\n", s); + if (op->id_used) + { + fprintf(ofile, "\tEM_Nilb(op_%s,l);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_%s(l);\n", s); + } + break; + case EXT: + fprintf(ofile, "%s\t| arith:n\t|\n", s); + if (op->id_used) + { + fprintf(ofile, "\tEM_Ncst(op_%s,n);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_%s(n);\n", s); + } + fprintf(ofile, "%s_dnam\t| char *:s arith:n\t|\n", s); + if (op->id_used) + { + fprintf(ofile, "\tEM_Nsof(op_%s,s,n);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_%s_dnam(s,n);\n", s); + } + fprintf(ofile, "%s_dlb\t| label:l arith:n\t|\n", s); + if (op->id_used) + { + fprintf(ofile, "\tEM_Nnof(op_%s,l,n);\n", s); + fprintf(ofile, "\tOO_dfa(op_%s);\n", s); + } + else + { + fprintf(ofile, "\tFLUSHDFA();\n"); + fprintf(ofile, "\tC_%s_dlb(l,n);\n", s); + } + break; } } } diff --git a/modules/src/em_opt/outputdfa.c b/modules/src/em_opt/outputdfa.c index c58c966b9..110bdea2f 100644 --- a/modules/src/em_opt/outputdfa.c +++ b/modules/src/em_opt/outputdfa.c @@ -3,25 +3,31 @@ static char rcsidp5[] = "$Id$"; #endif #include +#include "alloc.h" #include "parser.h" #include "Lpars.h" FILE *ofile; -PRIVATE openofile(); -PRIVATE installofile(); -PRIVATE UNLINK(); -PRIVATE RENAME(); -PRIVATE outdfa(); -PRIVATE outmnems(); -PRIVATE outdotrans(); -PRIVATE outoneaction(); -PRIVATE outrepl(); -PRIVATE outexp(); -PRIVATE outext(); -PRIVATE outop(); +PRIVATE void openofile(char *); +PRIVATE void installofile(void); +PRIVATE void UNLINK(char *); +PRIVATE void RENAME(char *, char *); +PRIVATE void increase_next(unsigned int); +PRIVATE void store_row(int, register int *); +PRIVATE void outdfa(void); +PRIVATE void outmnems(struct mnems); +PRIVATE int sametest(int, int, struct exp_node *, struct exp_node *); +PRIVATE int samerepl(int, int, struct mnems, struct mnems); +PRIVATE int samecode(int, int); +PRIVATE void outdotrans(void); +PRIVATE void outoneaction(int, struct action *); +PRIVATE void outrepl(int, struct mnems); +PRIVATE void outexp(struct exp_node *, int); +PRIVATE void outext(struct exp_node *); +PRIVATE void outop(int op); -outputnopt() +void outputnopt(void) { openofile("dfa.c"); outdfa(); @@ -37,170 +43,173 @@ outputnopt() static char ofilename[80]; static char ofiletemp[80]; -PRIVATE -openofile(filename) - char *filename; +PRIVATE void openofile(char *filename) { - strcpy(ofilename,filename); - strcpy(ofiletemp,filename); - strcat(ofiletemp,".new"); - if((ofile=fopen(ofiletemp,"w"))==NULL) { - fprintf(stderr,"Fatal Error: cannot open output file %s\n",ofiletemp); + strcpy(ofilename, filename); + strcpy(ofiletemp, filename); + strcat(ofiletemp, ".new"); + if ((ofile = fopen(ofiletemp, "w")) == NULL) + { + fprintf(stderr, "Fatal Error: cannot open output file %s\n", ofiletemp); sys_stop(S_EXIT); } } -PRIVATE -installofile() +PRIVATE void installofile(void) { /* * if contents of newly generated ofiletemp is different * from that of ofilename then copy over old file else * delete newly generated file */ - register FILE *f1, *f2; - register int c1, c2; + register FILE *f1, *f2; + register int c1, c2; fclose(ofile); - if((f1 = fopen(ofiletemp,"r")) == NULL) { - fprintf(stderr,"Fatal Error: cannont reopen file %s\n",ofiletemp); + if ((f1 = fopen(ofiletemp, "r")) == NULL) + { + fprintf(stderr, "Fatal Error: cannont reopen file %s\n", ofiletemp); sys_stop(S_EXIT); } - if((f2 = fopen(ofilename,"r")) == NULL) { + if ((f2 = fopen(ofilename, "r")) == NULL) + { fclose(f1); - RENAME(ofiletemp,ofilename); + RENAME(ofiletemp, ofilename); return; } - do { + do + { c1 = getc(f1); c2 = getc(f2); } while (c1 == c2 && c1 != EOF); fclose(f1); fclose(f2); - if (c1 != c2) { - RENAME(ofiletemp,ofilename); + if (c1 != c2) + { + RENAME(ofiletemp, ofilename); } - else UNLINK(ofiletemp); + else + UNLINK(ofiletemp); } -PRIVATE -UNLINK(x) - char *x; +PRIVATE void UNLINK(char *x) { /* Must remove the file "x" */ - unlink(x); /* systemcall to remove file */ + remove(x); /* systemcall to remove file */ } -PRIVATE -RENAME(x,y) - char *x, *y; +PRIVATE void RENAME(char *x, char*y) { /* Must move the file "x" to the file "y" */ - unlink(y); - if(link(x,y)!=0) { - fprintf(stderr,"Cannot link to %s",y); + if (rename(x, y) != 0) + { + fprintf(stderr, "Cannot rename to %s", y); sys_stop(S_EXIT); } - unlink(x); } # define MAXOPCODE 255 # define EMPTY -1 int *next, *check, *base; -unsigned currsize; /* current size of next and check arrays */ -int maxpos = 0; /* highest used position in these arrayes */ +unsigned currsize; /* current size of next and check arrays */ +int maxpos = 0; /* highest used position in these arrayes */ -PRIVATE -increase_next(size) - int size; +PRIVATE void increase_next(unsigned int size) { /* realloc arrays next and check so they are at least * of size 'size' */ - char *Realloc(); unsigned newsize = currsize; - register int i; - do { + register unsigned int i; + do + { newsize *= 2; - } while (newsizecurrsize) increase_next(o); - if(n[o]!=EMPTY) goto nextpos; + for (i = 0; i < MAXOPCODE; i++) + { + if (row[i]) + { + if ((o = b + i) > currsize) + increase_next(o); + if (n[o] != EMPTY) + goto nextpos; } } /* found a place */ - base[state]=b; - for(i=0;imaxpos) maxpos = o; + base[state] = b; + for (i = 0; i < MAXOPCODE; i++) + if (row[i]) + { + if ((o = b + i) > maxpos) + maxpos = o; next[o] = row[i]; check[o] = state; } return; - nextpos: - ++b; + nextpos: ++b; } } -PRIVATE -outdfa() +PRIVATE void outdfa(void) { - register int s,i; + register int s, i; register struct state *p; int nout, ncpy, ngto; int row[MAXOPCODE]; int numinrow; int numentries = 0; - - fprintf(ofile,"#include \"nopt.h\"\n"); - fprintf(ofile,"\n"); - fprintf(ofile,"int OO_maxreplacement = %d;\n", maxreplacement); - fprintf(ofile,"\n"); + + fprintf(ofile, "#include \"nopt.h\"\n"); + fprintf(ofile, "\n"); + fprintf(ofile, "int OO_maxreplacement = %d;\n", maxreplacement); + fprintf(ofile, "\n"); /* find how many entries in dfa */ - for(s=0;s<=higheststate;s++) - for(p=states[s];p!=(struct state *)NULL;p=p->next) + for (s = 0; s <= higheststate; s++) + for (p = states[s]; p != (struct state *) NULL; p = p->next) numentries++; /* start with next and check arrays twice this size */ currsize = 2 * numentries; - next = (int *)Malloc(currsize*sizeof(int)); - check = (int *)Malloc(currsize*sizeof(int)); - base = (int *)Malloc(((unsigned)(higheststate+1))*sizeof(int)); + next = (int *) Malloc(currsize * sizeof(int)); + check = (int *) Malloc(currsize * sizeof(int)); + base = (int *) Malloc(((unsigned) (higheststate + 1)) * sizeof(int)); /* fill next array with EMPTY */ - for(i=0;inext) { + for (p = states[s]; p != (struct state *) NULL; p = p->next) + { numinrow++; row[p->op->id_opcode] = p->goto_state; } /* look for a place to store row */ - if(numinrow) - store_row(s,row); + if (numinrow) + store_row(s, row); else base[s] = EMPTY; } @@ -209,56 +218,304 @@ outdfa() printf("Longest pattern: %d\n", maxpattern); printf("Longest replacement: %d\n", maxreplacement); printf("Dfa contains %d states and %d distinct state/opcode pairs\n", - higheststate+1,numentries); - printf("Compacted using row displacement into %d entries\n",maxpos); + higheststate + 1, numentries); + printf("Compacted using row displacement into %d entries\n", maxpos); /* output the arrays */ - fprintf(ofile,"struct dfa OO_checknext[] = {\n"); - for(i=0;i<=maxpos;i++) { - fprintf(ofile,"\t/* %4d */\t",i); - fprintf(ofile,"{%4d,%4d},\n", check[i], next[i]); + fprintf(ofile, "struct dfa OO_checknext[] = {\n"); + for (i = 0; i <= maxpos; i++) + { + fprintf(ofile, "\t/* %4d */\t", i); + fprintf(ofile, "{%4d,%4d},\n", check[i], next[i]); } - fprintf(ofile,"};\n\n"); - fprintf(ofile,"struct dfa *OO_base[] = {\n"); - for(s=0;s<=higheststate;s++) { - fprintf(ofile,"\t/* %4d: ",s); + fprintf(ofile, "};\n\n"); + fprintf(ofile, "struct dfa *OO_base[] = {\n"); + for (s = 0; s <= higheststate; s++) + { + fprintf(ofile, "\t/* %4d: ", s); outmnems(patterns[s]); - fprintf(ofile,"*/\t"); - if(base[s]==EMPTY) - fprintf(ofile,"0,\n"); + fprintf(ofile, "*/\t"); + if (base[s] == EMPTY) + fprintf(ofile, "0,\n"); else - fprintf(ofile,"&OO_checknext[%4d],\n", base[s]); + fprintf(ofile, "&OO_checknext[%4d],\n", base[s]); } - fprintf(ofile,"};\n\n"); - fprintf(ofile,"struct dodefault OO_default[] = {\n"); - for(s=0;s<=higheststate;s++) { - fprintf(ofile,"\t/* %4d: ",s); + fprintf(ofile, "};\n\n"); + fprintf(ofile, "struct dodefault OO_default[] = {\n"); + for (s = 0; s <= higheststate; s++) + { + fprintf(ofile, "\t/* %4d: ", s); outmnems(patterns[s]); - fprintf(ofile,"*/\t"); - findfail(s,&nout,&ncpy,&ngto); - fprintf(ofile,"{%4d,%4d},\n", nout,ngto); + fprintf(ofile, "*/\t"); + findfail(s, &nout, &ncpy, &ngto); + fprintf(ofile, "{%4d,%4d},\n", nout, ngto); } - fprintf(ofile,"};\n\n"); + fprintf(ofile, "};\n\n"); } -PRIVATE -outmnems(l) - struct mnems l; +PRIVATE void outmnems(struct mnems l) { int i; - for(i=1;i<=l.m_len;i++) - fprintf(ofile,"%s ",l.m_elems[i-1]->op_code->id_text); + for (i = 1; i <= l.m_len; i++) + fprintf(ofile, "%s ", l.m_elems[i - 1]->op_code->id_text); } -PRIVATE int -sametest(s1,s2,e1,e2) - int s1,s2; - struct exp_node *e1,*e2; +PRIVATE int sametest(int s1, int s2, struct exp_node *e1, struct exp_node *e2) { /* return 1 if tests are identical */ - if(e1) { - if(!e2) return 0; - if(e1->node_type!=e2->node_type) return 0; - switch(e1->node_type) { + if (e1) + { + if (!e2) + return 0; + if (e1->node_type != e2->node_type) + return 0; + switch (e1->node_type) + { + case LOGAND: + case LOGOR: + case BITAND: + case BITOR: + case XOR: + case MINUS: + case PLUS: + case TIMES: + case DIV: + case MOD: + case EQ: + case NE: + case LT: + case LE: + case GT: + case GE: + case LSHIFT: + case RSHIFT: + case COMMA: + case SAMESIGN: + case SFIT: + case UFIT: + case ROTATE: + case SAMEEXT: + case SAMENAM: + return (sametest(s1, s2, e1->exp_left, e2->exp_left) + && sametest(s1, s2, e1->exp_right, e2->exp_right)); + case NOT: + case COMP: + case UPLUS: + case UMINUS: + return sametest(s1, s2, e1->exp_left, e2->exp_left); + case DEFINED: + case UNDEFINED: + case INT: + return (e1->leaf_val == e2->leaf_val); + case PATARG: + /* depends on pattern !! */ + if (e1->leaf_val != e2->leaf_val) + return 0; + return (patterns[s1].m_elems[e1->leaf_val - 1]->op_code->id_argfmt + == patterns[s2].m_elems[e2->leaf_val - 1]->op_code->id_argfmt); + case PSIZE: + case WSIZE: + case DWSIZE: + return 1; + + } + /*NOTREACHED*/ + } + else + return (e2 == 0); +} + +PRIVATE int samerepl(int s1, int s2, struct mnems r1, struct mnems r2) +{ + /* return 1 if replacements are identical */ + register int i; + register struct mnem_elem *m1, *m2; + if (r1.m_len != r2.m_len) + return 0; /* different length */ + for (i = 0; i < r1.m_len; i++) + { + m1 = r1.m_elems[i]; + m2 = r2.m_elems[i]; + if (m1->op_code != m2->op_code) + return 0; + if (!sametest(s1, s2, m1->arg, m2->arg)) + return 0; + } + return 1; +} + +PRIVATE int samecode(int s1, int s2) +{ + /* return 1 if replacement code of state s1 and s2 are identical */ + register struct action *a1, *a2; + if (patterns[s1].m_len != patterns[s2].m_len) + return 0; + a1 = actions[s1]; + a2 = actions[s2]; + while (a1) + { + if (!a2) + return 0; /* a2 is shorter */ + if (!samerepl(s1, s2, a1->replacement, a2->replacement)) + return 0; + if (!sametest(s1, s2, a1->test, a2->test)) + return 0; + a1 = a1->next; + a2 = a2->next; + } + if (a2) + return 0; /* a2 is longer */ + return 1; +} + +PRIVATE void outdotrans(void) +{ + register int s, t; + struct action *a; + int seennontested; + int *farray; + fprintf(ofile, "#include \"nopt.h\"\n\n"); + /* keep track of which procedure used for each state */ + farray = (int *) Malloc((unsigned) (higheststate + 1) * sizeof(int)); + for (s = 0; s <= higheststate; s++) + farray[s] = EMPTY; + /* output the functions avoiding duplicates */ + for (s = 0; s <= higheststate; s++) + { + if (actions[s] != (struct action *) NULL) + { + /* first look for a previous identical function */ + for (t = 0; t < s; t++) + { + if (actions[t] != (struct action *) NULL && samecode(s, t)) + { + /* use state 't' instead */ + farray[s] = t; + goto next_func; + } + } + /* no identical function so make new one */ + farray[s] = s; + fprintf(ofile, "\nstatic void do%dtrans(void) {\n", s); + fprintf(ofile, "\tregister p_instr patt = OO_patternqueue;\n"); + fprintf(ofile, "\t/* "); + outmnems(patterns[s]); + fprintf(ofile, " */\n"); + seennontested = 0; + for (a = actions[s]; a != (struct action *) NULL; a = a->next) + { + if (a->test != (struct exp_node *) NULL) + { + fprintf(ofile, "\tif("); + outexp(a->test, s); + fprintf(ofile, ") {\n"); + outoneaction(s, a); + fprintf(ofile, "\t\treturn;\n"); + fprintf(ofile, "\t}\n"); + } + else + { + if (seennontested) + { + fprintf(stderr, + "parser: more than one untested action on state %d\n", + s); + nerrors++; + } + seennontested++; + outoneaction(s, a); + } + } + fprintf(ofile, "}\n"); + } + next_func: continue; + } + /* output the array itself */ + fprintf(ofile, "\n\nvoid (*OO_ftrans[])(void)=\n{\n"); + for (s = 0; s <= higheststate; s++) + { + if (farray[s] != EMPTY) + fprintf(ofile, "\tdo%dtrans,\n", farray[s]); + else + fprintf(ofile, "\t0,\n"); + } + fprintf(ofile, "};\n"); +} + +PRIVATE void outoneaction(int s, struct action *a) +{ + fprintf(ofile, "\t\t/* -> "); + outmnems(a->replacement); + fprintf(ofile, " */\n"); + fprintf(ofile, "#ifdef STATS\n"); + fprintf(ofile, "\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n", + a->linenum); + fprintf(ofile, "#endif\n"); + outrepl(s, a->replacement); + findworst(patterns[s], a->replacement); +} + +PRIVATE void outrepl(int state, struct mnems repl) +{ + /* Contruct =r1 r2 ... rn and put on output queue. + */ + int n = repl.m_len; + int i; + for (i = 1; i <= n; i++) + { + struct mnem_elem *ri = repl.m_elems[i - 1]; + char *mnem = ri->op_code->id_text; + switch (ri->op_code->id_argfmt) + { + case NOARG: + fprintf(ofile, "\t\tEM_Rop(op_%s);\n", mnem); + break; + case CST: + fprintf(ofile, "\t\tEM_Rcst(op_%s,", mnem); + fprintf(ofile, "(arith)"); + outexp(ri->arg, state); + fprintf(ofile, ");\n"); + break; + case CSTOPT: + if (ri->arg) + { + fprintf(ofile, "\t\tEM_Rcst(op_%s,", mnem); + fprintf(ofile, "(arith)"); + outexp(ri->arg, state); + } + else + { + fprintf(ofile, "\t\tEM_Rnarg(op_%s);\n", mnem); + } + fprintf(ofile, ");\n"); + break; + case LAB: + fprintf(ofile, "\t\tEM_Rilb(op_%s,", mnem); + outexp(ri->arg, state); + fprintf(ofile, ");\n"); + break; + case DEFILB: + fprintf(ofile, "\t\tEM_Rdefilb(op_%s,", mnem); + outexp(ri->arg, state); + fprintf(ofile, ");\n"); + break; + case PNAM: + fprintf(ofile, "\t\tEM_Rpro(op_%s,", mnem); + outexp(ri->arg, state); + fprintf(ofile, ");\n"); + break; + case EXT: + fprintf(ofile, "\t\tOO_mkext(GETNXTREPL(), op_%s,", mnem); + outexp(ri->arg, state); + fprintf(ofile, ");\n"); + break; + } + } +} + +PRIVATE void outexp(struct exp_node *e, int state) +{ + switch (e->node_type) + { case LOGAND: case LOGOR: case BITAND: @@ -277,367 +534,191 @@ sametest(s1,s2,e1,e2) case GE: case LSHIFT: case RSHIFT: - case COMMA: - case SAMESIGN: - case SFIT: - case UFIT: - case ROTATE: - case SAMEEXT: - case SAMENAM: - return (sametest(s1,s2,e1->exp_left,e2->exp_left) && - sametest(s1,s2,e1->exp_right,e2->exp_right)); + fprintf(ofile, "("); + outexp(e->exp_left, state); + outop(e->node_type); + outexp(e->exp_right, state); + fprintf(ofile, ")"); + break; case NOT: case COMP: case UPLUS: case UMINUS: - return sametest(s1,s2,e1->exp_left,e2->exp_left); + fprintf(ofile, "("); + outop(e->node_type); + outexp(e->exp_left, state); + fprintf(ofile, ")"); + break; case DEFINED: + fprintf(ofile, "DEFINED(patt[%d])", e->leaf_val - 1); + break; case UNDEFINED: - case INT: - return (e1->leaf_val == e2->leaf_val); + fprintf(ofile, "!DEFINED(patt[%d])", e->leaf_val - 1); + break; + case COMMA: + outext(e->exp_left); + fprintf(ofile, ","); + fprintf(ofile, "(arith)"); + outexp(e->exp_right, state); + break; + case SAMESIGN: + case SFIT: + case UFIT: + case ROTATE: + outop(e->node_type); + fprintf(ofile, "(arith)"); + outexp(e->exp_left, state); + fprintf(ofile, ","); + fprintf(ofile, "(arith)"); + outexp(e->exp_right, state); + fprintf(ofile, ")"); + break; + case SAMEEXT: + case SAMENAM: + outop(e->node_type); + outext(e->exp_left); + fprintf(ofile, ","); + outext(e->exp_right); + fprintf(ofile, ")"); + break; case PATARG: - /* depends on pattern !! */ - if (e1->leaf_val != e2->leaf_val) return 0; - return (patterns[s1].m_elems[e1->leaf_val-1]-> - op_code->id_argfmt - == patterns[s2].m_elems[e2->leaf_val-1]-> - op_code->id_argfmt); + switch (patterns[state].m_elems[e->leaf_val - 1]->op_code->id_argfmt) + { + case NOARG: + fprintf(stderr, "error: mnem %d has no argument\n", + e->leaf_val); + nerrors++; + break; + case CST: + case CSTOPT: + fprintf(ofile, "CST(patt[%d])", e->leaf_val - 1); + break; + case LAB: + fprintf(ofile, "LAB(patt[%d])", e->leaf_val - 1); + break; + case DEFILB: + fprintf(ofile, "DEFILB(patt[%d])", e->leaf_val - 1); + break; + case PNAM: + fprintf(ofile, "PNAM(patt[%d])", e->leaf_val - 1); + break; + case EXT: + fprintf(ofile, "OO_offset(patt+%d)", e->leaf_val - 1); + break; + } + break; case PSIZE: + fprintf(ofile, "OO_PSIZE"); + break; case WSIZE: + fprintf(ofile, "OO_WSIZE"); + break; case DWSIZE: - return 1; - - } - /*NOTREACHED*/ - } - else return (e2==0); -} - -PRIVATE int -samerepl(s1,s2,r1,r2) - int s1,s2; - struct mnems r1,r2; -{ - /* return 1 if replacements are identical */ - register int i; - register struct mnem_elem *m1,*m2; - if (r1.m_len != r2.m_len) return 0; /* different length */ - for(i=0;iop_code!=m2->op_code) return 0; - if(!sametest(s1,s2,m1->arg,m2->arg)) return 0; - } - return 1; -} - -PRIVATE int -samecode(s1,s2) - int s1,s2; -{ - /* return 1 if replacement code of state s1 and s2 are identical */ - register struct action *a1,*a2; - if (patterns[s1].m_len != patterns[s2].m_len) return 0; - a1 = actions[s1]; - a2 = actions[s2]; - while(a1) { - if(!a2) return 0; /* a2 is shorter */ - if(!samerepl(s1,s2,a1->replacement,a2->replacement)) return 0; - if(!sametest(s1,s2,a1->test,a2->test)) return 0; - a1 = a1->next; - a2 = a2->next; - } - if(a2) return 0; /* a2 is longer */ - return 1; -} - -PRIVATE -outdotrans() -{ - register int s,t; - struct action *a; - int seennontested; - int *farray; - fprintf(ofile,"#include \"nopt.h\"\n\n"); - /* keep track of which procedure used for each state */ - farray = (int *)Malloc((unsigned)(higheststate+1)*sizeof(int)); - for(s=0;s<=higheststate;s++) farray[s] = EMPTY; - /* output the functions avoiding duplicates */ - for(s=0;s<=higheststate;s++) { - if(actions[s]!=(struct action *)NULL) { - /* first look for a previous identical function */ - for(t=0;tnext) { - if(a->test!=(struct exp_node *)NULL) { - fprintf(ofile,"\tif("); - outexp(a->test,s); - fprintf(ofile,") {\n"); - outoneaction(s,a); - fprintf(ofile,"\t\treturn;\n"); - fprintf(ofile,"\t}\n"); - } - else { - if(seennontested) { - fprintf(stderr,"parser: more than one untested action on state %d\n",s); - nerrors++; - } - seennontested++; - outoneaction(s,a); - } - } - fprintf(ofile,"}\n"); - } - next_func: - continue; - } - /* output the array itself */ - fprintf(ofile,"\n\nint (*OO_ftrans[])()=\n{\n"); - for(s=0;s<=higheststate;s++) { - if(farray[s]!=EMPTY) - fprintf(ofile,"\tdo%dtrans,\n",farray[s]); - else - fprintf(ofile,"\t0,\n"); - } - fprintf(ofile,"};\n"); -} - -PRIVATE -outoneaction(s,a) - int s; - struct action *a; -{ - fprintf(ofile,"\t\t/* -> "); - outmnems(a->replacement); - fprintf(ofile," */\n"); - fprintf(ofile,"#ifdef STATS\n"); - fprintf(ofile,"\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n",a->linenum); - fprintf(ofile,"#endif\n"); - outrepl(s,a->replacement); - findworst(patterns[s],a->replacement); -} - -PRIVATE -outrepl(state,repl) - int state; - struct mnems repl; -{ - /* - /* Contruct =r1 r2 ... rn and put on output queue. - */ - int n = repl.m_len; - int i; - for(i=1;i<=n;i++) { - struct mnem_elem *ri = repl.m_elems[i-1]; - char *mnem = ri->op_code->id_text; - switch(ri->op_code->id_argfmt) { - case NOARG: - fprintf(ofile,"\t\tEM_Rop(op_%s);\n",mnem); + fprintf(ofile, "OO_DWSIZE"); break; - case CST: - fprintf(ofile,"\t\tEM_Rcst(op_%s,",mnem); - fprintf(ofile,"(arith)"); - outexp(ri->arg,state); - fprintf(ofile,");\n"); + case INT: + fprintf(ofile, "%d", e->leaf_val); break; - case CSTOPT: - if(ri->arg) { - fprintf(ofile,"\t\tEM_Rcst(op_%s,",mnem); - fprintf(ofile,"(arith)"); - outexp(ri->arg,state); - } - else { - fprintf(ofile,"\t\tEM_Rnarg(op_%s);\n",mnem); - } - fprintf(ofile,");\n"); - break; - case LAB: - fprintf(ofile,"\t\tEM_Rilb(op_%s,",mnem); - outexp(ri->arg,state); - fprintf(ofile,");\n"); - break; - case DEFILB: - fprintf(ofile,"\t\tEM_Rdefilb(op_%s,",mnem); - outexp(ri->arg,state); - fprintf(ofile,");\n"); - break; - case PNAM: - fprintf(ofile,"\t\tEM_Rpro(op_%s,",mnem); - outexp(ri->arg,state); - fprintf(ofile,");\n"); - break; - case EXT: - fprintf(ofile,"\t\tOO_mkext(GETNXTREPL(), op_%s,",mnem); - outexp(ri->arg,state); - fprintf(ofile,");\n"); - break; - } } } -PRIVATE -outexp(e,state) - struct exp_node *e; - int state; +PRIVATE void outext(struct exp_node *e) { - switch(e->node_type) { - case LOGAND: - case LOGOR: - case BITAND: - case BITOR: - case XOR: - case MINUS: - case PLUS: - case TIMES: - case DIV: - case MOD: - case EQ: - case NE: - case LT: - case LE: - case GT: - case GE: - case LSHIFT: - case RSHIFT: - fprintf(ofile,"("); - outexp(e->exp_left,state); - outop(e->node_type); - outexp(e->exp_right,state); - fprintf(ofile,")"); - break; - case NOT: - case COMP: - case UPLUS: - case UMINUS: - fprintf(ofile,"("); - outop(e->node_type); - outexp(e->exp_left,state); - fprintf(ofile,")"); - break; - case DEFINED: - fprintf(ofile,"DEFINED(patt[%d])",e->leaf_val-1); - break; - case UNDEFINED: - fprintf(ofile,"!DEFINED(patt[%d])",e->leaf_val-1); - break; - case COMMA: - outext(e->exp_left); - fprintf(ofile,","); - fprintf(ofile,"(arith)"); - outexp(e->exp_right,state); - break; - case SAMESIGN: - case SFIT: - case UFIT: - case ROTATE: - outop(e->node_type); - fprintf(ofile,"(arith)"); - outexp(e->exp_left,state); - fprintf(ofile,","); - fprintf(ofile,"(arith)"); - outexp(e->exp_right,state); - fprintf(ofile,")"); - break; - case SAMEEXT: - case SAMENAM: - outop(e->node_type); - outext(e->exp_left); - fprintf(ofile,","); - outext(e->exp_right); - fprintf(ofile,")"); - break; - case PATARG: - switch(patterns[state].m_elems[e->leaf_val-1]->op_code->id_argfmt) { - case NOARG: - fprintf(stderr,"error: mnem %d has no argument\n",e->leaf_val); - nerrors++; - break; - case CST: - case CSTOPT: - fprintf(ofile,"CST(patt[%d])",e->leaf_val-1); - break; - case LAB: - fprintf(ofile,"LAB(patt[%d])",e->leaf_val-1); - break; - case DEFILB: - fprintf(ofile,"DEFILB(patt[%d])",e->leaf_val-1); - break; - case PNAM: - fprintf(ofile,"PNAM(patt[%d])",e->leaf_val-1); - break; - case EXT: - fprintf(ofile,"OO_offset(patt+%d)",e->leaf_val-1); - break; - } - break; - case PSIZE: - fprintf(ofile,"OO_PSIZE"); break; - case WSIZE: - fprintf(ofile,"OO_WSIZE"); break; - case DWSIZE: - fprintf(ofile,"OO_DWSIZE"); break; - case INT: - fprintf(ofile,"%d",e->leaf_val); break; - } -} - -PRIVATE -outext(e) - struct exp_node *e; -{ - if(e->node_type!=PATARG) { - fprintf(stderr,"Internal error in outext of parser\n"); + if (e->node_type != PATARG) + { + fprintf(stderr, "Internal error in outext of parser\n"); nerrors++; } - fprintf(ofile,"patt+%d",e->leaf_val-1); + fprintf(ofile, "patt+%d", e->leaf_val - 1); } -PRIVATE -outop(op) - int op; +PRIVATE void outop(int op) { - switch(op) { - case LOGAND: fprintf(ofile,"&&"); break; - case LOGOR: fprintf(ofile,"||"); break; - case BITAND: fprintf(ofile,"&"); break; - case BITOR: fprintf(ofile,"|"); break; - case XOR: fprintf(ofile,"^"); break; - case MINUS: fprintf(ofile,"-"); break; - case PLUS: fprintf(ofile,"+"); break; - case TIMES: fprintf(ofile,"*"); break; - case DIV: fprintf(ofile,"/"); break; - case MOD: fprintf(ofile,"%%"); break; - case EQ: fprintf(ofile,"=="); break; - case NE: fprintf(ofile,"!="); break; - case LT: fprintf(ofile,"<"); break; - case LE: fprintf(ofile,"<="); break; - case GT: fprintf(ofile,">"); break; - case GE: fprintf(ofile,">="); break; - case LSHIFT: fprintf(ofile,"<<"); break; - case RSHIFT: fprintf(ofile,">>"); break; - case NOT: fprintf(ofile,"!"); break; - case COMP: fprintf(ofile,"~"); break; - case UPLUS: fprintf(ofile,"+"); break; - case UMINUS: fprintf(ofile,"-"); break; - case SAMESIGN: fprintf(ofile,"OO_signsame("); break; - case SFIT: fprintf(ofile,"OO_sfit("); break; - case UFIT: fprintf(ofile,"OO_ufit("); break; - case ROTATE: fprintf(ofile,"OO_rotate("); break; - case SAMEEXT: fprintf(ofile,"OO_extsame("); break; - case SAMENAM: fprintf(ofile,"OO_namsame("); break; + switch (op) + { + case LOGAND: + fprintf(ofile, "&&"); + break; + case LOGOR: + fprintf(ofile, "||"); + break; + case BITAND: + fprintf(ofile, "&"); + break; + case BITOR: + fprintf(ofile, "|"); + break; + case XOR: + fprintf(ofile, "^"); + break; + case MINUS: + fprintf(ofile, "-"); + break; + case PLUS: + fprintf(ofile, "+"); + break; + case TIMES: + fprintf(ofile, "*"); + break; + case DIV: + fprintf(ofile, "/"); + break; + case MOD: + fprintf(ofile, "%%"); + break; + case EQ: + fprintf(ofile, "=="); + break; + case NE: + fprintf(ofile, "!="); + break; + case LT: + fprintf(ofile, "<"); + break; + case LE: + fprintf(ofile, "<="); + break; + case GT: + fprintf(ofile, ">"); + break; + case GE: + fprintf(ofile, ">="); + break; + case LSHIFT: + fprintf(ofile, "<<"); + break; + case RSHIFT: + fprintf(ofile, ">>"); + break; + case NOT: + fprintf(ofile, "!"); + break; + case COMP: + fprintf(ofile, "~"); + break; + case UPLUS: + fprintf(ofile, "+"); + break; + case UMINUS: + fprintf(ofile, "-"); + break; + case SAMESIGN: + fprintf(ofile, "OO_signsame("); + break; + case SFIT: + fprintf(ofile, "OO_sfit("); + break; + case UFIT: + fprintf(ofile, "OO_ufit("); + break; + case ROTATE: + fprintf(ofile, "OO_rotate("); + break; + case SAMEEXT: + fprintf(ofile, "OO_extsame("); + break; + case SAMENAM: + fprintf(ofile, "OO_namsame("); + break; } } diff --git a/modules/src/em_opt/parser.g b/modules/src/em_opt/parser.g index 2c3041ba8..719fec156 100644 --- a/modules/src/em_opt/parser.g +++ b/modules/src/em_opt/parser.g @@ -17,6 +17,7 @@ static char rcsidp1[] = "$Id$"; #endif #include "parser.h" +#include "alloc.h" #define MAXPRIO 11 @@ -33,6 +34,20 @@ int nerrors = 0; static int lencurrpatt; static int lenthisrepl; static int currentstate; /* Current state of dfa */ + +extern void back_token(void); +extern void parser(void); + +/* Forward declarations */ +void addaction(int, int, struct exp_node *,struct exp_node *, + struct mnem_list *); +struct mnem_elem **constructlist(struct mnem_list *, int); +struct mnem_list *addelem(struct mnem_list *, struct idf *, + struct exp_node *); +int dotransition(int, struct idf *, struct mnem_list *, int); +int priority(int); +void LLmessage(int); + } input : /* empty */ @@ -326,11 +341,8 @@ binop : LOGAND %lexical yylex; { -addaction(startline, state, restrictions, finaltest, repllist) - int startline; - int state; - struct exp_node *restrictions, *finaltest; - struct mnem_list *repllist; +void addaction(int startline, int state, struct exp_node *restrictions, + struct exp_node *finaltest, struct mnem_list *repllist) { struct action *p, *q; p=(struct action *)Malloc(sizeof(struct action)); @@ -349,10 +361,7 @@ addaction(startline, state, restrictions, finaltest, repllist) } } -struct mnem_elem ** -constructlist(list,len) - struct mnem_list *list; - int len; +struct mnem_elem **constructlist(struct mnem_list *list, int len) { struct mnem_elem **p; p = (struct mnem_elem **) @@ -364,11 +373,9 @@ constructlist(list,len) return(p); } -struct mnem_list * -addelem(oldlist, mnem, test) - struct mnem_list *oldlist; - struct idf *mnem; - struct exp_node *test; +struct mnem_list *addelem(struct mnem_list *oldlist, + struct idf *mnem, + struct exp_node *test) { struct mnem_list *reslist; struct mnem_elem *element; @@ -381,12 +388,11 @@ addelem(oldlist, mnem, test) return(reslist); } -int -dotransition(state, mnem, mnem_list, lenlist) - int state; - struct idf *mnem; - struct mnem_list *mnem_list; - int lenlist; +int dotransition( + int state, + struct idf *mnem, + struct mnem_list *mnem_list, + int lenlist) { struct state *p; /* look for existing transition */ @@ -399,7 +405,7 @@ dotransition(state, mnem, mnem_list, lenlist) p=(struct state *)Malloc(sizeof(struct state)); p->op=mnem; if(++higheststate>MAXSTATES) { - fprintf(stderr,"Parser: More than %s states\n",MAXSTATES); + fprintf(stderr,"Parser: More than %d states\n",MAXSTATES); sys_stop(S_EXIT); } p->goto_state= higheststate; @@ -427,7 +433,7 @@ combinetests(test1, test2) return(mknode(LOGAND,test1,test2)); } -priority(op) int op; { +int priority(int op) { switch (op) { case LOGOR: return(1); case LOGAND: return(2); @@ -456,10 +462,8 @@ priority(op) int op; { return(0); } -struct exp_node * -mknode(op,left,right) - int op; - struct exp_node *left,*right; +struct exp_node *mknode(int op, struct exp_node *left, + struct exp_node *right) { struct exp_node *p; p = (struct exp_node *)Malloc(sizeof(struct exp_node)); @@ -469,9 +473,7 @@ mknode(op,left,right) return(p); } -struct exp_node * -mkleaf(op,val) - int op,val; +struct exp_node *mkleaf(int op, int val) { struct exp_node *p; p = (struct exp_node *)Malloc(sizeof(struct exp_node)); @@ -480,8 +482,7 @@ mkleaf(op,val) return(p); } -LLmessage(insertedtok) - int insertedtok; +void LLmessage(int insertedtok) { nerrors++; fprintf(stderr,"parser: syntax error on line %d: ",linenum); @@ -492,7 +493,8 @@ LLmessage(insertedtok) else fprintf(stderr,"Deleted token %d\n",LLsymb); } -main() { +int main(int argc, char **argv) +{ initlex(); states[0] = (struct state *)NULL; patterns[0].m_len = 0; diff --git a/modules/src/em_opt/parser.h b/modules/src/em_opt/parser.h index aedaec153..32e9c481b 100644 --- a/modules/src/em_opt/parser.h +++ b/modules/src/em_opt/parser.h @@ -1,4 +1,7 @@ /* $Id$ */ +#ifndef PARSER_H_ +#define PARSER_H_ + #include #include @@ -88,10 +91,17 @@ extern struct idf *opval; /* opcode of returned OPCODE*/ extern int lastintval; /* value of last integer seen */ extern int linenum; /*line number of input file*/ -/* Functions not returning int */ -char *Malloc(); -struct exp_node *mknode(); -struct exp_node *mkleaf(); -struct exp_node *combinetests(); -struct mnem_list *addelem(); -struct mnem_elem **constructlist(); +struct exp_node *mknode(int, struct exp_node *, struct exp_node *); +struct exp_node *mkleaf(int, int); +struct exp_node *combinetests(struct exp_node *, struct exp_node *); +struct mnem_list *addelem(struct mnem_list *, struct idf *, struct exp_node *); +struct mnem_elem **constructlist(struct mnem_list *, int); +void findworst(struct mnems,struct mnems); + +void outputincalls(void); +void outputnopt(void); +void initlex(void); +void findfail(int, int *, int *, int *); + + +#endif /* PARSER_H_ */ diff --git a/modules/src/em_opt/syntax.l b/modules/src/em_opt/syntax.l index a9d30069d..a4c55522b 100644 --- a/modules/src/em_opt/syntax.l +++ b/modules/src/em_opt/syntax.l @@ -3,6 +3,7 @@ #include "Lpars.h" #include "parser.h" + struct idf *opval; /* opcode of returned OPCODE*/ int lastintval; /* value of last integer seen */ int linenum = 1; /*current line number of input file*/ @@ -59,7 +60,12 @@ offset return(OFFSET); . return(yytext[0]); %% -back_token() +int yywrap(void) +{ + return 1; +} + +void back_token(void) { yyless(0); } diff --git a/modules/src/em_opt/utils.c b/modules/src/em_opt/utils.c index 4ba33c43d..9ade89016 100644 --- a/modules/src/em_opt/utils.c +++ b/modules/src/em_opt/utils.c @@ -2,97 +2,88 @@ static char rcsid4[] = "$Id$"; #endif +#include #include "nopt.h" -arith -OO_rotate(w,amount) - arith w, amount; +arith OO_rotate(arith w, arith amount) { long highmask, lowmask; - highmask = (long)(-1) << amount; + highmask = (long) (-1) << amount; lowmask = ~highmask; - if(OO_WSIZE!=4) - highmask &= (OO_WSIZE==2)?0xFFFF:0xFF; - return(((w<> (8*OO_WSIZE-amount))&lowmask)); + if (OO_WSIZE != 4) + highmask &= (OO_WSIZE == 2) ? 0xFFFF : 0xFF; + return (((w << amount) & highmask) + | ((w >> (8 * OO_WSIZE - amount)) & lowmask)); } -int -OO_signsame(a,b) - arith a, b; +int OO_signsame(arith a, arith b) { - return( (a ^ b) >= 0); + return ((a ^ b) >= 0); } -int -OO_sfit(val,nbits) - arith val, nbits; +int OO_sfit(arith val, arith nbits) { register long mask = ~((1L << (nbits - 1)) - 1); - return(((val&mask) == 0) | (val&mask)==mask); + return (((val & mask) == 0) | ((val & mask) == mask)); } -int -OO_ufit(val, nbits) - arith val, nbits; +int OO_ufit(arith val, arith nbits) { - return((val&(~((1L << (nbits - 1)) - 1))) == 0); + return ((val & (~((1L << (nbits - 1)) - 1))) == 0); } -int -OO_extsame(a1,a2) - register p_instr a1, a2; +int OO_extsame(register p_instr a1, register p_instr a2) { if (a1->em_argtype != a2->em_argtype) - return(0); - switch(a1->em_argtype) { - case cst_ptyp: - return (a1->em_cst == a2->em_cst); - case sof_ptyp: - if(a1->em_off != a2->em_off) - return(0); - return (strcmp(a1->em_dnam,a2->em_dnam)==0); - case nof_ptyp: - if (a1->em_off != a2->em_off) - return(0); - return (a1->em_dlb == a2->em_dlb); - default: - fatal("illegal type (%d) to sameext!",a1->em_argtype); - /*NOTREACHED*/ + return (0); + switch (a1->em_argtype) + { + case cst_ptyp: + return (a1->em_cst == a2->em_cst); + case sof_ptyp: + if (a1->em_off != a2->em_off) + return (0); + return (strcmp(a1->em_dnam, a2->em_dnam) == 0); + case nof_ptyp: + if (a1->em_off != a2->em_off) + return (0); + return (a1->em_dlb == a2->em_dlb); + default: + fatal("illegal type (%d) to sameext!", a1->em_argtype); + /*NOTREACHED*/ } } -int -OO_namsame(a1,a2) - register p_instr a1, a2; +int OO_namsame(register p_instr a1, register p_instr a2) { if (a1->em_argtype != a2->em_argtype) - return(0); - switch(a1->em_argtype) { - case cst_ptyp: - return 1; - case sof_ptyp: - return (strcmp(a1->em_dnam,a2->em_dnam)==0); - case nof_ptyp: - return (a1->em_dlb == a2->em_dlb); - default: - fatal("illegal type (%d) to samenam!",a1->em_argtype); - /*NOTREACHED*/ + return (0); + switch (a1->em_argtype) + { + case cst_ptyp: + return 1; + case sof_ptyp: + return (strcmp(a1->em_dnam, a2->em_dnam) == 0); + case nof_ptyp: + return (a1->em_dlb == a2->em_dlb); + default: + fatal("illegal type (%d) to samenam!", a1->em_argtype); + /*NOTREACHED*/ } } -arith -OO_offset(a) - register p_instr a; +arith OO_offset(register p_instr a) { - switch(a->em_argtype) { - case cst_ptyp: - return a->em_cst; - case sof_ptyp: - return a->em_off; - case nof_ptyp: - return a->em_off; - default: - fatal("illegal type (%d) to offset!",a->em_argtype); - /*NOTREACHED*/ + switch (a->em_argtype) + { + case cst_ptyp: + return a->em_cst; + case sof_ptyp: + return a->em_off; + case nof_ptyp: + return a->em_off; + default: + fatal("illegal type (%d) to offset!", a->em_argtype); + /*NOTREACHED*/ } } From 48480dcae5323a9200771a5e26ad6206ddd60a21 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 10 Jun 2019 16:12:36 +0200 Subject: [PATCH 72/84] Fix a tiny ackbuilder bug where you can't set properties to false. --- first/ackbuilder.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/first/ackbuilder.lua b/first/ackbuilder.lua index 81e86b528..616c805d2 100644 --- a/first/ackbuilder.lua +++ b/first/ackbuilder.lua @@ -7,6 +7,7 @@ -- is = { set of rule types which made the target } -- } +local posix = require("posix") local emitter = {} local rules = {} local targets = {} @@ -544,7 +545,7 @@ local function definerule(rulename, types, cb) local args = {} for propname, typespec in pairs(types) do - if not e[propname] then + if e[propname] == nil then if not typespec.optional and (typespec.default == nil) then error(string.format("missing mandatory property '%s'", propname)) end From 3f938d651b9c9441770e6fa83fca4abf264c18aa Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 10 Jun 2019 18:33:04 +0200 Subject: [PATCH 73/84] EM requires 2-alignment in structures, sadly. --- plat/cpm/descr | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plat/cpm/descr b/plat/cpm/descr index 58fef69d5..2dea09e10 100644 --- a/plat/cpm/descr +++ b/plat/cpm/descr @@ -3,19 +3,19 @@ # $Revision$ var w=2 -var wa=1 +var wa=2 var p=2 -var pa=1 +var pa=2 var s=2 -var sa=1 +var sa=2 var l=4 -var la=1 +var la=2 var f=4 -var fa=1 +var fa=2 var d=8 -var da=1 +var da=2 var x=8 -var xa=1 +var xa=2 var ARCH=i80 var PLATFORM=cpm var PLATFORMDIR={EM}/share/ack/{PLATFORM} From d0967e683b286e01fce486ddfb53d6013ed67c03 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 10 Jun 2019 23:54:23 +0200 Subject: [PATCH 74/84] Extend the CP/M libsys with a full set of (hopefully correct) 2.2 BDOS calls. --- plat/cpm/boot.s | 47 +++++++++-- plat/cpm/include/cpm.h | 168 ++++++++++++++++++++++++-------------- plat/cpm/libsys/_bdos.s | 62 ++++---------- plat/cpm/libsys/_trap.s | 24 ++---- plat/cpm/libsys/brk.c | 13 +-- plat/cpm/libsys/build.lua | 63 +++++++++++++- plat/cpm/libsys/read.c | 8 +- plat/cpm/libsys/write.c | 19 +---- 8 files changed, 240 insertions(+), 164 deletions(-) diff --git a/plat/cpm/boot.s b/plat/cpm/boot.s index 40ab0d775..a1e99ed00 100644 --- a/plat/cpm/boot.s +++ b/plat/cpm/boot.s @@ -27,7 +27,7 @@ begtext: mov c, a ! c = high byte of BDOS address mov a, b ! a = high byte of _end cmp c - jnc __exit ! emergency exit if a >= c + rnc ! emergency exit if a >= c ! We have to clear the bss. (argify requires it.) @@ -46,6 +46,9 @@ begtext: ! Set up the stack (now it's been cleared, since it's in the BSS). + lxi h, 0 + dad sp + shld saved_sp ! save old stack pointer lxi sp, stack + STACKSIZE ! Initialise the rsts (if desired). @@ -54,8 +57,13 @@ begtext: call .rst_init #endif + ! Now the 'heap'. + + lxi h, __end + shld _cpm_ram + ! C-ify the command line at 0x0080. - + lxi h, 0x0080 mov a, m ! a = length of command line cpi 0x7F ! 127-byte command lines... @@ -119,16 +127,39 @@ end_of_argify: lhld argc ! slightly evil mvi h, 0 push h - call __m_a_i_n - ! FALLTHROUGH + push h ! return address is 0 + jmp __m_a_i_n + +.define _cpm_fastexit +_cpm_fastexit: +saved_sp = _cpm_fastexit + 1 + lxi sp, 0 ! patched on startup + ret ! Emergency exit routine. -.define EXIT, __exit -EXIT: -__exit: - rst 0 +.define EXIT, __exit, _cpm_exit +EXIT = 0 +__exit = 0 +_cpm_exit = 0 +! Special CP/M stuff. + +.define _cpm_fcb +_cpm_fcb = 0x005c + +.define _cpm_ram +.comm _cpm_ram, 2 +.define _cpm_ramtop +_cpm_ramtop = 0x0001 + +.define _cpm_default_dma +_cpm_default_dma = 0x0080 + +.define _cpm_cmdlinelen, _cpm_cmdline +_cpm_cmdlinelen = 0x0080 +_cpm_cmdline = 0x0081 + ! Define symbols at the beginning of our various segments, so that we can find ! them. (Except .text, which has already been done.) diff --git a/plat/cpm/include/cpm.h b/plat/cpm/include/cpm.h index bdda5ed23..9a354eb03 100644 --- a/plat/cpm/include/cpm.h +++ b/plat/cpm/include/cpm.h @@ -1,66 +1,114 @@ -/* - * unistd.h - standard system calls - */ -/* $Id$ */ - -#ifndef _CPM_H -#define _CPM_H +#ifndef CPM_H +#define CPM_H #include -/* These interface provides a very bare-bones interface to the CP/M BDOS. Set - * the following four variables as you wish, call cpm_bdos(), and the contents - * of the variables will have been updated accordingly. */ - -extern uint8_t cpm_a_register; -extern uint16_t cpm_bc_register; -extern uint16_t cpm_de_register; -extern uint16_t cpm_hl_register; - -extern void cpm_bdos(void); - -/* Describes the available CP/M BDOS calls. They're a fairly conservative set - * taken from the CP/M 2.0 manual. */ - -enum +typedef struct { - CPM_BDOS_SYSTEM_RESET, - CPM_BDOS_CONSOLE_INPUT, - CPM_BDOS_CONSOLE_OUTPUT, - CPM_BDOS_READER_INPUT, - CPM_BDOS_PUNCH_OUTPUT, - CPM_BDOS_LIST_OUTPUT, - CPM_BDOS_CONSOLE_IO, - CPM_BDOS_GET_IO_BYTE, - CPM_BDOS_SET_IO_BYTE, - CPM_BDOS_PRINT_STRING, - CPM_BDOS_READ_CONSOLE_BUFFER, - CPM_BDOS_GET_CONSOLE_STATUS, - CPM_BDOS_GET_VERSION_NUMBER, - CPM_BDOS_RESET_DISK_SYSTEM, - CPM_BDOS_SELECT_DISK, - CPM_BDOS_OPEN_FILE, - CPM_BDOS_CLOSE_FILE, - CPM_BDOS_SEARCHFIRST, - CPM_BDOS_SEARCHNEXT, - CPM_BDOS_DELETE_FILE, - CPM_BDOS_READ_SEQ, - CPM_BDOS_WRITE_SEQ, - CPM_BDOS_MAKE_FILE, - CPM_BDOS_RENAME_FILE, - CPM_BDOS_GET_LOGIN_VECTOR, - CPM_BDOS_GET_CURRENT_DISK, - CPM_BDOS_SET_DMA_ADDRESS, - CPM_BDOS_GET_ALLOC_VECTOR, - CPM_BDOS_WRITE_PROTECT, - CPM_BDOS_GET_RO_VECTOR, - CPM_BDOS_SET_FILE_ATTR, - CPM_BDOS_GET_DISK_PARMS, - CPM_BDOS_SETGET_USER, - CPM_BDOS_READ_RANDOM, - CPM_BDOS_WRITE_RANDOM, - CPM_BDOS_GET_FILE_SIZE, - CPM_BDOS_SET_RANDOM -}; + uint8_t dr; + uint8_t f[11]; + uint8_t ex; + uint8_t s1; + uint8_t s2; + uint8_t rc; + uint8_t d[16]; + uint8_t cr; + uint16_t r; + uint8_t r2; +} +FCB; + +typedef struct +{ + uint8_t dr; + uint8_t src[11]; + uint8_t _padding[5]; + uint8_t dest[11]; +} +RCB; + +typedef struct +{ + uint8_t us; + uint8_t f[11]; + uint8_t ex; + uint8_t s[2]; + uint8_t rc; + union + { + uint8_t al8[16]; + uint16_t al16[8]; + } + al; +} +DIRE; + +typedef struct +{ + uint16_t spt; /* number of 128-byte sectors per track */ + uint8_t bsh; /* block shift; 3=1kB, 4=2kB, 5=4kB etc */ + uint8_t blm; /* block mask; 0x07=1kB, 0x0f=2kB, 0x1f=4k etc */ + uint8_t exm; /* extent mask */ + uint16_t dsm; /* maximum block number */ + uint16_t drm; /* maximum directory entry number */ + uint16_t al; /* directory allocation bitmap */ + uint16_t cks; /* checksum vector size */ + uint16_t off; /* number of reserved tracks */ +} +DPB; + +extern FCB cpm_fcb; /* primary FCB */ +extern FCB cpm_fcb2; /* secondary FCB (special purpose) */ +extern uint8_t cpm_iobyte; + +extern uint8_t cpm_default_dma[128]; /* also contains the parsed command line */ +extern uint8_t* cpm_ram; +extern uint8_t* cpm_ramtop; +extern uint8_t cpm_cmdlinelen; +extern char cpm_cmdline[0x7f]; + +/* Special: longjmps out of the program. Don't use if you've overwritten the + * CCP. */ +extern void cpm_fastexit(void); + +/* 0 */ extern void cpm_exit(void); +/* 1 */ extern uint8_t cpm_conin(void); +/* 2 */ extern void cpm_conout(uint8_t b); +/* 3 */ extern uint8_t cpm_auxin(void); +/* 4 */ extern void cpm_auxout(uint8_t b); +/* 5 */ extern void cpm_lstout(uint8_t b); +/* 6 */ extern uint8_t cpm_conio(uint8_t b); +/* 7 */ extern uint8_t cpm_get_iobyte(void); +/* 8 */ extern void cpm_set_iobyte(uint8_t iob); +/* 9 */ extern void cpm_printstring(const char* s); /* $-terminated */ +/* 10 */ extern uint8_t cpm_readline(uint8_t* buffer); +/* 11 */ extern uint8_t cpm_const(void); +/* 12 */ extern uint16_t cpm_get_version(void); +/* 13 */ extern void cpm_reset_disk_system(void); +/* 14 */ extern void cpm_select_disk(uint8_t disk); +/* 15 */ extern uint8_t cpm_open_file(FCB* fcb); +/* 16 */ extern uint8_t cpm_close_file(FCB* fcb); +/* 17 */ extern uint8_t cpm_findfirst(FCB* fcb); +/* 18 */ extern uint8_t cpm_findnext(FCB* fcb); +/* 19 */ extern uint8_t cpm_delete_file(FCB* fcb); +/* 20 */ extern uint8_t cpm_read_sequential(FCB* fcb); +/* 21 */ extern uint8_t cpm_write_sequential(FCB* fcb); +/* 22 */ extern uint8_t cpm_make_file(FCB* fcb); +/* 23 */ extern uint8_t cpm_rename_file(RCB* rcb); +/* 24 */ extern uint16_t cpm_get_login_vector(void); +/* 25 */ extern uint8_t cpm_get_current_drive(void); +/* 26 */ extern void cpm_set_dma(void* ptr); +/* 27 */ extern uint8_t* cpm_get_allocation_vector(void); +/* 28 */ extern void cpm_write_protect_drive(void); +/* 29 */ extern uint16_t cpm_get_readonly_vector(void); +/* 30 */ extern uint8_t cpm_set_file_attributes(FCB* fcb); +/* 31 */ extern DPB* cpm_get_dpb(void); +/* 32 */ extern uint8_t cpm_get_set_user(uint8_t user); +/* 33 */ extern uint8_t cpm_read_random(FCB* fcb); +/* 34 */ extern uint8_t cpm_write_random(FCB* fcb); +/* 35 */ extern void cpm_seek_to_end(FCB* fcb); +/* 36 */ extern void cpm_seek_to_seq_pos(FCB* fcb); +/* 37 */ extern uint8_t cpm_reset_drives(uint16_t drive_bitmap); +/* 40 */ extern uint8_t cpm_write_random_filled(FCB* fcb); #endif diff --git a/plat/cpm/libsys/_bdos.s b/plat/cpm/libsys/_bdos.s index 4a05dfcdf..9e136925e 100644 --- a/plat/cpm/libsys/_bdos.s +++ b/plat/cpm/libsys/_bdos.s @@ -1,55 +1,21 @@ # -! $Source$ -! $State$ -! $Revision$ +#include "asm.h" -! Declare segments (the order is important). +! Calls a BDOS routine and returns the result. +! a = BDOS opcode -.sect .text -.sect .rom -.sect .data -.sect .bss +.define call_bdos +call_bdos: + pop h ! pop return address + pop d ! pop parameter (possibly junk) + push d + push h -.sect .text - -! Calls a BDOS routine. - -.define _cpm_bdos -_cpm_bdos: - push b + push b ! save FP as the BDOS will corrupt it + mov c, a ! move opcode to C + call 0x0005 + pop b ! restore FP - lda _cpm_a_register - - lhld _cpm_bc_register - mov b, h - mov c, l - - lhld _cpm_de_register mov d, h mov e, l - - lhld _cpm_hl_register - - call 5 - - shld _cpm_hl_register - - mov h, d - mov l, e - shld _cpm_de_register - - mov h, b - mov l, c - shld _cpm_bc_register - - sta _cpm_a_register - - pop b - ret - -.sect .bss -.define _cpm_a_register, _cpm_bc_register, _cpm_de_register, _cpm_hl_register -.comm _cpm_a_register, 1 -.comm _cpm_bc_register, 2 -.comm _cpm_de_register, 2 -.comm _cpm_hl_register, 2 + ret \ No newline at end of file diff --git a/plat/cpm/libsys/_trap.s b/plat/cpm/libsys/_trap.s index a3836c998..678b9cc7f 100644 --- a/plat/cpm/libsys/_trap.s +++ b/plat/cpm/libsys/_trap.s @@ -3,12 +3,8 @@ ! $State$ ! $Revision$ -! Declare segments (the order is important). - -.sect .text -.sect .rom -.sect .data -.sect .bss +# +#include "asm.h" .define .trp .define earray, erange, eset, eiovfl, efovfl, efunfl, eidivz, eidivz @@ -16,8 +12,6 @@ .define ecase, ememflt, ebadptr, ebadpc, ebadlae, ebadmon, ebadlin, ebadgto .define eunimpl -.sect .text - ! Trap routine ! Expects trap number on stack. ! Just returns if trap has to be ignored. @@ -206,15 +200,11 @@ eunimpl:lxi h,EUNIMPL pop d ret 1: - lxi h, 6 - push h - lxi h, text - push h - lxi h, 1 - push h - call _write - jmp EXIT + lxi d, text + mvi c, 9 ! write $-terminated string + call 0x0005 + rst 0 ! abend .sect .rom -text: .ascii "TRAP!\n" +text: .ascii "TRAP!\r\n$" diff --git a/plat/cpm/libsys/brk.c b/plat/cpm/libsys/brk.c index 6c139dd2a..e9f13c1e6 100644 --- a/plat/cpm/libsys/brk.c +++ b/plat/cpm/libsys/brk.c @@ -1,8 +1,4 @@ -/* $Source$ - * $State$ - * $Revision$ - */ - +#include #include #include #include @@ -11,7 +7,6 @@ #define STACK_BUFFER 128 /* number of bytes to leave for stack */ extern char _end[1]; -static char* current = _end; int brk(void* newend) { @@ -24,7 +19,7 @@ int brk(void* newend) (p < _end)) return -1; - current = p; + cpm_ram = p; return 0; } @@ -34,9 +29,9 @@ void* sbrk(int increment) char* new; if (increment == 0) - return current; + return cpm_ram; - old = current; + old = cpm_ram; new = old + increment; if ((increment > 0) && (new <= old)) diff --git a/plat/cpm/libsys/build.lua b/plat/cpm/libsys/build.lua index c2a75a4c3..780dea626 100644 --- a/plat/cpm/libsys/build.lua +++ b/plat/cpm/libsys/build.lua @@ -1,12 +1,73 @@ +acklibrary { + name = "internal", + hdrs = { "./*.h" } +} + +local bdos_calls = { + [ 0] = "cpm_exit", + [ 1] = "cpm_conin", + [ 2] = "cpm_conout", + [ 3] = "cpm_auxin", + [ 4] = "cpm_auxout", + [ 5] = "cpm_lstout", + [ 6] = "cpm_conio", + [ 7] = "cpm_get_iobyte", + [ 8] = "cpm_set_iobyte", + [ 9] = "cpm_printstring", + [10] = "cpm_readline", + [11] = "cpm_const", + [12] = "cpm_get_version", + [13] = "cpm_reset_disk_system", + [14] = "cpm_select_disk", + [15] = "cpm_open_file", + [16] = "cpm_close_file", + [17] = "cpm_findfirst", + [18] = "cpm_findnext", + [19] = "cpm_delete_file", + [20] = "cpm_read_sequential", + [21] = "cpm_write_sequential", + [22] = "cpm_make_file", + [23] = "cpm_rename_file", + [24] = "cpm_get_login_vector", + [25] = "cpm_get_current_drive", + [26] = "cpm_set_dma", + [27] = "cpm_get_allocation_vector", + [28] = "cpm_write_protect_drive", + [29] = "cpm_get_readonly_vector", + [30] = "cpm_set_file_attributes", + [31] = "cpm_get_dpb", + [32] = "cpm_get_set_user", + [33] = "cpm_read_random", + [34] = "cpm_write_random", + [35] = "cpm_seek_to_end", + [36] = "cpm_seek_to_seq_pos", + [37] = "cpm_reset_drives", + [40] = "cpm_write_random_filled", +} + +local generated = {} +for n, name in pairs(bdos_calls) do + generated[#generated+1] = normalrule { + name = name, + ins = { "./make_bdos_call.sh" }, + outleaves = { name..".s" }, + commands = { + "%{ins[1]} "..n.." "..name.." > %{outs}" + } + } +end + acklibrary { name = "lib", srcs = { "./*.c", "./*.s", + generated }, deps = { "lang/cem/libcc.ansi/headers+headers", - "plat/cpm/include+headers", + "plat/cpm/include+headers", + "+internal", }, vars = { plat = "cpm" diff --git a/plat/cpm/libsys/read.c b/plat/cpm/libsys/read.c index df4a3ef3b..b04a13ee5 100644 --- a/plat/cpm/libsys/read.c +++ b/plat/cpm/libsys/read.c @@ -36,18 +36,14 @@ ssize_t read(int fd, void* buffer, size_t count) /* Read one line from the console. */ ((unsigned char*)buffer)[-2] = before_n; - cpm_bc_register = CPM_BDOS_READ_CONSOLE_BUFFER; - cpm_de_register = (uint16_t)(char*)buffer - 2; - cpm_bdos(); + cpm_readline((uint8_t*)buffer - 2); before_n = ((unsigned char*)buffer)[-1]; ((char*)buffer)[before_n] = '\n'; /* Append '\n'. */ ((short*)buffer)[-1] = save; /* Give back borrowed bytes. */ /* Echo '\n' to console. */ - cpm_bc_register = CPM_BDOS_PRINT_STRING; - cpm_de_register = (uint16_t)"\r\n$"; - cpm_bdos(); + cpm_printstring("\r\n$"); return (int)before_n + 1; } diff --git a/plat/cpm/libsys/write.c b/plat/cpm/libsys/write.c index 21dbc90c0..768e9b2eb 100644 --- a/plat/cpm/libsys/write.c +++ b/plat/cpm/libsys/write.c @@ -10,16 +10,9 @@ void _sys_write_tty(char c) { - cpm_bc_register = CPM_BDOS_CONSOLE_OUTPUT; - cpm_de_register = c; - cpm_bdos(); - + cpm_conout(c); if (c == '\n') - { - cpm_bc_register = CPM_BDOS_CONSOLE_OUTPUT; - cpm_de_register = '\r'; - cpm_bdos(); - } + cpm_conout(c); } ssize_t write(int fd, void* buffer, size_t count) @@ -37,13 +30,9 @@ ssize_t write(int fd, void* buffer, size_t count) /* Write all data. */ - i = 0; - while (i < count) - { + i = count; + while (i--) _sys_write_tty(*p++); - - i++; - } /* No failures. */ From ec2ea1feffa85f1138e5b091fcea164dbfbf7979 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 10 Jun 2019 23:57:43 +0200 Subject: [PATCH 75/84] Add missing file. --- plat/cpm/libsys/make_bdos_call.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 plat/cpm/libsys/make_bdos_call.sh diff --git a/plat/cpm/libsys/make_bdos_call.sh b/plat/cpm/libsys/make_bdos_call.sh new file mode 100755 index 000000000..949523007 --- /dev/null +++ b/plat/cpm/libsys/make_bdos_call.sh @@ -0,0 +1,10 @@ +#!/bin/sh +cat < Date: Tue, 11 Jun 2019 00:12:00 +0200 Subject: [PATCH 76/84] Generate traps procedurally. For some reason they always keep getting pulled in, though... --- plat/cpm/libsys/_trap.s | 124 ++--------------------------------- plat/cpm/libsys/build.lua | 37 +++++++++++ plat/cpm/libsys/make_trap.sh | 12 ++++ 3 files changed, 53 insertions(+), 120 deletions(-) create mode 100755 plat/cpm/libsys/make_trap.sh diff --git a/plat/cpm/libsys/_trap.s b/plat/cpm/libsys/_trap.s index 678b9cc7f..ec6208a72 100644 --- a/plat/cpm/libsys/_trap.s +++ b/plat/cpm/libsys/_trap.s @@ -11,6 +11,10 @@ .define efdivz, eiund, efund, econv, estack, eheap, eillins, eoddz .define ecase, ememflt, ebadptr, ebadpc, ebadlae, ebadmon, ebadlin, ebadgto .define eunimpl +.define EARRAY, ERANGE, ESET, EIOVFL, EFOVFL, EFUNFL, EIDIVZ, EIDIVZ +.define EFDIVZ, EIUND, EFUND, ECONV, ESTACK, EHEAP, EILLINS, EODDZ +.define ECASE, EMEMFLT, EBADPTR, EBADPC, EBADLAE, EBADMON, EBADLIN, EBADGTO +.define EUNIMPL ! Trap routine ! Expects trap number on stack. @@ -45,126 +49,6 @@ EBADGTO = 27 EUNIMPL = 63 ! unimplemented em-instruction called -earray: lxi h,EARRAY - push h - call .trp - ret - -erange: lxi h,ERANGE - push h - call .trp - ret - -eset: lxi h,ESET - push h - call .trp - ret - -eiovfl: lxi h,EIOVFL - push h - call .trp - ret - -efovfl: lxi h,EFOVFL - push h - call .trp - ret - -efunfl: lxi h,EFUNFL - push h - call .trp - ret - -eidivz: lxi h,EIDIVZ - push h - call .trp - ret - -efdivz: lxi h,EFDIVZ - push h - call .trp - ret - -eiund: lxi h,EIUND - push h - call .trp - ret - -efund: lxi h,EFUND - push h - call .trp - ret - -econv: lxi h,ECONV - push h - call .trp - ret - -estack: lxi h,ESTACK - push h - call .trp - ret - -eheap: lxi h,EHEAP - push h - call .trp - ret - -eillins:lxi h,EILLINS - push h - call .trp - ret - -eoddz: lxi h,EODDZ - push h - call .trp - ret - -ecase: lxi h,ECASE - push h - call .trp - ret - -ememflt:lxi h,EMEMFLT - push h - call .trp - ret - -ebadptr:lxi h,EBADPTR - push h - call .trp - ret - -ebadpc: lxi h,EBADPC - push h - call .trp - ret - -ebadlae:lxi h,EBADLAE - push h - call .trp - ret - -ebadmon:lxi h,EBADMON - push h - call .trp - ret - -ebadlin:lxi h,EBADLIN - push h - call .trp - ret - -ebadgto:lxi h,EBADGTO - push h - call .trp - ret - -eunimpl:lxi h,EUNIMPL - push h - call .trp - ret - .trp: pop h xthl diff --git a/plat/cpm/libsys/build.lua b/plat/cpm/libsys/build.lua index 780dea626..f9cd9a96e 100644 --- a/plat/cpm/libsys/build.lua +++ b/plat/cpm/libsys/build.lua @@ -45,6 +45,33 @@ local bdos_calls = { [40] = "cpm_write_random_filled", } +local trap_calls = { + "EARRAY", + "ERANGE", + "ESET", + "EIOVFL", + "EFOVFL", + "EFUNFL", + "EIDIVZ", + "EFDIVZ", + "EIUND", + "EFUND", + "ECONV", + "ESTACK", + "EHEAP", + "EILLINS", + "EODDZ", + "ECASE", + "EMEMFLT", + "EBADPTR", + "EBADPC", + "EBADLAE", + "EBADMON", + "EBADLIN", + "EBADGTO", + "EUNIMPL", +} + local generated = {} for n, name in pairs(bdos_calls) do generated[#generated+1] = normalrule { @@ -56,6 +83,16 @@ for n, name in pairs(bdos_calls) do } } end +for _, name in pairs(trap_calls) do + generated[#generated+1] = normalrule { + name = name, + ins = { "./make_trap.sh" }, + outleaves = { name..".s" }, + commands = { + "%{ins[1]} "..name:lower().." "..name.." > %{outs}" + } + } +end acklibrary { name = "lib", diff --git a/plat/cpm/libsys/make_trap.sh b/plat/cpm/libsys/make_trap.sh new file mode 100755 index 000000000..25562fa2a --- /dev/null +++ b/plat/cpm/libsys/make_trap.sh @@ -0,0 +1,12 @@ +#!/bin/sh +cat < Date: Tue, 11 Jun 2019 00:12:10 +0200 Subject: [PATCH 77/84] Allow building one plat at a time. --- build.lua | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/build.lua b/build.lua index d7eb0829f..ccd113f1a 100644 --- a/build.lua +++ b/build.lua @@ -27,17 +27,8 @@ vars.plats_with_tests = { "pc86", } -local plat_packages = {} -local test_packages = {} -for _, p in ipairs(vars.plats) do - plat_packages[#plat_packages+1] = "plat/"..p.."+pkg" -end -for _, p in ipairs(vars.plats_with_tests) do - test_packages[#test_packages+1] = "plat/"..p.."/tests+tests" -end - installable { - name = "ack", + name = "ack-common", map = { "lang/basic/src+pkg", "lang/cem/cemcom.ansi+pkg", @@ -53,6 +44,31 @@ installable { "util/led+pkg", "util/misc+pkg", "util/opt+pkg", + }, +} + +local plat_packages = {} +local test_packages = {} +for _, p in ipairs(vars.plats) do + local pkg = "plat/"..p.."+pkg" + plat_packages[#plat_packages+1] = pkg + + installable { + name = "ack-"..p, + map = { + "+ack-common", + pkg, + }, + } +end +for _, p in ipairs(vars.plats_with_tests) do + test_packages[#test_packages+1] = "plat/"..p.."/tests+tests" +end + +installable { + name = "ack", + map = { + "+ack-common", "examples+pkg", plat_packages }, From f58d7e7d3090a8480ead93a53424b20102814c8e Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 11 Jun 2019 19:40:46 +0200 Subject: [PATCH 78/84] Add missing file. --- plat/cpm/libsys/asm.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 plat/cpm/libsys/asm.h diff --git a/plat/cpm/libsys/asm.h b/plat/cpm/libsys/asm.h new file mode 100644 index 000000000..f86b91104 --- /dev/null +++ b/plat/cpm/libsys/asm.h @@ -0,0 +1,13 @@ +#ifndef ASM_H +#define ASM_H + +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + +#endif From 4e90de00e946a60fb9f0c133878dda5378ce2867 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 11 Jun 2019 19:47:42 +0200 Subject: [PATCH 79/84] Don't pull in all the trap handlers every time. --- plat/cpm/libsys/_trap.s | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plat/cpm/libsys/_trap.s b/plat/cpm/libsys/_trap.s index ec6208a72..bb541932f 100644 --- a/plat/cpm/libsys/_trap.s +++ b/plat/cpm/libsys/_trap.s @@ -7,10 +7,6 @@ #include "asm.h" .define .trp -.define earray, erange, eset, eiovfl, efovfl, efunfl, eidivz, eidivz -.define efdivz, eiund, efund, econv, estack, eheap, eillins, eoddz -.define ecase, ememflt, ebadptr, ebadpc, ebadlae, ebadmon, ebadlin, ebadgto -.define eunimpl .define EARRAY, ERANGE, ESET, EIOVFL, EFOVFL, EFUNFL, EIDIVZ, EIDIVZ .define EFDIVZ, EIUND, EFUND, ECONV, ESTACK, EHEAP, EILLINS, EODDZ .define ECASE, EMEMFLT, EBADPTR, EBADPC, EBADLAE, EBADMON, EBADLIN, EBADGTO From 3feb79ad0c7bfbe484859f94d276e3b3474b79ea Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 11 Jun 2019 20:02:03 +0200 Subject: [PATCH 80/84] Simplify the .trp API to make it a bit smaller. --- mach/i80/ncg/table | 5 +++-- plat/cpm/boot.s | 6 ++---- plat/cpm/libsys/_trap.s | 12 ++++++------ plat/cpm/libsys/make_trap.sh | 6 ++---- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/mach/i80/ncg/table b/mach/i80/ncg/table index 74c85f89e..783500195 100644 --- a/mach/i80/ncg/table +++ b/mach/i80/ncg/table @@ -2475,5 +2475,6 @@ with hlreg gen shld {label,".reghp"} pat trp -kills ALL -gen Call {label,".trp"} + with areg + kills ALL + gen Call {label,".trp"} diff --git a/plat/cpm/boot.s b/plat/cpm/boot.s index a1e99ed00..64f85fd2a 100644 --- a/plat/cpm/boot.s +++ b/plat/cpm/boot.s @@ -170,8 +170,7 @@ _cpm_cmdline = 0x0081 ! Some magic data. All EM systems need these. -.define .trppc, .ignmask, _errno -.comm .trppc, 2 +.define .ignmask, _errno .comm .ignmask, 2 .comm _errno, 2 @@ -184,11 +183,10 @@ envp: .space 2 ! envp array (always empty, must be after argv) ! These are used specifically by the i80 code generator. -.define .trapproc, .retadr, .retadr1 +.define .retadr, .retadr1 .define .bcreg, .areg .define .tmp1, .fra, block1, block2, block3 -.comm .trapproc, 2 .comm .retadr, 2 ! used to save return address .comm .retadr1, 2 ! reserve .comm .bcreg, 2 diff --git a/plat/cpm/libsys/_trap.s b/plat/cpm/libsys/_trap.s index bb541932f..cd561fa65 100644 --- a/plat/cpm/libsys/_trap.s +++ b/plat/cpm/libsys/_trap.s @@ -13,7 +13,8 @@ .define EUNIMPL ! Trap routine -! Expects trap number on stack. +! Expects trap number in A, and must be called directly from the code +! where execution should resume (for those traps which support it). ! Just returns if trap has to be ignored. ! Otherwise it calls a user-defined trap handler if provided. ! When no user-defined trap handler is provided or when the user-defined @@ -46,9 +47,6 @@ EUNIMPL = 63 ! unimplemented em-instruction called .trp: - pop h - xthl - push h ! trap number and return address exchanged mov a,l cpi 16 jnc 3f ! jump if trap cannot be ignored @@ -66,10 +64,12 @@ ret ! OGEN DICHT EN ... SPRING!!! 3: - lhld .trapproc ! user defined trap handler? +.define .trapproc +.trapproc = . + 1 + lxi h, 0 ! user defined trap handler held inline here mov a,l ora h - jz 1f ! jump if there was not + jz 1f ! jump if there was not xra a sta .trapproc ! .trapproc := 0 sta .trapproc+1 diff --git a/plat/cpm/libsys/make_trap.sh b/plat/cpm/libsys/make_trap.sh index 25562fa2a..1c09388ae 100755 --- a/plat/cpm/libsys/make_trap.sh +++ b/plat/cpm/libsys/make_trap.sh @@ -4,9 +4,7 @@ cat < Date: Tue, 11 Jun 2019 20:32:00 +0200 Subject: [PATCH 81/84] Miscellaneous byte shaving; you can now choose whether or not you want the CCP overwritten or not, and cpm_exit() does the right thing. --- plat/cpm/boot.s | 44 ++++++++++++++++------------- plat/cpm/include/cpm.h | 11 +++++--- plat/cpm/libsys/brk.c | 17 +++++------ plat/cpm/libsys/cpm_overwrite_ccp.s | 12 ++++++++ 4 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 plat/cpm/libsys/cpm_overwrite_ccp.s diff --git a/plat/cpm/boot.s b/plat/cpm/boot.s index 64f85fd2a..1330e8309 100644 --- a/plat/cpm/boot.s +++ b/plat/cpm/boot.s @@ -22,12 +22,13 @@ begtext: ! BDOS and crash CP/M. We cheat by comparing only high bytes ! of each address. - lxi b, __end lda 0x0007 - mov c, a ! c = high byte of BDOS address - mov a, b ! a = high byte of _end + mov c, a ! c = high byte of BDOS address + lda _cpm_ram+1 ! a = high byte of top of BSS, a.k.a. _end cmp c - rnc ! emergency exit if a >= c + lxi d, noroom + mvi c, 9 + jnc 0x0005 ! print error and exit if a >= c ! We have to clear the bss. (argify requires it.) @@ -59,8 +60,10 @@ begtext: ! Now the 'heap'. - lxi h, __end - shld _cpm_ram + lhld 0x0006 ! BDOS entry point + lxi d, -0x806 ! offset to start of CCP + dad d + shld _cpm_ramtop ! C-ify the command line at 0x0080. @@ -127,31 +130,29 @@ end_of_argify: lhld argc ! slightly evil mvi h, 0 push h - push h ! return address is 0 - jmp __m_a_i_n - -.define _cpm_fastexit -_cpm_fastexit: -saved_sp = _cpm_fastexit + 1 + call __m_a_i_n +.define _cpm_exit, EXIT, __exit +_cpm_exit: +EXIT: +__exit: + stc ! set carry bit + jnc _cpm_warmboot ! warm boot if not set +saved_sp = . + 1 lxi sp, 0 ! patched on startup ret ! Emergency exit routine. -.define EXIT, __exit, _cpm_exit -EXIT = 0 -__exit = 0 -_cpm_exit = 0 +.define _cpm_warmboot +_cpm_warmboot = 0 ! Special CP/M stuff. .define _cpm_fcb _cpm_fcb = 0x005c -.define _cpm_ram -.comm _cpm_ram, 2 .define _cpm_ramtop -_cpm_ramtop = 0x0001 +.comm _cpm_ramtop, 2 .define _cpm_default_dma _cpm_default_dma = 0x0080 @@ -197,5 +198,10 @@ block1: .space 4 ! used by 32 bits divide and block2: .space 4 ! multiply routines block3: .space 4 ! must be contiguous (.comm doesn't guarantee this) +.sect .data +.define _cpm_ram +_cpm_ram: .data2 __end + .sect .rom progname: .asciz 'ACKCPM' +noroom: .ascii 'No room$' diff --git a/plat/cpm/include/cpm.h b/plat/cpm/include/cpm.h index 9a354eb03..81dfa5dab 100644 --- a/plat/cpm/include/cpm.h +++ b/plat/cpm/include/cpm.h @@ -67,11 +67,14 @@ extern uint8_t* cpm_ramtop; extern uint8_t cpm_cmdlinelen; extern char cpm_cmdline[0x7f]; -/* Special: longjmps out of the program. Don't use if you've overwritten the - * CCP. */ -extern void cpm_fastexit(void); +/* Special: if the CCP hasn't been overwritten, returns to it; otherwise does + * a warmboot. */ +extern void cpm_exit(void); -/* 0 */ extern void cpm_exit(void); +/* Extends cpm_ramtop over the CCP, for a little extra space. */ +extern void cpm_overwrite_ccp(void); + +/* 0 */ extern void cpm_warmboot(void); /* 1 */ extern uint8_t cpm_conin(void); /* 2 */ extern void cpm_conout(uint8_t b); /* 3 */ extern uint8_t cpm_auxin(void); diff --git a/plat/cpm/libsys/brk.c b/plat/cpm/libsys/brk.c index e9f13c1e6..5debaa5ff 100644 --- a/plat/cpm/libsys/brk.c +++ b/plat/cpm/libsys/brk.c @@ -1,32 +1,29 @@ #include +#include #include #include #include #define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */ -#define STACK_BUFFER 128 /* number of bytes to leave for stack */ -extern char _end[1]; +extern uint8_t _end[1]; int brk(void* newend) { - /* We determine the amount of free memory by looking at the address of the - * BDOS vector at 0x0006. */ - char* memtop = (char*) ((*(unsigned char*)0x0007)<<8); - char* p = newend; + uint8_t* p = newend; - if ((p >= memtop) || + if ((p >= cpm_ramtop) || (p < _end)) return -1; - cpm_ram = p; + cpm_ram = (uint8_t*)p; return 0; } void* sbrk(int increment) { - char* old; - char* new; + uint8_t* old; + uint8_t* new; if (increment == 0) return cpm_ram; diff --git a/plat/cpm/libsys/cpm_overwrite_ccp.s b/plat/cpm/libsys/cpm_overwrite_ccp.s new file mode 100644 index 000000000..78083b770 --- /dev/null +++ b/plat/cpm/libsys/cpm_overwrite_ccp.s @@ -0,0 +1,12 @@ +# +#include "asm.h" + +.define _cpm_overwrite_ccp +_cpm_overwrite_ccp: + mvi a, 0xaf ! 0xaf = xor a = clear carry bit + sta _cpm_exit + lhld _cpm_ramtop + lxi d, 0x800 + dad d + shld _cpm_ramtop + ret From 3fe9a05adc223a4aaabf7e68a92ce9c5fbe7ece2 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 11 Jun 2019 21:33:23 +0200 Subject: [PATCH 82/84] Ignore .vscode directory. --- .hgignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.hgignore b/.hgignore index 231210b94..de1136d12 100644 --- a/.hgignore +++ b/.hgignore @@ -1,3 +1,5 @@ .obj .sass-cache _site +.vscode + From 0607529df280c3440eb0245fefb88891d8dda950 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 11 Jun 2019 21:33:57 +0200 Subject: [PATCH 83/84] Miscellaneous bugfixed and renamings. --- plat/cpm/boot.s | 6 +++++- plat/cpm/include/cpm.h | 2 +- plat/cpm/libsys/_bdos.s | 3 +-- plat/cpm/libsys/build.lua | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plat/cpm/boot.s b/plat/cpm/boot.s index 1330e8309..4b33dbfab 100644 --- a/plat/cpm/boot.s +++ b/plat/cpm/boot.s @@ -148,8 +148,9 @@ _cpm_warmboot = 0 ! Special CP/M stuff. -.define _cpm_fcb +.define _cpm_fcb, _cpm_fcb2 _cpm_fcb = 0x005c +_cpm_fcb2 = 0x006c .define _cpm_ramtop .comm _cpm_ramtop, 2 @@ -157,6 +158,9 @@ _cpm_fcb = 0x005c .define _cpm_default_dma _cpm_default_dma = 0x0080 +.define _cpm_iobyte +_cpm_iobyte = 3 + .define _cpm_cmdlinelen, _cpm_cmdline _cpm_cmdlinelen = 0x0080 _cpm_cmdline = 0x0081 diff --git a/plat/cpm/include/cpm.h b/plat/cpm/include/cpm.h index 81dfa5dab..197ef3b10 100644 --- a/plat/cpm/include/cpm.h +++ b/plat/cpm/include/cpm.h @@ -88,7 +88,7 @@ extern void cpm_overwrite_ccp(void); /* 11 */ extern uint8_t cpm_const(void); /* 12 */ extern uint16_t cpm_get_version(void); /* 13 */ extern void cpm_reset_disk_system(void); -/* 14 */ extern void cpm_select_disk(uint8_t disk); +/* 14 */ extern void cpm_select_drive(uint8_t disk); /* 15 */ extern uint8_t cpm_open_file(FCB* fcb); /* 16 */ extern uint8_t cpm_close_file(FCB* fcb); /* 17 */ extern uint8_t cpm_findfirst(FCB* fcb); diff --git a/plat/cpm/libsys/_bdos.s b/plat/cpm/libsys/_bdos.s index 9e136925e..fd6b53de5 100644 --- a/plat/cpm/libsys/_bdos.s +++ b/plat/cpm/libsys/_bdos.s @@ -16,6 +16,5 @@ call_bdos: call 0x0005 pop b ! restore FP - mov d, h - mov e, l + xchg ! DE = HL ret \ No newline at end of file diff --git a/plat/cpm/libsys/build.lua b/plat/cpm/libsys/build.lua index f9cd9a96e..9091a6917 100644 --- a/plat/cpm/libsys/build.lua +++ b/plat/cpm/libsys/build.lua @@ -18,7 +18,7 @@ local bdos_calls = { [11] = "cpm_const", [12] = "cpm_get_version", [13] = "cpm_reset_disk_system", - [14] = "cpm_select_disk", + [14] = "cpm_select_drive", [15] = "cpm_open_file", [16] = "cpm_close_file", [17] = "cpm_findfirst", From 784fc67596efa91badc62c2b083698fb22bf7916 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 11 Jun 2019 22:33:25 +0200 Subject: [PATCH 84/84] Alignment issues mean we can't access 16-bit CP/M structure elements directly. --- plat/cpm/include/cpm.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plat/cpm/include/cpm.h b/plat/cpm/include/cpm.h index 197ef3b10..3ea9f6e09 100644 --- a/plat/cpm/include/cpm.h +++ b/plat/cpm/include/cpm.h @@ -3,6 +3,9 @@ #include +/* EM requires 2-byte alignment, even on the i80, so we can't declare these + * structures to contain uint16_ts. Use U16() to access them. */ + typedef struct { uint8_t dr; @@ -13,8 +16,7 @@ typedef struct uint8_t rc; uint8_t d[16]; uint8_t cr; - uint16_t r; - uint8_t r2; + uint8_t r[3]; } FCB; @@ -34,29 +36,27 @@ typedef struct uint8_t ex; uint8_t s[2]; uint8_t rc; - union - { - uint8_t al8[16]; - uint16_t al16[8]; - } - al; + uint8_t al[16]; } DIRE; typedef struct { - uint16_t spt; /* number of 128-byte sectors per track */ + uint8_t spt[2]; /* number of 128-byte sectors per track */ uint8_t bsh; /* block shift; 3=1kB, 4=2kB, 5=4kB etc */ uint8_t blm; /* block mask; 0x07=1kB, 0x0f=2kB, 0x1f=4k etc */ uint8_t exm; /* extent mask */ - uint16_t dsm; /* maximum block number */ - uint16_t drm; /* maximum directory entry number */ - uint16_t al; /* directory allocation bitmap */ - uint16_t cks; /* checksum vector size */ - uint16_t off; /* number of reserved tracks */ + uint8_t dsm[2]; /* maximum block number */ + uint8_t drm[2]; /* maximum directory entry number */ + uint8_t al[2]; /* directory allocation bitmap */ + uint8_t cks[2]; /* checksum vector size */ + uint8_t off[2]; /* number of reserved tracks */ } DPB; +/* Access an unaligned field (see above). */ +#define U16(ptr) (*(uint16_t*)(ptr)) + extern FCB cpm_fcb; /* primary FCB */ extern FCB cpm_fcb2; /* secondary FCB (special purpose) */ extern uint8_t cpm_iobyte;