| ... | @@ -63,13 +63,20 @@ const String = extern struct { | ... | @@ -63,13 +63,20 @@ const String = extern struct { |
| 63 | .start = 0, | 63 | .start = 0, |
| 64 | .len = 0, | 64 | .len = 0, |
| 65 | }; | 65 | }; |
| | 66 | |
| | 67 | fn concat(lhs: String, rhs: String) String { |
| | 68 | assert(lhs.start + lhs.len == rhs.start); |
| | 69 | return .{ |
| | 70 | .start = lhs.start, |
| | 71 | .len = lhs.len + rhs.len, |
| | 72 | }; |
| | 73 | } |
| 66 | }; | 74 | }; |
| 67 | | 75 | |
| 68 | /// Per-declaration data. | 76 | /// Per-declaration data. |
| 69 | pub const AvBlock = struct { | 77 | pub const AvBlock = struct { |
| 70 | fwd_decl: String = .empty, | 78 | fwd_decl: String = .empty, |
| 71 | code: String = .empty, | 79 | code: String = .empty, |
| 72 | code_header: String = .empty, | | |
| 73 | /// Each `Decl` stores a set of used `CType`s. In `flush()`, we iterate | 80 | /// Each `Decl` stores a set of used `CType`s. In `flush()`, we iterate |
| 74 | /// over each `Decl` and generate the definition for each used `CType` once. | 81 | /// over each `Decl` and generate the definition for each used `CType` once. |
| 75 | ctype_pool: codegen.CType.Pool = .empty, | 82 | ctype_pool: codegen.CType.Pool = .empty, |
| ... | @@ -205,9 +212,10 @@ pub fn updateFunc( | ... | @@ -205,9 +212,10 @@ pub fn updateFunc( |
| 205 | .ctype_pool = mir.c.ctype_pool.move(), | 212 | .ctype_pool = mir.c.ctype_pool.move(), |
| 206 | .lazy_fns = mir.c.lazy_fns.move(), | 213 | .lazy_fns = mir.c.lazy_fns.move(), |
| 207 | }; | 214 | }; |
| 208 | gop.value_ptr.code = try self.addString(mir.c.code); | | |
| 209 | gop.value_ptr.fwd_decl = try self.addString(mir.c.fwd_decl); | 215 | gop.value_ptr.fwd_decl = try self.addString(mir.c.fwd_decl); |
| 210 | gop.value_ptr.code_header = try self.addString(mir.c.code_header); | 216 | const code_header = try self.addString(mir.c.code_header); |
| | 217 | const code = try self.addString(mir.c.code); |
| | 218 | gop.value_ptr.code = code_header.concat(code); |
| 211 | try self.addUavsFromCodegen(&mir.c.uavs); | 219 | try self.addUavsFromCodegen(&mir.c.uavs); |
| 212 | } | 220 | } |
| 213 | | 221 | |