Targeting Clang?

I am considering writing a LLVM back end for Scala. A major goal of mine is interoperability with C (and perhaps C++)
Would it make sense to try to leverage parts of Clang for this purpose? Is there an intermediate language for c/c++/objc that languages are compiled into before being compiled to LLVM? That would be optimal. If that’s not possible, are there parts of clang that are recommended for use with other languages?

Failing any of that, does anyone have any recommendations for setting out to build an LLVM back end for a language with the goal of ABI compatibility in mind?

Thanks,

Rick Richardson

Rick R wrote:

I am considering writing a LLVM back end for Scala. A major goal of mine is interoperability with C (and perhaps C++)
Would it make sense to try to leverage parts of Clang for this purpose? Is there an intermediate language for c/c++/objc that languages are compiled into before being compiled to LLVM? That would be optimal. If that's not possible, are there parts of clang that are recommended for use with other languages?

Failing any of that, does anyone have any recommendations for setting out to build an LLVM back end for a language with the goal of ABI compatibility in mind?

LLVM doesn't make any formal promises about this, but it will generally ensure ABI compatibility for function types featuring only pointer, integer, and floating-point types.

If you really needed to use clang's ABI support (and you might), there's an ABIInfo interface, but it's not really factored for ease of external use. Ideally we would have an interface taking a clang::FunctionType, a list of arguments, and an IRBuilder (possibly +1 for making allocas), but that's not how it's written.

John.

Hello Rick,

I am considering writing a LLVM back end for Scala. A major goal of mine is interoperability with C (and perhaps C++)
Would it make sense to try to leverage parts of Clang for this purpose?
Is there an intermediate language for c/c++/objc that languages are compiled into before being compiled to LLVM?

There is no intermediate language in Clang. Clang builds its own abstract syntax trees, which are *very* specific to C/C++/Objective-C, and lowers them directly to LLVM IR.

That would be optimal. If that's not possible, are there parts of clang that are recommended for use with other languages?

Parts of Clang's "Basic" library, such as the source manager, file manager, and diagnostics engine, would be useful for building another front end. Everything else is very specific to the C family of languages.

  - Doug

I am considering writing a LLVM back end for Scala. A major goal of mine is
interoperability with C (and perhaps C++)
Would it make sense to try to leverage parts of Clang for this purpose?

I think that recycling clang would not give you C++ interoperability
for free. Also, it could be more hassle to adapt the specific C/C++
semantics than it would be creating a new compiler from scratch.

Failing any of that, does anyone have any recommendations for setting out to
build an LLVM back end for a language with the goal of ABI compatibility in
mind?

Scala is very different from C++. Building the IR functions the same
way might force you loose Scala semantics. I may be wrong, but if you
manage, binary compatibility should be taken care by the back-end
target code generator.

--renato

Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm