adapt to latest firm (no need to explicitely invoke switch lowerer, backend does...
[cparser] / ast2firm.c
index 12764a8..28542d7 100644 (file)
@@ -129,7 +129,7 @@ static void enqueue_inner_function(entity_t *entity)
        ARR_APP1(entity_t*, inner_functions, entity);
 }
 
-ir_node *uninitialized_local_var(ir_graph *irg, ir_mode *mode, int pos)
+static ir_node *uninitialized_local_var(ir_graph *irg, ir_mode *mode, int pos)
 {
        const entity_t *entity = get_irg_loc_description(irg, pos);
 
@@ -868,11 +868,11 @@ static const struct {
        { rts_strncmp,    1, "strncmp",      3, _C89 },
        { rts_strcpy,     1, "strcpy",       2, _C89 },
        { rts_strlen,     1, "strlen",       1, _C89 },
-       { rts_memcpy,     1, "memcpy",       3, _C89 },  /* HMM, man say its C99 */
+       { rts_memcpy,     1, "memcpy",       3, _C89 },
        { rts_mempcpy,    1, "mempcpy",      3, _GNUC },
-       { rts_memmove,    1, "memmove",      3, _C89 },  /* HMM, man say its C99 */
-       { rts_memset,     1, "memset",       3, _C89 },  /* HMM, man say its C99 */
-       { rts_memcmp,     1, "memcmp",       3, _C89 },  /* HMM, man say its C99 */
+       { rts_memmove,    1, "memmove",      3, _C89 },
+       { rts_memset,     1, "memset",       3, _C89 },
+       { rts_memcmp,     1, "memcmp",       3, _C89 },
 };
 
 static ident *rts_idents[lengthof(rts_data)];
@@ -1026,6 +1026,22 @@ static ir_entity *get_function_entity(entity_t *entity, ir_type *owner_type)
                        if (id != rts_idents[i])
                                continue;
 
+                       function_type_t *function_type
+                               = &entity->declaration.type->function;
+                       /* rts_entities code can't handle a "wrong" number of parameters */
+                       if (function_type->unspecified_parameters)
+                               continue;
+
+                       /* check number of parameters */
+                       int n_params = count_parameters(function_type);
+                       if (n_params != rts_data[i].n_params)
+                               continue;
+
+                       type_t *return_type = skip_typeref(function_type->return_type);
+                       int     n_res       = return_type != type_void ? 1 : 0;
+                       if (n_res != rts_data[i].n_res)
+                               continue;
+
                        /* ignore those rts functions not necessary needed for current mode */
                        if ((c_mode & rts_data[i].flags) == 0)
                                continue;
@@ -1747,7 +1763,7 @@ static ir_node *process_builtin_call(const call_expression_t *call)
        type_t *type = skip_typeref(builtin->base.type);
        assert(is_type_pointer(type));
 
-       type_t   *function_type = skip_typeref(type->pointer.points_to);
+       type_t *function_type = skip_typeref(type->pointer.points_to);
 
        switch (builtin->entity->function.btk) {
        case bk_gnu_builtin_alloca: {
@@ -1816,7 +1832,6 @@ static ir_node *process_builtin_call(const call_expression_t *call)
                }
        }
        case bk_gnu_builtin_return_address: {
-
                expression_t *const expression = call->arguments->expression;
                ir_node *in[2];
 
@@ -1947,6 +1962,7 @@ static ir_node *call_expression_to_firm(const call_expression_t *const call)
                                return process_builtin_call(call);
                        }
 
+#if 0
                        if (irentity == rts_entities[rts_alloca]) {
                                /* handle alloca() call */
                                expression_t *argument = call->arguments->expression;
@@ -1964,6 +1980,7 @@ static ir_node *call_expression_to_firm(const call_expression_t *const call)
 
                                return res;
                        }
+#endif
                }
        }
        ir_node *callee = expression_to_firm(function);
@@ -4256,7 +4273,7 @@ static void create_dynamic_initializer_sub(ir_initializer_t *initializer,
                return;
        }
        case IR_INITIALIZER_COMPOUND: {
-               assert(is_compound_type(type));
+               assert(is_compound_type(type) || is_Array_type(type));
                int n_members;
                if (is_Array_type(type)) {
                        assert(has_array_upper_bound(type, 0));
@@ -4631,7 +4648,7 @@ static ir_node *compound_statement_to_firm(compound_statement_t *compound)
 
 static void create_global_variable(entity_t *entity)
 {
-       ir_linkage    linkage    = 0;
+       ir_linkage    linkage    = IR_LINKAGE_DEFAULT;
        ir_visibility visibility = ir_visibility_default;
        ir_entity    *irentity;
        assert(entity->kind == ENTITY_VARIABLE);
@@ -5475,7 +5492,7 @@ static void asm_statement_to_firm(const asm_statement_t *statement)
 
        /* create output projs & connect them */
        if (needs_memory) {
-               ir_node *projm = new_Proj(node, mode_M, out_size+1);
+               ir_node *projm = new_Proj(node, mode_M, out_size);
                set_store(projm);
        }
 
@@ -5918,7 +5935,7 @@ static void create_function(entity_t *entity)
        set_type_size_bytes(frame_type, offset);
        set_type_alignment_bytes(frame_type, align_all);
 
-       irg_vrfy(irg);
+       irg_verify(irg, VERIFY_ENFORCE_SSA);
        current_function = old_current_function;
 
        if (current_trampolines != NULL) {
@@ -6062,6 +6079,7 @@ void translation_unit_to_firm(translation_unit_t *unit)
 {
        /* initialize firm arithmetic */
        tarval_set_integer_overflow_mode(TV_OVERFLOW_WRAP);
+       ir_set_uninitialized_local_variable_func(uninitialized_local_var);
 
        /* just to be sure */
        continue_label           = NULL;