Example #1
0
int main(int argc, char **argv)
{
    int dargc;
    char **arg, **dargv;

    if (argc == 1)
    {
        printf("\nUsage :%s filename[.pas]\n\n", argv[0]);
        return 1;
    }

    memset(arena, 0, sizeof(arena));
    printf("\nCompiling...\n");

    arg = argv + 1;
    dargc = 0;
    dargv = malloc(argc * sizeof(char *));

    prepare_file(arg[0]);

    global_env.u.program.argc = dargc;
    global_env.u.program.argv = dargv;

    /*IR = &x86_dos_interface;*/

    yyparse();
    fclose(ifp);

    if (!err_occur())
    {
        emit_asm();
        print_result(pasname);
        return 0;
    }
    else
    {
        clear();
        print_result(pasname);
        return 1;
    }

    finalize();

    free(dargv);

    return 0;
}
Example #2
0
int main(int argc, char **argv)
{
    int dargc;
    char **arg, **dargv;


    if (argc == 1)
    {
        printf("\nUsage :%s [-t targetmachine] [-d stad] filename[.pas]\n\n", argv[0]);
        return 1;
    }

	init_spl();

    arg = argv + 1;
    dargc = 0;
    dargv = malloc(argc * sizeof(char *));

    /*
     * arguments not recognized by main is pased to 
     * target program_begin
     */
    while(arg)
    {
        if (**(arg) == '-')
        {
            switch(arg[0][1])
            {
            case 't':
				if (strlen(*arg) == 2)
				{
                	arg++;
                	IR = find_target(*arg);
				}
				else
				{
                	IR = find_target(*arg + 2);
				}

                if (IR == NULL)
                {
                    printf("Can't find target %s, only x86dos and x86linux is supported.\n",
                           *arg);
                    return 1;
                }

                arg++;
                break;
            case 'd':
                {
                    char *p = arg[1];
                    while (*p)
                    {
                        switch(*p++)
                        {
                        case 's':
                            dump_source = 1;
                            break;
                        case 'a':
                            dump_ast = 1;
                            break;
                        case 't':
                            dump_token = 1;
                            break;
                        case 'd':
                            dump_dag = 1;
                            break;
                        default:
                            printf("Unkown dump option %c.\n", *(p - 1));
                            break;
                        }
                    }
                }
                arg++;
                arg++;
                break;
            default:
                dargv[dargc++] = *arg++;
                dargv[dargc++] = *arg++;
                break;
            }
        }
        else
        {
            prepare_file(arg[0]);
            break;
        }
    }



    global_env.u.program.argc = dargc;
    global_env.u.program.argv = dargv;

#ifndef GENERATE_AST
	IR = find_target("x86dos");
#endif

    yyparse();
    fclose(ifp);

    if (!err_occur())
    {
        emit_asm();
        print_result(pasname);
        return 0;
    }
    else
    {
        clear();
        print_result(pasname);
        return 1;
    }

    finalize();

    free(dargv);

    return 0;
}