Pass more tests

This commit is contained in:
David Gonzalez Martin 2024-02-02 08:18:52 +01:00
parent cbd1438781
commit cb4226295b
11 changed files with 117 additions and 61 deletions

View File

@ -20,44 +20,44 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Zig - name: Set up Zig
uses: davidgm94/setup-zig@foo uses: goto-bus-stop/setup-zig@v2
with: with:
version: master version: master
- name: Test - name: Test
run: zig build test -Dself_hosted_ci=true -Dllvm_path=../../../../../dev/llvm/llvm-static-release-zen4-17.0.6/out/x86_64-linux-musl-native run: zig build test -Dself_hosted_ci=true -Dllvm_path=../../../../../dev/llvm/llvm-static-release-zen4-17.0.6/out/x86_64-linux-musl-native
macos_m1: # macos_m1:
runs-on: macos-14 # runs-on: macos-14
timeout-minutes: 15 # timeout-minutes: 15
steps: # steps:
- name: Checkout # - name: Checkout
uses: actions/checkout@v4 # uses: actions/checkout@v4
- name: Set up Zig # - name: Set up Zig
uses: davidgm94/setup-zig@foo # uses: davidgm94/setup-zig@foo
with: # with:
version: master # version: master
- name: Build # - name: Build
run: zig build -Dthird_party_ci=true -Dtarget=aarch64-macos-none -Dcpu=apple_m1 # run: zig build -Dthird_party_ci=true -Dtarget=aarch64-macos-none -Dcpu=apple_m1
linux_x86_64_v3: # linux_x86_64_v3:
runs-on: ubuntu-latest # runs-on: ubuntu-latest
timeout-minutes: 15 # timeout-minutes: 15
steps: # steps:
- name: Checkout # - name: Checkout
uses: actions/checkout@v4 # uses: actions/checkout@v4
- name: Set up Zig # - name: Set up Zig
uses: davidgm94/setup-zig@foo # uses: davidgm94/setup-zig@foo
with: # with:
version: master # version: master
- name: Build # - name: Build
run: zig build -Dthird_party_ci=true -Dtarget=x86_64-linux-musl -Dcpu=x86_64_v3 # run: zig build -Dthird_party_ci=true -Dtarget=x86_64-linux-musl -Dcpu=x86_64_v3
windows_x86_64_v3: # windows_x86_64_v3:
runs-on: windows-latest # runs-on: windows-latest
timeout-minutes: 15 # timeout-minutes: 15
steps: # steps:
- name: Checkout # - name: Checkout
uses: actions/checkout@v4 # uses: actions/checkout@v4
- name: Set up Zig # - name: Set up Zig
uses: davidgm94/setup-zig@foo # uses: davidgm94/setup-zig@foo
with: # with:
version: master # version: master
- name: Build # - name: Build
run: zig build -Dthird_party_ci=true -Dtarget=x86_64-windows-gnu -Dcpu=x86_64_v3 # run: zig build -Dthird_party_ci=true -Dtarget=x86_64-windows-gnu -Dcpu=x86_64_v3

View File

