Ignore:
Timestamp:
May 5, 2016, 11:08:09 AM (3 years ago)
Author:
cameron
Message:

Restructure regular expression command flags

File:
1 edited

Legend:

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

    r4984 r5030  
    2525
    2626using namespace pablo;
     27namespace re {
     28
     29static cl::OptionCategory RegexOptions("Regex Toolchain Options",
     30                                              "These options control the regular expression transformation and compilation.");
     31const cl::OptionCategory * re_toolchain_flags() {return &RegexOptions;};
     32
     33static cl::bits<RE_PrintFlags>
     34    PrintOptions(cl::values(clEnumVal(PrintAllREs, "print regular expression passes"),
     35                            clEnumVal(PrintParsedREs, "print out parsed regular expressions"),
     36                            clEnumVal(PrintStrippedREs, "print out REs with nullable prefixes/suffixes removed"),
     37                            clEnumVal(PrintSimplifiedREs, "print out final simplified REs"),
     38                            clEnumValEnd), cl::cat(RegexOptions));
     39
     40static cl::bits<RE_AlgorithmFlags>
     41    AlgorithmOptions(cl::values(clEnumVal(DisableLog2BoundedRepetition, "disable log2 optimizations for bounded repetition of bytes"),
     42                              clEnumVal(DisableIfHierarchy, "disable nested if hierarchy for generated Unicode classes (not recommended)"),
     43                              clEnumVal(DisableMatchStar, "disable MatchStar optimization"),
     44                              clEnumVal(DisableUnicodeMatchStar, "disable Unicode MatchStar optimization"),
     45                              clEnumVal(DisableUnicodeLineBreak, "disable Unicode line breaks - use LF only"),
     46                              clEnumVal(InvertMatches, "select non-matching lines"),
     47#ifndef DISABLE_PREGENERATED_UCD_FUNCTIONS
     48                              clEnumVal(UsePregeneratedUnicode, "use fixed pregenerated Unicode character class sets instead"),
     49#endif
     50                              clEnumValEnd),
     51                   cl::cat(RegexOptions));
     52   
     53bool AlgorithmOptionIsSet(RE_AlgorithmFlags flag) {
     54    return AlgorithmOptions.isSet(flag);
     55}
     56
     57int IfInsertionGap;
     58static cl::opt<int, true>
     59    IfInsertionGapOption("if-insertion-gap",  cl::location(IfInsertionGap), cl::init(3),
     60                         cl::desc("minimum number of nonempty elements between inserted if short-circuit tests"),
     61                         cl::cat(RegexOptions));
    2762
    2863
    29 static cl::OptionCategory cRegexOutputOptions("Regex Dump Options",
    30                                               "These options control printing of intermediate regular expression structures.");
    31 static cl::opt<bool> PrintAllREs("print-REs", cl::init(false), cl::desc("print regular expression passes"), cl::cat(cRegexOutputOptions));
    32 static cl::opt<bool> PrintParsedREs("print-parsed-REs", cl::init(false), cl::desc("print out parsed regular expressions"), cl::cat(cRegexOutputOptions));
    33 static cl::opt<bool> PrintStrippedREs("print-stripped-REs", cl::init(false), cl::desc("print out REs with nullable prefixes/suffixes removed"), cl::cat(cRegexOutputOptions));
    34 static cl::opt<bool> PrintNamedREs("print-named-REs", cl::init(false), cl::desc("print out named REs"), cl::cat(cRegexOutputOptions));
    35 static cl::opt<bool> PrintUTF8REs("print-utf8-REs", cl::init(false), cl::desc("print out UTF-8 REs"), cl::cat(cRegexOutputOptions));
    36 static cl::opt<bool> PrintSimplifiedREs("print-simplified-REs", cl::init(false), cl::desc("print out final simplified REs"), cl::cat(cRegexOutputOptions));
    3764
    38 re::RE * regular_expression_passes(const Encoding encoding, re::RE * re_ast)  {
    39     if (PrintAllREs || PrintParsedREs) {
     65RE * regular_expression_passes(const Encoding encoding, RE * re_ast)  {
     66    if (PrintOptions.isSet(PrintAllREs) || PrintOptions.isSet(PrintParsedREs)) {
    4067        std::cerr << "Parser:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    4168    }
     
    4370    //Optimization passes to simplify the AST.
    4471    re_ast = re::RE_Nullable::removeNullablePrefix(re_ast);
    45     if (PrintAllREs || PrintStrippedREs) {
     72    if (PrintOptions.isSet(PrintAllREs) || PrintOptions.isSet(PrintStrippedREs)) {
    4673        std::cerr << "RemoveNullablePrefix:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    4774    }
    4875    re_ast = re::RE_Nullable::removeNullableSuffix(re_ast);
    49     if (PrintAllREs || PrintStrippedREs) {
     76    if (PrintOptions.isSet(PrintAllREs) || PrintOptions.isSet(PrintStrippedREs)) {
    5077        std::cerr << "RemoveNullableSuffix:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    5178    }
    5279
    5380    re_ast = re::RE_Simplifier::simplify(re_ast);
    54     if (PrintAllREs || PrintSimplifiedREs) {
     81    if (PrintOptions.isSet(PrintAllREs) || PrintOptions.isSet(PrintSimplifiedREs)) {
    5582        //Print to the terminal the AST that was generated by the simplifier.
    5683        std::cerr << "Simplifier:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     
    5986}
    6087   
    61 PabloFunction * re2pablo_compiler(const Encoding encoding, re::RE * re_ast) {
     88PabloFunction * re2pablo_compiler(const Encoding encoding, RE * re_ast) {
    6289    PabloFunction * function = PabloFunction::Create("process_block", 8, 2);
    6390    cc::CC_Compiler cc_compiler(*function, encoding);
     
    6592    re_compiler.initializeRequiredStreams();
    6693    re_compiler.compileUnicodeNames(re_ast);
    67     re_compiler.finalizeMatchResult(re_compiler.compile(re_ast));
     94    re_compiler.finalizeMatchResult(re_compiler.compile(re_ast), AlgorithmOptions.isSet(InvertMatches));
    6895    return function;
    6996}
    70 
     97}
Note: See TracChangeset for help on using the changeset viewer.