2 * Simple Test program for libtcc
4 * libtcc can be useful to use tcc as a "backend" for a code generator.
12 /* this function is called by the generated code */
24 " return fib(n-1) + fib(n-2);\n"
29 " printf(\"Hello World!\\n\");\n"
30 " printf(\"fib(%d) = %d\\n\", n, fib(n));\n"
31 " printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n"
35 int main(int argc
, char **argv
)
42 fprintf(stderr
, "Could not create tcc state\n");
46 /* if tcclib.h and libtcc1.a are not installed, where can we find them */
47 if (argc
== 2 && !memcmp(argv
[1], "lib_path=",9))
48 tcc_set_lib_path(s
, argv
[1]+9);
50 /* MUST BE CALLED before any compilation */
51 tcc_set_output_type(s
, TCC_OUTPUT_MEMORY
);
53 if (tcc_compile_string(s
, my_program
) == -1)
56 /* as a test, we add a symbol that the compiled program can use.
57 You may also open a dll with tcc_add_dll() and use symbols from that */
58 tcc_add_symbol(s
, "add", add
);
60 /* relocate the code */
61 if (tcc_relocate(s
) < 0)
64 /* get entry symbol */
65 func
= tcc_get_symbol(s
, "foo");
72 /* delete the state */