示例#1
0
 ValueGenerator::ValueGenerator(
   RC::ConstHandle<ValueOutputOperator> const &operator_,
   RC::ConstHandle<ValueProducer> const &shared
   )
   : m_operator( operator_ )
   , m_shared( shared )
 {
   RC::ConstHandle<RT::Desc> operatorValueDesc = m_operator->getValueDesc();
   if ( !operatorValueDesc )
     throw Exception("operator is invalid");
   m_valueDesc = operatorValueDesc;
   
   RC::ConstHandle<RT::Desc> operatorSharedDesc = m_operator->getSharedDesc();
   if ( operatorSharedDesc )
   {
     RC::ConstHandle<RT::Desc> sharedValueDesc = m_shared? m_shared->getValueDesc(): RC::ConstHandle<RT::Desc>();
     if ( !sharedValueDesc )
       throw Exception( "operator requires a shared value but no shared value producer is provided" );
     if ( !sharedValueDesc->isEquivalentTo( operatorSharedDesc ) )
       throw Exception(
         "shared value type ("
         + _(sharedValueDesc->getUserName())
         + ") is not equivalent to operator shared type ("
         + _(operatorSharedDesc->getUserName()) + ")"
         );
   }
 }
示例#2
0
 void ValueGenerator::ComputeState::produce( void *data ) const
 {
   RC::ConstHandle<ValueOutputOperator> valueTransformOperator = m_valueTransform->m_operator;
   if ( valueTransformOperator->takesSharedValue() )
     valueTransformOperator->call( data, &m_sharedData[0] );
   else valueTransformOperator->call( data );
 }
示例#3
0
 void DictImpl::encodeJSON( void const *data, JSON::Encoder &encoder ) const
 {
   RC::ConstHandle<StringImpl> keyImplAsStringImpl;
   if ( isString( m_keyImpl->getType() ) )
     keyImplAsStringImpl = RC::ConstHandle<StringImpl>::StaticCast( m_keyImpl );
   
   JSON::ObjectEncoder objectEncoder = encoder.makeObject();
   bits_t const *bits = *reinterpret_cast<bits_t const * const *>( data );
   if ( bits )
   {
     node_t *node = bits->firstNode;
     while ( node )
     {
       void const *keyData = immutableKeyData( node );
       void const *valueData = immutableValueData( node );
       if ( keyImplAsStringImpl )
       {
         JSON::Encoder memberEncoder = objectEncoder.makeMember( keyImplAsStringImpl->getValueData( keyData ), keyImplAsStringImpl->getValueLength( keyData ) );
         m_valueImpl->encodeJSON( valueData, memberEncoder );
       }
       else
       {
         Util::SimpleString encodedKey;
         {
           JSON::Encoder encodedKeyEncoder( &encodedKey );
           m_keyImpl->encodeJSON( keyData, encodedKeyEncoder );
         }
         JSON::Encoder memberEncoder = objectEncoder.makeMember( encodedKey );
         m_valueImpl->encodeJSON( valueData, memberEncoder );
       }
       node = node->bitsNextNode;
     }
   }
 }
示例#4
0
    void *ExecutionEngine::LazyFunctionCreator( std::string const &functionName )
    {
      if ( functionName == "report" )
        return (void *)&ExecutionEngine::Report;
      else
      {
        void *result = 0;
        if ( !result )
          result = KL::LookupExternalSymbol( functionName );
        if ( !result )
          result = Plug::Manager::Instance()->llvmResolveExternalFunction( functionName );
#if defined(FABRIC_MODULE_OPENCL)
        if ( !result )
          result = OCL::llvmResolveExternalFunction( functionName );
#endif
        if ( !result )
        {
          RC::ConstHandle<Context> context = s_currentContext;
          result = context->getCGManager()->llvmResolveExternalFunction( functionName );
        }
        
        // We should *always* return a valid symbol. Otherwise something's
        // wrong in the KL compiler/support.
        if( !result )
          throw Exception( "LLVM lookup failed for symbol: " + functionName );

        return result;
      }
    }
