Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-07

Tool to create C-Header from Pascal source?

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matthias Klumpp

Hi!
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.
Regards
Matthias Klumpp

Reply by email

dmitry boyarintsev
to Matthias Klumpp
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.

You can try to use fcl-passrc for the this.

thanks,
dmitry

Reply by email

Jonas Maebe
to Matthias Klumpp: Hi! Is there a tool to generate C headers from Pascal library source files? The Delphi…
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

Reply by email

Matthias Klumpp
to Jonas Maebe

Okay, than I'll do it by myself.
Thanks for your explanation! If I had a little more time, I would like to look at the code to improve it, but cause I don't know much about compiler development this wouldn't be the best idea. I'm faster if I just translate everything manually.

Jonas Maebe wrote 10 lines
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

Show quoted text 5 lines
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

Show quoted text 16 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email