Merge pull request #87 from birth-software/enable-macos-tests

Make some MacOS tests pass
This commit is contained in:
David 2024-02-18 10:53:12 -06:00 committed by GitHub
commit 863603c03c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 40 deletions

6
.vscode/launch.json vendored
View File

@ -8,9 +8,11 @@
"type": "lldb",
"request": "launch",
"name": "Launch",
"program": "${workspaceFolder}/zig-out/bin/nativity",
"program": "${workspaceFolder}/zig-out/bin/nat",
"args": [
"test/hello_world/main.nat"
"exe",
"-main_source_file",
"test/standalone/first/main.nat"
],
"cwd": "${workspaceFolder}",
},

View File

@ -1282,9 +1282,12 @@ pub const LLVM = struct {
fn renderTypeName(llvm: *LLVM, unit: *Compilation.Unit, context: *const Compilation.Context, sema_type_index: Compilation.Type.Index) ![]const u8 {
const gop = try llvm.type_name_map.getOrPut(context.allocator, sema_type_index);
if (!gop.found_existing) {
if (gop.found_existing) {
return gop.value_ptr.*;
} else {
if (unit.type_declarations.get(sema_type_index)) |global_declaration| {
gop.value_ptr.* = unit.getIdentifier(global_declaration.declaration.name);
return gop.value_ptr.*;
} else {
const sema_type = unit.types.get(sema_type_index);
const result: []const u8 = switch (sema_type.*) {
@ -1348,11 +1351,11 @@ pub const LLVM = struct {
else => |t| @panic(@tagName(t)),
};
gop.value_ptr.* = result;
}
}
try llvm.type_name_map.put(context.allocator, sema_type_index, result);
return gop.value_ptr.*;
return result;
}
}
}
fn createDebugStructType(llvm: *LLVM, arguments: struct {
@ -2302,7 +2305,13 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
try llvm.scope_map.putNoClobber(context.allocator, &unit.scope.scope, llvm.scope);
}
for (unit.code_to_emit.values()) |function_declaration| {
const functions = unit.code_to_emit.values();
{
var function_i: usize = functions.len;
while (function_i > 0) {
function_i -= 1;
const function_declaration = functions[function_i];
const function_definition_index = function_declaration.getFunctionDefinitionIndex();
const function_definition = unit.function_definitions.get(function_definition_index);
const function_type = try llvm.getType(unit, context, function_definition.type);
@ -2334,6 +2343,7 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
try llvm.function_definition_map.putNoClobber(context.allocator, function_declaration, function);
}
}
// First, cache all the global variables
for (unit.data_to_emit.items) |global_declaration| {
@ -3100,22 +3110,27 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
// TODO: initialize only the target we are going to use
bindings.NativityLLVMInitializeCodeGeneration();
const target_triple = "x86_64-linux-none";
// TODO: proper target selection
const target_triple = switch (unit.descriptor.target.os.tag) {
.linux => "x86_64-linux-none",
.macos => "aarch64-apple-macosx-none",
else => |t| @panic(@tagName(t)),
};
const cpu = "generic";
const features = "";
const target = blk: {
var error_message: [*]const u8 = undefined;
var error_message_len: usize = 0;
const target = bindings.NativityLLVMGetTarget(target_triple, target_triple.len, &error_message, &error_message_len) orelse unreachable;
const target = bindings.NativityLLVMGetTarget(target_triple.ptr, target_triple.len, &error_message, &error_message_len) orelse unreachable;
break :blk target;
};
const jit = false;
const code_model: LLVM.CodeModel = undefined;
const is_code_model_present = false;
const target_machine = target.createTargetMachine(target_triple, target_triple.len, cpu, cpu.len, features, features.len, LLVM.RelocationModel.static, code_model, is_code_model_present, LLVM.OptimizationLevel.none, jit) orelse unreachable;
const target_machine = target.createTargetMachine(target_triple.ptr, target_triple.len, cpu, cpu.len, features, features.len, LLVM.RelocationModel.static, code_model, is_code_model_present, LLVM.OptimizationLevel.none, jit) orelse unreachable;
llvm.module.setTargetMachineDataLayout(target_machine);
llvm.module.setTargetTriple(target_triple, target_triple.len);
llvm.module.setTargetTriple(target_triple.ptr, target_triple.len);
const file_path = unit.descriptor.executable_path;
const object_file_path = try std.mem.joinZ(context.allocator, "", &.{ file_path, ".o" });
const destination_file_path = try std.mem.joinZ(context.allocator, "", &.{file_path});

View File

@ -388,7 +388,6 @@ pub fn build(b: *std.Build) !void {
// not tested
const result = b.addSystemCommand(&.{"lldb"});
result.addArg("--");
result.addArg(compiler_exe_path);
break :blk result;
},
else => @compileError("OS not supported"),
@ -409,9 +408,13 @@ pub fn build(b: *std.Build) !void {
test_command.step.dependOn(b.getInstallStep());
if (b.args) |args| {
std.debug.print("Args: {s}", .{args});
run_command.addArgs(args);
debug_command.addArgs(args);
test_command.addArgs(args);
for (debug_command.argv.items, 0..) |arg, i| {
std.debug.print("Arg #{}: {s}\n", .{i, arg.bytes});
}
}
const run_step = b.step("run", "Test the Nativity compiler");