comparison gen/toir.cpp @ 1434:5d0c043ff131

Remove code duplication for vtable loads and improve instruction naming to make bitcode with virtual calls easier to read.
author Frits van Bommel <fvbommel wxs.nl>
date Sat, 30 May 2009 13:04:49 +0200
parents a6dfd3cb5b99
children dd72f56ad211
comparison
equal deleted inserted replaced
1433:f79971a45bee 1434:5d0c043ff131
1132 fdecl->codegen(Type::sir); 1132 fdecl->codegen(Type::sir);
1133 funcval = fdecl->ir.irFunc->func; 1133 funcval = fdecl->ir.irFunc->func;
1134 assert(funcval); 1134 assert(funcval);
1135 } 1135 }
1136 else { 1136 else {
1137 assert(fdecl->vtblIndex > 0); 1137 DImValue vthis3(e1type, vthis);
1138 assert(e1type->ty == Tclass); 1138 funcval = DtoVirtualFunctionPointer(&vthis3, fdecl, toChars());
1139
1140 LLValue* zero = DtoConstUint(0);
1141 size_t vtblidx = fdecl->vtblIndex;
1142 if (Logger::enabled())
1143 Logger::cout() << "vthis: " << *vthis << '\n';
1144 funcval = DtoGEP(vthis, zero, zero);
1145 funcval = DtoLoad(funcval);
1146 Logger::println("vtblidx = %lu", vtblidx);
1147 funcval = DtoGEP(funcval, zero, DtoConstUint(vtblidx), toChars());
1148 funcval = DtoLoad(funcval);
1149
1150 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type)));
1151 if (Logger::enabled())
1152 Logger::cout() << "funcval casted: " << *funcval << '\n';
1153 } 1139 }
1154 1140
1155 return new DFuncValue(fdecl, funcval, vthis2); 1141 return new DFuncValue(fdecl, funcval, vthis2);
1156 } 1142 }
1157 else { 1143 else {
2029 2015
2030 Logger::println("func: '%s'", func->toPrettyChars()); 2016 Logger::println("func: '%s'", func->toPrettyChars());
2031 2017
2032 LLValue* castfptr; 2018 LLValue* castfptr;
2033 if (func->isVirtual() && !func->isFinal()) 2019 if (func->isVirtual() && !func->isFinal())
2034 castfptr = DtoVirtualFunctionPointer(u, func); 2020 castfptr = DtoVirtualFunctionPointer(u, func, toChars());
2035 else if (func->isAbstract()) 2021 else if (func->isAbstract())
2036 assert(0 && "TODO delegate to abstract method"); 2022 assert(0 && "TODO delegate to abstract method");
2037 else if (func->toParent()->isInterfaceDeclaration()) 2023 else if (func->toParent()->isInterfaceDeclaration())
2038 assert(0 && "TODO delegate to interface method"); 2024 assert(0 && "TODO delegate to interface method");
2039 else 2025 else