Ignore:
Timestamp:
Apr 19, 2017, 1:41:55 PM (2 years ago)
Author:
cameron
Message:

Speed-up file output using new temporary files; unlinking old files

File:
1 edited

Legend:

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

    r5412 r5415  
    6868    return CreateCall(closeFn, {fildes});
    6969}
     70
     71
     72Value * CBuilder::CreateUnlinkCall(Value * path) {
     73    Function * unlinkFunc = mMod->getFunction("unlink");
     74    if (unlinkFunc == nullptr) {
     75        FunctionType * fty = FunctionType::get(getInt32Ty(), {getInt8PtrTy()}, false);
     76        unlinkFunc = Function::Create(fty, Function::ExternalLinkage, "unlink", mMod);
     77        unlinkFunc->setCallingConv(CallingConv::C);
     78    }
     79    return CreateCall(unlinkFunc, {path});
     80}
     81
     82Value * CBuilder::CreateMkstempCall(Value * ftemplate) {
     83    Function * mkstempFn = mMod->getFunction("mkstemp");
     84    if (mkstempFn == nullptr) {
     85        mkstempFn = cast<Function>(mMod->getOrInsertFunction("mkstemp", getInt32Ty(), getInt8PtrTy(), nullptr));
     86    }
     87    return CreateCall(mkstempFn, {ftemplate});
     88}
     89
     90
     91Value * CBuilder::CreateStrlenCall(Value * str) {
     92    Function * strlenFn = mMod->getFunction("strlen");
     93    if (strlenFn == nullptr) {
     94        strlenFn = cast<Function>(mMod->getOrInsertFunction("strlen", getSizeTy(), getInt8PtrTy(), nullptr));
     95    }
     96    return CreateCall(strlenFn, {str});
     97}
     98
    7099
    71100Function * CBuilder::GetPrintf() {
     
    472501    }
    473502    return CreateCall(fCloseFunc, {stream});
     503}
     504
     505Value * CBuilder::CreateRenameCall(Value * oldName, Value * newName) {
     506    Function * renameFunc = mMod->getFunction("rename");
     507    if (renameFunc == nullptr) {
     508        FunctionType * fty = FunctionType::get(getInt32Ty(), {getInt8PtrTy(), getInt8PtrTy()}, false);
     509        renameFunc = Function::Create(fty, Function::ExternalLinkage, "rename", mMod);
     510        renameFunc->setCallingConv(CallingConv::C);
     511    }
     512    return CreateCall(renameFunc, {oldName, newName});
     513}
     514
     515Value * CBuilder::CreateRemoveCall(Value * path) {
     516    Function * removeFunc = mMod->getFunction("remove");
     517    if (removeFunc == nullptr) {
     518        FunctionType * fty = FunctionType::get(getInt32Ty(), {getInt8PtrTy()}, false);
     519        removeFunc = Function::Create(fty, Function::ExternalLinkage, "remove", mMod);
     520        removeFunc->setCallingConv(CallingConv::C);
     521    }
     522    return CreateCall(removeFunc, {path});
    474523}
    475524
Note: See TracChangeset for help on using the changeset viewer.