| ... | @@ -275,7 +275,6 @@ pub fn generate(file: *C, module: *Module, decl: *Decl) !void { | ... | @@ -275,7 +275,6 @@ pub fn generate(file: *C, module: *Module, decl: *Decl) !void { |
| 275 | try writer.writeAll(" {"); | 275 | try writer.writeAll(" {"); |
| 276 | | 276 | |
| 277 | const func: *Module.Fn = func_payload.data; | 277 | const func: *Module.Fn = func_payload.data; |
| 278 | //func.dump(module.*); | | |
| 279 | const instructions = func.analysis.success.instructions; | 278 | const instructions = func.analysis.success.instructions; |
| 280 | if (instructions.len > 0) { | 279 | if (instructions.len > 0) { |
| 281 | try writer.writeAll("\n"); | 280 | try writer.writeAll("\n"); |
| ... | @@ -297,6 +296,7 @@ pub fn generate(file: *C, module: *Module, decl: *Decl) !void { | ... | @@ -297,6 +296,7 @@ pub fn generate(file: *C, module: *Module, decl: *Decl) !void { |
| 297 | .cmp_neq => try genBinOp(&ctx, file, inst.castTag(.cmp_neq).?, "!="), | 296 | .cmp_neq => try genBinOp(&ctx, file, inst.castTag(.cmp_neq).?, "!="), |
| 298 | .dbg_stmt => try genDbgStmt(&ctx, inst.castTag(.dbg_stmt).?), | 297 | .dbg_stmt => try genDbgStmt(&ctx, inst.castTag(.dbg_stmt).?), |
| 299 | .intcast => try genIntCast(&ctx, file, inst.castTag(.intcast).?), | 298 | .intcast => try genIntCast(&ctx, file, inst.castTag(.intcast).?), |
| | 299 | .load => try genLoad(&ctx, file, inst.castTag(.load).?), |
| 300 | .ret => try genRet(&ctx, file, inst.castTag(.ret).?), | 300 | .ret => try genRet(&ctx, file, inst.castTag(.ret).?), |
| 301 | .retvoid => try genRetVoid(file), | 301 | .retvoid => try genRetVoid(file), |
| 302 | .store => try genStore(&ctx, file, inst.castTag(.store).?), | 302 | .store => try genStore(&ctx, file, inst.castTag(.store).?), |
| ... | @@ -431,6 +431,16 @@ fn genRetVoid(file: *C) !?[]u8 { | ... | @@ -431,6 +431,16 @@ fn genRetVoid(file: *C) !?[]u8 { |
| 431 | return null; | 431 | return null; |
| 432 | } | 432 | } |
| 433 | | 433 | |
| | 434 | fn genLoad(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { |
| | 435 | const operand = try ctx.resolveInst(inst.operand); |
| | 436 | const writer = file.main.writer(); |
| | 437 | try indent(file); |
| | 438 | const local_name = try ctx.name(); |
| | 439 | try renderTypeAndName(ctx, writer, inst.base.ty, local_name, .Const); |
| | 440 | try writer.print(" = *{s};\n", .{operand}); |
| | 441 | return local_name; |
| | 442 | } |
| | 443 | |
| 434 | fn genRet(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { | 444 | fn genRet(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { |
| 435 | try indent(file); | 445 | try indent(file); |
| 436 | const writer = file.main.writer(); | 446 | const writer = file.main.writer(); |
| ... | @@ -442,7 +452,6 @@ fn genIntCast(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { | ... | @@ -442,7 +452,6 @@ fn genIntCast(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { |
| 442 | if (inst.base.isUnused()) | 452 | if (inst.base.isUnused()) |
| 443 | return null; | 453 | return null; |
| 444 | try indent(file); | 454 | try indent(file); |
| 445 | const op = inst.operand; | | |
| 446 | const writer = file.main.writer(); | 455 | const writer = file.main.writer(); |
| 447 | const name = try ctx.name(); | 456 | const name = try ctx.name(); |
| 448 | const from = try ctx.resolveInst(inst.operand); | 457 | const from = try ctx.resolveInst(inst.operand); |