Пример #1
0
static cfunc codegen( TCCState *s, const char *prog, const char *fname )
{
    unsigned long val;

    if (s) 
       tcc_delete(s);
    
    s = tcc_new();
    if (!s) 
       return 0;

    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
    tcc_compile_string(s, prog);

/*     tcc_add_dll("/usr/lib/libm.so"); */

    tcc_add_symbol(s, "TEX", (unsigned long)&TEX);
    tcc_add_symbol(s, "TXB", (unsigned long)&TXB);
    tcc_add_symbol(s, "TXP", (unsigned long)&TXP);


    tcc_relocate(s);
    tcc_get_symbol(s, &val, fname);
    return (cfunc) val;
}
Пример #2
0
string oclraster_program::preprocess_code(const string& raw_code) {
	// init
	string ret_code = "";
	TCCState* state = tcc_new();
	state->output_type = TCC_OUTPUT_PREPROCESS;
	
	// split build options and let tcc parse them
	const string kernels_include_path = "-I" + core::strip_path(oclraster::kernel_path("")) + " ";
	const auto build_option_args = core::tokenize(kernels_include_path+build_options, ' ');
	const size_t argc = build_option_args.size();
	vector<const char*> argv;
	for(const auto& arg : build_option_args) {
		argv.emplace_back(arg.data());
	}
	tcc_parse_args(state, (int)argc, &argv[0]);
	
	// in-memory preprocessing
	const uint8_t* code_input = (const uint8_t*)raw_code.c_str();
	tcc_in_memory_preprocess(state, code_input, raw_code.length(), false, NULL, &ret_code,
							 [](const char* str, void* ret) -> void {
								 *(string*)ret += str;
							 });
	
	// cleanup + return
	tcc_delete(state);
	//oclr_msg("preprocessed code: %s", ret_code);
	return ret_code;
}
Пример #3
0
/*
 * Compile source code and call a callback with a pointer to the symbol "f".
 */
