Ignore:
Timestamp:
Jun 21, 2015, 4:38:51 PM (4 years ago)
Author:
nmedfort
Message:

Multiplexing bug fix and some CC changes.

File:
1 edited

Legend:

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

    r4602 r4612  
    2727namespace cc {
    2828
    29 CC_Compiler::CC_Compiler(PabloBlock & cg, const Encoding encoding, const std::string basis_pattern)
    30 : mCG(cg)
     29CC_Compiler::CC_Compiler(PabloBlock & entry, const Encoding encoding, const std::string basis_pattern)
     30: mBuilder(entry)
    3131, mBasisBit(encoding.getBits())
    3232, mEncoding(encoding)
    3333{
    3434    for (int i = 0; i < mEncoding.getBits(); i++) {
    35         mBasisBit[i] = mCG.createVar(basis_pattern + std::to_string(i));
    36     }
    37 }
    38 
    39 Assign * CC_Compiler::compileCC(const CC *cc) {
    40     return compileCC(cc, mCG);
    41 }
    42 
    43 Assign * CC_Compiler::compileCC(const CC *cc, PabloBlock & block) {
    44     PabloBuilder pb(block);
    45     return compileCC(cc, pb);
    46 }
    47 
    48 Assign * CC_Compiler::compileCC(const CC *cc, PabloBuilder & pb) {
    49     return pb.createAssign(cc->canonicalName(ByteClass), charset_expr(cc, pb));
    50 }
    51 
    52 std::vector<Var *> CC_Compiler::getBasisBits(const CC_NameMap & nameMap) {
    53     return mBasisBit;
     35        mBasisBit[i] = mBuilder.createVar(basis_pattern + std::to_string(i));
     36    }
     37}
     38
     39Assign * CC_Compiler::compileCC(const std::string && canonicalName, const CC *cc, PabloBlock & block) {
     40    return block.createAssign(std::move(canonicalName), charset_expr(cc, block));
     41}
     42
     43Assign * CC_Compiler::compileCC(const std::string && canonicalName, const CC *cc, PabloBuilder & builder) {
     44    return builder.createAssign(std::move(canonicalName), charset_expr(cc, builder));
    5445}
    5546
     
    8677            }
    8778            else if (name->getCompiled() == nullptr) {
    88                 name->setCompiled(compileCC(cast<CC>(def), mCG));
     79                name->setCompiled(compileCC(cast<CC>(def)));
    8980            }
    9081        }
     
    9586}
    9687
    97 
    98 
    99 PabloAST * CC_Compiler::charset_expr(const CC * cc, PabloBuilder & pb) {
     88template<typename PabloBlockOrBuilder>
     89PabloAST * CC_Compiler::charset_expr(const CC * cc, PabloBlockOrBuilder & pb) {
    10090    if (cc->empty()) {
    10191        return pb.createZeroes();
     
    120110            }
    121111            if (combine) {
    122                 CodePointType lo = cc->front().lo_codepoint;
    123                 CodePointType hi = cc->back().lo_codepoint;
    124                 const CodePointType mask = mEncoding.getMask();
     112                codepoint_t lo = cc->front().lo_codepoint;
     113                codepoint_t hi = cc->back().lo_codepoint;
     114                const codepoint_t mask = mEncoding.getMask();
    125115                lo &= (mask - 1);
    126116                hi |= (mask ^ (mask - 1));
     
    142132}
    143133
    144 PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits, PabloBuilder &pb)
     134template<typename PabloBlockOrBuilder>
     135PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits, PabloBlockOrBuilder &pb)
    145136{
    146137    if (selected_bits == 0) {
     
    192183}
    193184
    194 inline PabloAST * CC_Compiler::char_test_expr(const CodePointType ch, PabloBuilder &pb) {
     185template<typename PabloBlockOrBuilder>
     186inline PabloAST * CC_Compiler::char_test_expr(const codepoint_t ch, PabloBlockOrBuilder &pb) {
    195187    return bit_pattern_expr(ch, mEncoding.getMask(), pb);
    196188}
    197189
    198 PabloAST * CC_Compiler::make_range(const CodePointType n1, const CodePointType n2, PabloBuilder & pb) {
    199     CodePointType diff_count = 0;
    200 
    201     for (CodePointType diff_bits = n1 ^ n2; diff_bits; diff_count++, diff_bits >>= 1);
     190template<typename PabloBlockOrBuilder>
     191PabloAST * CC_Compiler::make_range(const codepoint_t n1, const codepoint_t n2, PabloBlockOrBuilder & pb) {
     192    codepoint_t diff_count = 0;
     193
     194    for (codepoint_t diff_bits = n1 ^ n2; diff_bits; diff_count++, diff_bits >>= 1);
    202195
    203196    if ((n2 < n1) || (diff_count > mEncoding.getBits()))
     
    206199    }
    207200
    208     const CodePointType mask0 = (static_cast<CodePointType>(1) << diff_count) - 1;
     201    const codepoint_t mask0 = (static_cast<codepoint_t>(1) << diff_count) - 1;
    209202
    210203    PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncoding.getMask() ^ mask0, pb);
     
    212205    if (diff_count == 0) return common;
    213206
    214     const CodePointType mask1 = (static_cast<CodePointType>(1) << (diff_count - 1)) - 1;
     207    const codepoint_t mask1 = (static_cast<codepoint_t>(1) << (diff_count - 1)) - 1;
    215208
    216209    PabloAST* lo_test = GE_Range(diff_count - 1, n1 & mask1, pb);
     
    220213}
    221214
    222 PabloAST * CC_Compiler::GE_Range(const unsigned N, const unsigned n, PabloBuilder &pb) {
     215template<typename PabloBlockOrBuilder>
     216PabloAST * CC_Compiler::GE_Range(const unsigned N, const unsigned n, PabloBlockOrBuilder &pb) {
    223217    if (N == 0) {
    224218        return pb.createOnes(); //Return a true literal.
     
    256250}
    257251
    258 PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n, PabloBuilder &pb)
     252template<typename PabloBlockOrBuilder>
     253PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n, PabloBlockOrBuilder &pb)
    259254{
    260255    /*
     
    270265}
    271266
    272 inline PabloAST * CC_Compiler::char_or_range_expr(const CodePointType lo, const CodePointType hi, PabloBuilder &pb) {
     267template<typename PabloBlockOrBuilder>
     268inline PabloAST * CC_Compiler::char_or_range_expr(const codepoint_t lo, const codepoint_t hi, PabloBlockOrBuilder &pb) {
    273269    if (lo == hi) {
    274270        return char_test_expr(lo, pb);
Note: See TracChangeset for help on using the changeset viewer.