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/pabloAST.cpp

    r5156 r5160  
    133133}
    134134
    135 
    136135/** ------------------------------------------------------------------------------------------------------------- *
    137136 * @brief checkEscapedValueList
     
    154153                            return;
    155154                        }
    156                         parent = parent->getParent();
     155                        parent = parent->getPredecessor ();
    157156                        if (parent == nullptr) {
    158157                            break;
     
    188187 * @brief setOperand
    189188 ** ------------------------------------------------------------------------------------------------------------- */
    190 void Statement::setOperand(const unsigned index, PabloAST * const value) {
     189void Statement::setOperand(const unsigned index, PabloAST * const value) {   
    191190    assert ("Operand cannot be null!" && value);
    192191    assert (index < getNumOperands());
     
    196195        return;
    197196    }   
     197    throwIfNonMatchingTypes(prior, value);
    198198    prior->removeUser(this);
    199199    mOperand[index] = value;
     
    227227    if (LLVM_UNLIKELY(isa<If>(this) || isa<While>(this))) {
    228228        PabloBlock * body = isa<If>(this) ? cast<If>(this)->getBody() : cast<While>(this)->getBody();
    229         body->setParent(mParent);
     229        body->setPredecessor (mParent);
    230230    }
    231231}
     
    255255    if (LLVM_UNLIKELY(isa<If>(this) || isa<While>(this))) {
    256256        PabloBlock * body = isa<If>(this) ? cast<If>(this)->getBody() : cast<While>(this)->getBody();
    257         body->setParent(mParent);
     257        body->setPredecessor (mParent);
    258258    }
    259259}
     
    282282        if (LLVM_UNLIKELY(isa<If>(this) || isa<While>(this))) {
    283283            PabloBlock * body = isa<If>(this) ? cast<If>(this)->getBody() : cast<While>(this)->getBody();
    284             body->setParent(nullptr);
     284            body->setPredecessor (nullptr);
    285285        }
    286286    }
     
    295295 ** ------------------------------------------------------------------------------------------------------------- */
    296296Statement * Statement::eraseFromParent(const bool recursively) {
     297
     298    if (LLVM_UNLIKELY(getParent() == nullptr)) {
     299        return nullptr;
     300    }
    297301
    298302    SmallVector<Statement *, 1> redundantBranches;
     
    334338    }
    335339
    336     replaceAllUsesWith(PabloBlock::createZeroes());
     340    replaceAllUsesWith(getParent()->createZeroes(getType()));
    337341
    338342    if (recursively) {
     
    394398 ** ------------------------------------------------------------------------------------------------------------- */
    395399void Variadic::addOperand(PabloAST * const expr) {
     400    throwIfNonMatchingTypes(this, expr);
    396401    if (LLVM_UNLIKELY(mOperands == mCapacity)) {
    397402        mCapacity = std::max<unsigned>(mCapacity * 2, 2);
     
    446451            const PabloBlock * used = cast<Statement>(user)->getParent();
    447452            while (used != parent) {
    448                 used = used->getParent();
     453                used = used->getPredecessor ();
    449454                if (used == nullptr) {
    450455                    assert (isa<Assign>(statement) || isa<Next>(statement));
     
    550555}
    551556
    552 
    553 }
     557/** ------------------------------------------------------------------------------------------------------------- *
     558 * @brief throwIfNonMatchingTypes
     559 ** ------------------------------------------------------------------------------------------------------------- */
     560void PabloAST::throwIfNonMatchingTypes(const PabloAST * const a, const PabloAST * const b) {
     561    if (LLVM_UNLIKELY(a->getType() != b->getType())) {
     562        std::string tmp;
     563        raw_string_ostream out(tmp);
     564        out << "Error: ";
     565        PabloPrinter::print(a, out);
     566        out << "'s type does not match ";
     567        PabloPrinter::print(b, out);
     568        throw std::runtime_error(out.str());
     569    }
     570}
     571
     572/** ------------------------------------------------------------------------------------------------------------- *
     573 * @brief throwIfNonMatchingTypes
     574 ** ------------------------------------------------------------------------------------------------------------- */
     575void PabloAST::throwIfNonMatchingType(const PabloAST * const a, const PabloType::TypeId typeId) {
     576    if (LLVM_UNLIKELY(a->getType() == nullptr || a->getType()->getTypeId() != typeId)) {
     577        std::string tmp;
     578        raw_string_ostream out(tmp);
     579        out << "Error: ";
     580        PabloPrinter::print(a, out);
     581        out << "'s type is invalid.";
     582        throw std::runtime_error(out.str());
     583    }
     584}
     585
     586}
Note: See TracChangeset for help on using the changeset viewer.