elna/gcc/elna-tree.cc

127 lines
3.7 KiB
C++
Raw Normal View History

2024-12-29 22:28:53 +01:00
#include "elna/gcc/elna-tree.h"
#include "elna/gcc/elna-diagnostic.h"
2024-12-29 22:28:53 +01:00
2025-01-01 23:02:19 +01:00
#include "stor-layout.h"
#include "fold-const.h"
#include "diagnostic-core.h"
2025-01-01 23:02:19 +01:00
2024-12-29 22:28:53 +01:00
tree elna_global_trees[ELNA_TI_MAX];
2025-01-01 23:02:19 +01:00
2025-01-03 22:18:35 +01:00
namespace elna
2025-01-01 23:02:19 +01:00
{
2025-01-03 22:18:35 +01:00
namespace gcc
{
void init_ttree()
{
elna_string_type_node = build_pointer_type(
build_qualified_type(char_type_node, TYPE_QUAL_CONST)); /* const char* */
}
2025-01-10 23:17:18 +01:00
bool is_pointer_type(tree type)
2025-01-03 22:18:35 +01:00
{
gcc_assert(TYPE_P(type));
2025-01-10 23:17:18 +01:00
return TREE_CODE(type) == POINTER_TYPE;
}
bool are_compatible_pointers(tree lhs, tree rhs)
{
return (lhs == null_pointer_node || rhs == null_pointer_node)
&& is_pointer_type(TREE_TYPE(lhs)) && is_pointer_type(TREE_TYPE(rhs));
}
2025-01-04 20:24:34 +01:00
tree tree_chain_base::head()
{
return first;
}
void tree_chain_base::append(tree t)
{
gcc_assert(t != NULL_TREE);
if (this->first == NULL_TREE)
{
this->first = this->last = t;
}
else
{
chain(t);
this->last = t;
}
}
void tree_chain::chain(tree t)
{
TREE_CHAIN(this->last) = t;
}
tree_symbol_mapping::tree_symbol_mapping(tree bind_expression, tree block)
: m_bind_expression(bind_expression), m_block(block)
{
}
tree tree_symbol_mapping::bind_expression()
{
return m_bind_expression;
}
tree tree_symbol_mapping::block()
{
return m_block;
}
2025-01-31 09:46:17 +01:00
std::shared_ptr<boot::symbol_table<tree>> builtin_symbol_table()
{
2025-01-31 09:46:17 +01:00
std::shared_ptr<boot::symbol_table<tree>> initial_table =
std::make_shared<boot::symbol_table<tree>>();
initial_table->enter("Int", boot::make_info(long_integer_type_node));
initial_table->enter("Word", boot::make_info(size_type_node));
initial_table->enter("Bool", boot::make_info(boolean_type_node));
initial_table->enter("Float", boot::make_info(double_type_node));
2025-02-01 09:21:29 +01:00
initial_table->enter("Char", boot::make_info(unsigned_char_type_node));
initial_table->enter("Byte", boot::make_info(make_unsigned_type(8)));
2025-01-31 09:46:17 +01:00
initial_table->enter("String", boot::make_info(elna_string_type_node));
2025-01-18 21:30:11 +01:00
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;
}
tree build_binary_operation(bool condition, boot::binary_expression *expression,
tree_code operator_code, tree left, tree right, tree target_type)
{
location_t expression_location = get_location(&expression->position());
tree left_type = TREE_TYPE(left);
tree right_type = TREE_TYPE(right);
if (condition)
{
return build2_loc(expression_location, operator_code, target_type, left, right);
}
else
{
error_at(expression_location,
"invalid operands of type %s and %s for operator %s",
print_type(left_type), print_type(right_type),
elna::boot::print_binary_operator(expression->operation()));
return error_mark_node;
}
}
2025-01-03 22:18:35 +01:00
}
2025-01-01 23:02:19 +01:00
}