Clang & Objective-C questions

Hello,

I am learning LLVM and would like to add JIT support to the F-Script language. F-Script is a Smalltalk like scripting language that lives above the Objective-C runtime. In F-Script everything is represented as an Objective-C object.

Right now, when a block is parsed, a AST representation is built and then interpreted. This results in selectors calls (by large), but also classes and methods definitions.

My question are:

  1. Do you think it would make sense to use the clang codebase (specifically Objective-C CodeGen / CGObjCRuntime) in order to generate the code that will replace F-Script’s interpretation?

(I have asked llvmdev if it was possible to use the objc code generation module in clang to emit the code, and they sent me to cfe-dev.)

  1. If the previous answer is yes, can you point me to some code where CGObjCRuntime is used? Or advices on how to use it?

  2. If this is not a good idea, do you have a suggestion for an alternative approach?

Thanks!

Best Regards,
Camille

Hi Camille,

The CGObjCRuntime class was originally designed to be reused, but has since grown a lot of dependencies on other bits of clang, so reusing it requires keeping a lot of the other clang code, including the type system and bits of the AST.

The code generation in Étoilé's LanguageKit is based on the first version of CGObjCRuntime that I wrote, and doesn't have these dependencies (the interface is slightly more convoluted because of this, but it generates the same code - I have been testing most changes there before submitting them to clang). Unfortunately, it also doesn't have an implementation for the Apple runtimes. You may find some inspiration here, however, as it is currently used to compile a Smalltalk dialect that is ABI-compatible with GNU Objective-C, as well as a dialect of JavaScript.

David

Camille Troillard wrote:

Hello,

I am learning LLVM and would like to add JIT support to the F-Script
language. F-Script is a Smalltalk like scripting language that lives
above the Objective-C runtime. In F-Script everything is represented
as an Objective-C object.

Right now, when a block is parsed, a AST representation is built and
then interpreted. This results in selectors calls (by large), but
also classes and methods definitions.

My question are:

1. Do you think it would make sense to use the clang codebase
(specifically Objective-C CodeGen / CGObjCRuntime) in order to
generate the code that will replace F-Script's interpretation?

Caveat: I know nothing about F-Script and very little about Objective-C.

I don't think the ObjC CodeGen in its current state is very usable for
this purpose. It is designed to be supplied with a Clang AST and
generate code. Since the AST is very much bound to the C family of
languages, I don't see a good way to translate the AST of any other
language to it.

3. If this is not a good idea, do you have a suggestion for an
alternative approach?

However, you may be able to extract the pure code generating part of the
CodeGen facility and pack it behind a more generic interface. If that's
possible, you could then use this to generate your calls.

Sebastian

Hello,

I am learning LLVM and would like to add JIT support to the F-Script language. F-Script is a Smalltalk like scripting language that lives above the Objective-C runtime. In F-Script everything is represented as an Objective-C object.

Right now, when a block is parsed, a AST representation is built and then interpreted. This results in selectors calls (by large), but also classes and methods definitions.

My question are:

  1. Do you think it would make sense to use the clang codebase (specifically Objective-C CodeGen / CGObjCRuntime) in order to generate the code that will replace F-Script’s interpretation?

(I have asked llvmdev if it was possible to use the objc code generation module in clang to emit the code, and they sent me to cfe-dev.)

  1. If the previous answer is yes, can you point me to some code where CGObjCRuntime is used? Or advices on how to use it?

  2. If this is not a good idea, do you have a suggestion for an alternative approach?

If you can write an F-Script to Objective-c translator, then you should be able to generate the objective-c like ASTs expected by the
CGObjCRuntime. If you need to generate specific meta-data, then look at CGObjCMac.cpp for guidance.

  • Fariborz

Thanks to everybody for your suggestions.