2 * common code for all the assemblers
8 while(getnsc() != '\n')
15 while(getnsc() != '\n')
22 while(getnsc() != '\n')
29 while(getnsc() != '\n')
36 while(getnsc() != '\n')
47 for(i=1; i < ninclude; i++)
48 if(strcmp(p, include[i]) == 0)
51 if(ninclude >= nelem(include)) {
52 yyerror("ninclude too small %d", nelem(include));
55 include[ninclude++] = p;
74 yyerror("botch in pushio");
85 static int pushdepth = 0;
90 if(pushdepth > 1000) {
91 yyerror("macro/io expansion too deep");
94 i = alloc(sizeof(*i));
103 newfile(char *s, int f)
114 yyerror("%Ca: %r: %s", thechar, s);
124 strncpy(symb, s, NSYMB);
125 if(symb[NSYMB-1] != '\0'){
126 yyerror("symbol too long: %s", s);
150 for(s = hash[h]; s != S; s = s->link) {
153 if(strcmp(s->name, symb) == 0)
156 s = alloc(sizeof(*s));
158 memmove(s->name, symb, n);
229 if(cp >= &symb[NSYMB-1])
233 if(isalpha(c) || isdigit(c) || c == '_' || c == '$')
241 macexpand(s, cp, sizeof(ionext->b)-1);
243 ionext->link = iostack;
256 if(s->type == LNAME ||
262 yylval.lval = s->value;
272 if(c == 'x' || c == 'X') {
276 if(c < '0' || c > '7')
280 if(c >= '0' && c <= '9') {
281 if(c > '7' && c1 == 3)
284 yylval.lval += c - '0';
290 if(c >= 'A' && c <= 'F')
292 if(c >= 'a' && c <= 'f') {
294 yylval.lval += c - 'a' + 10;
306 if(cp >= &symb[NSYMB-1])
313 if(c == 'e' || c == 'E')
316 if(sizeof(yylval.lval) == sizeof(vlong))
317 yylval.lval = strtoull(symb, nil, 10);
319 yylval.lval = strtoul(symb, nil, 10);
322 while(c == 'U' || c == 'u' || c == 'l' || c == 'L')
329 if(cp >= &symb[NSYMB-1])
336 if(c == 'e' || c == 'E')
341 if(cp >= &symb[NSYMB-1])
345 if(c == '+' || c == '-') {
346 if(cp >= &symb[NSYMB-1])
352 if(cp >= &symb[NSYMB-1])
362 yylval.dval = atof(symb);
365 yyerror("assembler cannot interpret fp constants");
370 memcpy(yylval.sval, nullgen.sval, sizeof(yylval.sval));
377 if(c1 < sizeof(yylval.sval))
381 if(c1 > sizeof(yylval.sval))
382 yyerror("string constant too long");
389 if(escchar('\'') != EOF)
390 yyerror("missing '");
402 yyerror("eof in comment");
416 yyerror("eof in comment");
431 yyerror("token too long: %.*s...", utfnlen(symb, cp-symb), symb);
452 yyerror("End of file");
465 if(!isspace(c) || c == '\n')
487 yyerror("newline in string");
496 if(c >= '0' && c <= '7') {
499 if(c >= '0' && c <= '7') {
502 if(c >= '0' && c <= '7') {
512 case '\n': goto loop;
513 case 'n': return '\n';
514 case 't': return '\t';
515 case 'b': return '\b';
516 case 'r': return '\r';
517 case 'f': return '\f';
518 case 'a': return 0x07;
519 case 'v': return 0x0b;
520 case 'z': return 0x00;
537 for(i=0; i<NSYM; i++) {
541 for(i=0; i<NHASH; i++)
542 for(s = hash[i]; s != S; s = s->link)
557 fi.c = read(i->f, i->b, BUFSIZ) - 1;
581 yyerror(char *a, ...)
587 * hack to intercept message from yaccpar
589 if(strcmp(a, "syntax error") == 0) {
590 yyerror("syntax error, last name: %s", symb);
595 vseprint(buf, buf+sizeof(buf), a, arg);
600 print("too many errors\n");
613 for(h = hist; h != H; h = h->link) {
618 if(n >= 0 && n < HISTSZ)
623 if(n > 0 && n < HISTSZ)
624 if(a[n-1].offset == 0) {
632 if(n >= 0 && n < HISTSZ) {
633 d = h->line - a[n].line;
641 print("%s:%ld ", a[i].name, (long)(l-a[i].line+a[i].offset+1));
645 ieeedtod(Ieee *ieee, double native)
651 ieeedtod(ieee, -native);
652 ieee->h |= 0x80000000L;
660 fr = frexp(native, &exp);
661 f = 2097152L; /* shouldnt use fp constants here */
662 fr = modf(fr*f, &ho);
665 ieee->h |= (exp+1022L) << 20;
667 fr = modf(fr*f, &ho);
670 ieee->l |= (long)(fr*f);