当前位置: 首页>>代码示例>>C++>>正文


C++ cg::BasicBlockBuilder类代码示例

本文整理汇总了C++中cg::BasicBlockBuilder的典型用法代码示例。如果您正苦于以下问题:C++ BasicBlockBuilder类的具体用法?C++ BasicBlockBuilder怎么用?C++ BasicBlockBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BasicBlockBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: llvmCompileToBuilder

 void ReturnStatement::llvmCompileToBuilder( CG::BasicBlockBuilder &basicBlockBuilder, CG::Diagnostics &diagnostics ) const
 {
   try
   {
     CG::ReturnInfo const &returnInfo = basicBlockBuilder.getFunctionBuilder().getScope().getReturnInfo();
     if ( basicBlockBuilder->GetInsertBlock()->getTerminator() )
       throw CG::Error( getLocation(), "unreachable code" );
     CG::ExprValue returnExprValue( CG::ExprValue( basicBlockBuilder.getContext() ) );
     if ( m_expr )
     {
       if ( !returnInfo )
         throw CG::Error( getLocation(), "functions with no return types do not return values" );
       returnExprValue = m_expr->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, "cannot be assigned to" );
     }
     else
     {
       if ( returnInfo )
         throw CG::Error( getLocation(), "function must return a value" );
     }
     basicBlockBuilder.getScope().llvmReturn( basicBlockBuilder, returnExprValue );
   }
   catch ( Exception e )
   {
     addError( diagnostics, e );
   }
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:26,代码来源:ReturnStatement.cpp

