Mercurial > projects > ldc
comparison tango/lib/compiler/llvmdc/genobj.d @ 323:0d52412d5b1a trunk
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
Changed the way moduleinfo is registered to use the same approach as DMD, this eliminates the need for correct linking order and should make the way for using a natively compiled runtime library. This should speed up linking tremendously and should now be possible.
Fixed the llvm.used array to only be emitted if really necessary.
author | lindquist |
---|---|
date | Wed, 09 Jul 2008 23:43:51 +0200 |
parents | 665b81613475 |
children |
comparison
equal
deleted
inserted
replaced
322:1aaf6ff7f685 | 323:0d52412d5b1a |
---|---|
1011 return ret; | 1011 return ret; |
1012 } | 1012 } |
1013 } | 1013 } |
1014 | 1014 |
1015 | 1015 |
1016 // Win32: this gets initialized by minit.asm | 1016 // this gets initialized in _moduleCtor() |
1017 // linux: this gets initialized in _moduleCtor() | |
1018 extern (C) ModuleInfo[] _moduleinfo_array; | 1017 extern (C) ModuleInfo[] _moduleinfo_array; |
1019 | 1018 |
1020 // llvmdc method | 1019 // This linked list is created by a compiler generated function inserted |
1021 extern (C) void** _d_get_moduleinfo_array(); | 1020 // into the .ctor list by the compiler. |
1022 | 1021 struct ModuleReference |
1022 { | |
1023 ModuleReference* next; | |
1024 ModuleInfo mod; | |
1025 } | |
1026 extern (C) ModuleReference* _Dmodule_ref; // start of linked list | |
1027 | |
1028 // this list is built from the linked list above | |
1023 ModuleInfo[] _moduleinfo_dtors; | 1029 ModuleInfo[] _moduleinfo_dtors; |
1024 uint _moduleinfo_dtors_i; | 1030 uint _moduleinfo_dtors_i; |
1025 | |
1026 // Register termination function pointers | |
1027 extern (C) int _fatexit(void *); | |
1028 | 1031 |
1029 /** | 1032 /** |
1030 * Initialize the modules. | 1033 * Initialize the modules. |
1031 */ | 1034 */ |
1032 | 1035 |
1033 extern (C) void _moduleCtor() | 1036 extern (C) void _moduleCtor() |
1034 { | 1037 { |
1035 debug(PRINTF) printf("_moduleCtor()\n"); | 1038 debug(PRINTF) printf("_moduleCtor()\n"); |
1036 | 1039 |
1037 ModuleInfo* mrbegin = cast(ModuleInfo*)_d_get_moduleinfo_array(); | |
1038 assert(mrbegin !is null); | |
1039 | |
1040 int len = 0; | 1040 int len = 0; |
1041 ModuleInfo* mr; | 1041 ModuleReference *mr; |
1042 for (mr = mrbegin; *mr !is null; ++mr) | 1042 |
1043 for (mr = _Dmodule_ref; mr; mr = mr.next) | |
1043 len++; | 1044 len++; |
1044 _moduleinfo_array = new ModuleInfo[len]; | 1045 _moduleinfo_array = new ModuleInfo[len]; |
1045 | |
1046 len = 0; | 1046 len = 0; |
1047 for (mr = mrbegin; *mr !is null; ++mr) | 1047 for (mr = _Dmodule_ref; mr; mr = mr.next) |
1048 { _moduleinfo_array[len] = *mr; | 1048 { _moduleinfo_array[len] = mr.mod; |
1049 len++; | 1049 len++; |
1050 } | |
1051 | |
1052 version (Win32) | |
1053 { | |
1054 // Ensure module destructors also get called on program termination | |
1055 //_fatexit(&_STD_moduleDtor); | |
1056 } | 1050 } |
1057 | 1051 |
1058 _moduleinfo_dtors = new ModuleInfo[_moduleinfo_array.length]; | 1052 _moduleinfo_dtors = new ModuleInfo[_moduleinfo_array.length]; |
1059 debug(PRINTF) printf("_moduleinfo_dtors = x%x\n", cast(void *)_moduleinfo_dtors); | 1053 debug(PRINTF) printf("_moduleinfo_dtors = x%x\n", cast(void *)_moduleinfo_dtors); |
1060 _moduleIndependentCtors(); | 1054 _moduleIndependentCtors(); |
1061 _moduleCtor2(_moduleinfo_array, 0); | 1055 _moduleCtor2(_moduleinfo_array, 0); |
1062 debug(PRINTF) printf("_moduleCtor() DONE\n"); | |
1063 } | 1056 } |
1064 | 1057 |
1065 extern (C) void _moduleIndependentCtors() | 1058 extern (C) void _moduleIndependentCtors() |
1066 { | 1059 { |
1067 debug(PRINTF) printf("_moduleIndependentCtors()\n"); | 1060 debug(PRINTF) printf("_moduleIndependentCtors()\n"); |