Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавить поддержку IR. #374

Draft
wants to merge 21 commits into
base: feature
Choose a base branch
from

Conversation

georgiy-belyanin
Copy link
Contributor

Реализовал часть основных IR функций. Этот PR не влияет на существующие методы генерации, он содержит только код потенциально применимый для построения этого дерева, чтобы ничего не сломать из существующего.

@georgiy-belyanin georgiy-belyanin force-pushed the feature-ir branch 2 times, most recently from 9842f62 to 6908dcb Compare March 21, 2023 13:51
* значения, используемые в инструкциях функций. Фактически эквивалентен единице
* трансляции.
*/
typedef struct ir_module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А где очистка

@georgiy-belyanin georgiy-belyanin marked this pull request as draft March 28, 2023 11:58
Comment on lines +266 to +272
static extern_data create_extern_data(const item_t id, const item_t type)
{
return (extern_data) {
.id = id,
.type = type
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как-нибудь отделить static

Comment on lines 490 to 494
static char* ir_imm_value_get_string(const ir_value *const value)
{
(void) value;
return NULL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что-то странное

Comment on lines +530 to +533
static item_t ir_value_save(const ir_value *const value)
{
return (item_t) node_save(value);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем преобразование

static item_t ir_build_param(ir_builder *const builder, const item_t type, size_t number)
{
const ir_value value = create_ir_param_value(&builder->module->values_root, type, number);
//ir_locals_add(builder, type);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Убрать

Comment on lines 1256 to 1257
ir_instr instr = create_ir_instr(&function, ic, op1, op2, res);
(void) instr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем заводить переменную?


static item_t ir_build_ptr(ir_builder *const builder, const item_t type, const item_t base, const size_t displ)
{
(void) displ;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment on lines 1521 to 1524
{

break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно и без скобок

}
static void ir_dump_ic(const ir_builder *const builder, const ir_ic ic)
{
(void) builder;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Снова


static void ir_dump_label_kind(const ir_builder *const builder, const ir_label_kind label_kind)
{
(void) builder;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже

Comment on lines 2142 to 2144
const item_t type = expression_get_type(nd);

(void) type;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зочем

Comment on lines +2220 to +2221
const item_t return_type = type_function_get_return_type(sx, expression_get_type(&callee));
(void) return_type;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зочем

Comment on lines 2295 to 2308
else
{
const item_t operand_rvalue = ir_build_load(builder, operand_lvalue);
const item_t second_value = ir_build_imm_one(builder);
const item_t incremented_value = ir_emit_binary_operation(builder, operand_rvalue, second_value, (is_inc) ? BIN_ADD : BIN_SUB);
ir_free_value(builder, second_value);

ir_build_store(builder, incremented_value, operand_lvalue);
ir_free_value(builder, incremented_value);

return operand_rvalue;
}

return IR_VALUE_VOID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно else не ставить

{
const node operand = expression_unary_get_operand(nd);
const item_t value = ir_emit_expression(builder, &operand);
//const item_t second_value = builder->value_zero;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Комменты с кодом удалять

Comment on lines +2395 to +2397
const node operand = expression_unary_get_operand(nd);

(void) operand;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зочем

{
if (type_is_integer(sx, lhs_type) && type_is_integer(sx, rhs_type))
{
//printf("%d %d\n", lhs, rhs);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Код в комментах

Comment on lines 2435 to 2442
return ir_build_add(builder, lhs, rhs);
}
else
{
const item_t lhs_value = type_is_floating(lhs_type) ? lhs : ir_build_itof(builder, lhs);
const item_t rhs_value = type_is_floating(rhs_type) ? rhs : ir_build_itof(builder, rhs);
return ir_build_fadd(builder, lhs_value, rhs_value);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

без else

Comment on lines +2877 to +2878
const syntax *const sx = builder->sx;
(void) sx;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зочем

Comment on lines +2884 to +2885
const item_t rhs_type = expression_get_type(&rhs);
(void) rhs_type;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зочем

Comment on lines 3013 to 3039
// const syntax *const sx = builder->sx;

// const size_t member_amount = type_structure_get_member_amount(sx, target->type);

// for (size_t i = 0; i < member_amount; i++)
// {
// const item_t type = type_structure_get_member_type(sx, target->type, i);
// const lvalue member_lvalue = {
// .base_reg = target->base_reg,
// .kind = target->kind,
// .loc.displ = target->loc.displ + displ,
// .type = type
// };
// displ += type_size(sx, type);

// const node subexpr = expression_initializer_get_subexpr(initializer, i);
// if (expression_get_class(&subexpr) == EXPR_INITIALIZER)
// {
// ir_emit_structure_init(builder, &member_lvalue, &subexpr);
// continue;
// }

// if (type_is_structure(sx, expression_get_type(&subexpr)))
// {
// ir_emit_struct_assignment(builder, &member_lvalue, &subexpr);
// }
// else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ужас, удаляю

static void ir_emit_function_definition(ir_builder *const builder, const node *const nd)
{
const syntax *const sx = builder->sx;
const item_t id = (item_t) declaration_function_get_id(nd);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужен size_t


ir_emit_statement(builder, &body);

// ir_build_ret(builder, IR_VALUE_VOID);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Код в комментах

Comment on lines +3212 to +3216
const item_t begin_label = ir_add_label(builder, IR_LABEL_KIND_BEGIN_CYCLE);
const item_t end_label = ir_add_label(builder, IR_LABEL_KIND_END);

const item_t old_continue = builder->continue_label;
const item_t old_break = builder->break_label;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, метки тоже можно сделать size_t

Comment on lines 3626 to 3638
static ir_gen_rl_instr_func ir_get_rl_instr_gen(const ir_context *const ctx, const ir_instr *const instr)
{
(void) ctx;

const ir_ic ic = ir_instr_get_ic(instr);

switch (ic)
{
default:
unreachable();
return NULL;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если не надо, то и зачем

Comment on lines 3717 to 3729
static ir_gen_fn_instr_func ir_get_fn_instr_gen(const ir_context *const ctx, const ir_instr *const instr)
{
(void) ctx;

const ir_ic ic = ir_instr_get_ic(instr);

switch (ic)
{
default:
unreachable();
return NULL;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если не надо, то зачем

Comment on lines 1187 to 1188
//const lvalue param_value = create_param_lvalue(i);
//mips_gen_store(enc, value, param_value);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Код в комментах

Comment on lines -3879 to 1519
if (!ws_is_correct(ws) || sx == NULL)
{
return -1;
}
(void) ws;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему удалили?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants