| ... | @@ -287,6 +287,15 @@ pub fn supportsTailCall(target: std.Target) bool { | ... | @@ -287,6 +287,15 @@ pub fn supportsTailCall(target: std.Target) bool { |
| 287 | } | 287 | } |
| 288 | } | 288 | } |
| 289 | | 289 | |
| | 290 | /// TODO can this be done with simpler logic / different API binding? |
| | 291 | fn deleteLlvmGlobal(llvm_global: *const llvm.Value) void { |
| | 292 | if (llvm_global.globalGetValueType().getTypeKind() == .Function) { |
| | 293 | llvm_global.deleteFunction(); |
| | 294 | return; |
| | 295 | } |
| | 296 | return llvm_global.deleteGlobal(); |
| | 297 | } |
| | 298 | |
| 290 | pub const Object = struct { | 299 | pub const Object = struct { |
| 291 | gpa: Allocator, | 300 | gpa: Allocator, |
| 292 | module: *Module, | 301 | module: *Module, |
| ... | @@ -640,7 +649,7 @@ pub const Object = struct { | ... | @@ -640,7 +649,7 @@ pub const Object = struct { |
| 640 | | 649 | |
| 641 | const new_global_ptr = other_global.constBitCast(llvm_global.typeOf()); | 650 | const new_global_ptr = other_global.constBitCast(llvm_global.typeOf()); |
| 642 | llvm_global.replaceAllUsesWith(new_global_ptr); | 651 | llvm_global.replaceAllUsesWith(new_global_ptr); |
| 643 | object.deleteLlvmGlobal(llvm_global); | 652 | deleteLlvmGlobal(llvm_global); |
| 644 | entry.value_ptr.* = new_global_ptr; | 653 | entry.value_ptr.* = new_global_ptr; |
| 645 | } | 654 | } |
| 646 | object.extern_collisions.clearRetainingCapacity(); | 655 | object.extern_collisions.clearRetainingCapacity(); |
| ... | @@ -666,7 +675,7 @@ pub const Object = struct { | ... | @@ -666,7 +675,7 @@ pub const Object = struct { |
| 666 | const new_global_ptr = llvm_global.constBitCast(other_global.typeOf()); | 675 | const new_global_ptr = llvm_global.constBitCast(other_global.typeOf()); |
| 667 | other_global.replaceAllUsesWith(new_global_ptr); | 676 | other_global.replaceAllUsesWith(new_global_ptr); |
| 668 | llvm_global.takeName(other_global); | 677 | llvm_global.takeName(other_global); |
| 669 | other_global.deleteGlobal(); | 678 | deleteLlvmGlobal(other_global); |
| 670 | // Problem: now we need to replace in the decl_map that | 679 | // Problem: now we need to replace in the decl_map that |
| 671 | // the extern decl index points to this new global. However we don't | 680 | // the extern decl index points to this new global. However we don't |
| 672 | // know the decl index. | 681 | // know the decl index. |
| ... | @@ -1184,15 +1193,6 @@ pub const Object = struct { | ... | @@ -1184,15 +1193,6 @@ pub const Object = struct { |
| 1184 | return null; | 1193 | return null; |
| 1185 | } | 1194 | } |
| 1186 | | 1195 | |
| 1187 | /// TODO can this be done with simpler logic / different API binding? | | |
| 1188 | fn deleteLlvmGlobal(o: Object, llvm_global: *const llvm.Value) void { | | |
| 1189 | if (o.llvm_module.getNamedFunction(llvm_global.getValueName()) != null) { | | |
| 1190 | llvm_global.deleteFunction(); | | |
| 1191 | return; | | |
| 1192 | } | | |
| 1193 | return llvm_global.deleteGlobal(); | | |
| 1194 | } | | |
| 1195 | | | |
| 1196 | pub fn updateDeclExports( | 1196 | pub fn updateDeclExports( |
| 1197 | self: *Object, | 1197 | self: *Object, |
| 1198 | module: *Module, | 1198 | module: *Module, |
| ... | @@ -1287,7 +1287,7 @@ pub const Object = struct { | ... | @@ -1287,7 +1287,7 @@ pub const Object = struct { |
| 1287 | alias.setAliasee(llvm_global); | 1287 | alias.setAliasee(llvm_global); |
| 1288 | } else { | 1288 | } else { |
| 1289 | _ = self.llvm_module.addAlias( | 1289 | _ = self.llvm_module.addAlias( |
| 1290 | llvm_global.typeOf(), | 1290 | llvm_global.globalGetValueType(), |
| 1291 | 0, | 1291 | 0, |
| 1292 | llvm_global, | 1292 | llvm_global, |
| 1293 | exp_name_z, | 1293 | exp_name_z, |