Read the input filename from the command line

This commit is contained in:
2025-02-02 08:22:40 +01:00
parent b41d6fb907
commit ae6c7095d5
4 changed files with 73 additions and 46 deletions

View File

@ -303,24 +303,26 @@ namespace gcc
void generic_visitor::visit(boot::binary_expression *expression)
{
expression->lhs().accept(this);
auto left = this->current_expression;
auto left_type = TREE_TYPE(left);
tree left = this->current_expression;
tree left_type = TREE_TYPE(left);
expression->rhs().accept(this);
auto right = this->current_expression;
auto right_type = TREE_TYPE(right);
tree right = this->current_expression;
tree right_type = TREE_TYPE(right);
auto expression_location = get_location(&expression->position());
location_t expression_location = get_location(&expression->position());
tree_code operator_code = ERROR_MARK;
tree target_type = error_mark_node;
if (is_pointer_type(left_type) && is_integral_type(right_type)
&& expression->operation() == boot::binary_operator::sum)
if (is_pointer_type(left_type) && is_integral_type(right_type))
{
tree convert_expression = build1_loc(expression_location, CONVERT_EXPR,
sizetype, right);
this->current_expression = build2_loc(expression_location,
POINTER_PLUS_EXPR, left_type, left, convert_expression);
this->current_expression = do_pointer_arithmetic(expression->operation(), left, right);
if (this->current_expression == error_mark_node)
{
error_at(expression_location,
"invalid operation %s on a pointer and an integral type",
boot::print_binary_operator(expression->operation()));
}
return;
}
if (left_type != right_type)

View File

@ -1,6 +1,7 @@
#include "elna/gcc/elna-tree.h"
#include "stor-layout.h"
#include "fold-const.h"
tree elna_global_trees[ELNA_TI_MAX];
@ -81,5 +82,22 @@ namespace gcc
return initial_table;
}
tree do_pointer_arithmetic(boot::binary_operator binary_operator, tree left, tree right)
{
tree result = error_mark_node;
tree convert_expression = fold_convert(sizetype, right);
if (binary_operator == boot::binary_operator::sum)
{
result = fold_build2(POINTER_PLUS_EXPR, TREE_TYPE(left), left, convert_expression);
}
else if (binary_operator == boot::binary_operator::subtraction)
{
convert_expression = fold_build1(NEGATE_EXPR, sizetype, convert_expression);
result = fold_build2(POINTER_PLUS_EXPR, TREE_TYPE(left), left, convert_expression);
}
return result;
}
}
}