From 95f58615e066592fb399301204c51ad82d60514d Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 15 May 2025 12:06:04 +0100 Subject: [PATCH] asm: reader: implement reading ident and atom constpool values --- asm/reader.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/asm/reader.c b/asm/reader.c index 6b9780d..6327c42 100644 --- a/asm/reader.c +++ b/asm/reader.c @@ -333,6 +333,8 @@ enum ivy_status ivy_asm_constpool_reader_read_value( break; case IVY_CONSTPOOL_TABLE_ATOM: value->v_type = IVY_ASM_CONSTPOOL_TYPE_ATOM; + handle = b_i32_btoh(entry.e_ex_handle); + status = read_string_xdata(reader, handle, &value->v_str); break; case IVY_CONSTPOOL_TABLE_SELECTOR: { value->v_type = IVY_ASM_CONSTPOOL_TYPE_SELECTOR; @@ -395,6 +397,8 @@ enum ivy_status ivy_asm_constpool_reader_read_value( ivy_selector_add_arg(sel, arg_name, NULL); free(arg_name); + + handle += sizeof arg; } if (status != IVY_OK) { @@ -405,11 +409,69 @@ enum ivy_status ivy_asm_constpool_reader_read_value( value->v_sel = sel; break; } - case IVY_CONSTPOOL_TABLE_IDENT: + case IVY_CONSTPOOL_TABLE_IDENT: { value->v_type = IVY_ASM_CONSTPOOL_TYPE_IDENT; + handle = b_i32_btoh(entry.e_ex_handle); + + struct ivy_bin_ident id_entry; + status = ivy_asm_section_reader_read( + reader->r_xdat, handle, sizeof id_entry, &id_entry, &r); + + if (status != IVY_OK) { + break; + } + + if (r != sizeof id_entry) { + status = IVY_ERR_BAD_FORMAT; + break; + } + + struct ivy_ident *id; + id = ivy_ident_create(); + if (!id) { + status = IVY_ERR_NO_MEMORY; + break; + } + + handle += sizeof id_entry; + size_t nr_parts = id_entry.id_nr_parts; + for (size_t i = 0; i < nr_parts; i++) { + b_i32 part; + status = ivy_asm_section_reader_read( + reader->r_xdat, handle, sizeof part, &part, &r); + + if (status != IVY_OK) { + break; + } + + if (r != sizeof part) { + status = IVY_ERR_BAD_FORMAT; + break; + } + + size_t part_key = b_i32_btoh(part); + char *part_name = NULL; + status = read_string_xdata(reader, part_key, &part_name); + if (status != IVY_OK) { + break; + } + + ivy_ident_add_part(id, part_name); + free(part_name); + + handle += sizeof part; + } + + if (status != IVY_OK) { + ivy_ident_destroy(id); + break; + } + + value->v_ident = id; break; + } default: - status = IVY_ERR_BAD_FORMAT; + value->v_type = IVY_ASM_CONSTPOOL_TYPE_NONE; break; }