Esempio n. 1
0
    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" );
          stringAdapter->llvmInit( subBasicBlockBuilder, errorMsgBLValue );
          stringAdapter->llvmCallConcat(
            subBasicBlockBuilder,
            stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsgALValue ),
            errorMsgBRValue,
            errorMsgBLValue
            );
          stringAdapter->llvmDispose( subBasicBlockBuilder, errorMsgALValue );
          
          llvm::Value *errorMsgCRValue = stringAdapter->llvmCast( subBasicBlockBuilder,
            ExprValue( constStringAdapter, USAGE_RVALUE, context, constStringAdapter->llvmConst( subBasicBlockBuilder, " (" ) )
            );
          
          llvm::Value *errorMsgCLValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsgC" );
          stringAdapter->llvmInit( subBasicBlockBuilder, errorMsgCLValue );
          stringAdapter->llvmCallConcat(
            subBasicBlockBuilder,
            stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsgBLValue ),
            errorMsgCRValue,
            errorMsgCLValue
            );
          stringAdapter->llvmDispose( subBasicBlockBuilder, errorMsgBLValue );
          
          llvm::Value *indexStringRValue = stringAdapter->llvmCast(
            subBasicBlockBuilder,
            ExprValue( sizeAdapter, USAGE_RVALUE, context, indexRValue )
            );
            
          llvm::Value *errorMsg1PlusIndexLValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsg1PlusIndex" );
          stringAdapter->llvmInit( subBasicBlockBuilder, errorMsg1PlusIndexLValue );
          stringAdapter->llvmCallConcat(
            subBasicBlockBuilder,
            stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsgCLValue ),
            indexStringRValue,
            errorMsg1PlusIndexLValue
            );
          stringAdapter->llvmDispose( subBasicBlockBuilder, errorMsgCLValue );
          
          llvm::Value *errorMsg2RValue = stringAdapter->llvmCast(
            subBasicBlockBuilder,
            ExprValue( constStringAdapter, USAGE_RVALUE, context, constStringAdapter->llvmConst( subBasicBlockBuilder, ") out of range (" ) )
            );
            
          llvm::Value *errorMsg1PlusIndexPlusErrorMsg2LValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsg1PlusIndexPlusErrorMsg2" );
          stringAdapter->llvmInit( subBasicBlockBuilder, errorMsg1PlusIndexPlusErrorMsg2LValue );
          stringAdapter->llvmCallConcat(
            subBasicBlockBuilder,
            stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsg1PlusIndexLValue ),
            errorMsg2RValue,
            errorMsg1PlusIndexPlusErrorMsg2LValue
            );
          stringAdapter->llvmDispose( subBasicBlockBuilder, errorMsg1PlusIndexLValue );

          llvm::Value *sizeStringRValue = stringAdapter->llvmCast(
            subBasicBlockBuilder,
            ExprValue( sizeAdapter, USAGE_RVALUE, context, sizeRValue )
            );
            
          llvm::Value *errorMsg1PlusIndexPlusErrorMsg2PlusSizeLValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsg1PlusIndexPlusErrorMsg2PlusSize" );
          stringAdapter->llvmInit( subBasicBlockBuilder, errorMsg1PlusIndexPlusErrorMsg2PlusSizeLValue );
          stringAdapter->llvmCallConcat(
            subBasicBlockBuilder,
            stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsg1PlusIndexPlusErrorMsg2LValue ),
            sizeStringRValue,
            errorMsg1PlusIndexPlusErrorMsg2PlusSizeLValue
            );
          stringAdapter->llvmDispose( subBasicBlockBuilder, errorMsg1PlusIndexPlusErrorMsg2LValue );

          llvm::Value *errorMsg3RValue = stringAdapter->llvmCast(
            subBasicBlockBuilder,
            ExprValue( constStringAdapter, USAGE_RVALUE, context, constStringAdapter->llvmConst( subBasicBlockBuilder, ")" ) )
            );
            
          errorMsg1PlusIndexPlusErrorMsg2PlusSizePlusErrorMsg3LValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsg1PlusIndexPlusErrorMsg2PlusSizePlusErrorMsg3" );
          stringAdapter->llvmInit( subBasicBlockBuilder, errorMsg1PlusIndexPlusErrorMsg2PlusSizePlusErrorMsg3LValue );
          stringAdapter->llvmCallConcat(
            subBasicBlockBuilder,
            stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsg1PlusIndexPlusErrorMsg2PlusSizeLValue ),
            errorMsg3RValue,
            errorMsg1PlusIndexPlusErrorMsg2PlusSizePlusErrorMsg3LValue
            );
          stringAdapter->llvmDispose( subBasicBlockBuilder, errorMsg1PlusIndexPlusErrorMsg2PlusSizeLValue );
          
          subScope.llvmUnwind( subBasicBlockBuilder );
        }
        llvmThrowException( bbb, errorMsg1PlusIndexPlusErrorMsg2PlusSizePlusErrorMsg3LValue );
        bbb->CreateRetVoid();
      }
      
      std::vector<llvm::Value *> args;
      args.push_back( itemDescRValue );
      args.push_back( indexRValue );
      args.push_back( sizeRValue );
      args.push_back( errorDescRValue );
      basicBlockBuilder->CreateCall( func, args.begin(), args.end() );
    }
