Ignore:
Timestamp:
Aug 29, 2016, 3:37:03 PM (3 years ago)
Author:
cameron
Message:

Some clean ups of encoding info for ccc restructuring.

Location:
icGREP/icgrep-devel/icgrep/cc
Files:
2 edited

Legend:

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

    r5037 r5137  
    66
    77#include "cc_compiler.h"
    8 #include "utf_encoding.h"
    98
    109//Pablo Expressions
     
    2726namespace cc {
    2827
    29 CC_Compiler::CC_Compiler(PabloFunction & function, const Encoding & encoding, const std::string prefix)
     28CC_Compiler::CC_Compiler(PabloFunction & function, const unsigned encodingBits, const std::string prefix)
    3029: mBuilder(function.getEntryBlock())
    31 , mBasisBit(encoding.getBits())
    32 , mEncoding(encoding) {
    33     for (unsigned i = 0; i != encoding.getBits(); i++) {
     30, mBasisBit(encodingBits)
     31, mEncodingBits(encodingBits) {
     32    for (unsigned i = 0; i != mEncodingBits; i++) {
    3433        Var * var = mBuilder.createVar(prefix + std::to_string(i));
    3534        function.setParameter(i, var);
    3635        mBasisBit[i] = var;
    3736    }
     37    mEncodingMask = (static_cast<unsigned>(1) << encodingBits) - static_cast<unsigned>(1);
    3838}
    3939
     
    5353        return pb.createZeroes();
    5454    }
    55 #ifdef CC_COMPILER_ENFORCES_INFILE
    56     bool includes_codepoint_zero = lo_codepoint(cc->begin()) == 0;
    57 #endif
    5855    if (cc->size() > 2) {
    5956        bool combine = true;
     
    7572                codepoint_t lo = lo_codepoint(cc->front());
    7673                codepoint_t hi = lo_codepoint(cc->back());
    77                 const codepoint_t mask = mEncoding.getMask();
    78                 lo &= (mask - 1);
    79                 hi |= (mask ^ (mask - 1));
     74                lo &= (mEncodingMask - 1);
     75                hi |= (mEncodingMask ^ (mEncodingMask - 1));
    8076                PabloAST * expr = make_range(lo, hi, pb);
    8177                PabloAST * bit0 = getBasisVar(0);
     
    9288        expr = (expr == nullptr) ? temp : pb.createOr(expr, temp);
    9389    }
    94 #ifdef CC_COMPILER_ENFORCES_INFILE
    95     if (includes_codepoint_zero) {
    96         return pb.createInFile(expr);
    97     }
    98     else {
    99         return expr;
    100     }
    101 #else
    10290    return expr;
    103 #endif
    10491   
    10592}
     
    146133template<typename PabloBlockOrBuilder>
    147134inline PabloAST * CC_Compiler::char_test_expr(const codepoint_t ch, PabloBlockOrBuilder &pb) {
    148     return bit_pattern_expr(ch, mEncoding.getMask(), pb);
     135    return bit_pattern_expr(ch, mEncodingMask, pb);
    149136}
    150137
     
    155142    for (codepoint_t diff_bits = n1 ^ n2; diff_bits; diff_count++, diff_bits >>= 1);
    156143
    157     if ((n2 < n1) || (diff_count > mEncoding.getBits()))
     144    if ((n2 < n1) || (diff_count > mEncodingBits))
    158145    {
    159146        throw std::runtime_error("Bad Range: [" + std::to_string(n1) + "," + std::to_string(n2) + "]");
     
    162149    const codepoint_t mask0 = (static_cast<codepoint_t>(1) << diff_count) - 1;
    163150
    164     PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncoding.getMask() ^ mask0, pb);
     151    PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncodingMask ^ mask0, pb);
    165152
    166153    if (diff_count == 0) return common;
     
    238225
    239226inline Var * CC_Compiler::getBasisVar(const unsigned i) const {
    240     assert (i < mEncoding.getBits());
    241     return mBasisBit[mEncoding.getBits() - i - 1];
     227    assert (i < mEncodingBits);
     228    return mBasisBit[mEncodingBits - i - 1];
    242229}
    243230
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r5046 r5137  
    1010#include <re/re_cc.h>
    1111#include <pablo/builder.hpp>
    12 #include "utf_encoding.h"
    1312#include <string>
    1413
     
    2726    using Vars = std::vector<pablo::Var *>;
    2827
    29     CC_Compiler(pablo::PabloFunction & function, const Encoding & encoding, const std::string prefix = "basis");
     28    CC_Compiler(pablo::PabloFunction & function, const unsigned encodingBits = 8, const std::string prefix = "basis");
    3029
    3130    pablo::Assign * compileCC(const re::CC *cc);
     
    4645
    4746    bool isUTF_16() {
    48         return mEncoding.getBits() == 16;
     47        return mEncodingBits == 16;
    4948    }
    5049
     
    6867    pablo::PabloBuilder         mBuilder;
    6968    std::vector<pablo::Var *>   mBasisBit;
    70     const Encoding &            mEncoding;
     69    const unsigned              mEncodingBits;
     70    unsigned                    mEncodingMask;
    7171};
    7272
Note: See TracChangeset for help on using the changeset viewer.