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

FileSink? kernel

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.