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')
48 while((uintptr)hunk & MAXALIGN) {
61 allocn(void *p, long on, long n)
66 if(q != hunk || nhunk < n) {
86 for(i=1; i < ninclude; i++)
87 if(strcmp(p, include[i]) == 0)
90 if(ninclude >= nelem(include)) {
91 yyerror("ninclude too small %d", nelem(include));
94 include[ninclude++] = p;
113 yyerror("botch in pushio");
124 static int pushdepth = 0;
129 if(pushdepth > 1000) {
130 yyerror("macro/io expansion too deep");
133 i = alloc(sizeof(*i));
142 newfile(char *s, int f)
153 yyerror("%ca: %r: %s", thechar, s);
177 for(p=symb; c = *p; p++)
184 for(s = hash[h]; s != S; s = s->link) {
187 if(memcmp(s->name, symb, l) == 0)
190 s = alloc(sizeof(*s));
192 memmove(s->name, symb, l);
264 if(isalpha(c) || isdigit(c) || c == '_' || c == '$')
274 ionext->link = iostack;
287 if(s->type == LNAME ||
293 yylval.lval = s->value;
303 if(c == 'x' || c == 'X') {
307 if(c < '0' || c > '7')
311 if(c >= '0' && c <= '9') {
312 if(c > '7' && c1 == 3)
315 yylval.lval += c - '0';
321 if(c >= 'A' && c <= 'F')
323 if(c >= 'a' && c <= 'f') {
325 yylval.lval += c - 'a' + 10;
342 if(c == 'e' || c == 'E')
345 if(sizeof(yylval.lval) == sizeof(vlong))
346 yylval.lval = strtoull(symb, nil, 10);
348 yylval.lval = strtoul(symb, nil, 10);
351 while(c == 'U' || c == 'u' || c == 'l' || c == 'L')
363 if(c == 'e' || c == 'E')
370 if(c == '+' || c == '-') {
383 yylval.dval = atof(symb);
386 yyerror("assembler cannot interpret fp constants");
391 memcpy(yylval.sval, nullgen.sval, sizeof(yylval.sval));
398 if(c1 < sizeof(yylval.sval))
402 if(c1 > sizeof(yylval.sval))
403 yyerror("string constant too long");
410 if(escchar('\'') != EOF)
411 yyerror("missing '");
423 yyerror("eof in comment");
437 yyerror("eof in comment");
469 yyerror("End of file");
482 if(!isspace(c) || c == '\n')
504 yyerror("newline in string");
513 if(c >= '0' && c <= '7') {
516 if(c >= '0' && c <= '7') {
519 if(c >= '0' && c <= '7') {
529 case '\n': goto loop;
530 case 'n': return '\n';
531 case 't': return '\t';
532 case 'b': return '\b';
533 case 'r': return '\r';
534 case 'f': return '\f';
535 case 'a': return 0x07;
536 case 'v': return 0x0b;
537 case 'z': return 0x00;
554 for(i=0; i<NSYM; i++) {
558 for(i=0; i<NHASH; i++)
559 for(s = hash[i]; s != S; s = s->link)
574 fi.c = read(i->f, i->b, BUFSIZ) - 1;
598 yyerror(char *a, ...)
604 * hack to intercept message from yaccpar
606 if(strcmp(a, "syntax error") == 0) {
607 yyerror("syntax error, last name: %s", symb);
612 vseprint(buf, buf+sizeof(buf), a, arg);
617 print("too many errors\n");
630 for(h = hist; h != H; h = h->link) {
635 if(n >= 0 && n < HISTSZ)
640 if(n > 0 && n < HISTSZ)
641 if(a[n-1].offset == 0) {
649 if(n >= 0 && n < HISTSZ) {
650 d = h->line - a[n].line;
658 print("%s:%ld ", a[i].name, (long)(l-a[i].line+a[i].offset+1));
662 ieeedtod(Ieee *ieee, double native)
668 ieeedtod(ieee, -native);
669 ieee->h |= 0x80000000L;
677 fr = frexp(native, &exp);
678 f = 2097152L; /* shouldnt use fp constants here */
679 fr = modf(fr*f, &ho);
682 ieee->h |= (exp+1022L) << 20;
684 fr = modf(fr*f, &ho);
687 ieee->l |= (long)(fr*f);