aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig13
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);