Commit c54e751d authored by 王宇航's avatar 王宇航

lab3 publish

parent 03dc00fe
......@@ -30,7 +30,7 @@ class BasicBlock : public Value, public llvm::ilist_node<BasicBlock> {
void add_succ_basic_block(BasicBlock *bb) { succ_bbs_.push_back(bb); }
void remove_pre_basic_block(BasicBlock *bb) { pre_bbs_.remove(bb); }
void remove_succ_basic_block(BasicBlock *bb) { succ_bbs_.remove(bb); }
BasicBlock* get_entry_block_of_same_function();
BasicBlock* get_entry_block_of_same_function();
// If the Block is terminated by ret/br
bool is_terminated() const;
......@@ -40,6 +40,9 @@ class BasicBlock : public Value, public llvm::ilist_node<BasicBlock> {
/****************api about Instruction****************/
void add_instruction(Instruction *instr);
void add_instr_begin(Instruction *instr) { instr_list_.push_front(instr); }
void add_instr_before_end(Instruction *instr) {
instr_list_.insert(std::prev(instr_list_.end()), instr);
}
void erase_instr(Instruction *instr) { instr_list_.erase(instr); }
void remove_instr(Instruction *instr) { instr_list_.remove(instr); }
......
......@@ -303,7 +303,10 @@ AllocaInst *AllocaInst::create_alloca_begin(Type *ty, BasicBlock *bb) {
if(bb != nullptr)
{
ret->set_parent(bb);
bb->add_instr_begin(ret);
if (bb->is_terminated())
bb->add_instr_before_end(ret);
else
bb->add_instruction(ret);
}
return ret;
}
......
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