diff --git a/bootstrap/compiler.zig b/bootstrap/compiler.zig index 627b304..1b7118d 100644 --- a/bootstrap/compiler.zig +++ b/bootstrap/compiler.zig @@ -1062,6 +1062,18 @@ const Bitcode = struct { function = 12, identification = 13, value_symtab = 14, + metadata = 15, + metadata_attachment = 16, + type = 17, + uselist = 18, + module_strtab = 19, + global_value_summary = 20, + operand_bundle_tags = 21, + metadata_kind = 22, + strtab = 23, + full_lto_global_value_summary = 24, + symtab = 25, + sync_scope_names = 26, }; const ValueSymtabAbbreviationId = enum(u8){ @@ -1279,6 +1291,35 @@ const Bitcode = struct { block_addr_users = 60, }; + const TypeCode = enum(u8) { + num_entry = 1, + void = 2, + float = 3, + double = 4, + label = 5, + @"opaque" = 6, + integer = 7, + pointer = 8, + function_old = 9, + half = 10, + array = 11, + vector = 12, + x86_fp80 = 13, + fp128 = 14, + ppc_fp128 = 15, + metadata = 16, + x86_mmx = 17, + struct_anon = 18, + struct_name = 19, + struct_named = 20, + function = 21, + token = 22, + bfloat = 23, + x86_amx = 24, + opaque_pointer = 25, + target_type = 26, + }; + const BlockInfoCode = enum(u8) { set_bid = 1, block_name = 2, @@ -1300,6 +1341,7 @@ const Bitcode = struct { current_abbreviations: PinnedArray(*Abbreviation) = .{}, abbreviation_buffer: PinnedArray(Abbreviation) = .{}, block_info_records: PinnedArray(BlockInfo) = .{}, + vst_offset_placeholder: u64 = 0, current_bit: u32 = 0, current_value: u32 = 0, current_codesize: u32 = 2, @@ -1312,522 +1354,566 @@ const Bitcode = struct { return final_slice; } - pub fn write(writer: *Writer) void { - const magic align(4) = [_]u8{ 0x42, 0x43, 0xc0, 0xde }; - writer.append_bytes(&magic); + // TODO: fix? + fn get_byte_position(writer: *Writer) u32 { + return writer.buffer.length * @sizeOf(u32); + } - writer.write_identification_block(); - const identification_block = .{ - 0x35, 0x14, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x62, 0x0c, 0x30, 0x24, - 0x4a, 0x59, 0xbe, 0x66, - 0xbd, 0xfb, 0xb4, 0xaf, - 0x0b, 0x51, 0x80, 0x4c, - 0x01, 0x00, 0x00, 0x00, - }; - std.testing.expectEqualSlices(u8, &identification_block, writer.get_byte_slice()[4..]) catch unreachable; - const module_version_start = writer.buffer.length; - _ = module_version_start; // autofix - writer.enter_subblock(.identification, 3); + fn write_module_block(writer: *Writer) void { + const raw = true; + if (raw) { + const module_block align(4) = [_]u8{ + 0x21, 0x0c, 0x00, 0x00, + 0xe6, 0x01, 0x00, 0x00, + 0x0b, 0x02, 0x21, 0x00, + 0x02, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, + 0x07, 0x81, 0x23, 0x91, + 0x41, 0xc8, 0x04, 0x49, + 0x06, 0x10, 0x32, 0x39, + 0x92, 0x01, 0x84, 0x0c, + 0x25, 0x05, 0x08, 0x19, + 0x1e, 0x04, 0x8b, 0x62, + 0x80, 0x0c, 0x45, 0x02, + 0x42, 0x92, 0x0b, 0x42, + 0x64, 0x10, 0x32, 0x14, + 0x38, 0x08, 0x18, 0x4b, + 0x0a, 0x32, 0x32, 0x88, + 0x48, 0x70, 0xc4, 0x21, + 0x23, 0x44, 0x12, 0x87, + 0x8c, 0x10, 0x41, 0x92, + 0x02, 0x64, 0xc8, 0x08, + 0xb1, 0x14, 0x20, 0x43, + 0x46, 0x88, 0x20, 0xc9, + 0x01, 0x32, 0x32, 0x84, + 0x18, 0x2a, 0x28, 0x2a, + 0x90, 0x31, 0x7c, 0xb0, + 0x5c, 0x91, 0x20, 0xc3, + 0xc8, 0x00, 0x00, 0x00, + 0x89, 0x20, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, + 0x22, 0x66, 0x04, 0x10, + 0xb2, 0x42, 0x82, 0xc9, + 0x10, 0x52, 0x42, 0x82, + 0xc9, 0x90, 0x71, 0xc2, + 0x50, 0x48, 0x0a, 0x09, + 0x26, 0x43, 0xc6, 0x05, + 0x42, 0x32, 0x26, 0x08, + 0x0a, 0x9a, 0x23, 0x00, + 0x83, 0x32, 0x24, 0x18, + 0x08, 0x18, 0x01, 0x00, + 0x51, 0x18, 0x00, 0x00, + 0x4c, 0x00, 0x00, 0x00, + 0x1b, 0x58, 0x23, 0xf8, + 0xff, 0xff, 0xff, 0xff, + 0x01, 0x70, 0x00, 0x09, + 0x28, 0x03, 0x80, 0x0b, + 0xc2, 0x40, 0x20, 0xcc, + 0x41, 0x1e, 0xc2, 0xa1, + 0x1d, 0xca, 0xa1, 0x0d, + 0xe0, 0xe1, 0x1d, 0xd2, + 0xc1, 0x1d, 0xe8, 0xa1, + 0x1c, 0xe4, 0x01, 0x08, + 0x07, 0x76, 0x60, 0x07, + 0x80, 0x68, 0x87, 0x74, + 0x70, 0x87, 0x36, 0x60, + 0x87, 0x72, 0x38, 0x87, + 0x70, 0x60, 0x87, 0x36, + 0xb0, 0x87, 0x72, 0x18, + 0x07, 0x7a, 0x78, 0x07, + 0x79, 0x68, 0x83, 0x7b, + 0x48, 0x07, 0x72, 0xa0, + 0x07, 0x74, 0x00, 0xe0, + 0x00, 0x20, 0xdc, 0xe1, + 0x1d, 0xda, 0x80, 0x1e, + 0xe4, 0x21, 0x1c, 0xe0, + 0x01, 0x1e, 0xd2, 0xc1, + 0x1d, 0xce, 0xa1, 0x0d, + 0xda, 0x21, 0x1c, 0xe8, + 0x01, 0x1d, 0x00, 0x7a, + 0x90, 0x87, 0x7a, 0x28, + 0x07, 0x80, 0x98, 0x07, + 0x7a, 0x08, 0x87, 0x71, + 0x58, 0x87, 0x36, 0x80, + 0x07, 0x79, 0x78, 0x07, + 0x7a, 0x28, 0x87, 0x71, + 0xa0, 0x87, 0x77, 0x90, + 0x87, 0x36, 0x10, 0x87, + 0x7a, 0x30, 0x07, 0x73, + 0x28, 0x07, 0x79, 0x68, + 0x83, 0x79, 0x48, 0x07, + 0x7d, 0x28, 0x07, 0x00, + 0x0f, 0x00, 0x82, 0x1e, + 0xc2, 0x41, 0x1e, 0xce, + 0xa1, 0x1c, 0xe8, 0xa1, + 0x0d, 0xc6, 0x01, 0x1e, + 0xea, 0x01, 0xc0, 0x07, + 0x3c, 0xb0, 0x83, 0x36, + 0xb0, 0x03, 0x3a, 0x00, + 0x08, 0x7a, 0x08, 0x07, + 0x79, 0x38, 0x87, 0x72, + 0xa0, 0x87, 0x36, 0x30, + 0x87, 0x72, 0x08, 0x07, + 0x7a, 0xa8, 0x07, 0x79, + 0x28, 0x87, 0x79, 0x00, + 0xd6, 0x60, 0x1c, 0xda, + 0xe1, 0x1d, 0xec, 0x81, + 0x0d, 0xd6, 0x60, 0x1c, + 0xf0, 0x01, 0x0f, 0xd8, + 0x60, 0x0d, 0xcc, 0x01, + 0x1f, 0xe6, 0x41, 0x1e, + 0xd8, 0x60, 0x0d, 0xda, + 0xa1, 0x1d, 0xf0, 0x81, + 0x0d, 0xd6, 0x60, 0x1e, + 0xe6, 0xa1, 0x1c, 0xd8, + 0x60, 0x0d, 0xe6, 0x61, + 0x1e, 0xca, 0x41, 0x0e, + 0xd8, 0x60, 0x0d, 0xf0, + 0x01, 0x0f, 0xee, 0x00, + 0x20, 0xe8, 0xa1, 0x1e, + 0xdc, 0xa1, 0x1c, 0xda, + 0x60, 0x1c, 0xe0, 0xa1, + 0x1e, 0x80, 0x73, 0x28, + 0x07, 0x77, 0x28, 0x07, + 0x79, 0x48, 0x87, 0x71, + 0x00, 0x36, 0x10, 0x42, + 0x00, 0x90, 0xc2, 0x06, + 0x62, 0x10, 0x00, 0x52, + 0x00, 0x00, 0x00, 0x00, + 0x49, 0x18, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, + 0x13, 0x86, 0x40, 0x18, + 0x00, 0x00, 0x00, 0x00, + 0x13, 0x26, 0x7c, 0xc0, + 0x03, 0x3b, 0xf8, 0x05, + 0x3b, 0xa0, 0x83, 0x36, + 0x80, 0x87, 0x71, 0x68, + 0x03, 0x76, 0x48, 0x07, + 0x77, 0xa8, 0x07, 0x7c, + 0x68, 0x83, 0x73, 0x70, + 0x87, 0x7a, 0xd8, 0x60, + 0x0a, 0xe5, 0xd0, 0x06, + 0xed, 0xa0, 0x07, 0xe5, + 0xd0, 0x06, 0xf0, 0x20, + 0x07, 0x77, 0x00, 0x07, + 0x7a, 0x30, 0x07, 0x72, + 0xa0, 0x07, 0x73, 0x20, + 0x07, 0x6d, 0x00, 0x0f, + 0x72, 0x70, 0x07, 0x71, + 0xa0, 0x07, 0x73, 0x20, + 0x07, 0x7a, 0x30, 0x07, + 0x72, 0xd0, 0x06, 0xf0, + 0x20, 0x07, 0x77, 0x20, + 0x07, 0x7a, 0x60, 0x07, + 0x74, 0xa0, 0x07, 0x76, + 0x40, 0x07, 0x6d, 0x90, + 0x0e, 0x76, 0x40, 0x07, + 0x7a, 0x60, 0x07, 0x74, + 0xd0, 0x06, 0xe6, 0x80, + 0x07, 0x70, 0xa0, 0x07, + 0x71, 0x20, 0x07, 0x78, + 0xd0, 0x06, 0xee, 0x80, + 0x07, 0x7a, 0x10, 0x07, + 0x76, 0xa0, 0x07, 0x73, + 0x20, 0x07, 0x7a, 0x60, + 0x07, 0x74, 0xd0, 0x06, + 0xb3, 0x10, 0x07, 0x72, + 0x80, 0x07, 0x1a, 0x21, + 0x4c, 0x0e, 0x13, 0x36, + 0xdb, 0xde, 0x6e, 0xb1, + 0xd3, 0xee, 0xf5, 0x90, + 0x0a, 0x20, 0x04, 0x00, + 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x02, + 0x90, 0xd8, 0x20, 0x50, + 0x54, 0x3d, 0x00, 0x00, + 0x20, 0x0b, 0x04, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x32, 0x1e, 0x98, 0x0c, + 0x19, 0x11, 0x4c, 0x90, + 0x8c, 0x09, 0x26, 0x47, + 0xc6, 0x04, 0x43, 0x4a, + 0x09, 0x14, 0x42, 0x41, + 0x14, 0x41, 0x39, 0x00, + 0xb1, 0x18, 0x00, 0x00, + 0xb9, 0x00, 0x00, 0x00, + 0x33, 0x08, 0x80, 0x1c, + 0xc4, 0xe1, 0x1c, 0x66, + 0x14, 0x01, 0x3d, 0x88, + 0x43, 0x38, 0x84, 0xc3, + 0x8c, 0x42, 0x80, 0x07, + 0x79, 0x78, 0x07, 0x73, + 0x98, 0x71, 0x0c, 0xe6, + 0x00, 0x0f, 0xed, 0x10, + 0x0e, 0xf4, 0x80, 0x0e, + 0x33, 0x0c, 0x42, 0x1e, + 0xc2, 0xc1, 0x1d, 0xce, + 0xa1, 0x1c, 0x66, 0x30, + 0x05, 0x3d, 0x88, 0x43, + 0x38, 0x84, 0x83, 0x1b, + 0xcc, 0x03, 0x3d, 0xc8, + 0x43, 0x3d, 0x8c, 0x03, + 0x3d, 0xcc, 0x78, 0x8c, + 0x74, 0x70, 0x07, 0x7b, + 0x08, 0x07, 0x79, 0x48, + 0x87, 0x70, 0x70, 0x07, + 0x7a, 0x70, 0x03, 0x76, + 0x78, 0x87, 0x70, 0x20, + 0x87, 0x19, 0xcc, 0x11, + 0x0e, 0xec, 0x90, 0x0e, + 0xe1, 0x30, 0x0f, 0x6e, + 0x30, 0x0f, 0xe3, 0xf0, + 0x0e, 0xf0, 0x50, 0x0e, + 0x33, 0x10, 0xc4, 0x1d, + 0xde, 0x21, 0x1c, 0xd8, + 0x21, 0x1d, 0xc2, 0x61, + 0x1e, 0x66, 0x30, 0x89, + 0x3b, 0xbc, 0x83, 0x3b, + 0xd0, 0x43, 0x39, 0xb4, + 0x03, 0x3c, 0xbc, 0x83, + 0x3c, 0x84, 0x03, 0x3b, + 0xcc, 0xf0, 0x14, 0x76, + 0x60, 0x07, 0x7b, 0x68, + 0x07, 0x37, 0x68, 0x87, + 0x72, 0x68, 0x07, 0x37, + 0x80, 0x87, 0x70, 0x90, + 0x87, 0x70, 0x60, 0x07, + 0x76, 0x28, 0x07, 0x76, + 0xf8, 0x05, 0x76, 0x78, + 0x87, 0x77, 0x80, 0x87, + 0x5f, 0x08, 0x87, 0x71, + 0x18, 0x87, 0x72, 0x98, + 0x87, 0x79, 0x98, 0x81, + 0x2c, 0xee, 0xf0, 0x0e, + 0xee, 0xe0, 0x0e, 0xf5, + 0xc0, 0x0e, 0xec, 0x30, + 0x03, 0x62, 0xc8, 0xa1, + 0x1c, 0xe4, 0xa1, 0x1c, + 0xcc, 0xa1, 0x1c, 0xe4, + 0xa1, 0x1c, 0xdc, 0x61, + 0x1c, 0xca, 0x21, 0x1c, + 0xc4, 0x81, 0x1d, 0xca, + 0x61, 0x06, 0xd6, 0x90, + 0x43, 0x39, 0xc8, 0x43, + 0x39, 0x98, 0x43, 0x39, + 0xc8, 0x43, 0x39, 0xb8, + 0xc3, 0x38, 0x94, 0x43, + 0x38, 0x88, 0x03, 0x3b, + 0x94, 0xc3, 0x2f, 0xbc, + 0x83, 0x3c, 0xfc, 0x82, + 0x3b, 0xd4, 0x03, 0x3b, + 0xb0, 0xc3, 0x0c, 0xc7, + 0x69, 0x87, 0x70, 0x58, + 0x87, 0x72, 0x70, 0x83, + 0x74, 0x68, 0x07, 0x78, + 0x60, 0x87, 0x74, 0x18, + 0x87, 0x74, 0xa0, 0x87, + 0x19, 0xce, 0x53, 0x0f, + 0xee, 0x00, 0x0f, 0xf2, + 0x50, 0x0e, 0xe4, 0x90, + 0x0e, 0xe3, 0x40, 0x0f, + 0xe1, 0x20, 0x0e, 0xec, + 0x50, 0x0e, 0x33, 0x20, + 0x28, 0x1d, 0xdc, 0xc1, + 0x1e, 0xc2, 0x41, 0x1e, + 0xd2, 0x21, 0x1c, 0xdc, + 0x81, 0x1e, 0xdc, 0xe0, + 0x1c, 0xe4, 0xe1, 0x1d, + 0xea, 0x01, 0x1e, 0x66, + 0x18, 0x51, 0x38, 0xb0, + 0x43, 0x3a, 0x9c, 0x83, + 0x3b, 0xcc, 0x50, 0x24, + 0x76, 0x60, 0x07, 0x7b, + 0x68, 0x07, 0x37, 0x60, + 0x87, 0x77, 0x78, 0x07, + 0x78, 0x98, 0x51, 0x4c, + 0xf4, 0x90, 0x0f, 0xf0, + 0x50, 0x0e, 0x33, 0x1e, + 0x6a, 0x1e, 0xca, 0x61, + 0x1c, 0xe8, 0x21, 0x1d, + 0xde, 0xc1, 0x1d, 0x7e, + 0x01, 0x1e, 0xe4, 0xa1, + 0x1c, 0xcc, 0x21, 0x1d, + 0xf0, 0x61, 0x06, 0x54, + 0x85, 0x83, 0x38, 0xcc, + 0xc3, 0x3b, 0xb0, 0x43, + 0x3d, 0xd0, 0x43, 0x39, + 0xfc, 0xc2, 0x3c, 0xe4, + 0x43, 0x3b, 0x88, 0xc3, + 0x3b, 0xb0, 0xc3, 0x8c, + 0xc5, 0x0a, 0x87, 0x79, + 0x98, 0x87, 0x77, 0x18, + 0x87, 0x74, 0x08, 0x07, + 0x7a, 0x28, 0x07, 0x72, + 0x98, 0x81, 0x5c, 0xe3, + 0x10, 0x0e, 0xec, 0xc0, + 0x0e, 0xe5, 0x50, 0x0e, + 0xf3, 0x30, 0x23, 0xc1, + 0xd2, 0x41, 0x1e, 0xe4, + 0xe1, 0x17, 0xd8, 0xe1, + 0x1d, 0xde, 0x01, 0x1e, + 0x66, 0x48, 0x19, 0x3b, + 0xb0, 0x83, 0x3d, 0xb4, + 0x83, 0x1b, 0x84, 0xc3, + 0x38, 0x8c, 0x43, 0x39, + 0xcc, 0xc3, 0x3c, 0xb8, + 0xc1, 0x39, 0xc8, 0xc3, + 0x3b, 0xd4, 0x03, 0x3c, + 0xcc, 0x48, 0xb4, 0x71, + 0x08, 0x07, 0x76, 0x60, + 0x07, 0x71, 0x08, 0x87, + 0x71, 0x58, 0x87, 0x19, + 0xdb, 0xc6, 0x0e, 0xec, + 0x60, 0x0f, 0xed, 0xe0, + 0x06, 0xf0, 0x20, 0x0f, + 0xe5, 0x30, 0x0f, 0xe5, + 0x20, 0x0f, 0xf6, 0x50, + 0x0e, 0x6e, 0x10, 0x0e, + 0xe3, 0x30, 0x0e, 0xe5, + 0x30, 0x0f, 0xf3, 0xe0, + 0x06, 0xe9, 0xe0, 0x0e, + 0xe4, 0x50, 0x0e, 0xf8, + 0x30, 0x23, 0xe2, 0xec, + 0x61, 0x1c, 0xc2, 0x81, + 0x1d, 0xd8, 0xe1, 0x17, + 0xec, 0x21, 0x1d, 0xe6, + 0x21, 0x1d, 0xc4, 0x21, + 0x1d, 0xd8, 0x21, 0x1d, + 0xe8, 0x21, 0x1f, 0x66, + 0x20, 0x9d, 0x3b, 0xbc, + 0x43, 0x3d, 0xb8, 0x03, + 0x39, 0x94, 0x83, 0x39, + 0xcc, 0x58, 0xbc, 0x70, + 0x70, 0x07, 0x77, 0x78, + 0x07, 0x7a, 0x08, 0x07, + 0x7a, 0x48, 0x87, 0x77, + 0x70, 0x87, 0x19, 0xcb, + 0xe7, 0x0e, 0xef, 0x30, + 0x0f, 0xe1, 0xe0, 0x0e, + 0xe9, 0x40, 0x0f, 0xe9, + 0xa0, 0x0f, 0xe5, 0x30, + 0xc3, 0x01, 0x03, 0x73, + 0xa8, 0x07, 0x77, 0x18, + 0x87, 0x5f, 0x98, 0x87, + 0x70, 0x70, 0x87, 0x74, + 0xa0, 0x87, 0x74, 0xd0, + 0x87, 0x72, 0x98, 0x81, + 0x84, 0x41, 0x39, 0xe0, + 0xc3, 0x38, 0xb0, 0x43, + 0x3d, 0x90, 0x43, 0x39, + 0xcc, 0x40, 0xc4, 0xa0, + 0x1d, 0xca, 0xa1, 0x1d, + 0xe0, 0x41, 0x1e, 0xde, + 0xc1, 0x1c, 0x66, 0x24, + 0x63, 0x30, 0x0e, 0xe1, + 0xc0, 0x0e, 0xec, 0x30, + 0x0f, 0xe9, 0x40, 0x0f, + 0xe5, 0x30, 0x43, 0x21, + 0x83, 0x75, 0x18, 0x07, + 0x73, 0x48, 0x87, 0x5f, + 0xa0, 0x87, 0x7c, 0x80, + 0x87, 0x72, 0x98, 0xb1, + 0x94, 0x01, 0x3c, 0x8c, + 0xc3, 0x3c, 0x94, 0xc3, + 0x38, 0xd0, 0x43, 0x3a, + 0xbc, 0x83, 0x3b, 0xcc, + 0xc3, 0x8c, 0xc5, 0x0c, + 0x48, 0x21, 0x15, 0x42, + 0x61, 0x1e, 0xe6, 0x21, + 0x1d, 0xce, 0xc1, 0x1d, + 0x52, 0x81, 0x14, 0x00, + 0x79, 0x20, 0x00, 0x00, + 0x31, 0x00, 0x00, 0x00, + 0x72, 0x1e, 0x48, 0x20, + 0x43, 0x88, 0x0c, 0x19, + 0x09, 0x72, 0x32, 0x48, + 0x20, 0x23, 0x81, 0x8c, + 0x91, 0x91, 0xd1, 0x44, + 0xa0, 0x10, 0x28, 0x64, + 0x3c, 0x31, 0x32, 0x42, + 0x8e, 0x90, 0x21, 0xa3, + 0x68, 0x20, 0xac, 0x00, + 0x94, 0x92, 0x24, 0x47, + 0x03, 0x00, 0x00, 0x00, + 0x63, 0x6c, 0x61, 0x6e, + 0x67, 0x20, 0x76, 0x65, + 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x20, 0x31, 0x37, + 0x2e, 0x30, 0x2e, 0x36, + 0x77, 0x63, 0x68, 0x61, + 0x72, 0x5f, 0x73, 0x69, + 0x7a, 0x65, 0x50, 0x49, + 0x43, 0x20, 0x4c, 0x65, + 0x76, 0x65, 0x6c, 0x50, + 0x49, 0x45, 0x20, 0x4c, + 0x65, 0x76, 0x65, 0x6c, + 0x75, 0x77, 0x74, 0x61, + 0x62, 0x6c, 0x65, 0x66, + 0x72, 0x61, 0x6d, 0x65, + 0x2d, 0x70, 0x6f, 0x69, + 0x6e, 0x74, 0x65, 0x72, + 0x23, 0x08, 0x41, 0x30, + 0x82, 0x10, 0x08, 0x23, + 0x08, 0xc1, 0x30, 0x82, + 0x10, 0x10, 0x23, 0x08, + 0x41, 0x31, 0x43, 0x10, + 0xcc, 0x30, 0x1c, 0x02, + 0x32, 0xc3, 0x90, 0x0c, + 0xca, 0x0c, 0xc3, 0x42, + 0x28, 0x33, 0x0c, 0x4b, + 0xa1, 0xcc, 0x30, 0x2c, + 0x86, 0x22, 0x23, 0x81, + 0x09, 0x4a, 0x85, 0x8d, + 0xcd, 0xae, 0xcd, 0x25, + 0x8d, 0xac, 0xcc, 0x8d, + 0x6e, 0x94, 0x60, 0xc9, + 0x88, 0x8d, 0xcd, 0xae, + 0xcd, 0xa5, 0xed, 0x8d, + 0xac, 0x8e, 0xad, 0xcc, + 0xc5, 0x8c, 0x2d, 0xec, + 0x6c, 0x6e, 0x94, 0x82, + 0x69, 0x9c, 0x07, 0x02, + 0xa9, 0x18, 0x00, 0x00, + 0x2d, 0x00, 0x00, 0x00, + 0x0b, 0x0a, 0x72, 0x28, + 0x87, 0x77, 0x80, 0x07, + 0x7a, 0x58, 0x70, 0x98, + 0x43, 0x3d, 0xb8, 0xc3, + 0x38, 0xb0, 0x43, 0x39, + 0xd0, 0xc3, 0x82, 0xe6, + 0x1c, 0xc6, 0xa1, 0x0d, + 0xe8, 0x41, 0x1e, 0xc2, + 0xc1, 0x1d, 0xe6, 0x21, + 0x1d, 0xe8, 0x21, 0x1d, + 0xde, 0xc1, 0x1d, 0x16, + 0x34, 0xe3, 0x60, 0x0e, + 0xe7, 0x50, 0x0f, 0xe1, + 0x20, 0x0f, 0xe4, 0x40, + 0x0f, 0xe1, 0x20, 0x0f, + 0xe7, 0x50, 0x0e, 0xf4, + 0xb0, 0x80, 0x81, 0x07, + 0x79, 0x28, 0x87, 0x70, + 0x60, 0x07, 0x76, 0x78, + 0x87, 0x71, 0x08, 0x07, + 0x7a, 0x28, 0x07, 0x72, + 0x58, 0x70, 0x9c, 0xc3, + 0x38, 0xb4, 0x01, 0x3b, + 0xa4, 0x83, 0x3d, 0x94, + 0xc3, 0x02, 0x6b, 0x1c, + 0xd8, 0x21, 0x1c, 0xdc, + 0xe1, 0x1c, 0xdc, 0x20, + 0x1c, 0xe4, 0x61, 0x1c, + 0xdc, 0x20, 0x1c, 0xe8, + 0x81, 0x1e, 0xc2, 0x61, + 0x1c, 0xd0, 0xa1, 0x1c, + 0xc8, 0x61, 0x1c, 0xc2, + 0x81, 0x1d, 0xd8, 0x61, + 0xc1, 0x01, 0x0f, 0xf4, + 0x20, 0x0f, 0xe1, 0x50, + 0x0f, 0xf4, 0x80, 0x0e, + 0x0b, 0x88, 0x75, 0x18, + 0x07, 0x73, 0x48, 0x87, + 0x05, 0xcf, 0x38, 0xbc, + 0x83, 0x3b, 0xd8, 0x43, + 0x39, 0xc8, 0xc3, 0x39, + 0x94, 0x83, 0x3b, 0x8c, + 0x43, 0x39, 0x8c, 0x03, + 0x3d, 0xc8, 0x03, 0x3b, + 0x00, 0x00, 0x00, 0x00, + 0xd1, 0x10, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x07, 0xcc, 0x3c, 0xa4, + 0x83, 0x3b, 0x9c, 0x03, + 0x3b, 0x94, 0x03, 0x3d, + 0xa0, 0x83, 0x3c, 0x94, + 0x43, 0x38, 0x90, 0xc3, + 0x01, 0x00, 0x00, 0x00, + 0x61, 0x20, 0x00, 0x00, + 0x0e, 0x00, 0x00, 0x00, + 0x13, 0x04, 0x41, 0x2c, + 0x10, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, + 0x94, 0x11, 0x00, 0x00, + 0x33, 0x11, 0x41, 0x10, + 0x8c, 0xc2, 0x4c, 0x44, + 0x10, 0x04, 0xa3, 0x30, + 0x13, 0x01, 0x04, 0x01, + 0x29, 0x0c, 0x1b, 0x10, + 0x03, 0x31, 0x00, 0xc3, + 0x06, 0x84, 0x60, 0x0c, + 0xc0, 0xb0, 0x01, 0x11, + 0x14, 0x04, 0xb0, 0x04, + 0x00, 0x00, 0x00, 0x00, + 0x71, 0x20, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, + 0x32, 0x0e, 0x10, 0x22, + 0x84, 0x00, 0xda, 0x03, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; + writer.append_bytes(&module_block); + } else { + const module_version_start = writer.buffer.length; + _ = module_version_start; // autofix + writer.enter_subblock(.identification, 3); + const block_start_position = writer.get_byte_position(); + _ = block_start_position; // autofix - writer.write_module_version(); + writer.write_module_version(); - writer.write_block_info(); + writer.write_block_info(); + writer.write_type_table(); - const rest_module_block align(4) = [_]u8{ - 0x21, 0x0c, 0x00, 0x00, - 0xe6, 0x01, 0x00, 0x00, - 0x0b, 0x02, 0x21, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x16, 0x00, 0x00, 0x00, - 0x07, 0x81, 0x23, 0x91, - 0x41, 0xc8, 0x04, 0x49, - 0x06, 0x10, 0x32, 0x39, - 0x92, 0x01, 0x84, 0x0c, - 0x25, 0x05, 0x08, 0x19, - 0x1e, 0x04, 0x8b, 0x62, - 0x80, 0x0c, 0x45, 0x02, - 0x42, 0x92, 0x0b, 0x42, - 0x64, 0x10, 0x32, 0x14, - 0x38, 0x08, 0x18, 0x4b, - 0x0a, 0x32, 0x32, 0x88, - 0x48, 0x70, 0xc4, 0x21, - 0x23, 0x44, 0x12, 0x87, - 0x8c, 0x10, 0x41, 0x92, - 0x02, 0x64, 0xc8, 0x08, - 0xb1, 0x14, 0x20, 0x43, - 0x46, 0x88, 0x20, 0xc9, - 0x01, 0x32, 0x32, 0x84, - 0x18, 0x2a, 0x28, 0x2a, - 0x90, 0x31, 0x7c, 0xb0, - 0x5c, 0x91, 0x20, 0xc3, - 0xc8, 0x00, 0x00, 0x00, - 0x89, 0x20, 0x00, 0x00, - 0x0a, 0x00, 0x00, 0x00, - 0x22, 0x66, 0x04, 0x10, - 0xb2, 0x42, 0x82, 0xc9, - 0x10, 0x52, 0x42, 0x82, - 0xc9, 0x90, 0x71, 0xc2, - 0x50, 0x48, 0x0a, 0x09, - 0x26, 0x43, 0xc6, 0x05, - 0x42, 0x32, 0x26, 0x08, - 0x0a, 0x9a, 0x23, 0x00, - 0x83, 0x32, 0x24, 0x18, - 0x08, 0x18, 0x01, 0x00, - 0x51, 0x18, 0x00, 0x00, - 0x4c, 0x00, 0x00, 0x00, - 0x1b, 0x58, 0x23, 0xf8, - 0xff, 0xff, 0xff, 0xff, - 0x01, 0x70, 0x00, 0x09, - 0x28, 0x03, 0x80, 0x0b, - 0xc2, 0x40, 0x20, 0xcc, - 0x41, 0x1e, 0xc2, 0xa1, - 0x1d, 0xca, 0xa1, 0x0d, - 0xe0, 0xe1, 0x1d, 0xd2, - 0xc1, 0x1d, 0xe8, 0xa1, - 0x1c, 0xe4, 0x01, 0x08, - 0x07, 0x76, 0x60, 0x07, - 0x80, 0x68, 0x87, 0x74, - 0x70, 0x87, 0x36, 0x60, - 0x87, 0x72, 0x38, 0x87, - 0x70, 0x60, 0x87, 0x36, - 0xb0, 0x87, 0x72, 0x18, - 0x07, 0x7a, 0x78, 0x07, - 0x79, 0x68, 0x83, 0x7b, - 0x48, 0x07, 0x72, 0xa0, - 0x07, 0x74, 0x00, 0xe0, - 0x00, 0x20, 0xdc, 0xe1, - 0x1d, 0xda, 0x80, 0x1e, - 0xe4, 0x21, 0x1c, 0xe0, - 0x01, 0x1e, 0xd2, 0xc1, - 0x1d, 0xce, 0xa1, 0x0d, - 0xda, 0x21, 0x1c, 0xe8, - 0x01, 0x1d, 0x00, 0x7a, - 0x90, 0x87, 0x7a, 0x28, - 0x07, 0x80, 0x98, 0x07, - 0x7a, 0x08, 0x87, 0x71, - 0x58, 0x87, 0x36, 0x80, - 0x07, 0x79, 0x78, 0x07, - 0x7a, 0x28, 0x87, 0x71, - 0xa0, 0x87, 0x77, 0x90, - 0x87, 0x36, 0x10, 0x87, - 0x7a, 0x30, 0x07, 0x73, - 0x28, 0x07, 0x79, 0x68, - 0x83, 0x79, 0x48, 0x07, - 0x7d, 0x28, 0x07, 0x00, - 0x0f, 0x00, 0x82, 0x1e, - 0xc2, 0x41, 0x1e, 0xce, - 0xa1, 0x1c, 0xe8, 0xa1, - 0x0d, 0xc6, 0x01, 0x1e, - 0xea, 0x01, 0xc0, 0x07, - 0x3c, 0xb0, 0x83, 0x36, - 0xb0, 0x03, 0x3a, 0x00, - 0x08, 0x7a, 0x08, 0x07, - 0x79, 0x38, 0x87, 0x72, - 0xa0, 0x87, 0x36, 0x30, - 0x87, 0x72, 0x08, 0x07, - 0x7a, 0xa8, 0x07, 0x79, - 0x28, 0x87, 0x79, 0x00, - 0xd6, 0x60, 0x1c, 0xda, - 0xe1, 0x1d, 0xec, 0x81, - 0x0d, 0xd6, 0x60, 0x1c, - 0xf0, 0x01, 0x0f, 0xd8, - 0x60, 0x0d, 0xcc, 0x01, - 0x1f, 0xe6, 0x41, 0x1e, - 0xd8, 0x60, 0x0d, 0xda, - 0xa1, 0x1d, 0xf0, 0x81, - 0x0d, 0xd6, 0x60, 0x1e, - 0xe6, 0xa1, 0x1c, 0xd8, - 0x60, 0x0d, 0xe6, 0x61, - 0x1e, 0xca, 0x41, 0x0e, - 0xd8, 0x60, 0x0d, 0xf0, - 0x01, 0x0f, 0xee, 0x00, - 0x20, 0xe8, 0xa1, 0x1e, - 0xdc, 0xa1, 0x1c, 0xda, - 0x60, 0x1c, 0xe0, 0xa1, - 0x1e, 0x80, 0x73, 0x28, - 0x07, 0x77, 0x28, 0x07, - 0x79, 0x48, 0x87, 0x71, - 0x00, 0x36, 0x10, 0x42, - 0x00, 0x90, 0xc2, 0x06, - 0x62, 0x10, 0x00, 0x52, - 0x00, 0x00, 0x00, 0x00, - 0x49, 0x18, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x13, 0x86, 0x40, 0x18, - 0x00, 0x00, 0x00, 0x00, - 0x13, 0x26, 0x7c, 0xc0, - 0x03, 0x3b, 0xf8, 0x05, - 0x3b, 0xa0, 0x83, 0x36, - 0x80, 0x87, 0x71, 0x68, - 0x03, 0x76, 0x48, 0x07, - 0x77, 0xa8, 0x07, 0x7c, - 0x68, 0x83, 0x73, 0x70, - 0x87, 0x7a, 0xd8, 0x60, - 0x0a, 0xe5, 0xd0, 0x06, - 0xed, 0xa0, 0x07, 0xe5, - 0xd0, 0x06, 0xf0, 0x20, - 0x07, 0x77, 0x00, 0x07, - 0x7a, 0x30, 0x07, 0x72, - 0xa0, 0x07, 0x73, 0x20, - 0x07, 0x6d, 0x00, 0x0f, - 0x72, 0x70, 0x07, 0x71, - 0xa0, 0x07, 0x73, 0x20, - 0x07, 0x7a, 0x30, 0x07, - 0x72, 0xd0, 0x06, 0xf0, - 0x20, 0x07, 0x77, 0x20, - 0x07, 0x7a, 0x60, 0x07, - 0x74, 0xa0, 0x07, 0x76, - 0x40, 0x07, 0x6d, 0x90, - 0x0e, 0x76, 0x40, 0x07, - 0x7a, 0x60, 0x07, 0x74, - 0xd0, 0x06, 0xe6, 0x80, - 0x07, 0x70, 0xa0, 0x07, - 0x71, 0x20, 0x07, 0x78, - 0xd0, 0x06, 0xee, 0x80, - 0x07, 0x7a, 0x10, 0x07, - 0x76, 0xa0, 0x07, 0x73, - 0x20, 0x07, 0x7a, 0x60, - 0x07, 0x74, 0xd0, 0x06, - 0xb3, 0x10, 0x07, 0x72, - 0x80, 0x07, 0x1a, 0x21, - 0x4c, 0x0e, 0x13, 0x36, - 0xdb, 0xde, 0x6e, 0xb1, - 0xd3, 0xee, 0xf5, 0x90, - 0x0a, 0x20, 0x04, 0x00, - 0x00, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x08, 0x00, 0x02, - 0x90, 0xd8, 0x20, 0x50, - 0x54, 0x3d, 0x00, 0x00, - 0x20, 0x0b, 0x04, 0x00, - 0x06, 0x00, 0x00, 0x00, - 0x32, 0x1e, 0x98, 0x0c, - 0x19, 0x11, 0x4c, 0x90, - 0x8c, 0x09, 0x26, 0x47, - 0xc6, 0x04, 0x43, 0x4a, - 0x09, 0x14, 0x42, 0x41, - 0x14, 0x41, 0x39, 0x00, - 0xb1, 0x18, 0x00, 0x00, - 0xb9, 0x00, 0x00, 0x00, - 0x33, 0x08, 0x80, 0x1c, - 0xc4, 0xe1, 0x1c, 0x66, - 0x14, 0x01, 0x3d, 0x88, - 0x43, 0x38, 0x84, 0xc3, - 0x8c, 0x42, 0x80, 0x07, - 0x79, 0x78, 0x07, 0x73, - 0x98, 0x71, 0x0c, 0xe6, - 0x00, 0x0f, 0xed, 0x10, - 0x0e, 0xf4, 0x80, 0x0e, - 0x33, 0x0c, 0x42, 0x1e, - 0xc2, 0xc1, 0x1d, 0xce, - 0xa1, 0x1c, 0x66, 0x30, - 0x05, 0x3d, 0x88, 0x43, - 0x38, 0x84, 0x83, 0x1b, - 0xcc, 0x03, 0x3d, 0xc8, - 0x43, 0x3d, 0x8c, 0x03, - 0x3d, 0xcc, 0x78, 0x8c, - 0x74, 0x70, 0x07, 0x7b, - 0x08, 0x07, 0x79, 0x48, - 0x87, 0x70, 0x70, 0x07, - 0x7a, 0x70, 0x03, 0x76, - 0x78, 0x87, 0x70, 0x20, - 0x87, 0x19, 0xcc, 0x11, - 0x0e, 0xec, 0x90, 0x0e, - 0xe1, 0x30, 0x0f, 0x6e, - 0x30, 0x0f, 0xe3, 0xf0, - 0x0e, 0xf0, 0x50, 0x0e, - 0x33, 0x10, 0xc4, 0x1d, - 0xde, 0x21, 0x1c, 0xd8, - 0x21, 0x1d, 0xc2, 0x61, - 0x1e, 0x66, 0x30, 0x89, - 0x3b, 0xbc, 0x83, 0x3b, - 0xd0, 0x43, 0x39, 0xb4, - 0x03, 0x3c, 0xbc, 0x83, - 0x3c, 0x84, 0x03, 0x3b, - 0xcc, 0xf0, 0x14, 0x76, - 0x60, 0x07, 0x7b, 0x68, - 0x07, 0x37, 0x68, 0x87, - 0x72, 0x68, 0x07, 0x37, - 0x80, 0x87, 0x70, 0x90, - 0x87, 0x70, 0x60, 0x07, - 0x76, 0x28, 0x07, 0x76, - 0xf8, 0x05, 0x76, 0x78, - 0x87, 0x77, 0x80, 0x87, - 0x5f, 0x08, 0x87, 0x71, - 0x18, 0x87, 0x72, 0x98, - 0x87, 0x79, 0x98, 0x81, - 0x2c, 0xee, 0xf0, 0x0e, - 0xee, 0xe0, 0x0e, 0xf5, - 0xc0, 0x0e, 0xec, 0x30, - 0x03, 0x62, 0xc8, 0xa1, - 0x1c, 0xe4, 0xa1, 0x1c, - 0xcc, 0xa1, 0x1c, 0xe4, - 0xa1, 0x1c, 0xdc, 0x61, - 0x1c, 0xca, 0x21, 0x1c, - 0xc4, 0x81, 0x1d, 0xca, - 0x61, 0x06, 0xd6, 0x90, - 0x43, 0x39, 0xc8, 0x43, - 0x39, 0x98, 0x43, 0x39, - 0xc8, 0x43, 0x39, 0xb8, - 0xc3, 0x38, 0x94, 0x43, - 0x38, 0x88, 0x03, 0x3b, - 0x94, 0xc3, 0x2f, 0xbc, - 0x83, 0x3c, 0xfc, 0x82, - 0x3b, 0xd4, 0x03, 0x3b, - 0xb0, 0xc3, 0x0c, 0xc7, - 0x69, 0x87, 0x70, 0x58, - 0x87, 0x72, 0x70, 0x83, - 0x74, 0x68, 0x07, 0x78, - 0x60, 0x87, 0x74, 0x18, - 0x87, 0x74, 0xa0, 0x87, - 0x19, 0xce, 0x53, 0x0f, - 0xee, 0x00, 0x0f, 0xf2, - 0x50, 0x0e, 0xe4, 0x90, - 0x0e, 0xe3, 0x40, 0x0f, - 0xe1, 0x20, 0x0e, 0xec, - 0x50, 0x0e, 0x33, 0x20, - 0x28, 0x1d, 0xdc, 0xc1, - 0x1e, 0xc2, 0x41, 0x1e, - 0xd2, 0x21, 0x1c, 0xdc, - 0x81, 0x1e, 0xdc, 0xe0, - 0x1c, 0xe4, 0xe1, 0x1d, - 0xea, 0x01, 0x1e, 0x66, - 0x18, 0x51, 0x38, 0xb0, - 0x43, 0x3a, 0x9c, 0x83, - 0x3b, 0xcc, 0x50, 0x24, - 0x76, 0x60, 0x07, 0x7b, - 0x68, 0x07, 0x37, 0x60, - 0x87, 0x77, 0x78, 0x07, - 0x78, 0x98, 0x51, 0x4c, - 0xf4, 0x90, 0x0f, 0xf0, - 0x50, 0x0e, 0x33, 0x1e, - 0x6a, 0x1e, 0xca, 0x61, - 0x1c, 0xe8, 0x21, 0x1d, - 0xde, 0xc1, 0x1d, 0x7e, - 0x01, 0x1e, 0xe4, 0xa1, - 0x1c, 0xcc, 0x21, 0x1d, - 0xf0, 0x61, 0x06, 0x54, - 0x85, 0x83, 0x38, 0xcc, - 0xc3, 0x3b, 0xb0, 0x43, - 0x3d, 0xd0, 0x43, 0x39, - 0xfc, 0xc2, 0x3c, 0xe4, - 0x43, 0x3b, 0x88, 0xc3, - 0x3b, 0xb0, 0xc3, 0x8c, - 0xc5, 0x0a, 0x87, 0x79, - 0x98, 0x87, 0x77, 0x18, - 0x87, 0x74, 0x08, 0x07, - 0x7a, 0x28, 0x07, 0x72, - 0x98, 0x81, 0x5c, 0xe3, - 0x10, 0x0e, 0xec, 0xc0, - 0x0e, 0xe5, 0x50, 0x0e, - 0xf3, 0x30, 0x23, 0xc1, - 0xd2, 0x41, 0x1e, 0xe4, - 0xe1, 0x17, 0xd8, 0xe1, - 0x1d, 0xde, 0x01, 0x1e, - 0x66, 0x48, 0x19, 0x3b, - 0xb0, 0x83, 0x3d, 0xb4, - 0x83, 0x1b, 0x84, 0xc3, - 0x38, 0x8c, 0x43, 0x39, - 0xcc, 0xc3, 0x3c, 0xb8, - 0xc1, 0x39, 0xc8, 0xc3, - 0x3b, 0xd4, 0x03, 0x3c, - 0xcc, 0x48, 0xb4, 0x71, - 0x08, 0x07, 0x76, 0x60, - 0x07, 0x71, 0x08, 0x87, - 0x71, 0x58, 0x87, 0x19, - 0xdb, 0xc6, 0x0e, 0xec, - 0x60, 0x0f, 0xed, 0xe0, - 0x06, 0xf0, 0x20, 0x0f, - 0xe5, 0x30, 0x0f, 0xe5, - 0x20, 0x0f, 0xf6, 0x50, - 0x0e, 0x6e, 0x10, 0x0e, - 0xe3, 0x30, 0x0e, 0xe5, - 0x30, 0x0f, 0xf3, 0xe0, - 0x06, 0xe9, 0xe0, 0x0e, - 0xe4, 0x50, 0x0e, 0xf8, - 0x30, 0x23, 0xe2, 0xec, - 0x61, 0x1c, 0xc2, 0x81, - 0x1d, 0xd8, 0xe1, 0x17, - 0xec, 0x21, 0x1d, 0xe6, - 0x21, 0x1d, 0xc4, 0x21, - 0x1d, 0xd8, 0x21, 0x1d, - 0xe8, 0x21, 0x1f, 0x66, - 0x20, 0x9d, 0x3b, 0xbc, - 0x43, 0x3d, 0xb8, 0x03, - 0x39, 0x94, 0x83, 0x39, - 0xcc, 0x58, 0xbc, 0x70, - 0x70, 0x07, 0x77, 0x78, - 0x07, 0x7a, 0x08, 0x07, - 0x7a, 0x48, 0x87, 0x77, - 0x70, 0x87, 0x19, 0xcb, - 0xe7, 0x0e, 0xef, 0x30, - 0x0f, 0xe1, 0xe0, 0x0e, - 0xe9, 0x40, 0x0f, 0xe9, - 0xa0, 0x0f, 0xe5, 0x30, - 0xc3, 0x01, 0x03, 0x73, - 0xa8, 0x07, 0x77, 0x18, - 0x87, 0x5f, 0x98, 0x87, - 0x70, 0x70, 0x87, 0x74, - 0xa0, 0x87, 0x74, 0xd0, - 0x87, 0x72, 0x98, 0x81, - 0x84, 0x41, 0x39, 0xe0, - 0xc3, 0x38, 0xb0, 0x43, - 0x3d, 0x90, 0x43, 0x39, - 0xcc, 0x40, 0xc4, 0xa0, - 0x1d, 0xca, 0xa1, 0x1d, - 0xe0, 0x41, 0x1e, 0xde, - 0xc1, 0x1c, 0x66, 0x24, - 0x63, 0x30, 0x0e, 0xe1, - 0xc0, 0x0e, 0xec, 0x30, - 0x0f, 0xe9, 0x40, 0x0f, - 0xe5, 0x30, 0x43, 0x21, - 0x83, 0x75, 0x18, 0x07, - 0x73, 0x48, 0x87, 0x5f, - 0xa0, 0x87, 0x7c, 0x80, - 0x87, 0x72, 0x98, 0xb1, - 0x94, 0x01, 0x3c, 0x8c, - 0xc3, 0x3c, 0x94, 0xc3, - 0x38, 0xd0, 0x43, 0x3a, - 0xbc, 0x83, 0x3b, 0xcc, - 0xc3, 0x8c, 0xc5, 0x0c, - 0x48, 0x21, 0x15, 0x42, - 0x61, 0x1e, 0xe6, 0x21, - 0x1d, 0xce, 0xc1, 0x1d, - 0x52, 0x81, 0x14, 0x00, - 0x79, 0x20, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x00, - 0x72, 0x1e, 0x48, 0x20, - 0x43, 0x88, 0x0c, 0x19, - 0x09, 0x72, 0x32, 0x48, - 0x20, 0x23, 0x81, 0x8c, - 0x91, 0x91, 0xd1, 0x44, - 0xa0, 0x10, 0x28, 0x64, - 0x3c, 0x31, 0x32, 0x42, - 0x8e, 0x90, 0x21, 0xa3, - 0x68, 0x20, 0xac, 0x00, - 0x94, 0x92, 0x24, 0x47, - 0x03, 0x00, 0x00, 0x00, - 0x63, 0x6c, 0x61, 0x6e, - 0x67, 0x20, 0x76, 0x65, - 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x31, 0x37, - 0x2e, 0x30, 0x2e, 0x36, - 0x77, 0x63, 0x68, 0x61, - 0x72, 0x5f, 0x73, 0x69, - 0x7a, 0x65, 0x50, 0x49, - 0x43, 0x20, 0x4c, 0x65, - 0x76, 0x65, 0x6c, 0x50, - 0x49, 0x45, 0x20, 0x4c, - 0x65, 0x76, 0x65, 0x6c, - 0x75, 0x77, 0x74, 0x61, - 0x62, 0x6c, 0x65, 0x66, - 0x72, 0x61, 0x6d, 0x65, - 0x2d, 0x70, 0x6f, 0x69, - 0x6e, 0x74, 0x65, 0x72, - 0x23, 0x08, 0x41, 0x30, - 0x82, 0x10, 0x08, 0x23, - 0x08, 0xc1, 0x30, 0x82, - 0x10, 0x10, 0x23, 0x08, - 0x41, 0x31, 0x43, 0x10, - 0xcc, 0x30, 0x1c, 0x02, - 0x32, 0xc3, 0x90, 0x0c, - 0xca, 0x0c, 0xc3, 0x42, - 0x28, 0x33, 0x0c, 0x4b, - 0xa1, 0xcc, 0x30, 0x2c, - 0x86, 0x22, 0x23, 0x81, - 0x09, 0x4a, 0x85, 0x8d, - 0xcd, 0xae, 0xcd, 0x25, - 0x8d, 0xac, 0xcc, 0x8d, - 0x6e, 0x94, 0x60, 0xc9, - 0x88, 0x8d, 0xcd, 0xae, - 0xcd, 0xa5, 0xed, 0x8d, - 0xac, 0x8e, 0xad, 0xcc, - 0xc5, 0x8c, 0x2d, 0xec, - 0x6c, 0x6e, 0x94, 0x82, - 0x69, 0x9c, 0x07, 0x02, - 0xa9, 0x18, 0x00, 0x00, - 0x2d, 0x00, 0x00, 0x00, - 0x0b, 0x0a, 0x72, 0x28, - 0x87, 0x77, 0x80, 0x07, - 0x7a, 0x58, 0x70, 0x98, - 0x43, 0x3d, 0xb8, 0xc3, - 0x38, 0xb0, 0x43, 0x39, - 0xd0, 0xc3, 0x82, 0xe6, - 0x1c, 0xc6, 0xa1, 0x0d, - 0xe8, 0x41, 0x1e, 0xc2, - 0xc1, 0x1d, 0xe6, 0x21, - 0x1d, 0xe8, 0x21, 0x1d, - 0xde, 0xc1, 0x1d, 0x16, - 0x34, 0xe3, 0x60, 0x0e, - 0xe7, 0x50, 0x0f, 0xe1, - 0x20, 0x0f, 0xe4, 0x40, - 0x0f, 0xe1, 0x20, 0x0f, - 0xe7, 0x50, 0x0e, 0xf4, - 0xb0, 0x80, 0x81, 0x07, - 0x79, 0x28, 0x87, 0x70, - 0x60, 0x07, 0x76, 0x78, - 0x87, 0x71, 0x08, 0x07, - 0x7a, 0x28, 0x07, 0x72, - 0x58, 0x70, 0x9c, 0xc3, - 0x38, 0xb4, 0x01, 0x3b, - 0xa4, 0x83, 0x3d, 0x94, - 0xc3, 0x02, 0x6b, 0x1c, - 0xd8, 0x21, 0x1c, 0xdc, - 0xe1, 0x1c, 0xdc, 0x20, - 0x1c, 0xe4, 0x61, 0x1c, - 0xdc, 0x20, 0x1c, 0xe8, - 0x81, 0x1e, 0xc2, 0x61, - 0x1c, 0xd0, 0xa1, 0x1c, - 0xc8, 0x61, 0x1c, 0xc2, - 0x81, 0x1d, 0xd8, 0x61, - 0xc1, 0x01, 0x0f, 0xf4, - 0x20, 0x0f, 0xe1, 0x50, - 0x0f, 0xf4, 0x80, 0x0e, - 0x0b, 0x88, 0x75, 0x18, - 0x07, 0x73, 0x48, 0x87, - 0x05, 0xcf, 0x38, 0xbc, - 0x83, 0x3b, 0xd8, 0x43, - 0x39, 0xc8, 0xc3, 0x39, - 0x94, 0x83, 0x3b, 0x8c, - 0x43, 0x39, 0x8c, 0x03, - 0x3d, 0xc8, 0x03, 0x3b, - 0x00, 0x00, 0x00, 0x00, - 0xd1, 0x10, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, - 0x07, 0xcc, 0x3c, 0xa4, - 0x83, 0x3b, 0x9c, 0x03, - 0x3b, 0x94, 0x03, 0x3d, - 0xa0, 0x83, 0x3c, 0x94, - 0x43, 0x38, 0x90, 0xc3, - 0x01, 0x00, 0x00, 0x00, - 0x61, 0x20, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, - 0x13, 0x04, 0x41, 0x2c, - 0x10, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x94, 0x11, 0x00, 0x00, - 0x33, 0x11, 0x41, 0x10, - 0x8c, 0xc2, 0x4c, 0x44, - 0x10, 0x04, 0xa3, 0x30, - 0x13, 0x01, 0x04, 0x01, - 0x29, 0x0c, 0x1b, 0x10, - 0x03, 0x31, 0x00, 0xc3, - 0x06, 0x84, 0x60, 0x0c, - 0xc0, 0xb0, 0x01, 0x11, - 0x14, 0x04, 0xb0, 0x04, - 0x00, 0x00, 0x00, 0x00, - 0x71, 0x20, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x32, 0x0e, 0x10, 0x22, - 0x84, 0x00, 0xda, 0x03, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; - writer.append_bytes(&rest_module_block); + writer.write_attribute_group_table(); + writer.write_attribute_table(); + + // TODO + // writer.write_comdats(); + + writer.write_module_info(); + + writer.write_module_constants(); + + writer.write_module_metadata_kinds(); + + writer.write_module_metadata(); + + // TODO: + const should_preserve_use_list_order = false; + if (should_preserve_use_list_order) { + writer.write_use_list_block(null); + } + + writer.write_operand_bundle_tags(); + + writer.write_sync_scope_names(); + + // TODO: functions + // for (functions) |function| { + // if (!function.is_declaration) { + // write.write_function(function); + // } + // } + // + + // TODO: module summary + // if (index) { + // writer.write_per_module_global_value_summary(); + // } + + // TODO: + // writer.write_global_value_symbol_table(map); + + // writer.write_module_hash(block_start_position); + writer.exit_block(); + } + } + + fn write_symtab(writer: *Writer) void { + // TODO: const symtab_block align(4) = .{ 0x65, 0x0c, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, @@ -1864,7 +1950,10 @@ const Bitcode = struct { 0x00, 0x00, 0x00, 0x00, }; writer.append_bytes(&symtab_block); + } + fn write_strtab(writer: *Writer) void { + // TODO: const strtab_block align(4) = .{ 0x5d, 0x0c, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, @@ -1885,6 +1974,19 @@ const Bitcode = struct { writer.append_bytes(&strtab_block); } + pub fn write(writer: *Writer) void { + const magic align(4) = [_]u8{ 0x42, 0x43, 0xc0, 0xde }; + writer.append_bytes(&magic); + + writer.write_identification_block(); + + writer.write_module_block(); + + writer.write_symtab(); + + writer.write_strtab(); + } + fn write_module_version(writer: *Writer) void { writer.emit_record(u64, @intFromEnum(ModuleCode.version), &.{2}, 0); } @@ -2121,6 +2223,201 @@ const Bitcode = struct { writer.exit_block(); } + fn write_type_table(writer: *Writer) void { + writer.enter_subblock(.type, 4); + + var type_values = std.BoundedArray(u64, 64){}; + + // TODO: compute + const type_indices_needed_bits = 0; + const type_count = 0; + + const opaque_pointer_abbreviation = blk: { + const abbreviation = writer.abbreviation_buffer.append(.{}); + abbreviation.add_literal(@intFromEnum(TypeCode.opaque_pointer)); + // TODO: this could be wrong? + abbreviation.add_literal(0); + break :blk writer.emit_abbreviation(abbreviation); + }; + _ = opaque_pointer_abbreviation; // autofix + const function_abbreviation = blk: { + const abbreviation = writer.abbreviation_buffer.append(.{}); + abbreviation.add_literal(@intFromEnum(TypeCode.function)); + // TODO: this could be wrong? + abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = 1 }); + abbreviation.add_with_encoding(.{ .encoding = .array }); + abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = type_indices_needed_bits }); + + break :blk writer.emit_abbreviation(abbreviation); + }; + + const struct_anon_abbreviation = blk: { + const abbreviation = writer.abbreviation_buffer.append(.{}); + abbreviation.add_literal(@intFromEnum(TypeCode.struct_anon)); + // TODO: this could be wrong? + abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = 1 }); + abbreviation.add_with_encoding(.{ .encoding = .array }); + abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = type_indices_needed_bits }); + + break :blk writer.emit_abbreviation(abbreviation); + }; + _ = struct_anon_abbreviation; // autofix + const struct_name_abbreviation = blk: { + const abbreviation = writer.abbreviation_buffer.append(.{}); + abbreviation.add_literal(@intFromEnum(TypeCode.struct_name)); + // TODO: this could be wrong? + abbreviation.add_with_encoding(.{ .encoding = .array }); + abbreviation.add_with_encoding(.{ .encoding = .char6 }); + + break :blk writer.emit_abbreviation(abbreviation); + }; + + const struct_named_abbreviation = blk: { + const abbreviation = writer.abbreviation_buffer.append(.{}); + abbreviation.add_literal(@intFromEnum(TypeCode.struct_named)); + // TODO: this could be wrong? + abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = 1 }); + abbreviation.add_with_encoding(.{ .encoding = .array }); + abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = type_indices_needed_bits }); + + break :blk writer.emit_abbreviation(abbreviation); + }; + _ = struct_named_abbreviation; // autofix + + const array_abbreviation = blk: { + const abbreviation = writer.abbreviation_buffer.append(.{}); + abbreviation.add_literal(@intFromEnum(TypeCode.array)); + // TODO: this could be wrong? + abbreviation.add_with_encoding(.{ .encoding = .vbr, .value = 8 }); + abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = type_indices_needed_bits }); + + break :blk writer.emit_abbreviation(abbreviation); + }; + _ = array_abbreviation; // autofix + + _ = struct_name_abbreviation; // autofix + _ = function_abbreviation; // autofix + // + type_values.appendAssumeCapacity(type_count); + writer.emit_record(u64, @intFromEnum(TypeCode.num_entry), type_values.constSlice(), 0); + type_values.resize(0) catch unreachable; + + // TODO: + // Now loop over types and emit records for them + + writer.exit_block(); + } + + fn write_attribute_group_table(writer: *Writer) void { + _ = writer; // autofix + // TODO: + } + + fn write_attribute_table(writer: *Writer) void { + _ = writer; // autofix + // TODO: + } + + fn write_module_info(writer: *Writer) void { + const target_triple = "x86_64-pc-linux-gnu"; + writer.write_string_record(@intFromEnum(ModuleCode.triple), target_triple, + // TODO in LLVM code + 0); + + const data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"; + writer.write_string_record(@intFromEnum(ModuleCode.data_layout), data_layout, + // TODO in LLVM code + 0); + + // TODO: global inline assembly + // const global_inline_assembly = ""; + // write_string_record(@intFromEnum(ModuleCode.@"asm"), global_inline_assembly, + // // TODO in LLVM code + // 0); + // + + // TODO: section names + + // TODO: global abbreviation + + var values = std.BoundedArray(u32, 64){}; + { + const source_filename = "llvm-link"; + const source_string_encoding = get_string_encoding(source_filename); + const abbreviation = writer.abbreviation_buffer.append(.{}); + abbreviation.add_literal(@intFromEnum(ModuleCode.source_filename)); + abbreviation.add_with_encoding(.{ .encoding = .array }); + switch (source_string_encoding) { + .char6 => abbreviation.add_with_encoding(.{ .encoding = .char6 }), + .fixed7 => abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = 7 }), + .fixed8 => abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = 8 }), + } + + const filename_abbreviation = writer.emit_abbreviation(abbreviation); + for (source_filename) |ch| { + values.appendAssumeCapacity(ch); + } + + writer.emit_record(u32, @intFromEnum(ModuleCode.source_filename), values.constSlice(), filename_abbreviation); + values.resize(0) catch unreachable; + } + + // TODO: global variables + + // TODO: functions + + // TODO: global aliases + + // TODO: global ifunc + + writer.write_value_symbol_table_forward_declaration(); + } + + fn write_module_constants(writer: *Writer) void { + _ = writer; // autofix + // TODO: + } + + fn write_module_metadata_kinds(writer: *Writer) void { + _ = writer; // autofix + // TODO: + } + + fn write_module_metadata(writer: *Writer) void { + _ = writer; // autofix + // TODO: + } + + fn write_use_list_block(writer: *Writer, function: ?*u32) void { + _ = function; // autofix + _ = writer; // autofix + // TODO: + } + + fn write_operand_bundle_tags(writer: *Writer) void { + _ = writer; // autofix + } + + fn write_sync_scope_names(writer: *Writer) void { + _ = writer; // autofix + } + + fn write_value_symbol_table_forward_declaration(writer: *Writer) void { + const abbreviation = writer.abbreviation_buffer.append(.{}); + abbreviation.add_literal(@intFromEnum(ModuleCode.vst_offset)); + abbreviation.add_with_encoding(.{ .encoding = .fixed, .value = 32 }); + + const vst_offset_abbreviation = writer.emit_abbreviation(abbreviation); + const values = [_]u64{@intFromEnum(ModuleCode.vst_offset), 0}; + writer.emit_record_with_abbrev(u64, vst_offset_abbreviation, &values); + + writer.vst_offset_placeholder = (writer.buffer.length * 32) - 32; + } + + fn emit_record_with_abbrev(writer: *Writer, comptime T: type, abbreviation: u32, values: []const T) void { + writer.emit_record_with_abbrev_impl(T, abbreviation, values, null, null); + } + fn switch_to_block_id(writer: *Writer, block_id: u32) void { if (block_id != writer.block_info_current_block_id) { const v = [1]u32{block_id}; @@ -2230,7 +2527,7 @@ const Bitcode = struct { return writer.current_abbreviations.length - 1 + @intFromEnum(FixedAbbreviationId.first_application_abbrev); } - fn emit_abbreviated_literal(writer: *Writer, operand: *Abbreviation.Op, value: u32) void { + fn emit_abbreviated_literal(writer: *Writer, comptime T: type, operand: *Abbreviation.Op, value: T) void { _ = writer; // autofix assert(operand.is_literal); assert(value == operand.value); @@ -2262,6 +2559,17 @@ const Bitcode = struct { writer.emit_record(u32, @intFromEnum(IdentificationCode.epoch), &values, epoch_abbreviation); writer.exit_block(); } + + const identification_block = .{ + 0x35, 0x14, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, + 0x62, 0x0c, 0x30, 0x24, + 0x4a, 0x59, 0xbe, 0x66, + 0xbd, 0xfb, 0xb4, 0xaf, + 0x0b, 0x51, 0x80, 0x4c, + 0x01, 0x00, 0x00, 0x00, + }; + std.testing.expectEqualSlices(u8, &identification_block, writer.get_byte_slice()[4..]) catch unreachable; } fn exit_block(writer: *Writer) void { @@ -2286,7 +2594,7 @@ const Bitcode = struct { } fn write_string_record(writer: *Writer, code: u32, string: []const u8, abbreviation_to_use: u32) void { - var values = std.BoundedArray(u32, 64){}; + var values = std.BoundedArray(u32, 128){}; var a = abbreviation_to_use; for (string) |ch| { if (a != 0 and !is_char6(ch)) { @@ -2309,11 +2617,11 @@ const Bitcode = struct { writer.emit_vbr64(v, 6); } } else { - writer.emit_record_with_abbrev(T, abbreviation, values, null, code); + writer.emit_record_with_abbrev_impl(T, abbreviation, values, null, code); } } - fn emit_record_with_abbrev(writer: *Writer, comptime T: type, abbreviation_int: u32, values: []const T, string: ?[]const u8, code: ?u32) void { + fn emit_record_with_abbrev_impl(writer: *Writer, comptime T: type, abbreviation_int: u32, values: []const T, string: ?[]const u8, code: ?u32) void { const abbreviation_number = abbreviation_int - @intFromEnum(FixedAbbreviationId.first_application_abbrev); assert(abbreviation_number < writer.current_abbreviations.length); const abbreviation = writer.current_abbreviations.slice()[abbreviation_number]; @@ -2328,7 +2636,7 @@ const Bitcode = struct { operand_index += 1; if (operand.is_literal) { - writer.emit_abbreviated_literal(operand, c); + writer.emit_abbreviated_literal(u32, operand, c); } else { unreachable; } @@ -2339,7 +2647,9 @@ const Bitcode = struct { const operand = &abbreviation.operands.slice()[operand_index]; if (operand.is_literal) { - unreachable; + assert(record_index < values.len); + writer.emit_abbreviated_literal(T, operand, values[record_index]); + record_index += 1; } else if (operand.encoding == .array) { assert(operand_index + 2 == operand_count); operand_index += 1; @@ -2370,7 +2680,9 @@ const Bitcode = struct { switch (operand.encoding) { else => unreachable, .fixed => { - unreachable; + if (operand.get_encoding_data()) |v| { + writer.emit(@intCast(value), @intCast(v)); + } }, .vbr => { if (operand.get_encoding_data()) |v| { @@ -2393,6 +2705,27 @@ const Bitcode = struct { unreachable; } + const StringEncoding = enum{ + char6, + fixed7, + fixed8, + }; + + fn get_string_encoding(string: []const u8) StringEncoding{ + var char6 = true; + for (string) |ch| { + if (char6) { + char6 = is_char6(ch); + } + + if (ch & 128 != 0) { + return .fixed8; + } + } + + return if (char6) .char6 else .fixed7; + } + fn enter_subblock(writer: *Writer, block_id: BlockId, code_length: u32) void { writer.emit_code(@intFromEnum(FixedAbbreviationId.enter_subblock)); writer.emit_vbr(@intFromEnum(block_id), width.block_id);