本文整理汇总了C++中AstIf::condition方法的典型用法代码示例。如果您正苦于以下问题:C++ AstIf::condition方法的具体用法?C++ AstIf::condition怎么用?C++ AstIf::condition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstIf
的用法示例。
在下文中一共展示了AstIf::condition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visit
void IrGen::visit(AstIf& if_) {
// setup needed basic blocks
Function* functionIr = m_builder.GetInsertBlock()->getParent();
BasicBlock* ThenFirstBB =
BasicBlock::Create(llvmContext, "if_then", functionIr);
BasicBlock* ElseFirstBB = BasicBlock::Create(llvmContext, "if_else");
BasicBlock* MergeBB = BasicBlock::Create(llvmContext, "if_merge");
// current BB:
Value* condIr = callAcceptOn(if_.condition());
assert(condIr);
m_builder.CreateCondBr(condIr, ThenFirstBB, ElseFirstBB);
// thenFirstBB:
m_builder.SetInsertPoint(ThenFirstBB);
Value* thenValue = callAcceptOn(if_.action());
assert(thenValue);
if (!if_.action().objType().isNoreturn()) { m_builder.CreateBr(MergeBB); }
BasicBlock* ThenLastBB = m_builder.GetInsertBlock();
// elseFirstBB:
functionIr->getBasicBlockList().push_back(ElseFirstBB);
m_builder.SetInsertPoint(ElseFirstBB);
Value* elseValue = nullptr;
if (if_.elseAction()) {
elseValue = callAcceptOn(*if_.elseAction());
assert(elseValue);
if (!if_.elseAction()->objType().isNoreturn()) {
m_builder.CreateBr(MergeBB);
}
}
else {
elseValue = m_abstractObject;
m_builder.CreateBr(MergeBB);
}
BasicBlock* ElseLastBB = m_builder.GetInsertBlock();
// mergeBB:
// also sets IrValue of this AstIf
functionIr->getBasicBlockList().push_back(MergeBB);
m_builder.SetInsertPoint(MergeBB);
if (thenValue != m_abstractObject && elseValue != m_abstractObject) {
PHINode* phi = m_builder.CreatePHI(thenValue->getType(), 2, "if_phi");
assert(phi);
phi->addIncoming(thenValue, ThenLastBB);
phi->addIncoming(elseValue, ElseLastBB);
allocateAndInitLocalIrObjectFor(if_, phi);
}
else {
allocateAndInitLocalIrObjectFor(if_, m_abstractObject);
}
}