Ignore:
Timestamp:
Nov 6, 2016, 8:37:11 PM (3 years ago)
Author:
nmedfort
Message:

Initial work on adding types to PabloAST and mutable Var objects.

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

Legend:

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

    r5160 r5202  
    3030, mBasisBit(encodingBits)
    3131, mEncodingBits(encodingBits) {
    32     const PabloType * streamType = getPabloType(PabloType::Stream, 1);
     32
     33    // TODO: basisBits should be defined prior and only retrieved here.
     34    Var * const basisBits = function.addParameter(prefix, getStreamTy(1, 8));
    3335    for (unsigned i = 0; i != mEncodingBits; i++) {
    34         Var * var = mBuilder.createVar(prefix + std::to_string(i), streamType);
    35         function.setParameter(i, var);
    36         mBasisBit[i] = var;
     36        mBasisBit[i] = mBuilder.createExtract(basisBits, mBuilder.getInteger(i)); assert (mBasisBit[i]);
    3737    }
    3838    mEncodingMask = (static_cast<unsigned>(1) << encodingBits) - static_cast<unsigned>(1);
    3939}
    4040
    41 Assign * CC_Compiler::compileCC(const std::string && canonicalName, const CC *cc, PabloBlock & block) {
    42     return block.createAssign(std::move(canonicalName), charset_expr(cc, block));
    43 }
    44 
    45 Assign * CC_Compiler::compileCC(const std::string && canonicalName, const CC *cc, PabloBuilder & builder) {
    46     return builder.createAssign(std::move(canonicalName), charset_expr(cc, builder));
    47 }
    48 
    49 
     41PabloAST * CC_Compiler::compileCC(const std::string & canonicalName, const CC *cc, PabloBlock & block) {
     42    PabloAST * const var = charset_expr(cc, block);
     43    var->setName(block.makeName(canonicalName));
     44    return var;
     45}
     46
     47PabloAST * CC_Compiler::compileCC(const std::string & canonicalName, const CC *cc, PabloBuilder & builder) {
     48    PabloAST * const var = charset_expr(cc, builder);
     49    var->setName(builder.makeName(canonicalName));
     50    return var;
     51}
    5052   
    5153template<typename PabloBlockOrBuilder>
     
    200202
    201203template<typename PabloBlockOrBuilder>
    202 PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n, PabloBlockOrBuilder &pb)
    203 {
     204PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n, PabloBlockOrBuilder & pb) {
    204205    /*
    205206      If an N-bit pattern is all ones, then it is always true that any n-bit value is LE this pattern.
     
    208209    if ((n + 1) == (1UL << N)) {
    209210        return pb.createOnes(); //True.
    210     }
    211     else {
     211    } else {
    212212        return pb.createNot(GE_Range(N, n + 1, pb));
    213213    }
     
    218218    if (lo == hi) {
    219219        return char_test_expr(lo, pb);
    220     }
    221     else if (lo < hi) {
     220    } else if (lo < hi) {
    222221        return make_range(lo, hi, pb);
    223222    }
     
    225224}
    226225
    227 inline Var * CC_Compiler::getBasisVar(const unsigned i) const {
     226inline PabloAST *CC_Compiler::getBasisVar(const unsigned i) const {
    228227    assert (i < mEncodingBits);
    229     return mBasisBit[mEncodingBits - i - 1];
     228    const unsigned index = mEncodingBits - i - 1; assert (index < mEncodingBits);
     229    assert (mBasisBit[index]);
     230    return mBasisBit[index];
    230231}
    231232   
    232 pablo::PabloFunction * ParabixCharacterClassFunction(std::string ccSetName, std::vector<re::CC *> charClasses, unsigned basisBitsCount) {
    233        
    234     pablo::PabloFunction * cc_function = pablo::PabloFunction::Create(ccSetName + "_fn", basisBitsCount, charClasses.size());
    235     CC_Compiler ccc(* cc_function, basisBitsCount);
    236    
    237     pablo::PabloBuilder pBuilder(ccc.getBuilder().getPabloBlock(), ccc.getBuilder());
    238     const std::vector<pablo::Var *> bits = ccc.getBasisBits();
    239    
    240     for (unsigned i = 0; i < charClasses.size(); i++) {
    241         cc_function->setResult(i, ccc.compileCC(charClasses[i]));
    242     }
    243     return cc_function;
     233PabloFunction * ParabixCharacterClassFunction(const std::string & name, const std::vector<CC *> & charClasses, const unsigned basisBitsCount) {
     234    PabloFunction * f = PabloFunction::Create(name + "_fn");
     235    CC_Compiler ccc(*f, basisBitsCount);
     236    PabloBuilder builder(f->getEntryBlock());
     237    for (CC * cc : charClasses) {
     238        Var * const r = f->addResult(cc->canonicalName(re::ByteClass), getStreamTy());
     239        builder.createAssign(r, ccc.charset_expr(cc, builder));
     240    }
     241    return f;
    244242}
    245243
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r5140 r5202  
    1515namespace pablo {
    1616    class PabloFunction;
     17    class Var;
    1718}
    1819
     
    2223
    2324class CC_Compiler{
     25
     26    friend pablo::PabloFunction * ParabixCharacterClassFunction(const std::string &, const std::vector<re::CC *> &, const unsigned);
     27
    2428public:
    2529
     
    2832    CC_Compiler(pablo::PabloFunction & function, const unsigned encodingBits = 8, const std::string prefix = "basis");
    2933
    30     pablo::Assign * compileCC(const re::CC *cc);
     34    pablo::PabloAST * compileCC(const re::CC *cc);
    3135
    32     pablo::Assign * compileCC(const re::CC *cc, pablo::PabloBlock & block);
     36    pablo::PabloAST *compileCC(const re::CC *cc, pablo::PabloBlock & block);
    3337
    34     pablo::Assign * compileCC(const re::CC *cc, pablo::PabloBuilder & builder);
     38    pablo::PabloAST * compileCC(const re::CC *cc, pablo::PabloBuilder & builder);
    3539
    36     pablo::Assign * compileCC(const std::string && canonicalName, const re::CC *cc, pablo::PabloBlock & block);
     40    pablo::PabloAST * compileCC(const std::string & canonicalName, const re::CC *cc, pablo::PabloBlock & block);
    3741
    38     pablo::Assign * compileCC(const std::string && canonicalName, const re::CC *cc, pablo::PabloBuilder & builder);
     42    pablo::PabloAST * compileCC(const std::string & canonicalName, const re::CC *cc, pablo::PabloBuilder & builder);
    3943
    4044    pablo::PabloBuilder & getBuilder();
    4145
    42     const std::vector<pablo::Var *> & getBasisBits() {
     46    const std::vector<pablo::PabloAST *> & getBasisBits() {
    4347        return mBasisBit;
    4448    }
    4549
    46     bool isUTF_16() {
    47         return mEncodingBits == 16;
     50    bool isUTF_16() const {
     51        return mEncodingBits == 16;
    4852    }
    4953
    5054private:
    51     pablo::Var * getBasisVar(const unsigned n) const;
     55    pablo::PabloAST * getBasisVar(const unsigned n) const;
    5256    template<typename PabloBlockOrBuilder>
    5357    pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits, PabloBlockOrBuilder & pb);
     
    6569    pablo::PabloAST * charset_expr(const re::CC *cc, PabloBlockOrBuilder & pb);
    6670private:   
    67     pablo::PabloBuilder         mBuilder;
    68     std::vector<pablo::Var *>   mBasisBit;
    69     const unsigned              mEncodingBits;
    70     unsigned                    mEncodingMask;
     71    pablo::PabloBuilder             mBuilder;
     72    std::vector<pablo::PabloAST *>  mBasisBit;
     73    const unsigned                  mEncodingBits;
     74    unsigned                        mEncodingMask;
    7175};
    7276
    73 inline pablo::Assign * CC_Compiler::compileCC(const re::CC *cc) {
     77inline pablo::PabloAST *CC_Compiler::compileCC(const re::CC *cc) {
    7478    return compileCC(cc, mBuilder);
    7579}
    7680
    77 inline pablo::Assign * CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBlock & block) {
    78     return compileCC(std::move(cc->canonicalName(re::ByteClass)), cc, block);
     81inline pablo::PabloAST * CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBlock & block) {
     82    return compileCC(cc->canonicalName(re::ByteClass), cc, block);
    7983}
    8084
    81 inline pablo::Assign * CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBuilder & builder) {
    82     return compileCC(std::move(cc->canonicalName(re::ByteClass)), cc, builder);
     85inline pablo::PabloAST *CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBuilder & builder) {
     86    return compileCC(cc->canonicalName(re::ByteClass), cc, builder);
    8387}
    8488
     
    8791}
    8892
    89 pablo::PabloFunction * ParabixCharacterClassFunction(std::string ccSetName, std::vector<re::CC *> charClasses, unsigned basisBitsCount);
    90 
     93pablo::PabloFunction * ParabixCharacterClassFunction(const std::string & name, const std::vector<re::CC *> & charClasses, const unsigned basisBitsCount);
    9194
    9295}
Note: See TracChangeset for help on using the changeset viewer.