diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/astgen.zig | 6 | ||||
| -rw-r--r-- | src/codegen/c.zig | 13 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/astgen.zig b/src/astgen.zig index 2ce21dbab4..1142907faf 100644 --- a/src/astgen.zig +++ b/src/astgen.zig @@ -625,9 +625,9 @@ fn varDecl( const alloc = try addZIRUnOp(mod, scope, name_src, .alloc_mut, type_inst); break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } }; } else a: { - const alloc = try addZIRNoOp(mod, scope, name_src, .alloc_inferred_mut); - resolve_inferred_alloc = alloc; - break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc.castTag(.alloc_inferred_mut).? } }; + const alloc = try addZIRNoOpT(mod, scope, name_src, .alloc_inferred); + resolve_inferred_alloc = &alloc.base; + break :a .{ .alloc = &alloc.base, .result_loc = .{ .inferred_ptr = alloc } }; }; const init_inst = try expr(mod, scope, var_data.result_loc, init_node); if (resolve_inferred_alloc) |inst| { diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 6d9563b991..c6c29942d9 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -275,7 +275,6 @@ pub fn generate(file: *C, module: *Module, decl: *Decl) !void { try writer.writeAll(" {"); const func: *Module.Fn = func_payload.data; - //func.dump(module.*); const instructions = func.analysis.success.instructions; if (instructions.len > 0) { try writer.writeAll("\n"); @@ -297,6 +296,7 @@ pub fn generate(file: *C, module: *Module, decl: *Decl) !void { .cmp_neq => try genBinOp(&ctx, file, inst.castTag(.cmp_neq).?, "!="), .dbg_stmt => try genDbgStmt(&ctx, inst.castTag(.dbg_stmt).?), .intcast => try genIntCast(&ctx, file, inst.castTag(.intcast).?), + .load => try genLoad(&ctx, file, inst.castTag(.load).?), .ret => try genRet(&ctx, file, inst.castTag(.ret).?), .retvoid => try genRetVoid(file), .store => try genStore(&ctx, file, inst.castTag(.store).?), @@ -431,6 +431,16 @@ fn genRetVoid(file: *C) !?[]u8 { return null; } +fn genLoad(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { + const operand = try ctx.resolveInst(inst.operand); + const writer = file.main.writer(); + try indent(file); + const local_name = try ctx.name(); + try renderTypeAndName(ctx, writer, inst.base.ty, local_name, .Const); + try writer.print(" = *{s};\n", .{operand}); + return local_name; +} + fn genRet(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { try indent(file); const writer = file.main.writer(); @@ -442,7 +452,6 @@ fn genIntCast(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { if (inst.base.isUnused()) return null; try indent(file); - const op = inst.operand; const writer = file.main.writer(); const name = try ctx.name(); const from = try ctx.resolveInst(inst.operand); |
