diff options
| author | grischka <grischka> | 2009-04-16 22:03:03 +0200 |
|---|---|---|
| committer | grischka <grischka> | 2009-04-18 15:08:02 +0200 |
| commit | 795f67428e7863353d7c466c211d8fcbb9e8c988 (patch) | |
| tree | a2c7195cb7a651325dce6f51c51b9a318664e7b3 /libtcc_test.c | |
| parent | 9a8b2912ed2e3de97cde5fec0e886a0660fe6b5f (diff) | |
| download | tinycc-795f67428e7863353d7c466c211d8fcbb9e8c988.tar.gz tinycc-795f67428e7863353d7c466c211d8fcbb9e8c988.tar.bz2 | |
alternative int tcc_relocate(TCCState *s1, void *ptr);
Diffstat (limited to 'libtcc_test.c')
| -rw-r--r-- | libtcc_test.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/libtcc_test.c b/libtcc_test.c index c67d4f3..4c16902 100644 --- a/libtcc_test.c +++ b/libtcc_test.c @@ -36,6 +36,8 @@ int main(int argc, char **argv) TCCState *s; int (*func)(int); unsigned long val; + void *mem; + int size; s = tcc_new(); if (!s) { @@ -53,13 +55,25 @@ int main(int argc, char **argv) with tcc_add_dll(() and using its symbols directly. */ tcc_add_symbol(s, "add", (unsigned long)&add); - tcc_relocate(s); + /* 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 */ tcc_get_symbol(s, &val, "foo"); func = (void *)val; + /* delete the state */ + tcc_delete(s); + + /* run the code */ func(32); - tcc_delete(s); + free(mem); return 0; } |
