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);
138 for(p=symb; c = *p; p++)
145 for(s = hash[h]; s != S; s = s->link) {
148 if(memcmp(s->name, symb, l) == 0)
151 s = alloc(sizeof(*s));
153 memmove(s->name, symb, l);
225 if(isalpha(c) || isdigit(c) || c == '_' || c == '$')
235 ionext->link = iostack;
248 if(s->type == LNAME ||
254 yylval.lval = s->value;
264 if(c == 'x' || c == 'X') {
268 if(c < '0' || c > '7')
272 if(c >= '0' && c <= '9') {
273 if(c > '7' && c1 == 3)
276 yylval.lval += c - '0';
282 if(c >= 'A' && c <= 'F')
284 if(c >= 'a' && c <= 'f') {
286 yylval.lval += c - 'a' + 10;
303 if(c == 'e' || c == 'E')
306 if(sizeof(yylval.lval) == sizeof(vlong))
307 yylval.lval = strtoull(symb, nil, 10);
309 yylval.lval = strtoul(symb, nil, 10);
312 while(c == 'U' || c == 'u' || c == 'l' || c == 'L')
324 if(c == 'e' || c == 'E')
331 if(c == '+' || c == '-') {
344 yylval.dval = atof(symb);
347 yyerror("assembler cannot interpret fp constants");
352 memcpy(yylval.sval, nullgen.sval, sizeof(yylval.sval));
359 if(c1 < sizeof(yylval.sval))
363 if(c1 > sizeof(yylval.sval))
364 yyerror("string constant too long");
371 if(escchar('\'') != EOF)
372 yyerror("missing '");
384 yyerror("eof in comment");
398 yyerror("eof in comment");
430 yyerror("End of file");
443 if(!isspace(c) || c == '\n')
465 yyerror("newline in string");
474 if(c >= '0' && c <= '7') {
477 if(c >= '0' && c <= '7') {
480 if(c >= '0' && c <= '7') {
490 case '\n': goto loop;
491 case 'n': return '\n';
492 case 't': return '\t';
493 case 'b': return '\b';
494 case 'r': return '\r';
495 case 'f': return '\f';
496 case 'a': return 0x07;
497 case 'v': return 0x0b;
498 case 'z': return 0x00;
515 for(i=0; i<NSYM; i++) {
519 for(i=0; i<NHASH; i++)
520 for(s = hash[i]; s != S; s = s->link)
535 fi.c = read(i->f, i->b, BUFSIZ) - 1;
559 yyerror(char *a, ...)
565 * hack to intercept message from yaccpar
567 if(strcmp(a, "syntax error") == 0) {
568 yyerror("syntax error, last name: %s", symb);
573 vseprint(buf, buf+sizeof(buf), a, arg);
578 print("too many errors\n");
591 for(h = hist; h != H; h = h->link) {
596 if(n >= 0 && n < HISTSZ)
601 if(n > 0 && n < HISTSZ)
602 if(a[n-1].offset == 0) {
610 if(n >= 0 && n < HISTSZ) {
611 d = h->line - a[n].line;
619 print("%s:%ld ", a[i].name, (long)(l-a[i].line+a[i].offset+1));
623 ieeedtod(Ieee *ieee, double native)
629 ieeedtod(ieee, -native);
630 ieee->h |= 0x80000000L;
638 fr = frexp(native, &exp);
639 f = 2097152L; /* shouldnt use fp constants here */
640 fr = modf(fr*f, &ho);
643 ieee->h |= (exp+1022L) << 20;
645 fr = modf(fr*f, &ho);
648 ieee->l |= (long)(fr*f);