Mercurial > projects > ldc
diff gen/irstate.c @ 40:8b0e809563df trunk
[svn r44] Lots of bug fixes.
New array literal support
New array ~= operator support (for single element)
New with statement support
More...
author | lindquist |
---|---|
date | Fri, 19 Oct 2007 07:43:21 +0200 |
parents | 2841234d2aea |
children | 28e99b04a132 |
line wrap: on
line diff
--- a/gen/irstate.c Wed Oct 10 06:21:31 2007 +0200 +++ b/gen/irstate.c Fri Oct 19 07:43:21 2007 +0200 @@ -4,8 +4,15 @@ * has been parsed. Substitute your own behaviors for these routimes. */ +#include <cstdarg> + +#include "gen/llvm.h" + #include "mtype.h" +#include "declaration.h" + #include "gen/irstate.h" +#include "tollvm.h" IRState* gIR = 0; llvm::TargetData* gTargetData = 0; @@ -13,15 +20,14 @@ ////////////////////////////////////////////////////////////////////////////////////////// IRScope::IRScope() { - begin = end = 0; - returned = false; + begin = end = NULL; } IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) { begin = b; end = e; - returned = false; + builder.SetInsertPoint(b); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -32,24 +38,31 @@ inLvalue = false; emitMain = false; mainFunc = 0; + ir.state = this; +} + +IRFunction& IRState::func() +{ + assert(!functions.empty() && "Function stack is empty!"); + return functions.back(); } llvm::Function* IRState::topfunc() { - assert(!funcs.empty() && "Function stack is empty!"); - return funcs.top(); + assert(!functions.empty() && "Function stack is empty!"); + return functions.back().func; } TypeFunction* IRState::topfunctype() { - assert(!functypes.empty() && "TypeFunction stack is empty!"); - return functypes.top(); + assert(!functions.empty() && "Function stack is empty!"); + return functions.back().type; } llvm::Instruction* IRState::topallocapoint() { - assert(!functypes.empty() && "AllocaPoint stack is empty!"); - return functypes.top()->llvmAllocaPoint; + assert(!functions.empty() && "AllocaPoint stack is empty!"); + return functions.back().allocapoint; } IRStruct& IRState::topstruct() @@ -108,6 +121,35 @@ queueFuncs = true; } -IRStruct::~IRStruct() +////////////////////////////////////////////////////////////////////////////////////////// + +IRFinally::IRFinally() + : bb(NULL), ret(false), retval(NULL) +{ +} + +IRFinally::IRFinally(llvm::BasicBlock* b) + : bb(b), ret(false), retval(NULL) { } + +////////////////////////////////////////////////////////////////////////////////////////// + +LLVMBuilder* IRBuilderHelper::operator->() +{ + LLVMBuilder& b = state->scope().builder; + assert(b.GetInsertBlock() != NULL); + return &b; +} + +////////////////////////////////////////////////////////////////////////////////////////// + +IRFunction::IRFunction(FuncDeclaration* fd) +{ + decl = fd; + Type* t = LLVM_DtoDType(fd->type); + assert(t->ty == Tfunction); + type = (TypeFunction*)t; + func = NULL; + allocapoint = NULL; +}