type_t *from_type, type_t *type)
{
type = skip_typeref(type);
+ if (type == type_void) {
+ /* make sure firm type is constructed */
+ (void) get_ir_type(type);
+ return NULL;
+ }
if (!is_type_scalar(type)) {
/* make sure firm type is constructed */
(void) get_ir_type(type);
/* we're past the last member of the current sub-aggregate, try if we
* can ascend in the type hierarchy and continue with another subobject */
- size_t len = ARR_LEN(path->path);
+ size_t len = ARR_LEN(path->path);
if (len > 1) {
ascend_from_subtype(path);
panic("unknown initializer");
}
-static void create_dynamic_initializer_sub(ir_initializer_t *initializer,
- ir_entity *entity, ir_type *type, dbg_info *dbgi, ir_node *base_addr)
+/** ANSI C §6.7.8:21: If there are fewer initializers [..] than there
+ * are elements [...] the remainder of the aggregate shall be initialized
+ * implicitly the same as objects that have static storage duration. */
+static void create_dynamic_null_initializer(ir_entity *entity, dbg_info *dbgi,
+ ir_node *base_addr)
{
- switch(get_initializer_kind(initializer)) {
- case IR_INITIALIZER_NULL: {
- /* ANSI C §6.7.8:21: If there are fewer initializers [..] than there
- are elements [...] the remainder of the aggregate shall be initialized
- implicitly the same as objects that have static storage duration. */
- ir_type *ent_type = get_entity_type(entity);
- ir_mode *value_mode = get_type_mode(ent_type);
- ir_node *node = new_Const_long(value_mode, 0);
+ /* for unions we must NOT do anything for null initializers */
+ ir_type *owner = get_entity_owner(entity);
+ if (is_Union_type(owner)) {
+ return;
+ }
- /* is it a bitfield type? */
- if (is_Primitive_type(ent_type) &&
- get_primitive_base_type(ent_type) != NULL) {
- bitfield_store_to_firm(dbgi, entity, base_addr, node, false);
- return;
+ ir_type *ent_type = get_entity_type(entity);
+ /* create sub-initializers for a compound type */
+ if (is_compound_type(ent_type)) {
+ unsigned n_members = get_compound_n_members(ent_type);
+ for (unsigned n = 0; n < n_members; ++n) {
+ ir_entity *member = get_compound_member(ent_type, n);
+ ir_node *addr = new_d_simpleSel(dbgi, new_NoMem(), base_addr,
+ member);
+ create_dynamic_null_initializer(member, dbgi, addr);
}
+ return;
+ }
+ if (is_Array_type(ent_type)) {
+ assert(has_array_upper_bound(ent_type, 0));
+ long n = get_array_upper_bound_int(ent_type, 0);
+ for (long i = 0; i < n; ++i) {
+ ir_tarval *index_tv = new_tarval_from_long(i, mode_uint);
+ ir_node *cnst = new_d_Const(dbgi, index_tv);
+ ir_node *in[1] = { cnst };
+ ir_entity *arrent = get_array_element_entity(ent_type);
+ ir_node *addr = new_d_Sel(dbgi, new_NoMem(), base_addr, 1, in,
+ arrent);
+ create_dynamic_null_initializer(arrent, dbgi, addr);
+ }
+ return;
+ }
- assert(get_type_mode(type) == get_irn_mode(node));
- ir_node *mem = get_store();
- ir_node *store = new_d_Store(dbgi, mem, base_addr, node, cons_none);
- ir_node *proj_m = new_Proj(store, mode_M, pn_Store_M);
- set_store(proj_m);
+ ir_mode *value_mode = get_type_mode(ent_type);
+ ir_node *node = new_Const_long(value_mode, 0);
+
+ /* is it a bitfield type? */
+ if (is_Primitive_type(ent_type) &&
+ get_primitive_base_type(ent_type) != NULL) {
+ bitfield_store_to_firm(dbgi, entity, base_addr, node, false);
return;
}
+
+ ir_node *mem = get_store();
+ ir_node *store = new_d_Store(dbgi, mem, base_addr, node, cons_none);
+ ir_node *proj_m = new_Proj(store, mode_M, pn_Store_M);
+ set_store(proj_m);
+}
+
+static void create_dynamic_initializer_sub(ir_initializer_t *initializer,
+ ir_entity *entity, ir_type *type, dbg_info *dbgi, ir_node *base_addr)
+{
+ switch(get_initializer_kind(initializer)) {
+ case IR_INITIALIZER_NULL:
+ create_dynamic_null_initializer(entity, dbgi, base_addr);
+ return;
case IR_INITIALIZER_CONST: {
ir_node *node = get_initializer_const_value(initializer);
ir_type *ent_type = get_entity_type(entity);
ir_node *fallthrough_block = NULL;
/* the true (blocks) */
- ir_node *true_block = NULL;
- if (statement->true_statement != NULL) {
- true_block = new_immBlock();
- set_cur_block(true_block);
- statement_to_firm(statement->true_statement);
- if (get_cur_block() != NULL) {
- ir_node *jmp = new_Jmp();
- if (fallthrough_block == NULL)
- fallthrough_block = new_immBlock();
- add_immBlock_pred(fallthrough_block, jmp);
- }
+ ir_node *const true_block = new_immBlock();
+ set_cur_block(true_block);
+ statement_to_firm(statement->true_statement);
+ if (get_cur_block() != NULL) {
+ ir_node *jmp = new_Jmp();
+ if (fallthrough_block == NULL)
+ fallthrough_block = new_immBlock();
+ add_immBlock_pred(fallthrough_block, jmp);
}
/* the false (blocks) */
/* create the condition */
if (cur_block != NULL) {
- if (true_block == NULL || false_block == NULL) {
+ if (false_block == NULL) {
if (fallthrough_block == NULL)
fallthrough_block = new_immBlock();
- if (true_block == NULL)
- true_block = fallthrough_block;
- if (false_block == NULL)
- false_block = fallthrough_block;
+ false_block = fallthrough_block;
}
set_cur_block(cur_block);
static void while_statement_to_firm(while_statement_t *statement)
{
- ir_node *jmp = NULL;
- if (get_cur_block() != NULL) {
- jmp = new_Jmp();
- }
-
/* create the header block */
ir_node *header_block = new_immBlock();
- if (jmp != NULL) {
+ if (get_cur_block() != NULL) {
+ ir_node *const jmp = new_Jmp();
add_immBlock_pred(header_block, jmp);
}
break_label = old_break_label;
if (get_cur_block() != NULL) {
- jmp = new_Jmp();
+ ir_node *const jmp = new_Jmp();
add_immBlock_pred(header_block, jmp);
}
ir_node *const false_block = new_immBlock();
/* the loop body */
- ir_node *body_block;
- if (statement->body != NULL) {
- ir_node *const old_continue_label = continue_label;
- ir_node *const old_break_label = break_label;
- continue_label = step_block;
- break_label = false_block;
+ ir_node *const old_continue_label = continue_label;
+ ir_node *const old_break_label = break_label;
+ continue_label = step_block;
+ break_label = false_block;
- body_block = new_immBlock();
- set_cur_block(body_block);
- statement_to_firm(statement->body);
+ ir_node *const body_block = new_immBlock();
+ set_cur_block(body_block);
+ statement_to_firm(statement->body);
- assert(continue_label == step_block);
- assert(break_label == false_block);
- continue_label = old_continue_label;
- break_label = old_break_label;
+ assert(continue_label == step_block);
+ assert(break_label == false_block);
+ continue_label = old_continue_label;
+ break_label = old_break_label;
- if (get_cur_block() != NULL) {
- jmp = new_Jmp();
- add_immBlock_pred(step_block, jmp);
- }
- } else {
- body_block = step_block;
+ if (get_cur_block() != NULL) {
+ jmp = new_Jmp();
+ add_immBlock_pred(step_block, jmp);
}
/* create the condition */
set_entity_ld_ident(ptr, new_id_from_chars("", 0));
set_entity_compiler_generated(ptr, 1);
- set_entity_visibility(ptr, ir_visibility_local);
+ set_entity_visibility(ptr, ir_visibility_private);
add_entity_linkage(ptr, IR_LINKAGE_CONSTANT|IR_LINKAGE_HIDDEN_USER);
set_atomic_ent_value(ptr, val);
}