Mercurial > projects > ldc
view gen/irstate.cpp @ 1605:1d5721f9ae18
[WIP] Merge DMD r251: bugzilla 111 (appending a dchar to a char[])
This patch needs some work in the code generation, because of the runtime
changes (functions "_d_arrayappendcd" and "_d_arrayappendwd" are added).
This doesn't affect existing code though, it just makes with patch
a little useless, because something like this:
char [] s;
s ~= '\u6211';
That failed to compile with a nice error message previously to this
change, now fails with and ugly error message (a failed assertion).
Apparently there is a regression introduced by this patch too, when
compiling Dil I get this assertion message:
ldc: /home/luca/tesis/ldc/gen/statements.cpp:132: virtual void ReturnStatement::toIR(IRState*): Assertion `p->topfunc()->getReturnType() == llvm::Type::getVoidTy(gIR->context())' failed.
0 ldc 0x08a91628
Thank god we have bisecting capabilities in VCSs now ;)
---
dmd/expression.c | 47 +++++++++++++++++++++++++++++++++++++++++------
1 files changed, 41 insertions(+), 6 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:19 -0300 |
parents | 7f728c52e63c |
children |
line wrap: on
line source
/* DMDFE backend stubs * This file contains the implementations of the backend routines. * For dmdfe these do nothing but print a message saying the module * has been parsed. Substitute your own behaviors for these routimes. */ #include <cstdarg> #include "gen/llvm.h" #include "mtype.h" #include "declaration.h" #include "statement.h" #include "gen/irstate.h" #include "tollvm.h" IRState* gIR = 0; llvm::TargetMachine* gTargetMachine = 0; const llvm::TargetData* gTargetData = 0; TargetABI* gABI = 0; ////////////////////////////////////////////////////////////////////////////////////////// IRScope::IRScope() : builder(gIR->context()) { begin = end = NULL; } IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) : builder(b) { begin = b; end = e; } const IRScope& IRScope::operator=(const IRScope& rhs) { begin = rhs.begin; end = rhs.end; builder.SetInsertPoint(begin); return *this; } ////////////////////////////////////////////////////////////////////////////////////////// IRTargetScope::IRTargetScope() { } IRTargetScope::IRTargetScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* continueTarget, llvm::BasicBlock* breakTarget) { this->s = s; this->enclosinghandler = enclosinghandler; this->breakTarget = breakTarget; this->continueTarget = continueTarget; } ////////////////////////////////////////////////////////////////////////////////////////// IRState::IRState(llvm::Module* m) : module(m), difactory(*m) { interfaceInfoType = NULL; mutexType = NULL; moduleRefType = NULL; dmodule = 0; emitMain = false; mainFunc = 0; ir.state = this; asmBlock = NULL; dwarfCUs = NULL; dwarfSPs = NULL; dwarfGVs = NULL; } IrFunction* IRState::func() { assert(!functions.empty() && "Function stack is empty!"); return functions.back(); } llvm::Function* IRState::topfunc() { assert(!functions.empty() && "Function stack is empty!"); return functions.back()->func; } TypeFunction* IRState::topfunctype() { assert(!functions.empty() && "Function stack is empty!"); return functions.back()->type; } llvm::Instruction* IRState::topallocapoint() { assert(!functions.empty() && "AllocaPoint stack is empty!"); return functions.back()->allocapoint; } IrStruct* IRState::topstruct() { assert(!structs.empty() && "Struct vector is empty!"); return structs.back(); } IRScope& IRState::scope() { assert(!scopes.empty()); return scopes.back(); } llvm::BasicBlock* IRState::scopebb() { IRScope& s = scope(); assert(s.begin); return s.begin; } llvm::BasicBlock* IRState::scopeend() { IRScope& s = scope(); assert(s.end); return s.end; } bool IRState::scopereturned() { //return scope().returned; return !scopebb()->empty() && scopebb()->back().isTerminator(); } LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name) { LLSmallVector<LLValue*, 1> args; return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); } LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name) { LLSmallVector<LLValue*, 1> args; args.push_back(Arg1); return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); } LLCallSite IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name) { LLSmallVector<LLValue*, 2> args; args.push_back(Arg1); args.push_back(Arg2); return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); } LLCallSite IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name) { LLSmallVector<LLValue*, 3> args; args.push_back(Arg1); args.push_back(Arg2); args.push_back(Arg3); return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); } LLCallSite IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name) { LLSmallVector<LLValue*, 4> args; args.push_back(Arg1); args.push_back(Arg2); args.push_back(Arg3); args.push_back(Arg4); return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); } ////////////////////////////////////////////////////////////////////////////////////////// IRBuilder<>* IRBuilderHelper::operator->() { IRBuilder<>& b = state->scope().builder; assert(b.GetInsertBlock() != NULL); return &b; }