cbind - Translator for "thin" Ada bindings to C REVISION 4: Includes new features added by Mitch Gart to support Ada 95 and the gnat compiler. See also: README ------------------------------------------------------------------- NOTE: if the source file you're translating is copyrighted then the translation of the source is also copyrighted! ------------------------------------------------------------------- The source distribution of this tool is available by anonymous ftp at rational.com in the directory public/tools/cbind. If you received this tool by another distribution you may wish to check the rational server to see if an updated version exists. Apply any patches that may exist for the tool before compiling (see README). This tool has thus far been ported to the following Ada compilers: Rational VADS Irvine Compiler GNAT To be very useful your Ada compiler should have some mechanism for supporting unsigned integer types and C unions. C unions translate into records with representation clauses which cause the fields to overlap. This is not legal but a FEW compilers have some switch or pragma which will allow it (why they allow preprocessing, function pointers and unsigned integer types but not unions is beyond me). My guess is that when a union is generated you'll most likely wish to hand edit the source to create a variant record. Unfortunately there isn't enough information in the C type system for the tool to do this for you. Try the -fun switch. You will need to write a package named "C" which defines many of the C predefined types. It should become quickly obvious what types need to be defined. Here is an example for the VADS compiler: with unsigned_types; with system; package c is max_bound: constant := 2**14; -- High bound for: char *argv[] subtype double is standard.float; subtype float is standard.short_float; subtype signed_int is integer; subtype signed_short is short_integer; subtype signed_char is tiny_integer; subtype unsigned_int is unsigned_types.unsigned_integer; subtype unsigned_short is unsigned_types.unsigned_short_integer; subtype unsigned_char is unsigned_types.unsigned_tiny_integer; subtype void is integer; subtype function_pointer is system.address; type charp is access character; -- or maybe -- type charv is array(natural) of character; -- type charp is access charv; type bits1 is range 0 .. 2**0; for bits1'size use 1; type bits2 is range 0 .. 2**1; for bits2'size use 2; type bits3 is range 0 .. 2**2; for bits3'size use 3; type bits4 is range 0 .. 2**3; for bits4'size use 4; type bits5 is range 0 .. 2**4; for bits5'size use 5; type bits6 is range 0 .. 2**5; for bits6'size use 6; type bits7 is range 0 .. 2**6; for bits7'size use 7; type bits8 is range 0 .. 2**7; for bits8'size use 8; type bits9 is range 0 .. 2**8; for bits9'size use 9; type bits10 is range 0 .. 2**9; for bits10'size use 10; type bits11 is range 0 .. 2**10; for bits11'size use 11; type bits12 is range 0 .. 2**11; for bits12'size use 12; type bits13 is range 0 .. 2**12; for bits13'size use 13; type bits14 is range 0 .. 2**13; for bits14'size use 14; type bits15 is range 0 .. 2**14; for bits15'size use 15; type bits16 is range 0 .. 2**15; for bits16'size use 16; type bits17 is range 0 .. 2**16; for bits17'size use 17; type bits18 is range 0 .. 2**17; for bits18'size use 18; type bits19 is range 0 .. 2**18; for bits19'size use 19; type bits20 is range 0 .. 2**19; for bits20'size use 20; type bits21 is range 0 .. 2**20; for bits21'size use 21; type bits22 is range 0 .. 2**21; for bits22'size use 22; type bits23 is range 0 .. 2**22; for bits23'size use 23; type bits24 is range 0 .. 2**23; for bits24'size use 24; type bits25 is range 0 .. 2**24; for bits25'size use 25; type bits26 is range 0 .. 2**25; for bits26'size use 26; type bits27 is range 0 .. 2**26; for bits27'size use 27; type bits28 is range 0 .. 2**27; for bits28'size use 28; type bits29 is range 0 .. 2**28; for bits29'size use 29; type bits30 is range 0 .. 2**29; for bits30'size use 30; end c; example: To get invocation help: % cbind To generate a binding for gen.c and all of it's include files: % cbind -C -cs -ap -ratonal -fun gen.c or maybe % cbind gen.c To examine the preprocessed source: % cbind -p gen.c