| ... | ... | @@ -117,6 +117,8 @@ fn genFn(file: *C, decl: *Decl) !void { |
| 117 | 117 | .dbg_stmt => try genDbgStmt(file, inst.castTag(.dbg_stmt).?, decl), |
| 118 | 118 | .breakpoint => try genBreak(file, inst.castTag(.breakpoint).?, decl), |
| 119 | 119 | .unreach => try genUnreach(file, inst.castTag(.unreach).?, decl), |
| 120 | // This will be handled correctly later? |
| 121 | .intcast => {}, |
| 120 | 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 | 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 | 148 | fn genCall(file: *C, inst: *Inst.Call, decl: *Decl) !void { |
| 133 | 149 | const writer = file.main.writer(); |
| 134 | 150 | const header = file.header.writer(); |
| ... | ... | @@ -196,6 +212,8 @@ fn genAsm(file: *C, as: *Inst.Assembly, decl: *Decl, argdex: *usize) !void { |
| 196 | 212 | } else if (arg.castTag(.arg)) |inst| { |
| 197 | 213 | try writer.print("arg{}", .{argdex.*}); |
| 198 | 214 | argdex.* += 1; |
| 215 | } else if (arg.castTag(.intcast)) |inst| { |
| 216 | try genIntCast(file, inst, decl, argdex); |
| 199 | 217 | } else { |
| 200 | 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 | 238 | if (index > 0) { |
| 221 | 239 | try writer.writeAll(", "); |
| 222 | 240 | } |
| 223 | | try writer.writeAll("\"\"("); |
| 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(')'); |
| 241 | try writer.print("\"\"({}_constant)", .{reg}); |
| 231 | 242 | } else { |
| 232 | 243 | // This is blocked by the earlier test |
| 233 | 244 | unreachable; |