A minimal example to create and execute a LLVM IR module in Zig.
First of all, you need to install LLVM and Zig according to your system.
with Scoop
scoop install llvm zigWarning
untested
with Chocolatey
choco install llvm zigWarning
untested
apt-get install llvm zigWarning
untested
with Homebrew
brew install llvm zigTip
Tested successfully with LLVM 17.0.6 and Zig 0.11+.
git clone https://github.com/seyhajin/llvm-ir-zigAlternatively, download zip from Github repository and extract wherever you want.
Note
For simplicity, the program uses LLVM's dynamic libraries installed in your environment.
Build and run program :
zig build runOutput:
Hello, world!
sum(2, 3)=5
LLVM IR module equivalent of:
int sum(int a, int b) {
return a + b;
}
void main() {
printf("Hello, world!\nsum(2, 3)=%d\n", sum(2, 3));
}