本文整理汇总了C++中rc::ConstHandle::getElementAdapter方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstHandle::getElementAdapter方法的具体用法?C++ ConstHandle::getElementAdapter怎么用?C++ ConstHandle::getElementAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rc::ConstHandle
的用法示例。
在下文中一共展示了ConstHandle::getElementAdapter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildExprValue
CG::ExprValue CreateArrayMap::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const
{
if ( usage == CG::USAGE_LVALUE )
throw Exception( "cannot be used as l-values" );
RC::Handle<CG::Context> context = basicBlockBuilder.getContext();
llvm::LLVMContext &llvmContext = context->getLLVMContext();
RC::ConstHandle<CG::SizeAdapter> sizeAdapter = basicBlockBuilder.getManager()->getSizeAdapter();
RC::ConstHandle<CG::Symbol> operatorSymbol = basicBlockBuilder.getScope().get( m_operatorName );
if ( !operatorSymbol )
throw CG::Error( getLocation(), _(m_operatorName) + ": operator not found" );
if ( !operatorSymbol->isPencil() )
throw CG::Error( getLocation(), _(m_operatorName) + ": not an operator" );
RC::ConstHandle<CG::PencilSymbol> pencil = RC::ConstHandle<CG::PencilSymbol>::StaticCast( operatorSymbol );
CG::Function const *function = pencil->getUniqueFunction( getLocation(), "operator " + _(m_operatorName) );
std::vector<CG::FunctionParam> const &operatorParams = function->getParams();
if ( operatorParams.size() < 2 )
throw MR::ArrayMapOperator::GetPrototypeException();
CG::ExprType inputExprType = m_input->getExprType( basicBlockBuilder );
if ( !RT::isArrayProducer( inputExprType.getAdapter()->getType() ) )
throw CG::Error( getLocation(), "input must be a value producer" );
RC::ConstHandle<CG::ArrayProducerAdapter> inputArrayProducerAdapter = RC::ConstHandle<CG::ArrayProducerAdapter>::StaticCast( inputExprType.getAdapter() );
RC::ConstHandle<CG::Adapter> inputAdapter = inputArrayProducerAdapter->getElementAdapter();
if ( !operatorParams[0].getAdapter()->isEquivalentTo( inputAdapter ) )
throw CG::Error( getLocation(), "operator input value parameter type (" + operatorParams[0].getAdapter()->getUserName() + ") does not match input array producer element type (" + inputAdapter->getUserName() + ")" );
if ( operatorParams[0].getUsage() != CG::USAGE_RVALUE )
throw CG::Error( getLocation(), "operator input value parameter must be an 'in' parameter" );
CG::ExprValue inputExprRArray = m_input->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
if ( operatorParams[1].getUsage() != CG::USAGE_LVALUE )
throw CG::Error( getLocation(), "operator output value parameter must be an 'io' parameter" );
RC::ConstHandle<CG::Adapter> outputAdapter = operatorParams[1].getAdapter();
RC::ConstHandle<CG::ArrayProducerAdapter> outputArrayProducerAdapter = basicBlockBuilder.getManager()->getArrayProducerOf( outputAdapter );
llvm::Value *resultLValue = outputArrayProducerAdapter->llvmAlloca( basicBlockBuilder, "result" );
outputArrayProducerAdapter->llvmInit( basicBlockBuilder, resultLValue );
basicBlockBuilder.getScope().put(
CG::VariableSymbol::Create(
CG::ExprValue(
outputArrayProducerAdapter,
CG::USAGE_LVALUE,
context,
resultLValue
)
)
);
bool needCall = true;
if ( operatorParams.size() >= 3 )
{
if ( !operatorParams[2].getAdapter()->isEquivalentTo( sizeAdapter ) )
throw CG::Error( getLocation(), "operator index parameter type (" + operatorParams[2].getAdapter()->getUserName() + ") must be 'Index'" );
if ( operatorParams[2].getUsage() != CG::USAGE_RVALUE )
throw CG::Error( getLocation(), "operator index parameter must be an 'in' parameter" );
if ( operatorParams.size() >= 4 )
{
if ( !operatorParams[3].getAdapter()->isEquivalentTo( sizeAdapter ) )
throw CG::Error( getLocation(), "operator count parameter type (" + operatorParams[3].getAdapter()->getUserName() + ") must be 'Size'" );
if ( operatorParams[3].getUsage() != CG::USAGE_RVALUE )
throw CG::Error( getLocation(), "operator count parameter must be an 'in' parameter" );
if ( operatorParams.size() >= 5 )
{
if ( operatorParams.size() > 5 )
throw MR::ArrayMapOperator::GetPrototypeException();
if ( !m_shared )
throw CG::Error( getLocation(), "operator takes a shared value but no shared value is provided" );
CG::ExprType sharedExprType = m_shared->getExprType( basicBlockBuilder );
if ( !RT::isValueProducer( sharedExprType.getAdapter()->getType() ) )
throw CG::Error( getLocation(), "shared value must be a value producer" );
RC::ConstHandle<CG::ValueProducerAdapter> sharedValueProducerAdapter = RC::ConstHandle<CG::ValueProducerAdapter>::StaticCast( sharedExprType.getAdapter() );
RC::ConstHandle<CG::Adapter> sharedAdapter = sharedValueProducerAdapter->getValueAdapter();
if ( operatorParams[4].getAdapter() != sharedAdapter )
throw CG::Error( getLocation(), "operator shared value parameter type (" + operatorParams[4].getAdapter()->getUserName() + ") does not match shared value type (" + sharedAdapter->getUserName() + ")" );
if ( operatorParams[4].getUsage() != CG::USAGE_RVALUE )
throw CG::Error( getLocation(), "operator shared value parameter must be an 'in' parameter" );
CG::ExprValue sharedExprRValue = m_shared->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
std::vector<llvm::Type *> argTypes;
argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // function
argTypes.push_back( sizeAdapter->llvmRType( context ) ); // numParams
argTypes.push_back( inputArrayProducerAdapter->llvmLType( context ) ); // input array producer
argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // output array producer adapter
argTypes.push_back( sharedValueProducerAdapter->llvmLType( context ) ); // shared array producer
argTypes.push_back( outputArrayProducerAdapter->llvmLType( context ) ); // output array producer
llvm::FunctionType *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateArrayMap_5", funcType );
std::vector<llvm::Value *> args;
args.push_back( basicBlockBuilder->CreateBitCast(
function->getLLVMFunction(),
llvm::Type::getInt8PtrTy( llvmContext )
) );
args.push_back( sizeAdapter->llvmConst( context, operatorParams.size() ) );
//.........这里部分代码省略.........