Ignore:
Timestamp:
Mar 22, 2018, 7:26:40 AM (13 months ago)
Author:
cameron
Message:

mmap - command line flag + overridden for stdin, devices, files of size 0 (incl virtual files such as /proc/cpuinfo)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep/grep_engine.cpp

    r5914 r5927  
    423423    const unsigned encodingBits = 8;
    424424
    425     Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), nullptr));
     425    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt8Ty(), idb->getInt32Ty(), nullptr));
    426426    mainFunc->setCallingConv(CallingConv::C);
    427427    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    428428    auto args = mainFunc->arg_begin();
    429429
     430    Value * const useMMap = &*(args++);
     431    useMMap->setName("useMMap");
    430432    Value * const fileDescriptor = &*(args++);
    431433    fileDescriptor->setName("fileDescriptor");
     
    433435    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits));
    434436    kernel::Kernel * sourceK = mGrepDriver->addKernelInstance<kernel::FDSourceKernel>(idb);
    435     sourceK->setInitialArguments({fileDescriptor});
     437    sourceK->setInitialArguments({useMMap, fileDescriptor});
    436438    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
    437439
     
    516518    const unsigned encodingBits = 8;
    517519
    518     Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), idb->getIntAddrTy(), nullptr));
     520    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt8Ty(), idb->getInt32Ty(), idb->getIntAddrTy(), nullptr));
    519521    mainFunc->setCallingConv(CallingConv::C);
    520522    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    521523    auto args = mainFunc->arg_begin();
    522524
     525    Value * const useMMap = &*(args++);
     526    useMMap->setName("useMMap");
    523527    Value * const fileDescriptor = &*(args++);
    524528    fileDescriptor->setName("fileDescriptor");
     
    528532    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits));
    529533    kernel::Kernel * sourceK = mGrepDriver->addKernelInstance<kernel::FDSourceKernel>(idb);
    530     sourceK->setInitialArguments({fileDescriptor});
     534    sourceK->setInitialArguments({useMMap, fileDescriptor});
    531535    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
    532536
     
    553557
    554558uint64_t GrepEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
    555     typedef uint64_t (*GrepFunctionType)(int32_t fileDescriptor);
     559    typedef uint64_t (*GrepFunctionType)(bool useMMap, int32_t fileDescriptor);
     560    using namespace boost::filesystem;
     561    path p(fileName);
     562    bool useMMap = grep::MmapFlag;
     563    if (p == "-") useMMap = false;
     564    if (!is_regular_file(p)) useMMap = false;
     565
    556566    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
    557567
     
    559569    if (fileDescriptor == -1) return 0;
    560570
    561     uint64_t grepResult = f(fileDescriptor);
     571    uint64_t grepResult = f(useMMap, fileDescriptor);
    562572    close(fileDescriptor);
    563573    return grepResult;
     
    589599
    590600uint64_t EmitMatchesEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
    591     typedef uint64_t (*GrepFunctionType)(int32_t fileDescriptor, intptr_t accum_addr);
     601    typedef uint64_t (*GrepFunctionType)(bool useMMap, int32_t fileDescriptor, intptr_t accum_addr);
     602    using namespace boost::filesystem;
     603    path p(fileName);
     604    bool useMMap = grep::MmapFlag;
     605    if (p == "-") useMMap = false;
     606    if (!is_regular_file(p)) useMMap = false;
    592607    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
    593 
    594608    int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx]);
    595609    if (fileDescriptor == -1) return 0;
    596610    EmitMatch accum(linePrefix(fileName), mResultStrs[fileIdx]);
    597     f(fileDescriptor, reinterpret_cast<intptr_t>(&accum));
     611    f(useMMap, fileDescriptor, reinterpret_cast<intptr_t>(&accum));
    598612    close(fileDescriptor);
    599613    if (accum.mLineCount > 0) grepMatchFound = true;
Note: See TracChangeset for help on using the changeset viewer.