diff options
| author | gingerBill <bill@gingerbill.org> | 2020-03-26 15:56:08 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-03-26 15:56:08 +0000 |
| commit | 7909872877fd5c82c29df711f160838a7a4e59e1 (patch) | |
| tree | 64184c011253bf986bc48333ad3344f2f6d4abfc /src/ir.cpp | |
| parent | 0a920b5439a66c08dedd4bfbef76223bd8fb8a13 (diff) | |
Allow referencing a compound literal to act like C99
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 8a36be1f5..9fb7b54da 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -138,6 +138,7 @@ struct irProcedure { bool is_foreign; bool is_export; bool is_entry_point; + bool is_startup; irDebugInfo * debug_scope; @@ -7257,7 +7258,20 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { switch (ue->op.kind) { case Token_And: { Ast *ue_expr = unparen_expr(ue->expr); - if (ue_expr->kind == Ast_TypeAssertion) { + if (ue_expr->kind == Ast_CompoundLit) { + irValue *v = ir_build_expr(proc, ue->expr); + + Type *type = ir_type(v); + irValue *ptr = nullptr; + if (proc->is_startup) { + ptr = ir_add_global_generated(proc->module, type, v); + } else { + ptr = ir_add_local_generated(proc, type, false); + } + ir_emit_store(proc, ptr, v); + return ptr; + + } else if (ue_expr->kind == Ast_TypeAssertion) { gbAllocator a = ir_allocator(); GB_ASSERT(is_type_pointer(tv.type)); @@ -12094,6 +12108,7 @@ void ir_gen_tree(irGen *s) { Ast *body = alloc_ast_node(nullptr, Ast_Invalid); Entity *e = alloc_entity_procedure(nullptr, make_token_ident(name), proc_type, 0); irValue *p = ir_value_procedure(m, e, proc_type, nullptr, body, name); + p->Proc.is_startup = true; map_set(&m->values, hash_entity(e), p); map_set(&m->members, hash_string(name), p); @@ -12174,6 +12189,7 @@ void ir_gen_tree(irGen *s) { Ast *body = alloc_ast_node(nullptr, Ast_Invalid); Entity *e = alloc_entity_procedure(nullptr, make_token_ident(name), proc_type, 0); irValue *p = ir_value_procedure(m, e, proc_type, nullptr, body, name); + p->Proc.is_startup = true; map_set(&m->values, hash_entity(e), p); map_set(&m->members, hash_string(name), p); @@ -12272,6 +12288,7 @@ void ir_gen_tree(irGen *s) { Ast *body = alloc_ast_node(nullptr, Ast_Invalid); Entity *e = alloc_entity_procedure(nullptr, make_token_ident(name), proc_type, 0); irValue *p = ir_value_procedure(m, e, proc_type, nullptr, body, name); + p->Proc.is_startup = true; m->entry_point_entity = e; @@ -12309,6 +12326,7 @@ void ir_gen_tree(irGen *s) { Ast *body = alloc_ast_node(nullptr, Ast_Invalid); Entity *e = alloc_entity_procedure(nullptr, make_token_ident(name), proc_type, 0); irValue *p = ir_value_procedure(m, e, proc_type, nullptr, body, name); + p->Proc.is_startup = true; map_set(&m->values, hash_entity(e), p); map_set(&m->members, hash_string(name), p); |