2014-10-31 155 views
0

我試圖在代碼中插入一個非常簡單的指令到我的基本塊LLVM IR插入

Value *ten=ConstantInt::get(Type::getInt32Ty(con),10,true); 
Instruction *newinst=new AllocaInst(Type::getInt32Ty(con),ten,"jst"); 
b->getInstList().push_back(newinst); 
Instruction *add=BinaryOperator::Create(Instruction :: Add,ten,ten,"twenty"); 
b->getInstList().push_back(add); 

它給堆棧轉儲,而我是在一個非常小的文件運行它:

While deleting: i32 % 

在Def被破壞後仍然卡住:%twenty = add i32 10, 10

我對LLVM比較陌生,所以如果這段代碼沒有意義,我會採取任何建議。

回答

1

LLVM指令構造函數和Create工廠接受要麼插入一個Instruction後,要麼插入一個BasicBlock的末尾。不要使用getInstList來做到這一點。

Here are samplesAllocaInst

AllocaInst (Type *Ty, Value *ArraySize=nullptr, 
      const Twine &Name="", Instruction *InsertBefore=nullptr) 
AllocaInst (Type *Ty, Value *ArraySize, 
      const Twine &Name, BasicBlock *InsertAtEnd) 
+0

什麼樣的價值是給予說法「常量繩索及名稱」如果假設我想10點的整數 – techcomp 2014-10-31 19:04:09

+0

@techcomp數組:任何東西,它只是用於調試目的。你可以傳入一個空字符串 – 2014-10-31 19:36:52