zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2f28ecf946b566f40e648145af18d207d0c5770d (tree)
parent aaaebfe97fa876356c22469001c6511dbdb8354d
Author: Noam Preil <pleasantatk@gmail.com>
Date:   Tue,  7 Jul 2020 17:06:07 -0400

CBE: Get test more useful

Diffstat:
Asrc-self-hosted/cgen.zig | 11+++++++++++
Msrc-self-hosted/link.zig | 3++-
Msrc-self-hosted/test.zig | 5++++-
3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src-self-hosted/cgen.zig b/src-self-hosted/cgen.zig @@ -0,0 +1,11 @@ +const link = @import("link.zig"); +const Module = @import("Module.zig"); + +const C = link.File.C; +const Decl = Module.Decl; +const CStandard = Module.CStandard; + +pub fn generate(file: *C, decl: *Decl, standard: CStandard) !void { + const writer = file.file.?.writer(); + try writer.print("Generating decl '{}', targeting {}", .{ decl.name, @tagName(standard) }); +} diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig @@ -7,6 +7,7 @@ const Module = @import("Module.zig"); const fs = std.fs; const elf = std.elf; const codegen = @import("codegen.zig"); +const cgen = @import("cgen.zig"); const default_entry_addr = 0x8000000; @@ -229,7 +230,7 @@ pub const File = struct { } pub fn updateDecl(self: *File.C, module: *Module, decl: *Module.Decl) !void { - return error.Unimplemented; + try cgen.generate(self, decl, self.options.c_standard.?); } }; diff --git a/src-self-hosted/test.zig b/src-self-hosted/test.zig @@ -481,7 +481,10 @@ pub const TestContext = struct { if (case.c_standard) |cstd| { label = @tagName(cstd); var c: *link.File.C = module.bin_file.cast(link.File.C).?; - var out = c.file.?.reader().readAllAlloc(allocator, 1024 * 1024) catch @panic("Unable to read C output!"); + c.file.?.close(); + var file = try tmp.dir.openFile(bin_name, .{ .read = true }); + defer file.close(); + var out = file.reader().readAllAlloc(allocator, 1024 * 1024) catch @panic("Unable to read C output!"); defer allocator.free(out); if (expected_output.len != out.len) {