Ignore:
Timestamp:
Nov 18, 2016, 1:46:55 PM (3 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/codegenstate.cpp

    r5202 r5217  
    66
    77#include <pablo/codegenstate.h>
    8 #include <pablo/printer_pablos.h>
     8
     9#define CHECK_SAME_TYPE(A, B) \
     10    assert ("DIFFERING CONTEXTS" && (&((A)->getType()->getContext()) == &((B)->getType()->getContext()))); \
     11    assert ("DIFFERING TYPES" && ((A)->getType() == (B)->getType()))
     12
     13using StreamType = IDISA::StreamType;
    914
    1015namespace pablo {
     
    1924
    2025Count * PabloBlock::createCount(PabloAST * expr) {
    21     return insertAtInsertionPoint(new Count(expr, makeName("count")));
     26    Type * type = getParent()->getBuilder()->getSizeTy();
     27    return insertAtInsertionPoint(new Count(expr, makeName("count"), type));
    2228}
    2329
    2430Count * PabloBlock::createCount(PabloAST * const expr, const std::string & prefix)  {
    25     return insertAtInsertionPoint(new Count(expr, makeName(prefix)));
     31    Type * type = getParent()->getBuilder()->getSizeTy();
     32    return insertAtInsertionPoint(new Count(expr, makeName(prefix), type));
    2633}
    2734
     
    3643Var * PabloBlock::createVar(PabloAST * name, Type * type) {
    3744    if (type == nullptr) {
    38         type = getStreamTy();
     45        type = getParent()->getStreamSetTy();
    3946    }
    4047    if (LLVM_UNLIKELY(name == nullptr || !isa<String>(name))) {
     
    7986Extract * PabloBlock::createExtract(PabloAST * array, PabloAST * index, String * name) {
    8087    assert (array && index);
    81     if (LLVM_LIKELY(isa<ArrayType>(array->getType()))) {
    82         if (name == nullptr) {
    83             std::string tmp;
    84             raw_string_ostream out(tmp);
    85             PabloPrinter::print(array, out);
    86             PabloPrinter::print(index, out);
    87             name = makeName(out.str());
    88         }
    89         return insertAtInsertionPoint(new Extract(array, index, name));
     88    if (name == nullptr) {
     89        std::string tmp;
     90        raw_string_ostream out(tmp);
     91        array->print(out);
     92        out << '[';
     93        index->print(out);
     94        out << ']';
     95        name = makeName(out.str());
     96    }
     97    llvm::Type * const type = array->getType();
     98    if (LLVM_LIKELY(isa<StreamType>(type))) {
     99        Type * elementType = cast<StreamType>(type)->getStreamElementType();
     100        return insertAtInsertionPoint(new Extract(array, index, name, elementType));
     101    }
     102    if (LLVM_LIKELY(isa<ArrayType>(type))) {
     103        Type * elementType = cast<ArrayType>(type)->getArrayElementType();
     104        return insertAtInsertionPoint(new Extract(array, index, name, elementType));
    90105    }
    91106    std::string tmp;
     
    93108    out << "cannot extract element from ";
    94109    array->print(out);
    95     out << ": type is not a valid ArrayType";
     110    out << " : not a StreamType or ArrayType";
    96111    throw std::runtime_error(out.str());
    97112}
    98113
    99114And * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2, String * name) {
     115    CHECK_SAME_TYPE(expr1, expr2);
    100116    if (name == nullptr) {
    101117        name = makeName("and");
     
    112128
    113129Or * PabloBlock::createOr(PabloAST * expr1, PabloAST * expr2, String * name) {
     130    CHECK_SAME_TYPE(expr1, expr2);
    114131    if (name == nullptr) {
    115132        name = makeName("or");
     
    126143
    127144Xor * PabloBlock::createXor(PabloAST * expr1, PabloAST * expr2, String * name) {
     145    CHECK_SAME_TYPE(expr1, expr2);
    128146    if (name == nullptr) {
    129147        name = makeName("xor");
     
    139157}
    140158
     159Add * PabloBlock::createAdd(PabloAST * expr1, PabloAST * expr2, String * name) {
     160    CHECK_SAME_TYPE(expr1, expr2);
     161    if (name == nullptr) {
     162        name = makeName("add");
     163    }
     164    return insertAtInsertionPoint(new Add(expr1->getType(), expr1, expr2, name));
     165}
     166
     167Subtract * PabloBlock::createSubtract(PabloAST * expr1, PabloAST * expr2, String * name) {
     168    CHECK_SAME_TYPE(expr1, expr2);
     169    if (name == nullptr) {
     170        name = makeName("sub");
     171    }
     172    return insertAtInsertionPoint(new Subtract(expr1->getType(), expr1, expr2, name));
     173}
     174
    141175Assign * PabloBlock::createAssign(PabloAST * const var, PabloAST * const value) {
     176    CHECK_SAME_TYPE(var, value);
    142177    return insertAtInsertionPoint(new Assign(var, value));
    143178}
    144179
    145180MatchStar * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass, String * name) {
     181    CHECK_SAME_TYPE(marker, charclass);
    146182    if (name == nullptr) {
    147183        name = makeName("matchstar");
     
    151187
    152188ScanThru * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru, String * name) {
     189    CHECK_SAME_TYPE(from, thru);
    153190    if (name == nullptr) {
    154191        name = makeName("scanthru");
     
    174211
    175212Sel * PabloBlock::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, String * name) {
     213    CHECK_SAME_TYPE(trueExpr, falseExpr);
    176214    if (name == nullptr) {
    177215        name = makeName("sel");
     
    230268    return nextScopeIndex;
    231269}   
    232    
    233 /// CONSTRUCTOR
    234 
    235 PabloBlock::PabloBlock(PabloFunction * const parent) noexcept
    236 : PabloAST(PabloAST::ClassTypeId::Block, nullptr, nullptr)
    237 , mParent(parent)
    238 , mBranch(nullptr)
    239 , mScopeIndex(0)
    240 {
    241 
    242 }
    243 
    244 PabloBlock::~PabloBlock() {
    245 
    246 }
    247 
    248 }
     270
     271}
Note: See TracChangeset for help on using the changeset viewer.