| ... | @@ -139,6 +139,17 @@ pub fn BitcodeWriter(comptime types: []const type) type { | ... | @@ -139,6 +139,17 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 139 | try self.writeBits(charTo6Bit(c), 6); | 139 | try self.writeBits(charTo6Bit(c), 6); |
| 140 | } | 140 | } |
| 141 | | 141 | |
| | 142 | pub fn writeBlob(self: *BcWriter, blob: []const u8) Error!void { |
| | 143 | const blob_word_size = std.mem.alignForward(usize, blob.len, 4); |
| | 144 | try self.buffer.ensureUnusedCapacity(blob_word_size + 1); |
| | 145 | self.alignTo32() catch unreachable; |
| | 146 | |
| | 147 | const slice = self.buffer.addManyAsSliceAssumeCapacity(blob_word_size / 4); |
| | 148 | const slice_bytes = std.mem.sliceAsBytes(slice); |
| | 149 | @memcpy(slice_bytes[0..blob.len], blob); |
| | 150 | @memset(slice_bytes[blob.len..], 0); |
| | 151 | } |
| | 152 | |
| 142 | pub fn alignTo32(self: *BcWriter) Error!void { | 153 | pub fn alignTo32(self: *BcWriter) Error!void { |
| 143 | if (self.bit_count == 0) return; | 154 | if (self.bit_count == 0) return; |
| 144 | | 155 | |
| ... | @@ -256,11 +267,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { | ... | @@ -256,11 +267,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 256 | .char6 => try self.bitcode.write6BitChar(adapter.get(param, field_name)), | 267 | .char6 => try self.bitcode.write6BitChar(adapter.get(param, field_name)), |
| 257 | .blob => { | 268 | .blob => { |
| 258 | try self.bitcode.writeVBR(param.len, 6); | 269 | try self.bitcode.writeVBR(param.len, 6); |
| 259 | try self.bitcode.alignTo32(); | 270 | try self.bitcode.writeBlob(param); |
| 260 | for (param) |x| { | | |
| 261 | try self.bitcode.writeBits(x, 8); | | |
| 262 | } | | |
| 263 | try self.bitcode.alignTo32(); | | |
| 264 | }, | 271 | }, |
| 265 | .array_fixed => |len| { | 272 | .array_fixed => |len| { |
| 266 | try self.bitcode.writeVBR(param.len, 6); | 273 | try self.bitcode.writeVBR(param.len, 6); |