示例#5
0
 bool Function::isLValueToRValueMatch( ExprTypeVector const &argTypes ) const
 {
   if ( argTypes.size() != m_params.size() )
     return false;
   
   for ( size_t i=0; i<argTypes.size(); ++i )
   {
     Usage argUsage = argTypes[i].getUsage(), paramUsage = m_params[i].getUsage();
     RC::ConstHandle<Adapter> argAdapter = argTypes[i].getAdapter(), paramAdapter = m_params[i].getAdapter();
     
     if ( argUsage == paramUsage
       && argAdapter->isEquivalentTo( paramAdapter )
       )
       continue;
       
     if ( paramUsage == USAGE_RVALUE )
     {
       if ( argUsage == USAGE_LVALUE
         && argAdapter->isEquivalentTo( paramAdapter )
         )
         continue;
     }
       
     return false;
   }
   
   return true;
 }
示例#6
0
    bool SlicedArrayImpl::isEquivalentTo( RC::ConstHandle<Impl> const &that ) const
    {
      if ( !isSlicedArray( that->getType() ) )
        return false;
      RC::ConstHandle<SlicedArrayImpl> slicedArrayImpl = RC::ConstHandle<SlicedArrayImpl>::StaticCast( that );

      return getMemberImpl()->isEquivalentTo( slicedArrayImpl->getMemberImpl() );
    }
示例#7
0
 SlicedArrayImpl::SlicedArrayImpl( std::string const &codeName, RC::ConstHandle<Impl> const &memberImpl )
   : ArrayImpl( codeName, DT_SLICED_ARRAY, memberImpl )
   , m_memberImpl( memberImpl )
   , m_memberSize( memberImpl->getAllocSize() )
   , m_variableArrayImpl( memberImpl->getVariableArrayImpl() )
 {
   setSize( sizeof(bits_t) );
 }
示例#8
0
 ValueGenerator::ComputeState::~ComputeState()
 {
   if ( m_valueTransform->m_operator->takesSharedValue() )
   {
     RC::ConstHandle<ValueProducer> sharedValueProducer = m_valueTransform->m_shared;
     sharedValueProducer->getValueDesc()->disposeData( &m_sharedData[0] );
   }
 }
示例#9
0
 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 ) );
 }
示例#10
0
 BCCache::BCCache( std::string const &compileOptionsString )
 {
   RC::ConstHandle<IO::Dir> rootDir = IO::Dir::Private();
   RC::ConstHandle<IO::Dir> baseDir = IO::Dir::Create( rootDir, "IRCache" );
   baseDir->recursiveDeleteFilesOlderThan( time(NULL) - FABRIC_BC_CACHE_EXPIRY_SEC );
   RC::ConstHandle<IO::Dir> osDir = IO::Dir::Create( baseDir, buildOS );
   RC::ConstHandle<IO::Dir> archDir = IO::Dir::Create( osDir, runningArch );
   RC::ConstHandle<IO::Dir> compileOptionsDir = IO::Dir::Create( archDir, compileOptionsString );
   m_dir = IO::Dir::Create( compileOptionsDir, buildCacheGeneration );
 }
示例#11
0
 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();
 }
 ArrayProducerAdapter::ArrayProducerAdapter(
   RC::ConstHandle<Manager> const &manager,
   RC::ConstHandle<RT::ArrayProducerDesc> const &arrayProducerDesc
   )
   : Adapter( manager, arrayProducerDesc, FL_PASS_BY_REFERENCE )
   , m_arrayProducerDesc( arrayProducerDesc )
   , m_elementAdapter( manager->getAdapter( arrayProducerDesc->getElementDesc() ) )
   , m_elementVariableArrayAdapter( manager->getVariableArrayOf( m_elementAdapter ) )
 {
 }
示例#13
0
 void ArrayProducer::ComputeState::produceJSON( size_t index, JSON::Encoder &jg ) const
 {
   RC::ConstHandle<RT::Desc> elementDesc = m_arrayProducer->getElementDesc();
   
   size_t allocSize = elementDesc->getAllocSize();
   void *valueData = alloca( allocSize );
   memset( valueData, 0, allocSize );
   produce( index, valueData );
   elementDesc->encodeJSON( valueData, jg );
   elementDesc->disposeData( valueData );
 }
 void ArrayProducerAdapter::Produce2( void const *_adapter, void const *arrayProducerRValue, size_t indexRValue, size_t countRValue, void *dstLValue )
 {
   MR::ArrayProducer *arrayProducer = *static_cast<MR::ArrayProducer * const *>( arrayProducerRValue );
   if ( arrayProducer )
   {
     RC::ConstHandle<RT::VariableArrayDesc> elementVariableArrayDesc =  RC::ConstHandle<RT::VariableArrayDesc>::StaticCast( static_cast<ArrayProducerAdapter const *>( _adapter )->m_elementVariableArrayAdapter->getDesc() );
     elementVariableArrayDesc->setNumMembers( dstLValue, countRValue );
     void *firstMemberData = elementVariableArrayDesc->getMutableMemberData( dstLValue, 0 );
     arrayProducer->createComputeState()->produce( indexRValue, countRValue, firstMemberData );
   }
 }
