authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-03 16:27:24-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-03 16:27:24-05:00
log67b02326f88805df8bbda5e93d1cf46e40c48862
treea26915853f491c5eb20ecac7c42a3d491aa47078
parentd3f1889951fa37332f67556a0a253128a710f23c

preserve names of exported variables


1 files changed, 12 insertions(+), 12 deletions(-)

src/codegen.cpp+12-12
......@@ -231,7 +231,7 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) {
231231
232232
233233static void render_const_val(CodeGen *g, ConstExprValue *const_val);
234static void render_const_val_global(CodeGen *g, ConstExprValue *const_val);
234static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name);
235235
236236static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
237237 if (fn_table_entry->llvm_value)
......@@ -686,7 +686,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
686686 // we might have to do some pointer casting here due to the way union
687687 // values are rendered with a type other than the one we expect
688688 if (handle_is_ptr(instruction->value.type)) {
689 render_const_val_global(g, &instruction->value);
689 render_const_val_global(g, &instruction->value, "");
690690 TypeTableEntry *ptr_type = get_pointer_to_type(g, instruction->value.type, true);
691691 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.llvm_global, ptr_type->type_ref, "");
692692 } else if (instruction->value.type->id == TypeTableEntryIdPointer) {
......@@ -2425,7 +2425,7 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar
24252425 base_ptr = gen_const_ptr_array_recursive(g, parent_array, parent_array_index);
24262426 } else {
24272427 render_const_val(g, array_const_val);
2428 render_const_val_global(g, array_const_val);
2428 render_const_val_global(g, array_const_val, "");
24292429 base_ptr = array_const_val->llvm_global;
24302430 }
24312431 TypeTableEntry *usize = g->builtin_types.entry_usize;
......@@ -2573,16 +2573,16 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
25732573 return fn_llvm_value(g, const_val->data.x_fn);
25742574 case TypeTableEntryIdPointer:
25752575 {
2576 render_const_val_global(g, const_val);
2576 render_const_val_global(g, const_val, "");
25772577 size_t index = const_val->data.x_ptr.index;
25782578 ConstExprValue *base_ptr = const_val->data.x_ptr.base_ptr;
25792579 if (base_ptr) {
25802580 if (index == SIZE_MAX) {
25812581 render_const_val(g, base_ptr);
2582 render_const_val_global(g, base_ptr);
2582 render_const_val_global(g, base_ptr, "");
25832583 ConstExprValue *other_val = base_ptr;
25842584 const_val->llvm_value = LLVMConstBitCast(other_val->llvm_global, const_val->type->type_ref);
2585 render_const_val_global(g, const_val);
2585 render_const_val_global(g, const_val, "");
25862586 return const_val->llvm_value;
25872587 } else {
25882588 ConstExprValue *array_const_val = base_ptr;
......@@ -2592,19 +2592,19 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
25922592 TypeTableEntry *usize = g->builtin_types.entry_usize;
25932593 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),
25942594 const_val->type->type_ref);
2595 render_const_val_global(g, const_val);
2595 render_const_val_global(g, const_val, "");
25962596 return const_val->llvm_value;
25972597 }
25982598 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, index);
25992599 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, const_val->type->type_ref);
26002600 const_val->llvm_value = ptr_val;
2601 render_const_val_global(g, const_val);
2601 render_const_val_global(g, const_val, "");
26022602 return ptr_val;
26032603 }
26042604 } else {
26052605 TypeTableEntry *usize = g->builtin_types.entry_usize;
26062606 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstInt(usize->type_ref, index, false), const_val->type->type_ref);
2607 render_const_val_global(g, const_val);
2607 render_const_val_global(g, const_val, "");
26082608 return const_val->llvm_value;
26092609 }
26102610 }
......@@ -2659,10 +2659,10 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val) {
26592659 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
26602660}
26612661
2662static void render_const_val_global(CodeGen *g, ConstExprValue *const_val) {
2662static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name) {
26632663 if (!const_val->llvm_global) {
26642664 LLVMTypeRef type_ref = const_val->llvm_value ? LLVMTypeOf(const_val->llvm_value) : const_val->type->type_ref;
2665 LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, "");
2665 LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, name);
26662666 LLVMSetLinkage(global_value, LLVMInternalLinkage);
26672667 LLVMSetGlobalConstant(global_value, true);
26682668 LLVMSetUnnamedAddr(global_value, true);
......@@ -2846,7 +2846,7 @@ static void do_code_gen(CodeGen *g) {
28462846 LLVMSetLinkage(global_value, LLVMExternalLinkage);
28472847 } else {
28482848 render_const_val(g, &var->value);
2849 render_const_val_global(g, &var->value);
2849 render_const_val_global(g, &var->value, buf_ptr(&var->name));
28502850 global_value = var->value.llvm_global;
28512851
28522852 if (var->linkage == VarLinkageExport) {