Ignore:
Timestamp:
Mar 10, 2016, 2:38:50 PM (3 years ago)
Author:
lindanl
Message:

Multiple input files can run on separate threads.

File:
1 edited

Legend:

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

    r4961 r4967  
    5252
    5353
    54 bool GrepEngine::finalLineIsUnterminated() const {
     54bool GrepEngine::finalLineIsUnterminated(char * mFileBuffer, int mFileSize) const {
    5555    if (mFileSize == 0) return false;
    5656    unsigned char end_byte = static_cast<unsigned char>(mFileBuffer[mFileSize-1]);
     
    6868}
    6969
    70 bool GrepEngine::openMMap(const std::string & fileName) {
    71 
    72     mFileName = fileName;
     70void GrepEngine::doGrep(const std::string & fileName) {
     71    std::string mFileName = fileName;
     72    int mFileSize;
     73    char * mFileBuffer;
    7374
    7475#ifdef USE_BOOST_MMAP
     
    9394        } catch (std::ios_base::failure e) {
    9495            std::cerr << "Error: Boost mmap of " << mFileName << ": " << e.what() << std::endl;
    95             return false;
     96            return;
    9697        }
    9798        mFileBuffer = mFile.data();
     
    102103    if (fdSrc == -1) {
    103104        std::cerr << "Error: cannot open " << mFileName << " for processing. Skipped.\n";
    104         return false;
     105        return;
    105106    }
    106107    if (fstat(fdSrc, &infile_sb) == -1) {
    107108        std::cerr << "Error: cannot stat " << mFileName << " for processing. Skipped.\n";
    108109        close (fdSrc);
    109         return false;
     110        return;
    110111    }
    111112    if (S_ISDIR(infile_sb.st_mode)) {
    112113        close (fdSrc);
    113         return false;
     114        return;
    114115    }
    115116    mFileSize = infile_sb.st_size;
     
    128129                close (fdSrc);
    129130            }
    130             return false;
     131            return;
    131132        }
    132133    }
     
    134135
    135136#endif
    136     return true;  // success
    137 }
     137   
     138    uint64_t finalLineUnterminated = 0;
     139    if(finalLineIsUnterminated(mFileBuffer, mFileSize))
     140        finalLineUnterminated = 1;
     141   
     142    mMainFcn(mFileBuffer, mFileSize, mFileName.c_str(), finalLineUnterminated);
    138143
    139 void GrepEngine::closeMMap() {
    140144#ifdef USE_BOOST_MMAP
    141145    mFile.close();
    142146#else
    143147    munmap((void *)mFileBuffer, mFileSize);
    144 #endif  
     148#endif
    145149
    146150}
    147151
    148 void GrepEngine::doGrep() {
    149        
    150     llvm::raw_os_ostream out(std::cout);
    151    
    152     uint64_t finalLineUnterminated = 0;
    153     if(finalLineIsUnterminated())
    154         finalLineUnterminated = 1;
    155    
    156     mMainFcn(mFileBuffer, mFileSize, mFileName.c_str(), finalLineUnterminated);
    157    
    158     if (!mIsNameExpression) PrintTotalCount();
    159 }
    160152
    161153void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool isNameExpression) {
    162154                           
    163     Module * M = new Module(moduleName, getGlobalContext());
     155    Module * M = new Module("moduleName", getGlobalContext());
    164156   
    165157    IDISA::IDISA_Builder * idb = GetIDISA_Builder(M);
     
    190182re::CC *  GrepEngine::grepCodepoints() {
    191183    setParsedCodePointSet();
    192     mFileBuffer = getUnicodeNameDataPtr();
    193     mFileSize = getUnicodeNameDataSize();
    194     mFileName = "Uname.txt";
    195     doGrep();
     184    char * mFileBuffer = getUnicodeNameDataPtr();
     185    int mFileSize = getUnicodeNameDataSize();
     186    std::string mFileName = "Uname.txt";
     187
     188    uint64_t finalLineUnterminated = 0;
     189    if(finalLineIsUnterminated(mFileBuffer, mFileSize))
     190        finalLineUnterminated = 1;   
     191    mMainFcn(mFileBuffer, mFileSize, mFileName.c_str(), finalLineUnterminated);
     192
    196193    return getParsedCodePointSet();
    197194}
Note: See TracChangeset for help on using the changeset viewer.