Esempio n. 1
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 ) ) );
     }
   }
 }
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 ) ) );
       }
     }
   }
 }