Esempio n. 2
0
 void StructAdapter::llvmCompileToModule( ModuleBuilder &moduleBuilder ) const
 {
   if ( moduleBuilder.haveCompiledToModule( getCodeName() ) )
     return;
     
   RC::Handle<Context> context = moduleBuilder.getContext();
   
   RC::ConstHandle<StringAdapter> stringAdapter = getManager()->getStringAdapter();
   stringAdapter->llvmCompileToModule( moduleBuilder );
   RC::ConstHandle<SizeAdapter> sizeAdapter = getManager()->getSizeAdapter();
   sizeAdapter->llvmCompileToModule( moduleBuilder );
   RC::ConstHandle<OpaqueAdapter> dataAdapter = getManager()->getDataAdapter();
   dataAdapter->llvmCompileToModule( moduleBuilder );
   for ( MemberAdaptorVector::const_iterator it=m_memberAdapters.begin(); it!=m_memberAdapters.end(); ++it )
     (*it)->llvmCompileToModule( moduleBuilder );
   
   static const bool buildFunctions = true;
   
   if ( !m_isShallow )
   {
     {
       InternalFunctionBuilder functionBuilder(
         moduleBuilder,
         0, "__" + getCodeName() + "__DefaultAssign",
         "dst", this, USAGE_LVALUE,
         "src", this, USAGE_RVALUE,
         0
         );
       if ( buildFunctions )
       {
         llvm::Value *dstLValue = functionBuilder[0];
         llvm::Value *srcRValue = functionBuilder[1];
         BasicBlockBuilder basicBlockBuilder( functionBuilder );
         basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
         for ( size_t i=0; i<getNumMembers(); ++i )
         {
           RC::ConstHandle<Adapter> const &memberAdapter = m_memberAdapters[i];
           llvm::Value *dstMemberLValue = basicBlockBuilder->CreateConstGEP2_32( dstLValue, 0, i );
           llvm::Value *srcMemberLValue = basicBlockBuilder->CreateConstGEP2_32( srcRValue, 0, i );
           llvm::Value *srcMemberRValue = memberAdapter->llvmLValueToRValue( basicBlockBuilder, srcMemberLValue );
           memberAdapter->llvmAssign( basicBlockBuilder, dstMemberLValue, srcMemberRValue );
         }
         basicBlockBuilder->CreateRetVoid();
       }
     }
   }
   
   {
     ConstructorBuilder functionBuilder( moduleBuilder, stringAdapter, this, ConstructorBuilder::HighCost );
     if ( buildFunctions )
     {
       llvm::Value *stringLValue = functionBuilder[0];
       llvm::Value *structRValue = functionBuilder[1];
       BasicBlockBuilder basicBlockBuilder( functionBuilder );
       basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
       llvm::Value *structLValue = llvmRValueToLValue( basicBlockBuilder, structRValue );
       stringAdapter->llvmCallCast( basicBlockBuilder, this, structLValue, stringLValue );
       basicBlockBuilder->CreateRetVoid();
     }
   }
   
   if ( getDesc()->isShallow() )
   {
     {
       MethodBuilder functionBuilder(
         moduleBuilder,
         sizeAdapter,
         this, USAGE_RVALUE,
         "dataSize"
         );
       if ( buildFunctions )
       {
         BasicBlockBuilder basicBlockBuilder( functionBuilder );
         basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
         llvm::Value *dataSizeRValue = llvm::ConstantInt::get( sizeAdapter->llvmRType( context ), getDesc()->getAllocSize() );
         basicBlockBuilder->CreateRet( dataSizeRValue );
       }
     }
     
     {
       MethodBuilder functionBuilder(
         moduleBuilder,
         dataAdapter,
         this, USAGE_LVALUE,
         "data"
         );
       if ( buildFunctions )
       {
         llvm::Value *thisLValue = functionBuilder[0];
         BasicBlockBuilder basicBlockBuilder( functionBuilder );
         basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
         basicBlockBuilder->CreateRet( basicBlockBuilder->CreatePointerCast( thisLValue, dataAdapter->llvmRType( context ) ) );
       }
     }
   }
 }
