[cfe-dev] Rewrite Objective-C to C

David Chisnall csdavec at swansea.ac.uk
Mon Nov 10 08:44:13 PST 2008


On 10 Nov 2008, at 14:41, Dado Colussi wrote:

> Hello everybody,
>
> I am new to this list, and my inexperience in compiler technology is
> likely to shine in my questions. Here we go...
>
> I am interested in trying to use clang to convert Objective-C code to
> C, and compiling the generated C code with 3rd party compiler. I have
> managed to convert and compile a very simple hello application on my
> Mac using Apple's runtime after having tweaked the generated code. I
> have failed with anything more complex than the hello in one file.

What problem are you trying to solve?  If you want to compile ObjC  
code on OS X with a different compiler, then this is possible.  If you  
want to target a different platform, then you will need to tweak the  
rewriter to support the GNU runtime (not difficult, and something  
that's on my todo list, but very low down).

If you are targeting OS X, then you must have a good reason for  
picking your other compiler instead of GCC or LLVM.  Presumably  
language support isn't the reason.  If it is performance, then you  
will have some other issues since the rewriter does not produce  
particularly good code.  As I recall, it looks up the selectors from  
strings on every message send (which is very expensive) while this is  
usually done at module load time.  If you are using GNUstep instead of  
Cocoa then you will find most headers are safe to use with #include  
instead of #import (the FSF-GCC guys tried to drop support for #import  
a few years ago, made everyone change their code, and then realised  
that it was a silly idea since Apple weren't going to drop #import in  
their branch and break everyone's code), but third-party frameworks  
may not be.  One option here is to use the clang preprocessor and then  
the rewriter on the preprocessed output and then pass this to your  
other compiler.

David



More information about the cfe-dev mailing list