Example #1
0
File: test.c Project: bigos/radare2
int main(int argc, char **argv) {
	TCCState *T = tcc_new ();
	//T->nostdlib = 1;
//	tcc_set_output_type(T, TCC_OUTPUT_MEMORY); //PREPROCESS);
	//tcc_output_file (T, "test.cpp");
	const char *file = argc>1? argv[1]: "test.cparse";
	if (tcc_add_file (T, file) == -1) {
		printf ("Cannot parse file\n");
		return 1;
	}

	tcc_compile_string (T,
		"int foo = 3;"
		"int bar = 10;");
	tcc_delete (T);
}
Example #2
0
TCCState * tcc_init_state(void)
{
	int i;
	TCCState *tcc_state = NULL;
	tcc_state = tcc_new();
	if (!tcc_state) {
		fprintf(stderr, "Impossible de creer un contexte TCC\n");
		exit(1);
	}
	tcc_set_output_type(tcc_state, TCC_OUTPUT_MEMORY);

	//tcc_add_file(tcc_state, libcodenat_path);
	for (i=0;i<lib_array_count; i++){
		tcc_add_file(tcc_state, lib_array[i]);
	}

	for (i=0;i<include_array_count; i++){
		tcc_add_include_path(tcc_state, include_array[i]);
	}
	return tcc_state;
}
Example #3
0
File: tcc.c Project: raldoni/tcc
int main(int argc, char **argv)
{
    TCCState *s;
    int ret, optind, i;
    int64_t start_time = 0;

    s = tcc_new();

    optind = tcc_parse_args(s, argc - 1, argv + 1);

    if (s->do_bench)
        start_time = getclock_us();

    tcc_set_environment(s);

    if (optind == 0) {
        help();
        return 1;
    }

    if (s->option_m)
        exec_other_tcc(s, argv, s->option_m);

    if (s->verbose)
        display_info(s, 0);

    if (s->print_search_dirs || (s->verbose == 2 && optind == 1)) {
        tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
        display_info(s, 1);
        return 0;
    }

    if (s->verbose && optind == 1)
        return 0;

    if (s->nb_files == 0)
        tcc_error("no input files\n");

    /* check -c consistency : only single file handled. XXX: checks file type */
    if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) {
        if (s->nb_libraries != 0)
            tcc_error("cannot specify libraries with -c");
        /* accepts only a single input file */
        if ((s->nb_files != 1) && s->outfile) {
            tcc_error("cannot specify multiple files with -c and -o");
        }
    }

    if (s->output_type == TCC_OUTPUT_PREPROCESS) {
        if (!s->outfile) {
            s->ppfp = stdout;
        } else {
            s->ppfp = fopen(s->outfile, "w");
            if (!s->ppfp)
                tcc_error("could not write '%s'", s->outfile);
        }
    }

    tcc_set_output_type(s, s->output_type);

    /* compile or add each files or library */
    for(i = ret = 0; i < s->nb_files && ret == 0; i++) {
        int filetype = *(unsigned char *)s->files[i];
        const char *filename = s->files[i] + 1;
        if (filename[0] == '-' && filename[1] == 'l') {
            if (tcc_add_library(s, filename + 2) < 0) {
                tcc_error_noabort("cannot find library 'lib%s'", filename+2);
                ret = 1;
            }
        } else {
            if (1 == s->verbose)
                printf("-> %s\n", filename);
            if (!s->outfile)
                s->outfile = default_outputfile(s, filename);
            if (tcc_add_file(s, filename, filetype) < 0)
                ret = 1;
            else
            if (s->output_type == TCC_OUTPUT_OBJ) {
                ret = !!tcc_output_file(s, s->outfile);
                if (s->gen_deps && !ret)
                    gen_makedeps(s, s->outfile, s->deps_outfile);
                if (!ret) {
                    if ((i+1) < s->nb_files) {
                        tcc_delete(s);
                        s = tcc_new();
                        tcc_parse_args(s, argc - 1, argv + 1);
                        tcc_set_environment(s);
                        if (s->output_type != TCC_OUTPUT_OBJ)
                            tcc_error("interlnal error");
                        tcc_set_output_type(s, s->output_type);
                    }
                }
            }
        }
    }

    if (0 == ret) {
        if (s->output_type == TCC_OUTPUT_MEMORY) {
#ifdef TCC_IS_NATIVE
            ret = tcc_run(s, argc - 1 - optind, argv + 1 + optind);
#else
            tcc_error_noabort("-run is not available in a cross compiler");
            ret = 1;
#endif
        } else
        if (s->output_type == TCC_OUTPUT_EXE ||
            s->output_type == TCC_OUTPUT_DLL)
        {
            ret = !!tcc_output_file(s, s->outfile);
            if (s->gen_deps && !ret)
                gen_makedeps(s, s->outfile, s->deps_outfile);
        }
    }

    if (s->do_bench)
        tcc_print_stats(s, getclock_us() - start_time);

    tcc_delete(s);
    return ret;
}