| ... | ... | @@ -438,6 +438,10 @@ pub const Function = struct { |
| 438 | 438 | return f.object.dg.renderType(w, t); |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | fn renderCType(f: *Function, w: anytype, t: CType.Index) !void { |
| 442 | return f.object.dg.renderCType(w, t); |
| 443 | } |
| 444 | |
| 441 | 445 | fn renderIntCast(f: *Function, w: anytype, dest_ty: Type, src: CValue, v: Vectorizer, src_ty: Type, location: ValueRenderLocation) !void { |
| 442 | 446 | return f.object.dg.renderIntCast(w, dest_ty, .{ .c_value = .{ .f = f, .value = src, .v = v } }, src_ty, location); |
| 443 | 447 | } |
| ... | ... | @@ -1576,9 +1580,12 @@ pub const DeclGen = struct { |
| 1576 | 1580 | /// | `renderType` | "uint8_t *" | "uint8_t *[10]" | |
| 1577 | 1581 | /// |
| 1578 | 1582 | fn renderType(dg: *DeclGen, w: anytype, t: Type) error{ OutOfMemory, AnalysisFail }!void { |
| 1583 | try dg.renderCType(w, try dg.typeToIndex(t, .complete)); |
| 1584 | } |
| 1585 | |
| 1586 | fn renderCType(dg: *DeclGen, w: anytype, idx: CType.Index) error{ OutOfMemory, AnalysisFail }!void { |
| 1579 | 1587 | const store = &dg.ctypes.set; |
| 1580 | 1588 | const module = dg.module; |
| 1581 | | const idx = try dg.typeToIndex(t, .complete); |
| 1582 | 1589 | _ = try renderTypePrefix(dg.decl_index, store.*, module, w, idx, .suffix, .{}); |
| 1583 | 1590 | try renderTypeSuffix(dg.decl_index, store.*, module, w, idx, .suffix, .{}); |
| 1584 | 1591 | } |
| ... | ... | @@ -6543,21 +6550,37 @@ fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6543 | 6550 | |
| 6544 | 6551 | fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6545 | 6552 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; |
| 6553 | |
| 6546 | 6554 | if (f.liveness.isUnused(inst)) { |
| 6547 | 6555 | try reap(f, inst, &.{ty_op.operand}); |
| 6548 | 6556 | return .none; |
| 6549 | 6557 | } |
| 6550 | 6558 | |
| 6551 | | const inst_ty = f.air.typeOfIndex(inst); |
| 6552 | 6559 | const operand = try f.resolveInst(ty_op.operand); |
| 6553 | 6560 | try reap(f, inst, &.{ty_op.operand}); |
| 6561 | |
| 6562 | const inst_ty = f.air.typeOfIndex(inst); |
| 6563 | const inst_scalar_ty = inst_ty.scalarType(); |
| 6564 | const inst_scalar_cty = try f.typeToIndex(inst_scalar_ty, .complete); |
| 6565 | const need_memcpy = f.indexToCType(inst_scalar_cty).tag() == .array; |
| 6566 | |
| 6554 | 6567 | const writer = f.object.writer(); |
| 6555 | 6568 | const local = try f.allocLocal(inst, inst_ty); |
| 6569 | const v = try Vectorizer.start(f, inst, writer, inst_ty); |
| 6570 | if (need_memcpy) try writer.writeAll("memcpy(&"); |
| 6556 | 6571 | try f.writeCValue(writer, local, .Other); |
| 6557 | | try writer.writeAll(" = "); |
| 6572 | try v.elem(f, writer); |
| 6573 | try writer.writeAll(if (need_memcpy) ", &" else " = "); |
| 6574 | try f.writeCValue(writer, operand, .Other); |
| 6575 | if (need_memcpy) { |
| 6576 | try writer.writeAll(", sizeof("); |
| 6577 | try f.renderCType(writer, inst_scalar_cty); |
| 6578 | try writer.writeAll("))"); |
| 6579 | } |
| 6580 | try writer.writeAll(";\n"); |
| 6581 | try v.end(f, inst, writer); |
| 6558 | 6582 | |
| 6559 | | _ = operand; |
| 6560 | | return f.fail("TODO: C backend: implement airSplat", .{}); |
| 6583 | return local; |
| 6561 | 6584 | } |
| 6562 | 6585 | |
| 6563 | 6586 | fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue { |