static const backend_params *be_params;
static ir_type *ir_type_char;
-static ir_type *ir_type_wchar_t;
/* architecture specific floating point arithmetic mode (if any) */
static ir_mode *mode_float_arithmetic;
ir_initializer_t *const initializer = create_initializer_compound(slen);
ir_type * elem_type;
switch (value->encoding) {
- case STRING_ENCODING_CHAR: {
+ case STRING_ENCODING_CHAR:
+ case STRING_ENCODING_UTF8: {
elem_type = ir_type_char;
ir_mode *const mode = get_type_mode(elem_type);
goto finish;
}
- case STRING_ENCODING_WIDE: {
- elem_type = ir_type_wchar_t;
+ {
+ type_t *type;
+ case STRING_ENCODING_CHAR16: type = type_char16_t; goto init_wide;
+ case STRING_ENCODING_CHAR32: type = type_char32_t; goto init_wide;
+ case STRING_ENCODING_WIDE: type = type_wchar_t; goto init_wide;
+init_wide:;
+ elem_type = get_ir_type(type);
ir_mode *const mode = get_type_mode(elem_type);
char const *p = value->begin;
}
/**
- * Keep all memory edges of the given block.
+ * Keep the current block and memory.
+ * This is necessary for all loops, because they could become infinite.
*/
-static void keep_all_memory(ir_node *block)
+static void keep_loop(void)
{
- ir_node *old = get_cur_block();
-
- set_cur_block(block);
+ keep_alive(get_cur_block());
keep_alive(get_store());
- /* TODO: keep all memory edges from restricted pointers */
- set_cur_block(old);
}
static ir_node *enum_constant_to_firm(reference_expression_t const *const ref)
static ir_node *conditional_to_firm(const conditional_expression_t *expression)
{
- dbg_info *const dbgi = get_dbg_info(&expression->base.source_position);
-
/* first try to fold a constant condition */
if (is_constant_expression(expression->condition) == EXPR_CLASS_CONSTANT) {
bool val = fold_constant_to_bool(expression->condition);
ir_node *const false_val = expression_to_firm(expression->false_expression);
jump_to_target(&exit_target);
if (val) {
- ir_node *const in[] = { val, false_val };
+ ir_node *const in[] = { val, false_val };
+ dbg_info *const dbgi = get_dbg_info(&expression->base.source_position);
val = new_rd_Phi(dbgi, exit_target.block, lengthof(in), in, get_irn_mode(val));
} else {
val = false_val;
break;
}
- dbg_info *dbgi = get_dbg_info(&expression->base.source_position);
- ir_node *cond_expr = _expression_to_firm(expression);
- ir_node *condition = create_conv(dbgi, cond_expr, mode_b);
- ir_node *cond = new_d_Cond(dbgi, condition);
- ir_node *true_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_true);
- ir_node *false_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_false);
-
- /* set branch prediction info based on __builtin_expect */
- if (is_builtin_expect(expression) && is_Cond(cond)) {
- call_argument_t *argument = expression->call.arguments->next;
- if (is_constant_expression(argument->expression) == EXPR_CLASS_CONSTANT) {
- bool const cnst = fold_constant_to_bool(argument->expression);
- cond_jmp_predicate const pred = cnst ? COND_JMP_PRED_TRUE : COND_JMP_PRED_FALSE;
- set_Cond_jmp_pred(cond, pred);
+ ir_node *cond_expr = _expression_to_firm(expression);
+ if (is_Const(cond_expr)) {
+ if (tarval_is_null(get_Const_tarval(cond_expr))) {
+ jump_to_target(false_target);
+ } else {
+ jump_to_target(true_target);
+ }
+ } else {
+ dbg_info *dbgi = get_dbg_info(&expression->base.source_position);
+ ir_node *condition = create_conv(dbgi, cond_expr, mode_b);
+ ir_node *cond = new_d_Cond(dbgi, condition);
+ ir_node *true_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_true);
+ ir_node *false_proj = new_d_Proj(dbgi, cond, mode_X, pn_Cond_false);
+
+ /* set branch prediction info based on __builtin_expect */
+ if (is_builtin_expect(expression) && is_Cond(cond)) {
+ call_argument_t *argument = expression->call.arguments->next;
+ if (is_constant_expression(argument->expression) == EXPR_CLASS_CONSTANT) {
+ bool const cnst = fold_constant_to_bool(argument->expression);
+ cond_jmp_predicate const pred = cnst ? COND_JMP_PRED_TRUE : COND_JMP_PRED_FALSE;
+ set_Cond_jmp_pred(cond, pred);
+ }
}
- }
-
- add_pred_to_jump_target(true_target, true_proj);
- add_pred_to_jump_target(false_target, false_proj);
+ add_pred_to_jump_target(true_target, true_proj);
+ add_pred_to_jump_target(false_target, false_proj);
+ }
set_unreachable_now();
return cond_expr;
}
static ir_initializer_t *create_ir_initializer_value(
const initializer_value_t *initializer)
{
- if (is_type_compound(initializer->value->base.type)) {
- panic("initializer creation for compounds not implemented yet");
- }
- type_t *type = initializer->value->base.type;
expression_t *expr = initializer->value;
+ type_t *type = expr->base.type;
+
+ if (is_type_compound(type)) {
+ if (expr->kind == EXPR_UNARY_CAST) {
+ expr = expr->unary.value;
+ type = expr->base.type;
+ }
+ /* must be a compound literal... */
+ if (expr->kind != EXPR_COMPOUND_LITERAL)
+ panic("initializer creation for compounds needs compound literals");
+ return create_ir_initializer(expr->compound_literal.initializer, type);
+ }
+
ir_node *value = expression_to_firm(expr);
ir_mode *mode = get_ir_mode_storage(type);
value = create_conv(NULL, value, mode);
}
if (sub_initializer->kind == INITIALIZER_VALUE) {
- /* we might have to descend into types until we're at a scalar
- * type */
+ const expression_t *expr = sub_initializer->value.value;
+ const type_t *expr_type = skip_typeref(expr->base.type);
+ /* we might have to descend into types until the types match */
while(true) {
type_t *orig_top_type = path.top_type;
type_t *top_type = skip_typeref(orig_top_type);
- if (is_type_scalar(top_type))
+ if (types_compatible(top_type, expr_type))
break;
descend_into_subtype(&path);
}
char const * p = str->value.begin;
switch (str->value.encoding) {
case STRING_ENCODING_CHAR:
+ case STRING_ENCODING_UTF8:
for (size_t i = 0; i != arr_len; ++i) {
char const c = i < str_len ? *p++ : 0;
ir_tarval *const tv = new_tarval_from_long(c, mode);
}
break;
+ case STRING_ENCODING_CHAR16:
+ case STRING_ENCODING_CHAR32:
case STRING_ENCODING_WIDE:
for (size_t i = 0; i != arr_len; ++i) {
utf32 const c = i < str_len ? read_utf8_char(&p) : 0;
init_jump_target(&body_target, NULL);
jump_to_target(&body_target);
enter_immature_jump_target(&body_target);
+ keep_loop();
statement_to_firm(statement->body);
jump_to_target(&continue_target);
if (enter_jump_target(&continue_target))
init_jump_target(&header_target, NULL);
jump_to_target(&header_target);
enter_immature_jump_target(&header_target);
+ keep_loop();
expression_t *const step = statement->step;
PUSH_BREAK(NULL);
init_jump_target(&body_target, NULL);
create_condition_evaluation(cond, &body_target, &break_target);
enter_jump_target(&body_target);
- } else {
- /* for-ever. */
- keep_alive(header_target.block);
- keep_all_memory(header_target.block);
}
/* Create the loop body. */
enter_jump_target(&label->target);
} else {
enter_immature_jump_target(&label->target);
- keep_alive(label->target.block);
- keep_all_memory(label->target.block);
+ keep_loop();
}
return statement_to_firm(statement->statement);
}
if (enter_jump_target(&ijmp_target)) {
+ keep_loop();
size_t const n = ARR_LEN(ijmp_ops);
ir_node *const op = n == 1 ? ijmp_ops[0] : new_Phi(n, ijmp_ops, get_irn_mode(ijmp_ops[0]));
ir_node *const ijmp = new_IJmp(op);
return;
ir_types_initialized = 1;
- ir_type_char = get_ir_type(type_char);
- ir_type_wchar_t = get_ir_type(type_wchar_t);
+ ir_type_char = get_ir_type(type_char);
be_params = be_get_backend_param();
mode_float_arithmetic = be_params->mode_float_arithmetic;