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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.