comparison gen/statements.c @ 82:d8dd47ef3973 trunk

[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes. Initial support for debug information. Very limited, but MUCH better than nothing :)
author lindquist
date Fri, 02 Nov 2007 01:17:26 +0100
parents 3587401b6eeb
children
comparison
equal deleted inserted replaced
81:3587401b6eeb 82:d8dd47ef3973
20 #include "gen/elem.h" 20 #include "gen/elem.h"
21 #include "gen/logger.h" 21 #include "gen/logger.h"
22 #include "gen/tollvm.h" 22 #include "gen/tollvm.h"
23 #include "gen/runtime.h" 23 #include "gen/runtime.h"
24 #include "gen/arrays.h" 24 #include "gen/arrays.h"
25 #include "gen/todebug.h"
25 26
26 ////////////////////////////////////////////////////////////////////////////// 27 //////////////////////////////////////////////////////////////////////////////
27 28
28 void CompoundStatement::toIR(IRState* p) 29 void CompoundStatement::toIR(IRState* p)
29 { 30 {
60 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { 61 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) {
61 assert(DtoIsPassedByRef(exptype)); 62 assert(DtoIsPassedByRef(exptype));
62 63
63 TypeFunction* f = p->topfunctype(); 64 TypeFunction* f = p->topfunctype();
64 assert(f->llvmRetInPtr && f->llvmRetArg); 65 assert(f->llvmRetInPtr && f->llvmRetArg);
66
67 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum);
65 68
66 p->exps.push_back(IRExp(NULL,exp,f->llvmRetArg)); 69 p->exps.push_back(IRExp(NULL,exp,f->llvmRetArg));
67 elem* e = exp->toElem(p); 70 elem* e = exp->toElem(p);
68 p->exps.pop_back(); 71 p->exps.pop_back();
69 72
91 } 94 }
92 else 95 else
93 assert(0); 96 assert(0);
94 97
95 IRFunction::FinallyVec& fin = p->func().finallys; 98 IRFunction::FinallyVec& fin = p->func().finallys;
96 if (fin.empty()) 99 if (fin.empty()) {
100 if (global.params.symdebug) DtoDwarfFuncEnd(p->func().decl);
97 new llvm::ReturnInst(p->scopebb()); 101 new llvm::ReturnInst(p->scopebb());
102 }
98 else { 103 else {
99 new llvm::BranchInst(fin.back().retbb, p->scopebb()); 104 new llvm::BranchInst(fin.back().retbb, p->scopebb());
100 } 105 }
101 delete e; 106 delete e;
102 } 107 }
103 else { 108 else {
109 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum);
104 elem* e = exp->toElem(p); 110 elem* e = exp->toElem(p);
105 llvm::Value* v = e->getValue(); 111 llvm::Value* v = e->getValue();
106 delete e; 112 delete e;
107 Logger::cout() << "return value is '" <<*v << "'\n"; 113 Logger::cout() << "return value is '" <<*v << "'\n";
108 114
109 IRFunction::FinallyVec& fin = p->func().finallys; 115 IRFunction::FinallyVec& fin = p->func().finallys;
110 if (fin.empty()) { 116 if (fin.empty()) {
117 if (global.params.symdebug) DtoDwarfFuncEnd(p->func().decl);
111 new llvm::ReturnInst(v, p->scopebb()); 118 new llvm::ReturnInst(v, p->scopebb());
112 } 119 }
113 else { 120 else {
114 if (!p->func().finallyretval) 121 if (!p->func().finallyretval)
115 p->func().finallyretval = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint()); 122 p->func().finallyretval = new llvm::AllocaInst(v->getType(),"tmpreturn",p->topallocapoint());
122 else 129 else
123 { 130 {
124 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { 131 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) {
125 IRFunction::FinallyVec& fin = p->func().finallys; 132 IRFunction::FinallyVec& fin = p->func().finallys;
126 if (fin.empty()) { 133 if (fin.empty()) {
134 if (global.params.symdebug) DtoDwarfFuncEnd(p->func().decl);
127 new llvm::ReturnInst(p->scopebb()); 135 new llvm::ReturnInst(p->scopebb());
128 } 136 }
129 else { 137 else {
130 new llvm::BranchInst(fin.back().retbb, p->scopebb()); 138 new llvm::BranchInst(fin.back().retbb, p->scopebb());
131 } 139 }
142 void ExpStatement::toIR(IRState* p) 150 void ExpStatement::toIR(IRState* p)
143 { 151 {
144 static int esi = 0; 152 static int esi = 0;
145 Logger::println("ExpStatement::toIR(%d): %s", esi++, toChars()); 153 Logger::println("ExpStatement::toIR(%d): %s", esi++, toChars());
146 LOG_SCOPE; 154 LOG_SCOPE;
155
156 if (global.params.symdebug)
157 DtoDwarfStopPoint(loc.linnum);
147 158
148 if (exp != 0) { 159 if (exp != 0) {
149 elem* e = exp->toElem(p); 160 elem* e = exp->toElem(p);
150 delete e; 161 delete e;
151 } 162 }
471 p->ir->CreateBr(ofin.retbb); 482 p->ir->CreateBr(ofin.retbb);
472 } 483 }
473 // no outer 484 // no outer
474 else 485 else
475 { 486 {
487 if (global.params.symdebug) DtoDwarfFuncEnd(p->func().decl);
476 llvm::Value* retval = p->func().finallyretval; 488 llvm::Value* retval = p->func().finallyretval;
477 if (retval) { 489 if (retval) {
478 retval = p->ir->CreateLoad(retval,"tmp"); 490 retval = p->ir->CreateLoad(retval,"tmp");
479 p->ir->CreateRet(retval); 491 p->ir->CreateRet(retval);
480 } 492 }