Ignore:
Timestamp:
Jan 26, 2017, 6:05:38 PM (2 years ago)
Author:
cameron
Message:

FileSink? kernel

Location:
icGREP/icgrep-devel/icgrep/IR_Gen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5267 r5280  
    242242}
    243243
     244
     245PointerType * CBuilder::getFILEptrTy() {
     246    if (mFILEtype == nullptr) {
     247        mFILEtype = StructType::create(getContext(), "struct._IO_FILE");
     248    }
     249    return mFILEtype->getPointerTo();
     250}
     251
     252Value * CBuilder::CreateFOpenCall(Value * filename, Value * mode) {
     253    Function * fOpenFunc = mMod->getFunction("fopen");
     254    if (fOpenFunc == nullptr) {
     255        fOpenFunc = cast<Function>(mMod->getOrInsertFunction("fopen", getFILEptrTy(), getInt8Ty()->getPointerTo(), getInt8Ty()->getPointerTo(), nullptr));
     256        fOpenFunc->setCallingConv(llvm::CallingConv::C);
     257    }
     258    return CreateCall(fOpenFunc, {filename, mode});
     259}
     260
     261Value * CBuilder::CreateFWriteCall(Value * ptr, Value * size, Value * nitems, Value * stream) {
     262    Function * fWriteFunc = mMod->getFunction("fwrite");
     263    if (fWriteFunc == nullptr) {
     264        fWriteFunc = cast<Function>(mMod->getOrInsertFunction("fwrite", getSizeTy(), getVoidPtrTy(), getSizeTy(), getSizeTy(), getFILEptrTy(), nullptr));
     265        fWriteFunc->setCallingConv(llvm::CallingConv::C);
     266    }
     267    return CreateCall(fWriteFunc, {ptr, size, nitems, stream});
     268}
     269
     270Value * CBuilder::CreateFCloseCall(Value * stream) {
     271    Function * fCloseFunc = mMod->getFunction("fclose");
     272    if (fCloseFunc == nullptr) {
     273        fCloseFunc = cast<Function>(mMod->getOrInsertFunction("fclose", getInt32Ty(), getFILEptrTy(), nullptr));
     274        fCloseFunc->setCallingConv(llvm::CallingConv::C);
     275    }
     276    return CreateCall(fCloseFunc, {stream});
     277}
     278
    244279Value * CBuilder::CreatePThreadCreateCall(Value * thread, Value * attr, Function * start_routine, Value * arg) {
    245280    Function * pthreadCreateFunc = mMod->getFunction("pthread_create");
     
    285320, mMod(m)
    286321, mCacheLineAlignment(CacheLineAlignmentInBytes)
    287 , mSizeType(getIntNTy(GeneralRegisterWidthInBits)) {
    288 }
     322, mSizeType(getIntNTy(GeneralRegisterWidthInBits))
     323, mFILEtype(nullptr) {
     324}
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5267 r5280  
    3131        mMod = m;
    3232    }
    33        
     33   
    3434    llvm::Value * CreateMalloc(llvm::Type * type, llvm::Value * size);
    35 
     35   
    3636    llvm::Value * CreateAlignedMalloc(llvm::Type * type, llvm::Value * size, const unsigned alignment);
    37 
     37   
    3838    void CreateFree(llvm::Value * const ptr);
    39 
     39   
    4040    void CreateAlignedFree(llvm::Value * const ptr, const bool ptrMayBeNull = false);
    41 
     41   
    4242    llvm::Value * CreateRealloc(llvm::Value * ptr, llvm::Value * size);
    43 
     43   
    4444    void CreateMemZero(llvm::Value * ptr, llvm::Value * size, const unsigned alignment = 1);
    4545
     
    5050    }
    5151   
     52    // stdio.h functions
     53    //
     54    //  Create a call to:  FILE *fopen(const char *filename, const char *mode);
     55    llvm::Value * CreateFOpenCall(llvm::Value * filename, llvm::Value * mode);
     56    //  Create a call to:  size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream));
     57    llvm::Value * CreateFWriteCall(llvm::Value * ptr, llvm::Value * size, llvm::Value * nitems, llvm::Value * stream);
     58    //  Create a call to:  int fclose ( FILE * stream );
     59    llvm::Value * CreateFCloseCall(llvm::Value * stream);
     60   
    5261    llvm::Function * GetPrintf();
    5362
     63    //  Create calls to unistd.h functions.
     64    //
     65    //  Create a call to:  ssize_t write(int fildes, const void *buf, size_t nbyte);
    5466    llvm::Value * CreateWriteCall(llvm::Value * fildes, llvm::Value * buf, llvm::Value * nbyte);
    5567   
     68    //  Posix thread (pthread.h) functions.
     69    //
     70    //  Create a call to:  int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
     71    //                    void *(*start_routine)(void*), void *arg);
    5672    llvm::Value * CreatePThreadCreateCall(llvm::Value * thread, llvm::Value * attr, llvm::Function * start_routine, llvm::Value * arg);
    57 
     73   
     74    //  Create a call to:  void pthread_exit(void *value_ptr);
    5875    llvm::Value * CreatePThreadExitCall(llvm::Value * value_ptr);
    59 
     76   
     77    //  Create a call to:  int pthread_join(pthread_t thread, void **value_ptr);
    6078    llvm::Value * CreatePThreadJoinCall(llvm::Value * thread, llvm::Value * value_ptr);
    6179   
     
    7189   
    7290    llvm::PointerType * getVoidPtrTy() const;
     91    llvm::PointerType * getFILEptrTy();
    7392   
    7493    inline unsigned getCacheAlignment() const {
     
    84103    unsigned            mCacheLineAlignment;
    85104    llvm::IntegerType * mSizeType;
     105    llvm::StructType *  mFILEtype;
    86106};
    87107
Note: See TracChangeset for help on using the changeset viewer.