7 main(int argc, char *argv[])
10 int nout, nproc, status, i, c;
14 memset(debug, 0, sizeof(debug));
17 include[ninclude++] = ".";
21 if(c >= 0 || c < sizeof(debug))
39 case 'L': /* for little-endian mips */
45 print("usage: %ca [-options] file.s\n", thechar);
48 if(argc > 1 && systemtype(Windows)){
49 print("can't assemble multiple files on windows\n");
52 if(argc > 1 && !systemtype(Windows)) {
54 if(p = getenv("NPROC"))
55 nproc = atol(p); /* */
59 while(nout < nproc && argc > 0) {
71 print("%s:\n", *argv);
99 char ofile[100], incfile[20], *p;
103 p = utfrrune(ofile, pathchar());
112 p = utfrrune(outfile, '.');
114 if(p[1] == 's' && p[2] == 0)
116 p = utfrune(outfile, 0);
121 outfile = "/dev/null";
123 p = getenv("INCLUDE");
127 if(systemtype(Plan9)) {
128 sprint(incfile,"/%s/include", thestring);
129 setinclude(strdup(incfile));
133 of = mycreat(outfile, 0664);
135 yyerror("%ca: cannot create %s", thechar, outfile);
138 Binit(&obuf, of, OWRITE);
142 for(i=0; i<nDlist; i++)
153 for(i=0; i<nDlist; i++)
312 "ADDU", LTYPE1, AADDU,
313 "SUB", LTYPE1, ASUB, /* converted to ADD(-) in loader */
314 "SUBU", LTYPE1, ASUBU,
316 "SGTU", LTYPE1, ASGTU,
324 "ADDV", LTYPE1, AADDV,
325 "ADDVU", LTYPE1, AADDVU,
326 "SUBV", LTYPE1, ASUBV, /* converted to ADD(-) in loader */
327 "SUBVU", LTYPE1, ASUBVU,
328 "SLLV", LTYPE1, ASLLV,
329 "SRLV", LTYPE1, ASRLV,
330 "SRAV", LTYPE1, ASRAV,
334 "MOVB", LTYPE3, AMOVB,
335 "MOVBU", LTYPE3, AMOVBU,
336 "MOVH", LTYPE3, AMOVH,
337 "MOVHU", LTYPE3, AMOVHU,
338 "MOVWL", LTYPE3, AMOVWL,
339 "MOVWR", LTYPE3, AMOVWR,
340 "MOVVL", LTYPE3, AMOVVL,
341 "MOVVR", LTYPE3, AMOVVR,
343 "BREAK", LTYPEJ, ABREAK, /* overloaded CACHE opcode */
346 "REMU", LTYPE6, AREMU,
348 "SYSCALL", LTYPE4, ASYSCALL,
349 "TLBP", LTYPE4, ATLBP,
350 "TLBR", LTYPE4, ATLBR,
351 "TLBWI", LTYPE4, ATLBWI,
352 "TLBWR", LTYPE4, ATLBWR,
354 "MOVW", LTYPE5, AMOVW,
355 "MOVV", LTYPE5, AMOVV,
356 "MOVD", LTYPE5, AMOVD,
357 "MOVF", LTYPE5, AMOVF,
360 "DIVU", LTYPE6, ADIVU,
362 "MULU", LTYPE6, AMULU,
363 "DIVV", LTYPE6, ADIVV,
364 "DIVVU", LTYPE6, ADIVVU,
365 "MULV", LTYPE6, AMULV,
366 "MULVU", LTYPE6, AMULVU,
376 "BGEZ", LTYPEA, ABGEZ,
377 "BGEZAL", LTYPEA, ABGEZAL,
378 "BGTZ", LTYPEA, ABGTZ,
379 "BLEZ", LTYPEA, ABLEZ,
380 "BLTZ", LTYPEA, ABLTZ,
381 "BLTZAL", LTYPEA, ABLTZAL,
383 "TEXT", LTYPEB, ATEXT,
384 "GLOBL", LTYPEB, AGLOBL,
386 "DATA", LTYPEC, ADATA,
388 "MOVDF", LTYPE5, AMOVDF,
389 "MOVDW", LTYPE5, AMOVDW,
390 "MOVFD", LTYPE5, AMOVFD,
391 "MOVFW", LTYPE5, AMOVFW,
392 "MOVWD", LTYPE5, AMOVWD,
393 "MOVWF", LTYPE5, AMOVWF,
395 "ABSD", LTYPED, AABSD,
396 "ABSF", LTYPED, AABSF,
397 "ABSW", LTYPED, AABSW,
398 "NEGD", LTYPED, ANEGD,
399 "NEGF", LTYPED, ANEGF,
400 "NEGW", LTYPED, ANEGW,
402 "CMPEQD", LTYPEF, ACMPEQD,
403 "CMPEQF", LTYPEF, ACMPEQF,
404 "CMPGED", LTYPEF, ACMPGED,
405 "CMPGEF", LTYPEF, ACMPGEF,
406 "CMPGTD", LTYPEF, ACMPGTD,
407 "CMPGTF", LTYPEF, ACMPGTF,
409 "ADDD", LTYPEE, AADDD,
410 "ADDF", LTYPEE, AADDF,
411 "ADDW", LTYPEE, AADDW,
412 "DIVD", LTYPEE, ADIVD,
413 "DIVF", LTYPEE, ADIVF,
414 "DIVW", LTYPEE, ADIVW,
415 "MULD", LTYPEE, AMULD,
416 "MULF", LTYPEE, AMULF,
417 "MULW", LTYPEE, AMULW,
418 "SUBD", LTYPEE, ASUBD,
419 "SUBF", LTYPEE, ASUBF,
420 "SUBW", LTYPEE, ASUBW,
422 "BFPT", LTYPEG, ABFPT,
423 "BFPF", LTYPEG, ABFPF,
425 "WORD", LTYPEH, AWORD,
428 "NOSCHED", LSCHED, 0x80,
440 nullgen.type = D_NONE;
441 nullgen.name = D_NONE;
445 for(i=0; i<sizeof(nullgen.sval); i++)
453 for(i=0; i<NHASH; i++)
455 for(i=0; itab[i].name; i++) {
456 s = slookup(itab[i].name);
457 s->type = itab[i].type;
458 s->value = itab[i].value;
461 pathname = allocn(pathname, 0, 100);
462 if(mygetwd(pathname, 99) == 0) {
463 pathname = allocn(pathname, 100, 900);
464 if(mygetwd(pathname, 999) == 0)
465 strcpy(pathname, "/???");
489 outcode(AEND, &nullgen, NREG, &nullgen);
494 zname(char *n, int t, int s)
498 Bputc(&obuf, t); /* type */
499 Bputc(&obuf, s); /* sym */
515 Bputc(&obuf, a->type);
516 Bputc(&obuf, a->reg);
518 Bputc(&obuf, a->name);
521 print("unknown type %d\n", a->type);
546 for(i=0; i<NSNAME; i++) {
553 ieeedtod(&e, a->dval);
555 Bputc(&obuf, e.l>>8);
556 Bputc(&obuf, e.l>>16);
557 Bputc(&obuf, e.l>>24);
559 Bputc(&obuf, e.h>>8);
560 Bputc(&obuf, e.h>>16);
561 Bputc(&obuf, e.h>>24);
567 outcode(int a, Gen *g1, int reg, Gen *g2)
579 if(sf < 0 || sf >= NSYM)
585 zname(s->name, t, sym);
599 if(st < 0 || st >= NSYM)
605 zname(s->name, t, sym);
618 Bputc(&obuf, reg|nosched);
619 Bputc(&obuf, lineno);
620 Bputc(&obuf, lineno>>8);
621 Bputc(&obuf, lineno>>16);
622 Bputc(&obuf, lineno>>24);
627 if(a != AGLOBL && a != ADATA)
641 for(h = hist; h != H; h = h->link) {
644 /* on windows skip drive specifier in pathname */
645 if(systemtype(Windows) && p && p[1] == ':'){
649 if(p && p[0] != c && h->offset == 0 && pathname){
650 /* on windows skip drive specifier in pathname */
651 if(systemtype(Windows) && pathname[1] == ':') {
655 } else if(pathname[0] == c){
665 n = 1; /* leading "/" */
666 *p = '/'; /* don't emit "\" on windows */
675 Bputc(&obuf, D_FILE); /* type */
676 Bputc(&obuf, 1); /* sym */
687 g.offset = h->offset;
689 Bputc(&obuf, AHISTORY);
691 Bputc(&obuf, h->line);
692 Bputc(&obuf, h->line>>8);
693 Bputc(&obuf, h->line>>16);
694 Bputc(&obuf, h->line>>24);
700 #include "../cc/lexbody"
701 #include "../cc/macbody"
702 #include "../cc/compat"