Select
This commit is contained in:
parent
c59a77e7a0
commit
d61a71c07d
@ -721,7 +721,7 @@ pub const Value = struct {
|
|||||||
int_from_enum: *Value,
|
int_from_enum: *Value,
|
||||||
int_from_pointer: *Value,
|
int_from_pointer: *Value,
|
||||||
pointer_cast: *Value,
|
pointer_cast: *Value,
|
||||||
select,
|
select: Select,
|
||||||
trap,
|
trap,
|
||||||
truncate: *Value,
|
truncate: *Value,
|
||||||
va_start,
|
va_start,
|
||||||
@ -746,6 +746,13 @@ pub const Value = struct {
|
|||||||
va_copy,
|
va_copy,
|
||||||
va_arg,
|
va_arg,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Select = struct {
|
||||||
|
condition: *Value,
|
||||||
|
true_value: *Value,
|
||||||
|
false_value: *Value,
|
||||||
|
};
|
||||||
|
|
||||||
const VaArg = struct {
|
const VaArg = struct {
|
||||||
list: *Value,
|
list: *Value,
|
||||||
type: *Type,
|
type: *Type,
|
||||||
@ -2556,6 +2563,31 @@ pub const Module = struct {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
.select => blk: {
|
||||||
|
module.skip_space();
|
||||||
|
module.expect_character(left_parenthesis);
|
||||||
|
module.skip_space();
|
||||||
|
const condition = module.parse_value(function, .{});
|
||||||
|
module.expect_character(',');
|
||||||
|
module.skip_space();
|
||||||
|
const true_value = module.parse_value(function, .{});
|
||||||
|
module.expect_character(',');
|
||||||
|
module.skip_space();
|
||||||
|
const false_value = module.parse_value(function, .{});
|
||||||
|
module.skip_space();
|
||||||
|
module.expect_character(right_parenthesis);
|
||||||
|
break :blk .{
|
||||||
|
.bb = .{
|
||||||
|
.intrinsic = .{
|
||||||
|
.select = .{
|
||||||
|
.condition = condition,
|
||||||
|
.true_value = true_value,
|
||||||
|
.false_value = false_value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
.trap => blk: {
|
.trap => blk: {
|
||||||
module.skip_space();
|
module.skip_space();
|
||||||
module.expect_character(left_parenthesis);
|
module.expect_character(left_parenthesis);
|
||||||
@ -4848,6 +4880,11 @@ pub const Module = struct {
|
|||||||
module.report_error();
|
module.report_error();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
.select => |select| {
|
||||||
|
module.analyze_value_type(function, select.condition, .{});
|
||||||
|
module.analyze_value_type(function, select.true_value, .{ .type = expected_type });
|
||||||
|
module.analyze_value_type(function, select.false_value, .{ .type = expected_type });
|
||||||
|
},
|
||||||
.truncate => |value_to_truncate| {
|
.truncate => |value_to_truncate| {
|
||||||
module.analyze_value_type(function, value_to_truncate, .{});
|
module.analyze_value_type(function, value_to_truncate, .{});
|
||||||
if (expected_type.get_bit_size() >= value_to_truncate.type.?.get_bit_size()) {
|
if (expected_type.get_bit_size() >= value_to_truncate.type.?.get_bit_size()) {
|
||||||
@ -5415,6 +5452,20 @@ pub const Module = struct {
|
|||||||
module.emit_value(function, pointer_value);
|
module.emit_value(function, pointer_value);
|
||||||
break :blk pointer_value.llvm.?;
|
break :blk pointer_value.llvm.?;
|
||||||
},
|
},
|
||||||
|
.select => |select| blk: {
|
||||||
|
module.emit_value(function, select.condition);
|
||||||
|
const condition = switch (select.condition.type.?.bb) {
|
||||||
|
.integer => |integer| switch (integer.bit_count) {
|
||||||
|
1 => select.condition.llvm.?,
|
||||||
|
else => @trap(),
|
||||||
|
},
|
||||||
|
else => @trap(),
|
||||||
|
};
|
||||||
|
module.emit_value(function, select.true_value);
|
||||||
|
module.emit_value(function, select.false_value);
|
||||||
|
const result = module.llvm.builder.create_select(condition, select.true_value.llvm.?, select.false_value.llvm.?);
|
||||||
|
break :blk result;
|
||||||
|
},
|
||||||
.trap => blk: {
|
.trap => blk: {
|
||||||
// TODO: lookup in advance
|
// TODO: lookup in advance
|
||||||
const intrinsic_id = module.llvm.intrinsic_table.trap;
|
const intrinsic_id = module.llvm.intrinsic_table.trap;
|
||||||
|
@ -227,4 +227,5 @@ const names = &[_][]const u8{
|
|||||||
"ret_c_bool",
|
"ret_c_bool",
|
||||||
"return_type_builtin",
|
"return_type_builtin",
|
||||||
"return_u64_u64",
|
"return_u64_u64",
|
||||||
|
"select",
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user