implement compound literals (ineficient code at the moment)
authorMatthias Braun <matze@braunis.de>
Thu, 14 Feb 2008 14:06:58 +0000 (14:06 +0000)
committerMatthias Braun <matze@braunis.de>
Thu, 14 Feb 2008 14:06:58 +0000 (14:06 +0000)
[r18853]

ast2firm.c
parsetest/shouldfail/init2.c [new file with mode: 0644]

index 5fd9b57..1f81df3 100644 (file)
@@ -2315,14 +2315,19 @@ static ir_node *offsetof_to_firm(const offsetof_expression_t *expression)
        return new_d_Const(dbgi, mode, tv);
 }
 
+static void create_local_initializer(initializer_t *initializer, dbg_info *dbgi,
+                                     ir_entity *entity, type_t *type);
+
 static ir_node *compound_literal_to_firm(
                const compound_literal_expression_t *expression)
 {
+       type_t *type = expression->type;
+
        /* create an entity on the stack */
        ir_type *frame_type = get_irg_frame_type(current_ir_graph);
 
        ident     *const id     = unique_ident("CompLit");
-       ir_type   *const irtype = get_ir_type(expression->type);
+       ir_type   *const irtype = get_ir_type(type);
        dbg_info  *const dbgi   = get_dbg_info(&expression->base.source_position);
        ir_entity *const entity = new_d_entity(frame_type, id, irtype, dbgi);
        set_entity_ld_ident(entity, id);
@@ -2330,7 +2335,13 @@ static ir_node *compound_literal_to_firm(
        set_entity_variability(entity, variability_uninitialized);
 
        /* create initialisation code TODO */
-       return NULL;
+       initializer_t *initializer = expression->initializer;
+       create_local_initializer(initializer, dbgi, entity, type);
+
+       /* create a sel for the compound literal address */
+       ir_node   *frame = get_local_frame(entity);
+       ir_node   *sel   = new_d_simpleSel(dbgi, new_NoMem(), frame, entity);
+       return sel;
 }
 
 /**
diff --git a/parsetest/shouldfail/init2.c b/parsetest/shouldfail/init2.c
new file mode 100644 (file)
index 0000000..9e2b90a
--- /dev/null
@@ -0,0 +1,5 @@
+struct S {
+       int a, b;
+};
+
+struct S arr[] = { { 1, 2, { 3, 4 } } };