Changeset 5725


Ignore:
Timestamp:
Nov 5, 2017, 11:52:18 AM (18 months ago)
Author:
cameron
Message:

Utility functions for regular expression transformations

Location:
icGREP/icgrep-devel/icgrep
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r5722 r5725  
    8888add_library(CodeGen ${TOOLCHAIN_SRC} ${DRIVER_SRC} ${OBJECT_CACHE_SRC} ${KERNEL_SRC} ${IDISA_SRC})
    8989add_library(PabloADT ${PABLO_SRC})
    90 add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_rep.cpp re/re_diff.cpp re/re_intersect.cpp re/printer_re.cpp)
     90add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_rep.cpp re/re_diff.cpp re/re_intersect.cpp re/re_assertion.cpp re/printer_re.cpp)
    9191add_library(RegExpCompiler re/re_parser.cpp re/re_memoizer.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_star_normal.cpp re/re_minimizer.cpp re/re_local.cpp re/re_compiler.cpp re/re_analysis.cpp re/re_toolchain.cpp re/re_name_resolve.cpp re/re_name_gather.cpp re/re_collect_unicodesets.cpp re/re_multiplex.cpp re/re_parser_pcre.cpp re/re_parser_ere.cpp re/re_parser_bre.cpp re/re_parser_prosite.cpp re/re_utility.cpp ${GREP_CORE_SRC})
    9292add_library(CCADT cc/cc_compiler.cpp utf8_encoder.cpp utf16_encoder.cpp UCD/CaseFolding.cpp cc/alphabet.cpp cc/multiplex_CCs.cpp)
  • icGREP/icgrep-devel/icgrep/re/re_assertion.h

    r5493 r5725  
    11/*
    2  *  Copyright (c) 2015 International Characters.
     2 *  Copyright (c) 2017 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    99
    1010#include <re/re_re.h>
     11#include <re/re_nullable.h>
     12#include <re/re_seq.h>
    1113
    1214namespace re {
     
    3234
    3335protected:
    34     friend Assertion * makeAssertion(RE * asserted, Kind k, Sense s);
     36    friend RE * makeAssertion(RE * asserted, Kind k, Sense s);
    3537    Assertion(RE * r, Kind k, Sense s) : RE(ClassTypeId::Assertion), mAsserted(r), mKind(k), mSense(s) {}
    3638    virtual ~Assertion() {}
     
    5153}
    5254
    53 inline Assertion * makeAssertion(RE * asserted, Assertion::Kind k, Assertion::Sense s) {
     55inline RE * makeAssertion(RE * asserted, Assertion::Kind k, Assertion::Sense s) {
     56    if (RE_Nullable::isNullable(asserted)) return makeSeq();
    5457    return new Assertion(asserted, k, s);
    5558}
     
    7881    return makeAssertion(r, Assertion::Kind::Boundary, Assertion::Sense::Negative);
    7982}
    80    
     83
     84RE * expandBoundaryAssertion(RE * r);
    8185}
    8286
  • icGREP/icgrep-devel/icgrep/re/re_rep.cpp

    r5646 r5725  
    9393}
    9494
     95RE * unrollFirst(Rep * rep) {
     96    RE * e = rep->getRE();
     97    auto lb = rep->getLB();
     98    auto ub = rep->getUB();
     99    if (ub == 0) return makeAlt();  // Can't unroll - return unmatchable regexp.
     100    // Unroll one copy of the loop and simplify.
     101    RE * reduced = makeRep(e, lb == 0 ? lb : lb - 1, ub == Rep::UNBOUNDED_REP ? ub : ub - 1);
     102    RE * unrolled = makeSeq({e, reduced});
     103    if (lb == 0) return makeAlt({makeSeq(), unrolled});
     104    else return unrolled;
    95105}
     106RE * unrollLast(Rep * rep) {
     107    RE * e = rep->getRE();
     108    auto lb = rep->getLB();
     109    auto ub = rep->getUB();
     110    if (ub == 0) return makeAlt();  // Can't unroll - return unmatchable regexp.
     111    // Unroll one copy of the loop and simplify.
     112    RE * reduced = makeRep(e, lb == 0 ? lb : lb - 1, ub == Rep::UNBOUNDED_REP ? ub : ub - 1);
     113    RE * unrolled = makeSeq({reduced, e});
     114    if (lb == 0) return makeAlt({makeSeq(), unrolled});
     115    else return unrolled;
     116}
     117}
  • icGREP/icgrep-devel/icgrep/re/re_rep.h

    r4516 r5725  
    7575
    7676RE * makeRep(RE * re, const int lower_bound, const int upper_bound);
     77   
     78RE * unrollFirst(Rep * re);
     79
     80RE * unrollLast(Rep * re);
    7781
    7882}
  • icGREP/icgrep-devel/icgrep/re/re_seq.h

    r5267 r5725  
    5555    if (LLVM_UNLIKELY(std::distance(begin, end) == 0)) {
    5656        return makeSeq();
    57     } else if (std::distance(begin, end) == 1) {
    58         return *begin;
    5957    } else {
    6058        Seq * seq = makeSeq();
Note: See TracChangeset for help on using the changeset viewer.