Changeset 5992 for icGREP


Ignore:
Timestamp:
Apr 26, 2018, 9:29:20 AM (13 months ago)
Author:
cameron
Message:

Setting BinaryFilesMode? to Text (temporary); conversion to unique_ptr progress

Location:
icGREP/icgrep-devel/icgrep
Files:
7 edited

Legend:

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

    r5990 r5992  
    141141GrepEngine::GrepEngine() :
    142142    mSuppressFileMessages(false),
     143    mBinaryFilesMode(argv::Text),
    143144    mPreferMMap(true),
    144145    mShowFileNames(false),
     
    150151    mMaxCount(0),
    151152    mGrepStdIn(false),
    152     mGrepDriver(nullptr),
     153    mGrepDriver(make_unique<ParabixDriver>("engine")),
    153154    mNextFileToGrep(0),
    154155    mNextFileToPrint(0),
     
    159160
    160161GrepEngine::~GrepEngine() {
    161     delete mGrepDriver;
     162    //delete mGrepDriver;
    162163}
    163164
     
    242243}
    243244   
    244 std::pair<StreamSetBuffer *, StreamSetBuffer *> GrepEngine::grepPipeline(StreamSetBuffer * ByteStream, Value * callback_object_addr) {
     245std::pair<StreamSetBuffer *, StreamSetBuffer *> GrepEngine::grepPipeline(StreamSetBuffer * SourceStream, Value * callback_object_addr) {
    245246    auto & idb = mGrepDriver->getBuilder();
    246247    const unsigned segmentSize = codegen::SegmentSize;
     
    260261        anyGCB |= hasGCB[i];
    261262    }
    262     StreamSetBuffer * SourceStream = ByteStream;
    263     ByteStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 8), baseBufferSize);
    264     kernel::Kernel * binaryCheckK = mGrepDriver->addKernelInstance<kernel::AbortOnNull>(idb);
    265     binaryCheckK->setInitialArguments({callback_object_addr});
    266     mGrepDriver->makeKernelCall(binaryCheckK, {SourceStream}, {ByteStream});
    267     mGrepDriver->LinkFunction(*binaryCheckK, "signal_dispatcher", &signal_dispatcher);
    268 
     263    StreamSetBuffer * ByteStream = nullptr;
     264    if (mBinaryFilesMode == argv::Text) {
     265        ByteStream = SourceStream;
     266    } else if (mBinaryFilesMode == argv::WithoutMatch) {
     267        ByteStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 8), baseBufferSize);
     268        kernel::Kernel * binaryCheckK = mGrepDriver->addKernelInstance<kernel::AbortOnNull>(idb);
     269        binaryCheckK->setInitialArguments({callback_object_addr});
     270        mGrepDriver->makeKernelCall(binaryCheckK, {SourceStream}, {ByteStream});
     271        mGrepDriver->LinkFunction(*binaryCheckK, "signal_dispatcher", &signal_dispatcher);
     272    } else {
     273        llvm::report_fatal_error("Binary mode not supported.");
     274    }
    269275    StreamSetBuffer * LineBreakStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), baseBufferSize);
    270276    std::vector<StreamSetBuffer *> MatchResultsBufs(nREs);
     
    460466
    461467void GrepEngine::grepCodeGen() {
    462 
    463     assert (mGrepDriver == nullptr);
    464     mGrepDriver = new ParabixDriver("engine");
    465468    auto & idb = mGrepDriver->getBuilder();
    466469    Module * M = idb->getModule();
     
    540543
    541544void EmitMatchesEngine::grepCodeGen() {
    542     assert (mGrepDriver == nullptr);
    543     mGrepDriver = new ParabixDriver("engine");
    544545    auto & idb = mGrepDriver->getBuilder();
    545546    Module * M = idb->getModule();
     
    775776    mGrepRecordBreak(GrepRecordBreakKind::LF),
    776777    mCaseInsensitive(false),
    777     mGrepDriver(nullptr) {}
     778    mGrepDriver(make_unique<ParabixDriver>("InternalEngine")) {}
    778779   
    779780InternalSearchEngine::~InternalSearchEngine() {
    780     delete mGrepDriver;
    781781}
    782782
    783783void InternalSearchEngine::grepCodeGen(re::RE * matchingRE, re::RE * excludedRE, MatchAccumulator * accum) {
    784     mGrepDriver = new ParabixDriver("InternalEngine");
    785784    auto & idb = mGrepDriver->getBuilder();
    786785    Module * M = idb->getModule();
  • icGREP/icgrep-devel/icgrep/grep/grep_engine.h

    r5989 r5992  
    7171
    7272    void suppressFileMessages() {mSuppressFileMessages = true;}
    73 
     73    void setBinaryFilesOption(argv::BinaryFilesMode mode) {mBinaryFilesMode = mode;}
    7474    void setRecordBreak(GrepRecordBreakKind b);
    7575    void initFileResult(std::vector<boost::filesystem::path> & filenames);
     
    9292
    9393    bool mSuppressFileMessages;
     94    argv::BinaryFilesMode mBinaryFilesMode;
    9495    bool mPreferMMap;
    9596    bool mShowFileNames;
     
    101102    int mMaxCount;
    102103    bool mGrepStdIn;
    103    
    104     Driver * mGrepDriver;
     104    std::unique_ptr<Driver> mGrepDriver;
    105105
    106106    std::atomic<unsigned> mNextFileToGrep;
     
    193193    bool mSaveSegmentPipelineParallel;
    194194
    195     Driver * mGrepDriver;
     195    std::unique_ptr<Driver> mGrepDriver;
    196196};
    197197   
  • icGREP/icgrep-devel/icgrep/grep_interface.cpp

    r5964 r5992  
    9999                                                                clEnumValN(WithoutMatch, "without-match", "Always report as non-matching."),
    100100                                                                clEnumValN(Text, "text", "Treat binary files as text.")
    101                                                                 CL_ENUM_VAL_SENTINEL), cl::cat(Input_Options), cl::location(BinaryFilesFlag), cl::init(Binary));
     101                                                                CL_ENUM_VAL_SENTINEL), cl::cat(Input_Options), cl::location(BinaryFilesFlag), cl::init(Text));
    102102   
    103103
     
    230230    }
    231231    if (BinaryNonMatchingFlag) {
    232         if (BinaryFilesFlag == Text) {
     232        if (BinaryFilesFlag == Binary) {
    233233            llvm::report_fatal_error("Conflicting options for binary files.\n");
    234234        }
  • icGREP/icgrep-devel/icgrep/grep_interface.h

    r5945 r5992  
    4545
    4646// Use DirectoriesFlag==Recurse to test for recursive mode.
    47 extern bool TextFlag; // -a
    48 extern bool BinaryFlag; // -U
     47//extern bool TextFlag; // -a
     48//extern bool BinaryFlag; // -U
     49enum BinaryFilesMode {Binary, WithoutMatch, Text};
     50extern BinaryFilesMode BinaryFilesFlag;
     51   
    4952extern bool NullDataFlag; // -z
    5053extern bool UnicodeLinesFlag; // -Unicode-lines
     
    6568extern ColoringType ColorFlag;
    6669
    67 enum BinaryFilesMode {Binary, WithoutMatch, Text};
    68 extern BinaryFilesMode BinaryFilesFlag;
    69    
    7070extern bool NoMessagesFlag; // -s  (also set by QuietMode/-q)
    7171extern bool WithFilenameFlag; // -H
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r5990 r5992  
    3030#include <sys/stat.h>
    3131#include <fcntl.h>
     32#include <llvm/ADT/STLExtras.h> // for make_unique
    3233
    3334using namespace llvm;
     
    111112
    112113int main(int argc, char *argv[]) {
    113     sys::PrintStackTraceOnErrorSignal(argv[0]);
    114     llvm::PrettyStackTraceProgram X(argc, argv);
    115     llvm_shutdown_obj shutdown;
    116114
    117115    argv::InitializeCommandLineInterface(argc, argv);
     
    127125    }
    128126
    129     grep::GrepEngine * grepEngine = nullptr;
     127    std::unique_ptr<grep::GrepEngine> grepEngine;
    130128   
    131129    switch (argv::Mode) {
    132130        case argv::NormalMode:
    133             grepEngine = new grep::EmitMatchesEngine();
     131            grepEngine = make_unique<grep::EmitMatchesEngine>();
    134132            if (argv::MaxCountFlag) grepEngine->setMaxCount(argv::MaxCountFlag);
    135133            if (argv::WithFilenameFlag) grepEngine->showFileNames();
     
    138136           break;
    139137        case argv::CountOnly:
    140             grepEngine = new grep::CountOnlyEngine();
     138            grepEngine = make_unique<grep::CountOnlyEngine>();
    141139            if (argv::WithFilenameFlag) grepEngine->showFileNames();
    142140            if (argv::MaxCountFlag) grepEngine->setMaxCount(argv::MaxCountFlag);
     
    144142        case argv::FilesWithMatch:
    145143        case argv::FilesWithoutMatch:
    146             grepEngine = new grep::MatchOnlyEngine(argv::Mode == argv::FilesWithMatch, argv::NullFlag);
     144            grepEngine = make_unique<grep::MatchOnlyEngine>(argv::Mode == argv::FilesWithMatch, argv::NullFlag);
    147145            break;
    148146        case argv::QuietMode:
    149             grepEngine = new grep::QuietModeEngine(); break;
     147            grepEngine = make_unique<grep::QuietModeEngine>();
     148            break;
    150149        default: llvm_unreachable("Invalid grep mode!");
    151150    }
     
    163162    if (argv::NoMessagesFlag) grepEngine->suppressFileMessages();
    164163    if (argv::MmapFlag) grepEngine->setPreferMMap();
     164    grepEngine->setBinaryFilesOption(argv::BinaryFilesFlag);
    165165    grepEngine->initREs(REs);
    166166    grepEngine->grepCodeGen();
    167167    grepEngine->initFileResult(allFiles);
    168168    bool matchFound = grepEngine->searchAllFiles();
    169     delete(grepEngine);
    170169   
    171170    return matchFound ? argv::MatchFoundExitCode : argv::MatchNotFoundExitCode;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5977 r5992  
    856856PabloCompiler::PabloCompiler(PabloKernel * const kernel)
    857857: mKernel(kernel)
    858 , mCarryManager(new CarryManager)
     858, mCarryManager(make_unique<CarryManager>())
    859859, mBranchCount(0) {
    860860    assert ("PabloKernel cannot be null!" && kernel);
     
    862862
    863863PabloCompiler::~PabloCompiler() {
    864     delete mCarryManager;
    865 }
    866 
    867 }
     864}
     865
     866}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5828 r5992  
    7070
    7171    PabloKernel * const             mKernel;
    72     CarryManager * const            mCarryManager;
     72    std::unique_ptr<CarryManager> const mCarryManager;
    7373    TranslationMap                  mMarker;
    7474    TranslationMap                  mAccumulator;
Note: See TracChangeset for help on using the changeset viewer.