示例#15
0
 ValueGenerator::ComputeState::ComputeState( RC::ConstHandle<ValueGenerator> const &valueTransform )
   : ValueProducer::ComputeState( valueTransform )
   , m_valueTransform( valueTransform )
 {
   if ( m_valueTransform->m_operator->takesSharedValue() )
   {
     RC::ConstHandle<ValueProducer> sharedValueProducer = m_valueTransform->m_shared;
     m_sharedData.resize( sharedValueProducer->getValueDesc()->getAllocSize(), 0 );
     sharedValueProducer->createComputeState()->produce( &m_sharedData[0] );
   }
 }
示例#16
0
 RC::ConstHandle<CaseVector> CaseVector::Create( RC::ConstHandle<Case> const &first, RC::ConstHandle<CaseVector> const &remaining )
 {
   CaseVector *result = new CaseVector;
   if ( first )
     result->push_back( first );
   if ( remaining )
   {
     for ( const_iterator it=remaining->begin(); it!=remaining->end(); ++it )
       result->push_back( *it );
   }
   return result;
 }
示例#17
0
 std::string BinOpFullDesc(
   RC::ConstHandle<Adapter> const &returnAdapter,
   BinOpType type,
   RC::ConstHandle<CG::Adapter> const &lhsAdapter,
   RC::ConstHandle<CG::Adapter> const &rhsAdapter
   )
 {
   std::string result = "function ";
   if ( returnAdapter )
     result += returnAdapter->getUserName() + " ";
   result += binOpUserName( type ) + "(" + lhsAdapter->getUserName() + ", " + rhsAdapter->getUserName() + ")";
   return result;
 }
示例#18
0
    llvm::MemoryBuffer *BCCache::get( std::string const &key ) const
    {
      RC::ConstHandle<IO::Dir> subDir;
      std::string entry;
      subDirAndEntryFromKey( key, subDir, entry );

      llvm::OwningPtr<llvm::MemoryBuffer> buffer;
      llvm::error_code fileError =
        llvm::MemoryBuffer::getFileOrSTDIN( subDir->getFullFilePath( entry ), buffer );
      if ( !fileError )
        return buffer.take();
      return NULL;
    }
示例#19
0
 llvm::Value *ArrayAdapter::llvmLocationConstStringRValue(
   BasicBlockBuilder &basicBlockBuilder,
   RC::ConstHandle<ConstStringAdapter> const &constStringAdapter,
   CG::Location const *location
   ) const
 {
   if ( location )
   {
     RC::ConstHandle<RC::String> filename = location->getFilename();
     std::string locationString = (filename? filename->stdString(): std::string("(unknown)")) + ":" + _(location->getLine()) + ":" + _(location->getColumn());
     return constStringAdapter->llvmConst( basicBlockBuilder, locationString );
   }
   else return constStringAdapter->llvmConst( basicBlockBuilder, "KL" );
 }
示例#20
0
 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 );
 }
示例#21
0
    bool Function::isImplicitCastMatch( ExprTypeVector const &argTypes, ModuleBuilder const &moduleBuilder, size_t &maxCost ) const
    {
      if ( argTypes.size() != m_params.size() )
        return false;
     
      maxCost = 0;
      size_t numExactTypeMatch = 0;
       
      for ( size_t i=0; i<argTypes.size(); ++i )
      {
        Usage argUsage = argTypes[i].getUsage(), paramUsage = m_params[i].getUsage();
        RC::ConstHandle<Adapter> argAdapter = argTypes[i].getAdapter(), paramAdapter = m_params[i].getAdapter();
        
        if ( argUsage == paramUsage
          && argAdapter->isEquivalentTo( paramAdapter )
          )
        {
          ++numExactTypeMatch;
          continue;
        }
          
        if ( paramUsage == USAGE_RVALUE )
        {
          if ( argUsage == USAGE_LVALUE
            && argAdapter->isEquivalentTo( paramAdapter )
            )
          {
            ++numExactTypeMatch;
            continue;
          }

          Function const *function = moduleBuilder.maybeGetPreciseFunction(
            ConstructorPencilKey( paramAdapter ),
            ExprTypeVector(
              ExprType( paramAdapter, USAGE_LVALUE ),
              ExprType( argAdapter, USAGE_RVALUE )
              )
            );
          if ( function )
          {
            maxCost += function->getPolymorphismParameters()->cost;
            continue;
          }
        }
          
        return false;
      }
      
      return numExactTypeMatch >= getPolymorphismParameters()->minExactTypeMatch;
    }
