initial implementation of builtin_object_size
authorMatthias Braun <matze@braunis.de>
Tue, 12 Oct 2010 22:17:53 +0000 (22:17 +0000)
committerMatthias Braun <matze@braunis.de>
Tue, 12 Oct 2010 22:17:53 +0000 (22:17 +0000)
[r28112]

ast2firm.c
parser.c

index fe9aa08..6082e67 100644 (file)
@@ -1884,6 +1884,22 @@ static ir_node *process_builtin_call(const call_expression_t *call)
                set_store(new_Proj(irn, mode_M, pn_Builtin_M));
                return NULL;
        }
+       case bk_gnu_builtin_object_size: {
+               /* determine value of "type" */
+               expression_t *type_expression = call->arguments->next->expression;
+               long          type_val        = fold_constant_to_int(type_expression);
+               type_t       *type            = function_type->function.return_type;
+               ir_mode      *mode            = get_ir_mode_arithmetic(type);
+               ir_tarval    *result;
+
+               /* just produce a "I don't know" result */
+               if (type_val & 2)
+                       result = new_tarval_from_long(0, mode);
+               else
+                       result = new_tarval_from_long(-1, mode);
+
+               return new_d_Const(dbgi, result);
+       }
        case bk_gnu_builtin_trap:
        case bk_ms__ud2:
        {
index 0174b5b..e0a7cc4 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -7421,8 +7421,21 @@ static void handle_builtin_argument_restrictions(call_expression_t *call) {
                        }
                        break;
                }
-               case bk_gnu_builtin_prefetch: {
+               case bk_gnu_builtin_object_size:
+                       if (call->arguments == NULL)
+                               break;
+
+                       call_argument_t *arg = call->arguments->next;
+                       if (arg != NULL && ! is_constant_expression(arg->expression)) {
+                               errorf(&call->base.source_position,
+                                          "second argument of '%Y' must be a constant expression",
+                                          call->function->reference.entity->base.symbol);
+                       }
+                       break;
+               case bk_gnu_builtin_prefetch:
                        /* second and third argument must be constant if existent */
+                       if (call->arguments == NULL)
+                               break;
                        call_argument_t *rw = call->arguments->next;
                        call_argument_t *locality = NULL;
 
@@ -7443,7 +7456,6 @@ static void handle_builtin_argument_restrictions(call_expression_t *call) {
                                locality = rw->next;
                        }
                        break;
-               }
                default:
                        break;
        }