Add alias_value() function.

alias_value returns a new value where only the type is different, the
bit-pattern of the value itself is untouched.
This commit is contained in:
Bill Currie 2012-12-23 19:25:35 +09:00
parent 82ded2b638
commit 42ba0c9d54
2 changed files with 17 additions and 2 deletions

View file

@ -54,8 +54,9 @@ struct ex_value_s *new_uinteger_val (int uinteger_val);
struct ex_value_s *new_short_val (short short_val);
struct ex_value_s *new_nil_val (struct type_s *type);
struct ex_value_s * convert_value (struct ex_value_s *value,
struct type_s *type);
struct ex_value_s *convert_value (struct ex_value_s *value,
struct type_s *type);
struct ex_value_s *alias_value (struct ex_value_s *value, struct type_s *type);
struct def_s *emit_value (struct ex_value_s *value, struct def_s *def);
int ReuseString (const char *str);

View file

@ -397,6 +397,20 @@ convert_value (ex_value_t *value, type_t *type)
}
}
ex_value_t *
alias_value (ex_value_t *value, type_t *type)
{
ex_value_t new;
if (type_size (type) != type_size (ev_types[value->type])) {
error (0, "unable to alias different sized values");
return value;
}
new = *value;
new.type = type->type;
return find_value (&new);
}
static immediate_t *
make_def_imm (def_t *def, hashtab_t *tab, ex_value_t *val)
{