CBE: Get test more useful

This commit is contained in:
Noam Preil 2020-07-07 17:06:07 -04:00
parent aaaebfe97f
commit 2f28ecf946
No known key found for this signature in database
GPG Key ID: FC347E7C85BE8238
3 changed files with 17 additions and 2 deletions

11
src-self-hosted/cgen.zig Normal file
View File

@ -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) });
}

View File

@ -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.?);
}
};

View File

@ -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) {