diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2015-12-14 23:49:56 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2015-12-14 23:49:56 -0700 |
| commit | 4dc2b8250638efda3a9990182f46ad57c403b28b (patch) | |
| tree | 25ced26eb3a257753ac0b877326eea82697960d1 /src/codegen.cpp | |
| parent | 83b68c9f13c90dfbbd2735cde4ef570ac50476c0 (diff) | |
| download | zig-4dc2b8250638efda3a9990182f46ad57c403b28b.tar.gz zig-4dc2b8250638efda3a9990182f46ad57c403b28b.zip | |
constant initializers allow simple expressions
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 6b1b3428ee..1d0e669411 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -103,6 +103,8 @@ static int count_non_void_params(CodeGen *g, ZigList<AstNode *> *params) { } static void add_debug_source_node(CodeGen *g, AstNode *node) { + if (!g->cur_block_context) + return; LLVMZigSetCurrentDebugLocation(g->builder, node->line + 1, node->column + 1, g->cur_block_context->di_scope); } @@ -1040,12 +1042,16 @@ static void do_code_gen(CodeGen *g) { for (int i = 0; i < g->global_vars.length; i += 1) { VariableTableEntry *var = g->global_vars.at(i); - LLVMValueRef init_val = gen_expr(g, var->decl_node->data.variable_declaration.expr); - // TODO if the global is exported, set external linkage - LLVMValueRef global_value = LLVMAddGlobal(g->module, LLVMTypeOf(init_val), ""); + LLVMValueRef global_value = LLVMAddGlobal(g->module, var->type->type_ref, ""); LLVMSetLinkage(global_value, LLVMPrivateLinkage); - LLVMSetInitializer(global_value, init_val); + + if (var->is_const) { + LLVMValueRef init_val = gen_expr(g, var->decl_node->data.variable_declaration.expr); + LLVMSetInitializer(global_value, init_val); + } else { + LLVMSetInitializer(global_value, LLVMConstNull(var->type->type_ref)); + } LLVMSetGlobalConstant(global_value, var->is_const); LLVMSetUnnamedAddr(global_value, true); |
