asm: parse: implement label reference generation
This commit is contained in:
@@ -147,7 +147,7 @@ static unsigned long long get_register_index(struct ivy_asm_token *tok)
|
||||
}
|
||||
|
||||
char index_str[5] = {0};
|
||||
strncpy(index_str + 1, s, sizeof index_str - 1);
|
||||
strncpy(index_str, s + 1, sizeof index_str - 1);
|
||||
char *ep = NULL;
|
||||
unsigned long long index = strtoul(index_str, &ep, 10);
|
||||
|
||||
@@ -331,17 +331,26 @@ static enum ivy_status write_instruction(
|
||||
instr.i_arg[i++] = arg->arg_reg.reg_index;
|
||||
break;
|
||||
case ARG_CONST:
|
||||
instr.i_arg[i++] = arg->arg_const->t_int.v;
|
||||
instr.i_arg[i++] = arg->arg_const->t_int.sign
|
||||
? arg->arg_const->t_int.v
|
||||
: arg->arg_const->t_int.uv;
|
||||
break;
|
||||
case ARG_LABEL:
|
||||
instr.i_arg[i++] = 0;
|
||||
ivy_assembler_put_label_ref(
|
||||
p->p_assembler, arg->arg_label,
|
||||
ivy_assembler_get_ptr(p->p_assembler));
|
||||
break;
|
||||
case ARG_INDEX_REG:
|
||||
instr.i_arg[i++] = arg->arg_index_reg.index_offset_reg;
|
||||
break;
|
||||
case ARG_INDEX_CONST:
|
||||
instr.i_arg[i++]
|
||||
= arg->arg_index_const.index_offset->t_int.v;
|
||||
= arg->arg_index_const.index_offset->t_int.sign
|
||||
? arg->arg_index_const.index_offset
|
||||
->t_int.v
|
||||
: arg->arg_index_const.index_offset
|
||||
->t_int.uv;
|
||||
break;
|
||||
default:
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
@@ -372,21 +381,11 @@ static enum ivy_status push_const_arg(
|
||||
}
|
||||
|
||||
static enum ivy_status push_label(
|
||||
struct block_parser_state *state, struct ivy_asm_token *tok)
|
||||
struct ivy_asm_parser *p, struct block_parser_state *state,
|
||||
struct ivy_asm_token *tok)
|
||||
{
|
||||
struct label *label = malloc(sizeof *label);
|
||||
if (!label) {
|
||||
return IVY_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
memset(label, 0x0, sizeof *label);
|
||||
|
||||
label->l_name = tok;
|
||||
/* TODO */
|
||||
label->l_offset = 0;
|
||||
|
||||
b_queue_push_back(&state->s_labels, &label->l_entry);
|
||||
return IVY_OK;
|
||||
return ivy_assembler_put_label(
|
||||
p->p_assembler, tok, ivy_assembler_get_ptr(p->p_assembler));
|
||||
}
|
||||
|
||||
static enum ivy_status push_label_arg(
|
||||
@@ -557,7 +556,7 @@ static enum ivy_status parse_label(
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
return push_label(state, tok);
|
||||
return push_label(ctx, state, tok);
|
||||
}
|
||||
|
||||
static enum ivy_status parse_comma(
|
||||
|
||||
Reference in New Issue
Block a user