On 11 Jul 2010, at 21:15, Matthias Klumpp wrote:

> Is there a tool to generate C headers from Pascal library source files? The
> Delphi compiler can do this, but I would need a solution for Linux.
> If there's not such a tool, I would have to do everything by hand, which is
> a lot of effort.

I was contracted a while ago to create a basis for this in FPC itself. The code 
I wrote does *not* generate C headers, but it does offer all type and symbol 
information in a generic way that would enable implementing generating C 
headers from it (the only implemented "backend" simply dumps all collected 
information in a plain text format). I haven't found time yet to integrate it 
in FPC itself though.

Note that some of the extra work still necessary would be:
a) generating FPC units containing procedural cdecl wrappers for all 
class/object methods (and for functions/procedures using non-cdecl calling 
conventions on i386)
b) munging all global symbol names (types, variables, procedures), since in 
Pascal every unit has its own name space while in C everything exists in one 
single global name space (or at least doing that in case of conflicts -- but 
since such conflicts can arise as soon as your code depends on one more unit, 
it might seem prudent to do this from the start somehow, even if the result 
won't be very pretty)
c) actually generating C headers from the collected information (my code only 
extracts a bunch of information from internal compiler structures and presents 
it in a generic tree structure)

I think that the compiler itself is the most appropriate place to implement 
this exporting (rather than, e.g., fcl-passrc), because you need details from 
the code generator level to do it correctly, e.g.
* you have to know whether to generate C prototypes with pointer or value 
parameter arguments, so you need to know how the compiler passes a particular 
parameter on the current platform (so keep in mind that the generated C headers 
would always be completely specific to a particular architecture/OS combination 
with this approach!)
* what the offsets of individual fields in records are, so you can add padding 
in the C versions of the records where necessary

But in short: no, currently there is no way yet to do what you want.


Jonas_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to