-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: feature
Are you sure you want to change the base?
Добавить поддержку IR. #374
Conversation
9842f62
to
6908dcb
Compare
6908dcb
to
10e50c7
Compare
libs/compiler/ir.h
Outdated
* значения, используемые в инструкциях функций. Фактически эквивалентен единице | ||
* трансляции. | ||
*/ | ||
typedef struct ir_module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А где очистка
…valuation with this.
e99b82e
to
34d741f
Compare
static extern_data create_extern_data(const item_t id, const item_t type) | ||
{ | ||
return (extern_data) { | ||
.id = id, | ||
.type = type | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как-нибудь отделить static
libs/compiler/ir.c
Outdated
static char* ir_imm_value_get_string(const ir_value *const value) | ||
{ | ||
(void) value; | ||
return NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что-то странное
static item_t ir_value_save(const ir_value *const value) | ||
{ | ||
return (item_t) node_save(value); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем преобразование
libs/compiler/ir.c
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрать
libs/compiler/ir.c
Outdated
ir_instr instr = create_ir_instr(&function, ic, op1, op2, res); | ||
(void) instr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем заводить переменную?
libs/compiler/ir.c
Outdated
|
||
static item_t ir_build_ptr(ir_builder *const builder, const item_t type, const item_t base, const size_t displ) | ||
{ | ||
(void) displ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
libs/compiler/ir.c
Outdated
{ | ||
|
||
break; | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тоже
libs/compiler/ir.c
Outdated
const item_t type = expression_get_type(nd); | ||
|
||
(void) type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зочем
const item_t return_type = type_function_get_return_type(sx, expression_get_type(&callee)); | ||
(void) return_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зочем
libs/compiler/ir.c
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно else не ставить
libs/compiler/ir.c
Outdated
{ | ||
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Комменты с кодом удалять
const node operand = expression_unary_get_operand(nd); | ||
|
||
(void) operand; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зочем
libs/compiler/ir.c
Outdated
{ | ||
if (type_is_integer(sx, lhs_type) && type_is_integer(sx, rhs_type)) | ||
{ | ||
//printf("%d %d\n", lhs, rhs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Код в комментах
libs/compiler/ir.c
Outdated
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
без else
const syntax *const sx = builder->sx; | ||
(void) sx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зочем
const item_t rhs_type = expression_get_type(&rhs); | ||
(void) rhs_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зочем
libs/compiler/ir.c
Outdated
// 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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужен size_t
libs/compiler/ir.c
Outdated
|
||
ir_emit_statement(builder, &body); | ||
|
||
// ir_build_ret(builder, IR_VALUE_VOID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Код в комментах
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, метки тоже можно сделать size_t
libs/compiler/ir.c
Outdated
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если не надо, то и зачем
libs/compiler/ir.c
Outdated
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если не надо, то зачем
libs/compiler/mipsgen.c
Outdated
//const lvalue param_value = create_param_lvalue(i); | ||
//mips_gen_store(enc, value, param_value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Код в комментах
if (!ws_is_correct(ws) || sx == NULL) | ||
{ | ||
return -1; | ||
} | ||
(void) ws; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А почему удалили?
Реализовал часть основных IR функций. Этот PR не влияет на существующие методы генерации, он содержит только код потенциально применимый для построения этого дерева, чтобы ничего не сломать из существующего.