Mercurial > projects > ldc
comparison gen/statements.c @ 54:28e99b04a132 trunk
[svn r58] Fixed cond expression resulting in a non-basic type.
Fixed identity expression for dynamic arrays.
Revamped the system to keep track of lvalues and rvalues and their relations.
Typedef declaration now generate the custom typeinfo.
Other bugfixes.
author | lindquist |
---|---|
date | Wed, 24 Oct 2007 01:37:34 +0200 |
parents | 61bc1b4ad3c4 |
children | b706170e24a9 |
comparison
equal
deleted
inserted
replaced
53:06ccc817acd4 | 54:28e99b04a132 |
---|---|
49 { | 49 { |
50 static int rsi = 0; | 50 static int rsi = 0; |
51 Logger::println("ReturnStatement::toIR(%d): %s", rsi++, toChars()); | 51 Logger::println("ReturnStatement::toIR(%d): %s", rsi++, toChars()); |
52 LOG_SCOPE; | 52 LOG_SCOPE; |
53 | 53 |
54 IRFunction::FinallyVec& fin = p->func().finallys; | |
55 | |
56 if (exp) | 54 if (exp) |
57 { | 55 { |
56 Logger::println("return type is: %s", exp->type->toChars()); | |
57 | |
58 Type* exptype = LLVM_DtoDType(exp->type); | 58 Type* exptype = LLVM_DtoDType(exp->type); |
59 TY expty = exptype->ty; | 59 TY expty = exptype->ty; |
60 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { | 60 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { |
61 assert(LLVM_DtoIsPassedByRef(exptype)); | 61 assert(LLVM_DtoIsPassedByRef(exptype)); |
62 | 62 |
63 TypeFunction* f = p->topfunctype(); | 63 TypeFunction* f = p->topfunctype(); |
64 assert(f->llvmRetInPtr && f->llvmRetArg); | 64 assert(f->llvmRetInPtr && f->llvmRetArg); |
65 | 65 |
66 p->lvals.push_back(f->llvmRetArg); | 66 p->exps.push_back(IRExp(NULL,exp,f->llvmRetArg)); |
67 elem* e = exp->toElem(p); | 67 elem* e = exp->toElem(p); |
68 p->lvals.pop_back(); | 68 p->exps.pop_back(); |
69 | 69 |
70 if (expty == Tstruct) { | 70 if (expty == Tstruct) { |
71 if (!e->inplace) { | 71 if (!e->inplace) |
72 assert(e->mem); | 72 LLVM_DtoStructCopy(f->llvmRetArg,e->getValue()); |
73 LLVM_DtoStructCopy(f->llvmRetArg,e->mem); | |
74 } | |
75 } | 73 } |
76 else if (expty == Tdelegate) { | 74 else if (expty == Tdelegate) { |
77 LLVM_DtoDelegateCopy(f->llvmRetArg,e->mem); | 75 if (!e->inplace) |
76 LLVM_DtoDelegateCopy(f->llvmRetArg,e->getValue()); | |
78 } | 77 } |
79 else if (expty == Tarray) { | 78 else if (expty == Tarray) { |
80 if (e->type == elem::SLICE) { | 79 if (e->type == elem::SLICE) { |
80 assert(e->mem); | |
81 LLVM_DtoSetArray(f->llvmRetArg,e->arg,e->mem); | 81 LLVM_DtoSetArray(f->llvmRetArg,e->arg,e->mem); |
82 } | 82 } |
83 // else the return value is a variable and should already have been assigned by now | 83 else if (!e->inplace) { |
84 if (e->type == elem::NUL) { | |
85 LLVM_DtoNullArray(f->llvmRetArg); | |
86 } | |
87 else { | |
88 LLVM_DtoArrayAssign(f->llvmRetArg, e->getValue()); | |
89 } | |
90 } | |
84 } | 91 } |
85 else | 92 else |
86 assert(0); | 93 assert(0); |
87 | 94 |
95 IRFunction::FinallyVec& fin = p->func().finallys; | |
88 if (fin.empty()) | 96 if (fin.empty()) |
89 new llvm::ReturnInst(p->scopebb()); | 97 new llvm::ReturnInst(p->scopebb()); |
90 else { | 98 else { |
91 new llvm::BranchInst(fin.back().bb); | 99 new llvm::BranchInst(fin.back().bb); |
92 fin.back().ret = true; | 100 fin.back().ret = true; |
96 else { | 104 else { |
97 elem* e = exp->toElem(p); | 105 elem* e = exp->toElem(p); |
98 llvm::Value* v = e->getValue(); | 106 llvm::Value* v = e->getValue(); |
99 delete e; | 107 delete e; |
100 Logger::cout() << "return value is '" <<*v << "'\n"; | 108 Logger::cout() << "return value is '" <<*v << "'\n"; |
109 | |
110 IRFunction::FinallyVec& fin = p->func().finallys; | |
101 if (fin.empty()) { | 111 if (fin.empty()) { |
102 new llvm::ReturnInst(v, p->scopebb()); | 112 new llvm::ReturnInst(v, p->scopebb()); |
103 } | 113 } |
104 else { | 114 else { |
105 llvm::Value* rettmp = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint()); | 115 llvm::Value* rettmp = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint()); |
111 } | 121 } |
112 } | 122 } |
113 else | 123 else |
114 { | 124 { |
115 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { | 125 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { |
126 IRFunction::FinallyVec& fin = p->func().finallys; | |
116 if (fin.empty()) { | 127 if (fin.empty()) { |
117 new llvm::ReturnInst(p->scopebb()); | 128 new llvm::ReturnInst(p->scopebb()); |
118 } | 129 } |
119 else { | 130 else { |
120 new llvm::BranchInst(fin.back().bb); | 131 new llvm::BranchInst(fin.back().bb); |