@ -558,7 +558,15 @@ pub const Instruction = union(enum) {
const Id = enum{ const Id = enum{
add, add,
div,
mod,
mul, mul,
sub,
bit_and,
bit_or,
bit_xor,
shift_left,
shift_right,
}; };
}; };
@ -578,6 +586,7 @@ pub const Instruction = union(enum) {
type: Type.Index, type: Type.Index,
const Id = enum{ const Id = enum{
bitcast,
enum_to_int, enum_to_int,
int_to_pointer, int_to_pointer,
sign_extend, sign_extend,
@ -760,6 +769,7 @@ pub const Debug = struct{
pub const Local = struct{ pub const Local = struct{
declaration: Declaration, declaration: Declaration,
init_value: V,
pub const List = BlockList(@This(), enum{}); pub const List = BlockList(@This(), enum{});
pub usingnamespace List.Index; pub usingnamespace List.Index;
}; };
@ -976,7 +986,8 @@ pub const Builder = struct {
else => |t| @panic(@tagName(t)), else => |t| @panic(@tagName(t)),
}, },
.identifier => b: { .identifier => b: {
const result = try builder.resolveIdentifier(unit, context, Type.Expect.none, operand_node_index, .left); const identifier = unit.getExpectedTokenBytes(operand_node.token, .identifier);
const result = try builder.resolveIdentifier(unit, context, Type.Expect.none, identifier, .left);
break :b .{ break :b .{
.value = result, .value = result,
@ -1052,7 +1063,8 @@ pub const Builder = struct {
.unsigned => .sign_extend, .unsigned => .sign_extend,
}; };
} else { } else {
unreachable; assert(destination_integer.signedness != source_integer.signedness);
break :b .bitcast;
} }
}, },
else => |t| @panic(@tagName(t)), else => |t| @panic(@tagName(t)),
@ -1660,14 +1672,16 @@ pub const Builder = struct {
const local_declaration = @fieldParentPtr(Debug.Declaration.Local, "declaration", declaration); const local_declaration = @fieldParentPtr(Debug.Declaration.Local, "declaration", declaration);
const local_scope = @fieldParentPtr(Debug.Scope.Local, "scope", scope); const local_scope = @fieldParentPtr(Debug.Scope.Local, "scope", scope);
const instruction_index = local_scope.local_declaration_map.get(local_declaration).?; if (local_scope.local_declaration_map.get(local_declaration)) |instruction_index| {
return .{
return .{ .value = .{
.value = .{ .runtime = instruction_index,
.runtime = instruction_index, },
}, .type = declaration.type,
.type = declaration.type, };
}; } else {
return local_declaration.init_value;
}
} }
const TypeCheckResult = enum{ const TypeCheckResult = enum{
@ -1709,6 +1723,20 @@ pub const Builder = struct {
else =>|t| @panic(@tagName(t)), else =>|t| @panic(@tagName(t)),
} }
}, },
.integer => |destination_integer| {
switch (source.*) {
.integer => |source_integer| {
if (destination_integer.signedness == source_integer.signedness) {
if (destination_integer.bit_count == source_integer.bit_count) {
unreachable;
}
}
unreachable;
},
else => |t| @panic(@tagName(t)),
}
},
else => |t| @panic(@tagName(t)), else => |t| @panic(@tagName(t)),
} }
unreachable; unreachable;
@ -1720,10 +1748,7 @@ pub const Builder = struct {
right, right,
}; };
fn resolveIdentifier(builder: *Builder, unit: *Unit, context: *const Context, type_expect: Type.Expect, node_index: Node.Index, side: Side) !V { fn resolveIdentifier(builder: *Builder, unit: *Unit, context: *const Context, type_expect: Type.Expect, identifier: []const u8, side: Side) !V {
const node = unit.getNode(node_index);
const identifier = unit.getExpectedTokenBytes(node.token, .identifier);
const hash = try unit.processIdentifier(context, identifier); const hash = try unit.processIdentifier(context, identifier);
const look_in_parent_scopes = true; const look_in_parent_scopes = true;
@ -2350,7 +2375,8 @@ pub const Builder = struct {
const node = unit.getNode(node_index); const node = unit.getNode(node_index);
switch (node.id) { switch (node.id) {
.identifier => { .identifier => {
const result = try builder.resolveIdentifier(unit, context, type_expect, node_index, side); const identifier = unit.getExpectedTokenBytes(node.token, .identifier);
const result = try builder.resolveIdentifier(unit, context, type_expect, identifier, side);
return result; return result;
}, },
.intrinsic => { .intrinsic => {
@ -2397,18 +2423,18 @@ pub const Builder = struct {
.type = load_type, .type = load_type,
}; };
}, },
.add, .mul => { .add, .sub, .mul, .div, .mod, .bit_and, .bit_or, .bit_xor, .shift_left, .shift_right => {
const left_node_index = node.left; const left_node_index = node.left;
const right_node_index = node.left; const right_node_index = node.left;
const binary_operation_id: BinaryOperationId = switch (node.id) { const binary_operation_id: BinaryOperationId = switch (node.id) {
.add => .add, .add => .add,
.sub => .sub, .sub => .sub,
.bit_and => .bit_and,
.bit_xor => .bit_xor,
.bit_or => .bit_or,
.mul => .mul, .mul => .mul,
.div => .div, .div => .div,
.mod => .mod, .mod => .mod,
.bit_and => .bit_and,
.bit_xor => .bit_xor,
.bit_or => .bit_or,
.shift_left => .shift_left, .shift_left => .shift_left,
.shift_right => .shift_right, .shift_right => .shift_right,
.compare_equal => .compare_equal, .compare_equal => .compare_equal,
@ -2490,7 +2516,15 @@ pub const Builder = struct {
.integer => |integer| b: { .integer => |integer| b: {
const id: Instruction.IntegerBinaryOperation.Id = switch (binary_operation_id) { const id: Instruction.IntegerBinaryOperation.Id = switch (binary_operation_id) {
.add => .add, .add => .add,
.div => .div,
.mod => .mod,
.mul => .mul, .mul => .mul,
.sub => .sub,
.bit_and => .bit_and,
.bit_or => .bit_or,
.bit_xor => .bit_xor,
.shift_left => .shift_left,
.shift_right => .shift_right,
else => |t| @panic(@tagName(t)), else => |t| @panic(@tagName(t)),
}; };
@ -2748,9 +2782,11 @@ pub const Builder = struct {
.column = token_debug_info.column, .column = token_debug_info.column,
.kind = .local, .kind = .local,
}, },
.init_value = initialization,
}); });
const local_declaration = unit.local_declarations.get(declaration_index); const local_declaration = unit.local_declarations.get(declaration_index);
assert(builder.current_scope.kind == .block);
try builder.current_scope.declarations.putNoClobber(context.allocator, identifier_hash, &local_declaration.declaration); try builder.current_scope.declarations.putNoClobber(context.allocator, identifier_hash, &local_declaration.declaration);
if (emit) { if (emit) {

View File

@ -3181,6 +3181,10 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
.pointer_var_to_const => { .pointer_var_to_const => {
try llvm.llvm_instruction_map.putNoClobber(context.allocator, instruction_index, value); try llvm.llvm_instruction_map.putNoClobber(context.allocator, instruction_index, value);
}, },
.bitcast => {
const bitcast = llvm.builder.createCast(.bitcast, value, dest_type, "bitcast", "bitcast".len) orelse return LLVM.Value.Instruction.Error.cast;
try llvm.llvm_instruction_map.putNoClobber(context.allocator, instruction_index, bitcast);
},
else => |t| @panic(@tagName(t)), else => |t| @panic(@tagName(t)),
} }
}, },
@ -3206,11 +3210,27 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
const no_signed_wrapping = binary_operation.signedness == .signed; const no_signed_wrapping = binary_operation.signedness == .signed;
const no_unsigned_wrapping = binary_operation.signedness == .unsigned; const no_unsigned_wrapping = binary_operation.signedness == .unsigned;
const name = @tagName(binary_operation.id); const name = @tagName(binary_operation.id);
// const is_exact = false;
const instruction = switch (binary_operation.id) { const instruction = switch (binary_operation.id) {
.add => llvm.builder.createAdd(left, right, name.ptr, name.len, no_unsigned_wrapping, no_signed_wrapping) orelse return LLVM.Value.Instruction.Error.add, .add => llvm.builder.createAdd(left, right, name.ptr, name.len, no_unsigned_wrapping, no_signed_wrapping) orelse return LLVM.Value.Instruction.Error.add,
.mul => llvm.builder.createMultiply(left, right, name.ptr, name.len, no_unsigned_wrapping, no_signed_wrapping) orelse return LLVM.Value.Instruction.Error.multiply, .mul => llvm.builder.createMultiply(left, right, name.ptr, name.len, no_unsigned_wrapping, no_signed_wrapping) orelse return LLVM.Value.Instruction.Error.multiply,
// .sub => llvm.builder.createSub(left, right, name.ptr, name.len, no_unsigned_wrapping, no_signed_wrapping) orelse return LLVM.Value.Instruction.Error.add, .sub => llvm.builder.createSub(left, right, name.ptr, name.len, no_unsigned_wrapping, no_signed_wrapping) orelse return LLVM.Value.Instruction.Error.add,
.div => switch (binary_operation.signedness) {
.unsigned => llvm.builder.createUDiv(left, right, name.ptr, name.len, is_exact) orelse unreachable,
.signed => llvm.builder.createSDiv(left, right, name.ptr, name.len, is_exact) orelse unreachable,
},
.mod => switch (binary_operation.signedness) {
.unsigned => llvm.builder.createURem(left, right, name.ptr, name.len) orelse unreachable,
.signed => llvm.builder.createSRem(left, right, name.ptr, name.len) orelse unreachable,
},
.bit_and => llvm.builder.createAnd(left, right, name.ptr, name.len) orelse unreachable,
.bit_or => llvm.builder.createOr(left, right, name.ptr, name.len) orelse unreachable,
.bit_xor => llvm.builder.createXor(left, right, name.ptr, name.len) orelse unreachable,
.shift_left => llvm.builder.createShiftLeft(left, right, name.ptr, name.len, no_unsigned_wrapping, no_signed_wrapping) orelse unreachable,
.shift_right => switch (binary_operation.signedness) {
.unsigned => llvm.builder.createLogicalShiftRight(left, right, name.ptr, name.len, is_exact) orelse unreachable,
.signed => llvm.builder.createArithmeticShiftRight(left, right, name.ptr, name.len, is_exact) orelse unreachable,
},
//else => |t| @panic(@tagName(t)), //else => |t| @panic(@tagName(t)),
}; };
try llvm.llvm_instruction_map.putNoClobber(context.allocator, instruction_index, instruction); try llvm.llvm_instruction_map.putNoClobber(context.allocator, instruction_index, instruction);

View File

@ -55,10 +55,10 @@ pub fn main() !void {
}; };
std.debug.print("[{s}]\n", .{if (success) "OK" else "FAIL"}); std.debug.print("[{s}]\n", .{if (success) "OK" else "FAIL"});
if (process_run.stdout.len > 0) { if (process_run.stdout.len > 0) {
std.debug.print("\tSTDOUT:\n{s}\n\n", .{process_run.stdout}); std.debug.print("STDOUT:\n\n{s}\n\n", .{process_run.stdout});
} }
if (process_run.stderr.len > 0) { if (process_run.stderr.len > 0) {
std.debug.print("\tSTDERR:\n{s}\n\n", .{process_run.stderr}); std.debug.print("STDERR:\n\n{s}\n\n", .{process_run.stderr});
} }
} }

View File

@ -3,5 +3,5 @@ const main = fn() s32 {
x = x << 5; x = x << 5;
x = x >> 5; x = x >> 5;
const b: u32 = 1; const b: u32 = 1;
return x - b; return #cast(x - b);
} }