comparison gen/llvmhelpers.cpp @ 1593:b0dfdd5f6006

Make ref vars work with nesting.
author Christian Kamm <kamm incasoftware de>
date Sat, 07 Nov 2009 14:06:11 +0100
parents 91af6d05338c
children 8f121883bce8
comparison
equal deleted inserted replaced
1592:91af6d05338c 1593:b0dfdd5f6006
894 if (global.params.llvmAnnotate) 894 if (global.params.llvmAnnotate)
895 DtoAnnotation(declaration->toChars()); 895 DtoAnnotation(declaration->toChars());
896 896
897 Logger::println("vdtype = %s", vd->type->toChars()); 897 Logger::println("vdtype = %s", vd->type->toChars());
898 898
899 // ref vardecls are generated when DMD lowers foreach to a for statement,
900 // and this is a hack to support them for this case only
901 if(vd->isRef())
902 {
903 if (!vd->ir.irLocal)
904 vd->ir.irLocal = new IrLocal(vd);
905
906 ExpInitializer* ex = vd->init->isExpInitializer();
907 assert(ex && "ref vars must have expression initializer");
908 assert(ex->exp);
909 AssignExp* as = dynamic_cast<AssignExp*>(ex->exp);
910 assert(as && "ref vars must be initialized by an assign exp");
911 vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal();
912 }
913
899 // referenced by nested delegate? 914 // referenced by nested delegate?
900 #if DMDV2 915 #if DMDV2
901 if (vd->nestedrefs.dim) { 916 if (vd->nestedrefs.dim) {
902 #else 917 #else
903 if (vd->nestedref) { 918 if (vd->nestedref) {
925 if (global.params.symdebug) 940 if (global.params.symdebug)
926 { 941 {
927 DtoDwarfLocalVariable(allocainst, vd); 942 DtoDwarfLocalVariable(allocainst, vd);
928 } 943 }
929 } 944 }
930 else if(vd->isRef())
931 {
932 // ref vardecls are generated when DMD lowers foreach to a for statement,
933 // and this is a hack to support them for this case only
934 if (!vd->ir.irLocal)
935 vd->ir.irLocal = new IrLocal(vd);
936
937 ExpInitializer* ex = vd->init->isExpInitializer();
938 assert(ex && "ref vars must have expression initializer");
939 assert(ex->exp);
940 AssignExp* as = dynamic_cast<AssignExp*>(ex->exp);
941 assert(as && "ref vars must be initialized by an assign exp");
942 vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal();
943 return new DVarValue(vd->type, vd, vd->ir.getIrValue());
944 }
945 else 945 else
946 { 946 {
947 assert(vd->ir.irLocal->value); 947 assert(vd->ir.irLocal->value);
948 } 948 }
949 949
950 if (Logger::enabled()) 950 if (Logger::enabled())
951 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n'; 951 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n';
952 DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init); 952 if (!vd->isRef())
953 DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init);
953 } 954 }
954 955
955 return new DVarValue(vd->type, vd, vd->ir.getIrValue()); 956 return new DVarValue(vd->type, vd, vd->ir.getIrValue());
956 } 957 }
957 // struct declaration 958 // struct declaration