Ignore:
Timestamp:
Oct 20, 2017, 12:40:18 PM (19 months ago)
Author:
cameron
Message:

Refactoring of grep_engine based on mode

File:
1 edited

Legend:

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

    r5698 r5700  
    3737static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<regex> <input file ...>"), cl::OneOrMore);
    3838
    39 static cl::opt<int> Threads("t", cl::desc("Total number of threads."), cl::init(1));
    40 
    4139static cl::opt<bool> ByteMode("enable-byte-mode", cl::desc("Process regular expressions in byte mode"));
    4240
     
    4442static cl::opt<int> REsPerGroup("re-num", cl::desc("Number of regular expressions processed by each kernel."), cl::init(1));
    4543
    46 static std::vector<std::string> allFiles;
    4744static re::ModeFlagSet globalFlags = 0;
    4845
     
    177174    const auto REs = readExpressions();
    178175
    179     allFiles = getFullFileList(inputFiles);
     176    std::vector<std::string> allFiles = getFullFileList(inputFiles);
    180177    if (allFiles.empty()) {
    181178        allFiles = { "-" };
     
    187184    grep::GrepEngine * grepEngine;
    188185   
    189     if (grep::Mode == grep::NormalMode) {
    190         grepEngine = new grep::GrepEngine();
    191     }
    192     else {
    193         grepEngine = new grep::CountOnlyGrepEngine();
    194     }
    195 
     186    switch (grep::Mode) {
     187        case grep::NormalMode:
     188            grepEngine = new grep::GrepEngine(); break;
     189        case grep::CountOnly:
     190            grepEngine = new grep::CountOnlyGrepEngine(); break;
     191        case grep::FilesWithMatch:
     192        case grep::FilesWithoutMatch:
     193        case grep::QuietMode:
     194            grepEngine = new grep::MatchOnlyGrepEngine(); break;
     195    }
    196196               
    197197    grepEngine->grepCodeGen(REs);
    198198
    199199    grepEngine->initFileResult(allFiles);
    200 
    201     if (Threads <= 1) {
    202         for (unsigned i = 0; i != allFiles.size(); ++i) {
    203             grepEngine->doGrep(allFiles[i], i);
    204         }
    205     } else if (Threads > 1) {
    206         const unsigned numOfThreads = Threads; // <- convert the command line value into an integer to allow stack allocation
    207         pthread_t threads[numOfThreads];
    208 
    209         for(unsigned long i = 0; i < numOfThreads; ++i){
    210             const int rc = pthread_create(&threads[i], nullptr, grep::DoGrepThreadFunction, (void *)grepEngine);
    211             if (rc) {
    212                 llvm::report_fatal_error("Failed to create thread: code " + std::to_string(rc));
    213             }
    214         }
    215         for(unsigned i = 0; i < numOfThreads; ++i) {
    216             void * status = nullptr;
    217             const int rc = pthread_join(threads[i], &status);
    218             if (rc) {
    219                 llvm::report_fatal_error("Failed to join thread: code " + std::to_string(rc));
    220             }
    221         }
    222     }
    223 
     200   
     201    grepEngine->run();
    224202   
    225203    grepEngine->PrintResults();
Note: See TracChangeset for help on using the changeset viewer.