aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_bindings.zig
AgeCommit message (Collapse)Author
2021-01-06stage2: rename and move files related to LLVM backendTimon Kruiper
2021-01-06stage2: make use of `llvm.Context` in LLVM backendTimon Kruiper
This for example allows for multiple LLVM instances to run in parallel. Also rename some functions in llvm_bindings.zig. Fixes #7688
2021-01-06stage2: hoist alloca instructions to top of function in LLVM backendTimon Kruiper
This way the generated code only has to setup the stack size at the beginning of a function and this improves codegen. Fixes #7689 ``` fn foo() void {} export fn hello(z: i8) void { var x: i16 = undefined; foo(); var y: i32 = 1; y += z; } ``` llvm-ir: ``` define void @hello(i8 %0) { Entry: %1 = alloca i8, align 1 %2 = alloca i16, align 2 %3 = alloca i32, align 4 store i8 %0, i8* %1, align 1 %4 = load i8, i8* %1, align 1 store i16 undef, i16* %2, align 2 call void @foo() store i32 1, i32* %3, align 4 %5 = load i32, i32* %3, align 4 %6 = sext i8 %4 to i32 %7 = add nsw i32 %5, %6 store i32 %7, i32* %3, align 4 ret void } ```
2021-01-06stage2: rename `*const llvm.ValueRef` to `*const llvm.Value` in LLVM backendTimon Kruiper
The same has been done for all the other LLVM types.
2021-01-06stage2: add initial impl for generating global decls in LLVM backendTimon Kruiper
Also adds support for extern functions, simple pointer and simple array types and values. A simple hello world now compiles: `zig build-exe example.zig -fLLVM -lc` ``` extern fn puts(s: [*:0]const u8) c_int; export fn main() c_int { _ = puts("hello world!"); return 0; } ```
2021-01-03stage2: add support for integers in LLVM backendTimon Kruiper
Also adds support for simple operators, like add and subtract. The intcast and bitcast instruction also have been implemented. Linking with libc also works, so we can now generate working executables! `zig build-exe example.zig -fLLVM -lc`: ``` fn add(a: i32, b: i32) i32 { return a + b; } export fn main() c_int { var a: i32 = -5; const x = add(a, 7); var y = add(2, 0); y -= x; return y; } ```
2021-01-03stage2: make use of proper LLVM intrinsic APIs in LLVM backendTimon Kruiper
2021-01-03stage2: implement argument passing and returning in LLVM backendTimon Kruiper
Furthermore add the Not instruction. The following now works: ``` export fn _start() noreturn { var x: bool = true; var other: bool = foo(x); exit(); } fn foo(cond: bool) bool { return !cond; } fn exit() noreturn { unreachable; } ```
2021-01-03stage2: Add code generation for Load instruction in LLVM backendTimon Kruiper
The following now works: ``` export fn _start() noreturn { var x: bool = true; var y: bool = x; exit(); } fn exit() noreturn { unreachable; } ```
2021-01-03stage2: implement register allocation in LLVM self-hosted backendTimon Kruiper
A HashMap has been added which store the LLVM values used in a function. Together with the alloc and store instructions the following now works: ``` export fn _start() noreturn { var x: bool = true; exit(); } fn exit() noreturn { unreachable; } ```
2020-12-28stage2: add initial implementation of func arguments in LLVM backendTimon Kruiper
The following works: ``` export fn _start() noreturn { assert(true); exit(); } fn assert(cond: bool) void {} fn exit() noreturn { unreachable; } ```
2020-12-28stage2: add initial impl of LLVM backend in self-hosted compilerTimon Kruiper
2020-12-28stage2: rename llvm.zig to llvm_bindings.zigTimon Kruiper
Putting functions in this file will create functions like `llvm.function`, and the compiler thinks these are llvm intrinsics.