[cfe-dev] Objective-C Code Generation

David Chisnall csdavec at swansea.ac.uk
Sun Feb 24 14:48:54 PST 2008


On 24 Feb 2008, at 19:31, Chris Lattner wrote:

>>>>
>>>> I imagine the easiest way of getting this working is to
>>>> transform the Objective-C AST into a pure-C AST with calls to the
>>>> relevant runtime libraries.
>>>
>>> This is the way that GCC works, but I don't think it is really the
>>> best way.  I'd much rather have the clang codegen module directly
>>> produce the LLVM IR for the constructs it needs.  I don't anticipate
>>> that this will be a problem for metadata or other objc constructs.
>>
>> I am not completely sure what would be gained by doing this.  Unlike
>> C+
>> +, every Objective-C construct maps cleanly to a C construct.
>> Objective-C objects are C structures, Objective-C message sends are C
>> function calls (and methods are just C functions with their pointers
>> added to the class structure), and so on.
>
> And all of them map onto LLVM IR :)

Yes, I see.  In a lot of cases, this will be equivalently easy and  
probably cleaner.  After poking the code a bit I can see one initial  
stumbling block.  Generating code for an Objective-C method involves  
two steps:

1) Emitting the function that implements the method.
2) Set up the class structure to point to it (modify the structure  
directly with the GNU runtime, via functions on the Étoilé and Apple  
runtimes).

The second step is best done via some custom LLVM IR code for each  
runtime.  The first step ought to be able to reuse the code in  
CodeGenFunction::GenerateCode.  Looking at the ObjCMethodDecl class,  
it seems that this implements most of the methods used by the code  
generator, but since they do not have a common superclass specifying  
these functions the code can not easily be used.  Can anyone suggest a  
good way of factoring this out so it can be used in both places?  I  
notice a few TODO and FIXME comments there, so I am hesitant about  
just copying and pasting code that is going to be changed later.

David



More information about the cfe-dev mailing list