From 7ddac4cf56954cd0063d010df958b3e03f3fcdc7 Mon Sep 17 00:00:00 2001 From: borutr Date: Sat, 29 Dec 2007 21:44:17 +0000 Subject: [PATCH 1/1] * as/hc08/Makefile.bcc, as/hc08/Makefile.in, as/hc08/as_hc08.dsp, as/mcs51/Makefile.bcc, as/mcs51/Makefile.in, as/mcs51/asx8051.dsp, as/z80/Makefile.bcc, as/z80/Makefile.in, as/z80/as_gbz80.dsp, as/z80/as_z80.dsp: added dbuf.[ch] and dbuf_string[ch] to project * as/asxxsrc/aslex.c: use dbuf_getline() * as/hc08/asdata.c, as/hc08/asexpr.c, as/hc08/asm.h, as/hc08/m08adr.c, as/mcs51/asdata.c, as/mcs51/asexpr.c, as/mcs51/asm.h, as/mcs51/i51adr.c, as/z80/asdata.c, as/z80/asexpr.c, as/z80/aslist.c, as/z80/asm.h, as/z80/z80adr.c: changed type of ib and ip to const char * git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4988 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 10 + as/asxxsrc/aslex.c | 153 ++++----- as/hc08/Makefile.bcc | 3 +- as/hc08/Makefile.in | 15 +- as/hc08/as_hc08.dsp | 20 +- as/hc08/asdata.c | 478 +++++++++++++-------------- as/hc08/asexpr.c | 736 +++++++++++++++++++++--------------------- as/hc08/asm.h | 4 +- as/hc08/m08adr.c | 306 +++++++++--------- as/mcs51/Makefile.bcc | 3 +- as/mcs51/Makefile.in | 15 +- as/mcs51/asdata.c | 4 +- as/mcs51/asexpr.c | 2 +- as/mcs51/asm.h | 4 +- as/mcs51/asx8051.dsp | 24 +- as/mcs51/i51adr.c | 280 ++++++++-------- as/z80/Makefile.bcc | 3 +- as/z80/Makefile.in | 18 +- as/z80/as_gbz80.dsp | 20 +- as/z80/as_z80.dsp | 20 +- as/z80/asdata.c | 4 +- as/z80/asexpr.c | 606 +++++++++++++++++----------------- as/z80/aslist.c | 1 - as/z80/asm.h | 4 +- as/z80/z80adr.c | 372 ++++++++++----------- src/SDCCasm.c | 17 +- 26 files changed, 1592 insertions(+), 1530 deletions(-) diff --git a/ChangeLog b/ChangeLog index 492ad2fb..8ee437ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,16 @@ * src/ds390/gen.c, src/hc08/gen.c, src/mcs51/gen.c, src/pic16/gen.c, src/pic/gen.c, src/z80/gen.c, src/xa51/gen.c, src/pic16/ralloc.c, src/pic16/pcode.[ch]: added const qualifier + * as/hc08/Makefile.bcc, as/hc08/Makefile.in, as/hc08/as_hc08.dsp, + as/mcs51/Makefile.bcc, as/mcs51/Makefile.in, as/mcs51/asx8051.dsp, + as/z80/Makefile.bcc, as/z80/Makefile.in, as/z80/as_gbz80.dsp, + as/z80/as_z80.dsp: added dbuf.[ch] and dbuf_string[ch] to project + * as/asxxsrc/aslex.c: use dbuf_getline() + * as/hc08/asdata.c, as/hc08/asexpr.c, as/hc08/asm.h, as/hc08/m08adr.c, + as/mcs51/asdata.c, as/mcs51/asexpr.c, as/mcs51/asm.h, + as/mcs51/i51adr.c, as/z80/asdata.c, as/z80/asexpr.c, as/z80/aslist.c, + as/z80/asm.h, as/z80/z80adr.c: + changed type of ib and ip to const char * 2007-12-28 Borut Razem diff --git a/as/asxxsrc/aslex.c b/as/asxxsrc/aslex.c index 22fa8f41..ae316156 100644 --- a/as/asxxsrc/aslex.c +++ b/as/asxxsrc/aslex.c @@ -19,6 +19,7 @@ #include #include #include +#include "dbuf_string.h" #include "asm.h" /*)Module aslex.c @@ -356,75 +357,6 @@ getmap(d) return (c); } -/*)Function char * readlin() - * - * char * str poinetr to beginning of the buffer - * size_t n size of the buffer - * FILE * infp input file pointer - * - * The function readlin() reads a line from a file to the buffer s. - * The buffer length is n. If the line is truncterd to n -1 caharecters - * if it is longer the n - 1 characters. - * Trailing LF or CR/LF are removed from str, if present. - * - * local variables: - * int c character read from the file - * char *s buffer pointer - * satic char eof_f EOF flag - * - * global variables: - * none - * - * called functions: - * int getc c-library - */ - -char * -readlin(char *str, size_t n, FILE *infp) -{ - int c = ' '; /* initialize it to something for the caharacter eating step */ - char *s; - static char eof_f = 0; - - if (eof_f) - { - eof_f = 0; - return NULL; - } - - if (n > 0) - { - s = str; - if (n > 1) - { - while (--n && (c = getc(infp)) != '\n' && c != EOF) - *s++ = c; - } - - /* chop CR */ - if (s > str && *(s - 1) == '\r') - --s; - - /* terminate the line */ - *s = '\0'; - - /* eat characters until the end of line */ - while (c != '\n' && c != EOF) - c = getc(infp); - - /* if the EOF is not at the beginning of the line, return the line; - return NULL at the next call of redlin */ - if (c == EOF) - { - if (s == str) - return NULL; - eof_f = 1; - } - } - - return str; -} - /*)Function int as_getline() * * The function as_getline() reads a line of assembler-source text @@ -442,7 +374,7 @@ readlin(char *str, size_t n, FILE *infp) * int i string length * * global variables: - * char ib[] string buffer containing + * const char ib[] string buffer containing * assembler-source text line * char ifp[] array of file handles for * include files @@ -459,6 +391,10 @@ readlin(char *str, size_t n, FILE *infp) * int inpfil maximum input file index * * called functions: + * int dbuf_init() + * int dbuf_set_length() + * int dbuf_getline() + * const char * dbuf_c_str() * int fclose() c-library * char * fgets() c-library * int strlen() c-library @@ -472,29 +408,64 @@ readlin(char *str, size_t n, FILE *infp) */ int -as_getline() +as_getline(void) { -loop: if (incfil >= 0) { - if (readlin(ib, sizeof ib, ifp[incfil]) == NULL) { - fclose(ifp[incfil]); - ifp[incfil--] = NULL; - lop = NLPP; - goto loop; - } else { - ++incline[incfil]; - } - } else { - if (readlin(ib, sizeof ib, sfp[cfile]) == NULL) { - if (++cfile <= inpfil) { - srcline[cfile] = 0; - goto loop; - } - return (0); - } else { - ++srcline[cfile]; - } + static struct dbuf_s dbuf; + static char dbufInitialized = 0; + size_t len; + + if (!dbufInitialized) + { + dbuf_init (&dbuf, 1024); + dbufInitialized = 1; + } + else + dbuf_set_length (&dbuf, 0); + +loop: + if (incfil >= 0) + { + if ((len = dbuf_getline (&dbuf, ifp[incfil])) == 0) + { + fclose (ifp[incfil]); + ifp[incfil--] = NULL; + lop = NLPP; + goto loop; + } + else + { + ++incline[incfil]; } - return (1); + } + else + { + if ((len = dbuf_getline (&dbuf, sfp[cfile])) == 0) + { + if (++cfile <= inpfil) + { + srcline[cfile] = 0; + goto loop; + } + return 0; + } + else + { + ++srcline[cfile]; + } + } + ib = dbuf_c_str (&dbuf); + + /* remove the trailing NL */ + if (len > 0 && '\n' == ib[len - 1]) + { + --len; + if (len > 0 && '\r' == ib[len - 1]) + --len; + dbuf_set_length (&dbuf, len); + ib = dbuf_c_str (&dbuf); + } + + return 1; } /*)Function int more() diff --git a/as/hc08/Makefile.bcc b/as/hc08/Makefile.bcc index 068d802b..384c518e 100644 --- a/as/hc08/Makefile.bcc +++ b/as/hc08/Makefile.bcc @@ -7,7 +7,8 @@ PRJDIR = ../.. ASOBJECTS = asmain.obj aslex.obj assubr.obj asnoice.obj \ asexpr.obj asdata.obj aslist.obj asout.obj \ h08ext.obj h08pst.obj h08mch.obj h08adr.obj \ - ../asxxsrc/strcmpi.obj ../asxxsrc/assym.obj + ../asxxsrc/strcmpi.obj ../asxxsrc/assym.obj \ + ../../support/Util/dbuf.obj ../../support/Util/dbuf_string.obj ASX8051 = $(PRJDIR)/bin/asx8051.exe diff --git a/as/hc08/Makefile.in b/as/hc08/Makefile.in index 65ab660f..4a4e3ce5 100644 --- a/as/hc08/Makefile.in +++ b/as/hc08/Makefile.in @@ -40,19 +40,22 @@ LDFLAGS = @LDFLAGS@ OBJDIR = obj -ASXXLIB = $(srcdir)/../asxxsrc +UTILLIB = $(srcdir)/../../support/Util +UTILSRC = dbuf.c dbuf_string.c +UTILLIBOBJS = $(UTILSRC:%.c=$(OBJDIR)/%.o) +ASXXLIB = $(srcdir)/../asxxsrc ASXXLIBSRC = strcmpi.c assym.c aslex.c +ASXXLIBOBJS = $(ASXXLIBSRC:%.c=$(OBJDIR)/%.o) SRC = asmain.c assubr.c asnoice.c \ asexpr.c asdata.c aslist.c asout.c \ m08ext.c m08pst.c m08mch.c m08adr.c - -ASSOURCES = %(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c) - OBJS = $(SRC:%.c=$(OBJDIR)/%.o) -ASXXLIBOBJS = $(ASXXLIBSRC:%.c=$(OBJDIR)/%.o) -ASOBJECTS = $(OBJS) $(ASXXLIBOBJS) + +ASSOURCES = %(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c) $(UTILSRC:%.c=$(UTILLIB)/%.c) + +AASOBJECTS = $(OBJS) $(ASXXLIBOBJS) $(UTILLIBOBJS) ASHC08 = $(top_builddir)/bin/as-hc08$(EXEEXT) diff --git a/as/hc08/as_hc08.dsp b/as/hc08/as_hc08.dsp index 8cd7b59c..2b2c675e 100644 --- a/as/hc08/as_hc08.dsp +++ b/as/hc08/as_hc08.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "." /I "../../support/Util" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /U "." /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "../../support/Util" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -123,6 +123,14 @@ SOURCE=..\asxxsrc\assym.c # End Source File # Begin Source File +SOURCE=..\..\support\Util\dbuf.c +# End Source File +# Begin Source File + +SOURCE=..\..\support\Util\dbuf_string.c +# End Source File +# Begin Source File + SOURCE=.\m08adr.c # End Source File # Begin Source File @@ -151,6 +159,14 @@ SOURCE=.\asm.h # End Source File # Begin Source File +SOURCE=..\..\support\Util\dbuf.h +# End Source File +# Begin Source File + +SOURCE=..\..\support\Util\dbuf_string.h +# End Source File +# Begin Source File + SOURCE=.\m6808.h # End Source File # End Group diff --git a/as/hc08/asdata.c b/as/hc08/asdata.c index 16657520..2069661d 100644 --- a/as/hc08/asdata.c +++ b/as/hc08/asdata.c @@ -8,8 +8,8 @@ * 721 Berkeley St. * Kent, Ohio 44240 * - * 28-Oct-97 JLH: - * - change s_id from [NCPS] to pointer (comment) + * 28-Oct-97 JLH: + * - change s_id from [NCPS] to pointer (comment) * 2-Nov-97 JLH: * - add jflag for debug control */ @@ -19,271 +19,271 @@ #include #include "asm.h" -/*)Module asdata.c +/*)Module asdata.c * - * The module asdata.c contains the global constants, - * structures, and variables used in the assembler. + * The module asdata.c contains the global constants, + * 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 - */ -int srcline[MAXFIL]; /* source line number - */ -char incfn[MAXINC][PATH_MAX]; /* array of include file names - */ -int incline[MAXINC]; /* include line number - */ +char afn[PATH_MAX]; /* afile temporary file name + */ +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 + */ +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 - */ -char *ip; /* pointer into the assembler-source - * text line in ib[] - */ -char ib[NINPUT]; /* 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 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 + */ +char optsdcc[NINPUT]; /* sdcc compile options + */ +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 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 - * mnemonics and directives. The list of mnemonics and - * directives contained in the device dependent file - * xxxpst.c are hashed and linked into NHASH lists in - * module assym.c by syminit(). The structure contains - * the mnemonic/directive name, a subtype which directs - * the evaluation of this mnemonic/directive, a flag which - * is used to detect the end of the mnemonic/directive - * list in xxxpst.c, and a value which is normally - * associated with the assembler mnemonic base instruction - * value. + * The mne structure is a linked list of the assembler + * mnemonics and directives. The list of mnemonics and + * directives contained in the device dependent file + * xxxpst.c are hashed and linked into NHASH lists in + * module assym.c by syminit(). The structure contains + * the mnemonic/directive name, a subtype which directs + * the evaluation of this mnemonic/directive, a flag which + * is used to detect the end of the mnemonic/directive + * list in xxxpst.c, and a value which is normally + * associated with the assembler mnemonic base instruction + * value. * - * struct mne - * { - * struct mne *m_mp; Hash link - * char m_id[NCPS]; Mnemonic - * char m_type; Mnemonic subtype - * char m_flag; Mnemonic flags - * Addr_T m_valu; Value - * }; + * struct mne + * { + * struct mne *m_mp; Hash link + * char m_id[NCPS]; Mnemonic + * char m_type; Mnemonic subtype + * char m_flag; Mnemonic flags + * Addr_T m_valu; Value + * }; */ -struct mne *mnehash[NHASH]; +struct mne *mnehash[NHASH]; /* - * The sym structure is a linked list of symbols defined - * in the assembler source files. The first symbol is "." - * defined here. The entry 'struct tsym *s_tsym' - * links any temporary symbols following this symbol and - * preceeding the next normal symbol. The structure also - * contains the symbol's name, type (USER or NEW), flag - * (global, assigned, and multiply defined), a pointer - * to the area structure defining where the symbol is - * located, a reference number assigned by outgsd() in - * asout.c, and the symbols address relative to the base - * address of the area where the symbol is located. + * The sym structure is a linked list of symbols defined + * in the assembler source files. The first symbol is "." + * defined here. The entry 'struct tsym *s_tsym' + * links any temporary symbols following this symbol and + * preceeding the next normal symbol. The structure also + * contains the symbol's name, type (USER or NEW), flag + * (global, assigned, and multiply defined), a pointer + * to the area structure defining where the symbol is + * located, a reference number assigned by outgsd() in + * asout.c, and the symbols address relative to the base + * address of the area where the symbol is located. * - * struct sym - * { - * struct sym *s_sp; Hash link - * struct tsym *s_tsym; Temporary symbol link - * char *s_id; Symbol (JLH) - * 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 - * }; + * struct sym + * { + * struct sym *s_sp; Hash link + * struct tsym *s_tsym; Temporary symbol link + * char *s_id; Symbol (JLH) + * 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 + * }; */ -struct sym sym[] = { - {NULL, NULL, ".", S_USER, S_END, NULL, 0, 0} +struct sym sym[] = { + {NULL, NULL, ".", S_USER, S_END, NULL, 0, 0} }; -struct sym *symp; /* pointer to a symbol structure - */ -struct sym *symhash[NHASH]; /* array of pointers to NHASH - * linked symbol lists - */ +struct sym *symp; /* pointer to a symbol structure + */ +struct sym *symhash[NHASH]; /* array of pointers to NHASH + * linked symbol lists + */ /* - * The area structure contains the parameter values for a - * specific program or data section. The area structure - * is a linked list of areas. The initial default area - * is "_CODE" defined here, the next area structure - * will be linked to this structure through the structure - * element 'struct area *a_ep'. The structure contains the - * area name, area reference number ("_CODE" is 0) determined - * by the order of .area directives, area size determined - * from the total code and/or data in an area, area fuzz is - * an variable used to track pass to pass changes in the - * area size caused by variable length instruction formats, - * and area flags which specify the area's relocation type. + * The area structure contains the parameter values for a + * specific program or data section. The area structure + * is a linked list of areas. The initial default area + * is "_CODE" defined here, the next area structure + * will be linked to this structure through the structure + * element 'struct area *a_ep'. The structure contains the + * area name, area reference number ("_CODE" is 0) determined + * by the order of .area directives, area size determined + * from the total code and/or data in an area, area fuzz is + * an variable used to track pass to pass changes in the + * area size caused by variable length instruction formats, + * and area flags which specify the area's relocation type. * - * struct area - * { - * struct area *a_ap; Area link - * char a_id[NCPS]; Area Name - * int a_ref; Reference number - * Addr_T a_size; Area size - * Addr_T a_fuzz; Area fuzz - * int a_flag; Area flags - * }; + * struct area + * { + * struct area *a_ap; Area link + * char a_id[NCPS]; Area Name + * int a_ref; Reference number + * Addr_T a_size; Area size + * Addr_T a_fuzz; Area fuzz + * int a_flag; Area flags + * }; */ -struct area area[] = { - {NULL, "_CODE", 0, 0, 0, A_CON|A_REL} +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 - * ASCII character + * array of character types, one per + * ASCII character */ -unsigned char ctype[128] = { -/*NUL*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, -/*BS*/ ILL, SPACE, ILL, ILL, SPACE, ILL, ILL, ILL, -/*DLE*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, -/*CAN*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, -/*SPC*/ SPACE, ETC, ETC, ETC, LETTER, BINOP, BINOP, ETC, -/*(*/ ETC, ETC, BINOP, BINOP, ETC, BINOP, LETTER, BINOP, -/*0*/ DGT2, DGT2, DGT8, DGT8, DGT8, DGT8, DGT8, DGT8, -/*8*/ DGT10, DGT10, ETC, ETC, BINOP, ETC, BINOP, ETC, -/*@*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER, -/*H*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/*P*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/*X*/ LETTER, LETTER, LETTER, ETC, ETC, ETC, BINOP, LETTER, -/*`*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER, -/*h*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/*p*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/*x*/ LETTER, LETTER, LETTER, ETC, BINOP, ETC, ETC, ETC +unsigned char ctype[128] = { +/*NUL*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, +/*BS*/ ILL, SPACE, ILL, ILL, SPACE, ILL, ILL, ILL, +/*DLE*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, +/*CAN*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, +/*SPC*/ SPACE, ETC, ETC, ETC, LETTER, BINOP, BINOP, ETC, +/*(*/ ETC, ETC, BINOP, BINOP, ETC, BINOP, LETTER, BINOP, +/*0*/ DGT2, DGT2, DGT8, DGT8, DGT8, DGT8, DGT8, DGT8, +/*8*/ DGT10, DGT10, ETC, ETC, BINOP, ETC, BINOP, ETC, +/*@*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER, +/*H*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/*P*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/*X*/ LETTER, LETTER, LETTER, ETC, ETC, ETC, BINOP, LETTER, +/*`*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER, +/*h*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/*p*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/*x*/ LETTER, LETTER, LETTER, ETC, BINOP, ETC, ETC, ETC }; /* - * an array of characters which - * perform the case translation function + * an array of characters which + * perform the case translation function */ -char ccase[128] = { -/*NUL*/ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', -/*BS*/ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', -/*DLE*/ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', -/*CAN*/ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', -/*SPC*/ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', -/*(*/ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', -/*0*/ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', -/*8*/ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', -/*@*/ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', -/*H*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', -/*P*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', -/*X*/ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', -/*`*/ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', -/*h*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', -/*p*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', -/*x*/ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177' -}; +char ccase[128] = { +/*NUL*/ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', +/*BS*/ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', +/*DLE*/ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', +/*CAN*/ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', +/*SPC*/ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', +/*(*/ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', +/*0*/ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', +/*8*/ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', +/*@*/ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', +/*H*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', +/*P*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', +/*X*/ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', +/*`*/ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', +/*h*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', +/*p*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', +/*x*/ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177' +}; diff --git a/as/hc08/asexpr.c b/as/hc08/asexpr.c index a21e9b0f..6f433940 100644 --- a/as/hc08/asexpr.c +++ b/as/hc08/asexpr.c @@ -1,4 +1,4 @@ - /* asexpr.c */ + /* asexpr.c */ /* * (C) Copyright 1989-1995 @@ -14,68 +14,68 @@ #include #include "asm.h" -/*)Module asexpr.c - * - * The module asexpr.c contains the routines to evaluate - * arithmetic/numerical expressions. The functions in - * asexpr.c perform a recursive evaluation of the arithmetic - * expression read from the assembler-source text line. - * The expression may include binary/unary operators, brackets, - * symbols, labels, and constants in hexadecimal, decimal, octal - * and binary. Arithmetic operations are prioritized and - * evaluated by normal arithmetic conventions. - * - * asexpr.c contains the following functions: - * VOID abscheck() - * Addr_T absexpr() - * VOID clrexpr() - * int digit() - * VOID expr() - * int oprio() - * VOID term() - * - * asexpr.c contains no local/static variables +/*)Module asexpr.c + * + * The module asexpr.c contains the routines to evaluate + * arithmetic/numerical expressions. The functions in + * asexpr.c perform a recursive evaluation of the arithmetic + * expression read from the assembler-source text line. + * The expression may include binary/unary operators, brackets, + * symbols, labels, and constants in hexadecimal, decimal, octal + * and binary. Arithmetic operations are prioritized and + * evaluated by normal arithmetic conventions. + * + * asexpr.c contains the following functions: + * VOID abscheck() + * Addr_T absexpr() + * VOID clrexpr() + * int digit() + * VOID expr() + * int oprio() + * VOID term() + * + * asexpr.c contains no local/static variables */ -/*)Function VOID expr(esp, n) - * - * expr * esp pointer to an expr structure - * int n a firewall priority; all top - * level calls (from the user) - * should be made with n set to 0. - * - * The function expr() evaluates an expression and - * stores its value and relocation information into - * the expr structure supplied by the user. - * - * local variables: - * int c current assembler-source - * text character - * int p current operator priority - * area * ap pointer to an area structure - * exp re internal expr structure - * - * global variables: - * char ctype[] array of character types, one per - * ASCII character - * - * functions called: - * VOID abscheck() asexpr.c - * VOID clrexpr() asexpr.c - * VOID expr() asexpr.c - * int getnb() aslex.c - * int oprio() asexpr.c - * VOID qerr() assubr.c - * VOID rerr() assubr.c - * VOID term() asexpr.c - * VOID unget() aslex.c - * - * - * side effects: - * An expression is evaluated modifying the user supplied - * expr structure, a sym structure maybe created for an - * undefined symbol, and the parse of the expression may - * terminate if a 'q' error occurs. +/*)Function VOID expr(esp, n) + * + * expr * esp pointer to an expr structure + * int n a firewall priority; all top + * level calls (from the user) + * should be made with n set to 0. + * + * The function expr() evaluates an expression and + * stores its value and relocation information into + * the expr structure supplied by the user. + * + * local variables: + * int c current assembler-source + * text character + * int p current operator priority + * area * ap pointer to an area structure + * exp re internal expr structure + * + * global variables: + * char ctype[] array of character types, one per + * ASCII character + * + * functions called: + * VOID abscheck() asexpr.c + * VOID clrexpr() asexpr.c + * VOID expr() asexpr.c + * int getnb() aslex.c + * int oprio() asexpr.c + * VOID qerr() assubr.c + * VOID rerr() assubr.c + * VOID term() asexpr.c + * VOID unget() aslex.c + * + * + * side effects: + * An expression is evaluated modifying the user supplied + * expr structure, a sym structure maybe created for an + * undefined symbol, and the parse of the expression may + * terminate if a 'q' error occurs. */ VOID @@ -89,31 +89,31 @@ int n; term(esp); while (ctype[c = getnb()] & BINOP) { - /* - * Handle binary operators + - * / & | % ^ << >> - */ + /* + * Handle binary operators + - * / & | % ^ << >> + */ if ((p = oprio(c)) <= n) break; if ((c == '>' || c == '<') && c != get()) qerr(); - clrexpr(&re); + clrexpr(&re); expr(&re, p); - esp->e_rlcf |= re.e_rlcf; + esp->e_rlcf |= re.e_rlcf; if (c == '+') { - /* - * esp + re, at least one must be absolute - */ + /* + * esp + re, at least one must be absolute + */ if (esp->e_base.e_ap == NULL) { - /* - * esp is absolute (constant), - * use area from re - */ + /* + * esp is absolute (constant), + * use area from re + */ esp->e_base.e_ap = re.e_base.e_ap; } else if (re.e_base.e_ap) { - /* - * re should be absolute (constant) - */ + /* + * re should be absolute (constant) + */ rerr(); } if (esp->e_flag && re.e_flag) @@ -123,9 +123,9 @@ int n; esp->e_addr += re.e_addr; } else if (c == '-') { - /* - * esp - re - */ + /* + * esp - re + */ if ((ap = re.e_base.e_ap) != NULL) { if (esp->e_base.e_ap == ap) { esp->e_base.e_ap = NULL; @@ -137,118 +137,118 @@ int n; rerr(); esp->e_addr -= re.e_addr; } else { - /* - * Both operands (esp and re) must be constants - */ - /* SD :- moved the abscheck to each case - case and change the right shift operator.. if - right shift by 8 bits of a relocatable address then - the user wants the higher order byte. set the R_MSB - for the expression */ + /* + * Both operands (esp and re) must be constants + */ + /* SD :- moved the abscheck to each case + case and change the right shift operator.. if + right shift by 8 bits of a relocatable address then + the user wants the higher order byte. set the R_MSB + for the expression */ switch (c) { case '*': - abscheck(esp); - abscheck(&re); - esp->e_addr *= re.e_addr; - break; + abscheck(esp); + abscheck(&re); + esp->e_addr *= re.e_addr; + break; case '/': - abscheck(esp); - abscheck(&re); - esp->e_addr /= re.e_addr; - break; + abscheck(esp); + abscheck(&re); + esp->e_addr /= re.e_addr; + break; case '&': - abscheck(esp); - abscheck(&re); - esp->e_addr &= re.e_addr; - break; + abscheck(esp); + abscheck(&re); + esp->e_addr &= re.e_addr; + break; case '|': - abscheck(esp); - abscheck(&re); - esp->e_addr |= re.e_addr; - break; + abscheck(esp); + abscheck(&re); + esp->e_addr |= re.e_addr; + break; case '%': - abscheck(esp); - abscheck(&re); - esp->e_addr %= re.e_addr; - break; + abscheck(esp); + abscheck(&re); + esp->e_addr %= re.e_addr; + break; case '^': - abscheck(esp); - abscheck(&re); - esp->e_addr ^= re.e_addr; - break; + abscheck(esp); + abscheck(&re); + esp->e_addr ^= re.e_addr; + break; case '<': - abscheck(esp); - abscheck(&re); - esp->e_addr <<= re.e_addr; - break; + abscheck(esp); + abscheck(&re); + esp->e_addr <<= re.e_addr; + break; case '>': - /* SD change here */ - abscheck(&re); - /* if the left is a relative address & - the right side is == 8 then */ - if (esp->e_base.e_ap && re.e_addr == 8) { - esp->e_rlcf |= R_MSB ; - break; - } - else if (esp->e_base.e_ap && re.e_addr == 16) - { - if (flat24Mode) - { - esp->e_rlcf |= R_HIB; - } - else - { - warnBanner(); - fprintf(stderr, - "(expr >> 16) is only meaningful in " - ".flat24 mode.\n"); - qerr(); - } - - break; - } - /* else continue with the normal processing */ - abscheck(esp); - esp->e_addr >>= re.e_addr; - break; - - default: - qerr(); - break; - } + /* SD change here */ + abscheck(&re); + /* if the left is a relative address & + the right side is == 8 then */ + if (esp->e_base.e_ap && re.e_addr == 8) { + esp->e_rlcf |= R_MSB ; + break; + } + else if (esp->e_base.e_ap && re.e_addr == 16) + { + if (flat24Mode) + { + esp->e_rlcf |= R_HIB; + } + else + { + warnBanner(); + fprintf(stderr, + "(expr >> 16) is only meaningful in " + ".flat24 mode.\n"); + qerr(); + } + + break; + } + /* else continue with the normal processing */ + abscheck(esp); + esp->e_addr >>= re.e_addr; + break; + + default: + qerr(); + break; + } } } unget(c); } -/*)Function Addr_T absexpr() +/*)Function Addr_T absexpr() * - * The function absexpr() evaluates an expression, verifies it - * is absolute (i.e. not position dependent or relocatable), and - * returns its value. + * The function absexpr() evaluates an expression, verifies it + * is absolute (i.e. not position dependent or relocatable), and + * returns its value. * - * local variables: - * expr e expr structure + * local variables: + * expr e expr structure * - * global variables: - * none + * global variables: + * none * - * functions called: - * VOID abscheck() asexpr.c - * VOID clrexpr() asexpr.c - * VOID expr() asexpr.c + * functions called: + * VOID abscheck() asexpr.c + * VOID clrexpr() asexpr.c + * VOID expr() asexpr.c * - * side effects: - * If the expression is not absolute then - * a 'r' error is reported. + * side effects: + * If the expression is not absolute then + * a 'r' error is reported. */ Addr_T @@ -256,55 +256,55 @@ absexpr() { struct expr e; - clrexpr(&e); - expr(&e, 0); - abscheck(&e); - return (e.e_addr); + clrexpr(&e); + expr(&e, 0); + abscheck(&e); + return (e.e_addr); } -/*)Function VOID term(esp) - * - * expr * esp pointer to an expr structure - * - * The function term() evaluates a single constant - * or symbol value prefaced by any unary operator - * ( +, -, ~, ', ", >, or < ). This routine is also - * responsible for setting the relocation type to symbol - * based (e.flag != 0) on global references. - * - * local variables: - * int c current character - * char id[] symbol name - * char * jp pointer to assembler-source text - * int n constant evaluation running sum - * int r current evaluation radix - * sym * sp pointer to a sym structure - * tsym * tp pointer to a tsym structure - * int v current digit evaluation - * - * global variables: - * char ctype[] array of character types, one per - * ASCII character - * sym * symp pointer to a symbol structure - * - * functions called: - * VOID abscheck() asexpr.c - * int digit() asexpr.c - * VOID err() assubr.c - * VOID expr() asexpr.c - * int is_abs() asexpr.c - * int get() aslex.c - * VOID getid() aslex.c - * int getmap() aslex.c - * int getnb() aslex.c - * sym * lookup() assym.c - * VOID qerr() assubr.c - * VOID unget() aslex.c - * - * side effects: - * An arithmetic term is evaluated, a symbol structure - * may be created, term evaluation may be terminated - * by a 'q' error. +/*)Function VOID term(esp) + * + * expr * esp pointer to an expr structure + * + * The function term() evaluates a single constant + * or symbol value prefaced by any unary operator + * ( +, -, ~, ', ", >, or < ). This routine is also + * responsible for setting the relocation type to symbol + * based (e.flag != 0) on global references. + * + * local variables: + * int c current character + * char id[] symbol name + * char * jp pointer to assembler-source text + * int n constant evaluation running sum + * int r current evaluation radix + * sym * sp pointer to a sym structure + * tsym * tp pointer to a tsym structure + * int v current digit evaluation + * + * global variables: + * char ctype[] array of character types, one per + * ASCII character + * sym * symp pointer to a symbol structure + * + * functions called: + * VOID abscheck() asexpr.c + * int digit() asexpr.c + * VOID err() assubr.c + * VOID expr() asexpr.c + * int is_abs() asexpr.c + * int get() aslex.c + * VOID getid() aslex.c + * int getmap() aslex.c + * int getnb() aslex.c + * sym * lookup() assym.c + * VOID qerr() assubr.c + * VOID unget() aslex.c + * + * side effects: + * An arithmetic term is evaluated, a symbol structure + * may be created, term evaluation may be terminated + * by a 'q' error. */ VOID @@ -312,23 +312,23 @@ term(esp) register struct expr *esp; { register int c, n; - register char *jp; + register const char *jp; char id[NCPS]; struct sym *sp; struct tsym *tp; int r=0, v; c = getnb(); - /* - * Discard the unary '+' at this point and - * also any reference to numerical arguments - * associated with the '#' prefix. - */ + /* + * Discard the unary '+' at this point and + * also any reference to numerical arguments + * associated with the '#' prefix. + */ while (c == '+' || c == '#') { c = getnb(); } - /* - * Evaluate all binary operators - * by recursively calling expr(). - */ + /* + * Evaluate all binary operators + * by recursively calling expr(). + */ if (c == LFTERM) { expr(esp, 0); if (getnb() != RTTERM) @@ -365,28 +365,28 @@ register struct expr *esp; } if (c == '>' || c == '<') { expr(esp, 100); - if (is_abs (esp)) { - /* - * evaluate msb/lsb directly - */ - if (c == '>') - esp->e_addr >>= 8; - esp->e_addr &= 0377; - return; - } else { - /* - * let linker perform msb/lsb, lsb is default - */ - esp->e_rlcf |= R_BYT2; - if (c == '>') - esp->e_rlcf |= R_MSB; - return; - } + if (is_abs (esp)) { + /* + * evaluate msb/lsb directly + */ + if (c == '>') + esp->e_addr >>= 8; + esp->e_addr &= 0377; + return; + } else { + /* + * let linker perform msb/lsb, lsb is default + */ + esp->e_rlcf |= R_BYT2; + if (c == '>') + esp->e_rlcf |= R_MSB; + return; + } } - /* - * Evaluate digit sequences as local symbols - * if followed by a '$' or as constants. - */ + /* + * Evaluate digit sequences as local symbols + * if followed by a '$' or as constants. + */ if (ctype[c] & DIGIT) { esp->e_mode = S_USER; jp = ip; @@ -452,58 +452,58 @@ register struct expr *esp; esp->e_addr = n; return; } - /* - * Evaluate '$' sequences as a temporary radix - * if followed by a '%', '&', '#', or '$'. - */ + /* + * Evaluate '$' sequences as a temporary radix + * if followed by a '%', '&', '#', or '$'. + */ if (c == '$') { c = get(); if (c == '%' || c == '&' || c == '#' || c == '$') { - switch (c) { - case '%': - r = 2; - break; - case '&': - r = 8; - break; - case '#': - r = 10; - break; - case '$': - r = 16; - break; - default: - break; - } - c = get(); - n = 0; - while ((v = digit(c, r)) >= 0) { - n = r*n + v; - c = get(); - } - unget(c); - esp->e_mode = S_USER; - esp->e_addr = n; - return; - } - unget(c); - c = '$'; + switch (c) { + case '%': + r = 2; + break; + case '&': + r = 8; + break; + case '#': + r = 10; + break; + case '$': + r = 16; + break; + default: + break; + } + c = get(); + n = 0; + while ((v = digit(c, r)) >= 0) { + n = r*n + v; + c = get(); + } + unget(c); + esp->e_mode = S_USER; + esp->e_addr = n; + return; + } + unget(c); + c = '$'; } - /* - * Evaluate symbols and labels - */ + /* + * Evaluate symbols and labels + */ if (ctype[c] & LETTER) { esp->e_mode = S_USER; getid(id, c); sp = lookup(id); if (sp->s_type == S_NEW) { esp->e_addr = 0; - if (sp->s_flag&S_GBL) { - esp->e_flag = 1; - esp->e_base.e_sp = sp; - return; - } - /* err('u'); */ + if (sp->s_flag&S_GBL) { + esp->e_flag = 1; + esp->e_base.e_sp = sp; + return; + } + /* err('u'); */ } else { esp->e_mode = sp->s_type; esp->e_addr = sp->s_addr; @@ -511,33 +511,33 @@ register struct expr *esp; } return; } - /* - * Else not a term. - */ + /* + * Else not a term. + */ qerr(); } -/*)Function int digit(c, r) +/*)Function int digit(c, r) * - * int c digit character - * int r current radix + * int c digit character + * int r current radix * - * The function digit() returns the value of c - * in the current radix r. If the c value is not - * a number of the current radix then a -1 is returned. + * The function digit() returns the value of c + * in the current radix r. If the c value is not + * a number of the current radix then a -1 is returned. * - * local variables: - * none + * local variables: + * none * - * global variables: - * char ctype[] array of character types, one per - * ASCII character + * global variables: + * char ctype[] array of character types, one per + * ASCII character * - * functions called: - * none + * functions called: + * none * - * side effects: - * none + * side effects: + * none */ int @@ -568,31 +568,31 @@ register int c, r; return (-1); } -/*)Function VOID abscheck(esp) +/*)Function VOID abscheck(esp) * - * expr * esp pointer to an expr structure + * expr * esp pointer to an expr structure * - * The function abscheck() tests the evaluation of an - * expression to verify it is absolute. If the evaluation - * is relocatable then an 'r' error is noted and the expression - * made absolute. + * The function abscheck() tests the evaluation of an + * expression to verify it is absolute. If the evaluation + * is relocatable then an 'r' error is noted and the expression + * made absolute. * - * Note: The area type (i.e. ABS) is not checked because - * the linker can be told to explicitly relocate an - * absolute area. + * Note: The area type (i.e. ABS) is not checked because + * the linker can be told to explicitly relocate an + * absolute area. * - * local variables: - * none + * local variables: + * none * - * global variables: - * none + * global variables: + * none * - * functions called: - * VOID rerr() assubr.c + * functions called: + * VOID rerr() assubr.c * - * side effects: - * The expression may be changed to absolute and the - * 'r' error invoked. + * side effects: + * The expression may be changed to absolute and the + * 'r' error invoked. */ VOID @@ -606,29 +606,29 @@ register struct expr *esp; } } -/*)Function int is_abs(esp) +/*)Function int is_abs(esp) * - * expr * esp pointer to an expr structure + * expr * esp pointer to an expr structure * - * The function is_abs() tests the evaluation of an - * expression to verify it is absolute. If the evaluation - * is absolute then 1 is returned, else 0 is returned. + * The function is_abs() tests the evaluation of an + * expression to verify it is absolute. If the evaluation + * is absolute then 1 is returned, else 0 is returned. * - * Note: The area type (i.e. ABS) is not checked because - * the linker can be told to explicitly relocate an - * absolute area. + * Note: The area type (i.e. ABS) is not checked because + * the linker can be told to explicitly relocate an + * absolute area. * - * local variables: - * none + * local variables: + * none * - * global variables: - * none + * global variables: + * none * - * functions called: - * none + * functions called: + * none * - * side effects: - * none + * side effects: + * none */ int @@ -636,31 +636,31 @@ is_abs (esp) register struct expr *esp; { if (esp->e_flag || esp->e_base.e_ap) { - return(0); + return(0); } - return(1); + return(1); } -/*)Function int oprio(c) +/*)Function int oprio(c) * - * int c operator character + * int c operator character * - * The function oprio() returns a relative priority - * for all valid unary and binary operators. + * The function oprio() returns a relative priority + * for all valid unary and binary operators. * - * local variables: - * none + * local variables: + * none * - * global variables: - * none + * global variables: + * none * - * functions called: - * none + * functions called: + * none * - * side effects: - * none + * side effects: + * none */ - + int oprio(c) register int c; @@ -680,32 +680,32 @@ register int c; return (0); } -/*)Function VOID clrexpr(esp) +/*)Function VOID clrexpr(esp) * - * expr * esp pointer to expression structure + * expr * esp pointer to expression structure * - * The function clrexpr() clears the expression structure. + * The function clrexpr() clears the expression structure. * - * local variables: - * none + * local variables: + * none * - * global variables: - * none + * global variables: + * none * - * functions called: - * none + * functions called: + * none * - * side effects: - * expression structure cleared. + * side effects: + * expression structure cleared. */ - + VOID clrexpr(esp) register struct expr *esp; { - esp->e_mode = 0; - esp->e_flag = 0; - esp->e_addr = 0; - esp->e_base.e_ap = NULL; - esp->e_rlcf = 0; + esp->e_mode = 0; + esp->e_flag = 0; + esp->e_addr = 0; + esp->e_base.e_ap = NULL; + esp->e_rlcf = 0; } diff --git a/as/hc08/asm.h b/as/hc08/asm.h index 17e31dc6..f6f44dba 100644 --- a/as/hc08/asm.h +++ b/as/hc08/asm.h @@ -465,10 +465,10 @@ extern char *ep; /* pointer into error list */ extern char eb[NERR]; /* array of generated error codes */ -extern char *ip; /* pointer into the assembler-source +extern const char *ip; /* pointer into the assembler-source * text line in ib[] */ -extern char ib[NINPUT]; /* assembler-source text line +extern const char *ib; /* assembler-source text line */ extern char *cp; /* pointer to assembler output * array cb[] diff --git a/as/hc08/m08adr.c b/as/hc08/m08adr.c index 61e10b4c..aa904650 100644 --- a/as/hc08/m08adr.c +++ b/as/hc08/m08adr.c @@ -18,114 +18,114 @@ int addr(esp) register struct expr *esp; { - register int c; - register struct area *espa; - register Addr_T espv; - char *tcp; - - if ((c = getnb()) == '#') { - expr(esp, 0); - esp->e_mode = S_IMMED; - } else if (c == ',') { - switch(admode(axs)) { - default: - aerr(); - - case S_X: - c = S_IX; - break; - - case S_S: - c = S_IS; - break; - - case S_XP: - c = S_IXP; - break; - } - esp->e_mode = c; - } else if (c == '*') { - expr(esp, 0); - esp->e_mode = S_DIR; - if (esp->e_addr & ~0xFF) - err('d'); - if (more()) { - comma(); - tcp = ip; - switch(admode(axs)) { - case S_X: - esp->e_mode = S_IX1; - break; - - case S_S: - esp->e_mode = S_SP1; - break; - - case S_XP: - esp->e_mode = S_IX1P; - break; - - default: - ip = --tcp; - } - } - } else { - unget(c); - if ((esp->e_mode = admode(axs)) != 0) { - ; - } else { - expr(esp, 0); - espa = esp->e_base.e_ap; - espv = esp->e_addr; - if (more()) { - comma(); - c = admode(axs); - if (esp->e_flag == 0 && - espa == NULL && - (espv & ~0xFF) == 0) { - switch(c) { - default: - aerr(); - - case S_X: - c = S_IX1; - break; - - case S_S: - c = S_SP1; - break; - - case S_XP: - c = S_IX1P; - break; - } - } else { - switch(c) { - default: - aerr(); - - case S_X: - c = S_IX2; - break; - - case S_S: - c = S_SP2; - break; - - case S_XP: - c = S_IX2P; - break; - } - } - esp->e_mode = c; - } else { - esp->e_mode = S_EXT; - } - } - } - return (esp->e_mode); + register int c; + register struct area *espa; + register Addr_T espv; + const char *tcp; + + if ((c = getnb()) == '#') { + expr(esp, 0); + esp->e_mode = S_IMMED; + } else if (c == ',') { + switch(admode(axs)) { + default: + aerr(); + + case S_X: + c = S_IX; + break; + + case S_S: + c = S_IS; + break; + + case S_XP: + c = S_IXP; + break; + } + esp->e_mode = c; + } else if (c == '*') { + expr(esp, 0); + esp->e_mode = S_DIR; + if (esp->e_addr & ~0xFF) + err('d'); + if (more()) { + comma(); + tcp = ip; + switch(admode(axs)) { + case S_X: + esp->e_mode = S_IX1; + break; + + case S_S: + esp->e_mode = S_SP1; + break; + + case S_XP: + esp->e_mode = S_IX1P; + break; + + default: + ip = --tcp; + } + } + } else { + unget(c); + if ((esp->e_mode = admode(axs)) != 0) { + ; + } else { + expr(esp, 0); + espa = esp->e_base.e_ap; + espv = esp->e_addr; + if (more()) { + comma(); + c = admode(axs); + if (esp->e_flag == 0 && + espa == NULL && + (espv & ~0xFF) == 0) { + switch(c) { + default: + aerr(); + + case S_X: + c = S_IX1; + break; + + case S_S: + c = S_SP1; + break; + + case S_XP: + c = S_IX1P; + break; + } + } else { + switch(c) { + default: + aerr(); + + case S_X: + c = S_IX2; + break; + + case S_S: + c = S_SP2; + break; + + case S_XP: + c = S_IX2P; + break; + } + } + esp->e_mode = c; + } else { + esp->e_mode = S_EXT; + } + } + } + return (esp->e_mode); } - + /* * Enter admode() to search a specific addressing mode table * for a match. Return the addressing value on a match or @@ -135,22 +135,22 @@ int admode(sp) register struct adsym *sp; { - register char *ptr; - register int i; - register char *ips; - - ips = ip; - unget(getnb()); - - i = 0; - while ( *(ptr = &sp[i].a_str[0]) ) { - if (srch(ptr)) { - return(sp[i].a_val); - } - i++; - } - ip = ips; - return(0); + register char *ptr; + register int i; + register const char *ips; + + ips = ip; + unget(getnb()); + + i = 0; + while ( *(ptr = &sp[i].a_str[0]) ) { + if (srch(ptr)) { + return(sp[i].a_val); + } + i++; + } + ip = ips; + return(0); } /* @@ -160,26 +160,26 @@ int srch(str) register char *str; { - register char *ptr; - ptr = ip; - - while (*ptr && *str) { - if(ccase[*ptr & 0x007F] != ccase[*str & 0x007F]) - break; - ptr++; - str++; - } - if (ccase[*ptr & 0x007F] == ccase[*str & 0x007F]) { - ip = ptr; - return(1); - } - - if (!*str) - if (any(*ptr," \t\n,];")) { - ip = ptr; - return(1); - } - return(0); + register const char *ptr; + ptr = ip; + + while (*ptr && *str) { + if(ccase[*ptr & 0x007F] != ccase[*str & 0x007F]) + break; + ptr++; + str++; + } + if (ccase[*ptr & 0x007F] == ccase[*str & 0x007F]) { + ip = ptr; + return(1); + } + + if (!*str) + if (any(*ptr," \t\n,];")) { + ip = ptr; + return(1); + } + return(0); } /* @@ -190,16 +190,16 @@ any(c,str) int c; char*str; { - while (*str) - if(*str++ == c) - return(1); - return(0); + while (*str) + if(*str++ == c) + return(1); + return(0); } -struct adsym axs[] = { /* a, x, or s registers */ - { "a", S_A }, - { "x", S_X }, - { "s", S_S }, - { "x+", S_XP }, - { "", 0x00 } +struct adsym axs[] = { /* a, x, or s registers */ + { "a", S_A }, + { "x", S_X }, + { "s", S_S }, + { "x+", S_XP }, + { "", 0x00 } }; diff --git a/as/mcs51/Makefile.bcc b/as/mcs51/Makefile.bcc index 825a7a3b..a2a2f1c6 100644 --- a/as/mcs51/Makefile.bcc +++ b/as/mcs51/Makefile.bcc @@ -7,7 +7,8 @@ PRJDIR = ../.. ASOBJECTS = asmain.obj aslex.obj assubr.obj asnoice.obj \ asexpr.obj asdata.obj aslist.obj asout.obj \ i51ext.obj i51pst.obj i51mch.obj i51adr.obj \ - ../asxxsrc/strcmpi.obj ../asxxsrc/assym.obj + ../asxxsrc/strcmpi.obj ../asxxsrc/assym.obj \ + ../../support/Util/dbuf.obj ../../support/Util/dbuf_string.obj ASX8051 = $(PRJDIR)/bin/asx8051.exe diff --git a/as/mcs51/Makefile.in b/as/mcs51/Makefile.in index 279c5deb..393d25f9 100644 --- a/as/mcs51/Makefile.in +++ b/as/mcs51/Makefile.in @@ -40,19 +40,22 @@ LDFLAGS = @LDFLAGS@ OBJDIR = obj -ASXXLIB = $(srcdir)/../asxxsrc +UTILLIB = $(srcdir)/../../support/Util +UTILSRC = dbuf.c dbuf_string.c +UTILLIBOBJS = $(UTILSRC:%.c=$(OBJDIR)/%.o) +ASXXLIB = $(srcdir)/../asxxsrc ASXXLIBSRC = strcmpi.c assym.c aslex.c +ASXXLIBOBJS = $(ASXXLIBSRC:%.c=$(OBJDIR)/%.o) SRC = asmain.c assubr.c asnoice.c \ asexpr.c asdata.c aslist.c asout.c \ i51ext.c i51pst.c i51mch.c i51adr.c - -ASSOURCES = %(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c) - OBJS = $(SRC:%.c=$(OBJDIR)/%.o) -ASXXLIBOBJS = $(ASXXLIBSRC:%.c=$(OBJDIR)/%.o) -ASOBJECTS = $(OBJS) $(ASXXLIBOBJS) + +ASSOURCES = %(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c) $(UTILSRC:%.c=$(UTILLIB)/%.c) + +AASOBJECTS = $(OBJS) $(ASXXLIBOBJS) $(UTILLIBOBJS) ASX8051 = $(top_builddir)/bin/asx8051$(EXEEXT) diff --git a/as/mcs51/asdata.c b/as/mcs51/asdata.c index be5dd3d6..4a9dfdc0 100644 --- a/as/mcs51/asdata.c +++ b/as/mcs51/asdata.c @@ -109,10 +109,10 @@ char *ep; /* pointer into error list */ char eb[NERR]; /* array of generated error codes */ -char *ip; /* pointer into the assembler-source +const char *ip; /* pointer into the assembler-source * text line in ib[] */ -char ib[NINPUT]; /* assembler-source text line +const char *ib; /* assembler-source text line */ char *cp; /* pointer to assembler output * array cb[] diff --git a/as/mcs51/asexpr.c b/as/mcs51/asexpr.c index 4bef5594..a424d144 100644 --- a/as/mcs51/asexpr.c +++ b/as/mcs51/asexpr.c @@ -324,7 +324,7 @@ VOID term(register struct expr *esp) { register int c, n; - register char *jp; + register const char *jp; char id[NCPS]; struct sym *sp; struct tsym *tp; diff --git a/as/mcs51/asm.h b/as/mcs51/asm.h index 6ef17d3a..ac98e3ad 100644 --- a/as/mcs51/asm.h +++ b/as/mcs51/asm.h @@ -480,10 +480,10 @@ extern char *ep; /* pointer into error list */ extern char eb[NERR]; /* array of generated error codes */ -extern char *ip; /* pointer into the assembler-source +extern const char *ip; /* pointer into the assembler-source * text line in ib[] */ -extern char ib[NINPUT]; /* assembler-source text line +extern const char *ib; /* assembler-source text line */ extern char *cp; /* pointer to assembler output * array cb[] diff --git a/as/mcs51/asx8051.dsp b/as/mcs51/asx8051.dsp index 5b40ddb9..fdd57547 100644 --- a/as/mcs51/asx8051.dsp +++ b/as/mcs51/asx8051.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "../../support/Util" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -67,7 +67,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c -# ADD CPP /nologo /ML /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c +# ADD CPP /nologo /ML /W3 /GX /O2 /I "." /I "../../support/Util" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -124,6 +124,14 @@ SOURCE=..\asxxsrc\assym.c # End Source File # Begin Source File +SOURCE=..\..\support\Util\dbuf.c +# End Source File +# Begin Source File + +SOURCE=..\..\support\Util\dbuf_string.c +# End Source File +# Begin Source File + SOURCE=.\i51adr.c # End Source File # Begin Source File @@ -152,8 +160,20 @@ SOURCE=.\asm.h # End Source File # Begin Source File +SOURCE=..\..\support\Util\dbuf.h +# End Source File +# Begin Source File + +SOURCE=..\..\support\Util\dbuf_string.h +# End Source File +# Begin Source File + SOURCE=.\i8051.h # End Source File +# Begin Source File + +SOURCE=..\..\sdcc_vc.h +# End Source File # End Group # End Target # End Project diff --git a/as/mcs51/i51adr.c b/as/mcs51/i51adr.c index 62ef33dc..3657d3c4 100644 --- a/as/mcs51/i51adr.c +++ b/as/mcs51/i51adr.c @@ -19,34 +19,34 @@ extern int admode (struct adsym *); -struct adsym reg51[] = { /* R0 thru R7 registers */ -{ "R0", R0}, -{ "R1", R1}, -{ "R2", R2}, -{ "R3", R3}, -{ "R4", R4}, -{ "R5", R5}, -{ "R6", R6}, -{ "R7", R7}, -{ "A", A}, -{ "DPTR", DPTR}, -{ "PC", PC}, -{ "C", C}, -{ "AB", AB}, -{ "r0", R0}, -{ "r1", R1}, -{ "r2", R2}, -{ "r3", R3}, -{ "r4", R4}, -{ "r5", R5}, -{ "r6", R6}, -{ "r7", R7}, -{ "a", A}, -{ "dptr", DPTR}, -{ "pc", PC}, -{ "c", C}, -{ "ab", AB}, -{ "", 0x00} +struct adsym reg51[] = { /* R0 thru R7 registers */ +{ "R0", R0}, +{ "R1", R1}, +{ "R2", R2}, +{ "R3", R3}, +{ "R4", R4}, +{ "R5", R5}, +{ "R6", R6}, +{ "R7", R7}, +{ "A", A}, +{ "DPTR", DPTR}, +{ "PC", PC}, +{ "C", C}, +{ "AB", AB}, +{ "r0", R0}, +{ "r1", R1}, +{ "r2", R2}, +{ "r3", R3}, +{ "r4", R4}, +{ "r5", R5}, +{ "r6", R6}, +{ "r7", R7}, +{ "a", A}, +{ "dptr", DPTR}, +{ "pc", PC}, +{ "c", C}, +{ "ab", AB}, +{ "", 0x00} }; /* Classify argument as to address mode */ @@ -54,91 +54,91 @@ int addr(esp) register struct expr *esp; { - register int c; + register int c; register unsigned rd; - if ((c = getnb()) == '#') { - /* Immediate mode */ - expr(esp, 0); - esp->e_mode = S_IMMED; - } + if ((c = getnb()) == '#') { + /* Immediate mode */ + expr(esp, 0); + esp->e_mode = S_IMMED; + } else if (c == '@') { - /* choices are @R0, @R1, @DPTR, @A+PC, @A+DPTR */ - switch (reg()) { + /* choices are @R0, @R1, @DPTR, @A+PC, @A+DPTR */ + switch (reg()) { case R0: - esp->e_mode = S_AT_R; - esp->e_addr = R0; + esp->e_mode = S_AT_R; + esp->e_addr = R0; break; case R1: - esp->e_mode = S_AT_R; - esp->e_addr = R1; + esp->e_mode = S_AT_R; + esp->e_addr = R1; break; case DPTR: - esp->e_mode = S_AT_DP; - esp->e_addr = DPTR; + esp->e_mode = S_AT_DP; + esp->e_addr = DPTR; break; case A: - if (getnb() == '+') { - rd = reg(); + if (getnb() == '+') { + rd = reg(); if (rd == PC) { - esp->e_mode = S_AT_APC; - esp->e_addr = 0; - } else if (rd == DPTR) { - esp->e_mode = S_AT_ADP; - esp->e_addr = 0; - } else { - aerr(); + esp->e_mode = S_AT_APC; + esp->e_addr = 0; + } else if (rd == DPTR) { + esp->e_mode = S_AT_ADP; + esp->e_addr = 0; + } else { + aerr(); } } else - aerr(); + aerr(); break; } - esp->e_flag = 0; - esp->e_base.e_ap = NULL; - } + esp->e_flag = 0; + esp->e_base.e_ap = NULL; + } else if (c == '*') { - /* Force direct page */ - expr(esp, 0); - esp->e_mode = S_DIR; - if (esp->e_addr & ~0xFF) - err('d'); - } + /* Force direct page */ + expr(esp, 0); + esp->e_mode = S_DIR; + if (esp->e_addr & ~0xFF) + err('d'); + } else if (c == '/') { - /* Force inverted bit */ - expr(esp, 0); - esp->e_mode = S_NOT_BIT; - if (esp->e_addr & ~0xFF) - err('d'); - } + /* Force inverted bit */ + expr(esp, 0); + esp->e_mode = S_NOT_BIT; + if (esp->e_addr & ~0xFF) + err('d'); + } else { - unget(c); + unget(c); - /* try for register: A, AB, R0-R7, DPTR, PC, Cy */ - if ((esp->e_addr = admode(reg51)) != -1) { - switch (esp->e_addr) { + /* try for register: A, AB, R0-R7, DPTR, PC, Cy */ + if ((esp->e_addr = admode(reg51)) != -1) { + switch (esp->e_addr) { case A: - esp->e_mode = S_A; + esp->e_mode = S_A; break; case AB: - esp->e_mode = S_RAB; + esp->e_mode = S_RAB; break; case DPTR: - esp->e_mode = S_DPTR; + esp->e_mode = S_DPTR; break; case PC: - esp->e_mode = S_PC; + esp->e_mode = S_PC; break; case C: - esp->e_mode = S_C; + esp->e_mode = S_C; break; - default: - /* R0-R7 */ - esp->e_mode = S_REG; + default: + /* R0-R7 */ + esp->e_mode = S_REG; } - } else { - /* Must be an expression */ - expr(esp, 0); + } else { + /* Must be an expression */ + expr(esp, 0); if ((!esp->e_flag) && (esp->e_base.e_ap==NULL) && !(esp->e_addr & ~0xFF)) { @@ -146,9 +146,9 @@ register struct expr *esp; } else { esp->e_mode = S_EXT; } - } - } - return (esp->e_mode); + } + } + return (esp->e_mode); } @@ -159,51 +159,51 @@ int any(c,str) char c, *str; { - while (*str) - if(*str++ == c) - return(1); - return(0); + while (*str) + if(*str++ == c) + return(1); + return(0); } int srch(str) register char *str; { - register char *ptr; - ptr = ip; + register const char *ptr; + ptr = ip; -#if CASE_SENSITIVE - while (*ptr && *str) { - if(*ptr != *str) - break; - ptr++; - str++; - } - if (*ptr == *str) { - ip = ptr; - return(1); - } +#if CASE_SENSITIVE + while (*ptr && *str) { + if(*ptr != *str) + break; + ptr++; + str++; + } + if (*ptr == *str) { + ip = ptr; + return(1); + } #else - while (*ptr && *str) { - if(ccase[*ptr] != ccase[*str]) - break; - ptr++; - str++; - } - if (ccase[*ptr] == ccase[*str]) { - ip = ptr; - return(1); - } + while (*ptr && *str) { + if(ccase[*ptr] != ccase[*str]) + break; + ptr++; + str++; + } + if (ccase[*ptr] == ccase[*str]) { + ip = ptr; + return(1); + } #endif - if (!*str) - if (any(*ptr," \t\n,];")) { - ip = ptr; - return(1); - } - return(0); + if (!*str) + if (any(*ptr," \t\n,];")) { + ip = ptr; + return(1); + } + return(0); } - + /* * Enter admode() to search a specific addressing mode table * for a match. Return the addressing value on a match or @@ -213,17 +213,17 @@ int admode(sp) register struct adsym *sp; { - register char *ptr; - register int i; - unget(getnb()); - i = 0; - while ( *(ptr = (char *) &sp[i]) ) { - if (srch(ptr)) { - return(sp[i].a_val); - } - i++; - } - return(-1); + register char *ptr; + register int i; + unget(getnb()); + i = 0; + while ( *(ptr = (char *) &sp[i]) ) { + if (srch(ptr)) { + return(sp[i].a_val); + } + i++; + } + return(-1); } /* @@ -236,23 +236,23 @@ register struct adsym *sp; int reg() { - register struct mne *mp; - char id[NCPS]; + register struct mne *mp; + char id[NCPS]; - getid(id, -1); - if ((mp = mlookup(id))==NULL) { - aerr(); - return (-1); - } + getid(id, -1); + if ((mp = mlookup(id))==NULL) { + aerr(); + return (-1); + } switch (mp->m_type) { case S_A: case S_AB: case S_DPTR: case S_PC: case S_REG: - return (mp->m_valu); + return (mp->m_valu); - default: - return (-1); + default: + return (-1); } } diff --git a/as/z80/Makefile.bcc b/as/z80/Makefile.bcc index 177563b4..f5107635 100644 --- a/as/z80/Makefile.bcc +++ b/as/z80/Makefile.bcc @@ -9,7 +9,8 @@ CFLAGS = $(CFLAGS) -DINDEXLIB -DMLH_MAP -DSDK OBJECTS = asdata.obj asexpr.obj aslex.obj aslist.obj asmain.obj \ asout.obj assubr.obj z80adr.obj z80ext.obj \ z80mch.obj z80pst.obj \ - ../asxxsrc/strcmpi.obj ../asxxsrc/assym.obj + ../asxxsrc/strcmpi.obj ../asxxsrc/assym.obj ../asxxsrc/aslex.obj \ + ../../support/Util/dbuf.obj ../../support/Util/dbuf_string.obj TARGET = $(PRJDIR)/bin/as-z80.exe diff --git a/as/z80/Makefile.in b/as/z80/Makefile.in index 63360141..3e484a9f 100644 --- a/as/z80/Makefile.in +++ b/as/z80/Makefile.in @@ -7,20 +7,22 @@ include $(top_builddir)/Makefile.common OBJDIR = obj$(EXT) -ASXXLIB = $(srcdir)/../asxxsrc +UTILLIB = $(srcdir)/../../support/Util +UTILSRC = dbuf.c dbuf_string.c +UTILLIBOBJS = $(UTILSRC:%.c=$(OBJDIR)/%.o) +ASXXLIB = $(srcdir)/../asxxsrc ASXXLIBSRC = strcmpi.c assym.c aslex.c - -SRC = asdata.c asexpr.c aslist.c asmain.c asout.c \ - assubr.c z80adr.c z80ext.c z80mch.c z80pst.c - -ASSOURCES = $(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c) - ASXXLIBOBJS = $(ASXXLIBSRC:%.c=$(OBJDIR)/%.o) +SRC = asmain.c assubr.c \ + asexpr.c asdata.c aslist.c asout.c \ + z80ext.c z80pst.c z80mch.c z80adr.c OBJS = $(SRC:%.c=$(OBJDIR)/%.o) -ASOBJECTS = $(OBJS) $(ASXXLIBOBJS) +ASSOURCES = %(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c) $(UTILSRC:%.c=$(UTILLIB)/%.c) + +AASOBJECTS = $(OBJS) $(ASXXLIBOBJS) $(UTILLIBOBJS) BINS = $(BUILDDIR)/as$(EXT)$(EXEEXT) diff --git a/as/z80/as_gbz80.dsp b/as/z80/as_gbz80.dsp index 4aba0c35..f960d441 100644 --- a/as/z80/as_gbz80.dsp +++ b/as/z80/as_gbz80.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "../../support/Util" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -67,7 +67,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c -# ADD CPP /nologo /ML /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c +# ADD CPP /nologo /ML /W3 /GX /O2 /I "." /I "../../support/Util" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -126,6 +126,14 @@ SOURCE=..\asxxsrc\assym.c # End Source File # Begin Source File +SOURCE=..\..\support\Util\dbuf.c +# End Source File +# Begin Source File + +SOURCE=..\..\support\Util\dbuf_string.c +# End Source File +# Begin Source File + SOURCE=..\asxxsrc\strcmpi.c # End Source File # Begin Source File @@ -162,6 +170,14 @@ SOURCE=.\asm.h # End Source File # Begin Source File +SOURCE=..\..\support\Util\dbuf.h +# End Source File +# Begin Source File + +SOURCE=..\..\support\Util\dbuf_string.h +# End Source File +# Begin Source File + SOURCE=.\string.h # End Source File # Begin Source File diff --git a/as/z80/as_z80.dsp b/as/z80/as_z80.dsp index b4b706fe..23aa96ea 100644 --- a/as/z80/as_z80.dsp +++ b/as/z80/as_z80.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "../../support/Util" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FR /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -67,7 +67,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c -# ADD CPP /nologo /ML /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c +# ADD CPP /nologo /ML /W3 /GX /O2 /I "." /I "../../support/Util" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "MLH_MAP" /D "SDK" /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -120,6 +120,14 @@ SOURCE=..\asxxsrc\assym.c # End Source File # Begin Source File +SOURCE=..\..\support\Util\dbuf.c +# End Source File +# Begin Source File + +SOURCE=..\..\support\Util\dbuf_string.c +# End Source File +# Begin Source File + SOURCE=..\asxxsrc\strcmpi.c # End Source File # Begin Source File @@ -152,6 +160,14 @@ SOURCE=.\asm.h # End Source File # Begin Source File +SOURCE=..\..\support\Util\dbuf.h +# End Source File +# Begin Source File + +SOURCE=..\..\support\Util\dbuf_string.h +# End Source File +# Begin Source File + SOURCE=.\string.h # End Source File # Begin Source File diff --git a/as/z80/asdata.c b/as/z80/asdata.c index 59ddc13a..1f7add6b 100644 --- a/as/z80/asdata.c +++ b/as/z80/asdata.c @@ -101,10 +101,10 @@ char *ep; /* pointer into error list */ char eb[NERR]; /* array of generated error codes */ -char *ip; /* pointer into the assembler-source +const char *ip; /* pointer into the assembler-source * text line in ib[] */ -char ib[NINPUT]; /* assembler-source text line +const char *ib; /* assembler-source text line */ char *cp; /* pointer to assembler output * array cb[] diff --git a/as/z80/asexpr.c b/as/z80/asexpr.c index 2664550d..58fc0776 100644 --- a/as/z80/asexpr.c +++ b/as/z80/asexpr.c @@ -15,68 +15,68 @@ #include "asm.h" -/*)Module asexpr.c - * - * The module asexpr.c contains the routines to evaluate - * arithmetic/numerical expressions. The functions in - * asexpr.c perform a recursive evaluation of the arithmetic - * expression read from the assembler-source text line. - * The expression may include binary/unary operators, brackets, - * symbols, labels, and constants in hexadecimal, decimal, octal - * and binary. Arithmetic operations are prioritized and - * evaluated by normal arithmetic conventions. - * - * asexpr.c contains the following functions: - * VOID abscheck() - * Addr_T absexpr() - * VOID clrexpr() - * int digit() - * VOID expr() - * int oprio() - * VOID term() - * - * asexpr.c contains no local/static variables +/*)Module asexpr.c + * + * The module asexpr.c contains the routines to evaluate + * arithmetic/numerical expressions. The functions in + * asexpr.c perform a recursive evaluation of the arithmetic + * expression read from the assembler-source text line. + * The expression may include binary/unary operators, brackets, + * symbols, labels, and constants in hexadecimal, decimal, octal + * and binary. Arithmetic operations are prioritized and + * evaluated by normal arithmetic conventions. + * + * asexpr.c contains the following functions: + * VOID abscheck() + * Addr_T absexpr() + * VOID clrexpr() + * int digit() + * VOID expr() + * int oprio() + * VOID term() + * + * asexpr.c contains no local/static variables */ -/*)Function VOID expr(esp, n) - * - * expr * esp pointer to an expr structure - * int n a firewall priority; all top - * level calls (from the user) - * should be made with n set to 0. - * - * The function expr() evaluates an expression and - * stores its value and relocation information into - * the expr structure supplied by the user. - * - * local variables: - * int c current assembler-source - * text character - * int p current operator priority - * area * ap pointer to an area structure - * exp re internal expr structure - * - * global variables: - * char ctype[] array of character types, one per - * ASCII character - * - * functions called: - * VOID abscheck() asexpr.c - * VOID clrexpr() asexpr.c - * VOID expr() asexpr.c - * int getnb() aslex.c - * int oprio() asexpr.c - * VOID qerr() assubr.c - * VOID rerr() assubr.c - * VOID term() asexpr.c - * VOID unget() aslex.c - * - * - * side effects: - * An expression is evaluated modifying the user supplied - * expr structure, a sym structure maybe created for an - * undefined symbol, and the parse of the expression may - * terminate if a 'q' error occurs. +/*)Function VOID expr(esp, n) + * + * expr * esp pointer to an expr structure + * int n a firewall priority; all top + * level calls (from the user) + * should be made with n set to 0. + * + * The function expr() evaluates an expression and + * stores its value and relocation information into + * the expr structure supplied by the user. + * + * local variables: + * int c current assembler-source + * text character + * int p current operator priority + * area * ap pointer to an area structure + * exp re internal expr structure + * + * global variables: + * char ctype[] array of character types, one per + * ASCII character + * + * functions called: + * VOID abscheck() asexpr.c + * VOID clrexpr() asexpr.c + * VOID expr() asexpr.c + * int getnb() aslex.c + * int oprio() asexpr.c + * VOID qerr() assubr.c + * VOID rerr() assubr.c + * VOID term() asexpr.c + * VOID unget() aslex.c + * + * + * side effects: + * An expression is evaluated modifying the user supplied + * expr structure, a sym structure maybe created for an + * undefined symbol, and the parse of the expression may + * terminate if a 'q' error occurs. */ VOID @@ -90,31 +90,31 @@ int n; term(esp); while (ctype[c = getnb()] & BINOP) { - /* - * Handle binary operators + - * / & | % ^ << >> - */ + /* + * Handle binary operators + - * / & | % ^ << >> + */ if ((p = oprio(c)) <= n) break; if ((c == '>' || c == '<') && c != get()) qerr(); - clrexpr(&re); + clrexpr(&re); expr(&re, p); - esp->e_rlcf |= re.e_rlcf; + esp->e_rlcf |= re.e_rlcf; if (c == '+') { - /* - * esp + re, at least one must be absolute - */ + /* + * esp + re, at least one must be absolute + */ if (esp->e_base.e_ap == NULL) { - /* - * esp is absolute (constant), - * use area from re - */ + /* + * esp is absolute (constant), + * use area from re + */ esp->e_base.e_ap = re.e_base.e_ap; } else if (re.e_base.e_ap) { - /* - * re should be absolute (constant) - */ + /* + * re should be absolute (constant) + */ rerr(); } if (esp->e_flag && re.e_flag) @@ -124,9 +124,9 @@ int n; esp->e_addr += re.e_addr; } else if (c == '-') { - /* - * esp - re - */ + /* + * esp - re + */ if ((ap = re.e_base.e_ap) != NULL) { if (esp->e_base.e_ap == ap) { esp->e_base.e_ap = NULL; @@ -138,9 +138,9 @@ int n; rerr(); esp->e_addr -= re.e_addr; } else { - /* - * Both operands (esp and re) must be constants - */ + /* + * Both operands (esp and re) must be constants + */ abscheck(esp); abscheck(&re); switch (c) { @@ -177,35 +177,35 @@ int n; esp->e_addr >>= re.e_addr; break; - default: - qerr(); - break; + default: + qerr(); + break; } } } unget(c); } -/*)Function Addr_T absexpr() +/*)Function Addr_T absexpr() * - * The function absexpr() evaluates an expression, verifies it - * is absolute (i.e. not position dependent or relocatable), and - * returns its value. + * The function absexpr() evaluates an expression, verifies it + * is absolute (i.e. not position dependent or relocatable), and + * returns its value. * - * local variables: - * expr e expr structure + * local variables: + * expr e expr structure * - * global variables: - * none + * global variables: + * none * - * functions called: - * VOID abscheck() asexpr.c - * VOID clrexpr() asexpr.c - * VOID expr() asexpr.c + * functions called: + * VOID abscheck() asexpr.c + * VOID clrexpr() asexpr.c + * VOID expr() asexpr.c * - * side effects: - * If the expression is not absolute then - * a 'r' error is reported. + * side effects: + * If the expression is not absolute then + * a 'r' error is reported. */ Addr_T @@ -213,55 +213,55 @@ absexpr() { struct expr e; - clrexpr(&e); - expr(&e, 0); - abscheck(&e); - return (e.e_addr); + clrexpr(&e); + expr(&e, 0); + abscheck(&e); + return (e.e_addr); } -/*)Function VOID term(esp) - * - * expr * esp pointer to an expr structure - * - * The function term() evaluates a single constant - * or symbol value prefaced by any unary operator - * ( +, -, ~, ', ", >, or < ). This routine is also - * responsible for setting the relocation type to symbol - * based (e.flag != 0) on global references. - * - * local variables: - * int c current character - * char id[] symbol name - * char * jp pointer to assembler-source text - * int n constant evaluation running sum - * int r current evaluation radix - * sym * sp pointer to a sym structure - * tsym * tp pointer to a tsym structure - * int v current digit evaluation - * - * global variables: - * char ctype[] array of character types, one per - * ASCII character - * sym * symp pointer to a symbol structure - * - * functions called: - * VOID abscheck() asexpr.c - * int digit() asexpr.c - * VOID err() assubr.c - * VOID expr() asexpr.c - * int is_abs() asexpr.c - * int get() aslex.c - * VOID getid() aslex.c - * int getmap() aslex.c - * int getnb() aslex.c - * sym * lookup() assym.c - * VOID qerr() assubr.c - * VOID unget() aslex.c - * - * side effects: - * An arithmetic term is evaluated, a symbol structure - * may be created, term evaluation may be terminated - * by a 'q' error. +/*)Function VOID term(esp) + * + * expr * esp pointer to an expr structure + * + * The function term() evaluates a single constant + * or symbol value prefaced by any unary operator + * ( +, -, ~, ', ", >, or < ). This routine is also + * responsible for setting the relocation type to symbol + * based (e.flag != 0) on global references. + * + * local variables: + * int c current character + * char id[] symbol name + * char * jp pointer to assembler-source text + * int n constant evaluation running sum + * int r current evaluation radix + * sym * sp pointer to a sym structure + * tsym * tp pointer to a tsym structure + * int v current digit evaluation + * + * global variables: + * char ctype[] array of character types, one per + * ASCII character + * sym * symp pointer to a symbol structure + * + * functions called: + * VOID abscheck() asexpr.c + * int digit() asexpr.c + * VOID err() assubr.c + * VOID expr() asexpr.c + * int is_abs() asexpr.c + * int get() aslex.c + * VOID getid() aslex.c + * int getmap() aslex.c + * int getnb() aslex.c + * sym * lookup() assym.c + * VOID qerr() assubr.c + * VOID unget() aslex.c + * + * side effects: + * An arithmetic term is evaluated, a symbol structure + * may be created, term evaluation may be terminated + * by a 'q' error. */ VOID @@ -269,23 +269,23 @@ term(esp) register struct expr *esp; { register int c, n; - register char *jp; + register const char *jp; char id[NCPS]; struct sym *sp; struct tsym *tp; int r = 0, v; c = getnb(); - /* - * Discard the unary '+' at this point and - * also any reference to numerical arguments - * associated with the '#' prefix. - */ + /* + * Discard the unary '+' at this point and + * also any reference to numerical arguments + * associated with the '#' prefix. + */ while (c == '+' || c == '#') { c = getnb(); } - /* - * Evaluate all binary operators - * by recursively calling expr(). - */ + /* + * Evaluate all binary operators + * by recursively calling expr(). + */ if (c == LFTERM) { expr(esp, 0); if (getnb() != RTTERM) @@ -322,28 +322,28 @@ register struct expr *esp; } if (c == '>' || c == '<') { expr(esp, 100); - if (is_abs (esp)) { - /* - * evaluate msb/lsb directly - */ - if (c == '>') - esp->e_addr >>= 8; - esp->e_addr &= 0377; - return; - } else { - /* - * let linker perform msb/lsb, lsb is default - */ - esp->e_rlcf |= R_BYT2; - if (c == '>') - esp->e_rlcf |= R_MSB; - return; - } + if (is_abs (esp)) { + /* + * evaluate msb/lsb directly + */ + if (c == '>') + esp->e_addr >>= 8; + esp->e_addr &= 0377; + return; + } else { + /* + * let linker perform msb/lsb, lsb is default + */ + esp->e_rlcf |= R_BYT2; + if (c == '>') + esp->e_rlcf |= R_MSB; + return; + } } - /* - * Evaluate digit sequences as local symbols - * if followed by a '$' or as constants. - */ + /* + * Evaluate digit sequences as local symbols + * if followed by a '$' or as constants. + */ if (ctype[c] & DIGIT) { esp->e_mode = S_USER; jp = ip; @@ -409,57 +409,57 @@ register struct expr *esp; esp->e_addr = n; return; } - /* - * Evaluate '$' sequences as a temporary radix - * if followed by a '%', '&', '#', or '$'. - */ + /* + * Evaluate '$' sequences as a temporary radix + * if followed by a '%', '&', '#', or '$'. + */ if (c == '$') { c = get(); if (c == '%' || c == '&' || c == '#' || c == '$') { - switch (c) { - case '%': - r = 2; - break; - case '&': - r = 8; - break; - case '#': - r = 10; - break; - case '$': - r = 16; - break; - default: - break; - } - c = get(); - n = 0; - while ((v = digit(c, r)) >= 0) { - n = r*n + v; - c = get(); - } - unget(c); - esp->e_mode = S_USER; - esp->e_addr = n; - return; - } - unget(c); - c = '$'; + switch (c) { + case '%': + r = 2; + break; + case '&': + r = 8; + break; + case '#': + r = 10; + break; + case '$': + r = 16; + break; + default: + break; + } + c = get(); + n = 0; + while ((v = digit(c, r)) >= 0) { + n = r*n + v; + c = get(); + } + unget(c); + esp->e_mode = S_USER; + esp->e_addr = n; + return; + } + unget(c); + c = '$'; } - /* - * Evaluate symbols and labels - */ + /* + * Evaluate symbols and labels + */ if (ctype[c] & LETTER) { esp->e_mode = S_USER; getid(id, c); sp = lookup(id); if (sp->s_type == S_NEW) { - if (sp->s_flag&S_GBL) { - esp->e_flag = 1; - esp->e_base.e_sp = sp; - return; - } - err('u'); + if (sp->s_flag&S_GBL) { + esp->e_flag = 1; + esp->e_base.e_sp = sp; + return; + } + err('u'); } else { esp->e_mode = sp->s_type; esp->e_addr = sp->s_addr; @@ -467,33 +467,33 @@ register struct expr *esp; } return; } - /* - * Else not a term. - */ + /* + * Else not a term. + */ qerr(); } -/*)Function int digit(c, r) +/*)Function int digit(c, r) * - * int c digit character - * int r current radix + * int c digit character + * int r current radix * - * The function digit() returns the value of c - * in the current radix r. If the c value is not - * a number of the current radix then a -1 is returned. + * The function digit() returns the value of c + * in the current radix r. If the c value is not + * a number of the current radix then a -1 is returned. * - * local variables: - * none + * local variables: + * none * - * global variables: - * char ctype[] array of character types, one per - * ASCII character + * global variables: + * char ctype[] array of character types, one per + * ASCII character * - * functions called: - * none + * functions called: + * none * - * side effects: - * none + * side effects: + * none */ int @@ -524,31 +524,31 @@ register int c, r; return (-1); } -/*)Function VOID abscheck(esp) +/*)Function VOID abscheck(esp) * - * expr * esp pointer to an expr structure + * expr * esp pointer to an expr structure * - * The function abscheck() tests the evaluation of an - * expression to verify it is absolute. If the evaluation - * is relocatable then an 'r' error is noted and the expression - * made absolute. + * The function abscheck() tests the evaluation of an + * expression to verify it is absolute. If the evaluation + * is relocatable then an 'r' error is noted and the expression + * made absolute. * - * Note: The area type (i.e. ABS) is not checked because - * the linker can be told to explicitly relocate an - * absolute area. + * Note: The area type (i.e. ABS) is not checked because + * the linker can be told to explicitly relocate an + * absolute area. * - * local variables: - * none + * local variables: + * none * - * global variables: - * none + * global variables: + * none * - * functions called: - * VOID rerr() assubr.c + * functions called: + * VOID rerr() assubr.c * - * side effects: - * The expression may be changed to absolute and the - * 'r' error invoked. + * side effects: + * The expression may be changed to absolute and the + * 'r' error invoked. */ VOID @@ -562,29 +562,29 @@ register struct expr *esp; } } -/*)Function int is_abs(esp) +/*)Function int is_abs(esp) * - * expr * esp pointer to an expr structure + * expr * esp pointer to an expr structure * - * The function is_abs() tests the evaluation of an - * expression to verify it is absolute. If the evaluation - * is absolute then 1 is returned, else 0 is returned. + * The function is_abs() tests the evaluation of an + * expression to verify it is absolute. If the evaluation + * is absolute then 1 is returned, else 0 is returned. * - * Note: The area type (i.e. ABS) is not checked because - * the linker can be told to explicitly relocate an - * absolute area. + * Note: The area type (i.e. ABS) is not checked because + * the linker can be told to explicitly relocate an + * absolute area. * - * local variables: - * none + * local variables: + * none * - * global variables: - * none + * global variables: + * none * - * functions called: - * none + * functions called: + * none * - * side effects: - * none + * side effects: + * none */ int @@ -592,31 +592,31 @@ is_abs (esp) register struct expr *esp; { if (esp->e_flag || esp->e_base.e_ap) { - return(0); + return(0); } - return(1); + return(1); } -/*)Function int oprio(c) +/*)Function int oprio(c) * - * int c operator character + * int c operator character * - * The function oprio() returns a relative priority - * for all valid unary and binary operators. + * The function oprio() returns a relative priority + * for all valid unary and binary operators. * - * local variables: - * none + * local variables: + * none * - * global variables: - * none + * global variables: + * none * - * functions called: - * none + * functions called: + * none * - * side effects: - * none + * side effects: + * none */ - + int oprio(c) register int c; @@ -636,32 +636,32 @@ register int c; return (0); } -/*)Function VOID clrexpr(esp) +/*)Function VOID clrexpr(esp) * - * expr * esp pointer to expression structure + * expr * esp pointer to expression structure * - * The function clrexpr() clears the expression structure. + * The function clrexpr() clears the expression structure. * - * local variables: - * none + * local variables: + * none * - * global variables: - * none + * global variables: + * none * - * functions called: - * none + * functions called: + * none * - * side effects: - * expression structure cleared. + * side effects: + * expression structure cleared. */ - + VOID clrexpr(esp) register struct expr *esp; { - esp->e_mode = 0; - esp->e_flag = 0; - esp->e_addr = 0; - esp->e_base.e_ap = NULL; - esp->e_rlcf = 0; + esp->e_mode = 0; + esp->e_flag = 0; + esp->e_addr = 0; + esp->e_base.e_ap = NULL; + esp->e_rlcf = 0; } diff --git a/as/z80/aslist.c b/as/z80/aslist.c index fa6f3b69..0a8293bb 100644 --- a/as/z80/aslist.c +++ b/as/z80/aslist.c @@ -600,7 +600,6 @@ lstsym(fp) FILE *fp; { register int c, i, j, k; - register char *ptr; int nmsym, narea; struct sym *sp; struct sym **p; diff --git a/as/z80/asm.h b/as/z80/asm.h index af0c054a..b403e734 100644 --- a/as/z80/asm.h +++ b/as/z80/asm.h @@ -403,10 +403,10 @@ extern char *ep; /* pointer into error list */ extern char eb[NERR]; /* array of generated error codes */ -extern char *ip; /* pointer into the assembler-source +extern const char *ip; /* pointer into the assembler-source * text line in ib[] */ -extern char ib[NINPUT]; /* assembler-source text line +extern const char *ib; /* assembler-source text line */ extern char *cp; /* pointer to assembler output * array cb[] diff --git a/as/z80/z80adr.c b/as/z80/z80adr.c index 58594b01..f4b12afc 100644 --- a/as/z80/z80adr.c +++ b/as/z80/z80adr.c @@ -26,87 +26,87 @@ * * This addr(esp) routine performs the following addressing decoding: * - * address mode flag addr base - * #n S_IMMED 0 n NULL - * label s_type ---- s_addr s_area - * [REG] S_IND+icode 0 0 NULL - * [label] S_INDM ---- s_addr s_area - * offset[REG] S_IND+icode ---- offset ---- + * address mode flag addr base + * #n S_IMMED 0 n NULL + * label s_type ---- s_addr s_area + * [REG] S_IND+icode 0 0 NULL + * [label] S_INDM ---- s_addr s_area + * offset[REG] S_IND+icode ---- offset ---- */ int addr(esp) register struct expr *esp; { - register int c, mode = 0, indx; + register int c, mode = 0, indx; - if ((c = getnb()) == '#') { - expr(esp, 0); - esp->e_mode = S_IMMED; - } else - if (c == LFIND) { - if ((indx = admode(R8)) != 0) { - mode = S_INDB; - } else - if ((indx = admode(R16)) != 0) { - mode = S_INDR; - } else - if ((indx = admode(R8X)) != 0) { - mode = S_R8X; - aerr(); - } else - if ((indx = admode(R16X)) != 0) { - mode = S_R16X; - aerr(); - } else { - expr(esp, 0); - esp->e_mode = S_INDM; - } - if (indx) { - esp->e_mode = (mode + indx)&0xFF; - esp->e_base.e_ap = NULL; - } - if ((c = getnb()) != RTIND) - qerr(); - } else { - unget(c); - if ((indx = admode(R8)) != 0) { - mode = S_R8; - } else - if ((indx = admode(R16)) != 0) { - mode = S_R16; - } else - if ((indx = admode(R8X)) != 0) { - mode = S_R8X; - } else - if ((indx = admode(R16X)) != 0) { - mode = S_R16X; - } else { - expr(esp, 0); - esp->e_mode = S_USER; - } - if (indx) { - esp->e_addr = indx&0xFF; - esp->e_mode = mode; - esp->e_base.e_ap = NULL; - } - if ((c = getnb()) == LFIND) { + if ((c = getnb()) == '#') { + expr(esp, 0); + esp->e_mode = S_IMMED; + } else + if (c == LFIND) { + if ((indx = admode(R8)) != 0) { + mode = S_INDB; + } else + if ((indx = admode(R16)) != 0) { + mode = S_INDR; + } else + if ((indx = admode(R8X)) != 0) { + mode = S_R8X; + aerr(); + } else + if ((indx = admode(R16X)) != 0) { + mode = S_R16X; + aerr(); + } else { + expr(esp, 0); + esp->e_mode = S_INDM; + } + if (indx) { + esp->e_mode = (mode + indx)&0xFF; + esp->e_base.e_ap = NULL; + } + if ((c = getnb()) != RTIND) + qerr(); + } else { + unget(c); + if ((indx = admode(R8)) != 0) { + mode = S_R8; + } else + if ((indx = admode(R16)) != 0) { + mode = S_R16; + } else + if ((indx = admode(R8X)) != 0) { + mode = S_R8X; + } else + if ((indx = admode(R16X)) != 0) { + mode = S_R16X; + } else { + expr(esp, 0); + esp->e_mode = S_USER; + } + if (indx) { + esp->e_addr = indx&0xFF; + esp->e_mode = mode; + esp->e_base.e_ap = NULL; + } + if ((c = getnb()) == LFIND) { #ifndef GAMEBOY - if ((indx=admode(R16))!=0 - && ((indx&0xFF)==IX || (indx&0xFF)==IY)) { + if ((indx=admode(R16))!=0 + && ((indx&0xFF)==IX || (indx&0xFF)==IY)) { #else /* GAMEBOY */ - if ((indx=admode(R16))!=0) { + if ((indx=admode(R16))!=0) { #endif /* GAMEBOY */ - esp->e_mode = S_INDR + (indx&0xFF); - } else { - aerr(); - } - if ((c = getnb()) != RTIND) - qerr(); - } else { - unget(c); - } - } - return (esp->e_mode); + esp->e_mode = S_INDR + (indx&0xFF); + } else { + aerr(); + } + if ((c = getnb()) != RTIND) + qerr(); + } else { + unget(c); + } + } + return (esp->e_mode); } /* @@ -118,22 +118,22 @@ int admode(sp) register struct adsym *sp; { - register char *ptr; - register int i; - register char *ips; + register char *ptr; + register int i; + register const char *ips; - ips = ip; - unget(getnb()); + ips = ip; + unget(getnb()); - i = 0; - while ( *(ptr = (char *) &sp[i]) ) { - if (srch(ptr)) { - return(sp[i].a_val); - } - i++; - } - ip = ips; - return(0); + i = 0; + while ( *(ptr = (char *) &sp[i]) ) { + if (srch(ptr)) { + return(sp[i].a_val); + } + i++; + } + ip = ips; + return(0); } /* @@ -143,39 +143,39 @@ int srch(str) register char *str; { - register char *ptr; - ptr = ip; + register const char *ptr; + ptr = ip; -#if CASE_SENSITIVE - while (*ptr && *str) { - if (*ptr != *str) - break; - ptr++; - str++; - } - if (*ptr == *str) { - ip = ptr; - return(1); - } +#if CASE_SENSITIVE + while (*ptr && *str) { + if (*ptr != *str) + break; + ptr++; + str++; + } + if (*ptr == *str) { + ip = ptr; + return(1); + } #else - while (*ptr && *str) { - if (ccase[(unsigned char)(*ptr)] != ccase[(unsigned char)(*str)]) - break; - ptr++; - str++; - } - if (ccase[(unsigned char)(*ptr)] == ccase[(unsigned char)(*str)]) { - ip = ptr; - return(1); - } + while (*ptr && *str) { + if (ccase[(unsigned char)(*ptr)] != ccase[(unsigned char)(*str)]) + break; + ptr++; + str++; + } + if (ccase[(unsigned char)(*ptr)] == ccase[(unsigned char)(*str)]) { + ip = ptr; + return(1); + } #endif - if (!*str) - if (any(*ptr," \t\n,);")) { - ip = ptr; - return(1); - } - return(0); + if (!*str) + if (any(*ptr," \t\n,);")) { + ip = ptr; + return(1); + } + return(0); } /* @@ -185,101 +185,101 @@ int any(c,str) char c, *str; { - while (*str) - if(*str++ == c) - return(1); - return(0); + while (*str) + if(*str++ == c) + return(1); + return(0); } /* * Registers */ -struct adsym R8[] = { - { "b", B|0400 }, - { "c", C|0400 }, - { "d", D|0400 }, - { "e", E|0400 }, - { "h", H|0400 }, - { "l", L|0400 }, - { "a", A|0400 }, - { "B", B|0400 }, - { "C", C|0400 }, - { "D", D|0400 }, - { "E", E|0400 }, - { "H", H|0400 }, - { "L", L|0400 }, - { "A", A|0400 }, - { "", 000 } +struct adsym R8[] = { + { "b", B|0400 }, + { "c", C|0400 }, + { "d", D|0400 }, + { "e", E|0400 }, + { "h", H|0400 }, + { "l", L|0400 }, + { "a", A|0400 }, + { "B", B|0400 }, + { "C", C|0400 }, + { "D", D|0400 }, + { "E", E|0400 }, + { "H", H|0400 }, + { "L", L|0400 }, + { "A", A|0400 }, + { "", 000 } }; -struct adsym R8X[] = { - { "i", I|0400 }, - { "r", R|0400 }, - { "I", I|0400 }, - { "R", R|0400 }, - { "", 000 } +struct adsym R8X[] = { + { "i", I|0400 }, + { "r", R|0400 }, + { "I", I|0400 }, + { "R", R|0400 }, + { "", 000 } }; -struct adsym R16[] = { - { "bc", BC|0400 }, - { "de", DE|0400 }, - { "hl", HL|0400 }, - { "sp", SP|0400 }, - { "BC", BC|0400 }, - { "DE", DE|0400 }, - { "HL", HL|0400 }, - { "SP", SP|0400 }, +struct adsym R16[] = { + { "bc", BC|0400 }, + { "de", DE|0400 }, + { "hl", HL|0400 }, + { "sp", SP|0400 }, + { "BC", BC|0400 }, + { "DE", DE|0400 }, + { "HL", HL|0400 }, + { "SP", SP|0400 }, #ifndef GAMEBOY - { "ix", IX|0400 }, - { "iy", IY|0400 }, - { "IX", IX|0400 }, - { "IY", IY|0400 }, + { "ix", IX|0400 }, + { "iy", IY|0400 }, + { "IX", IX|0400 }, + { "IY", IY|0400 }, #else /* GAMEBOY */ - { "hl-", HLD|0400 }, - { "hl+", HLI|0400 }, - { "hld", HLD|0400 }, - { "hli", HLI|0400 }, - { "HL-", HLD|0400 }, - { "HL+", HLI|0400 }, - { "HLD", HLD|0400 }, - { "HLI", HLI|0400 }, + { "hl-", HLD|0400 }, + { "hl+", HLI|0400 }, + { "hld", HLD|0400 }, + { "hli", HLI|0400 }, + { "HL-", HLD|0400 }, + { "HL+", HLI|0400 }, + { "HLD", HLD|0400 }, + { "HLI", HLI|0400 }, #endif /* GAMEBOY */ - { "", 000 } + { "", 000 } }; -struct adsym R16X[] = { - { "af", AF|0400 }, +struct adsym R16X[] = { + { "af", AF|0400 }, { "AF", AF|0400 }, #ifndef GAMEBOY - { "af'", AF|0400 }, - { "AF'", AF|0400 }, + { "af'", AF|0400 }, + { "AF'", AF|0400 }, #endif /* GAMEBOY */ - { "", 000 } + { "", 000 } }; /* * Conditional definitions */ -struct adsym CND[] = { - { "NZ", NZ|0400 }, - { "Z", Z |0400 }, - { "NC", NC|0400 }, - { "C", CS|0400 }, - { "nz", NZ|0400 }, - { "z", Z |0400 }, - { "nc", NC|0400 }, - { "c", CS|0400 }, +struct adsym CND[] = { + { "NZ", NZ|0400 }, + { "Z", Z |0400 }, + { "NC", NC|0400 }, + { "C", CS|0400 }, + { "nz", NZ|0400 }, + { "z", Z |0400 }, + { "nc", NC|0400 }, + { "c", CS|0400 }, #ifndef GAMEBOY - { "PO", PO|0400 }, - { "PE", PE|0400 }, - { "P", P |0400 }, - { "M", M |0400 }, - { "po", PO|0400 }, - { "pe", PE|0400 }, - { "p", P |0400 }, - { "m", M |0400 }, + { "PO", PO|0400 }, + { "PE", PE|0400 }, + { "P", P |0400 }, + { "M", M |0400 }, + { "po", PO|0400 }, + { "pe", PE|0400 }, + { "p", P |0400 }, + { "m", M |0400 }, #endif /* GAMEBOY */ - { "", 000 } + { "", 000 } }; diff --git a/src/SDCCasm.c b/src/SDCCasm.c index b8ce3b39..08d37303 100644 --- a/src/SDCCasm.c +++ b/src/SDCCasm.c @@ -247,6 +247,7 @@ printILine (iCode *ic) { char *verbalICode; struct dbuf_s tmpBuf; + size_t len; iCodeTable *icTab = getTableEntry (ic->op); dbuf_init (&tmpBuf, 1024); @@ -259,13 +260,15 @@ printILine (iCode *ic) icTab->iCodePrint (&tmpBuf, ic, icTab->printName); } + len = dbuf_get_length (&tmpBuf); + /* null terminate the buffer */ dbuf_c_str (&tmpBuf); verbalICode = dbuf_detach (&tmpBuf); /* kill the trailing NL */ - if ('\n' == verbalICode[strlen(verbalICode) - 1]) - verbalICode[strlen(verbalICode) - 1] = '\0'; + if (len > 0 && '\n' == verbalICode[len - 1]) + verbalICode[--len] = '\0'; /* and throw it up */ return verbalICode; @@ -295,7 +298,7 @@ skipLine (FILE *infp) /* EOF in the middle of the line */ is_eof = 1; return 1; - } + } else return 0; } @@ -315,6 +318,7 @@ printCLine (const char *srcFile, int lineno) static struct dbuf_s lastSrcFile; static char dbufInitialized = 0; static int inLineNo = 0; + size_t len; if (!dbufInitialized) { @@ -374,17 +378,16 @@ printCLine (const char *srcFile, int lineno) } /* get the line */ - if (dbuf_getline (&line, inFile)) + if (0 != (len = dbuf_getline (&line, inFile))) { const char *inLineString = dbuf_c_str (&line); - size_t len = strlen (inLineString); ++inLineNo; /* remove the trailing NL */ - if ('\n' == inLineString[len - 1]) + if (len > 0 &&'\n' == inLineString[len - 1]) { - dbuf_set_length (&line, len - 1); + dbuf_set_length (&line, --len); inLineString = dbuf_c_str (&line); } -- 2.30.2