Can LLVM be used with the C language?

Asked

Viewed 56 times

5

I’m studying compilers and I’m using the C language and learning about LLVM but all examples are in C++ language. The question is whether I can use the LLVM with the C language and how can I start a project? It would just clone the Github repository and use its codes?

1 answer

5


LLVM is a backend compilation, i.e., it takes an intermediate language that is specified along its entire ecosystem and creates a target code for some platform, which can be code native to some processor or other, for example Webassembly or even another language like Javascript, eventually doing optimizations. It generates a binary or other necessary format. It is a kit that helps a lot who will create a compiler to devote to frontend which is important for a language.

Linguagens entram no LLVM e sai códigos nativos

The LLVM is used by Clang, a compiler of C, C++ and other languages derived from C. They are sister projects. If you use Clang you are using the LLVM in any way.

It only makes sense to use the LLVM directly if you are making your own compiler, which seems to be the case.

LLVM was written in C++ so all of its API is for this language. But it is common for C++ codes to be called in C, with more or less effort (in some cases it needs an extra layer).

Luckily the LLVM already offers a API ready to be called by C.

There’s a independent tutorial showing the first steps in C. It seems to be a little outdated. It’s never just clone the repository, but it will be necessary to start using.

  • OK thank you very much! Helped me a lot!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.