[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Dynamic code generation

From: j . eh
Subject: [Tinycc-devel] Dynamic code generation
Date: Sun, 18 Aug 2013 14:56:07 -0500
User-agent: Mutt/1.4.1i


Saw the post about perl bindings this morning; lots of code to just extract
function signatures (even in perl ;-)) when the required information
is at your fingertips. Recalled using Haskell (GHC) parser generator
for similar tasks although not in the context of using tcc.
A while back, I was playing with the dynamic code generation
facilities using the example code in libtcc_test.c and noticed
couple of additional missing pieces. Decided to spent some time
in cooking up something to address some of these issues; the result
is attached as a diff. Added some functions to retrieve information
about declared symbols, struct definitions, and values of
object-like macros. Please see libtcc.h and libtcc_test.c to get
an idea about how to use these. Added a new function:

    tcc_compile_string_partial(TCCState *s, char *src, int final)

This permits compilation from multiple source strings keeping the
stacks intact as long as 'final' is 0:

    tcc_compile_string_partial(s, prgm_source, 0)

Inspect symbols such as function declarations to get the return
and the parameter types (see libtcc.h and libtcc_test.c for
example). One probably will generate wrapper functions suitable
for the host language, and compile that as the final piece:

    tcc_compile_string_partial(s, wrapper_source, 1)

Then generate the code as usual.

It seems necessary to carry around the entire TCCState when
only the memory for the code is really of interest. tcc_delete()
deletes the memory provided by the user, kinda impolite thing
to do. If that memory is kept, then the user can decide when to
free it. It seems to work even with multiple states. The process
goes something like this:

    req_mem_size = tcc_relocate(s, NULL);
    /* allocate memory */
    tcc_relocate(s, memory);
    tcc_delete_ret_code*(s); /* code memory is still there */

[* new function, can't think of a better name at this moment :-(.]

We can use the code, and later free it when no longer needed.



P.S. the diff is against the code in the mob branch.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]