Implement 'div'
This commit is contained in:
parent
ffb0110ea7
commit
7902aeca97
@ -566,6 +566,10 @@ const Parser = struct{
|
|||||||
sub_assign,
|
sub_assign,
|
||||||
mul,
|
mul,
|
||||||
mul_assign,
|
mul_assign,
|
||||||
|
udiv,
|
||||||
|
udiv_assign,
|
||||||
|
sdiv,
|
||||||
|
sdiv_assign,
|
||||||
@"and",
|
@"and",
|
||||||
and_assign,
|
and_assign,
|
||||||
@"or",
|
@"or",
|
||||||
@ -601,7 +605,7 @@ const Parser = struct{
|
|||||||
.none => {
|
.none => {
|
||||||
previous_value = current_value;
|
previous_value = current_value;
|
||||||
},
|
},
|
||||||
.add, .sub, .mul, .@"and", .@"or", .xor, .shift_left, .arithmetic_shift_right, .logical_shift_right => {
|
.add, .sub, .mul, .udiv, .sdiv, .@"and", .@"or", .xor, .shift_left, .arithmetic_shift_right, .logical_shift_right => {
|
||||||
const add = thread.integer_binary_operations.append(.{
|
const add = thread.integer_binary_operations.append(.{
|
||||||
.instruction = .{
|
.instruction = .{
|
||||||
.value = .{
|
.value = .{
|
||||||
@ -616,7 +620,7 @@ const Parser = struct{
|
|||||||
.left = previous_value,
|
.left = previous_value,
|
||||||
.right = current_value,
|
.right = current_value,
|
||||||
.id = switch (current_operation) {
|
.id = switch (current_operation) {
|
||||||
.none, .add_assign, .sub_assign, .mul_assign, .and_assign, .or_assign, .xor_assign, .shift_left_assign, .arithmetic_shift_right_assign, .logical_shift_right_assign => unreachable,
|
.none, .add_assign, .sub_assign, .mul_assign, .udiv_assign, .sdiv_assign, .and_assign, .or_assign, .xor_assign, .shift_left_assign, .arithmetic_shift_right_assign, .logical_shift_right_assign => unreachable,
|
||||||
inline else => |co| @field(IntegerBinaryOperation.Id, @tagName(co)),
|
inline else => |co| @field(IntegerBinaryOperation.Id, @tagName(co)),
|
||||||
},
|
},
|
||||||
.type = if (ty) |t| t else current_value.get_type(),
|
.type = if (ty) |t| t else current_value.get_type(),
|
||||||
@ -624,7 +628,7 @@ const Parser = struct{
|
|||||||
_ = analyzer.current_basic_block.instructions.append(&add.instruction);
|
_ = analyzer.current_basic_block.instructions.append(&add.instruction);
|
||||||
previous_value = &add.instruction.value;
|
previous_value = &add.instruction.value;
|
||||||
},
|
},
|
||||||
.add_assign, .sub_assign, .mul_assign, .and_assign, .or_assign, .xor_assign, .shift_left_assign, .logical_shift_right_assign, .arithmetic_shift_right_assign => unreachable,
|
.add_assign, .sub_assign, .mul_assign, .udiv_assign, .sdiv_assign, .and_assign, .or_assign, .xor_assign, .shift_left_assign, .logical_shift_right_assign, .arithmetic_shift_right_assign => unreachable,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (src[parser.i]) {
|
switch (src[parser.i]) {
|
||||||
@ -671,6 +675,28 @@ const Parser = struct{
|
|||||||
|
|
||||||
parser.skip_space(src);
|
parser.skip_space(src);
|
||||||
},
|
},
|
||||||
|
'/' => {
|
||||||
|
const int_ty = ty orelse previous_value.get_type();
|
||||||
|
const integer_type = int_ty.get_payload(.integer);
|
||||||
|
current_operation = switch (integer_type.signedness) {
|
||||||
|
.unsigned => .udiv,
|
||||||
|
.signed => .sdiv,
|
||||||
|
};
|
||||||
|
parser.i += 1;
|
||||||
|
|
||||||
|
switch (src[parser.i]) {
|
||||||
|
'=' => {
|
||||||
|
current_operation = switch (integer_type.signedness) {
|
||||||
|
.unsigned => .udiv_assign,
|
||||||
|
.signed => .sdiv_assign,
|
||||||
|
};
|
||||||
|
parser.i += 1;
|
||||||
|
},
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
parser.skip_space(src);
|
||||||
|
},
|
||||||
'&' => {
|
'&' => {
|
||||||
current_operation = .@"and";
|
current_operation = .@"and";
|
||||||
parser.i += 1;
|
parser.i += 1;
|
||||||
@ -1138,6 +1164,8 @@ const IntegerBinaryOperation = struct {
|
|||||||
add,
|
add,
|
||||||
sub,
|
sub,
|
||||||
mul,
|
mul,
|
||||||
|
udiv,
|
||||||
|
sdiv,
|
||||||
@"and",
|
@"and",
|
||||||
@"or",
|
@"or",
|
||||||
@"xor",
|
@"xor",
|
||||||
@ -2392,6 +2420,8 @@ fn worker_thread(thread_index: u32, cpu_count: *u32) void {
|
|||||||
.add => builder.createAdd(left, right, name, name.len, no_unsigned_wrapping, no_signed_wrapping),
|
.add => builder.createAdd(left, right, name, name.len, no_unsigned_wrapping, no_signed_wrapping),
|
||||||
.sub => builder.createSub(left, right, name, name.len, no_unsigned_wrapping, no_signed_wrapping),
|
.sub => builder.createSub(left, right, name, name.len, no_unsigned_wrapping, no_signed_wrapping),
|
||||||
.mul => builder.createMultiply(left, right, name, name.len, no_unsigned_wrapping, no_signed_wrapping),
|
.mul => builder.createMultiply(left, right, name, name.len, no_unsigned_wrapping, no_signed_wrapping),
|
||||||
|
.udiv => builder.createUDiv(left, right, name, name.len, is_exact),
|
||||||
|
.sdiv => builder.createSDiv(left, right, name, name.len, is_exact),
|
||||||
.@"and" => builder.createAnd(left, right, name, name.len),
|
.@"and" => builder.createAnd(left, right, name, name.len),
|
||||||
.@"or" => builder.createOr(left, right, name, name.len),
|
.@"or" => builder.createOr(left, right, name, name.len),
|
||||||
.@"xor" => builder.createXor(left, right, name, name.len),
|
.@"xor" => builder.createXor(left, right, name, name.len),
|
||||||
|
7
retest/standalone/div/main.nat
Normal file
7
retest/standalone/div/main.nat
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fn [cc(.c)] main [export] () s32 {
|
||||||
|
>dividend: s32 = 30;
|
||||||
|
>divisor: s32 = 6;
|
||||||
|
>result = dividend / divisor;
|
||||||
|
>n: s32 = 5;
|
||||||
|
return n - result;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user