| ... | @@ -644,6 +644,8 @@ const WasmDumper = struct { | ... | @@ -644,6 +644,8 @@ const WasmDumper = struct { |
| 644 | | 644 | |
| 645 | if (mem.eql(u8, name, "name")) { | 645 | if (mem.eql(u8, name, "name")) { |
| 646 | try parseDumpNames(reader, writer, data); | 646 | try parseDumpNames(reader, writer, data); |
| | 647 | } else if (mem.eql(u8, name, "producers")) { |
| | 648 | try parseDumpProducers(reader, writer, data); |
| 647 | } | 649 | } |
| 648 | // TODO: Implement parsing and dumping other custom sections (such as relocations) | 650 | // TODO: Implement parsing and dumping other custom sections (such as relocations) |
| 649 | }, | 651 | }, |
| ... | @@ -863,4 +865,38 @@ const WasmDumper = struct { | ... | @@ -863,4 +865,38 @@ const WasmDumper = struct { |
| 863 | } | 865 | } |
| 864 | } | 866 | } |
| 865 | } | 867 | } |
| | 868 | |
| | 869 | fn parseDumpProducers(reader: anytype, writer: anytype, data: []const u8) !void { |
| | 870 | const field_count = try std.leb.readULEB128(u32, reader); |
| | 871 | try writer.print("fields {d}\n", .{field_count}); |
| | 872 | var current_field: u32 = 0; |
| | 873 | while (current_field < field_count) : (current_field += 1) { |
| | 874 | const field_name_length = try std.leb.readULEB128(u32, reader); |
| | 875 | const field_name = data[reader.context.pos..][0..field_name_length]; |
| | 876 | reader.context.pos += field_name_length; |
| | 877 | |
| | 878 | const value_count = try std.leb.readULEB128(u32, reader); |
| | 879 | try writer.print( |
| | 880 | \\field_name {s} |
| | 881 | \\values {d} |
| | 882 | , .{ field_name, value_count }); |
| | 883 | try writer.writeByte('\n'); |
| | 884 | var current_value: u32 = 0; |
| | 885 | while (current_value < value_count) : (current_value += 1) { |
| | 886 | const value_length = try std.leb.readULEB128(u32, reader); |
| | 887 | const value = data[reader.context.pos..][0..value_length]; |
| | 888 | reader.context.pos += value_length; |
| | 889 | |
| | 890 | const version_length = try std.leb.readULEB128(u32, reader); |
| | 891 | const version = data[reader.context.pos..][0..version_length]; |
| | 892 | reader.context.pos += version_length; |
| | 893 | |
| | 894 | try writer.print( |
| | 895 | \\value_name {s} |
| | 896 | \\version {s} |
| | 897 | , .{ value, version }); |
| | 898 | try writer.writeByte('\n'); |
| | 899 | } |
| | 900 | } |
| | 901 | } |
| 866 | }; | 902 | }; |