Files
ivy/asm/assembler/class.c

52 lines
1.4 KiB
C

#include "assembler.h"
#include <ivy/asm/bin.h>
static enum ivy_status init_scope(struct ivy_assembler *as, struct assembler_scope *scope,
const ivy_assembler_attrib_table attrib)
{
struct ivy_bin_class header = {0};
header.c_ident = b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
assembler_write_data(as, &header, sizeof header);
return IVY_OK;
}
static enum ivy_status put_xval(
struct ivy_assembler *as,
struct assembler_scope *scope,
enum ivy_assembler_xval_type type,
const ivy_assembler_attrib_table attrib)
{
struct ivy_bin_class_table_entry entry = {0};
switch (type) {
case IVY_ASM_XVAL_PROPERTY:
entry.e_type = b_i32_htob(IVY_CLASS_TABLE_PROP);
entry.e_property.p_ident
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
entry.e_property.p_get
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_GET]);
entry.e_property.p_set
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SET]);
break;
case IVY_ASM_XVAL_MEMBER_VAR:
entry.e_type = b_i32_htob(IVY_CLASS_TABLE_MVAR);
entry.e_mvar.m_ident
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
entry.e_mvar.m_index
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
break;
default:
return IVY_ERR_NOT_SUPPORTED;
}
assembler_write_data(as, &entry, sizeof entry);
return IVY_OK;
}
const struct assembler_scope_type class_scope_type = {
.s_scope_size = sizeof(struct assembler_scope),
.s_init_scope = init_scope,
.s_put_xval = put_xval,
};