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