authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-07-07 17:06:07-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-07-07 17:06:07-04:00
log2f28ecf946b566f40e648145af18d207d0c5770d
tree79c819f9e099ae04bc102fcf52ceffc0f8752f2d
parentaaaebfe97fa876356c22469001c6511dbdb8354d
signature Commit is signed but in an unrecognized format.

CBE: Get test more useful


3 files changed, 17 insertions(+), 2 deletions(-)

src-self-hosted/cgen.zig created+11
......@@ -0,0 +1,11 @@
1const link = @import("link.zig");
2const Module = @import("Module.zig");
3
4const C = link.File.C;
5const Decl = Module.Decl;
6const CStandard = Module.CStandard;
7
8pub fn generate(file: *C, decl: *Decl, standard: CStandard) !void {
9 const writer = file.file.?.writer();
10 try writer.print("Generating decl '{}', targeting {}", .{ decl.name, @tagName(standard) });
11}
src-self-hosted/link.zig+2-1
......@@ -7,6 +7,7 @@ const Module = @import("Module.zig");
77const fs = std.fs;
88const elf = std.elf;
99const codegen = @import("codegen.zig");
10const cgen = @import("cgen.zig");
1011
1112const default_entry_addr = 0x8000000;
1213
......@@ -229,7 +230,7 @@ pub const File = struct {
229230 }
230231
231232 pub fn updateDecl(self: *File.C, module: *Module, decl: *Module.Decl) !void {
232 return error.Unimplemented;
233 try cgen.generate(self, decl, self.options.c_standard.?);
233234 }
234235 };
235236
src-self-hosted/test.zig+4-1
......@@ -481,7 +481,10 @@ pub const TestContext = struct {
481481 if (case.c_standard) |cstd| {
482482 label = @tagName(cstd);
483483 var c: *link.File.C = module.bin_file.cast(link.File.C).?;
484 var out = c.file.?.reader().readAllAlloc(allocator, 1024 * 1024) catch @panic("Unable to read C output!");
484 c.file.?.close();
485 var file = try tmp.dir.openFile(bin_name, .{ .read = true });
486 defer file.close();
487 var out = file.reader().readAllAlloc(allocator, 1024 * 1024) catch @panic("Unable to read C output!");
485488 defer allocator.free(out);
486489
487490 if (expected_output.len != out.len) {