示例#22
0
    void BCCache::put( std::string const &key, llvm::Module *module ) const
    {
      RC::ConstHandle<IO::Dir> subDir;
      std::string entry;
      subDirAndEntryFromKey( key, subDir, entry );

      std::string errors;
      llvm::raw_fd_ostream bcStream(
        subDir->getFullFilePath( entry ).c_str(),
        errors,
        llvm::raw_fd_ostream::F_Binary
      );

      llvm::WriteBitcodeToFile( module, bcStream );
      bcStream.flush();
    }
示例#23
0
 std::string ConstructorQueryDesc(
   RC::ConstHandle<CG::Adapter> const &thisAdapter,
   AdapterVector const &paramAdapters
   )
 {
   return "constructor " + thisAdapter->getUserName() + DescParams( paramAdapters );
 }
示例#24
0
 std::string MethodPencilKey(
   RC::ConstHandle<CG::Adapter> const &thisAdapter,
   std::string const &name
   )
 {
   return "m:" + thisAdapter->getCodeName() + ":" + name;
 }
示例#25
0
 void MemberDecl::buildStructMemberInfo( RC::ConstHandle<RT::Manager> const &rtManager, RT::StructMemberInfo &structMemberInfo ) const
 {
   structMemberInfo.name = m_name;
   structMemberInfo.desc = rtManager->maybeGetDesc( m_type );
   if ( !structMemberInfo.desc )
     throw CG::Error( getLocation(), "member " + _(m_name) + ": type " + _(m_type) + " not registered" );
 }
示例#26
0
 std::string AssignOpFullDesc(
   RC::ConstHandle<CG::Adapter> const &thisAdapter,
   AssignOpType type,
   RC::ConstHandle<CG::Adapter> const &thatAdapter
   )
 {
   return "function " + thisAdapter->getUserName() + "." + assignOpUserName( type ) + "(" + thatAdapter->getUserName() + ")";
 }
示例#27
0
 std::string AssignOpQueryDesc(
   RC::ConstHandle<CG::Adapter> const &thisAdapter,
   AssignOpType type,
   RC::ConstHandle<CG::Adapter> const &thatAdapter
   )
 {
   return "assignment operator " + thisAdapter->getUserName() + " " + assignOpUserName( type ) + " " + thatAdapter->getUserName();
 }
示例#28
0
 std::string BinOpQueryDesc(
   BinOpType type,
   RC::ConstHandle<CG::Adapter> const &lhsAdapter,
   RC::ConstHandle<CG::Adapter> const &rhsAdapter
   )
 {
   return "binary operation " + lhsAdapter->getUserName() + " " + binOpUserName( type ) + " " + rhsAdapter->getUserName();
 }
示例#29
0
    bool DictImpl::isEquivalentTo( RC::ConstHandle<Impl> const &that ) const
    {
      if ( !isDict( that->getType() ) )
        return false;
      RC::ConstHandle<DictImpl> dictImpl = RC::ConstHandle<DictImpl>::StaticCast( that );

      return m_keyImpl->isEquivalentTo( dictImpl->m_keyImpl )
        && m_valueImpl->isEquivalentTo( dictImpl->m_valueImpl );
    }
示例#30
0
 DictImpl::DictImpl(
   std::string const &codeName,
   RC::ConstHandle<ComparableImpl> const &keyImpl,
   RC::ConstHandle<Impl> const &valueImpl
   )
   : m_keyImpl( keyImpl )
   , m_keySize( keyImpl->getAllocSize() )
   , m_valueImpl( valueImpl )
   , m_valueSize( valueImpl->getAllocSize() )
   , m_nodeSize( sizeof(node_t) + m_keySize + m_valueSize )
 {
   size_t flags = 0;
   if ( keyImpl->isNoAliasUnsafe() || valueImpl->isNoAliasUnsafe() )
     flags |= FlagNoAliasUnsafe;
   if ( m_keyImpl->isExportable() && m_valueImpl->isExportable() )
     flags |= FlagExportable;
   initialize( codeName, DT_DICT, sizeof(bits_t *), flags );
 }