Ignore:
Timestamp:
Sep 23, 2016, 4:12:41 PM (3 years ago)
Author:
nmedfort
Message:

Initial work for incorporating Types into Pablo AST.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r5063 r5160  
    1010
    1111namespace pablo {
    12 
    13 Zeroes PabloBlock::mZeroes;
    14 
    15 Ones PabloBlock::mOnes;
    1612
    1713inline PabloAST * PabloBlock::renameNonNamedNode(PabloAST * expr, const std::string && prefix) {
     
    5046
    5147PabloAST * PabloBlock::createAdvance(PabloAST * expr, PabloAST * shiftAmount) {
     48    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    5249    if (isa<Zeroes>(expr) || cast<Integer>(shiftAmount)->value() == 0) {
    5350        return expr;
     
    5754
    5855PabloAST * PabloBlock::createAdvance(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix) {
     56    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    5957    if (isa<Zeroes>(expr) || cast<Integer>(shiftAmount)->value() == 0) {
    6058        return expr;
     
    6462
    6563PabloAST * PabloBlock::createAdvance(PabloAST * expr, const Integer::Type shiftAmount) {
     64    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    6665    if (isa<Zeroes>(expr) || shiftAmount == 0) {
    6766        return expr;
     
    7170
    7271PabloAST * PabloBlock::createAdvance(PabloAST * expr, const Integer::Type shiftAmount, const std::string prefix) {
     72    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    7373    if (isa<Zeroes>(expr) || shiftAmount == 0) {
    7474        return renameNonNamedNode(expr, std::move(prefix));
     
    7878
    7979Count * PabloBlock::createCount(const std::string counterName, PabloAST * const expr)  {
     80    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    8081    return insertAtInsertionPoint(new Count(expr, makeName(counterName, false)));
    8182}
     
    9091
    9192PabloAST * PabloBlock::createLookahead(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix) {
     93    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    9294    if (isa<Zeroes>(expr) || cast<Integer>(shiftAmount)->value() == 0) {
    9395        return expr;
     
    9799
    98100PabloAST * PabloBlock::createLookahead(PabloAST * expr, const Integer::Type shiftAmount) {
     101    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    99102    if (isa<Zeroes>(expr) || shiftAmount == 0) {
    100103        return expr;
     
    104107
    105108PabloAST * PabloBlock::createLookahead(PabloAST * expr, const Integer::Type shiftAmount, const std::string prefix) {
     109    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    106110    if (isa<Zeroes>(expr) || shiftAmount == 0) {
    107111        return renameNonNamedNode(expr, std::move(prefix));
     
    118122PabloAST * PabloBlock::createNot(PabloAST * expr) {
    119123    assert (expr);
     124    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    120125    if (isa<Ones>(expr)) {
    121         return createZeroes();
     126        return createZeroes(expr->getType());
    122127    }
    123128    else if (isa<Zeroes>(expr)){
    124         return createOnes();
     129        return createOnes(expr->getType());
    125130    }
    126131    else if (Not * not1 = dyn_cast<Not>(expr)) {
     
    132137PabloAST * PabloBlock::createNot(PabloAST * expr, const std::string prefix) {
    133138    assert (expr);
     139    PabloAST::throwIfNonMatchingType(expr, PabloType::Stream);
    134140    if (isa<Ones>(expr)) {
    135         return createZeroes();
     141        return createZeroes(expr->getType());
    136142    }
    137143    else if (isa<Zeroes>(expr)){
    138         return createOnes();
     144        return createOnes(expr->getType());
    139145    }
    140146    else if (Not * not1 = dyn_cast<Not>(expr)) {       
     
    144150}
    145151
    146 Var * PabloBlock::createVar(PabloAST * name) {
     152Var * PabloBlock::createVar(PabloAST * name, const PabloType * const type) {
    147153    assert (name);
    148     return new Var(name);
     154    return new Var(name, type);
    149155}
    150156
     
    179185
    180186PabloAST * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass) {
    181     assert (marker && charclass);
     187    throwIfNonMatchingTypes(marker, charclass);
    182188    if (isa<Zeroes>(marker) || isa<Zeroes>(charclass)) {
    183189        return marker;
     
    186192}
    187193
    188 PabloAST * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix) {
    189     assert (marker && charclass);
     194PabloAST * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix) {   
     195    throwIfNonMatchingTypes(marker, charclass);
     196    throwIfNonMatchingType(marker, PabloType::Stream);
    190197    if (isa<Zeroes>(marker) || isa<Zeroes>(charclass)) {
    191198        return renameNonNamedNode(marker, std::move(prefix));
     
    194201}
    195202
    196 PabloAST * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru) {
    197     assert (from && thru);
     203PabloAST * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru) {   
     204    throwIfNonMatchingTypes(from, thru);
     205    throwIfNonMatchingType(from, PabloType::Stream);
    198206    if (isa<Zeroes>(from) || isa<Zeroes>(thru)) {
    199207        return from;
     
    203211
    204212PabloAST * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru, const std::string prefix) {
    205     assert (from && thru);
     213    throwIfNonMatchingTypes(from, thru);
     214    throwIfNonMatchingType(from, PabloType::Stream);
    206215    if (isa<Zeroes>(from) || isa<Zeroes>(thru)) {       
    207216        return renameNonNamedNode(from, std::move(prefix));
     
    219228
    220229PabloAST * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2) {
    221     assert (expr1 && expr2);
     230    throwIfNonMatchingTypes(expr1, expr2);
    222231    if (isa<Zeroes>(expr2) || isa<Ones>(expr1)) {
    223232        return expr2;
     
    228237            return createNot(createOr(not1->getOperand(0), not2->getOperand(0)));
    229238        } else if (equals(not1->getOperand(0), expr2)) {
    230             return createZeroes();
     239            return createZeroes(expr1->getType());
    231240        }
    232241    } else if (Not * not2 = dyn_cast<Not>(expr2)) {
    233242        if (equals(expr1, not2->getOperand(0))) {
    234             return createZeroes();
     243            return createZeroes(expr1->getType());
    235244        }
    236245    } else if (Or * or1 = isBinary<Or>(expr1)) {
     
    243252        }
    244253    }
    245     return insertAtInsertionPoint(new And(expr1, expr2, makeName("and_")));
     254    return insertAtInsertionPoint(new And(expr1->getType(), expr1, expr2, makeName("and_")));
    246255}
    247256
    248257PabloAST * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2, const std::string prefix) {
    249     assert (expr1 && expr2);
     258    throwIfNonMatchingTypes(expr1, expr2);
    250259    if (isa<Zeroes>(expr2) || isa<Ones>(expr1)) {
    251260        return renameNonNamedNode(expr2, std::move(prefix));
     
    258267        }
    259268        else if (equals(not1->getOperand(0), expr2)) {
    260             return createZeroes();
     269            return createZeroes(expr1->getType());
    261270        }
    262271    } else if (Not * not2 = dyn_cast<Not>(expr2)) {
    263272        if (equals(expr1, not2->getOperand(0))) {
    264             return createZeroes();
     273            return createZeroes(expr1->getType());
    265274        }
    266275    } else if (Or * or1 = isBinary<Or>(expr1)) {
     
    273282        }
    274283    }
    275     return insertAtInsertionPoint(new And(expr1, expr2, makeName(prefix, false)));
    276 }
    277 
    278 And * PabloBlock::createAnd(const unsigned reserved) {
    279     return insertAtInsertionPoint(new And(reserved, makeName("and_")));
    280 }
    281 
    282 And * PabloBlock::createAnd(const unsigned reserved, const std::string prefix) {
    283     return insertAtInsertionPoint(new And(reserved, makeName(prefix, false)));
     284    return insertAtInsertionPoint(new And(expr1->getType(), expr1, expr2, makeName(prefix, false)));
     285}
     286
     287And * PabloBlock::createAnd(const PabloType * const type, const unsigned reserved) {
     288    return insertAtInsertionPoint(new And(type, reserved, makeName("and_")));
     289}
     290
     291And * PabloBlock::createAnd(const PabloType * const type, const unsigned reserved, const std::string prefix) {
     292    return insertAtInsertionPoint(new And(type, reserved, makeName(prefix, false)));
     293}
     294
     295And * PabloBlock::createAnd(const PabloType * const type, std::vector<PabloAST *>::iterator begin, std::vector<PabloAST *>::iterator end) {
     296    return insertAtInsertionPoint(new And(type, begin, end, makeName("and_")));
     297}
     298
     299And * PabloBlock::createAnd(const PabloType * const type, Variadic::iterator begin, Variadic::iterator end) {
     300    return insertAtInsertionPoint(new And(type, begin, end, makeName("and_")));
    284301}
    285302
    286303PabloAST * PabloBlock::createOr(PabloAST * expr1, PabloAST * expr2) {
    287     assert (expr1 && expr2);
     304    throwIfNonMatchingTypes(expr1, expr2);
    288305    if (isa<Zeroes>(expr1) || isa<Ones>(expr2)){
    289306        return expr2;
     
    325342        }
    326343    }
    327     return insertAtInsertionPoint(new Or(expr1, expr2, makeName("or_")));
     344    return insertAtInsertionPoint(new Or(expr1->getType(), expr1, expr2, makeName("or_")));
    328345}
    329346
    330347PabloAST * PabloBlock::createOr(PabloAST * expr1, PabloAST * expr2, const std::string prefix) {
    331     assert (expr1 && expr2);
     348    throwIfNonMatchingTypes(expr1, expr2);
    332349    if (isa<Zeroes>(expr1) || isa<Ones>(expr2)){
    333350        return renameNonNamedNode(expr2, std::move(prefix));
     
    367384        }
    368385    }
    369     return insertAtInsertionPoint(new Or(expr1, expr2, makeName(prefix, false)));
    370 }
    371 
    372 Or * PabloBlock::createOr(const unsigned reserved) {
    373     return insertAtInsertionPoint(new Or(reserved, makeName("or_")));
    374 }
    375 
    376 Or * PabloBlock::createOr(const unsigned reserved, const std::string prefix) {
    377     return insertAtInsertionPoint(new Or(reserved, makeName(prefix, false)));
     386    return insertAtInsertionPoint(new Or(expr1->getType(), expr1, expr2, makeName(prefix, false)));
     387}
     388
     389Or * PabloBlock::createOr(const PabloType * const type, const unsigned reserved) {
     390    return insertAtInsertionPoint(new Or(type, reserved, makeName("or_")));
     391}
     392
     393Or * PabloBlock::createOr(const PabloType * const type, const unsigned reserved, const std::string prefix) {
     394    return insertAtInsertionPoint(new Or(type, reserved, makeName(prefix, false)));
     395}
     396
     397Or * PabloBlock::createOr(const PabloType * const type, std::vector<PabloAST *>::iterator begin, std::vector<PabloAST *>::iterator end) {
     398    return insertAtInsertionPoint(new Or(type, begin, end, makeName("or_")));
     399}
     400
     401Or * PabloBlock::createOr(const PabloType * const type, Variadic::iterator begin, Variadic::iterator end) {
     402    return insertAtInsertionPoint(new Or(type, begin, end, makeName("or_")));
    378403}
    379404
    380405PabloAST * PabloBlock::createXor(PabloAST * expr1, PabloAST * expr2) {
    381     assert (expr1 && expr2);
     406    throwIfNonMatchingTypes(expr1, expr2);
    382407    if (expr1 == expr2) {
    383         return PabloBlock::createZeroes();
    384     }
    385     if (isa<Ones>(expr1)) {
     408        return PabloBlock::createZeroes(expr1->getType());
     409    } else if (isa<Ones>(expr1)) {
    386410        return createNot(expr2);
    387411    } else if (isa<Zeroes>(expr1)){
     
    396420        }
    397421    }
    398     return insertAtInsertionPoint(new Xor(expr1, expr2, makeName("xor_")));
     422    return insertAtInsertionPoint(new Xor(expr1->getType(), expr1, expr2, makeName("xor_")));
    399423}
    400424
    401425PabloAST * PabloBlock::createXor(PabloAST * expr1, PabloAST * expr2, const std::string prefix) {
    402     assert (expr1 && expr2);
     426    throwIfNonMatchingTypes(expr1, expr2);
    403427    if (expr1 == expr2) {
    404         return PabloBlock::createZeroes();
    405     }
    406     if (isa<Ones>(expr1)) {
     428        return PabloBlock::createZeroes(expr1->getType());
     429    } else if (isa<Ones>(expr1)) {
    407430        return createNot(expr2, prefix);
    408431    } else if (isa<Zeroes>(expr1)){
     
    417440        }
    418441    }
    419     return insertAtInsertionPoint(new Xor(expr1, expr2, makeName(prefix, false)));
    420 }
    421 
    422 Xor * PabloBlock::createXor(const unsigned reserved) {
    423     return insertAtInsertionPoint(new Xor(reserved, makeName("xor_")));
    424 }
    425 
    426 Xor * PabloBlock::createXor(const unsigned reserved, const std::string prefix) {
    427     return insertAtInsertionPoint(new Xor(reserved, makeName(prefix, false)));
     442    return insertAtInsertionPoint(new Xor(expr1->getType(), expr1, expr2, makeName(prefix, false)));
     443}
     444
     445Xor * PabloBlock::createXor(const PabloType * const type, const unsigned reserved) {
     446    return insertAtInsertionPoint(new Xor(type, reserved, makeName("xor_")));
     447}
     448
     449Xor * PabloBlock::createXor(const PabloType * const type, const unsigned reserved, const std::string prefix) {
     450    return insertAtInsertionPoint(new Xor(type, reserved, makeName(prefix, false)));
     451}
     452
     453Xor * PabloBlock::createXor(const PabloType * const type, std::vector<PabloAST *>::iterator begin, std::vector<PabloAST *>::iterator end) {
     454    return insertAtInsertionPoint(new Xor(type, begin, end, makeName("xor_")));
     455}
     456
     457Xor * PabloBlock::createXor(const PabloType * const type, Variadic::iterator begin, Variadic::iterator end) {
     458    return insertAtInsertionPoint(new Xor(type, begin, end, makeName("xor_")));
    428459}
    429460
     
    431462
    432463PabloAST * PabloBlock::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
    433     assert (condition && trueExpr && falseExpr);
     464    throwIfNonMatchingTypes(trueExpr, falseExpr);
    434465    if (isa<Ones>(condition)) {
    435466        return trueExpr;
     
    455486
    456487PabloAST * PabloBlock::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const std::string prefix) {
    457     assert (condition && trueExpr && falseExpr);
     488    throwIfNonMatchingTypes(trueExpr, falseExpr);
    458489    if (isa<Zeroes>(condition)){
    459490        return renameNonNamedNode(falseExpr, std::move(prefix));
    460     }
    461     else if (isa<Ones>(condition) || equals(trueExpr, falseExpr)) {
     491    } else if (isa<Ones>(condition) || equals(trueExpr, falseExpr)) {
    462492        return renameNonNamedNode(trueExpr, std::move(prefix));
    463     }
    464     else if (isa<Ones>(trueExpr)) {
     493    } else if (isa<Ones>(trueExpr)) {
    465494        return createOr(condition, falseExpr, prefix);
    466     }
    467     else if (isa<Zeroes>(trueExpr)){
     495    } else if (isa<Zeroes>(trueExpr)){
    468496        return createAnd(createNot(condition), falseExpr, prefix);
    469     }
    470     else if (isa<Ones>(falseExpr)) {
     497    } else if (isa<Ones>(falseExpr)) {
    471498        return createOr(createNot(condition), trueExpr, prefix);
    472     }
    473     else if (isa<Zeroes>(falseExpr)){
     499    } else if (isa<Zeroes>(falseExpr)){
    474500        return createAnd(condition, trueExpr, prefix);
    475     }
    476     else if (isa<Not>(trueExpr) && equals(cast<Not>(trueExpr)->getOperand(0), falseExpr)) {
     501    } else if (isa<Not>(trueExpr) && equals(cast<Not>(trueExpr)->getOperand(0), falseExpr)) {
    477502        return createXor(condition, falseExpr, prefix);
    478     }
    479     else if (isa<Not>(falseExpr) && equals(trueExpr, cast<Not>(falseExpr)->getOperand(0))){
     503    } else if (isa<Not>(falseExpr) && equals(trueExpr, cast<Not>(falseExpr)->getOperand(0))){
    480504        return createXor(condition, trueExpr, prefix);
    481505    }
     
    545569/// CONSTRUCTOR
    546570
    547 PabloBlock::PabloBlock(SymbolGenerator * symbolGenerator) noexcept
    548 : PabloAST(PabloAST::ClassTypeId::Block)
    549 , mSymbolGenerator(symbolGenerator)
    550 , mParent(nullptr)
     571PabloBlock::PabloBlock(PabloFunction * parent, PabloBlock *predecessor) noexcept
     572: PabloAST(PabloAST::ClassTypeId::Block, nullptr)
     573, mParent(parent)
     574, mPredecessor(predecessor)
    551575, mBranch(nullptr)
    552576, mScopeIndex(0)
Note: See TracChangeset for help on using the changeset viewer.