2 * Simple Test program for libtcc
4 * libtcc can be useful to use tcc as a "backend" for a code generator.
11 /* this function is called by the generated code */
23 " return fib(n-1) + fib(n-2);\n"
28 " printf(\"Hello World!\\n\");\n"
29 " printf(\"fib(%d) = %d\\n\", n, fib(n));\n"
30 " printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n"
34 int main(int argc
, char **argv
)
43 fprintf(stderr
, "Could not create tcc state\n");
47 /* MUST BE CALLED before any compilation or file loading */
48 tcc_set_output_type(s
, TCC_OUTPUT_MEMORY
);
50 tcc_compile_string(s
, my_program
);
52 /* as a test, we add a symbol that the compiled program can use.
53 You may also open a dll with tcc_add_dll() and use symbols from that */
54 tcc_add_symbol(s
, "add", add
);
56 /* get needed size of the code */
57 size
= tcc_relocate(s
, NULL
);
61 /* allocate memory and copy the code into it */
65 /* get entry symbol */
66 func
= tcc_get_symbol(s
, "foo");
70 /* delete the state */