Commit f1d4b01f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Ok some basic cases working, but exceptions are hard

parent e320ebee
...@@ -2843,8 +2843,9 @@ public: ...@@ -2843,8 +2843,9 @@ public:
irstate->getRefcounts()->refConsumed(exc_traceback, call_inst); irstate->getRefcounts()->refConsumed(exc_traceback, call_inst);
builder->CreateRet(getNullPtr(g.llvm_value_type_ptr)); builder->CreateRet(getNullPtr(g.llvm_value_type_ptr));
} else { } else {
auto call_inst = emitter.createCall3(UnwindInfo(unw_info.current_stmt, NO_CXX_INTERCEPTION), //auto call_inst = emitter.createCall3(UnwindInfo(unw_info.current_stmt, NO_CXX_INTERCEPTION),
g.funcs.rawThrow, exc_type, exc_value, exc_traceback); //g.funcs.rawThrow, exc_type, exc_value, exc_traceback);
auto call_inst = emitter.getBuilder()->CreateCall3(g.funcs.rawThrow, exc_type, exc_value, exc_traceback);
irstate->getRefcounts()->refConsumed(exc_type, call_inst); irstate->getRefcounts()->refConsumed(exc_type, call_inst);
irstate->getRefcounts()->refConsumed(exc_value, call_inst); irstate->getRefcounts()->refConsumed(exc_value, call_inst);
irstate->getRefcounts()->refConsumed(exc_traceback, call_inst); irstate->getRefcounts()->refConsumed(exc_traceback, call_inst);
......
...@@ -111,8 +111,9 @@ void addDecrefs(llvm::Value* v, int num_refs, llvm::Instruction* decref_pt) { ...@@ -111,8 +111,9 @@ void addDecrefs(llvm::Value* v, int num_refs, llvm::Instruction* decref_pt) {
new llvm::StoreInst(new_refcount, refcount_ptr, decref_pt); new llvm::StoreInst(new_refcount, refcount_ptr, decref_pt);
llvm::BasicBlock* cur_block = decref_pt->getParent(); llvm::BasicBlock* cur_block = decref_pt->getParent();
llvm::BasicBlock* dealloc_block = llvm::BasicBlock::Create(g.context, "dealloc", decref_pt->getParent()->getParent());
llvm::BasicBlock* continue_block = cur_block->splitBasicBlock(decref_pt); llvm::BasicBlock* continue_block = cur_block->splitBasicBlock(decref_pt);
llvm::BasicBlock* dealloc_block
= llvm::BasicBlock::Create(g.context, "dealloc", decref_pt->getParent()->getParent(), continue_block);
assert(llvm::isa<llvm::BranchInst>(cur_block->getTerminator())); assert(llvm::isa<llvm::BranchInst>(cur_block->getTerminator()));
cur_block->getTerminator()->eraseFromParent(); cur_block->getTerminator()->eraseFromParent();
...@@ -273,7 +274,6 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) { ...@@ -273,7 +274,6 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) {
assert(rt->vars.count(v)); assert(rt->vars.count(v));
auto refstate = rt->vars[v]; auto refstate = rt->vars[v];
if (refstate.reftype == RefType::BORROWED) {
int min_refs = 1000000000; int min_refs = 1000000000;
for (auto SBB : successors) { for (auto SBB : successors) {
auto it = states[SBB].refs.find(v); auto it = states[SBB].refs.find(v);
...@@ -283,6 +283,9 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) { ...@@ -283,6 +283,9 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) {
min_refs = 0; min_refs = 0;
} }
if (refstate.reftype == RefType::OWNED)
min_refs = std::max(1, min_refs);
for (auto SBB : successors) { for (auto SBB : successors) {
auto it = states[SBB].refs.find(v); auto it = states[SBB].refs.find(v);
int this_refs = 0; int this_refs = 0;
...@@ -293,6 +296,9 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) { ...@@ -293,6 +296,9 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) {
addIncrefs(v, this_refs - min_refs, findIncrefPt(SBB)); addIncrefs(v, this_refs - min_refs, findIncrefPt(SBB));
//llvm::outs() << *incref_pt << '\n'; //llvm::outs() << *incref_pt << '\n';
//llvm::outs() << "Need to incref " << *v << " at beginning of " << SBB->getName() << "\n"; //llvm::outs() << "Need to incref " << *v << " at beginning of " << SBB->getName() << "\n";
} else if (this_refs < min_refs) {
assert(refstate.reftype == RefType::OWNED);
addDecrefs(v, min_refs - this_refs, findIncrefPt(SBB));
} }
} }
...@@ -300,7 +306,9 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) { ...@@ -300,7 +306,9 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) {
state.refs[v] = min_refs; state.refs[v] = min_refs;
else else
assert(state.refs.count(v) == 0); assert(state.refs.count(v) == 0);
} else {
#if 0
llvm::outs() << *v << " goes to multiple successors\n"; llvm::outs() << *v << " goes to multiple successors\n";
for (auto SBB : successors) { for (auto SBB : successors) {
...@@ -310,9 +318,7 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) { ...@@ -310,9 +318,7 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) {
} else } else
llvm::outs() << SBB->getName() << ": " << 0 << '\n'; llvm::outs() << SBB->getName() << ": " << 0 << '\n';
} }
#endif
assert(0 && "finish implementing");
}
} }
} }
......
...@@ -4281,6 +4281,12 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe ...@@ -4281,6 +4281,12 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
throw e; throw e;
} }
if (num_output_args < 1)
arg1 = NULL;
if (num_output_args < 2)
arg2 = NULL;
if (num_output_args < 3)
arg3 = NULL;
AUTO_XDECREF(arg1); AUTO_XDECREF(arg1);
AUTO_XDECREF(arg2); AUTO_XDECREF(arg2);
AUTO_XDECREF(arg3); AUTO_XDECREF(arg3);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment