stage2: implement runtime @intToEnum

* Update AIR instruction `intcast` to allow the dest type to be an
   enum.
 * LLVM backend: update `intcast` to support when the bit counts of
   operand and dest type are the same. This was already a requirement of
   the instruction previously.
 * Type: `intInfo` supports the case when the type is an enum, and
   retrieves the info for the integer tag type. This makes it pretty
   easy for backends to implement `intcast` without having to care
   explicitly that the new type is an enum. As a bonus, simple enums
   never have to go through the type system; their signedness and bit
   count are computed directly.

The "int to enum" behavior test case is now passing for stage2 in the
LLVM backend.
This commit is contained in:
Andrew Kelley
2021-10-05 21:38:47 -07:00
parent 941b2f0d5e
commit cb616cb797
6 changed files with 70 additions and 587 deletions

View File

@@ -2381,8 +2381,11 @@ pub const FuncGen = struct {
.signed => return self.builder.buildSExt(operand, dest_llvm_ty, ""),
.unsigned => return self.builder.buildZExt(operand, dest_llvm_ty, ""),
}
} else if (operand_info.bits > dest_info.bits) {
return self.builder.buildTrunc(operand, dest_llvm_ty, "");
} else {
return operand;
}
return self.builder.buildTrunc(operand, dest_llvm_ty, "");
}
fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {