| ... | @@ -3519,6 +3519,7 @@ fn writeToFile( | ... | @@ -3519,6 +3519,7 @@ fn writeToFile( |
| 3519 | | 3519 | |
| 3520 | // Import section | 3520 | // Import section |
| 3521 | const import_memory = wasm.base.options.import_memory or is_obj; | 3521 | const import_memory = wasm.base.options.import_memory or is_obj; |
| | 3522 | const export_memory = wasm.base.options.export_memory; |
| 3522 | if (wasm.imports.count() != 0 or import_memory) { | 3523 | if (wasm.imports.count() != 0 or import_memory) { |
| 3523 | const header_offset = try reserveVecSectionHeader(&binary_bytes); | 3524 | const header_offset = try reserveVecSectionHeader(&binary_bytes); |
| 3524 | | 3525 | |
| ... | @@ -3621,7 +3622,7 @@ fn writeToFile( | ... | @@ -3621,7 +3622,7 @@ fn writeToFile( |
| 3621 | } | 3622 | } |
| 3622 | | 3623 | |
| 3623 | // Export section | 3624 | // Export section |
| 3624 | if (wasm.exports.items.len != 0 or !import_memory) { | 3625 | if (wasm.exports.items.len != 0 or export_memory) { |
| 3625 | const header_offset = try reserveVecSectionHeader(&binary_bytes); | 3626 | const header_offset = try reserveVecSectionHeader(&binary_bytes); |
| 3626 | | 3627 | |
| 3627 | for (wasm.exports.items) |exp| { | 3628 | for (wasm.exports.items) |exp| { |
| ... | @@ -3632,7 +3633,7 @@ fn writeToFile( | ... | @@ -3632,7 +3633,7 @@ fn writeToFile( |
| 3632 | try leb.writeULEB128(binary_writer, exp.index); | 3633 | try leb.writeULEB128(binary_writer, exp.index); |
| 3633 | } | 3634 | } |
| 3634 | | 3635 | |
| 3635 | if (!import_memory) { | 3636 | if (export_memory) { |
| 3636 | try leb.writeULEB128(binary_writer, @as(u32, @intCast("memory".len))); | 3637 | try leb.writeULEB128(binary_writer, @as(u32, @intCast("memory".len))); |
| 3637 | try binary_writer.writeAll("memory"); | 3638 | try binary_writer.writeAll("memory"); |
| 3638 | try binary_writer.writeByte(std.wasm.externalKind(.memory)); | 3639 | try binary_writer.writeByte(std.wasm.externalKind(.memory)); |
| ... | @@ -3644,7 +3645,7 @@ fn writeToFile( | ... | @@ -3644,7 +3645,7 @@ fn writeToFile( |
| 3644 | header_offset, | 3645 | header_offset, |
| 3645 | .@"export", | 3646 | .@"export", |
| 3646 | @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)), | 3647 | @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)), |
| 3647 | @as(u32, @intCast(wasm.exports.items.len)) + @intFromBool(!import_memory), | 3648 | @as(u32, @intCast(wasm.exports.items.len)) + @intFromBool(export_memory), |
| 3648 | ); | 3649 | ); |
| 3649 | section_count += 1; | 3650 | section_count += 1; |
| 3650 | } | 3651 | } |