From ebf4af6537683212c4a74d41a8fc1c5744c9bcb7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 7 Dec 2019 20:28:55 -0300 Subject: [PATCH] fixes for latest zig --- examples/hello.ry | 2 +- src/codegen/llvm.zig | 37 ++++++++++++++++++------------------- src/main.zig | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/examples/hello.ry b/examples/hello.ry index 62bfab3..40e69a4 100644 --- a/examples/hello.ry +++ b/examples/hello.ry @@ -30,5 +30,5 @@ fn add(a: i32, b: i32) i32 { } fn main() i32 { - return 1; + return 123; } diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 6da6f82..6071da0 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -4,8 +4,7 @@ const llvm = @import("../llvm.zig"); const comp = @import("../comp_ctx.zig"); const CompileError = @import("../codegen.zig").CompileError; -fn sliceify(non_slice: ?[*]const u8) []const u8 { - if (non_slice == null) return ""; +fn sliceify(non_slice: ?[*:0]const u8) []const u8 { return non_slice.?[0..std.mem.len(u8, non_slice.?)]; } @@ -126,8 +125,8 @@ pub const Codegen = struct { var right = try self.emitExpr(builder, unary.right); return switch (unary.op) { - .Negate => llvm.LLVMBuildNeg(builder, right, c"neg_tmp"), - .Not => llvm.LLVMBuildNot(builder, right, c"neg_tmp"), + .Negate => llvm.LLVMBuildNeg(builder, right, "neg_tmp"), + .Not => llvm.LLVMBuildNot(builder, right, "neg_tmp"), }; }, @@ -136,13 +135,13 @@ pub const Codegen = struct { var right = try self.emitExpr(builder, binary.right); return switch (binary.op) { - .Add => llvm.LLVMBuildAdd(builder, left, right, c"addtmp"), - .Sub => llvm.LLVMBuildSub(builder, left, right, c"subtmp"), - .Mul => llvm.LLVMBuildMul(builder, left, right, c"multmp"), + .Add => llvm.LLVMBuildAdd(builder, left, right, "addtmp"), + .Sub => llvm.LLVMBuildSub(builder, left, right, "subtmp"), + .Mul => llvm.LLVMBuildMul(builder, left, right, "multmp"), - //.Div => llvm.LLVMBuildDiv(builder, left, right, c"divtmp"), - .And => llvm.LLVMBuildAnd(builder, left, right, c"andtmp"), - .Or => llvm.LLVMBuildOr(builder, left, right, c"ortmp"), + //.Div => llvm.LLVMBuildDiv(builder, left, right, "divtmp"), + .And => llvm.LLVMBuildAnd(builder, left, right, "andtmp"), + .Or => llvm.LLVMBuildOr(builder, left, right, "ortmp"), else => { std.debug.warn("Unexpected binary operator: '{}'\n", binary.op); @@ -199,7 +198,7 @@ pub const Codegen = struct { llvm_func.?.value, args_slice.ptr, @intCast(c_uint, args_slice.len), - c"call", + "call", ); }, @@ -276,14 +275,14 @@ pub const Codegen = struct { .If => |ifstmt| { var cond = try self.emitExpr(builder, ifstmt.condition); var zero = mkLLVMBool(false); - var icmp = llvm.LLVMBuildICmp(builder, llvm.LLVMIntPredicate.LLVMIntNE, cond, zero, c"ifcond"); + var icmp = llvm.LLVMBuildICmp(builder, llvm.LLVMIntPredicate.LLVMIntNE, cond, zero, "ifcond"); var insert = llvm.LLVMGetInsertBlock(builder); var function = llvm.LLVMGetBasicBlockParent(insert); - var then_bb = llvm.LLVMAppendBasicBlock(function, c"then"); - var else_bb = llvm.LLVMAppendBasicBlock(function, c"else"); - var merge_bb = llvm.LLVMAppendBasicBlock(function, c"ifcont"); + var then_bb = llvm.LLVMAppendBasicBlock(function, "then"); + var else_bb = llvm.LLVMAppendBasicBlock(function, "else"); + var merge_bb = llvm.LLVMAppendBasicBlock(function, "ifcont"); var condbr = llvm.LLVMBuildCondBr(builder, icmp, then_bb, else_bb); @@ -514,7 +513,7 @@ pub const Codegen = struct { std.debug.warn("cgen: start gen\n"); _ = llvm.LLVMInitializeNativeTarget(); - var mod = llvm.LLVMModuleCreateWithName(c"awoo").?; + var mod = llvm.LLVMModuleCreateWithName("awoo").?; defer llvm.LLVMDisposeModule(mod); var root_slice = root.Root.toSlice(); @@ -522,15 +521,15 @@ pub const Codegen = struct { try self.genNode(mod, &root_slice[idx]); } - var err: ?[*]u8 = null; + var err: ?[*:0]u8 = null; defer llvm.LLVMDisposeMessage(err); - if (llvm.LLVMPrintModuleToFile(mod, c"output.ll", &err) != 0) { + if (llvm.LLVMPrintModuleToFile(mod, "output.ll", &err) != 0) { std.debug.warn("error printing module to file: {}\n", sliceify(err)); return CompileError.BackendError; } - //if (llvm.LLVMWriteBitcodeToFile(mod, c"awoo.bc") != 0) { + //if (llvm.LLVMWriteBitcodeToFile(mod, "awoo.bc") != 0) { // std.debug.warn("error writing bitcode to file: {}\n", sliceify(err)); // return CompileError.BackendError; //} diff --git a/src/main.zig b/src/main.zig index 4dc9918..5e91ab8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -60,7 +60,7 @@ pub fn run(allocator: *std.mem.Allocator, slice: []const u8) !Result { try cgen.gen(root); var child = try std.ChildProcess.init( - [_][]const u8{ "gcc", "src/entry.c", "outpath.o", "-o", "a.out" }, + &[_][]const u8{ "gcc", "src/entry.c", "outpath.o", "-o", "a.out" }, allocator, ); try child.spawn();