comparison tango/lib/compiler/llvmdc/genobj.d @ 133:44a95ac7368a trunk

[svn r137] Many fixes towards tango.io.Console working, but not quite there yet... In particular, assertions has been fixed to include file/line info, and much more!
author lindquist
date Mon, 14 Jan 2008 05:11:54 +0100
parents 1700239cab2e
children 7816aafeea3c
comparison
equal deleted inserted replaced
132:1700239cab2e 133:44a95ac7368a
35 * Modified by Sean Kelly <sean@f4.ca> for use with Tango. 35 * Modified by Sean Kelly <sean@f4.ca> for use with Tango.
36 */ 36 */
37 37
38 module object; 38 module object;
39 39
40 //debug=PRINTF;
41
40 private 42 private
41 { 43 {
42 import tango.stdc.string; // : memcmp, memcpy; 44 import tango.stdc.string; // : memcmp, memcpy;
43 import tango.stdc.stdlib; // : calloc, realloc, free; 45 import tango.stdc.stdlib; // : calloc, realloc, free;
44 import util.string; 46 import util.string;
960 962
961 // Win32: this gets initialized by minit.asm 963 // Win32: this gets initialized by minit.asm
962 // linux: this gets initialized in _moduleCtor() 964 // linux: this gets initialized in _moduleCtor()
963 extern (C) ModuleInfo[] _moduleinfo_array; 965 extern (C) ModuleInfo[] _moduleinfo_array;
964 966
965 967 // llvmdc method
966 version (linux) 968 extern (C) void** _d_get_moduleinfo_array();
967 {
968 // This linked list is created by a compiler generated function inserted
969 // into the .ctor list by the compiler.
970 struct ModuleReference
971 {
972 ModuleReference* next;
973 ModuleInfo mod;
974 }
975
976 extern (C) ModuleReference* _Dmodule_ref; // start of linked list
977 }
978 969
979 ModuleInfo[] _moduleinfo_dtors; 970 ModuleInfo[] _moduleinfo_dtors;
980 uint _moduleinfo_dtors_i; 971 uint _moduleinfo_dtors_i;
981 972
982 // Register termination function pointers 973 // Register termination function pointers
987 */ 978 */
988 979
989 extern (C) void _moduleCtor() 980 extern (C) void _moduleCtor()
990 { 981 {
991 debug(PRINTF) printf("_moduleCtor()\n"); 982 debug(PRINTF) printf("_moduleCtor()\n");
992 version (linux) 983
993 { 984 ModuleInfo* mrbegin = cast(ModuleInfo*)_d_get_moduleinfo_array();
994 int len = 0; 985 assert(mrbegin !is null);
995 ModuleReference *mr; 986
996 987 int len = 0;
997 for (mr = _Dmodule_ref; mr; mr = mr.next) 988 ModuleInfo* mr;
998 len++; 989 for (mr = mrbegin; *mr !is null; ++mr)
999 _moduleinfo_array = new ModuleInfo[len]; 990 len++;
1000 len = 0; 991 _moduleinfo_array = new ModuleInfo[len];
1001 for (mr = _Dmodule_ref; mr; mr = mr.next) 992
1002 { _moduleinfo_array[len] = mr.mod; 993 len = 0;
1003 len++; 994 for (mr = mrbegin; *mr !is null; ++mr)
1004 } 995 { _moduleinfo_array[len] = *mr;
996 len++;
1005 } 997 }
1006 998
1007 version (Win32) 999 version (Win32)
1008 { 1000 {
1009 // Ensure module destructors also get called on program termination 1001 // Ensure module destructors also get called on program termination
1012 1004
1013 _moduleinfo_dtors = new ModuleInfo[_moduleinfo_array.length]; 1005 _moduleinfo_dtors = new ModuleInfo[_moduleinfo_array.length];
1014 debug(PRINTF) printf("_moduleinfo_dtors = x%x\n", cast(void *)_moduleinfo_dtors); 1006 debug(PRINTF) printf("_moduleinfo_dtors = x%x\n", cast(void *)_moduleinfo_dtors);
1015 _moduleIndependentCtors(); 1007 _moduleIndependentCtors();
1016 _moduleCtor2(_moduleinfo_array, 0); 1008 _moduleCtor2(_moduleinfo_array, 0);
1009 debug(PRINTF) printf("_moduleCtor() DONE\n");
1017 } 1010 }
1018 1011
1019 extern (C) void _moduleIndependentCtors() 1012 extern (C) void _moduleIndependentCtors()
1020 { 1013 {
1021 debug(PRINTF) printf("_moduleIndependentCtors()\n"); 1014 debug(PRINTF) printf("_moduleIndependentCtors()\n");
1024 if (m && m.flags & MIhasictor && m.ictor) 1017 if (m && m.flags & MIhasictor && m.ictor)
1025 { 1018 {
1026 (*m.ictor)(); 1019 (*m.ictor)();
1027 } 1020 }
1028 } 1021 }
1022 debug(PRINTF) printf("_moduleIndependentCtors() DONE\n");
1029 } 1023 }
1030 1024
1031 void _moduleCtor2(ModuleInfo[] mi, int skip) 1025 void _moduleCtor2(ModuleInfo[] mi, int skip)
1032 { 1026 {
1033 debug(PRINTF) printf("_moduleCtor2(): %d modules\n", mi.length); 1027 debug(PRINTF) printf("_moduleCtor2(): %d modules\n", mi.length);
1036 ModuleInfo m = mi[i]; 1030 ModuleInfo m = mi[i];
1037 1031
1038 debug(PRINTF) printf("\tmodule[%d] = '%p'\n", i, m); 1032 debug(PRINTF) printf("\tmodule[%d] = '%p'\n", i, m);
1039 if (!m) 1033 if (!m)
1040 continue; 1034 continue;
1041 debug(PRINTF) printf("\tmodule[%d] = '%.*s'\n", i, m.name); 1035 debug(PRINTF) printf("\tmodule[%d] = '%.*s'\n", i, m.name.length, m.name.ptr);
1042 if (m.flags & MIctordone) 1036 if (m.flags & MIctordone)
1043 continue; 1037 continue;
1044 debug(PRINTF) printf("\tmodule[%d] = '%.*s', m = x%x\n", i, m.name, m); 1038 debug(PRINTF) printf("\tmodule[%d] = '%.*s', m = x%x\n", i, m.name.length, m.name.ptr, m);
1045 1039
1046 if (m.ctor || m.dtor) 1040 if (m.ctor || m.dtor)
1047 { 1041 {
1048 if (m.flags & MIctorstart) 1042 if (m.flags & MIctorstart)
1049 { if (skip || m.flags & MIstandalone) 1043 { if (skip || m.flags & MIstandalone)
1067 { 1061 {
1068 m.flags |= MIctordone; 1062 m.flags |= MIctordone;
1069 _moduleCtor2(m.importedModules, 1); 1063 _moduleCtor2(m.importedModules, 1);
1070 } 1064 }
1071 } 1065 }
1066 debug(PRINTF) printf("_moduleCtor2() DONE\n");
1072 } 1067 }
1073 1068
1074 /** 1069 /**
1075 * Destruct the modules. 1070 * Destruct the modules.
1076 */ 1071 */