Ignore:
Timestamp:
Nov 18, 2016, 1:46:55 PM (2 years ago)
Author:
nmedfort
Message:

Merged PabloFunction? and PabloKernel? classes. Updated projects where necessary.

File:
1 edited

Legend:

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

    r5202 r5217  
    9999}
    100100
     101inline void printType(const Type * type, raw_string_ostream & out) {
     102    if (auto st = dyn_cast<IDISA::StreamType>(type)) {
     103        out << "<" << st->getNumElements() << " x s" << st->getFieldWidth() << ">";
     104    } else {
     105        type->print(out);
     106    }
     107}
     108
    101109using TypeId = PabloAST::ClassTypeId;
    102110
     
    193201
    194202PabloAST * PabloBuilder::createAssign(PabloAST * const variable, PabloAST * const value) {
    195     MAKE_BINARY(createAssign, TypeId::Assign, variable, value);
    196     return result;
     203    if (variable->getType() != value->getType()) {
     204        std::string tmp;
     205        raw_string_ostream out(tmp);
     206        out << "Cannot assign ";
     207        value->print(out);
     208        out << " to ";
     209        variable->print(out);
     210        out << ": type of ";
     211        value->print(out);
     212        out << " ";
     213        printType(value->getType(), out);
     214        out << " does not match ";
     215        variable->print(out);
     216        out << " ";
     217        printType(variable->getType(), out);
     218        throw std::runtime_error(out.str());
     219    }
     220    return mPb->createAssign(variable, value);
    197221}
    198222
     
    399423}
    400424
     425PabloAST * PabloBuilder::createAdd(PabloAST * expr1, PabloAST * expr2) {
     426    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
     427        return getInteger(cast<Integer>(expr1)->value() + cast<Integer>(expr2)->value());
     428    }
     429    MAKE_BINARY(createAdd, TypeId::Add, expr1, expr2);
     430    return result;
     431}
     432
     433PabloAST * PabloBuilder::createAdd(PabloAST * expr1, PabloAST * expr2, const std::string & prefix) {
     434    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
     435        return getInteger(cast<Integer>(expr1)->value() + cast<Integer>(expr2)->value());
     436    }
     437    MAKE_NAMED_BINARY(createAdd, TypeId::Add, prefix, expr1, expr2);
     438    return result;
     439}
     440
     441PabloAST * PabloBuilder::createSubtract(PabloAST * expr1, PabloAST * expr2) {
     442    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
     443        return getInteger(cast<Integer>(expr1)->value() - cast<Integer>(expr2)->value());
     444    }
     445    MAKE_BINARY(createSubtract, TypeId::Subtract, expr1, expr2);
     446    return result;
     447}
     448
     449PabloAST * PabloBuilder::createSubtract(PabloAST * expr1, PabloAST * expr2, const std::string & prefix) {
     450    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
     451        return getInteger(cast<Integer>(expr1)->value() - cast<Integer>(expr2)->value());
     452    }
     453    MAKE_NAMED_BINARY(createSubtract, TypeId::Subtract, prefix, expr1, expr2);
     454    return result;
     455}
     456
    401457PabloAST * PabloBuilder::createInFile(PabloAST * expr) {
    402458    MAKE_UNARY(createInFile, TypeId::InFile, expr);
Note: See TracChangeset for help on using the changeset viewer.