date and time created 90/03/23 09:45:20 by bostic
[unix-history] / usr / src / old / as.tahoe / asscanl.h
CommitLineData
c13aa77a
KB
1/*
2 * Copyright (c) 1982 Regents of the University of California
3 * @(#)asscanl.h 4.5 6/30/83
4 */
5/*
6 * This file contains definitions local to the files implementing
7 * the character scanner and the token buffer managers.
8 * It is not intended to be shared with any other parts of the
9 * assembler.
10 * The file ``asscan.h'' is shared with other parts of the assembler
11 */
12#include <stdio.h>
13#include "as.h"
14#include "asscan.h"
15
16#define EOFCHAR (-1)
17/*
18 * The table of possible uses for each character to test set inclusion.
19 */
20#define HEXFLAG 01 /* 'x' or 'X' */
21#define HEXLDIGIT 02 /* 'a' .. 'f' */
22#define HEXUDIGIT 04 /* 'A' .. 'F' */
23#define ALPHA 010 /* 'A' .. 'Z', 'a' .. 'z', '_'*/
24#define DIGIT 020 /* '0' .. '9' */
25#define FLOATEXP 040 /* 'd' 'e' 'D' 'E' 'g' 'h' 'G' 'H' */
26#define SIGN 0100 /* '+' .. '-'*/
27#define REGDIGIT 0200 /* '0' .. '5' */
28#define SZSPECBEGIN 0400 /* 'b', 'B', 'l', 'L', 'w', 'W' */
29#define POINT 01000 /* '.' */
30#define SPACE 02000 /* '\t' or ' ' */
31#define BSESCAPE 04000 /* bnrtf */
32#define STRESCAPE 010000 /* '"', '\\', '\n' */
33#define OCTDIGIT 020000 /* '0' .. '7' */
34#define FLOATFLAG 040000 /* 'd', 'D', 'f', 'F' */
35
36#define INCHARSET(val, kind) (charsets[val] & (kind) )
37/*
38 * We use our own version of getchar/ungetc to get
39 * some speed improvement
40 */
41extern char *Ginbufptr;
42extern int Ginbufcnt;
43#define REGTOMEMBUF Ginbufptr = inbufptr, Ginbufcnt = inbufcnt
44#define MEMTOREGBUF inbufptr = Ginbufptr, inbufcnt = Ginbufcnt
45#undef getchar
46#define getchar() \
47 (inbufcnt-- > 0 ? (*inbufptr++) : \
48 (fillinbuffer(), \
49 MEMTOREGBUF, \
50 inbufptr[-1]))
51#undef ungetc
52#define ungetc(ch) \
53 (++inbufcnt, *--inbufptr = ch)
54\f
55/*
56 * Variables and definitions to manage the token buffering.
57 * We scan (lexically analyze) a large number of tokens, and
58 * then parse all of the tokens in the scan buffer.
59 * This reduces procedure call overhead when the parser
60 * demands a token, allows for an efficient reread during
61 * the second pass, and confuses the line number reporting
62 * for errors encountered in the scanner and in the parser.
63 */
64#define TOKDALLOP 8
65struct tokbufdesc *bufstart; /*where the buffer list begins*/
66struct tokbufdesc *buftail; /*last one on the list*/
67struct tokbufdesc *emptybuf; /*the one being filled*/
68/*
69 * If we are using VM, during the second pass we reclaim the used
70 * token buffers for saving the relocation information
71 */
72struct tokbufdesc *tok_free; /* free pool */
73struct tokbufdesc *tok_temp; /* temporary for doing list manipulation */
74/*
75 * Other token buffer managers
76 */
77int bufno; /*which buffer number: 0,1 for tmp file*/
78struct tokbufdesc tokbuf[2]; /*our initial increment of buffers*/
79ptrall tokptr; /*where the current token comes from*/
80ptrall tokub; /*the last token in the current token buffer*/
81/*
82 * as does not use fread and fwrite for the token buffering.
83 * The token buffers are integrals of BUFSIZ
84 * at all times, so we use direct read and write.
85 * fread and fwrite in stdio are HORRENDOUSLY inefficient,
86 * as they use putchar for each character, nested two deep in loops.
87 */
88#define writeTEST(pointer, size, nelements, ioptr) \
89 write(ioptr->_file, pointer, nelements * size) != nelements * size
90
91#define readTEST(pointer, size, nelements, ioptr) \
92 read(ioptr->_file, pointer, nelements * size) != nelements * size
93
94#define bskiplg(from, length) \
95 from = (char *)((int)(from + sizeof(lgtype)-1)&~(sizeof(lgtype)-1)); \
96 *(lgtype *)from = length; \
97 (bytetoktype *)from += sizeof(lgtype) + length
98
99#define bskipfromto(from, to) \
100 from = (char *)((int)(from + sizeof(lgtype)-1)&~(sizeof(lgtype)-1)); \
101 *(lgtype *)from = (bytetoktype *)to - (bytetoktype *)from - sizeof(lgtype); \
102 (bytetoktype *)from += sizeof (lgtype) + (bytetoktype *)to - (bytetoktype *)from
103
104#define eatskiplg(from) \
105 from = (char *)((int)(from + sizeof(lgtype)-1)&~(sizeof(lgtype)-1)); \
106 (bytetoktype *)from += sizeof(lgtype) + *(lgtype *)from
107
108#ifdef DEBUG
109 ptrall firsttoken;
110#endif DEBUG
111
112/*
113 * The following three variables are the slots for global
114 * communication with the parser.
115 * They are the semantic values associated with a particular token.
116 * The token itself is the return value from yylex()
117 */
118int yylval; /* normal semantic value */
119Bignum yybignum; /* a big number */
120u_char yyopcode; /* a structure opcode */
121
122int newfflag;
123char *newfname;
124int scanlineno; /*the scanner's linenumber*/
125
126/*
127 * Definitions for sets of characters
128 */
129readonly short charsets[];
130readonly short type[];