本文整理汇总了C++中rc::ConstHandle::llvmCast方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstHandle::llvmCast方法的具体用法?C++ ConstHandle::llvmCast怎么用?C++ ConstHandle::llvmCast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rc::ConstHandle
的用法示例。
在下文中一共展示了ConstHandle::llvmCast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: llvmCompileToBuilder
void Report::llvmCompileToBuilder( CG::BasicBlockBuilder &basicBlockBuilder, CG::Diagnostics &diagnostics ) const
{
RC::ConstHandle< CG::StringAdapter > stringAdapter = basicBlockBuilder.getManager()->getStringAdapter();
stringAdapter->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
try
{
CG::Scope subScope( basicBlockBuilder.getScope() );
CG::BasicBlockBuilder subBBB( basicBlockBuilder, subScope );
CG::ExprValue exprExprValue = m_expr->buildExprValue( subBBB, CG::USAGE_RVALUE, "cannot be an l-value" );
llvm::Value *stringRValue = stringAdapter->llvmCast( subBBB, exprExprValue );
stringAdapter->llvmReport( subBBB, stringRValue );
subScope.llvmUnwind( subBBB );
}
catch ( CG::Error e )
{
addError( diagnostics, e );
}
catch ( Exception e )
{
addError( diagnostics, e );
}
}
示例2: llvmThrowOutOfRangeException
void ArrayAdapter::llvmThrowOutOfRangeException(
BasicBlockBuilder &basicBlockBuilder,
llvm::Value *itemDescRValue,
llvm::Value *indexRValue,
llvm::Value *sizeRValue,
llvm::Value *errorDescRValue
) const
{
RC::Handle<Context> context = basicBlockBuilder.getContext();
RC::ConstHandle<SizeAdapter> sizeAdapter = basicBlockBuilder.getManager()->getSizeAdapter();
RC::ConstHandle<StringAdapter> stringAdapter = basicBlockBuilder.getManager()->getStringAdapter();
RC::ConstHandle<ConstStringAdapter> constStringAdapter = basicBlockBuilder.getManager()->getConstStringAdapter();
std::vector<llvm::Type const *> argTypes;
argTypes.push_back( constStringAdapter->llvmRType( context ) );
argTypes.push_back( sizeAdapter->llvmRType( context ) );
argTypes.push_back( sizeAdapter->llvmRType( context ) );
argTypes.push_back( constStringAdapter->llvmRType( context ) );
llvm::FunctionType const *funcType = llvm::FunctionType::get( basicBlockBuilder->getVoidTy(), argTypes, false );
llvm::AttributeWithIndex AWI[1];
AWI[0] = llvm::AttributeWithIndex::get( ~0u, 0 /*llvm::Attribute::InlineHint | llvm::Attribute::NoUnwind*/ );
llvm::AttrListPtr attrListPtr = llvm::AttrListPtr::get( AWI, 1 );
std::string name = "__ThrowOutOfRangeException";
llvm::Function *func = llvm::cast<llvm::Function>( basicBlockBuilder.getModuleBuilder()->getFunction( name ) );
if ( !func )
{
ModuleBuilder &mb = basicBlockBuilder.getModuleBuilder();
func = llvm::cast<llvm::Function>( mb->getOrInsertFunction( name, funcType, attrListPtr ) );
func->setLinkage( llvm::GlobalValue::PrivateLinkage );
FunctionBuilder fb( mb, funcType, func );
llvm::Argument *itemRValue = fb[0];
itemRValue->setName( "itemRValue" );
itemRValue->addAttr( llvm::Attribute::NoCapture );
llvm::Argument *indexRValue = fb[1];
indexRValue->setName( "indexRValue" );
llvm::Argument *sizeRValue = fb[2];
sizeRValue->setName( "sizeRValue" );
llvm::Argument *errorDescRValue = fb[3];
errorDescRValue->setName( "errorDescRValue" );
errorDescRValue->addAttr( llvm::Attribute::NoCapture );
BasicBlockBuilder bbb( fb );
llvm::BasicBlock *entryBB = fb.createBasicBlock( "entry" );
bbb->SetInsertPoint( entryBB );
llvm::Value *errorMsg1PlusIndexPlusErrorMsg2PlusSizePlusErrorMsg3LValue;
{
Scope subScope( bbb.getScope() );
BasicBlockBuilder subBasicBlockBuilder( bbb, subScope );
llvm::BasicBlock *haveErrorDescBB = fb.createBasicBlock( "haveErrorDescBB" );
llvm::BasicBlock *noErrorDescBB = fb.createBasicBlock( "noErrorDescBB" );
llvm::BasicBlock *goBB = fb.createBasicBlock( "goBB" );
subBasicBlockBuilder->CreateCondBr(
subBasicBlockBuilder->CreateIsNotNull( errorDescRValue ),
haveErrorDescBB,
noErrorDescBB
);
subBasicBlockBuilder->SetInsertPoint( haveErrorDescBB );
llvm::Value *haveErrorDescConstStringRValue = errorDescRValue;
subBasicBlockBuilder->CreateBr( goBB );
subBasicBlockBuilder->SetInsertPoint( noErrorDescBB );
llvm::Value *noErrorDescConstStringRValue = constStringAdapter->llvmConst( subBasicBlockBuilder, "KL" );
subBasicBlockBuilder->CreateBr( goBB );
subBasicBlockBuilder->SetInsertPoint( goBB );
llvm::PHINode *errorDescConstStringRValue = subBasicBlockBuilder->CreatePHI( haveErrorDescConstStringRValue->getType(), "errorDescConstStringRValue" );
errorDescConstStringRValue->addIncoming( haveErrorDescConstStringRValue, haveErrorDescBB );
errorDescConstStringRValue->addIncoming( noErrorDescConstStringRValue, noErrorDescBB );
llvm::Value *errorMsg0RValue = stringAdapter->llvmCast(
subBasicBlockBuilder,
ExprValue( constStringAdapter, USAGE_RVALUE, context, errorDescConstStringRValue )
);
llvm::Value *errorMsgARValue = stringAdapter->llvmCast( subBasicBlockBuilder,
ExprValue( constStringAdapter, USAGE_RVALUE, context, constStringAdapter->llvmConst( subBasicBlockBuilder, ": " ) )
);
llvm::Value *errorMsgALValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsgA" );
stringAdapter->llvmInit( subBasicBlockBuilder, errorMsgALValue );
stringAdapter->llvmCallConcat(
subBasicBlockBuilder,
errorMsg0RValue,
errorMsgARValue,
errorMsgALValue
);
llvm::Value *errorMsgBRValue = stringAdapter->llvmCast( subBasicBlockBuilder,
ExprValue( constStringAdapter, USAGE_RVALUE, context, itemRValue )
);
llvm::Value *errorMsgBLValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsgB" );
//.........这里部分代码省略.........
示例3: llvmCompileToModule
void ArrayProducerAdapter::llvmCompileToModule( ModuleBuilder &moduleBuilder ) const
{
if ( moduleBuilder.haveCompiledToModule( getCodeName() ) )
return;
RC::Handle<Context> context = moduleBuilder.getContext();
m_elementAdapter->llvmCompileToModule( moduleBuilder );
m_elementVariableArrayAdapter->llvmCompileToModule( moduleBuilder );
RC::ConstHandle<BooleanAdapter> booleanAdapter = getManager()->getBooleanAdapter();
booleanAdapter->llvmCompileToModule( moduleBuilder );
RC::ConstHandle<SizeAdapter> sizeAdapter = getManager()->getSizeAdapter();
sizeAdapter->llvmCompileToModule( moduleBuilder );
RC::ConstHandle<StringAdapter> stringAdapter = getManager()->getStringAdapter();
stringAdapter->llvmCompileToModule( moduleBuilder );
RC::ConstHandle<ConstStringAdapter> constStringAdapter = getManager()->getConstStringAdapter();
constStringAdapter->llvmCompileToModule( moduleBuilder );
static const bool buildFunctions = true;
{
ConstructorBuilder functionBuilder( moduleBuilder, stringAdapter, this, ConstructorBuilder::HighCost );
if ( buildFunctions )
{
llvm::Value *stringLValue = functionBuilder[0];
BasicBlockBuilder basicBlockBuilder( functionBuilder );
basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
std::string name = getUserName();
ExprValue exprValue( constStringAdapter, USAGE_RVALUE, context, constStringAdapter->llvmConst( basicBlockBuilder, name.data(), name.length() ) );
llvm::Value *stringRValue = stringAdapter->llvmCast( basicBlockBuilder, exprValue );
stringAdapter->llvmAssign( basicBlockBuilder, stringLValue, stringRValue );
stringAdapter->llvmDispose( basicBlockBuilder, stringRValue );
basicBlockBuilder->CreateRetVoid();
}
}
{
ConstructorBuilder functionBuilder( moduleBuilder, booleanAdapter, this, ConstructorBuilder::HighCost );
if ( buildFunctions )
{
llvm::Value *booleanLValue = functionBuilder[0];
llvm::Value *rValue = functionBuilder[1];
BasicBlockBuilder basicBlockBuilder( functionBuilder );
basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
llvm::Value *arrayProducerRValue = basicBlockBuilder->CreateLoad( rValue );
basicBlockBuilder->CreateStore(
basicBlockBuilder->CreateIsNotNull( arrayProducerRValue ),
booleanLValue
);
basicBlockBuilder->CreateRetVoid();
}
}
{
MethodBuilder functionBuilder( moduleBuilder, sizeAdapter, this, USAGE_RVALUE, "getCount" );
if ( buildFunctions )
{
BasicBlockBuilder basicBlockBuilder( functionBuilder );
llvm::Value *rValue = functionBuilder[0];
llvm::BasicBlock *entryBB = basicBlockBuilder.getFunctionBuilder().createBasicBlock( "entry" );
basicBlockBuilder->SetInsertPoint( entryBB );
basicBlockBuilder->CreateRet(
llvmGetCount( basicBlockBuilder, rValue )
);
}
}
{
MethodBuilder functionBuilder(
moduleBuilder,
m_elementVariableArrayAdapter,
this, USAGE_RVALUE,
"produce"
);
if ( buildFunctions )
{
BasicBlockBuilder basicBlockBuilder( functionBuilder );
llvm::Value *rValue = functionBuilder[0];
llvm::BasicBlock *entryBB = basicBlockBuilder.getFunctionBuilder().createBasicBlock( "entry" );
basicBlockBuilder->SetInsertPoint( entryBB );
llvmProduce0( basicBlockBuilder, rValue, functionBuilder.getScope().llvmGetReturnLValue() );
basicBlockBuilder->CreateRetVoid();
}
}
{
MethodBuilder functionBuilder(
moduleBuilder, m_elementAdapter,
this, USAGE_RVALUE,
"produce",
"index", sizeAdapter, USAGE_RVALUE
);
if ( buildFunctions )
//.........这里部分代码省略.........
示例4: buildExprValue
CG::ExprValue IndexOp::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const
{
CG::ExprValue result( basicBlockBuilder.getContext() );
try
{
CG::ExprValue arrayExprValue = m_expr->buildExprValue( basicBlockBuilder, usage, lValueErrorDesc );
RC::ConstHandle<CG::Adapter> adapter = arrayExprValue.getAdapter();
if ( RT::isArray( arrayExprValue.getAdapter()->getType() ) )
{
RC::ConstHandle<CG::ArrayAdapter> arrayAdapter = RC::ConstHandle<CG::ArrayAdapter>::StaticCast( adapter );
CG::ExprValue indexExprValue = m_indexExpr->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
RC::ConstHandle< CG::SizeAdapter > sizeAdapter = basicBlockBuilder.getManager()->getSizeAdapter();
llvm::Value *indexExprRValue = sizeAdapter->llvmCast( basicBlockBuilder, indexExprValue );
if ( indexExprRValue )
{
switch ( usage )
{
case CG::USAGE_LVALUE:
result = CG::ExprValue(
arrayAdapter->getMemberAdapter(),
CG::USAGE_LVALUE,
basicBlockBuilder.getContext(),
arrayAdapter->llvmNonConstIndexOp(
basicBlockBuilder,
arrayExprValue.getValue(),
indexExprRValue,
&getLocation()
)
);
break;
default:
result = CG::ExprValue(
arrayAdapter->getMemberAdapter(),
CG::USAGE_RVALUE,
basicBlockBuilder.getContext(),
arrayAdapter->llvmConstIndexOp(
basicBlockBuilder,
arrayExprValue.getValue(),
indexExprRValue,
&getLocation()
)
);
break;
}
}
}
else if ( RT::isDict( arrayExprValue.getAdapter()->getType() ) )
{
RC::ConstHandle<CG::DictAdapter> dictAdapter = RC::ConstHandle<CG::DictAdapter>::StaticCast( adapter );
CG::ExprValue indexExprValue = m_indexExpr->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
RC::ConstHandle<CG::ComparableAdapter> keyAdapter = dictAdapter->getKeyAdapter();
llvm::Value *indexExprRValue = keyAdapter->llvmCast( basicBlockBuilder, indexExprValue );
if ( indexExprRValue )
{
switch ( usage )
{
case CG::USAGE_LVALUE:
result = CG::ExprValue(
dictAdapter->getValueAdapter(),
CG::USAGE_LVALUE,
basicBlockBuilder.getContext(),
dictAdapter->llvmGetLValue(
basicBlockBuilder,
arrayExprValue.getValue(),
indexExprRValue
)
);
break;
default:
result = CG::ExprValue(
dictAdapter->getValueAdapter(),
CG::USAGE_RVALUE,
basicBlockBuilder.getContext(),
dictAdapter->llvmGetRValue(
basicBlockBuilder,
arrayExprValue.getValue(),
indexExprRValue
)
);
break;
}
}
}
else throw CG::Error( getLocation(), "only arrays and dictionaries can be indexed" );
}
catch ( CG::Error e )
{
throw e;
}
catch ( Exception e )
{
throw CG::Error( getLocation(), e );
}
return result;
}