From 7e1042b96de7c3e0126f46ebae693c905a3a4c10 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 14 Feb 2008 14:06:58 +0000 Subject: [PATCH] implement compound literals (ineficient code at the moment) [r18853] --- ast2firm.c | 15 +++++++++++++-- parsetest/shouldfail/init2.c | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 parsetest/shouldfail/init2.c diff --git a/ast2firm.c b/ast2firm.c index 5fd9b57..1f81df3 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -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 index 0000000..9e2b90a --- /dev/null +++ b/parsetest/shouldfail/init2.c @@ -0,0 +1,5 @@ +struct S { + int a, b; +}; + +struct S arr[] = { { 1, 2, { 3, 4 } } }; -- 2.20.1