Esempio n. 3
0
 void OpaqueAdapter::llvmCompileToModule( ModuleBuilder &moduleBuilder ) const
 {
   if ( moduleBuilder.haveCompiledToModule( getCodeName() ) )
     return;
   
   RC::Handle<Context> context = moduleBuilder.getContext();
   
   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<OpaqueAdapter> dataAdapter = getManager()->getDataAdapter();
   dataAdapter->llvmCompileToModule( moduleBuilder );
   
   static const bool buildFunctions = true;
   
   {
     ConstructorBuilder functionBuilder( moduleBuilder, booleanAdapter, this, ConstructorBuilder::HighCost );
     if ( buildFunctions )
     {
       llvm::Value *booleanLValue = functionBuilder[0];
       llvm::Value *opaqueRValue = functionBuilder[1];
       BasicBlockBuilder basicBlockBuilder( functionBuilder );
       basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
       llvm::Value *booleanRValue = basicBlockBuilder->CreateIsNotNull( opaqueRValue );
       booleanAdapter->llvmAssign( basicBlockBuilder, booleanLValue, booleanRValue );
       basicBlockBuilder->CreateRetVoid();
     }
   }
   
   {
     ConstructorBuilder functionBuilder( moduleBuilder, stringAdapter, this, ConstructorBuilder::HighCost );
     if ( buildFunctions )
     {
       llvm::Value *stringLValue = functionBuilder[0];
       llvm::Value *opaqueRValue = functionBuilder[1];
       BasicBlockBuilder basicBlockBuilder( functionBuilder );
       basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
       llvm::Value *opaqueLValue = llvmRValueToLValue( basicBlockBuilder, opaqueRValue );
       stringAdapter->llvmCallCast( basicBlockBuilder, this, opaqueLValue, stringLValue );
       basicBlockBuilder->CreateRetVoid();
     }
   }
   
   {
     MethodBuilder functionBuilder(
       moduleBuilder,
       sizeAdapter,
       this, USAGE_RVALUE,
       "dataSize"
       );
     if ( buildFunctions )
     {
       BasicBlockBuilder basicBlockBuilder( functionBuilder );
       basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
       llvm::Value *dataSizeRValue = sizeAdapter->llvmConst( context, getDesc()->getAllocSize() );
       basicBlockBuilder->CreateRet( dataSizeRValue );
     }
   }
   
   {
     MethodBuilder functionBuilder(
       moduleBuilder,
       dataAdapter,
       this, USAGE_LVALUE,
       "data"
       );
     if ( buildFunctions )
     {
       llvm::Value *thisLValue = functionBuilder[0];
       BasicBlockBuilder basicBlockBuilder( functionBuilder );
       basicBlockBuilder->SetInsertPoint( functionBuilder.createBasicBlock( "entry" ) );
       basicBlockBuilder->CreateRet( basicBlockBuilder->CreatePointerCast( thisLValue, dataAdapter->llvmRType( context ) ) );
     }
   }
 }
    CG::ExprValue CreateArrayGenerator::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() < 1 )
        throw MR::ArrayGeneratorOperator::GetPrototypeException();

      CG::ExprType countExprType = m_count->getExprType( basicBlockBuilder );
      if ( !RT::isValueProducer( countExprType.getAdapter()->getType() ) )
        throw CG::Error( getLocation(), "count must be a value producer" );
      RC::ConstHandle<CG::ValueProducerAdapter> countValueProducerAdapter = RC::ConstHandle<CG::ValueProducerAdapter>::StaticCast( countExprType.getAdapter() );
      RC::ConstHandle<CG::Adapter> countAdapter = countValueProducerAdapter->getValueAdapter();
      if ( countAdapter != sizeAdapter )
        throw CG::Error( getLocation(), "count value type must be 'Size'" );
      CG::ExprValue countValueProducerExprValue = m_count->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
        
      if ( operatorParams[0].getUsage() != CG::USAGE_LVALUE )
        throw CG::Error( getLocation(), "operator value parameter must be an 'io' parameter" );
      RC::ConstHandle<CG::Adapter> outputAdapter = operatorParams[0].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() >= 2 )
      {
        if ( operatorParams[1].getAdapter() != sizeAdapter )
          throw CG::Error( getLocation(), "operator index parameter type (" + operatorParams[1].getAdapter()->getUserName() + ") must be 'Size'" );
        if ( operatorParams[1].getUsage() != CG::USAGE_RVALUE )
          throw CG::Error( getLocation(), "operator index parameter must be an 'in' parameter" );
          
        if ( operatorParams.size() >= 3 )
        {
          if ( operatorParams[2].getAdapter() != sizeAdapter )
            throw CG::Error( getLocation(), "operator index parameter type (" + operatorParams[2].getAdapter()->getUserName() + ") must be 'Size'" );
          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.size() > 4 )
              throw MR::ArrayGeneratorOperator::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[3].getAdapter() != sharedAdapter )
              throw CG::Error( getLocation(), "operator shared value parameter type (" + operatorParams[3].getAdapter()->getUserName() + ") does not match shared value type (" + sharedAdapter->getUserName() + ")" );
            if ( operatorParams[3].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 const *> argTypes;
            argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // function
            argTypes.push_back( sizeAdapter->llvmRType( context ) ); // numParams
            argTypes.push_back( countValueProducerAdapter->llvmLType( context ) ); // count value producer
            argTypes.push_back( sharedValueProducerAdapter->llvmLType( context ) ); // shared value producer
            argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // output array producer adapter
            argTypes.push_back( outputArrayProducerAdapter->llvmLType( context ) ); // output array producer
            llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
            llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateArrayGenerator_4", 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() ) );
            args.push_back( countValueProducerExprValue.getValue() );
            args.push_back( sharedExprRValue.getValue() );
            args.push_back( outputArrayProducerAdapter->llvmAdapterPtr( basicBlockBuilder ) );
            args.push_back( resultLValue );
            basicBlockBuilder->CreateCall( func, args.begin(), args.end() );
            
            needCall = false;
          }
        }
      }
      
      if ( needCall )
      {
        std::vector<llvm::Type const *> argTypes;
        argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // function
        argTypes.push_back( sizeAdapter->llvmRType( context ) ); // numParams
        argTypes.push_back( countValueProducerAdapter->llvmLType( context ) ); // count value producer
        argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // output array producer adapter
        argTypes.push_back( outputArrayProducerAdapter->llvmLType( context ) ); // output array producer
        llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
        llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateArrayGenerator_3", 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() ) );
        args.push_back( countValueProducerExprValue.getValue() );
        args.push_back( outputArrayProducerAdapter->llvmAdapterPtr( basicBlockBuilder ) );
        args.push_back( resultLValue );
        basicBlockBuilder->CreateCall( func, args.begin(), args.end() );
      }

      return CG::ExprValue(
        outputArrayProducerAdapter,
        CG::USAGE_RVALUE,
        context,
        outputArrayProducerAdapter->llvmLValueToRValue( basicBlockBuilder, resultLValue )
        );
    }