示例2: buildExprValue

 CG::ExprValue ConstFloat::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const
 {
   if ( usage == CG::USAGE_LVALUE )
     throw Exception( "constants cannot be used as l-values" );
   RC::ConstHandle<CG::FloatAdapter> floatAdapter = basicBlockBuilder.getManager()->getFloat64Adapter();
   floatAdapter->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
   double value = Util::parseDouble( m_valueString );
   return CG::ExprValue( floatAdapter, CG::USAGE_RVALUE, basicBlockBuilder.getContext(), floatAdapter->llvmConst( basicBlockBuilder.getContext(), value ) );
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:9,代码来源:ConstFloat.cpp

示例3: llvmRelease

 void ArrayProducerAdapter::llvmRelease( CG::BasicBlockBuilder &basicBlockBuilder, llvm::Value *rValue ) const
 {    
   RC::Handle<Context> context = basicBlockBuilder.getContext();
   std::vector<llvm::Type *> argTypes;
   argTypes.push_back( llvmRType( context ) );
   llvm::FunctionType *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( context->getLLVMContext() ), argTypes, false );
   llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__"+getCodeName()+"__Release", funcType ); 
   basicBlockBuilder->CreateCall( func, rValue );
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:9,代码来源:ArrayProducerAdapter.cpp

示例4: getExprType

 CG::ExprType CreateArrayMap::getExprType( CG::BasicBlockBuilder &basicBlockBuilder ) const
 {
   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();
   RC::ConstHandle<CG::Adapter> outputAdapter = operatorParams[1].getAdapter();
   RC::ConstHandle<CG::ArrayProducerAdapter> outputArrayProducerAdapter = basicBlockBuilder.getManager()->getArrayProducerOf( outputAdapter );
   return CG::ExprType( outputArrayProducerAdapter, CG::USAGE_RVALUE );
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:14,代码来源:CreateArrayMap.cpp

示例5: llvmRType

 void ArrayProducerAdapter::llvmProduce0(
   CG::BasicBlockBuilder &basicBlockBuilder,
   llvm::Value *arrayProducerRValue,
   llvm::Value *dstLValue
   ) const
 {    
   RC::Handle<Context> context = basicBlockBuilder.getContext();
   std::vector<llvm::Type *> argTypes;
   argTypes.push_back( basicBlockBuilder->getInt8PtrTy() );
   argTypes.push_back( llvmRType( context ) );
   argTypes.push_back( m_elementVariableArrayAdapter->llvmLType( context ) );
   llvm::FunctionType *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( context->getLLVMContext() ), argTypes, false );
   llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__"+getCodeName()+"__Produce0", funcType ); 
   basicBlockBuilder->CreateCall3( func, llvmAdapterPtr( basicBlockBuilder ), arrayProducerRValue, dstLValue );
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:15,代码来源:ArrayProducerAdapter.cpp

示例6: buildExprValue

    CG::ExprValue CreateValueCache::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();
      
      CG::ExprType inputExprType = m_input->getExprType( basicBlockBuilder );
      if ( !RT::isValueProducer( inputExprType.getAdapter()->getType() ) )
        throw CG::Error( getLocation(), "input must be a value producer" );
      RC::ConstHandle<CG::ValueProducerAdapter> valueProducerAdapter = RC::ConstHandle<CG::ValueProducerAdapter>::StaticCast( inputExprType.getAdapter() );
      RC::ConstHandle<CG::Adapter> valueAdapter = valueProducerAdapter->getValueAdapter();
     
      CG::ExprValue inputExprRValue = m_input->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
      llvm::Value *resultLValue = valueProducerAdapter->llvmAlloca( basicBlockBuilder, "result" );

      valueProducerAdapter->llvmInit( basicBlockBuilder, resultLValue );
      basicBlockBuilder.getScope().put(
        CG::VariableSymbol::Create(
          CG::ExprValue(
            valueProducerAdapter,
            CG::USAGE_LVALUE,
            context,
            resultLValue
            )
          )
        );

      std::vector<llvm::Type const *> argTypes;
      argTypes.push_back( valueProducerAdapter->llvmLType( context ) );
      argTypes.push_back( valueProducerAdapter->llvmLType( context ) );
      llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
      llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateValueCache", funcType );
      
      basicBlockBuilder->CreateCall2(
        func,
        inputExprRValue.getValue(),
        resultLValue
        );
      
      return CG::ExprValue(
        valueProducerAdapter,
        CG::USAGE_RVALUE,
        context,
        valueProducerAdapter->llvmLValueToRValue( basicBlockBuilder, resultLValue )
        );
    }
开发者ID:nikelin,项目名称:PublicStable,代码行数:48,代码来源:CreateValueCache.cpp

示例7: buildExprValue

    CG::ExprValue MethodOp::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const
    {
      CG::Function const *function = getFunction( basicBlockBuilder );
      CG::ParamVector const &functionParams = function->getParams();
      
      try
      {
        CG::Usage thisUsage = functionParams[0].getUsage();
        std::vector<CG::Usage> argUsages;
        for ( size_t i=1; i<functionParams.size(); ++i )
          argUsages.push_back( functionParams[i].getUsage() );
        
        std::vector<CG::ExprValue> argExprValues;
        CG::ExprValue thisExprValue = m_expr->buildExprValue( basicBlockBuilder, thisUsage, "cannot be modified" );
        argExprValues.push_back( thisExprValue );
        m_args->appendExprValues( basicBlockBuilder, argUsages, argExprValues, "cannot be used as an io argument" );
        
        CG::ExprValue callResultExprValue = function->llvmCreateCall( basicBlockBuilder, argExprValues );

        CG::ExprValue result( basicBlockBuilder.getContext() );
        if ( function->getReturnInfo().getExprType() )
          result = callResultExprValue;
        else result = thisExprValue;

        return result.castTo( basicBlockBuilder, usage );
      }
      catch ( CG::Error e )
      {
        throw "calling method " + _(m_name) + " of type " + _(functionParams[0].getAdapter()->getUserName()) + ": " + e;
      }
      catch ( Exception e )
      {
        throw CG::Error( getLocation(), "calling method " + _(m_name) + " of type " + _(functionParams[0].getAdapter()->getUserName()) + ": " + e );
      }
    }
开发者ID:nikelin,项目名称:PublicStable,代码行数:35,代码来源:MethodOp.cpp

示例8: llvmDisposeImpl

 void StructAdapter::llvmDisposeImpl( CG::BasicBlockBuilder &basicBlockBuilder, llvm::Value *lValue ) const
 {
   for ( size_t i=0; i<m_memberAdapters.size(); ++i )
   {
     llvm::Value *memberLValue = basicBlockBuilder->CreateStructGEP( lValue, i );
     m_memberAdapters[i]->llvmDispose( basicBlockBuilder, memberLValue );
   }
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:8,代码来源:StructAdapter.cpp

示例9: buildExprValue

 CG::ExprValue ConstString::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const
 {
   if ( usage == CG::USAGE_LVALUE )
     throw Exception( "constants cannot be used as l-values" );
   std::string unquotedValue;
   try
   {
     unquotedValue = Util::parseQuotedString( m_value );
   }
   catch ( Exception e )
   {
     throw CG::Error( getLocation(), e.getDesc() + "(" + m_value + ")" );
   }
   RC::ConstHandle<CG::ConstStringAdapter> constStringAdapter = basicBlockBuilder.getManager()->getConstStringAdapter();
   constStringAdapter->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
   RC::ConstHandle<CG::StringAdapter> stringAdapter = basicBlockBuilder.getManager()->getStringAdapter();
   stringAdapter->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
   return CG::ExprValue( constStringAdapter, CG::USAGE_RVALUE, basicBlockBuilder.getContext(), constStringAdapter->llvmConst( basicBlockBuilder, unquotedValue.data(), unquotedValue.length() ) ).castTo( basicBlockBuilder, stringAdapter );
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:19,代码来源:ConstString.cpp

示例10: getExprType

 CG::ExprType MethodOp::getExprType( CG::BasicBlockBuilder &basicBlockBuilder ) const
 {
   RC::ConstHandle<CG::Adapter> adapter = getFunction( basicBlockBuilder )->getReturnInfo().getAdapter();
   if ( adapter )
   {
     adapter->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
     return CG::ExprType( adapter, CG::USAGE_RVALUE );
   }
   else return CG::ExprType();
 }
开发者ID:nikelin,项目名称:PublicStable,代码行数:10,代码来源:MethodOp.cpp

示例11: getExprType

 CG::ExprType IndexOp::getExprType( CG::BasicBlockBuilder &basicBlockBuilder ) const
 {
   CG::ExprType exprType = m_expr->getExprType( basicBlockBuilder );
   exprType.getAdapter()->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
   
   if ( RT::isArray( exprType.getAdapter()->getType() ) )
   {
     RC::ConstHandle<CG::ArrayAdapter> arrayType = RC::ConstHandle<CG::ArrayAdapter>::StaticCast( exprType.getAdapter() );
     
     RC::ConstHandle<CG::Adapter> memberAdapter = arrayType->getMemberAdapter();
     memberAdapter->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
     return CG::ExprType( memberAdapter, exprType.getUsage() );
   }
   else if ( RT::isDict( exprType.getAdapter()->getType() ) )
   {
     RC::ConstHandle<CG::DictAdapter> dictType = RC::ConstHandle<CG::DictAdapter>::StaticCast( exprType.getAdapter() );
     
     RC::ConstHandle<CG::Adapter> valueAdapter = dictType->getValueAdapter();
     valueAdapter->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
     return CG::ExprType( valueAdapter, exprType.getUsage() );
   }
   else throw Exception( "only arrays and dictionaries can be indexed" );
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:23,代码来源:IndexOp.cpp

示例12: 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 );
      }
    }
开发者ID:nikelin,项目名称:PublicStable,代码行数:23,代码来源:Report.cpp

示例13: buildExprValue

 CG::ExprValue CreateConstValue::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" );
   
   CG::ExprType childExprType = m_child->getExprType( basicBlockBuilder );
   RC::ConstHandle<CG::ValueProducerAdapter> valueProducerAdapter = basicBlockBuilder.getManager()->getValueProducerOf( childExprType.getAdapter() );
   
   RC::Handle<CG::Context> context = basicBlockBuilder.getContext();
   llvm::LLVMContext &llvmContext = context->getLLVMContext();
   
   std::vector<llvm::Type const *> argTypes;
   argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) );
   argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) );
   argTypes.push_back( valueProducerAdapter->llvmLType( context ) );
   llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
   llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateConstValue", funcType );
   
   CG::ExprValue childExprRValue = m_child->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
   llvm::Value *childExprLValue = childExprType.getAdapter()->llvmRValueToLValue( basicBlockBuilder, childExprRValue.getValue() );
   llvm::Value *resultLValue = valueProducerAdapter->llvmAlloca( basicBlockBuilder, "result" );
   valueProducerAdapter->llvmInit( basicBlockBuilder, resultLValue );
   basicBlockBuilder.getScope().put(
     CG::VariableSymbol::Create(
       CG::ExprValue(
         valueProducerAdapter,
         CG::USAGE_LVALUE,
         context,
         resultLValue
         )
       )
     );
   
   basicBlockBuilder->CreateCall3(
     func,
     valueProducerAdapter->llvmAdapterPtr( basicBlockBuilder ),
     basicBlockBuilder->CreatePointerCast(
       childExprLValue,
       llvm::Type::getInt8PtrTy( llvmContext )
       ),
     resultLValue
     );
   
   return CG::ExprValue(
     valueProducerAdapter,
     CG::USAGE_RVALUE,
     context,
     valueProducerAdapter->llvmLValueToRValue( basicBlockBuilder, resultLValue )
     );
 }
开发者ID:nikelin,项目名称:PublicStable,代码行数:50,代码来源:CreateConstValue.cpp

示例14: getExprType

 CG::ExprType ConstString::getExprType( CG::BasicBlockBuilder &basicBlockBuilder ) const
 {
   RC::ConstHandle<CG::Adapter> adapter = basicBlockBuilder.getManager()->getStringAdapter();
   adapter->llvmCompileToModule( basicBlockBuilder.getModuleBuilder() );
   return CG::ExprType( adapter, CG::USAGE_RVALUE );
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:6,代码来源:ConstString.cpp

示例15: 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;
 }
开发者ID:EgoIncarnate,项目名称:fe-devel,代码行数:98,代码来源:IndexOp.cpp


注:本文中的cg::BasicBlockBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。