Exemplo n.º 1
0
Arquivo: node.c Projeto: oridb/mc
void
initfile(File *f, char *name)
{
	memset(f, 0, sizeof(*f));
	f->builtins = mkstab(0);
	f->globls = mkstab(0);
	f->globls->super = file.builtins;
	f->ns = mkht(strhash, streq);
	lappend(&f->files, &f->nfiles, name);
	tyinit(f->builtins);
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    FILE *f;
    int opt;
    int i;

    while ((opt = getopt(argc, argv, "hud:I:")) != -1) {
        switch (opt) {
            case 'h':
                usage(argv[0]);
                exit(0);
                break;
            case 'u':
                fromuse = 1;
                break;
            case 'd':
                debug = 1;
                while (optarg && *optarg)
                    debugopt[*optarg++ & 0x7f] = 1;
                break;
            case 'I':
                lappend(&incpaths, &nincpaths, optarg);
                break;
            default:
                usage(argv[0]);
                exit(0);
                break;
        }
    }

    for (i = optind; i < argc; i++) {
        lappend(&incpaths, &nincpaths, Instroot "/lib/myr");
        file = mkfile(argv[i]);
        file->file.exports = mkstab();
        file->file.globls = mkstab();
        tyinit(file->file.globls);
        printf("%s:\n", argv[i]);
        if (fromuse) {
            f = fopen(argv[i], "r");
            if (!f)
                die("Unable to open usefile %s\n", argv[i]);
            loaduse(f, file->file.globls);
            dumpsyms(file->file.globls, 1);
        } else {
            tokinit(argv[i]);
            yyparse();
            infer(file);
            dumpsyms(file->file.globls, 1);
        }
    }

    return 0;
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: 8l/mc
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;
}