xref: /csrg-svn/old/as.vax/asscanl.h (revision 13465)
15814Srrh /*
25814Srrh  *	Copyright (c) 1982 Regents of the University of California
3*13465Srrh  *	@(#)asscanl.h 4.5 06/30/83
45814Srrh  */
55814Srrh /*
65814Srrh  *	This file contains definitions local to the files implementing
75814Srrh  *	the character scanner and the token buffer managers.
85814Srrh  *	It is not intended to be shared with any other parts of the
95814Srrh  *	assembler.
105814Srrh  *	The file ``asscan.h'' is shared with other parts of the assembler
115814Srrh  */
125814Srrh #include <stdio.h>
135814Srrh #include "as.h"
145814Srrh #include "asscan.h"
15*13465Srrh 
165814Srrh #define EOFCHAR	(-1)
175814Srrh /*
185814Srrh  *	The table of possible uses for each character to test set inclusion.
195814Srrh  */
205814Srrh #define	HEXFLAG		01		/* 'x' or 'X' */
215814Srrh #define	HEXLDIGIT	02		/* 'a' .. 'f' */
225814Srrh #define	HEXUDIGIT	04		/* 'A' .. 'F' */
235814Srrh #define	ALPHA		010		/* 'A' .. 'Z', 'a' .. 'z', '_'*/
245814Srrh #define	DIGIT		020		/* '0' .. '9' */
255814Srrh #define	FLOATEXP	040		/* 'd' 'e' 'D' 'E' 'g' 'h' 'G' 'H' */
265814Srrh #define	SIGN		0100		/* '+' .. '-'*/
275814Srrh #define	REGDIGIT	0200		/* '0' .. '5' */
285814Srrh #define	SZSPECBEGIN	0400		/* 'b', 'B', 'l', 'L', 'w', 'W' */
295814Srrh #define	POINT		01000		/* '.' */
305814Srrh #define	SPACE		02000		/* '\t' or ' ' */
315814Srrh #define	BSESCAPE	04000		/* bnrtf */
325814Srrh #define	STRESCAPE	010000		/* '"', '\\', '\n' */
335814Srrh #define	OCTDIGIT	020000		/* '0' .. '7' */
345814Srrh #define	FLOATFLAG	040000		/* 'd', 'D', 'f', 'F' */
355814Srrh 
365814Srrh #define	INCHARSET(val, kind) (charsets[val] & (kind) )
375814Srrh /*
38*13465Srrh  *	We use our own version of getchar/ungetc to get
39*13465Srrh  *	some speed improvement
405814Srrh  */
41*13465Srrh extern	char	*Ginbufptr;
42*13465Srrh extern	int	Ginbufcnt;
43*13465Srrh #define	REGTOMEMBUF	Ginbufptr = inbufptr, Ginbufcnt = inbufcnt
44*13465Srrh #define	MEMTOREGBUF	inbufptr = Ginbufptr, inbufcnt = Ginbufcnt
45*13465Srrh #undef getchar
46*13465Srrh #define	getchar() \
47*13465Srrh 	(inbufcnt-- > 0 ? (*inbufptr++) : \
48*13465Srrh 		(fillinbuffer(), \
49*13465Srrh 		MEMTOREGBUF, \
50*13465Srrh 		inbufptr[-1]))
51*13465Srrh #undef ungetc
52*13465Srrh #define ungetc(ch) \
53*13465Srrh 	(++inbufcnt, *--inbufptr = ch)
54*13465Srrh 
555814Srrh /*
56*13465Srrh  *	Variables and definitions to manage the token buffering.
575814Srrh  *	We scan (lexically analyze) a large number of tokens, and
585814Srrh  *	then parse all of the tokens in the scan buffer.
595814Srrh  *	This reduces procedure call overhead when the parser
605814Srrh  *	demands a token, allows for an efficient reread during
615814Srrh  *	the second pass, and confuses the line number reporting
625814Srrh  *	for errors encountered in the scanner and in the parser.
635814Srrh  */
645814Srrh #define TOKDALLOP	8
655814Srrh struct	tokbufdesc *bufstart;	/*where the buffer list begins*/
665814Srrh struct	tokbufdesc *buftail;	/*last one on the list*/
675814Srrh struct	tokbufdesc *emptybuf;	/*the one being filled*/
685814Srrh /*
695814Srrh  *	If we are using VM, during the second pass we reclaim the used
705814Srrh  *	token buffers for saving the relocation information
715814Srrh  */
725814Srrh struct	tokbufdesc *tok_free;	/* free pool */
735814Srrh struct	tokbufdesc *tok_temp;	/* temporary for doing list manipulation */
745814Srrh /*
755814Srrh  *	Other token buffer managers
765814Srrh  */
775814Srrh int	bufno;			/*which buffer number: 0,1 for tmp file*/
785814Srrh struct 	tokbufdesc tokbuf[2];	/*our initial increment of buffers*/
795814Srrh ptrall	tokptr;			/*where the current token comes from*/
805814Srrh ptrall	tokub;			/*the last token in the current token buffer*/
81*13465Srrh /*
82*13465Srrh  *	as does not use fread and fwrite for the token buffering.
83*13465Srrh  *	The token buffers are integrals of BUFSIZ
84*13465Srrh  *	at all times, so we use direct read and write.
85*13465Srrh  *	fread and fwrite in stdio are HORRENDOUSLY inefficient,
86*13465Srrh  *	as they use putchar for each character, nested two deep in loops.
87*13465Srrh  */
88*13465Srrh #define writeTEST(pointer, size, nelements, ioptr) \
89*13465Srrh 	write(ioptr->_file, pointer, nelements * size) != nelements * size
905814Srrh 
91*13465Srrh #define readTEST(pointer, size, nelements, ioptr) \
92*13465Srrh 	read(ioptr->_file, pointer, nelements * size) != nelements * size
935814Srrh 
945814Srrh #define bskiplg(from, length) \
955814Srrh 	*(lgtype *)from = length; \
965814Srrh 	(bytetoktype *)from += sizeof(lgtype) + length
975814Srrh 
985814Srrh #define bskipfromto(from, to) \
995814Srrh 	*(lgtype *)from = (bytetoktype *)to - (bytetoktype *)from - sizeof(lgtype); \
1005814Srrh 	(bytetoktype *)from += sizeof (lgtype) + (bytetoktype *)to - (bytetoktype *)from
1015814Srrh 
1025814Srrh #define eatskiplg(from) \
1035814Srrh 	(bytetoktype *)from += sizeof(lgtype) + *(lgtype *)from
1045814Srrh 
1055814Srrh #ifdef DEBUG
1065814Srrh 	ptrall	firsttoken;
1075814Srrh #endif DEBUG
1085814Srrh 
1095814Srrh /*
1105814Srrh  *	The following three variables are the slots for global
1115814Srrh  *	communication with the parser.
1125814Srrh  *	They are the semantic values associated with a particular token.
1135814Srrh  *	The token itself is the return value from yylex()
1145814Srrh  */
1155814Srrh int	yylval;			/* normal semantic value */
1165814Srrh Bignum	yybignum;		/* a big number */
1175814Srrh struct	Opcode	yyopcode;	/* a structure opcode */
1185814Srrh 
1195814Srrh int	newfflag;
1205814Srrh char	*newfname;
1215814Srrh int	scanlineno;		/*the scanner's linenumber*/
1225814Srrh 
1235814Srrh /*
1245814Srrh  *	Definitions for sets of characters
1255814Srrh  */
1265814Srrh readonly short charsets[];
1275814Srrh readonly short type[];
128