diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-31 02:42:48 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-12-31 02:42:48 -0700 |
| commit | 7deb1f4f6c038eaef815d5d179633683a9574ff0 (patch) | |
| tree | fcfabab97a321af087a1bf03a54db3d4108a8a5a /src/codegen | |
| parent | a46d24af1cf2885991c67bf39a2e639891c16121 (diff) | |
| download | zig-7deb1f4f6c038eaef815d5d179633683a9574ff0.tar.gz zig-7deb1f4f6c038eaef815d5d179633683a9574ff0.zip | |
stage2: type inference for local var
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/c.zig | 13 |
1 files changed, 11 insertions, 2 deletions
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); |
