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