cbe: fix code header being omitted from the output

This commit is contained in:
Jacob Young 2025-07-08 00:51:33 -04:00 committed by Andrew Kelley
parent 043079d765
commit 720cd43fc1
2 changed files with 12 additions and 3 deletions

View File

@ -154,6 +154,7 @@ pub const Env = enum {
else => Env.ast_gen.supports(feature),
},
.cbe => switch (feature) {
.legalize,
.c_backend,
.c_linker,
=> true,

View File

@ -63,13 +63,20 @@ const String = extern struct {
.start = 0,
.len = 0,
};
fn concat(lhs: String, rhs: String) String {
assert(lhs.start + lhs.len == rhs.start);
return .{
.start = lhs.start,
.len = lhs.len + rhs.len,
};
}
};
/// Per-declaration data.
pub const AvBlock = struct {
fwd_decl: String = .empty,
code: String = .empty,
code_header: String = .empty,
/// Each `Decl` stores a set of used `CType`s. In `flush()`, we iterate
/// over each `Decl` and generate the definition for each used `CType` once.
ctype_pool: codegen.CType.Pool = .empty,
@ -205,9 +212,10 @@ pub fn updateFunc(
.ctype_pool = mir.c.ctype_pool.move(),
.lazy_fns = mir.c.lazy_fns.move(),
};
gop.value_ptr.code = try self.addString(mir.c.code);
gop.value_ptr.fwd_decl = try self.addString(mir.c.fwd_decl);
gop.value_ptr.code_header = try self.addString(mir.c.code_header);
const code_header = try self.addString(mir.c.code_header);
const code = try self.addString(mir.c.code);
gop.value_ptr.code = code_header.concat(code);
try self.addUavsFromCodegen(&mir.c.uavs);
}