static int run_callback(const char *src, callback_type callback) {
  TCCState *s;
  int result;
  void *ptr;
  
  s = tcc_new();
  if (!s)
    return -1;
  if (tccdir)
    tcc_set_lib_path(s, tccdir);
  if (include_dir) {
    if (tcc_add_include_path(s, include_dir) == -1)
      return -1;
  }
  if (tcc_set_output_type(s, TCC_OUTPUT_MEMORY) == -1)
    return -1;
  if (tcc_compile_string(s, src) == -1)
    return -1;
  if (tcc_relocate(s, TCC_RELOCATE_AUTO) == -1)
    return -1;
  
  ptr = tcc_get_symbol(s, "f");
  if (!ptr)
    return -1;
  result = callback(ptr);
  
  tcc_delete(s);
  
  return result;
}
Пример #4
0
int main(int argc, char **argv)
{
    TCCState *s;
    int (*func)(int);
    unsigned long val;
    
    s = tcc_new();
    if (!s) {
        fprintf(stderr, "Could not create tcc state\n");
        exit(1);
    }

    /* MUST BE CALLED before any compilation or file loading */
    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

    tcc_compile_string(s, my_program);

    /* as a test, we add a symbol that the compiled program can be
       linked with. You can have a similar result by opening a dll
       with tcc_add_dll(() and using its symbols directly. */
    tcc_add_symbol(s, "add", (unsigned long)&add);
    
    tcc_relocate(s);

    tcc_get_symbol(s, &val, "foo");
    func = (void *)val;

    func(32);

    tcc_delete(s);
    return 0;
}
Пример #5
0
/*time_t lastmodtime;*/
int recompile()
{
	/*
	struct stat file_stat;
	int err = stat("update.c", &file_stat);

	if( !g_tcc )
	{
	lastmodtime = file_stat.st_mtime;		
	}
	else
	{
	if( lastmodtime == file_stat.st_mtime )
	return 0;
	lastmodtime = file_stat.st_mtime;
	}
	*/
	printf("recompile\n");
	FILE* f = fopen( "update.c", "rb" );	// MUST be "rb" on windows - othersize CRLF will be converted to \n, and file size will be wrong (CRLF:2bytes, \n:1bytes)
	fseek(f, 0L, SEEK_END);
	long sz = ftell(f);
	fseek(f, 0L, SEEK_SET);
	char* program = (char*)malloc( sz+1 );
	fread( program, sz, 1, f ); 
	program[sz] = '\0';
	fclose(f);

	TCCState* s = tcc_new();
	tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

	int n;
	tcc_set_error_func(s, &n, compile_err);

	addSymbols(s);

	int compileResult = tcc_compile_string(s, program);
	free( program );

	if ( compileResult == -1)
	{
		return 1;
	}
	
	tcc_add_library_path(s,".");
	
	/* relocate the code */
	if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
		return 1;

	/* get entry symbol */
	update = (updatefp_t)tcc_get_symbol(s, "update");
	if (!update)
		return 1;

	if( g_tcc ) tcc_delete(g_tcc);
	g_tcc = s;

	printf("recompile ok\n");
	return 0;
}
Пример #6
0
int main(int, char **)
{
    char program[] = "int foo() { return 123; }";
    TCCState *s = tcc_new();

    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

    if (tcc_compile_string(s, program) != -1)
    {
        int size = tcc_relocate(s, nullptr);
        if (size > 0)
        {
            void *mem = malloc(size);
            tcc_relocate(s, mem);

            int(*foo)() = (int(*)())tcc_get_symbol(s, "foo");
            if (foo != nullptr)
            {
                printf("%d", foo());
            }

            free(mem);
        }
    }
    tcc_delete(s);

    return 0;
}
Пример #7
0
int main(int argc, char **argv)
{
    TCCState *s;
    int (*foobar_func)(int);

    if(NULL == (s = tcc_new())){
            fprintf(stderr, "Allocation of a new TCC compilation enviroment failed\n");
            return 1;
    }

    tcc_set_output_type(s, TCC_OUTPUT_MEMORY); /*Do everything in memory!*/

    if(tcc_compile_string(s, my_program) > 0) 
            return -1;

    tcc_add_symbol(s, "add", add); /*add in that missing symbol*/

    tcc_relocate(s);

    foobar_func = tcc_get_symbol(s, "foobar");

    printf("foobar returned: %d\n", foobar_func(7));

    tcc_delete(s);

    return 0;
}
Пример #8
0
/* TODO: store the state globally or so.. */
static int r_lang_tcc_run(struct r_lang_t *lang, const char *code, int len)
{
	TCCState *ts = tcc_new ();
	/* TODO: set defined vars as global */
	//list_for_each(lang->defs) {
	tcc_compile_string (ts, code);
	tcc_run (ts, 0, 0);//argc, argv);
	tcc_delete (ts);
	return R_TRUE;
}
Пример #9
0
int main(int argc, char **argv)
{
    TCCState *s;
    int i;
    int (*func)(int);

    s = tcc_new();
    if (!s) {
        fprintf(stderr, "Could not create tcc state\n");
        exit(1);
    }

    /* if tcclib.h and libtcc1.a are not installed, where can we find them */
    for (i = 1; i < argc; ++i) {
        char *a = argv[i];
        if (a[0] == '-') {
            if (a[1] == 'B')
                tcc_set_lib_path(s, a+2);
            else if (a[1] == 'I')
                tcc_add_include_path(s, a+2);
            else if (a[1] == 'L')
                tcc_add_library_path(s, a+2);
        }
    }

    /* MUST BE CALLED before any compilation */
    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

    if (tcc_compile_string(s, my_program) == -1)
        return 1;

    /* as a test, we add a symbol that the compiled program can use.
       You may also open a dll with tcc_add_dll() and use symbols from that */
    tcc_add_symbol(s, "add", add);

    /* relocate the code */
    if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
        return 1;

    /* get entry symbol */
    func = tcc_get_symbol(s, "foo");
    if (!func)
        return 1;

    /* run the code */
    func(32);

    /* delete the state */
    tcc_delete(s);

    return 0;
}
Пример #10
0
int main(int argc, char **argv)
{
    TCCState *s;
    int (*func)(int);
    void *mem;
    int size;

    s = tcc_new();
    if (!s) {
        fprintf(stderr, "Could not create tcc state\n");
        exit(1);
    }

    /* if tcclib.h and libtcc1.a are not installed, where can we find them */
    if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
        tcc_set_lib_path(s, argv[1]+9);

    /* MUST BE CALLED before any compilation */
    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

    if (tcc_compile_string(s, my_program) == -1)
        return 1;

    /* as a test, we add a symbol that the compiled program can use.
       You may also open a dll with tcc_add_dll() and use symbols from that */
    tcc_add_symbol(s, "add", add);

    /* get needed size of the code */
    size = tcc_relocate(s, NULL);
    if (size == -1)
        return 1;

    /* allocate memory and copy the code into it */
    mem = malloc(size);
    tcc_relocate(s, mem);

    /* get entry symbol */
    func = tcc_get_symbol(s, "foo");
    if (!func)
        return 1;

    /* delete the state */
    tcc_delete(s);

    /* run the code */
    func(32);

    free(mem);
    return 0;
}
Пример #11
0
static tinycc_t *
_newTinycc (const char *opts) {
    tinycc_t *tcc = (tinycc_t *) calloc (1,sizeof (tinycc_t));
    if (tcc) {
        tcc->s = tcc_new ();
        if (tcc->s) {
            if (opts) {
                tcc_set_options (tcc->s,opts); /* handle error condition here? */
            }
        } else {
            DEBUGP (DERR,"_newTinycc","unable to allocate new TCC State object!");
            I (DynamicCompiler)->destroy (&tcc);
        }
    }
    return tcc;
}
Пример #12
0
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);
}
Пример #13
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;
}
Пример #14
0
Файл: tcc.c Проект: 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;
}
Пример #15
0
Файл: pitu.c Проект: fglock/Pitu
int main(int argc, char **argv)
{
    TCCState *s;
    int (*func)(int);

    s = tcc_new();
    if (!s) {
        fprintf(stderr, "Could not create tcc state\n");
        exit(1);
    }

    /* if tcclib.h and libtcc1.a are not installed, where can we find them */
    if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
        tcc_set_lib_path(s, argv[1]+9);

    /* MUST BE CALLED before any compilation */
    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

    if (tcc_compile_string(s, my_program_1) == -1)
        return 1;
    if (tcc_compile_string(s, my_program_2) == -1)
        return 1;

    /* as a test, we add a symbol that the compiled program can use.
       You may also open a dll with tcc_add_dll() and use symbols from that */
    tcc_add_symbol(s, "add", add);

    /* relocate the code */
    if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
        return 1;

    /* get entry symbol */
    func = tcc_get_symbol(s, "foo");
    if (!func)
        return 1;

    /* run the code */
    func(32);

    /* delete the state */
    tcc_delete(s);

// start again


    s = tcc_new();
    if (!s) {
        fprintf(stderr, "Could not create tcc state\n");
        exit(1);
    }

    /* if tcclib.h and libtcc1.a are not installed, where can we find them */
    if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
        tcc_set_lib_path(s, argv[1]+9);

    /* MUST BE CALLED before any compilation */
    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

    if (tcc_compile_string(s, my_program_1) == -1)
        return 1;
    // if (tcc_compile_string(s, my_program_2) == -1)
    //     return 1;
    if (tcc_compile_string(s, my_program_3) == -1)
       return 1;


    /* as a test, we add a symbol that the compiled program can use.
       You may also open a dll with tcc_add_dll() and use symbols from that */
    tcc_add_symbol(s, "add", add);

    /* relocate the code */
    if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
        return 1;

    /* get entry symbol */
    func = tcc_get_symbol(s, "foo");
    if (!func)
        return 1;

    /* run the code */
    func(32);

    /* delete the state */
    tcc_delete(s);



    return 0;
}
Пример #16
0
int loadScript()
{
    TCCState *s;
    char *buf, *source;
    int size, i;

    if (!(buf = lvgGetFileContents("main.c", 0)))
    {
        printf("error: could not open C script.\n");
        return -1;
    }
    source = malloc(strlen((char *)allh_h) + strlen(buf) + 1);
    source[0] = 0;
    strcat(source, (char *)allh_h);
    strcat(source, buf);
    free(buf);

    s = tcc_new();
    tcc_set_error_func(s, 0, tcc_error_func);
    //tcc_set_options(s, "-g");
    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
    tcc_set_lib_path(s, "./lib");

    if (tcc_compile_string(s, source) == -1)
        goto error;

    for (i = 0; i < sizeof(g_syms)/sizeof(g_syms[0]); i++)
        tcc_add_symbol(s, g_syms[i].m_name, g_syms[i].m_sym);
    tcc_add_symbol(s, "glCreateProgram", glCreateProgram);
    tcc_add_symbol(s, "glCreateShader", glCreateShader);
    tcc_add_symbol(s, "glShaderSource", glShaderSource);
    tcc_add_symbol(s, "glCompileShader", glCompileShader);
    tcc_add_symbol(s, "glGetShaderiv", glGetShaderiv);
    tcc_add_symbol(s, "glGetShaderInfoLog", glGetShaderInfoLog);
    tcc_add_symbol(s, "glAttachShader", glAttachShader);
    tcc_add_symbol(s, "glLinkProgram", glLinkProgram);
    tcc_add_symbol(s, "glGetProgramiv", glGetProgramiv);
    tcc_add_symbol(s, "glGetUniformLocation", glGetUniformLocation);
    tcc_add_symbol(s, "glGetAttribLocation", glGetAttribLocation);
    tcc_add_symbol(s, "glGenBuffers", glGenBuffers);
#ifdef GL3
    //tcc_add_symbol(s, "glGenVertexArrays", glGenVertexArrays);
    //tcc_add_symbol(s, "glBindVertexArray", glBindVertexArray);
#endif
    tcc_add_symbol(s, "glBindBuffer", glBindBuffer);
    tcc_add_symbol(s, "glEnableVertexAttribArray", glEnableVertexAttribArray);
    tcc_add_symbol(s, "glVertexAttribPointer", glVertexAttribPointer);
    tcc_add_symbol(s, "glBindTexture", glBindTexture);
    tcc_add_symbol(s, "glGenTextures", glGenTextures);
    tcc_add_symbol(s, "glTexParameteri", glTexParameteri);
    tcc_add_symbol(s, "glTexImage2D", glTexImage2D);
    tcc_add_symbol(s, "glDetachShader", glDetachShader);
    tcc_add_symbol(s, "glDeleteShader", glDeleteShader);
    tcc_add_symbol(s, "glDeleteProgram", glDeleteProgram);
    tcc_add_symbol(s, "glDeleteTextures", glDeleteTextures);
    tcc_add_symbol(s, "glDeleteBuffers", glDeleteBuffers);
    tcc_add_symbol(s, "glEnable", glEnable);
    tcc_add_symbol(s, "glBlendEquation", glBlendEquation);
    tcc_add_symbol(s, "glBlendFunc", glBlendFunc);
    tcc_add_symbol(s, "glDisable", glDisable);
    tcc_add_symbol(s, "glActiveTexture", glActiveTexture);
    tcc_add_symbol(s, "glUseProgram", glUseProgram);
    tcc_add_symbol(s, "glUniform1i", glUniform1i);
    tcc_add_symbol(s, "glUniformMatrix4fv", glUniformMatrix4fv);
    tcc_add_symbol(s, "glViewport", glViewport);
    tcc_add_symbol(s, "glBufferData", glBufferData);
    tcc_add_symbol(s, "glMapBuffer", glMapBuffer);
#ifdef GL3
    //tcc_add_symbol(s, "glMapBufferRange", glMapBufferRange);
#endif
    tcc_add_symbol(s, "glUnmapBuffer", glUnmapBuffer);
    tcc_add_symbol(s, "glScissor", glScissor);
    tcc_add_symbol(s, "glDrawElements", glDrawElements);
    tcc_add_symbol(s, "glPushAttrib", glPushAttrib);
    tcc_add_symbol(s, "glViewport", glViewport);
    tcc_add_symbol(s, "glMatrixMode", glMatrixMode);
    tcc_add_symbol(s, "glPushMatrix", glPushMatrix);
    tcc_add_symbol(s, "glLoadIdentity", glLoadIdentity);
    tcc_add_symbol(s, "glOrtho", glOrtho);
    tcc_add_symbol(s, "glEnableClientState", glEnableClientState);

    size = tcc_relocate(s, TCC_RELOCATE_AUTO);
    if (size == -1)
        goto error;

    onInit  = tcc_get_symbol(s, "onInit");
    onFrame = tcc_get_symbol(s, "onFrame");
    free(source);
    return 0;
error:
    free(source);
    return -1;
}
Пример #17
0
void
run_tccode(void)
{
    char * ccode;
    size_t ccodelen;

    FILE * ofd;
    TCCState *s;
    int rv;
    void * memp;
#ifdef __STRICT_ANSI__
    void * iso_workaround;
#endif

    libtcc_specials = 1;

    ofd = open_memstream(&ccode, &ccodelen);
    if (ofd == NULL) { perror("open_memstream"); exit(7); }
    print_ccode(ofd);
    putc('\0', ofd);
    fclose(ofd);

    memp = map_hugeram();

    s = tcc_new();
    if (s == NULL) { perror("tcc_new()"); exit(7); }
    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

    tcc_compile_string(s, ccode);

    tcc_add_symbol(s, "mem", memp);

    /* If our code was read from stdin it'll be done in standard mode,
     * the stdio stream is now modal (always a bad idea) so it's been switched
     * to standard mode, stupidly, it's now impossible to switch it back.
     *
     * So have the loaded C code use our getch and putch functions.
     *
     * The ugly casting is forced by the C99 standard as a (void*) is not a
     * valid cast for a function pointer.
     */

#ifdef __STRICT_ANSI__
    *(void_func*) &iso_workaround  = (void_func) &getch;
    tcc_add_symbol(s, "getch", iso_workaround);
    *(void_func*) &iso_workaround  = (void_func) &putch;
    tcc_add_symbol(s, "putch", iso_workaround);
#else
    tcc_add_symbol(s, "getch", &getch);
    tcc_add_symbol(s, "putch", &putch);

#if defined(__TCCLIB_VERSION) && __TCCLIB_VERSION == 0x000925
#define TCCDONE
    {
	int (*func)(void);
	int imagesize;
	void * image = 0;

	if (verbose)
	    fprintf(stderr, "Running C Code using libtcc 9.25.\n");

	imagesize = tcc_relocate(s, 0);
	if (imagesize <= 0) {
	    fprintf(stderr, "tcc_relocate failed to return code size.\n");
	    exit(1);
	}
	image = malloc(imagesize);
	rv = tcc_relocate(s, image);
	if (rv) {
	    fprintf(stderr, "tcc_relocate failed error=%d\n", rv);
	    exit(1);
	}

	/*
	 * The ugly casting is forced by the C99 standard as a (void*) is not a
	 * valid cast for a function pointer.
	 *
	*(void **) (&func) = tcc_get_symbol(s, "main");
	 */
	func = tcc_get_symbol(s, "main");

	if (!func) {
	    fprintf(stderr, "Could not find compiled code entry point\n");
	    exit(1);
	}
	tcc_delete(s);
	free(ccode);

	start_runclock();
	func();
	finish_runclock(&run_time, &io_time);
	free(image);
    }
#endif

#if defined(__TCCLIB_VERSION) && __TCCLIB_VERSION == 0x000926
#define TCCDONE
    {
	int (*func)(void);

	if (verbose)
	    fprintf(stderr, "Running C Code using libtcc 9.26.\n");

	rv = tcc_relocate(s);
	if (rv) {
	    perror("tcc_relocate()");
	    fprintf(stderr, "tcc_relocate failed return value=%d\n", rv);
	    exit(1);
	}

	/*
	 * The ugly casting is forced by the C99 standard as a (void*) is not a
	 * valid cast for a function pointer.
	*(void **) (&func) = tcc_get_symbol(s, "main");
	 */
	func = tcc_get_symbol(s, "main");

	if (!func) {
	    fprintf(stderr, "Could not find compiled code entry point\n");
	    exit(1);
	}
	start_runclock();
	func();
	finish_runclock(&run_time, &io_time);

	tcc_delete(s);
	free(ccode);
    }
#endif
#endif

#if !defined(TCCDONE)
    {
    static char arg0_tcclib[] = "tcclib";
    static char * args[] = {arg0_tcclib, 0};
    /*
	Hmm, I want to do the above without named initialisers ... so it looks
	like this ... but without the const problem.

    static char * args[] = {"tcclib", 0};
     */

	if (verbose)
	    fprintf(stderr, "Running C Code using libtcc tcc_run() to compile & run.\n");

	rv = tcc_run(s, 1, args);
	if (verbose && rv)
	    fprintf(stderr, "tcc_run returned %d\n", rv);
	tcc_delete(s);
	free(ccode);
    }
#endif
}
Пример #18
0
  longjmp(env, val);
}

extern "C"
void *tcc_mallocz(unsigned long size);

void Service::start()
{
  std::string code =
  R"VR(
    int test()
    {
      return 1;
    }
  )VR";
  
  debug2("Before tcc_new()\n");
  void* test = tcc_mallocz(64);
  printf("tcc internal malloc: %p\n", test);
  //tcc_set_lib_path(s, CONFIG_TCCDIR);
  
  TCCState* s;
  s = tcc_new();
  debug2("After tcc_new()\n");
  
  assert(s != nullptr);
  
  // I'll let someone else handle this part---
  printf ("Well, it starts.. GL!\n");
}