* 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 <borut.razem AT siol.net>
#include <stdio.h>
#include <setjmp.h>
#include <string.h>
+#include "dbuf_string.h"
#include "asm.h"
/*)Module aslex.c
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
* 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
* 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
*/
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()
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
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)
# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "." /I "../../support/Util" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
# ADD RSC /l 0x409 /d "NDEBUG"\r
BSC32=bscmake.exe\r
# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /U "." /YX /FD /GZ /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "../../support/Util" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
# ADD RSC /l 0x409 /d "_DEBUG"\r
BSC32=bscmake.exe\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\support\Util\dbuf.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.c\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\m08adr.c\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\support\Util\dbuf.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\m6808.h\r
# End Source File\r
# End Group\r
* 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
*/
#include <string.h>
#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'
+};
- /* asexpr.c */
+ /* asexpr.c */
/*
* (C) Copyright 1989-1995
#include <string.h>
#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
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)
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;
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
{
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
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)
}
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;
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;
}
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
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
}
}
-/*)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
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;
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;
}
*/
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[]
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
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);
}
/*
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);
}
/*
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 }
};
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
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)
*/
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[]
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;
*/
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[]
# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# 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\r
-# 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\r
+# 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\r
# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
# ADD RSC /l 0x409 /d "_DEBUG"\r
BSC32=bscmake.exe\r
# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# 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\r
-# 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\r
+# 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\r
# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
# ADD RSC /l 0x409 /d "NDEBUG"\r
BSC32=bscmake.exe\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\support\Util\dbuf.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.c\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\i51adr.c\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\support\Util\dbuf.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\i8051.h\r
# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\sdcc_vc.h\r
+# End Source File\r
# End Group\r
# End Target\r
# End Project\r
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 */
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)) {
} else {
esp->e_mode = S_EXT;
}
- }
- }
- return (esp->e_mode);
+ }
+ }
+ return (esp->e_mode);
}
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
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);
}
/*
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);
}
}
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
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)
# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# 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\r
-# 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\r
+# 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\r
# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
# ADD RSC /l 0x409 /d "_DEBUG"\r
BSC32=bscmake.exe\r
# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# 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\r
-# 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\r
+# 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\r
# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
# ADD RSC /l 0x409 /d "NDEBUG"\r
BSC32=bscmake.exe\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\support\Util\dbuf.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.c\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\asxxsrc\strcmpi.c\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\support\Util\dbuf.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\string.h\r
# End Source File\r
# Begin Source File\r
# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# 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\r
-# 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\r
+# 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\r
# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
# ADD RSC /l 0x409 /d "_DEBUG"\r
BSC32=bscmake.exe\r
# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# 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\r
-# 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\r
+# 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\r
# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
# ADD RSC /l 0x409 /d "NDEBUG"\r
BSC32=bscmake.exe\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\support\Util\dbuf.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.c\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\asxxsrc\strcmpi.c\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\support\Util\dbuf.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\support\Util\dbuf_string.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\string.h\r
# End Source File\r
# Begin Source File\r
*/
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[]
#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
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)
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;
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) {
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
{
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
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)
}
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;
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;
}
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
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
}
}
-/*)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
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;
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;
}
FILE *fp;
{
register int c, i, j, k;
- register char *ptr;
int nmsym, narea;
struct sym *sp;
struct sym **p;
*/
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[]
*
* 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);
}
/*
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);
}
/*
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);
}
/*
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 }
};
{
char *verbalICode;
struct dbuf_s tmpBuf;
+ size_t len;
iCodeTable *icTab = getTableEntry (ic->op);
dbuf_init (&tmpBuf, 1024);
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;
/* EOF in the middle of the line */
is_eof = 1;
return 1;
- }
+ }
else
return 0;
}
static struct dbuf_s lastSrcFile;
static char dbufInitialized = 0;
static int inLineNo = 0;
+ size_t len;
if (!dbufInitialized)
{
}
/* 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);
}