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) {...@@ -231,7 +231,7 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) {
231231
232232
233static void render_const_val(CodeGen *g, ConstExprValue *const_val);233static 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
236static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {236static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
237 if (fn_table_entry->llvm_value)237 if (fn_table_entry->llvm_value)
...@@ -686,7 +686,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {...@@ -686,7 +686,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
686 // we might have to do some pointer casting here due to the way union686 // we might have to do some pointer casting here due to the way union
687 // values are rendered with a type other than the one we expect687 // values are rendered with a type other than the one we expect
688 if (handle_is_ptr(instruction->value.type)) {688 if (handle_is_ptr(instruction->value.type)) {
689 render_const_val_global(g, &instruction->value);689 render_const_val_global(g, &instruction->value, "");
690 TypeTableEntry *ptr_type = get_pointer_to_type(g, instruction->value.type, true);690 TypeTableEntry *ptr_type = get_pointer_to_type(g, instruction->value.type, true);
691 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.llvm_global, ptr_type->type_ref, "");691 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.llvm_global, ptr_type->type_ref, "");
692 } else if (instruction->value.type->id == TypeTableEntryIdPointer) {692 } else if (instruction->value.type->id == TypeTableEntryIdPointer) {
...@@ -2425,7 +2425,7 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar...@@ -2425,7 +2425,7 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar
2425 base_ptr = gen_const_ptr_array_recursive(g, parent_array, parent_array_index);2425 base_ptr = gen_const_ptr_array_recursive(g, parent_array, parent_array_index);
2426 } else {2426 } else {
2427 render_const_val(g, array_const_val);2427 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, "");
2429 base_ptr = array_const_val->llvm_global;2429 base_ptr = array_const_val->llvm_global;
2430 }2430 }
2431 TypeTableEntry *usize = g->builtin_types.entry_usize;2431 TypeTableEntry *usize = g->builtin_types.entry_usize;
...@@ -2573,16 +2573,16 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {...@@ -2573,16 +2573,16 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
2573 return fn_llvm_value(g, const_val->data.x_fn);2573 return fn_llvm_value(g, const_val->data.x_fn);
2574 case TypeTableEntryIdPointer:2574 case TypeTableEntryIdPointer:
2575 {2575 {
2576 render_const_val_global(g, const_val);2576 render_const_val_global(g, const_val, "");
2577 size_t index = const_val->data.x_ptr.index;2577 size_t index = const_val->data.x_ptr.index;
2578 ConstExprValue *base_ptr = const_val->data.x_ptr.base_ptr;2578 ConstExprValue *base_ptr = const_val->data.x_ptr.base_ptr;
2579 if (base_ptr) {2579 if (base_ptr) {
2580 if (index == SIZE_MAX) {2580 if (index == SIZE_MAX) {
2581 render_const_val(g, base_ptr);2581 render_const_val(g, base_ptr);
2582 render_const_val_global(g, base_ptr);2582 render_const_val_global(g, base_ptr, "");
2583 ConstExprValue *other_val = base_ptr;2583 ConstExprValue *other_val = base_ptr;
2584 const_val->llvm_value = LLVMConstBitCast(other_val->llvm_global, const_val->type->type_ref);2584 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, "");
2586 return const_val->llvm_value;2586 return const_val->llvm_value;
2587 } else {2587 } else {
2588 ConstExprValue *array_const_val = base_ptr;2588 ConstExprValue *array_const_val = base_ptr;
...@@ -2592,19 +2592,19 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {...@@ -2592,19 +2592,19 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
2592 TypeTableEntry *usize = g->builtin_types.entry_usize;2592 TypeTableEntry *usize = g->builtin_types.entry_usize;
2593 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),2593 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),
2594 const_val->type->type_ref);2594 const_val->type->type_ref);
2595 render_const_val_global(g, const_val);2595 render_const_val_global(g, const_val, "");
2596 return const_val->llvm_value;2596 return const_val->llvm_value;
2597 }2597 }
2598 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, index);2598 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, index);
2599 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, const_val->type->type_ref);2599 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, const_val->type->type_ref);
2600 const_val->llvm_value = ptr_val;2600 const_val->llvm_value = ptr_val;
2601 render_const_val_global(g, const_val);2601 render_const_val_global(g, const_val, "");
2602 return ptr_val;2602 return ptr_val;
2603 }2603 }
2604 } else {2604 } else {
2605 TypeTableEntry *usize = g->builtin_types.entry_usize;2605 TypeTableEntry *usize = g->builtin_types.entry_usize;
2606 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstInt(usize->type_ref, index, false), const_val->type->type_ref);2606 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, "");
2608 return const_val->llvm_value;2608 return const_val->llvm_value;
2609 }2609 }
2610 }2610 }
...@@ -2659,10 +2659,10 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val) {...@@ -2659,10 +2659,10 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val) {
2659 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);2659 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
2660}2660}
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) {
2663 if (!const_val->llvm_global) {2663 if (!const_val->llvm_global) {
2664 LLVMTypeRef type_ref = const_val->llvm_value ? LLVMTypeOf(const_val->llvm_value) : const_val->type->type_ref;2664 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);
2666 LLVMSetLinkage(global_value, LLVMInternalLinkage);2666 LLVMSetLinkage(global_value, LLVMInternalLinkage);
2667 LLVMSetGlobalConstant(global_value, true);2667 LLVMSetGlobalConstant(global_value, true);
2668 LLVMSetUnnamedAddr(global_value, true);2668 LLVMSetUnnamedAddr(global_value, true);
...@@ -2846,7 +2846,7 @@ static void do_code_gen(CodeGen *g) {...@@ -2846,7 +2846,7 @@ static void do_code_gen(CodeGen *g) {
2846 LLVMSetLinkage(global_value, LLVMExternalLinkage);2846 LLVMSetLinkage(global_value, LLVMExternalLinkage);
2847 } else {2847 } else {
2848 render_const_val(g, &var->value);2848 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));
2850 global_value = var->value.llvm_global;2850 global_value = var->value.llvm_global;
28512851
2852 if (var->linkage == VarLinkageExport) {2852 if (var->linkage == VarLinkageExport) {