From 15c424c54b2e0a44b72b76a935d64cfb472f8031 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Wed, 7 May 2008 22:21:27 +0000 Subject: [PATCH] * as/mcs51/asdata.c, * as/mcs51/asm.h: added org_cnt * as/mcs51/asmain.c (main, asmbl): fixed bug 1957716, changed old K&R to ANSI * as/mcs51/asout.c: changed old K&R to ANSI * as/mcs51/Makefile.in: use common identifiers * as/hc08/asdata.c, * as/hc08/asexpr.c, * as/hc08/asm.h, * as/hc08/asmain.c, * as/hc08/asout.c, * as/hc08/Makefile.bcc, * as/hc08/Makefile.in: synchronized with as/mcs51/* * sdcc_vc_in.h: added define __func__ * src/SDCCast.c (expandInlineFuncs): applied patch 1957148 to fix bug 1717305, Thanks Ruud van Silfhout * support/regression/tests/bug1717305.c: new, added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5154 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 19 + as/hc08/Makefile.bcc | 2 +- as/hc08/Makefile.in | 19 +- as/hc08/asdata.c | 226 +++++----- as/hc08/asexpr.c | 26 +- as/hc08/asm.h | 582 +++++++++++++------------- as/hc08/asmain.c | 146 +++++-- as/hc08/asout.c | 188 +++++---- as/mcs51/Makefile.in | 13 +- as/mcs51/asdata.c | 6 +- as/mcs51/asm.h | 9 +- as/mcs51/asmain.c | 36 +- as/mcs51/asout.c | 41 +- sdcc_vc_in.h | 2 + src/SDCCast.c | 20 +- support/regression/tests/bug1717305.c | 26 ++ 16 files changed, 747 insertions(+), 614 deletions(-) create mode 100644 support/regression/tests/bug1717305.c diff --git a/ChangeLog b/ChangeLog index 46880e09..cb97c511 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2008-05-07 Maarten Brock + + * as/mcs51/asdata.c, + * as/mcs51/asm.h: added org_cnt + * as/mcs51/asmain.c (main, asmbl): fixed bug 1957716, changed old K&R to ANSI + * as/mcs51/asout.c: changed old K&R to ANSI + * as/mcs51/Makefile.in: use common identifiers + * as/hc08/asdata.c, + * as/hc08/asexpr.c, + * as/hc08/asm.h, + * as/hc08/asmain.c, + * as/hc08/asout.c, + * as/hc08/Makefile.bcc, + * as/hc08/Makefile.in: synchronized with as/mcs51/* + * sdcc_vc_in.h: added define __func__ + * src/SDCCast.c (expandInlineFuncs): applied patch 1957148 to fix bug 1717305, + Thanks Ruud van Silfhout + * support/regression/tests/bug1717305.c: new, added + 2008-05-05 Borut Razem * support/regression/Makefile.in, diff --git a/as/hc08/Makefile.bcc b/as/hc08/Makefile.bcc index 0ccc0a94..b822c8d7 100644 --- a/as/hc08/Makefile.bcc +++ b/as/hc08/Makefile.bcc @@ -1,4 +1,4 @@ -# Makefile for Borlad C++ +# Makefile for Borland C++ PRJDIR = ../.. diff --git a/as/hc08/Makefile.in b/as/hc08/Makefile.in index 1c0e5b2f..97cdcd0e 100644 --- a/as/hc08/Makefile.in +++ b/as/hc08/Makefile.in @@ -57,27 +57,28 @@ ASSOURCES = $(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c) $(UTILSRC:%.c=$(UTILLIB)/%.c ASOBJECTS = $(OBJS) $(ASXXLIBOBJS) $(UTILLIBOBJS) -ASHC08 = $(top_builddir)/bin/as-hc08$(EXEEXT) +ASX = $(top_builddir)/bin/as-hc08$(EXEEXT) +DEST = $(DESTDIR)$(bindir)/as-hc08$(EXEEXT) transform = @program_transform_name@ # Compiling entire program or any subproject # ------------------------------------------ -all: checkconf $(ASHC08) +all: checkconf $(ASX) -$(ASHC08): $(ASOBJECTS) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(ASOBJECTS) +$(ASX): $(ASOBJECTS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(ASOBJECTS) -# Compiling and installing everything and runing test -# --------------------------------------------------- +# Compiling and installing everything and running test +# ---------------------------------------------------- install: all installdirs - $(INSTALL) $(ASHC08) `echo $(DESTDIR)$(bindir)/as-hc08$(EXEEXT)|sed '$(transform)'` - $(STRIP) `echo $(DESTDIR)$(bindir)/as-hc08$(EXEEXT)|sed '$(transform)'` + $(INSTALL) $(ASX) `echo $(DEST)|sed '$(transform)'` + $(STRIP) `echo $(DEST)|sed '$(transform)'` # Deleting all the installed files # -------------------------------- uninstall: - rm -f $(DESTDIR)$(bindir)/as-hc08$(EXEEXT) + rm -f $(DEST) # Performing self-test diff --git a/as/hc08/asdata.c b/as/hc08/asdata.c index 2069661d..5455398f 100644 --- a/as/hc08/asdata.c +++ b/as/hc08/asdata.c @@ -25,121 +25,123 @@ * structures, and variables used in the assembler. */ -int aserr; /* ASxxxx error counter - */ -jmp_buf jump_env; /* compiler dependent structure - * used by setjmp() and longjmp() - */ -int inpfil; /* count of assembler - * input files specified - */ -int incfil; /* current file handle index - * for include files - */ -int cfile; /* current file handle index - * of input assembly files - */ -int flevel; /* IF-ELSE-ENDIF flag will be non - * zero for false conditional case - */ -int tlevel; /* current conditional level - */ -int ifcnd[MAXIF+1]; /* array of IF statement condition - * values (0 = FALSE) indexed by tlevel - */ -int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel - * values indexed by tlevel - */ +int aserr; /* ASxxxx error counter + */ +jmp_buf jump_env; /* compiler dependent structure + * used by setjmp() and longjmp() + */ +int inpfil; /* count of assembler + * input files specified + */ +int incfil; /* current file handle index + * for include files + */ +int cfile; /* current file handle index + * of input assembly files + */ +int flevel; /* IF-ELSE-ENDIF flag will be non + * zero for false conditional case + */ +int tlevel; /* current conditional level + */ +int ifcnd[MAXIF+1]; /* array of IF statement condition + * values (0 = FALSE) indexed by tlevel + */ +int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel + * values indexed by tlevel + */ char afn[PATH_MAX]; /* afile temporary file name */ -char srcfn[MAXFIL][PATH_MAX]; /* array of source file names +char srcfn[MAXFIL][PATH_MAX];/* array of source file names */ int srcline[MAXFIL]; /* source line number */ -char incfn[MAXINC][PATH_MAX]; /* array of include file names +char incfn[MAXINC][PATH_MAX];/* array of include file names */ int incline[MAXINC]; /* include line number */ -int radix; /* current number conversion radix: - * 2 (binary), 8 (octal), 10 (decimal), - * 16 (hexadecimal) - */ -int line; /* current assembler source - * line number - */ -int page; /* current page number - */ -int lop; /* current line number on page - */ -int pass; /* assembler pass number - */ -int lflag; /* -l, generate listing flag - */ -int cflag; /* -lc, generate sdcdb debug info - */ -int gflag; /* -g, make undefined symbols global flag - */ -int aflag; /* -a, make all symbols global flag - */ -int jflag; /* -j, generate debug information flag - */ -int oflag; /* -o, generate relocatable output flag - */ -int sflag; /* -s, generate symbol table flag - */ -int pflag; /* -p, enable listing pagination - */ -int xflag; /* -x, listing radix flag - */ -int fflag; /* -f(f), relocations flagged flag - */ -Addr_T laddr; /* address of current assembler line - * or value of .if argument - */ -Addr_T fuzz; /* tracks pass to pass changes in the - * address of symbols caused by - * variable length instruction formats - */ -int lmode; /* listing mode - */ -char *ep; /* pointer into error list - * array eb[NERR] - */ -char eb[NERR]; /* array of generated error codes - */ -const char *ip; /* pointer into the assembler-source - * text line in ib[] - */ -const char *ib; /* assembler-source text line - */ -char *cp; /* pointer to assembler output - * array cb[] - */ -char cb[NCODE]; /* array of assembler output values - */ -int *cpt; /* pointer to assembler relocation type - * output array cbt[] - */ -int cbt[NCODE]; /* array of assembler relocation types - * describing the data in cb[] - */ -char tb[NTITL]; /* Title string buffer - */ -char stb[NSBTL]; /* Subtitle string buffer - */ +int radix; /* current number conversion radix: + * 2 (binary), 8 (octal), 10 (decimal), + * 16 (hexadecimal) + */ +int line; /* current assembler source + * line number + */ +int page; /* current page number + */ +int lop; /* current line number on page + */ +int pass; /* assembler pass number + */ +int org_cnt; /* .org directive counter + */ +int lflag; /* -l, generate listing flag + */ +int cflag; /* -lc, generate sdcdb debug info + */ +int gflag; /* -g, make undefined symbols global flag + */ +int aflag; /* -a, make all symbols global flag + */ +int jflag; /* -j, generate debug information flag + */ +int oflag; /* -o, generate relocatable output flag + */ +int sflag; /* -s, generate symbol table flag + */ +int pflag; /* -p, enable listing pagination + */ +int xflag; /* -x, listing radix flag + */ +int fflag; /* -f(f), relocations flagged flag + */ +Addr_T laddr; /* address of current assembler line + * or value of .if argument + */ +Addr_T fuzz; /* tracks pass to pass changes in the + * address of symbols caused by + * variable length instruction formats + */ +int lmode; /* listing mode + */ +char *ep; /* pointer into error list + * array eb[NERR] + */ +char eb[NERR]; /* array of generated error codes + */ +const char *ip; /* pointer into the assembler-source + * text line in ib[] + */ +const char *ib; /* assembler-source text line + */ +char *cp; /* pointer to assembler output + * array cb[] + */ +char cb[NCODE]; /* array of assembler output values + */ +int *cpt; /* pointer to assembler relocation type + * output array cbt[] + */ +int cbt[NCODE]; /* array of assembler relocation types + * describing the data in cb[] + */ +char tb[NTITL]; /* Title string buffer + */ +char stb[NSBTL]; /* Subtitle string buffer + */ char optsdcc[NINPUT]; /* sdcc compile options - */ -int flat24Mode; /* non-zero if we are using DS390 24 bit - * flat mode (via .flat24 directive). - */ + */ +int flat24Mode; /* non-zero if we are using DS390 24 bit + * flat mode (via .flat24 directive). + */ char symtbl[] = { "Symbol Table" }; char aretbl[] = { "Area Table" }; -char module[NCPS]; /* module name string - */ +char module[NCPS]; /* module name string + */ /* * The mne structure is a linked list of the assembler @@ -228,19 +230,19 @@ struct area area[] = { {NULL, "_CODE", 0, 0, 0, A_CON|A_REL} }; -struct area *areap; /* pointer to an area structure - */ +struct area *areap; /* pointer to an area structure + */ -FILE *lfp; /* list output file handle - */ -FILE *ofp; /* relocation output file handle - */ -FILE *tfp; /* symbol table output file handle - */ -FILE *sfp[MAXFIL]; /* array of assembler-source file handles - */ -FILE *ifp[MAXINC]; /* array of include-file file handles - */ +FILE *lfp; /* list output file handle + */ +FILE *ofp; /* relocation output file handle + */ +FILE *tfp; /* symbol table output file handle + */ +FILE *sfp[MAXFIL]; /* array of assembler-source file handles + */ +FILE *ifp[MAXINC]; /* array of include-file file handles + */ /* * array of character types, one per diff --git a/as/hc08/asexpr.c b/as/hc08/asexpr.c index 6f433940..e146a5be 100644 --- a/as/hc08/asexpr.c +++ b/as/hc08/asexpr.c @@ -1,4 +1,4 @@ - /* asexpr.c */ +/* asexpr.c */ /* * (C) Copyright 1989-1995 @@ -79,9 +79,7 @@ */ VOID -expr(esp, n) -register struct expr *esp; -int n; +expr(register struct expr *esp, int n) { register int c, p; struct area *ap; @@ -252,7 +250,7 @@ int n; */ Addr_T -absexpr() +absexpr(void) { struct expr e; @@ -308,8 +306,7 @@ absexpr() */ VOID -term(esp) -register struct expr *esp; +term(register struct expr *esp) { register int c, n; register const char *jp; @@ -541,8 +538,7 @@ register struct expr *esp; */ int -digit(c, r) -register int c, r; +digit(register int c, register int r) { if (r == 16) { if (ctype[c] & RAD16) { @@ -596,8 +592,7 @@ register int c, r; */ VOID -abscheck(esp) -register struct expr *esp; +abscheck(register struct expr *esp) { if (esp->e_flag || esp->e_base.e_ap) { esp->e_flag = 0; @@ -632,8 +627,7 @@ register struct expr *esp; */ int -is_abs (esp) -register struct expr *esp; +is_abs (register struct expr *esp) { if (esp->e_flag || esp->e_base.e_ap) { return(0); @@ -662,8 +656,7 @@ register struct expr *esp; */ int -oprio(c) -register int c; +oprio(register int c) { if (c == '*' || c == '/' || c == '%') return (10); @@ -700,8 +693,7 @@ register int c; */ VOID -clrexpr(esp) -register struct expr *esp; +clrexpr(register struct expr *esp) { esp->e_mode = 0; esp->e_flag = 0; diff --git a/as/hc08/asm.h b/as/hc08/asm.h index f6f44dba..039fcfe4 100644 --- a/as/hc08/asm.h +++ b/as/hc08/asm.h @@ -80,44 +80,58 @@ * PATH_MAX */ #include -#ifndef PATH_MAX /* POSIX, but not required */ +#ifndef PATH_MAX /* POSIX, but not required */ #if defined(_MSC_VER) || defined(__BORLANDC__) /* Microsoft C or Borland C*/ #include #define PATH_MAX _MAX_PATH #else -#define PATH_MAX /* define a reasonable value */ +#define PATH_MAX /* define a reasonable value */ #endif #endif +#ifdef _WIN32 /* WIN32 native */ + +# define NATIVE_WIN32 1 +# ifdef __MINGW32__ /* GCC MINGW32 depends on configure */ +# include "../../sdccconf.h" +# else +# include "../../sdcc_vc.h" +# define PATH_MAX _MAX_PATH +# endif + +#else /* Assume Un*x style system */ +# include "../../sdccconf.h" +#endif + /* * Assembler definitions. */ -#define LFTERM '(' /* Left expression delimeter */ -#define RTTERM ')' /* Right expression delimeter */ - -#define NCPS 80 /* Chars. per symbol (JLH: change from 8) */ -#define HUGE 1000 /* A huge number */ -#define NERR 3 /* Errors per line */ -#define NINPUT 1024 /* Input buffer size (icodes need space) */ -#define NCODE 128 /* Listing code buffer size */ -#define NTITL 64 /* Title buffer size */ -#define NSBTL 64 /* SubTitle buffer size */ -#define NHASH 64 /* Buckets in hash table */ -#define HMASK 077 /* Hash mask */ -#define NLPP 60 /* Lines per page */ -#define MAXFIL 6 /* Maximum command line input files */ -#define MAXINC 6 /* Maximum nesting of include files */ -#define MAXIF 10 /* Maximum nesting of if/else/endif */ - -#define NLIST 0 /* No listing */ -#define SLIST 1 /* Source only */ -#define ALIST 2 /* Address only */ -#define BLIST 3 /* Address only with allocation */ -#define CLIST 4 /* Code */ -#define ELIST 5 /* Equate only */ - -#define dot sym[0] /* Dot, current loc */ -#define dca area[0] /* Dca, default code area */ +#define LFTERM '(' /* Left expression delimeter */ +#define RTTERM ')' /* Right expression delimeter */ + +#define NCPS 80 /* Chars. per symbol (JLH: change from 8) */ +#define HUGE 1000 /* A huge number */ +#define NERR 3 /* Errors per line */ +#define NINPUT 1024 /* Input buffer size (icodes need space) */ +#define NCODE 128 /* Listing code buffer size */ +#define NTITL 64 /* Title buffer size */ +#define NSBTL 64 /* SubTitle buffer size */ +#define NHASH 64 /* Buckets in hash table */ +#define HMASK 077 /* Hash mask */ +#define NLPP 60 /* Lines per page */ +#define MAXFIL 6 /* Maximum command line input files */ +#define MAXINC 6 /* Maximum nesting of include files */ +#define MAXIF 10 /* Maximum nesting of if/else/endif */ + +#define NLIST 0 /* No listing */ +#define SLIST 1 /* Source only */ +#define ALIST 2 /* Address only */ +#define BLIST 3 /* Address only with allocation */ +#define CLIST 4 /* Code */ +#define ELIST 5 /* Equate only */ + +#define dot sym[0] /* Dot, current loc */ +#define dca area[0] /* Dca, default code area */ /* NB: for Flat24 extentions to work, Addr_T must be at least 24 @@ -142,13 +156,13 @@ typedef unsigned int Addr_T; */ struct area { - struct area *a_ap; /* Area link */ - char a_id[NCPS]; /* Area Name */ - int a_ref; /* Ref. number */ - Addr_T a_addr; /* Area address */ - Addr_T a_size; /* Area size */ - Addr_T a_fuzz; /* Area fuzz */ - int a_flag; /* Area flags */ + struct area *a_ap; /* Area link */ + char a_id[NCPS]; /* Area Name */ + int a_ref; /* Ref. number */ + Addr_T a_addr; /* Area address */ + Addr_T a_size; /* Area size */ + Addr_T a_fuzz; /* Area fuzz */ + int a_flag; /* Area flags */ }; /* @@ -163,21 +177,21 @@ struct area * +-----+-----+-----+-----+-----+-----+-----+-----+ */ -#define A_CON 0000 /* Concatenating */ -#define A_OVR 0004 /* Overlaying */ -#define A_REL 0000 /* Relocatable */ -#define A_ABS 0010 /* absolute */ -#define A_NOPAG 0000 /* Non-Paged */ -#define A_PAG 0020 /* Paged */ +#define A_CON 0000 /* Concatenating */ +#define A_OVR 0004 /* Overlaying */ +#define A_REL 0000 /* Relocatable */ +#define A_ABS 0010 /* absolute */ +#define A_NOPAG 0000 /* Non-Paged */ +#define A_PAG 0020 /* Paged */ /* Additional flags for 8051 address spaces */ -#define A_DATA 0000 /* data space (default)*/ -#define A_CODE 0040 /* code space */ -#define A_XDATA 0100 /* external data space */ -#define A_BIT 0200 /* bit addressable space */ +#define A_DATA 0000 /* data space (default)*/ +#define A_CODE 0040 /* code space */ +#define A_XDATA 0100 /* external data space */ +#define A_BIT 0200 /* bit addressable space */ -#define A_NOLOAD 0400 /* nonloadable */ -#define A_LOAD 0000 /* loadable (default) */ +#define A_NOLOAD 0400 /* nonloadable */ +#define A_LOAD 0000 /* loadable (default) */ /* * The "R_" relocation constants define values used in @@ -192,64 +206,64 @@ struct area * +-----+-----+-----+-----+-----+-----+-----+-----+ */ -#define R_WORD 0x00 /* 16 bit */ -#define R_BYTE 0x01 /* 8 bit */ +#define R_WORD 0x00 /* 16 bit */ +#define R_BYTE 0x01 /* 8 bit */ -#define R_AREA 0x00 /* Base type */ +#define R_AREA 0x00 /* Base type */ #define R_SYM 0x02 -#define R_NORM 0x00 /* PC adjust */ +#define R_NORM 0x00 /* PC adjust */ #define R_PCR 0x04 -#define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */ -#define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */ +#define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */ +#define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */ -#define R_SGND 0x00 /* Signed Byte */ -#define R_USGN 0x10 /* Unsigned Byte */ +#define R_SGND 0x00 /* Signed Byte */ +#define R_USGN 0x10 /* Unsigned Byte */ -#define R_NOPAG 0x00 /* Page Mode */ -#define R_PAG0 0x20 /* Page '0' */ -#define R_PAG 0x40 /* Page 'nnn' */ +#define R_NOPAG 0x00 /* Page Mode */ +#define R_PAG0 0x20 /* Page '0' */ +#define R_PAG 0x40 /* Page 'nnn' */ -#define R_LSB 0x00 /* low byte */ -#define R_MSB 0x80 /* high byte */ +#define R_LSB 0x00 /* low byte */ +#define R_MSB 0x80 /* high byte */ -#define R_BYT3 0x100 /* if R_BYTE is set, this is a - * 3 byte address, of which - * the linker must select one byte. - */ -#define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker - * will select byte 3 of the relocated - * 24 bit address. - */ +#define R_BYT3 0x100 /* if R_BYTE is set, this is a + * 3 byte address, of which + * the linker must select one byte. + */ +#define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker + * will select byte 3 of the relocated + * 24 bit address. + */ -#define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */ -#define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */ -#define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */ +#define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */ +#define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */ +#define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */ #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB) #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19) #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11) #define IS_C24(x) (((x) & R_J19_MASK) == R_C24) -#define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes - * greater than 0xff in the .rel - * file. - */ +#define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes + * greater than 0xff in the .rel + * file. + */ /* * Listing Control Flags */ -#define R_HIGH 0040000 /* High Byte */ -#define R_RELOC 0100000 /* Relocation */ +#define R_HIGH 0040000 /* High Byte */ +#define R_RELOC 0100000 /* Relocation */ -#define R_DEF 00 /* Global def. */ -#define R_REF 01 /* Global ref. */ -#define R_REL 00 /* Relocatable */ -#define R_ABS 02 /* Absolute */ -#define R_GBL 00 /* Global */ -#define R_LCL 04 /* Local */ +#define R_DEF 00 /* Global def. */ +#define R_REF 01 /* Global ref. */ +#define R_REL 00 /* Relocatable */ +#define R_ABS 02 /* Absolute */ +#define R_GBL 00 /* Global */ +#define R_LCL 04 /* Local */ /* * The mne structure is a linked list of the assembler @@ -266,11 +280,11 @@ struct area */ struct mne { - struct mne *m_mp; /* Hash link */ - char *m_id; /* Mnemonic JLH: change from [NCPS] */ - char m_type; /* Mnemonic subtype */ - char m_flag; /* Mnemonic flags */ - Addr_T m_valu; /* Value */ + struct mne *m_mp; /* Hash link */ + char *m_id; /* Mnemonic JLH: change from [NCPS] */ + char m_type; /* Mnemonic subtype */ + char m_flag; /* Mnemonic flags */ + Addr_T m_valu; /* Value */ }; /* @@ -288,54 +302,54 @@ struct mne */ struct sym { - struct sym *s_sp; /* Hash link */ - struct tsym *s_tsym; /* Temporary symbol link */ - char *s_id; /* Symbol: JLH change from [NCPS] */ - char s_type; /* Symbol subtype */ - char s_flag; /* Symbol flags */ - struct area *s_area; /* Area line, 0 if absolute */ - int s_ref; /* Ref. number */ - Addr_T s_addr; /* Address */ - Addr_T s_org; /* Start Address if absolute */ + struct sym *s_sp; /* Hash link */ + struct tsym *s_tsym; /* Temporary symbol link */ + char *s_id; /* Symbol: JLH change from [NCPS] */ + char s_type; /* Symbol subtype */ + char s_flag; /* Symbol flags */ + struct area *s_area; /* Area line, 0 if absolute */ + int s_ref; /* Ref. number */ + Addr_T s_addr; /* Address */ + Addr_T s_org; /* Start Address if absolute */ }; -#define S_GBL 01 /* Global */ -#define S_ASG 02 /* Assigned */ -#define S_MDF 04 /* Mult. def */ -#define S_END 010 /* End mark for pst. */ - -#define S_NEW 0 /* New name */ -#define S_USER 1 /* User name */ - /* unused slot */ - /* unused slot */ - /* unused slot */ - -#define S_BYTE 5 /* .byte */ -#define S_WORD 6 /* .word */ -#define S_ASCII 7 /* .ascii */ -#define S_ASCIZ 8 /* .asciz */ -#define S_BLK 9 /* .blkb or .blkw */ -#define S_INCL 10 /* .include */ -#define S_DAREA 11 /* .area */ -#define S_ATYP 12 /* .area type */ -#define S_AREA 13 /* .area name */ -#define S_GLOBL 14 /* .globl */ -#define S_PAGE 15 /* .page */ -#define S_TITLE 16 /* .title */ -#define S_SBTL 17 /* .sbttl */ -#define S_IF 18 /* .if */ -#define S_ELSE 19 /* .else */ -#define S_ENDIF 20 /* .endif */ -#define S_EVEN 21 /* .even */ -#define S_ODD 22 /* .odd */ -#define S_RADIX 23 /* .radix */ -#define S_ORG 24 /* .org */ -#define S_MODUL 25 /* .module */ -#define S_ASCIS 26 /* .ascis */ -#define S_FLAT24 27 /* .flat24 */ -#define S_OPTSDCC 28 /* .optsdcc */ -#define S_ULEB128 29 /* .uleb128 */ -#define S_SLEB128 30 /* .sleb128 */ +#define S_GBL 01 /* Global */ +#define S_ASG 02 /* Assigned */ +#define S_MDF 04 /* Mult. def */ +#define S_END 010 /* End mark for pst. */ + +#define S_NEW 0 /* New name */ +#define S_USER 1 /* User name */ + /* unused slot */ + /* unused slot */ + /* unused slot */ + +#define S_BYTE 5 /* .byte */ +#define S_WORD 6 /* .word */ +#define S_ASCII 7 /* .ascii */ +#define S_ASCIZ 8 /* .asciz */ +#define S_BLK 9 /* .blkb or .blkw */ +#define S_INCL 10 /* .include */ +#define S_DAREA 11 /* .area */ +#define S_ATYP 12 /* .area type */ +#define S_AREA 13 /* .area name */ +#define S_GLOBL 14 /* .globl */ +#define S_PAGE 15 /* .page */ +#define S_TITLE 16 /* .title */ +#define S_SBTL 17 /* .sbttl */ +#define S_IF 18 /* .if */ +#define S_ELSE 19 /* .else */ +#define S_ENDIF 20 /* .endif */ +#define S_EVEN 21 /* .even */ +#define S_ODD 22 /* .odd */ +#define S_RADIX 23 /* .radix */ +#define S_ORG 24 /* .org */ +#define S_MODUL 25 /* .module */ +#define S_ASCIS 26 /* .ascis */ +#define S_FLAT24 27 /* .flat24 */ +#define S_OPTSDCC 28 /* .optsdcc */ +#define S_ULEB128 29 /* .uleb128 */ +#define S_SLEB128 30 /* .sleb128 */ /* * The tsym structure is a linked list of temporary @@ -349,170 +363,172 @@ struct sym */ struct tsym { - struct tsym *t_lnk; /* Link to next */ + struct tsym *t_lnk; /* Link to next */ /* sandeep changed to 'int' from 'char' */ /* this will increase the number temp symbols that can be defined from 255 to INT_MAX */ - int t_num; /* 0-INT_MAX$ */ - int t_flg; /* flags */ + int t_num; /* 0-INT_MAX$ */ + int t_flg; /* flags */ - struct area *t_area; /* Area */ - Addr_T t_addr; /* Address */ + struct area *t_area; /* Area */ + Addr_T t_addr; /* Address */ }; /* * External Definitions for all Global Variables */ -extern int aserr; /* ASxxxx error counter - */ -extern jmp_buf jump_env; /* compiler dependent structure - * used by setjmp() and longjmp() - */ -extern int inpfil; /* count of assembler - * input files specified - */ -extern int incfil; /* current file handle index - * for include files - */ -extern int cfile; /* current file handle index - * of input assembly files - */ -extern int flevel; /* IF-ELSE-ENDIF flag will be non - * zero for false conditional case - */ -extern int tlevel; /* current conditional level - */ -extern int ifcnd[MAXIF+1]; /* array of IF statement condition - * values (0 = FALSE) indexed by tlevel - */ -extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel - * values indexed by tlevel - */ +extern int aserr; /* ASxxxx error counter + */ +extern jmp_buf jump_env; /* compiler dependent structure + * used by setjmp() and longjmp() + */ +extern int inpfil; /* count of assembler + * input files specified + */ +extern int incfil; /* current file handle index + * for include files + */ +extern int cfile; /* current file handle index + * of input assembly files + */ +extern int flevel; /* IF-ELSE-ENDIF flag will be non + * zero for false conditional case + */ +extern int tlevel; /* current conditional level + */ +extern int ifcnd[MAXIF+1]; /* array of IF statement condition + * values (0 = FALSE) indexed by tlevel + */ +extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel + * values indexed by tlevel + */ extern char - afn[PATH_MAX]; /* afile() temporary filespec - */ + afn[PATH_MAX]; /* afile() temporary filespec + */ extern char srcfn[MAXFIL][PATH_MAX]; /* array of source file names - */ + */ extern int - srcline[MAXFIL]; /* current source file line - */ + srcline[MAXFIL]; /* current source file line + */ extern char incfn[MAXINC][PATH_MAX]; /* array of include file names - */ + */ extern int - incline[MAXINC]; /* current include file line - */ -extern int radix; /* current number conversion radix: - * 2 (binary), 8 (octal), 10 (decimal), - * 16 (hexadecimal) - */ -extern int line; /* current assembler source - * line number - */ -extern int page; /* current page number - */ -extern int lop; /* current line number on page - */ -extern int pass; /* assembler pass number - */ -extern int lflag; /* -l, generate listing flag - */ -extern int cflag; /* -c, generate sdcdb debug information - */ -extern int gflag; /* -g, make undefined symbols global flag - */ -extern int aflag; /* -a, make all symbols global flag - */ -extern int jflag; /* -j, generate debug information flag - */ -extern int oflag; /* -o, generate relocatable output flag - */ -extern int sflag; /* -s, generate symbol table flag - */ -extern int pflag; /* -p, enable listing pagination - */ -extern int xflag; /* -x, listing radix flag - */ -extern int fflag; /* -f(f), relocations flagged flag - */ -extern Addr_T laddr; /* address of current assembler line - * or value of .if argument - */ -extern Addr_T fuzz; /* tracks pass to pass changes in the - * address of symbols caused by - * variable length instruction formats - */ -extern int lmode; /* listing mode - */ -extern struct area area[]; /* array of 1 area - */ -extern struct area *areap; /* pointer to an area structure - */ -extern struct sym sym[]; /* array of 1 symbol - */ -extern struct sym *symp; /* pointer to a symbol structure - */ -extern struct sym *symhash[NHASH]; /* array of pointers to NHASH - * linked symbol lists - */ -extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH - * linked mnemonic/directive lists - */ -extern char *ep; /* pointer into error list - * array eb[NERR] - */ -extern char eb[NERR]; /* array of generated error codes - */ -extern const char *ip; /* pointer into the assembler-source - * text line in ib[] - */ -extern const char *ib; /* assembler-source text line - */ -extern char *cp; /* pointer to assembler output - * array cb[] - */ -extern char cb[NCODE]; /* array of assembler output values - */ -extern int *cpt; /* pointer to assembler relocation type - * output array cbt[] - */ -extern int cbt[NCODE]; /* array of assembler relocation types - * describing the data in cb[] - */ -extern char tb[NTITL]; /* Title string buffer - */ -extern char stb[NSBTL]; /* Subtitle string buffer - */ + incline[MAXINC]; /* current include file line + */ +extern int radix; /* current number conversion radix: + * 2 (binary), 8 (octal), 10 (decimal), + * 16 (hexadecimal) + */ +extern int line; /* current assembler source + * line number + */ +extern int page; /* current page number + */ +extern int lop; /* current line number on page + */ +extern int pass; /* assembler pass number + */ +extern int org_cnt; /* .org directive counter + */ +extern int lflag; /* -l, generate listing flag + */ +extern int cflag; /* -c, generate sdcdb debug information + */ +extern int gflag; /* -g, make undefined symbols global flag + */ +extern int aflag; /* -a, make all symbols global flag + */ +extern int jflag; /* -j, generate debug information flag + */ +extern int oflag; /* -o, generate relocatable output flag + */ +extern int sflag; /* -s, generate symbol table flag + */ +extern int pflag; /* -p, enable listing pagination + */ +extern int xflag; /* -x, listing radix flag + */ +extern int fflag; /* -f(f), relocations flagged flag + */ +extern Addr_T laddr; /* address of current assembler line + * or value of .if argument + */ +extern Addr_T fuzz; /* tracks pass to pass changes in the + * address of symbols caused by + * variable length instruction formats + */ +extern int lmode; /* listing mode + */ +extern struct area area[]; /* array of 1 area + */ +extern struct area *areap; /* pointer to an area structure + */ +extern struct sym sym[]; /* array of 1 symbol + */ +extern struct sym *symp; /* pointer to a symbol structure + */ +extern struct sym *symhash[NHASH]; /* array of pointers to NHASH + * linked symbol lists + */ +extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH + * linked mnemonic/directive lists + */ +extern char *ep; /* pointer into error list + * array eb[NERR] + */ +extern char eb[NERR]; /* array of generated error codes + */ +extern const char *ip; /* pointer into the assembler-source + * text line in ib[] + */ +extern const char *ib; /* assembler-source text line + */ +extern char *cp; /* pointer to assembler output + * array cb[] + */ +extern char cb[NCODE]; /* array of assembler output values + */ +extern int *cpt; /* pointer to assembler relocation type + * output array cbt[] + */ +extern int cbt[NCODE]; /* array of assembler relocation types + * describing the data in cb[] + */ +extern char tb[NTITL]; /* Title string buffer + */ +extern char stb[NSBTL]; /* Subtitle string buffer + */ extern char optsdcc[NINPUT]; /* sdcc compile options - */ -extern int flat24Mode; /* non-zero if we are using DS390 24 bit - * flat mode (via .flat24 directive). - */ -extern char symtbl[]; /* string "Symbol Table" - */ -extern char aretbl[]; /* string "Area Table" - */ -extern char module[NCPS]; /* module name string - */ -extern FILE *lfp; /* list output file handle - */ -extern FILE *ofp; /* relocation output file handle - */ -extern FILE *tfp; /* symbol table output file handle - */ -extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles - */ -extern FILE *ifp[MAXINC]; /* array of include-file file handles - */ + */ +extern int flat24Mode; /* non-zero if we are using DS390 24 bit + * flat mode (via .flat24 directive). + */ +extern char symtbl[]; /* string "Symbol Table" + */ +extern char aretbl[]; /* string "Area Table" + */ +extern char module[NCPS]; /* module name string + */ +extern FILE *lfp; /* list output file handle + */ +extern FILE *ofp; /* relocation output file handle + */ +extern FILE *tfp; /* symbol table output file handle + */ +extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles + */ +extern FILE *ifp[MAXINC]; /* array of include-file file handles + */ extern unsigned char ctype[128]; /* array of character types, one per - * ASCII character - */ + * ASCII character + */ -extern char ccase[128]; /* an array of characters which - * perform the case translation function - */ +extern char ccase[128]; /* an array of characters which + * perform the case translation function + */ /* * Definitions for Character Types */ @@ -550,14 +566,14 @@ extern char ccase[128]; /* an array of characters which */ struct expr { - char e_mode; /* Address mode */ - char e_flag; /* Symbol flag */ - Addr_T e_addr; /* Address */ + char e_mode; /* Address mode */ + char e_flag; /* Symbol flag */ + Addr_T e_addr; /* Address */ union { struct area *e_ap; struct sym *e_sp; - } e_base; /* Rel. base */ - int e_rlcf; /* Rel. flags */ + } e_base; /* Rel. base */ + int e_rlcf; /* Rel. flags */ }; /* C Library functions */ diff --git a/as/hc08/asmain.c b/as/hc08/asmain.c index ae5503f5..0de7a752 100644 --- a/as/hc08/asmain.c +++ b/as/hc08/asmain.c @@ -11,6 +11,7 @@ * 29-Oct-97 JLH pass ";!" comments to output file */ +#include #include #include #include @@ -37,6 +38,67 @@ * references the usage text strings printed by usage(). */ +static const char *search_path[100]; +static int search_path_length; + +/** + * The search_path_append is used to append another directory to the end + * of the include file search path. + * + * @param dir + * The directory to be added to the path. + */ +void +search_path_append(const char *dir) +{ + if (search_path_length < sizeof(search_path)/sizeof(char*)) + { + search_path[search_path_length++] = dir; + } +} + +/** + * The search_path_fopen function is used to open the named file. If + * the file isn't in the current directory, the search path is then used + * to build a series of possible file names, and attempts to open them. + * The first found is used. + * + * @param filename + * The name of the file to be opened. + * @param mode + * The mode of the file to be opened. + * @returns + * what the fopen function would return on success, or NULL if the + * file is not anywhere in the search path. + */ +static FILE * +search_path_fopen(const char *filename, const char *mode) +{ + FILE *fp; + int j; + + fp = fopen(filename, mode); + if (fp != NULL || filename[0] == '/' || filename[0] == '\\') + return fp; + for (j = 0; j < search_path_length; ++j) + { + char path[2000]; + + strncpy(path, search_path[j], sizeof(path)); + if ((path[strlen(path) - 1] != '/') && + (path[strlen(path) - 1] != DIR_SEPARATOR_CHAR)) + { + strncat(path, DIR_SEPARATOR_STRING, sizeof(path)); + } + strncat(path, filename, sizeof(path)); + fp = fopen(path, mode); + if (fp != NULL) + return fp; + } + errno = ENOENT; + return NULL; +} + /*)Function VOID main(argc, argv) * * int argc argument count @@ -151,8 +213,7 @@ int fatalErrors=0; char relFile[128]; int -main(argc, argv) -char *argv[]; +main(int argc, char *argv[]) { register char *p; register int c, i; @@ -177,14 +238,21 @@ char *argv[]; case 'c': case 'C': - ++cflag; - break; + ++cflag; + break; case 'g': case 'G': ++gflag; break; + case 'i': + case 'I': + search_path_append(p); + while (*p) + ++p; + break; + case 'j': /* JLH: debug info */ case 'J': ++jflag; @@ -245,9 +313,9 @@ char *argv[]; if (lflag) lfp = afile(p, "lst", 1); if (oflag) { - ofp = afile(p, "rel", 1); - // save the file name if we have to delete it on error - strcpy(relFile,afn); + ofp = afile(p, "rel", 1); + // save the file name if we have to delete it on error + strcpy(relFile,afn); } if (sflag) tfp = afile(p, "sym", 1); @@ -271,6 +339,7 @@ char *argv[]; radix = 10; srcline[0] = 0; page = 0; + org_cnt = 0; stb[0] = 0; lop = NLPP; cfile = 0; @@ -355,8 +424,7 @@ char *argv[]; */ VOID -asexit(i) -int i; +asexit(int i) { int j; @@ -469,7 +537,7 @@ int i; */ VOID -asmbl() +asmbl(void) { register struct mne *mp; register struct sym *sp; @@ -482,6 +550,7 @@ asmbl() char fn[PATH_MAX]; char *p; int d, n, uaf, uf; + static struct area *abs_ap; /* pointer to current absolute area structure */ laddr = dot.s_addr; lmode = SLIST; @@ -841,7 +910,7 @@ loop: lmode = SLIST; break; - case S_OPTSDCC: + case S_OPTSDCC: p = optsdcc; if ((c = getnb()) != 0) { do { @@ -852,8 +921,8 @@ loop: *p = 0; unget(c); lmode = SLIST; - /*if (pass == 0) printf("optsdcc=%s\n", optsdcc);*/ - break; + /*if (pass == 0) printf("optsdcc=%s\n", optsdcc);*/ + break; case S_GLOBL: do { @@ -901,17 +970,32 @@ loop: } newdot(ap); lmode = SLIST; + if (dot.s_area->a_flag & A_ABS) + abs_ap = ap; break; case S_ORG: if (dot.s_area->a_flag & A_ABS) { - outall(); - laddr = dot.s_addr = dot.s_org = absexpr(); + char buf[NCPS]; + + laddr = absexpr(); + sprintf(buf, "%s%x", abs_ap->a_id, org_cnt++); + if ((ap = alookup(buf)) == NULL) { + ap = (struct area *) new (sizeof(struct area)); + *ap = *areap; + ap->a_ap = areap; + strncpy(ap->a_id, buf, NCPS); + ap->a_ref = areap->a_ref + 1; + ap->a_size = 0; + ap->a_fuzz = 0; + areap = ap; + } + newdot(ap); + lmode = ALIST; + dot.s_addr = dot.s_org = laddr; } else { err('o'); } - outall(); - lmode = ALIST; break; case S_RADIX: @@ -961,7 +1045,7 @@ loop: } *p = 0; if ((++incfil == MAXINC) || - (ifp[incfil] = fopen(fn, "r")) == NULL) { + (ifp[incfil] = search_path_fopen(fn, "r")) == NULL) { --incfil; err('i'); } else { @@ -1079,10 +1163,7 @@ loop: */ FILE * -afile(fn, ft, wf) -char *fn; -char *ft; -int wf; +afile(char *fn, char *ft, int wf) { register char *p2, *p3; register int c; @@ -1150,8 +1231,7 @@ int wf; */ VOID -newdot(nap) -register struct area *nap; +newdot(register struct area *nap) { register struct area *oap; @@ -1166,7 +1246,8 @@ register struct area *nap; } } else if (oap->a_flag & A_ABS) { oap->a_addr = dot.s_org; - oap->a_size = dot.s_addr - dot.s_org; + oap->a_size += dot.s_addr - dot.s_org; + dot.s_addr = dot.s_org = 0; } else { oap->a_addr = 0; oap->a_size = dot.s_addr; @@ -1175,6 +1256,10 @@ register struct area *nap; // a new overlay starts at 0, no fuzz dot.s_addr = 0; fuzz = 0; + } else if (nap->a_flag & A_ABS) { + // a new absolute starts at org, no fuzz + dot.s_addr = dot.s_org; + fuzz = 0; } else { dot.s_addr = nap->a_size; fuzz = nap->a_fuzz; @@ -1208,16 +1293,14 @@ register struct area *nap; */ VOID -phase(ap, a) -struct area *ap; -Addr_T a; +phase(struct area *ap, Addr_T a) { if (ap != dot.s_area || a != dot.s_addr) err('p'); } char *usetxt[] = { - "Usage: [-dqxjgalopsf] file1 [file2 file3 ...]", + "Usage: [-dqxjgalopsf][ -I ] file1 [file2 file3 ...]", " d decimal listing", " q octal listing", " x hex listing (default)", @@ -1231,6 +1314,9 @@ char *usetxt[] = { " p disable listing pagination", " f flag relocatable references by ` in listing file", " ff flag relocatable references by mode in listing file", + "-I Add the named directory to the include file", + " search path. This option may be used more than once.", + " Directories are searched in the order given.", "", 0 }; @@ -1257,7 +1343,7 @@ char *usetxt[] = { */ VOID -usage() +usage(void) { register char **dp; diff --git a/as/hc08/asout.c b/as/hc08/asout.c index f5b731f5..6ffbae45 100644 --- a/as/hc08/asout.c +++ b/as/hc08/asout.c @@ -231,7 +231,7 @@ char *relp = { &rel[0] }; */ VOID -outab(b) +outab(int b) { if (pass == 2) { out_lb(b,0); @@ -266,7 +266,7 @@ outab(b) */ VOID -outaw(w) +outaw(int w) { if (pass == 2) { out_lw(w,0); @@ -656,9 +656,7 @@ outr24(struct expr *esp, int r) */ VOID -outdp(carea, esp) -register struct area *carea; -register struct expr *esp; +outdp(register struct area *carea, register struct expr *esp) { register int n, r; @@ -703,7 +701,7 @@ register struct expr *esp; */ VOID -outall() +outall(void) { if (oflag && pass==2) outbuf("R"); @@ -731,7 +729,7 @@ outall() */ VOID -outdot() +outdot(void) { if (oflag && pass==2) { fprintf(ofp, "T"); @@ -771,7 +769,7 @@ outdot() */ VOID -outchk(nt, nr) +outchk(int nt, int nr) { register struct area *ap; @@ -812,8 +810,7 @@ outchk(nt, nr) */ VOID -outbuf(s) -char *s; +outbuf(char *s) { if (txtp > &txt[2]) { fprintf(ofp, "T"); @@ -870,7 +867,7 @@ char *s; */ VOID -outgsd() +outgsd(void) { register struct area *ap; register struct sym *sp; @@ -991,8 +988,7 @@ outgsd() */ VOID -outarea(ap) -register struct area *ap; +outarea(register struct area *ap) { register char *ptr; register int c; @@ -1039,8 +1035,7 @@ register struct area *ap; */ VOID -outsym(sp) -register struct sym *sp; +outsym(register struct sym *sp) { register char *ptr; @@ -1121,8 +1116,7 @@ out(char *p, int n) */ VOID -out_lb(b,t) -register int b,t; +out_lb(register int b, register int t) { if (cp < &cb[NCODE]) { *cp++ = b; @@ -1154,8 +1148,7 @@ register int b,t; */ VOID -out_lw(n,t) -register int n,t; +out_lw(register int n, register int t) { if (hilo) { out_lb(hibyte(n),t ? t|R_HIGH : 0); @@ -1225,8 +1218,7 @@ out_l24(int n, int t) */ VOID -out_rw(n) -register int n; +out_rw(register int n) { if (hilo) { *relp++ = hibyte(n); @@ -1259,8 +1251,7 @@ register int n; */ VOID -out_tw(n) -register int n; +out_tw(register int n) { if (hilo) { *txtp++ = hibyte(n); @@ -1327,7 +1318,7 @@ out_t24(int n) */ int -lobyte(n) +lobyte(int n) { return (n&0377); } @@ -1353,7 +1344,7 @@ lobyte(n) */ int -hibyte(n) +hibyte(int n) { return ((n>>8)&0377); } @@ -1390,44 +1381,51 @@ byte3(int n) * 11 bit address. This form of address is used only on the 8051 and 8048. */ VOID -outr11(esp, op, r) -register struct expr *esp; -int op; -int r; +outr11(register struct expr *esp, int op, int r) { - register int n; - - if (pass == 2) { - if (esp->e_flag==0 && esp->e_base.e_ap==NULL) { - /* equated absolute destination. Assume value - * relative to current area */ - esp->e_base.e_ap = dot.s_area; - } - - /* Relocatable destination. Build THREE - * byte output: relocatable word, followed - * by op-code. Linker will combine them. - * Listing shows only the address. - */ - r |= R_WORD | esp->e_rlcf; - out_lw(esp->e_addr,r|R_RELOC); - if (oflag) { - outchk(3, 5); - out_tw(esp->e_addr); - *txtp++ = op; - - if (esp->e_flag) { - n = esp->e_base.e_sp->s_ref; - r |= R_SYM; - } else { - n = esp->e_base.e_ap->a_ref; + register int n; + + if (pass == 2) { + if (esp->e_flag==0 && esp->e_base.e_ap==NULL) { + /* Absolute destination. + * Listing shows only the address. + */ + out_lw(esp->e_addr,0); + if (oflag) { + outchk(3, 0); + out_tw(esp->e_addr); + *txtp++ = op; + + write_rmode(r); + *relp++ = txtp - txt - 3; + out_rw(0xFFFF); + } + } else { + /* Relocatable destination. Build THREE + * byte output: relocatable word, followed + * by op-code. Linker will combine them. + * Listing shows only the address. + */ + r |= R_WORD | esp->e_rlcf; + out_lw(esp->e_addr,r|R_RELOC); + if (oflag) { + outchk(3, 5); + out_tw(esp->e_addr); + *txtp++ = op; + + if (esp->e_flag) { + n = esp->e_base.e_sp->s_ref; + r |= R_SYM; + } else { + n = esp->e_base.e_ap->a_ref; + } + write_rmode(r); + *relp++ = txtp - txt - 3; + out_rw(n); } - write_rmode(r); - *relp++ = txtp - txt - 3; - out_rw(n); } - } - dot.s_addr += 2; + } + dot.s_addr += 2; } /* @@ -1440,37 +1438,47 @@ int r; VOID outr19(struct expr * esp, int op, int r) { - register int n; - - if (pass == 2) { - if (esp->e_flag==0 && esp->e_base.e_ap==NULL) { - /* equated absolute destination. Assume value - * relative to current area */ - esp->e_base.e_ap = dot.s_area; - } - - /* Relocatable destination. Build FOUR - * byte output: relocatable 24-bit entity, followed - * by op-code. Linker will combine them. - * Listing shows only the address. - */ - r |= R_WORD | esp->e_rlcf; - out_l24(esp->e_addr,r|R_RELOC); - if (oflag) { - outchk(4, 5); - out_t24(esp->e_addr); - *txtp++ = op; + register int n; + + if (pass == 2) { + if (esp->e_flag==0 && esp->e_base.e_ap==NULL) { + /* Absolute destination. + * Listing shows only the address. + */ + out_lw(esp->e_addr,0); + if (oflag) { + outchk(4, 0); + out_t24(esp->e_addr); + *txtp++ = op; + + write_rmode(r); + *relp++ = txtp - txt - 4; + out_rw(0xFFFF); + } + } else { + /* Relocatable destination. Build FOUR + * byte output: relocatable 24-bit entity, followed + * by op-code. Linker will combine them. + * Listing shows only the address. + */ + r |= R_WORD | esp->e_rlcf; + out_l24(esp->e_addr,r|R_RELOC); + if (oflag) { + outchk(4, 5); + out_t24(esp->e_addr); + *txtp++ = op; - if (esp->e_flag) { - n = esp->e_base.e_sp->s_ref; - r |= R_SYM; - } else { - n = esp->e_base.e_ap->a_ref; + if (esp->e_flag) { + n = esp->e_base.e_sp->s_ref; + r |= R_SYM; + } else { + n = esp->e_base.e_ap->a_ref; + } + write_rmode(r); + *relp++ = txtp - txt - 4; + out_rw(n); } - write_rmode(r); - *relp++ = txtp - txt - 4; - out_rw(n); } - } - dot.s_addr += 3; + } + dot.s_addr += 3; } diff --git a/as/mcs51/Makefile.in b/as/mcs51/Makefile.in index efcdd5d6..3cd5b2f1 100644 --- a/as/mcs51/Makefile.in +++ b/as/mcs51/Makefile.in @@ -57,27 +57,28 @@ ASSOURCES = $(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c) $(UTILSRC:%.c=$(UTILLIB)/%.c ASOBJECTS = $(OBJS) $(ASXXLIBOBJS) $(UTILLIBOBJS) -ASX8051 = $(top_builddir)/bin/asx8051$(EXEEXT) +ASX = $(top_builddir)/bin/asx8051$(EXEEXT) +DEST = $(DESTDIR)$(bindir)/asx8051$(EXEEXT) transform = @program_transform_name@ # Compiling entire program or any subproject # ------------------------------------------ -all: checkconf $(ASX8051) +all: checkconf $(ASX) -$(ASX8051): $(ASOBJECTS) +$(ASX): $(ASOBJECTS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(ASOBJECTS) # Compiling and installing everything and running test # ---------------------------------------------------- install: all installdirs - $(INSTALL) $(ASX8051) `echo $(DESTDIR)$(bindir)/asx8051$(EXEEXT)|sed '$(transform)'` - $(STRIP) `echo $(DESTDIR)$(bindir)/asx8051$(EXEEXT)|sed '$(transform)'` + $(INSTALL) $(ASX) `echo $(DEST)|sed '$(transform)'` + $(STRIP) `echo $(DEST)|sed '$(transform)'` # Deleting all the installed files # -------------------------------- uninstall: - rm -f $(DESTDIR)$(bindir)/asx8051$(EXEEXT) + rm -f $(DEST) # Performing self-test diff --git a/as/mcs51/asdata.c b/as/mcs51/asdata.c index 4a9dfdc0..8af9a419 100644 --- a/as/mcs51/asdata.c +++ b/as/mcs51/asdata.c @@ -72,9 +72,11 @@ int line; /* current assembler source int page; /* current page number */ int lop; /* current line number on page - */ + */ int pass; /* assembler pass number */ +int org_cnt; /* .org directive counter + */ int lflag; /* -l, generate listing flag */ int cflag; /* -lc, generate sdcdb debug info @@ -129,7 +131,7 @@ char tb[NTITL]; /* Title string buffer */ char stb[NSBTL]; /* Subtitle string buffer */ -char optsdcc[NINPUT]; /* sdcc compile options +char optsdcc[NINPUT]; /* sdcc compile options */ int flat24Mode; /* non-zero if we are using DS390 24 bit * flat mode (via .flat24 directive). diff --git a/as/mcs51/asm.h b/as/mcs51/asm.h index ac98e3ad..dab0e5f6 100644 --- a/as/mcs51/asm.h +++ b/as/mcs51/asm.h @@ -351,7 +351,6 @@ struct sym #define S_FLAT24 27 /* .flat24 */ #define S_OPTSDCC 28 /* .optsdcc */ - /* * The tsym structure is a linked list of temporary * symbols defined in the assembler source files following @@ -432,6 +431,8 @@ extern int lop; /* current line number on page */ extern int pass; /* assembler pass number */ +extern int org_cnt; /* .org directive counter + */ extern int lflag; /* -l, generate listing flag */ extern int cflag; /* -c, generate sdcdb debug information @@ -501,7 +502,7 @@ extern char tb[NTITL]; /* Title string buffer extern char stb[NSBTL]; /* Subtitle string buffer */ extern char optsdcc[NINPUT]; /* sdcc compile options - */ + */ extern int flat24Mode; /* non-zero if we are using DS390 24 bit * flat mode (via .flat24 directive). */ @@ -522,8 +523,8 @@ extern FILE *sfp[MAXFIL]; /* array of assembler-source file h extern FILE *ifp[MAXINC]; /* array of include-file file handles */ extern unsigned char ctype[128]; /* array of character types, one per - * ASCII character - */ + * ASCII character + */ extern char ccase[128]; /* an array of characters which * perform the case translation function diff --git a/as/mcs51/asmain.c b/as/mcs51/asmain.c index 9c88df19..34598db8 100644 --- a/as/mcs51/asmain.c +++ b/as/mcs51/asmain.c @@ -213,8 +213,7 @@ int fatalErrors=0; char relFile[128]; int -main(argc, argv) -char *argv[]; +main(int argc, char *argv[]) { register char *p; register int c, i; @@ -239,8 +238,8 @@ char *argv[]; case 'c': case 'C': - ++cflag; - break; + ++cflag; + break; case 'g': case 'G': @@ -314,9 +313,9 @@ char *argv[]; if (lflag) lfp = afile(p, "lst", 1); if (oflag) { - ofp = afile(p, "rel", 1); - // save the file name if we have to delete it on error - strcpy(relFile,afn); + ofp = afile(p, "rel", 1); + // save the file name if we have to delete it on error + strcpy(relFile,afn); } if (sflag) tfp = afile(p, "sym", 1); @@ -340,6 +339,7 @@ char *argv[]; radix = 10; srcline[0] = 0; page = 0; + org_cnt = 0; stb[0] = 0; lop = NLPP; cfile = 0; @@ -424,8 +424,7 @@ char *argv[]; */ VOID -asexit(i) -int i; +asexit(int i) { int j; @@ -538,7 +537,7 @@ int i; */ VOID -asmbl() +asmbl(void) { register struct mne *mp; register struct sym *sp; @@ -947,8 +946,9 @@ loop: case S_ORG: if (dot.s_area->a_flag & A_ABS) { char buf[NCPS]; + laddr = absexpr(); - sprintf(buf, "%s%x", abs_ap->a_id, laddr); + sprintf(buf, "%s%x", abs_ap->a_id, org_cnt++); if ((ap = alookup(buf)) == NULL) { ap = (struct area *) new (sizeof(struct area)); *ap = *areap; @@ -1132,10 +1132,7 @@ loop: */ FILE * -afile(fn, ft, wf) -char *fn; -char *ft; -int wf; +afile(char *fn, char *ft, int wf) { register char *p2, *p3; register int c; @@ -1203,8 +1200,7 @@ int wf; */ VOID -newdot(nap) -register struct area *nap; +newdot(register struct area *nap) { register struct area *oap; @@ -1266,9 +1262,7 @@ register struct area *nap; */ VOID -phase(ap, a) -struct area *ap; -Addr_T a; +phase(struct area *ap, Addr_T a) { if (ap != dot.s_area || a != dot.s_addr) err('p'); @@ -1318,7 +1312,7 @@ char *usetxt[] = { */ VOID -usage() +usage(void) { register char **dp; diff --git a/as/mcs51/asout.c b/as/mcs51/asout.c index c5fa425f..3bb68300 100644 --- a/as/mcs51/asout.c +++ b/as/mcs51/asout.c @@ -231,7 +231,7 @@ char *relp = { &rel[0] }; */ VOID -outab(b) +outab(int b) { if (pass == 2) { out_lb(b,0); @@ -266,7 +266,7 @@ outab(b) */ VOID -outaw(w) +outaw(int w) { if (pass == 2) { out_lw(w,0); @@ -629,9 +629,7 @@ outr24(struct expr *esp, int r) */ VOID -outdp(carea, esp) -register struct area *carea; -register struct expr *esp; +outdp(register struct area *carea, register struct expr *esp) { register int n, r; @@ -676,7 +674,7 @@ register struct expr *esp; */ VOID -outall() +outall(void) { if (oflag && pass==2) outbuf("R"); @@ -704,7 +702,7 @@ outall() */ VOID -outdot() +outdot(void) { if (oflag && pass==2) { fprintf(ofp, "T"); @@ -744,7 +742,7 @@ outdot() */ VOID -outchk(nt, nr) +outchk(int nt, int nr) { register struct area *ap; @@ -785,8 +783,7 @@ outchk(nt, nr) */ VOID -outbuf(s) -char *s; +outbuf(char *s) { if (txtp > &txt[2]) { fprintf(ofp, "T"); @@ -843,7 +840,7 @@ char *s; */ VOID -outgsd() +outgsd(void) { register struct area *ap; register struct sym *sp; @@ -964,8 +961,7 @@ outgsd() */ VOID -outarea(ap) -register struct area *ap; +outarea(register struct area *ap) { register char *ptr; register int c; @@ -1012,8 +1008,7 @@ register struct area *ap; */ VOID -outsym(sp) -register struct sym *sp; +outsym(register struct sym *sp) { register char *ptr; @@ -1094,8 +1089,7 @@ out(char *p, int n) */ VOID -out_lb(b,t) -register int b,t; +out_lb(register int b, register int t) { if (cp < &cb[NCODE]) { *cp++ = b; @@ -1127,8 +1121,7 @@ register int b,t; */ VOID -out_lw(n,t) -register int n,t; +out_lw(register int n, register int t) { if (hilo) { out_lb(hibyte(n),t ? t|R_HIGH : 0); @@ -1198,8 +1191,7 @@ out_l24(int n, int t) */ VOID -out_rw(n) -register int n; +out_rw(register int n) { if (hilo) { *relp++ = hibyte(n); @@ -1232,8 +1224,7 @@ register int n; */ VOID -out_tw(n) -register int n; +out_tw(register int n) { if (hilo) { *txtp++ = hibyte(n); @@ -1300,7 +1291,7 @@ out_t24(int n) */ int -lobyte(n) +lobyte(int n) { return (n&0377); } @@ -1326,7 +1317,7 @@ lobyte(n) */ int -hibyte(n) +hibyte(int n) { return ((n>>8)&0377); } diff --git a/sdcc_vc_in.h b/sdcc_vc_in.h index 40dbc081..2ce8d1b1 100644 --- a/sdcc_vc_in.h +++ b/sdcc_vc_in.h @@ -11,6 +11,8 @@ #define __FUNCTION__ __FILE__ #endif +#define __func__ __FUNCTION__ + #define DIR_SEPARATOR_STRING "\\" #define DIR_SEPARATOR_CHAR '\\' diff --git a/src/SDCCast.c b/src/SDCCast.c index 869752b3..4b16e347 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2487,10 +2487,8 @@ decorateType (ast * tree, RESULT_TYPE resultType) /* just get the type */ if (tree->type == EX_VALUE) { - if (IS_LITERAL (tree->opval.val->etype)) { - /* if this is a character array then declare it */ if (IS_ARRAY (tree->opval.val->type)) tree->opval.val = stringToSymbol (tree->opval.val); @@ -6288,19 +6286,13 @@ expandInlineFuncs (ast * tree, ast * block) /* during the function call. For example, a function */ /* declared as func(int x, int y) but called as func(y,x). */ /* { //inlinetree block */ - /* type1 temparg1; */ - /* ... */ - /* typen tempargn; */ - /* temparg1 = argument1; */ + /* type1 temparg1 = argument1; */ /* ... */ - /* tempargn = argumentn; */ + /* typen tempargn = argumentn; */ /* { //inlinetree2 block */ - /* type1 param1; */ + /* type1 param1 = temparg1; */ /* ... */ - /* typen paramn; */ - /* param1 = temparg1; */ - /* ... */ - /* paramn = tempargn; */ + /* typen paramn = tempargn; */ /* inline_function_code; */ /* retlab: */ /* } */ @@ -6326,6 +6318,7 @@ expandInlineFuncs (ast * tree, ast * block) assigntree = newNode ('=', newAst_VALUE (symbolVal (temparg)), passedarg); + assigntree->initMode=1; // tell that assignment is initializer inlinetree->right = newNode (NULLOP, assigntree, inlinetree->right); @@ -6337,11 +6330,11 @@ expandInlineFuncs (ast * tree, ast * block) assigntree = newNode ('=', newAst_VALUE (symbolVal (parm)), newAst_VALUE (symbolVal (temparg))); + assigntree->initMode=1; // tell that assignment is initializer inlinetree2->right = newNode (NULLOP, assigntree, inlinetree2->right); - args = args->next; argIndex++; } @@ -6381,7 +6374,6 @@ expandInlineFuncs (ast * tree, ast * block) fixupInline (inlinetree, inlinetree->level); inlineState.count++; } - } /* Recursively continue to search for functions to inline. */ diff --git a/support/regression/tests/bug1717305.c b/support/regression/tests/bug1717305.c new file mode 100644 index 00000000..5ff7845f --- /dev/null +++ b/support/regression/tests/bug1717305.c @@ -0,0 +1,26 @@ +/* + bug 1717305 +*/ + +#include + +#ifdef SDCC +#pragma std_sdcc99 +#endif + +static inline int f(const int a) +{ + return (a + 3); +} + +int g(int b) +{ + return (f(b)); +} + +void +testBug(void) +{ + int x = 0; + ASSERT (g(x) == 3); +} -- 2.47.2