| ... | @@ -117,6 +117,8 @@ fn genFn(file: *C, decl: *Decl) !void { | ... | @@ -117,6 +117,8 @@ fn genFn(file: *C, decl: *Decl) !void { |
| 117 | .dbg_stmt => try genDbgStmt(file, inst.castTag(.dbg_stmt).?, decl), | 117 | .dbg_stmt => try genDbgStmt(file, inst.castTag(.dbg_stmt).?, decl), |
| 118 | .breakpoint => try genBreak(file, inst.castTag(.breakpoint).?, decl), | 118 | .breakpoint => try genBreak(file, inst.castTag(.breakpoint).?, decl), |
| 119 | .unreach => try genUnreach(file, inst.castTag(.unreach).?, decl), | 119 | .unreach => try genUnreach(file, inst.castTag(.unreach).?, decl), |
| | 120 | // This will be handled correctly later? |
| | 121 | .intcast => {}, |
| 120 | else => |e| return file.fail(decl.src(), "TODO implement C codegen for {}", .{e}), | 122 | else => |e| return file.fail(decl.src(), "TODO implement C codegen for {}", .{e}), |
| 121 | } | 123 | } |
| 122 | } | 124 | } |
| ... | @@ -129,6 +131,20 @@ fn genRet(file: *C, inst: *Inst.UnOp, decl: *Decl, expected_return_type: Type) ! | ... | @@ -129,6 +131,20 @@ fn genRet(file: *C, inst: *Inst.UnOp, decl: *Decl, expected_return_type: Type) ! |
| 129 | return file.fail(decl.src(), "TODO return {}", .{expected_return_type}); | 131 | return file.fail(decl.src(), "TODO return {}", .{expected_return_type}); |
| 130 | } | 132 | } |
| 131 | | 133 | |
| | 134 | fn genIntCast(file: *C, inst: *Inst.UnOp, decl: *Decl, argdex: *usize) !void { |
| | 135 | const op = inst.operand; |
| | 136 | const writer = file.main.writer(); |
| | 137 | try writer.writeByte('('); |
| | 138 | try renderType(file, writer, inst.base.ty, decl.src()); |
| | 139 | try writer.writeByte(')'); |
| | 140 | if (op.castTag(.arg)) |_| { |
| | 141 | try writer.print("arg{}", .{argdex.*}); |
| | 142 | argdex.* += 1; |
| | 143 | } else { |
| | 144 | return file.fail(decl.src(), "TODO intcast {} to {}", .{ op, inst.base.ty }); |
| | 145 | } |
| | 146 | } |
| | 147 | |
| 132 | fn genCall(file: *C, inst: *Inst.Call, decl: *Decl) !void { | 148 | fn genCall(file: *C, inst: *Inst.Call, decl: *Decl) !void { |
| 133 | const writer = file.main.writer(); | 149 | const writer = file.main.writer(); |
| 134 | const header = file.header.writer(); | 150 | const header = file.header.writer(); |
| ... | @@ -196,6 +212,8 @@ fn genAsm(file: *C, as: *Inst.Assembly, decl: *Decl, argdex: *usize) !void { | ... | @@ -196,6 +212,8 @@ fn genAsm(file: *C, as: *Inst.Assembly, decl: *Decl, argdex: *usize) !void { |
| 196 | } else if (arg.castTag(.arg)) |inst| { | 212 | } else if (arg.castTag(.arg)) |inst| { |
| 197 | try writer.print("arg{}", .{argdex.*}); | 213 | try writer.print("arg{}", .{argdex.*}); |
| 198 | argdex.* += 1; | 214 | argdex.* += 1; |
| | 215 | } else if (arg.castTag(.intcast)) |inst| { |
| | 216 | try genIntCast(file, inst, decl, argdex); |
| 199 | } else { | 217 | } else { |
| 200 | return file.fail(decl.src(), "TODO non-constant inline asm args ({})", .{arg.tag}); | 218 | return file.fail(decl.src(), "TODO non-constant inline asm args ({})", .{arg.tag}); |
| 201 | } | 219 | } |
| ... | @@ -220,14 +238,7 @@ fn genAsm(file: *C, as: *Inst.Assembly, decl: *Decl, argdex: *usize) !void { | ... | @@ -220,14 +238,7 @@ fn genAsm(file: *C, as: *Inst.Assembly, decl: *Decl, argdex: *usize) !void { |
| 220 | if (index > 0) { | 238 | if (index > 0) { |
| 221 | try writer.writeAll(", "); | 239 | try writer.writeAll(", "); |
| 222 | } | 240 | } |
| 223 | try writer.writeAll("\"\"("); | 241 | try writer.print("\"\"({}_constant)", .{reg}); |
| 224 | if (arg.tag == .constant or arg.tag == .arg) { | | |
| 225 | try writer.print("{}_constant", .{reg}); | | |
| 226 | } else { | | |
| 227 | // This is blocked by the earlier test | | |
| 228 | unreachable; | | |
| 229 | } | | |
| 230 | try writer.writeByte(')'); | | |
| 231 | } else { | 242 | } else { |
| 232 | // This is blocked by the earlier test | 243 | // This is blocked by the earlier test |
| 233 | unreachable; | 244 | unreachable; |