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