From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,60e2922351e0e780 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-21 10:16:47 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!cyclone.bc.net!news.uunet.ca!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Generic thinbinding toolkit for C References: <3FB0B57D.6070906@noplace.com> <3FB22125.1040807@noplace.com> <3FB3751D.5090809@noplace.com> <3FB8B9BC.5040505@noplace.com> <3FBA1118.4060105@noplace.com> <0fxub.48425$bQ3.12107@nwrdny03.gnilink.net> <3FBC2EEC.212A1B5@cogeco.ca> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Fri, 21 Nov 2003 13:02:19 -0500 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1069437703 198.96.223.163 (Fri, 21 Nov 2003 13:01:43 EST) NNTP-Posting-Date: Fri, 21 Nov 2003 13:01:43 EST Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:2827 Date: 2003-11-21T13:02:19-05:00 List-Id: Lutz Donnerhacke wrote: > * Warren W. Gay VE3WWG wrote: > >>Lutz Donnerhacke wrote: >> >>>* Warren Gay wrote: >>> >>>>What thinbind would be required to do, is to preprocess the header >>>>file somewhat differently than the C's preprocessor. Instead of >>> >>>This destroys most of the original C API in a unusable way. >> >>Rubbish. > > I beg to differ. You have to write down an example C source using the > API for the requested thinbinding. Then you preprocess this source code and > now you can parse the result in order to find out what really happend. > > Example: Thinbinding to getc(3). > #include > return getc(stdin); Well, first of all, you're focusing on the program that is _using_ getc, that was defined in stdio.h. I am only interested in processing the stdio.h file (not the client code). So within stdio.h (or nested include), there is a #define for getc, if it is a macro. That is what thinbind will be inspecting closely. > results in > extern struct _IO_FILE *stdin; > return _IO_getc (stdin); > where > struct _IO_FILE { > int _flags; > char* _IO_read_ptr; ... > char _unused2[15 * sizeof (int) - 2 * sizeof (void *)]; > }; > > struct _IO_marker { > struct _IO_marker *_next; > struct _IO_FILE *_sbuf; > int _pos; > }; > > typedef long int __off_t; > typedef long long int __off64_t; > typedef void _IO_lock_t; > > You will notice, that the original API vanished by preprocessing. Which is to be expected: all macros disappear by preprocessing. Thin bind would have to be CPP syntax aware, and C aware at various stages (in some stages, it will be wearing two hats). > introduces a huge structure and a different name. What do you expect as the > generated Ada-API? I agree that there will still be some situations that will be too difficult to solve (at least in the early stages of such a tool at least). But this is where the hints file comes in: stdio.h.hints: -------------- wrapper: getc or #ifdef FreeBSD_HOST wrapper: getc -- Create C wrapper routine #else function returns int: getc -- Use native function call ... may be all that is necessary to get thinbind to compile a little C wrapper routine, that Ada can easily call, and that the C wrapper can invoke the real C macro. This is not ideal from a performance perspective, but it works. >>The whole purpose of preprocessing it in thinbind is to compile >>a package for Ada use. It need _NOT_ be the same. You only >>need to arrive at the correct internal answers. There are >>many ways to skin a cat (pardon the expression to cat lovers >>out there). > > You wrote about preprocessing and then searching the API. This does not work. > You have to specify the API and preprocessing it to find the real C code. You can do both at the same time. You have to manage a lot more state information this way, but it can be done. I have to end this post here, because I must attend a meeting right now. Stay tuned. ;-) -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg [Remove nospam from the email address: the worms made me do it!]