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

Multiplexing bug fix and some CC changes.

Location:
icGREP/icgrep-devel/icgrep/cc
Files:
2 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);
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4602 r4612  
    99
    1010#include <re/re_cc.h>
     11#include <pablo/builder.hpp>
    1112#include "utf_encoding.h"
    1213#include <string>
    13 
    14 namespace pablo {
    15     class PabloAST;
    16     class PabloBuilder;
    17     class PabloBlock;
    18     class Var;
    19     class Assign;
    20 }
    2114
    2215namespace cc {
     
    2720public:
    2821
    29     CC_Compiler(pablo::PabloBlock & cg, const Encoding encoding, const std::string basis_pattern = "basis");
     22    using Vars = std::vector<pablo::Var *>;
    3023
    31     std::vector<pablo::Var *> getBasisBits(const CC_NameMap & nameMap);
     24    CC_Compiler(pablo::PabloBlock & entry, const Encoding encoding, const std::string basis_pattern = "basis");
     25
     26    const Vars & getBasisBits(const CC_NameMap & nameMap) const;
     27
     28    pablo::Assign * compileCC(const re::CC *cc);
    3229
    3330    pablo::Assign * compileCC(const re::CC *cc, pablo::PabloBlock & block);
    3431
    35     pablo::Assign * compileCC(const re::CC *cc, pablo::PabloBuilder & pb);
     32    pablo::Assign * compileCC(const re::CC *cc, pablo::PabloBuilder & builder);
    3633
    37     pablo::Assign * compileCC(const re::CC *cc);
     34    pablo::Assign * compileCC(const std::string && canonicalName, const re::CC *cc, pablo::PabloBlock & block);
     35
     36    pablo::Assign * compileCC(const std::string &&canonicalName, const re::CC *cc, pablo::PabloBuilder & builder);
    3837
    3938    void compileByteClasses(re::RE * re);
     
    4140private:
    4241    pablo::Var * getBasisVar(const int n) const;
    43     pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits, pablo::PabloBuilder & pb);
    44     pablo::PabloAST * char_test_expr(const re::CodePointType ch, pablo::PabloBuilder & pb);
    45     pablo::PabloAST * make_range(const re::CodePointType n1, const re::CodePointType n2, pablo::PabloBuilder & pb);
    46     pablo::PabloAST * GE_Range(const unsigned N, const unsigned n, pablo::PabloBuilder & pb);
    47     pablo::PabloAST * LE_Range(const unsigned N, const unsigned n, pablo::PabloBuilder & pb);
    48     pablo::PabloAST * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi, pablo::PabloBuilder & pb);
    49     pablo::PabloAST * charset_expr(const re::CC *cc, pablo::PabloBuilder & pb);
     42    template<typename PabloBlockOrBuilder>
     43    pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits, PabloBlockOrBuilder & pb);
     44    template<typename PabloBlockOrBuilder>
     45    pablo::PabloAST * char_test_expr(const re::codepoint_t ch, PabloBlockOrBuilder & pb);
     46    template<typename PabloBlockOrBuilder>
     47    pablo::PabloAST * make_range(const re::codepoint_t n1, const re::codepoint_t n2, PabloBlockOrBuilder & pb);
     48    template<typename PabloBlockOrBuilder>
     49    pablo::PabloAST * GE_Range(const unsigned N, const unsigned n, PabloBlockOrBuilder & pb);
     50    template<typename PabloBlockOrBuilder>
     51    pablo::PabloAST * LE_Range(const unsigned N, const unsigned n, PabloBlockOrBuilder & pb);
     52    template<typename PabloBlockOrBuilder>
     53    pablo::PabloAST * char_or_range_expr(const re::codepoint_t lo, const re::codepoint_t hi, PabloBlockOrBuilder & pb);
     54    template<typename PabloBlockOrBuilder>
     55    pablo::PabloAST * charset_expr(const re::CC *cc, PabloBlockOrBuilder & pb);
    5056private:   
    51     pablo::PabloBlock &         mCG;
     57    pablo::PabloBuilder         mBuilder;
    5258    std::vector<pablo::Var *>   mBasisBit;
    5359    const Encoding              mEncoding;
    5460};
     61
     62inline pablo::Assign * CC_Compiler::compileCC(const re::CC *cc) {
     63    return compileCC(cc, mBuilder);
     64}
     65
     66inline pablo::Assign * CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBlock & block) {
     67    return compileCC(std::move(cc->canonicalName(re::ByteClass)), cc, block);
     68}
     69
     70inline pablo::Assign * CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBuilder & builder) {
     71    return compileCC(std::move(cc->canonicalName(re::ByteClass)), cc, builder);
     72}
     73
     74inline const CC_Compiler::Vars & CC_Compiler::getBasisBits(const CC_NameMap &) const {
     75    return mBasisBit;
     76}
     77
    5578
    5679}
Note: See TracChangeset for help on using the changeset viewer.