Commit 2f28ecf946

Noam Preil <pleasantatk@gmail.com>
2020-07-07 23:06:07
CBE: Get test more useful
1 parent aaaebfe
Changed files (3)
src-self-hosted
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) });
+}
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.?);
         }
     };
 
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) {