asm: assembler: constpool value indices are now used and enforced

constpool values must be defined in ascending sequence, each index must be greater than the last.
any gaps in the sequence will automatically be filled with null values.
This commit is contained in:
2025-05-15 12:06:39 +01:00
parent 95f58615e0
commit 2845c29c5f
4 changed files with 19 additions and 5 deletions

View File

@@ -287,7 +287,7 @@ enum ivy_status ivy_assembler_end_scope(struct ivy_assembler *as)
enum ivy_status ivy_assembler_put_pval(
struct ivy_assembler *as, enum ivy_assembler_pval_type type,
const void *val, ivy_extended_data_key *key)
size_t slot, const void *val, ivy_extended_data_key *key)
{
struct assembler_scope *scope = as->as_scope;
@@ -300,7 +300,7 @@ enum ivy_status ivy_assembler_put_pval(
return IVY_ERR_NOT_SUPPORTED;
}
return type_info->s_put_pval(as, scope, type, val, key);
return type_info->s_put_pval(as, scope, type, slot, val, key);
}
enum ivy_status ivy_assembler_put_xval(

View File

@@ -27,7 +27,7 @@ struct assembler_scope_type {
enum ivy_status (*s_put_pval)(
struct ivy_assembler *, struct assembler_scope *,
enum ivy_assembler_pval_type, const void *,
enum ivy_assembler_pval_type, size_t, const void *,
ivy_extended_data_key *key);
enum ivy_status (*s_put_xval)(

View File

@@ -13,6 +13,7 @@
struct constpool_assembler_scope {
struct assembler_scope s_base;
b_dict *s_strings;
size_t s_next_slot;
};
static enum ivy_status init_scope(
@@ -26,6 +27,7 @@ static enum ivy_status init_scope(
struct constpool_assembler_scope *c
= (struct constpool_assembler_scope *)scope;
c->s_strings = b_dict_create();
c->s_next_slot = 0;
return IVY_OK;
}
@@ -151,12 +153,18 @@ static ivy_extended_data_key write_ident(
static enum ivy_status put_pval(
struct ivy_assembler *as, struct assembler_scope *scope,
enum ivy_assembler_pval_type type, const void *val,
enum ivy_assembler_pval_type type, size_t slot, const void *val,
ivy_extended_data_key *key)
{
struct ivy_bin_constpool_table_entry entry = {0};
uintptr_t i = *(uintptr_t *)val;
ivy_extended_data_key k = IVY_EX_DATA_KEY_NULL;
struct constpool_assembler_scope *s
= (struct constpool_assembler_scope *)assembler_get_scope(as);
if (slot < s->s_next_slot) {
return IVY_ERR_NAME_EXISTS;
}
switch (type) {
case IVY_ASM_PVAL_STRING:
@@ -195,7 +203,13 @@ static enum ivy_status put_pval(
*key = k;
}
for (size_t i = s->s_next_slot; i < slot; i++) {
struct ivy_bin_constpool_table_entry null_entry = {0};
assembler_write_data(as, &null_entry, sizeof null_entry);
}
assembler_write_data(as, &entry, sizeof entry);
s->s_next_slot = slot + 1;
return IVY_OK;
}