int main(int argc, char **argv) { Optctx ctx; size_t i; FILE *f; localincpath = "."; optinit(&ctx, "sd:hmo:p:l:", argv, argc); while (!optdone(&ctx)) { switch (optnext(&ctx)) { case 'h': usage(argv[0]); exit(0); break; case 'p': pkgname = ctx.optarg; break; case 'o': outfile = ctx.optarg; break; case 'd': while (ctx.optarg && *ctx.optarg) debugopt[*ctx.optarg++ & 0x7f] = 1; break; case 'l': lappend(&extralibs, &nextralibs, ctx.optarg); break; default: usage(argv[0]); exit(0); break; } } if (!outfile && !show) { fprintf(stderr, "output file needed when merging usefiles.\n"); exit(1); } if (!pkgname) { fprintf(stderr, "package needed when merging usefiles.\n"); exit(1); } /* read and parse the file */ initfile(&file, outfile); updatens(file.globls, pkgname); for (i = 0; i < ctx.nargs; i++) mergeuse(ctx.args[i]); loaduses(); infer(); tagexports(1); addextlibs(extralibs, nextralibs); /* generate the usefile */ f = fopen(outfile, "w"); writeuse(f); fclose(f); return 0; }
int main(int argc, char **argv) { char buf[1024]; Stab *globls; Optctx ctx; size_t i; outfile = NULL; optinit(&ctx, "cd:?hSo:I:9G:", argv, argc); asmsyntax = Defaultasm; while (!optdone(&ctx)) { switch (optnext(&ctx)) { case 'o': outfile = ctx.optarg; break; case 'S': writeasm = 1; break; case '?': case 'h': usage(argv[0]); exit(0); break; case 'c': extracheck = 1; break; case 'd': while (ctx.optarg && *ctx.optarg) debugopt[*ctx.optarg++ & 0x7f]++; break; case '9': asmsyntax = Plan9; break; case 'G': if (!strcmp(ctx.optarg, "e")) asmsyntax = Gnugaself; else if (!strcmp(ctx.optarg, "m")) asmsyntax = Gnugasmacho; else die("unknown gnu syntax flavor"); break; case 'I': lappend(&incpaths, &nincpaths, ctx.optarg); break; default: usage(argv[0]); exit(0); break; } } lappend(&incpaths, &nincpaths, Instroot "/lib/myr"); if (ctx.nargs == 0) { fprintf(stderr, "No input files given\n"); exit(1); } else if (ctx.nargs > 1) outfile = NULL; for (i = 0; i < ctx.nargs; i++) { globls = mkstab(0); tyinit(globls); tokinit(ctx.args[i]); file = mkfile(ctx.args[i]); file->file.globls = globls; yyparse(); /* before we do anything to the parse */ if (debugopt['T']) dump(file, stdout); infer(file); if (hasmain(file)) geninit(file); tagexports(file, 0); /* after all type inference */ if (debugopt['t']) dump(file, stdout); if (writeasm) { if (outfile != NULL) swapout(buf, sizeof buf, ".s"); else swapsuffix(buf, sizeof buf, ctx.args[i], ".myr", ".s"); } else { gentempfile(buf, sizeof buf, ctx.args[i], ".s"); } genuse(ctx.args[i]); gen(file, buf); assemble(buf, ctx.args[i]); } return 0; }