Pointer cast
All checks were successful
CI / ci (ReleaseFast, ubuntu-latest) (push) Successful in 35s
CI / ci (ReleaseSmall, ubuntu-latest) (push) Successful in 35s
CI / ci (ReleaseSafe, ubuntu-latest) (push) Successful in 41s
CI / ci (Debug, ubuntu-latest) (push) Successful in 58s

This commit is contained in:
David Gonzalez Martin 2025-04-09 21:16:10 -06:00
parent 1bbd783184
commit 6c244c1243
2 changed files with 36 additions and 1 deletions

View File

@ -529,7 +529,7 @@ pub const Value = struct {
integer_max: *Type,
int_from_enum,
int_from_pointer,
pointer_cast,
pointer_cast: *Value,
select,
trap,
truncate: *Value,
@ -1852,6 +1852,20 @@ pub const Module = struct {
},
};
},
.pointer_cast => blk: {
module.skip_space();
module.expect_character(left_parenthesis);
module.skip_space();
const v = module.parse_value(.{});
module.expect_character(right_parenthesis);
break :blk .{
.bb = .{
.intrinsic = .{
.pointer_cast = v,
},
},
};
},
.truncate => blk: {
module.skip_space();
module.expect_character(left_parenthesis);
@ -2934,6 +2948,10 @@ pub const Module = struct {
const truncate = module.llvm.builder.create_truncate(llvm_value, value_type.llvm.handle.?);
break :blk truncate;
},
.pointer_cast => |pointer_value| blk: {
module.emit_value(function, pointer_value);
break :blk pointer_value.llvm.?;
},
else => @trap(),
},
.dereference => |dereferenceable_value| blk: {
@ -3412,6 +3430,21 @@ pub const Module = struct {
module.report_error();
}
},
.pointer_cast => |pointer_value| {
if (expected_type.bb != .pointer) {
module.report_error();
}
module.analyze_value_type(function, pointer_value, .{});
const pointer_type = pointer_value.type orelse module.report_error();
if (pointer_type == expected_type) {
module.report_error();
}
if (pointer_type.bb != .pointer) {
module.report_error();
}
},
.truncate => |value_to_truncate| {
module.analyze_value_type(function, value_to_truncate, .{});
if (expected_type.get_bit_size() >= value_to_truncate.type.?.get_bit_size()) {

View File

@ -189,10 +189,12 @@ const names = &[_][]const u8{
"extend",
"stack_negation",
"stack_add",
"stack_sub",
"integer_max",
"integer_hex",
"basic_pointer",
"basic_call",
"pointer",
"pointer_cast",
"u1_return",
};