15814Srrh /* 2*19826Sdist * Copyright (c) 1982 Regents of the University of California. 3*19826Sdist * All rights reserved. The Berkeley software License Agreement 4*19826Sdist * specifies the terms and conditions for redistribution. 5*19826Sdist * 6*19826Sdist * @(#)asscanl.h 5.1 (Berkeley) 04/30/85 75814Srrh */ 8*19826Sdist 95814Srrh /* 105814Srrh * This file contains definitions local to the files implementing 115814Srrh * the character scanner and the token buffer managers. 125814Srrh * It is not intended to be shared with any other parts of the 135814Srrh * assembler. 145814Srrh * The file ``asscan.h'' is shared with other parts of the assembler 155814Srrh */ 165814Srrh #include <stdio.h> 175814Srrh #include "as.h" 185814Srrh #include "asscan.h" 1913465Srrh 205814Srrh #define EOFCHAR (-1) 215814Srrh /* 225814Srrh * The table of possible uses for each character to test set inclusion. 235814Srrh */ 245814Srrh #define HEXFLAG 01 /* 'x' or 'X' */ 255814Srrh #define HEXLDIGIT 02 /* 'a' .. 'f' */ 265814Srrh #define HEXUDIGIT 04 /* 'A' .. 'F' */ 275814Srrh #define ALPHA 010 /* 'A' .. 'Z', 'a' .. 'z', '_'*/ 285814Srrh #define DIGIT 020 /* '0' .. '9' */ 295814Srrh #define FLOATEXP 040 /* 'd' 'e' 'D' 'E' 'g' 'h' 'G' 'H' */ 305814Srrh #define SIGN 0100 /* '+' .. '-'*/ 315814Srrh #define REGDIGIT 0200 /* '0' .. '5' */ 325814Srrh #define SZSPECBEGIN 0400 /* 'b', 'B', 'l', 'L', 'w', 'W' */ 335814Srrh #define POINT 01000 /* '.' */ 345814Srrh #define SPACE 02000 /* '\t' or ' ' */ 355814Srrh #define BSESCAPE 04000 /* bnrtf */ 365814Srrh #define STRESCAPE 010000 /* '"', '\\', '\n' */ 375814Srrh #define OCTDIGIT 020000 /* '0' .. '7' */ 385814Srrh #define FLOATFLAG 040000 /* 'd', 'D', 'f', 'F' */ 395814Srrh 405814Srrh #define INCHARSET(val, kind) (charsets[val] & (kind) ) 415814Srrh /* 4213465Srrh * We use our own version of getchar/ungetc to get 4313465Srrh * some speed improvement 445814Srrh */ 4513465Srrh extern char *Ginbufptr; 4613465Srrh extern int Ginbufcnt; 4713465Srrh #define REGTOMEMBUF Ginbufptr = inbufptr, Ginbufcnt = inbufcnt 4813465Srrh #define MEMTOREGBUF inbufptr = Ginbufptr, inbufcnt = Ginbufcnt 4913465Srrh #undef getchar 5013465Srrh #define getchar() \ 5113465Srrh (inbufcnt-- > 0 ? (*inbufptr++) : \ 5213465Srrh (fillinbuffer(), \ 5313465Srrh MEMTOREGBUF, \ 5413465Srrh inbufptr[-1])) 5513465Srrh #undef ungetc 5613465Srrh #define ungetc(ch) \ 5713465Srrh (++inbufcnt, *--inbufptr = ch) 5813465Srrh 595814Srrh /* 6013465Srrh * Variables and definitions to manage the token buffering. 615814Srrh * We scan (lexically analyze) a large number of tokens, and 625814Srrh * then parse all of the tokens in the scan buffer. 635814Srrh * This reduces procedure call overhead when the parser 645814Srrh * demands a token, allows for an efficient reread during 655814Srrh * the second pass, and confuses the line number reporting 665814Srrh * for errors encountered in the scanner and in the parser. 675814Srrh */ 685814Srrh #define TOKDALLOP 8 695814Srrh struct tokbufdesc *bufstart; /*where the buffer list begins*/ 705814Srrh struct tokbufdesc *buftail; /*last one on the list*/ 715814Srrh struct tokbufdesc *emptybuf; /*the one being filled*/ 725814Srrh /* 735814Srrh * If we are using VM, during the second pass we reclaim the used 745814Srrh * token buffers for saving the relocation information 755814Srrh */ 765814Srrh struct tokbufdesc *tok_free; /* free pool */ 775814Srrh struct tokbufdesc *tok_temp; /* temporary for doing list manipulation */ 785814Srrh /* 795814Srrh * Other token buffer managers 805814Srrh */ 815814Srrh int bufno; /*which buffer number: 0,1 for tmp file*/ 825814Srrh struct tokbufdesc tokbuf[2]; /*our initial increment of buffers*/ 835814Srrh ptrall tokptr; /*where the current token comes from*/ 845814Srrh ptrall tokub; /*the last token in the current token buffer*/ 8513465Srrh /* 8613465Srrh * as does not use fread and fwrite for the token buffering. 8713465Srrh * The token buffers are integrals of BUFSIZ 8813465Srrh * at all times, so we use direct read and write. 8913465Srrh * fread and fwrite in stdio are HORRENDOUSLY inefficient, 9013465Srrh * as they use putchar for each character, nested two deep in loops. 9113465Srrh */ 9213465Srrh #define writeTEST(pointer, size, nelements, ioptr) \ 9313465Srrh write(ioptr->_file, pointer, nelements * size) != nelements * size 945814Srrh 9513465Srrh #define readTEST(pointer, size, nelements, ioptr) \ 9613465Srrh read(ioptr->_file, pointer, nelements * size) != nelements * size 975814Srrh 985814Srrh #define bskiplg(from, length) \ 995814Srrh *(lgtype *)from = length; \ 1005814Srrh (bytetoktype *)from += sizeof(lgtype) + length 1015814Srrh 1025814Srrh #define bskipfromto(from, to) \ 1035814Srrh *(lgtype *)from = (bytetoktype *)to - (bytetoktype *)from - sizeof(lgtype); \ 1045814Srrh (bytetoktype *)from += sizeof (lgtype) + (bytetoktype *)to - (bytetoktype *)from 1055814Srrh 1065814Srrh #define eatskiplg(from) \ 1075814Srrh (bytetoktype *)from += sizeof(lgtype) + *(lgtype *)from 1085814Srrh 1095814Srrh #ifdef DEBUG 1105814Srrh ptrall firsttoken; 1115814Srrh #endif DEBUG 1125814Srrh 1135814Srrh /* 1145814Srrh * The following three variables are the slots for global 1155814Srrh * communication with the parser. 1165814Srrh * They are the semantic values associated with a particular token. 1175814Srrh * The token itself is the return value from yylex() 1185814Srrh */ 1195814Srrh int yylval; /* normal semantic value */ 1205814Srrh Bignum yybignum; /* a big number */ 1215814Srrh struct Opcode yyopcode; /* a structure opcode */ 1225814Srrh 1235814Srrh int newfflag; 1245814Srrh char *newfname; 1255814Srrh int scanlineno; /*the scanner's linenumber*/ 1265814Srrh 1275814Srrh /* 1285814Srrh * Definitions for sets of characters 1295814Srrh */ 1305814Srrh readonly short charsets[]; 1315814Srrh readonly short type[]; 132