comparison gen/llvmhelpers.cpp @ 1148:3d1b16dabd25

Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Fri, 27 Mar 2009 21:50:32 +0100
parents dbe4af57b240
children 3cf0066e6faf
comparison
equal deleted inserted replaced
1147:dbe4af57b240 1148:3d1b16dabd25
864 864
865 ////////////////////////////////////////////////////////////////////////////////////////// 865 //////////////////////////////////////////////////////////////////////////////////////////
866 866
867 void DtoDeclareDsymbol(Dsymbol* dsym) 867 void DtoDeclareDsymbol(Dsymbol* dsym)
868 { 868 {
869 DtoResolveDsymbol(dsym);
870
869 if (StructDeclaration* sd = dsym->isStructDeclaration()) { 871 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
870 DtoDeclareStruct(sd); 872 DtoDeclareStruct(sd);
871 } 873 }
872 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { 874 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
873 DtoDeclareClass(cd); 875 DtoDeclareClass(cd);
886 888
887 ////////////////////////////////////////////////////////////////////////////////////////// 889 //////////////////////////////////////////////////////////////////////////////////////////
888 890
889 void DtoConstInitDsymbol(Dsymbol* dsym) 891 void DtoConstInitDsymbol(Dsymbol* dsym)
890 { 892 {
893 DtoDeclareDsymbol(dsym);
894
891 if (StructDeclaration* sd = dsym->isStructDeclaration()) { 895 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
892 DtoConstInitStruct(sd); 896 DtoConstInitStruct(sd);
893 } 897 }
894 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { 898 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
895 DtoConstInitClass(cd); 899 DtoConstInitClass(cd);
908 912
909 ////////////////////////////////////////////////////////////////////////////////////////// 913 //////////////////////////////////////////////////////////////////////////////////////////
910 914
911 void DtoDefineDsymbol(Dsymbol* dsym) 915 void DtoDefineDsymbol(Dsymbol* dsym)
912 { 916 {
917 DtoConstInitDsymbol(dsym);
918
913 if (StructDeclaration* sd = dsym->isStructDeclaration()) { 919 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
914 DtoDefineStruct(sd); 920 DtoDefineStruct(sd);
915 } 921 }
916 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { 922 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
917 DtoDefineClass(cd); 923 DtoDefineClass(cd);
918 } 924 }
919 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { 925 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
920 DtoDefineFunction(fd); 926 Type::sir->addFunctionBody(fd->ir.irFunc);
921 } 927 }
922 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) { 928 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
923 DtoDefineTypeInfo(fd); 929 DtoDefineTypeInfo(fd);
924 } 930 }
925 else { 931 else {
930 936
931 ////////////////////////////////////////////////////////////////////////////////////////// 937 //////////////////////////////////////////////////////////////////////////////////////////
932 938
933 void DtoConstInitGlobal(VarDeclaration* vd) 939 void DtoConstInitGlobal(VarDeclaration* vd)
934 { 940 {
941 vd->codegen(Type::sir);
942
935 if (vd->ir.initialized) return; 943 if (vd->ir.initialized) return;
936 vd->ir.initialized = gIR->dmodule; 944 vd->ir.initialized = gIR->dmodule;
937 945
938 Logger::println("DtoConstInitGlobal(%s) @ %s", vd->toChars(), vd->locToChars()); 946 Logger::println("DtoConstInitGlobal(%s) @ %s", vd->toChars(), vd->locToChars());
939 LOG_SCOPE; 947 LOG_SCOPE;
973 LLGlobalVariable* gv = DtoDwarfGlobalVariable(gvar, vd).getGV(); 981 LLGlobalVariable* gv = DtoDwarfGlobalVariable(gvar, vd).getGV();
974 // keep a reference so GDCE doesn't delete it ! 982 // keep a reference so GDCE doesn't delete it !
975 gIR->usedArray.push_back(llvm::ConstantExpr::getBitCast(gv, getVoidPtrType())); 983 gIR->usedArray.push_back(llvm::ConstantExpr::getBitCast(gv, getVoidPtrType()));
976 } 984 }
977 } 985 }
978 }
979
980 //////////////////////////////////////////////////////////////////////////////////////////
981
982 void DtoForceDeclareDsymbol(Dsymbol* dsym)
983 {
984 if (dsym->ir.declared) return;
985 Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars());
986 LOG_SCOPE;
987 DtoResolveDsymbol(dsym);
988 DtoDeclareDsymbol(dsym);
989 }
990
991 //////////////////////////////////////////////////////////////////////////////////////////
992
993 void DtoForceConstInitDsymbol(Dsymbol* dsym)
994 {
995 if (dsym->ir.initialized) return;
996 Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars());
997 LOG_SCOPE;
998 DtoResolveDsymbol(dsym);
999 DtoDeclareDsymbol(dsym);
1000 DtoConstInitDsymbol(dsym);
1001 }
1002
1003 //////////////////////////////////////////////////////////////////////////////////////////
1004
1005 void DtoForceDefineDsymbol(Dsymbol* dsym)
1006 {
1007 if (dsym->ir.defined) return;
1008 Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars());
1009 LOG_SCOPE;
1010 DtoResolveDsymbol(dsym);
1011 DtoDeclareDsymbol(dsym);
1012 DtoConstInitDsymbol(dsym);
1013 DtoDefineDsymbol(dsym);
1014 } 986 }
1015 987
1016 /****************************************************************************************/ 988 /****************************************************************************************/
1017 /*//////////////////////////////////////////////////////////////////////////////////////// 989 /*////////////////////////////////////////////////////////////////////////////////////////
1018 // DECLARATION EXP HELPER 990 // DECLARATION EXP HELPER
1104 } 1076 }
1105 // struct declaration 1077 // struct declaration
1106 else if (StructDeclaration* s = declaration->isStructDeclaration()) 1078 else if (StructDeclaration* s = declaration->isStructDeclaration())
1107 { 1079 {
1108 Logger::println("StructDeclaration"); 1080 Logger::println("StructDeclaration");
1109 DtoForceConstInitDsymbol(s); 1081 s->codegen(Type::sir);
1110 } 1082 }
1111 // function declaration 1083 // function declaration
1112 else if (FuncDeclaration* f = declaration->isFuncDeclaration()) 1084 else if (FuncDeclaration* f = declaration->isFuncDeclaration())
1113 { 1085 {
1114 Logger::println("FuncDeclaration"); 1086 Logger::println("FuncDeclaration");
1115 DtoForceDeclareDsymbol(f); 1087 f->codegen(Type::sir);
1116 } 1088 }
1117 // alias declaration 1089 // alias declaration
1118 else if (AliasDeclaration* a = declaration->isAliasDeclaration()) 1090 else if (AliasDeclaration* a = declaration->isAliasDeclaration())
1119 { 1091 {
1120 Logger::println("AliasDeclaration - no work"); 1092 Logger::println("AliasDeclaration - no work");
1128 } 1100 }
1129 // class 1101 // class
1130 else if (ClassDeclaration* e = declaration->isClassDeclaration()) 1102 else if (ClassDeclaration* e = declaration->isClassDeclaration())
1131 { 1103 {
1132 Logger::println("ClassDeclaration"); 1104 Logger::println("ClassDeclaration");
1133 DtoForceConstInitDsymbol(e); 1105 e->codegen(Type::sir);
1134 } 1106 }
1135 // typedef 1107 // typedef
1136 else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration()) 1108 else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration())
1137 { 1109 {
1138 Logger::println("TypedefDeclaration"); 1110 Logger::println("TypedefDeclaration");
1390 { 1362 {
1391 type = type->merge(); // needed.. getTypeInfo does the same 1363 type = type->merge(); // needed.. getTypeInfo does the same
1392 type->getTypeInfo(NULL); 1364 type->getTypeInfo(NULL);
1393 TypeInfoDeclaration* tidecl = type->vtinfo; 1365 TypeInfoDeclaration* tidecl = type->vtinfo;
1394 assert(tidecl); 1366 assert(tidecl);
1395 DtoForceDeclareDsymbol(tidecl); 1367 tidecl->codegen(Type::sir);
1396 assert(tidecl->ir.irGlobal != NULL); 1368 assert(tidecl->ir.irGlobal != NULL);
1369 assert(tidecl->ir.irGlobal->value != NULL);
1397 LLConstant* c = isaConstant(tidecl->ir.irGlobal->value); 1370 LLConstant* c = isaConstant(tidecl->ir.irGlobal->value);
1398 assert(c != NULL); 1371 assert(c != NULL);
1399 if (base) 1372 if (base)
1400 return llvm::ConstantExpr::getBitCast(c, DtoType(Type::typeinfo->type)); 1373 return llvm::ConstantExpr::getBitCast(c, DtoType(Type::typeinfo->type));
1401 return c; 1374 return c;