Skip to content

Commit

Permalink
Merge branch 'llvm'
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor-Y-Fadeev committed Mar 10, 2022
2 parents d201925 + 8fd38ed commit 1815454
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ llvm-intel:
- apt-get update
- apt-get install -y build-essential cmake clang-11 gcc-mipsel-linux-gnu
script:
- ln -s /usr/bin/clang++-11 /usr/bin/clang++
- patch ./scripts/test.sh < ./scripts/llvm.patch
- ./scripts/test.sh -d
- ./scripts/test.sh

llvm-baikal:
stage: llvm
Expand Down
90 changes: 68 additions & 22 deletions libs/compiler/llvmgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1865,33 +1865,66 @@ static void emit_initialization(information *const info, const node *const nd, c
{
const size_t N = node_get_type(nd) == OP_INITIALIZER ? expression_initializer_get_size(nd) : SIZE_MAX;

for (size_t i = 0; i < N && N != SIZE_MAX; i++)
if (ident_is_local(info->sx, (size_t)id))
{
const node initializer = expression_initializer_get_subexpr(nd, i);
const item_t type = expression_get_type(&initializer);
for (size_t i = 0; i < N && N != SIZE_MAX; i++)
{
const node initializer = expression_initializer_get_subexpr(nd, i);
const item_t type = expression_get_type(&initializer);

const size_t member_reg = (size_t)info->register_num;
uni_printf(info->sx->io, " %%.%zu = getelementptr inbounds %%struct_opt.%" PRIitem ", "
"%%struct_opt.%" PRIitem "* %%var.%" PRIitem ", i32 0, i32 %zu\n", info->register_num, arr_type, arr_type
, id, i);
info->register_num++;
const size_t member_reg = (size_t)info->register_num;
uni_printf(info->sx->io, " %%.%zu = getelementptr inbounds %%struct_opt.%" PRIitem
", %%struct_opt.%" PRIitem "* %%var.%" PRIitem ", i32 0, i32 %zu\n"
, info->register_num, arr_type, arr_type, id, i);
info->register_num++;

emit_expression(info, &initializer);
emit_expression(info, &initializer);

if (info->answer_kind == AREG)
{
to_code_store_reg(info, info->answer_reg, member_reg, type, true, false, true);
}
// константа типа int
else if (type_is_integer(info->sx, type))
{
to_code_store_const_integer(info, info->answer_const, member_reg, true, true, type);
if (info->answer_kind == AREG)
{
to_code_store_reg(info, info->answer_reg, member_reg, type, true, false, true);
}
// константа типа int
else if (type_is_integer(info->sx, type))
{
to_code_store_const_integer(info, info->answer_const, member_reg, true, true, type);
}
// константа типа double
else
{
to_code_store_const_double(info, info->answer_const_double, member_reg, true, true);
}
}
// константа типа double
else
}
else
{
uni_printf(info->sx->io, "global %%struct_opt.%" PRIitem " { ", arr_type);

for (size_t i = 0; i < N && N != SIZE_MAX; i++)
{
to_code_store_const_double(info, info->answer_const_double, member_reg, true, true);
const node initializer = expression_initializer_get_subexpr(nd, i);
const item_t type = expression_get_type(&initializer);

emit_expression(info, &initializer);

if (i != 0)
{
uni_printf(info->sx->io, ", ");
}

// константа типа int
if (type_is_integer(info->sx, type))
{
uni_printf(info->sx->io, "i32 %" PRIitem, info->answer_const);
}
// константа типа double
else
{
uni_printf(info->sx->io, "double %f", info->answer_const_double);
}
}

uni_printf(info->sx->io, " }, align 4\n");
}
}
else if (expression_get_class(nd) == EXPR_CALL && type_is_structure(info->sx, expression_get_type(nd)))
Expand Down Expand Up @@ -2000,6 +2033,14 @@ static void emit_variable_declaration(information *const info, const node *const
{
info->variable_location = LFREE;

if (type_is_structure(info->sx, type))
{
const node initializer = declaration_variable_get_initializer(nd);
emit_initialization(info, &initializer, id, type);

return;
}

const node initializer = declaration_variable_get_initializer(nd);
emit_expression(info, &initializer);

Expand Down Expand Up @@ -2563,12 +2604,17 @@ static void emit_switch_statement(information *const info, const node *const nd)
uni_printf(info->sx->io, " %%.%zu, label %%label%zu [\n", info->answer_reg, info->label_switch - case_num - has_default);
for (size_t i = 0; i < case_num; i++)
{
uni_printf(info->sx->io, " i32 %" PRIitem ", label %%label%zu\n", case_values[i], info->label_switch - i);
uni_printf(info->sx->io, " ");
type_to_io(info, expression_get_type(&condition));
uni_printf(info->sx->io, " %" PRIitem ", label %%label%zu\n", case_values[i], info->label_switch - i);
}
uni_printf(info->sx->io, " ]\n");

info->label_break = info->label_switch - case_num - has_default;
emit_statement(info, &body);
if (statement_get_class(&body) == STMT_COMPOUND)
{
emit_compound_statement(info, &body, true);
}
to_code_label(info, info->label_break);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/llvm.patch
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
+ || $path != $dir_syntax/* || $path != $dir_multiple_errors/* || $path != $dir_unsorted/* ]] && [[ $path != */$subdir_no_llvm/* ]] ; then
action="compiling"
- run $compiler $compiler_debug $sources -o $vm_exec -VM
+ run $compiler $compiler_debug $sources -LLVM -o $vm_exec && clang-11 $vm_exec -o $llvm_exec &>$log
+ run $compiler $compiler_debug $sources -LLVM -o $vm_exec && clang++ $vm_exec -o $llvm_exec &>$log

case $? in
0)

0 comments on commit 1815454

Please sign in to comment.