- 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) {
- add_immBlock_pred(header_block, jmp);
- }
-
- /* the false block */
- ir_node *false_block = new_immBlock();
-
- /* the loop body */
- ir_node *body_block;
- if (statement->body != NULL) {
- ir_node *old_continue_label = continue_label;
- ir_node *old_break_label = break_label;
- continue_label = header_block;
- break_label = false_block;
-
- body_block = new_immBlock();
- statement_to_firm(statement->body);
-
- assert(continue_label == header_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(header_block, jmp);
- }
- } else {
- body_block = header_block;
- }
-
- /* create the condition */
- set_cur_block(header_block);
-
- create_condition_evaluation(statement->condition, body_block, false_block);
- mature_immBlock(body_block);
- mature_immBlock(false_block);
- mature_immBlock(header_block);
-
- set_cur_block(false_block);
-}
-
-static void do_while_statement_to_firm(do_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();
-
- /* the false block */
- ir_node *false_block = new_immBlock();
-
- /* the loop body */
- ir_node *body_block = new_immBlock();
- if(jmp != NULL) {
- add_immBlock_pred(body_block, jmp);
- }
-
- if (statement->body != NULL) {
- ir_node *old_continue_label = continue_label;
- ir_node *old_break_label = break_label;
- continue_label = header_block;
- break_label = false_block;
-
- statement_to_firm(statement->body);
-
- assert(continue_label == header_block);
- assert(break_label == false_block);
- continue_label = old_continue_label;
- break_label = old_break_label;
-
- if (get_cur_block() == NULL) {
- mature_immBlock(header_block);
- mature_immBlock(body_block);
- mature_immBlock(false_block);
- return;
- }
- }
-
- ir_node *body_jmp = new_Jmp();
- add_immBlock_pred(header_block, body_jmp);
- mature_immBlock(header_block);
-
- /* create the condition */
- set_cur_block(header_block);
-
- create_condition_evaluation(statement->condition, body_block, false_block);
- mature_immBlock(body_block);
- mature_immBlock(false_block);
- mature_immBlock(header_block);
-
- set_cur_block(false_block);
-}
-
-static void for_statement_to_firm(for_statement_t *statement)
-{
- ir_node *jmp = NULL;
- if (get_cur_block() != NULL) {
- if(statement->initialisation != NULL) {
- expression_to_firm(statement->initialisation);
- }
- jmp = new_Jmp();
- }
-
- /* create the step block */
- ir_node *const step_block = new_immBlock();
- if (statement->step != NULL) {
- expression_to_firm(statement->step);
- }
- ir_node *const step_jmp = new_Jmp();
-
- /* create the header block */
- ir_node *const header_block = new_immBlock();
- if (jmp != NULL) {
- add_immBlock_pred(header_block, jmp);
- }
- add_immBlock_pred(header_block, step_jmp);
-
- /* the false block */
- 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;
-
- body_block = new_immBlock();
- 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;
-
- if (get_cur_block() != NULL) {
- jmp = new_Jmp();
- add_immBlock_pred(step_block, jmp);
- }
- } else {
- body_block = step_block;
- }
-
- /* create the condition */
- set_cur_block(header_block);
- if (statement->condition != NULL) {
- create_condition_evaluation(statement->condition, body_block,
- false_block);
- } else {
- keep_alive(header_block);
- jmp = new_Jmp();
- add_immBlock_pred(body_block, jmp);
- }
-
- mature_immBlock(body_block);
- mature_immBlock(false_block);
- mature_immBlock(step_block);
- mature_immBlock(header_block);
- mature_immBlock(false_block);
-
- set_cur_block(false_block);
-}
-
-static void create_declaration_entity(declaration_t *declaration,
- declaration_type_t declaration_type,
- ir_type *parent_type)
-{
- ident *id = new_id_from_str(declaration->symbol->string);
- ir_type *irtype = get_ir_type(declaration->type);
- ir_entity *entity = new_entity(parent_type, id, irtype);
- set_entity_ld_ident(entity, id);
-
- declaration->declaration_type = (unsigned char) declaration_type;
- declaration->v.entity = entity;
- set_entity_variability(entity, variability_uninitialized);
- /* TODO: visibility? */
-}
-
-typedef struct compound_graph_path_entry_t compound_graph_path_entry_t;
-
-enum compound_graph_entry_type_t {
- COMPOUND_GRAPH_ENTRY_ARRAY,
- COMPOUND_GRAPH_ENTRY_COMPOUND
-};
-
-struct compound_graph_path_entry_t {
- int type;
- union {
- ir_entity *entity;
- int array_index;
- } v;
- compound_graph_path_entry_t *prev;
-};
-
-static void create_initializer_object(initializer_t *initializer, type_t *type,
- ir_entity *entity, compound_graph_path_entry_t *entry, int len);
-
-static compound_graph_path *create_compound_path(ir_type *type,
- compound_graph_path_entry_t *entry, int len)
-{
- compound_graph_path *path = new_compound_graph_path(type, len);
-
- int i = len - 1;
- for( ; entry != NULL; entry = entry->prev, --i) {
- assert(i >= 0);
- if(entry->type == COMPOUND_GRAPH_ENTRY_COMPOUND) {
- set_compound_graph_path_node(path, i, entry->v.entity);
- } else {
- assert(entry->type == COMPOUND_GRAPH_ENTRY_ARRAY);
- set_compound_graph_path_array_index(path, i, entry->v.array_index);
- }
- }
- assert(i == -1);
-
- return path;
-}
-
-static void create_initializer_value(initializer_value_t *initializer,
- ir_entity *entity,
- compound_graph_path_entry_t *entry,
- int len)
-{
- ir_node *node = expression_to_firm(initializer->value);
- ir_type *type = get_entity_type(entity);
- compound_graph_path *path = create_compound_path(type, entry, len);
- add_compound_ent_value_w_path(entity, node, path);
-}
-
-static void create_initializer_compound(initializer_list_t *initializer,
- compound_type_t *type,
- ir_entity *entity,
- compound_graph_path_entry_t *last_entry,
- int len)
-{
- declaration_t *compound_declaration = type->declaration;
-
- declaration_t *compound_entry = compound_declaration->context.declarations;
-
- compound_graph_path_entry_t entry;
- entry.type = COMPOUND_GRAPH_ENTRY_COMPOUND;
- entry.prev = last_entry;
- ++len;
-
- size_t i = 0;
- for( ; compound_entry != NULL; compound_entry = compound_entry->next) {
- if(compound_entry->symbol == NULL)
- continue;
- if(compound_entry->namespc != NAMESPACE_NORMAL)
- continue;
-
- if(i >= initializer->len)
- break;
-
- entry.v.entity = compound_entry->v.entity;
-
- initializer_t *sub_initializer = initializer->initializers[i];
-
- assert(compound_entry != NULL);
- assert(compound_entry->declaration_type
- == DECLARATION_TYPE_COMPOUND_MEMBER);
-
- if(sub_initializer->type == INITIALIZER_VALUE) {
- create_initializer_value(&sub_initializer->value,
- entity, &entry, len);
- } else {
- type_t *entry_type = skip_typeref(compound_entry->type);
- create_initializer_object(sub_initializer, entry_type, entity,
- &entry, len);
- }
-
- ++i;
- }
-}
-
-static void create_initializer_array(initializer_list_t *initializer,
- array_type_t *type, ir_entity *entity,
- compound_graph_path_entry_t *last_entry,
- int len)
-{
- type_t *element_type = type->element_type;
- element_type = skip_typeref(element_type);
-
- compound_graph_path_entry_t entry;
- entry.type = COMPOUND_GRAPH_ENTRY_ARRAY;
- entry.prev = last_entry;
- ++len;
-
- size_t i;
- for(i = 0; i < initializer->len; ++i) {
- entry.v.array_index = i;
-
- initializer_t *sub_initializer = initializer->initializers[i];
-
- if(sub_initializer->type == INITIALIZER_VALUE) {
- create_initializer_value(&sub_initializer->value,
- entity, &entry, len);
- } else {
- create_initializer_object(sub_initializer, element_type, entity,
- &entry, len);
- }
- }
-
-#if 0
- /* TODO: initialize rest... */
- if(type->size_expression != NULL) {
- size_t array_len = fold_constant(type->size_expression);
- for( ; i < array_len; ++i) {
-
- }
- }
-#endif
-}
-
-static void create_initializer_string(initializer_string_t *initializer,
- array_type_t *type, ir_entity *entity,
- compound_graph_path_entry_t *last_entry,
- int len)
-{
- type_t *element_type = type->element_type;
- element_type = skip_typeref(element_type);