more work on firm backend
[cparser] / ast2firm.c
index b125728..5f6d81e 100644 (file)
@@ -68,11 +68,12 @@ void init_ast2firm(void)
        type_void       = make_atomic_type(ATOMIC_TYPE_VOID, 0);
        type_int        = make_atomic_type(ATOMIC_TYPE_INT, 0);
 
+       ir_type_int        = get_ir_type(type_int);
        ir_type_const_char = get_ir_type(type_const_char);
-       ir_type_void       = get_ir_type(type_void);
+       ir_type_void       = get_ir_type(type_int); /* we don't have a real void
+                                                      type in firm */
        ir_type_void_ptr   = new_type_pointer(new_id_from_str("void_ptr"),
                                              ir_type_void, mode_P_data);
-       ir_type_int        = get_ir_type(type_int);
 }
 
 void exit_ast2firm(void)
@@ -524,7 +525,88 @@ static inline ir_mode *get_ir_mode(type_t *type)
        return mode;
 }
 
-int dummy(void)
+static ir_entity* get_entity_function(declaration_t *declaration)
+{
+       if(declaration->entity != NULL)
+               return declaration->entity;
+
+       symbol_t *symbol = declaration->symbol;
+       ident    *id     = new_id_from_str(symbol->string);
+
+       ir_type  *global_type    = get_glob_type();
+       ir_type  *ir_type_method = get_ir_type(declaration->type);
+       assert(is_Method_type(ir_type_method));
+
+       type_t    *type   = declaration->type;
+       ir_entity *entity = new_entity(global_type, id, ir_type_method);
+       set_entity_ld_ident(entity, id);
+       if(declaration->storage_class & STORAGE_CLASS_STATIC
+                       || type->qualifiers & TYPE_QUALIFIER_INLINE) {
+               set_entity_visibility(entity, visibility_local);
+       } else if(declaration->init.statement != NULL) {
+               set_entity_visibility(entity, visibility_external_visible);
+       } else {
+               set_entity_visibility(entity, visibility_external_allocated);
+       }
+
+       declaration->entity = entity;
+       return entity;
+}
+
+static void statement_to_firm(statement_t *statement)
+{
+       (void) statement;
+       (void) get_type_size;
+       /* TODO */
+}
+
+static int get_function_n_local_vars(declaration_t *declaration)
+{
+       (void) declaration;
+       /* TODO */
+       return 30;
+}
+
+static void create_function(declaration_t *declaration)
+{
+       ir_entity *entity = get_entity_function(declaration);
+
+       //context2firm(declaration->context);
+
+       if(declaration->init.statement) {
+               int        n_local_vars = get_function_n_local_vars(declaration);
+               ir_graph  *irg          = new_ir_graph(entity, n_local_vars);
+               ir_node   *first_block  = get_cur_block();
+
+               statement_to_firm(declaration->init.statement);
+
+               ir_node *end_block = get_irg_end_block(irg);
+
+               /* do we have a return statement yet? */
+               if(get_cur_block() != NULL) {
+                       ir_node *ret = new_Return(get_store(), 0, NULL);
+                       add_immBlock_pred(end_block, ret);
+               }
+
+               mature_immBlock(first_block);
+               mature_immBlock(end_block);
+       }
+}
+
+static void context_to_firm(context_t *context)
+{
+       declaration_t *declaration = context->declarations;
+       for( ; declaration != NULL; declaration = declaration->next) {
+               type_t *type = declaration->type;
+               if(type->type == TYPE_METHOD) {
+                       create_function(declaration);
+               } else {
+                       /* TODO... */
+               }
+       }
+}
+
+void translation_unit_to_firm(translation_unit_t *unit)
 {
-       return get_type_size(type_int);
+       context_to_firm(& unit->context);
 }