This commit is contained in:
agra
2026-02-20 12:12:51 +02:00
parent e0e655cd36
commit 1ecac79642
10 changed files with 265 additions and 29 deletions

View File

@@ -3108,6 +3108,11 @@ pub const CodeGen = struct {
.mul_assign => if (ty.isFloat()) c.LLVMBuildFMul(self.builder, cur, rhs, "multmp") else c.LLVMBuildMul(self.builder, cur, rhs, "multmp"),
.div_assign => if (ty.isFloat()) c.LLVMBuildFDiv(self.builder, cur, rhs, "divtmp") else if (ty.isUnsigned()) c.LLVMBuildUDiv(self.builder, cur, rhs, "divtmp") else c.LLVMBuildSDiv(self.builder, cur, rhs, "divtmp"),
.mod_assign => if (ty.isFloat()) c.LLVMBuildFRem(self.builder, cur, rhs, "modtmp") else if (ty.isUnsigned()) c.LLVMBuildURem(self.builder, cur, rhs, "modtmp") else c.LLVMBuildSRem(self.builder, cur, rhs, "modtmp"),
.and_assign => c.LLVMBuildAnd(self.builder, cur, rhs, "bandtmp"),
.or_assign => c.LLVMBuildOr(self.builder, cur, rhs, "bortmp"),
.xor_assign => c.LLVMBuildXor(self.builder, cur, rhs, "bxortmp"),
.shl_assign => c.LLVMBuildShl(self.builder, cur, rhs, "shltmp"),
.shr_assign => if (ty.isUnsigned()) c.LLVMBuildLShr(self.builder, cur, rhs, "shrtmp") else c.LLVMBuildAShr(self.builder, cur, rhs, "shrtmp"),
.assign => unreachable,
};
}
@@ -3560,6 +3565,7 @@ pub const CodeGen = struct {
c.LLVMBuildNeg(self.builder, operand, "negtmp");
},
.not => c.LLVMBuildNot(self.builder, operand, "nottmp"),
.bit_not => c.LLVMBuildNot(self.builder, operand, "bnottmp"),
.xx, .address_of => unreachable,
};
},
@@ -4460,15 +4466,17 @@ pub const CodeGen = struct {
}
// Bitwise op on enum type: recursively generate both sides with enum context
if (node.data == .binary_op and (node.data.binary_op.op == .bit_or or node.data.binary_op.op == .bit_and) and target_ty.isEnum()) {
if (node.data == .binary_op and (node.data.binary_op.op == .bit_or or node.data.binary_op.op == .bit_and or node.data.binary_op.op == .bit_xor) and target_ty.isEnum()) {
const binop = node.data.binary_op;
const lhs = try self.genExprAsType(binop.lhs, target_ty);
const rhs = try self.genExprAsType(binop.rhs, target_ty);
const b = self.builder;
return if (binop.op == .bit_or)
c.LLVMBuildOr(b, lhs, rhs, "bortmp")
else
c.LLVMBuildAnd(b, lhs, rhs, "bandtmp");
return switch (binop.op) {
.bit_or => c.LLVMBuildOr(b, lhs, rhs, "bortmp"),
.bit_and => c.LLVMBuildAnd(b, lhs, rhs, "bandtmp"),
.bit_xor => c.LLVMBuildXor(b, lhs, rhs, "bxortmp"),
else => unreachable,
};
}
// Enum/union literal assigned to union type: construct tagged enum
@@ -5714,6 +5722,9 @@ pub const CodeGen = struct {
.gte => if (is_float) c.LLVMBuildFCmp(b, c.LLVMRealOGE, lhs, rhs, "getmp") else if (is_unsigned) c.LLVMBuildICmp(b, c.LLVMIntUGE, lhs, rhs, "getmp") else c.LLVMBuildICmp(b, c.LLVMIntSGE, lhs, rhs, "getmp"),
.bit_and => c.LLVMBuildAnd(b, lhs, rhs, "bandtmp"),
.bit_or => c.LLVMBuildOr(b, lhs, rhs, "bortmp"),
.bit_xor => c.LLVMBuildXor(b, lhs, rhs, "bxortmp"),
.shl => c.LLVMBuildShl(b, lhs, rhs, "shltmp"),
.shr => if (is_unsigned) c.LLVMBuildLShr(b, lhs, rhs, "shrtmp") else c.LLVMBuildAShr(b, lhs, rhs, "shrtmp"),
.and_op, .or_op, .in_op => unreachable,
};
}