comparison gen/functions.cpp @ 758:f04dde6e882c

Added initial D2 support, D2 frontend and changes to codegen to make things compile.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:38:48 +0100
parents 2d7bcfa68128
children 340acf1535d0
comparison
equal deleted inserted replaced
757:2c730d530c98 758:f04dde6e882c
30 30
31 if (type->ir.type != NULL) { 31 if (type->ir.type != NULL) {
32 return llvm::cast<llvm::FunctionType>(type->ir.type->get()); 32 return llvm::cast<llvm::FunctionType>(type->ir.type->get());
33 } 33 }
34 34
35 bool typesafeVararg = false; 35 bool dVararg = false;
36 bool arrayVararg = false; 36 bool arrayVararg = false;
37 if (f->linkage == LINKd) 37 if (f->linkage == LINKd)
38 { 38 {
39 if (f->varargs == 1) 39 if (f->varargs == 1)
40 typesafeVararg = true; 40 dVararg = true;
41 else if (f->varargs == 2) 41 else if (f->varargs == 2)
42 arrayVararg = true; 42 arrayVararg = true;
43 } 43 }
44 44
45 // return value type 45 // return value type
94 else if (nesttype) { 94 else if (nesttype) {
95 paramvec.push_back(nesttype); 95 paramvec.push_back(nesttype);
96 usesnest = true; 96 usesnest = true;
97 } 97 }
98 98
99 if (typesafeVararg) { 99 if (dVararg) {
100 ClassDeclaration* ti = Type::typeinfo; 100 ClassDeclaration* ti = Type::typeinfo;
101 ti->toObjFile(0); // TODO: multiobj 101 ti->toObjFile(0); // TODO: multiobj
102 DtoForceConstInitDsymbol(ti); 102 DtoForceConstInitDsymbol(ti);
103 assert(ti->ir.irStruct->constInit); 103 assert(ti->ir.irStruct->constInit);
104 std::vector<const LLType*> types; 104 std::vector<const LLType*> types;
117 if (global.params.cpu == ARCHx86) 117 if (global.params.cpu == ARCHx86)
118 { 118 {
119 // more than one formal arg, 119 // more than one formal arg,
120 // extern(D) linkage 120 // extern(D) linkage
121 // not a D-style vararg 121 // not a D-style vararg
122 if (n > 1 && f->linkage == LINKd && !typesafeVararg) 122 if (n > 1 && f->linkage == LINKd && !dVararg)
123 { 123 {
124 f->reverseParams = true; 124 f->reverseParams = true;
125 f->reverseIndex = paramvec.size(); 125 f->reverseIndex = paramvec.size();
126 } 126 }
127 } 127 }
187 { 187 {
188 std::reverse(paramvec.begin() + f->reverseIndex, paramvec.end()); 188 std::reverse(paramvec.begin() + f->reverseIndex, paramvec.end());
189 } 189 }
190 190
191 // construct function type 191 // construct function type
192 bool isvararg = !(typesafeVararg || arrayVararg) && f->varargs; 192 bool isvararg = !(dVararg || arrayVararg) && f->varargs;
193 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg); 193 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg);
194 194
195 #if X86_PASS_IN_EAX 195 #if X86_PASS_IN_EAX
196 // tell first param to be passed in a register if we can 196 // tell first param to be passed in a register if we can
197 // ONLY extern(D) functions ! 197 // ONLY extern(D) functions !
718 fd->vthis->ir.irLocal = new IrLocal(fd->vthis); 718 fd->vthis->ir.irLocal = new IrLocal(fd->vthis);
719 fd->vthis->ir.irLocal->value = thismem; 719 fd->vthis->ir.irLocal->value = thismem;
720 720
721 if (global.params.symdebug) 721 if (global.params.symdebug)
722 DtoDwarfLocalVariable(thismem, fd->vthis); 722 DtoDwarfLocalVariable(thismem, fd->vthis);
723 723
724 #if DMDV2
725 if (fd->vthis->nestedrefs.dim)
726 #else
724 if (fd->vthis->nestedref) 727 if (fd->vthis->nestedref)
728 #endif
729 {
725 fd->nestedVars.insert(fd->vthis); 730 fd->nestedVars.insert(fd->vthis);
731 }
726 } 732 }
727 733
728 // give arguments storage 734 // give arguments storage
729 // and debug info 735 // and debug info
730 if (fd->parameters) 736 if (fd->parameters)
733 for (int i=0; i < n; ++i) 739 for (int i=0; i < n; ++i)
734 { 740 {
735 Dsymbol* argsym = (Dsymbol*)fd->parameters->data[i]; 741 Dsymbol* argsym = (Dsymbol*)fd->parameters->data[i];
736 VarDeclaration* vd = argsym->isVarDeclaration(); 742 VarDeclaration* vd = argsym->isVarDeclaration();
737 assert(vd); 743 assert(vd);
738 744
745 #if DMDV2
746 if (vd->nestedrefs.dim)
747 #else
739 if (vd->nestedref) 748 if (vd->nestedref)
749 #endif
750 {
740 fd->nestedVars.insert(vd); 751 fd->nestedVars.insert(vd);
752 }
741 753
742 IrLocal* irloc = vd->ir.irLocal; 754 IrLocal* irloc = vd->ir.irLocal;
743 assert(irloc); 755 assert(irloc);
744 756
745 bool refout = vd->storage_class & (STCref | STCout); 757 bool refout = vd->storage_class & (STCref | STCout);
755 if (global.params.symdebug && !(isaArgument(irloc->value) && !isaArgument(irloc->value)->hasByValAttr()) && !refout) 767 if (global.params.symdebug && !(isaArgument(irloc->value) && !isaArgument(irloc->value)->hasByValAttr()) && !refout)
756 DtoDwarfLocalVariable(irloc->value, vd); 768 DtoDwarfLocalVariable(irloc->value, vd);
757 } 769 }
758 } 770 }
759 771
760 // need result variable? (nested) 772 // need result variable? (nested)
773 #if DMDV2
774 if (fd->vresult && fd->vresult->nestedrefs.dim) {
775 #else
761 if (fd->vresult && fd->vresult->nestedref) { 776 if (fd->vresult && fd->vresult->nestedref) {
777 #endif
762 Logger::println("nested vresult value: %s", fd->vresult->toChars()); 778 Logger::println("nested vresult value: %s", fd->vresult->toChars());
763 fd->nestedVars.insert(fd->vresult); 779 fd->nestedVars.insert(fd->vresult);
764 } 780 }
765 781
766 // construct nested variables array 782 // construct nested variables array
834 Logger::println("nested var: %s", vd->toChars()); 850 Logger::println("nested var: %s", vd->toChars());
835 } 851 }
836 852
837 vd->ir.irLocal->nestedIndex = idx++; 853 vd->ir.irLocal->nestedIndex = idx++;
838 } 854 }
839 855
840 // fixup nested result variable 856 // fixup nested result variable
857 #if DMDV2
858 if (fd->vresult && fd->vresult->nestedrefs.dim) {
859 #else
841 if (fd->vresult && fd->vresult->nestedref) { 860 if (fd->vresult && fd->vresult->nestedref) {
861 #endif
842 Logger::println("nested vresult value: %s", fd->vresult->toChars()); 862 Logger::println("nested vresult value: %s", fd->vresult->toChars());
843 LLValue* gep = DtoGEPi(nestedVars, 0, fd->vresult->ir.irLocal->nestedIndex); 863 LLValue* gep = DtoGEPi(nestedVars, 0, fd->vresult->ir.irLocal->nestedIndex);
844 LLValue* val = DtoBitCast(fd->vresult->ir.irLocal->value, getVoidPtrType()); 864 LLValue* val = DtoBitCast(fd->vresult->ir.irLocal->value, getVoidPtrType());
845 DtoStore(val, gep); 865 DtoStore(val, gep);
846 } 866 }