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 = strtoll(symb, nil, 10);
348 yylval.lval = strtol(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");
467 yyerror("End of file");
480 if(!isspace(c) || c == '\n')
502 yyerror("newline in string");
511 if(c >= '0' && c <= '7') {
514 if(c >= '0' && c <= '7') {
517 if(c >= '0' && c <= '7') {
527 case '\n': goto loop;
528 case 'n': return '\n';
529 case 't': return '\t';
530 case 'b': return '\b';
531 case 'r': return '\r';
532 case 'f': return '\f';
533 case 'a': return 0x07;
534 case 'v': return 0x0b;
535 case 'z': return 0x00;
552 for(i=0; i<NSYM; i++) {
556 for(i=0; i<NHASH; i++)
557 for(s = hash[i]; s != S; s = s->link)
572 fi.c = read(i->f, i->b, BUFSIZ) - 1;
596 yyerror(char *a, ...)
602 * hack to intercept message from yaccpar
604 if(strcmp(a, "syntax error") == 0) {
605 yyerror("syntax error, last name: %s", symb);
610 vseprint(buf, buf+sizeof(buf), a, arg);
615 print("too many errors\n");
628 for(h = hist; h != H; h = h->link) {
633 if(n >= 0 && n < HISTSZ)
638 if(n > 0 && n < HISTSZ)
639 if(a[n-1].offset == 0) {
647 if(n >= 0 && n < HISTSZ) {
648 d = h->line - a[n].line;
656 print("%s:%ld ", a[i].name, (long)(l-a[i].line+a[i].offset+1));
660 ieeedtod(Ieee *ieee, double native)
666 ieeedtod(ieee, -native);
667 ieee->h |= 0x80000000L;
675 fr = frexp(native, &exp);
676 f = 2097152L; /* shouldnt use fp constants here */
677 fr = modf(fr*f, &ho);
680 ieee->h |= (exp+1022L) << 20;
682 fr = modf(fr*f, &ho);
685 ieee->l |= (long)(fr*f);