diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-22 22:02:07 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-22 22:02:07 -0700 |
| commit | 523e3b86af44b97bcf68e3eb0956ef297421ee10 (patch) | |
| tree | 61b3743aced3715ebc8f811cc3477fca45d0ad20 /src | |
| parent | 21fc5a6402c527675900397ea60f107730985f1c (diff) | |
| download | zig-523e3b86af44b97bcf68e3eb0956ef297421ee10.tar.gz zig-523e3b86af44b97bcf68e3eb0956ef297421ee10.zip | |
support statically initialized array literal
Diffstat (limited to 'src')
| -rw-r--r-- | src/analyze.cpp | 20 | ||||
| -rw-r--r-- | src/codegen.cpp | 10 |
2 files changed, 18 insertions, 12 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 56eb138a65..cc061a6b85 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -34,8 +34,6 @@ static AstNode *first_executing_node(AstNode *node) { return first_executing_node(node->data.field_access_expr.struct_expr); case NodeTypeSwitchRange: return first_executing_node(node->data.switch_range.start); - case NodeTypeContainerInitExpr: - return first_executing_node(node->data.container_init_expr.type); case NodeTypeRoot: case NodeTypeRootExportDecl: case NodeTypeFnProto: @@ -72,6 +70,7 @@ static AstNode *first_executing_node(AstNode *node) { case NodeTypeSwitchExpr: case NodeTypeSwitchProng: case NodeTypeArrayType: + case NodeTypeContainerInitExpr: return node; } zig_unreachable(); @@ -1586,9 +1585,22 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry assert(pointer_type->id == TypeTableEntryIdPointer); TypeTableEntry *child_type = pointer_type->data.pointer.child_type; + ConstExprValue *const_val = &get_resolved_expr(node)->const_val; + const_val->ok = true; + const_val->data.x_array.fields = allocate<ConstExprValue*>(elem_count); + for (int i = 0; i < elem_count; i += 1) { - AstNode *elem_node = container_init_expr->entries.at(i); - analyze_expression(g, import, context, child_type, elem_node); + AstNode **elem_node = &container_init_expr->entries.at(i); + analyze_expression(g, import, context, child_type, *elem_node); + + if (const_val->ok) { + ConstExprValue *elem_const_val = &get_resolved_expr(*elem_node)->const_val; + if (elem_const_val->ok) { + const_val->data.x_array.fields[i] = elem_const_val; + } else { + const_val->ok = false; + } + } } TypeTableEntry *fixed_size_array_type = get_array_type(g, child_type, elem_count); diff --git a/src/codegen.cpp b/src/codegen.cpp index 467740e946..6a5008b94e 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2105,13 +2105,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE return tag_value; } else { zig_panic("TODO"); - /* - LLVMValueRef fields[] = { - tag_value, - union_value, - }; - return LLVMConstStruct(fields, 2, false); - */ } } else if (type_entry->id == TypeTableEntryIdFn) { return const_val->data.x_fn->fn_value; @@ -2197,10 +2190,11 @@ static void do_code_gen(CodeGen *g) { } else { init_val = LLVMConstNull(var->type->type_ref); } - LLVMValueRef global_value = LLVMAddGlobal(g->module, LLVMTypeOf(init_val), ""); + LLVMValueRef global_value = LLVMAddGlobal(g->module, LLVMTypeOf(init_val), buf_ptr(&var->name)); LLVMSetInitializer(global_value, init_val); LLVMSetGlobalConstant(global_value, var->is_const); LLVMSetUnnamedAddr(global_value, true); + LLVMSetLinkage(global_value, LLVMInternalLinkage); var->value_ref = global_value; } |
