| ... | ... | @@ -791,7 +791,8 @@ pub const DeclGen = struct { |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | if (ty.optionalReprIsPayload()) { |
| 794 | | return dg.renderValue(writer, payload_ty, val, location); |
| 794 | const payload_val = if (val.castTag(.opt_payload)) |pl| pl.data else val; |
| 795 | return dg.renderValue(writer, payload_ty, payload_val, location); |
| 795 | 796 | } |
| 796 | 797 | |
| 797 | 798 | try writer.writeByte('('); |
| ... | ... | @@ -1457,7 +1458,7 @@ pub const DeclGen = struct { |
| 1457 | 1458 | .c_ulong => try w.writeAll("unsigned long"), |
| 1458 | 1459 | .c_longlong => try w.writeAll("long long"), |
| 1459 | 1460 | .c_ulonglong => try w.writeAll("unsigned long long"), |
| 1460 | | .int_signed, .int_unsigned => { |
| 1461 | .u29, .int_signed, .int_unsigned => { |
| 1461 | 1462 | const info = t.intInfo(target); |
| 1462 | 1463 | const sign_prefix = switch (info.signedness) { |
| 1463 | 1464 | .signed => "", |
| ... | ... | @@ -2242,11 +2243,11 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO |
| 2242 | 2243 | .field_parent_ptr => try airFieldParentPtr(f, inst), |
| 2243 | 2244 | |
| 2244 | 2245 | .struct_field_val => try airStructFieldVal(f, inst), |
| 2245 | | .slice_ptr => try airSliceField(f, inst, ".ptr;\n"), |
| 2246 | | .slice_len => try airSliceField(f, inst, ".len;\n"), |
| 2246 | .slice_ptr => try airSliceField(f, inst, " = ", ".ptr;\n"), |
| 2247 | .slice_len => try airSliceField(f, inst, " = ", ".len;\n"), |
| 2247 | 2248 | |
| 2248 | | .ptr_slice_len_ptr => try airPtrSliceFieldPtr(f, inst, ".len;\n"), |
| 2249 | | .ptr_slice_ptr_ptr => try airPtrSliceFieldPtr(f, inst, ".ptr;\n"), |
| 2249 | .ptr_slice_len_ptr => try airSliceField(f, inst, " = &", ".len;\n"), |
| 2250 | .ptr_slice_ptr_ptr => try airSliceField(f, inst, " = &", ".ptr;\n"), |
| 2250 | 2251 | |
| 2251 | 2252 | .ptr_elem_val => try airPtrElemVal(f, inst), |
| 2252 | 2253 | .ptr_elem_ptr => try airPtrElemPtr(f, inst), |
| ... | ... | @@ -2306,7 +2307,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO |
| 2306 | 2307 | try writer.writeByte('}'); |
| 2307 | 2308 | } |
| 2308 | 2309 | |
| 2309 | | fn airSliceField(f: *Function, inst: Air.Inst.Index, suffix: []const u8) !CValue { |
| 2310 | fn airSliceField(f: *Function, inst: Air.Inst.Index, prefix: []const u8, suffix: []const u8) !CValue { |
| 2310 | 2311 | if (f.liveness.isUnused(inst)) return CValue.none; |
| 2311 | 2312 | |
| 2312 | 2313 | const inst_ty = f.air.typeOfIndex(inst); |
| ... | ... | @@ -2314,27 +2315,12 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, suffix: []const u8) !CValue |
| 2314 | 2315 | const operand = try f.resolveInst(ty_op.operand); |
| 2315 | 2316 | const writer = f.object.writer(); |
| 2316 | 2317 | const local = try f.allocLocal(inst_ty, .Const); |
| 2317 | | try writer.writeAll(" = "); |
| 2318 | try writer.writeAll(prefix); |
| 2318 | 2319 | try f.writeCValue(writer, operand); |
| 2319 | 2320 | try writer.writeAll(suffix); |
| 2320 | 2321 | return local; |
| 2321 | 2322 | } |
| 2322 | 2323 | |
| 2323 | | fn airPtrSliceFieldPtr(f: *Function, inst: Air.Inst.Index, suffix: []const u8) !CValue { |
| 2324 | | if (f.liveness.isUnused(inst)) |
| 2325 | | return CValue.none; |
| 2326 | | |
| 2327 | | const ty_op = f.air.instructions.items(.data)[inst].ty_op; |
| 2328 | | const operand = try f.resolveInst(ty_op.operand); |
| 2329 | | const writer = f.object.writer(); |
| 2330 | | |
| 2331 | | _ = writer; |
| 2332 | | _ = operand; |
| 2333 | | _ = suffix; |
| 2334 | | |
| 2335 | | return f.fail("TODO: C backend: airPtrSliceFieldPtr", .{}); |
| 2336 | | } |
| 2337 | | |
| 2338 | 2324 | fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 2339 | 2325 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; |
| 2340 | 2326 | const ptr_ty = f.air.typeOf(bin_op.lhs); |
| ... | ... | @@ -3581,7 +3567,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3581 | 3567 | // for the string, we still use the next u32 for the null terminator. |
| 3582 | 3568 | extra_i += (constraint.len + name.len + (2 + 3)) / 4; |
| 3583 | 3569 | |
| 3584 | | try f.writeCValueDeref(writer, if (output == .none) .{ .local_ref = local.local } else try f.resolveInst(output)); |
| 3570 | try f.writeCValueDeref(writer, if (output == .none) CValue{ |
| 3571 | .local_ref = local.local, |
| 3572 | } else try f.resolveInst(output)); |
| 3585 | 3573 | try writer.writeAll(" = "); |
| 3586 | 3574 | try f.writeCValue(writer, .{ .identifier = name }); |
| 3587 | 3575 | try writer.writeAll(";\n"); |