Example of C Compiler using JIT Engine of Clang.
This is a sample of how to use Clang JIT Engine. I did a lot of searching how to do it, combining information, so many try & error, and I finally got it. I hope this information will help a lot of people.
Note: This information only for Windows.
See clang/README.md for details. I tried this with the version 8.0.0 of Clang.
- If you want to use a host prgrams funcion, please see predef.cpp.
- jit.h is available for C and C++. It defines
ClangJitCompiler
class wrapping C functions.
Try below after preparing Clang library modules under clang
folder.
$ make.cmd
Now you will find krycc.exe
.
Look at the folder carefully, and you will also find fib.c
.
Just do it as below.
$ krycc.exe fib.c
9227465
That's all.
Clang is very amazing compiler frontend and backend and it has a very high level optimizer.
But it is too much big component...
For example, my krycc.exe
is over 30MB with only one executable file.
If you want a compact C Compiler for your light use with direct execution on JIT or VM, look at kcs.
I believe it will help you.