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