Ignore:
Timestamp:
Jun 12, 2015, 2:16:59 PM (4 years ago)
Author:
nmedfort
Message:

Fixed PabloBuilder? and intergrated it into CC Compiler.

Location:
icGREP/icgrep-devel/icgrep
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4598 r4602  
    6060endif()
    6161
    62 SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/carry_data.cpp)
     62SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/carry_data.cpp)
    6363IF (ENABLE_MULTIPLEXING)
    6464SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp)
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4511 r4602  
    99
    1010//Pablo Expressions
    11 #include <pablo/codegenstate.h>
    1211#include <re/re_alt.h>
    1312#include <re/re_cc.h>
     
    1918#include <re/re_assertion.h>
    2019#include <cc/cc_namemap.hpp>
     20#include <pablo/codegenstate.h>
     21#include <pablo/builder.hpp>
    2122#include <stdexcept>
    2223
     
    3637}
    3738
    38 pablo::Assign * CC_Compiler::compileCC(const re::CC *cc) {
    39      return compileCC(cc, mCG);
    40 }
    41 
    42 pablo::Assign * CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBlock & pb) {
    43      return pb.createAssign(cc->canonicalName(ByteClass), charset_expr(cc, pb));
     39Assign * CC_Compiler::compileCC(const CC *cc) {
     40    return compileCC(cc, mCG);
     41}
     42
     43Assign * CC_Compiler::compileCC(const CC *cc, PabloBlock & block) {
     44    PabloBuilder pb(block);
     45    return compileCC(cc, pb);
     46}
     47
     48Assign * CC_Compiler::compileCC(const CC *cc, PabloBuilder & pb) {
     49    return pb.createAssign(cc->canonicalName(ByteClass), charset_expr(cc, pb));
    4450}
    4551
     
    9197
    9298
    93 PabloAST * CC_Compiler::charset_expr(const CC * cc, pablo::PabloBlock & pb) {
     99PabloAST * CC_Compiler::charset_expr(const CC * cc, PabloBuilder & pb) {
    94100    if (cc->empty()) {
    95101        return pb.createZeroes();
     
    136142}
    137143
    138 PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits, pablo::PabloBlock & pb)
     144PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits, PabloBuilder &pb)
    139145{
    140146    if (selected_bits == 0) {
     
    186192}
    187193
    188 inline PabloAST * CC_Compiler::char_test_expr(const CodePointType ch, pablo::PabloBlock & pb)
    189 {
     194inline PabloAST * CC_Compiler::char_test_expr(const CodePointType ch, PabloBuilder &pb) {
    190195    return bit_pattern_expr(ch, mEncoding.getMask(), pb);
    191196}
    192197
    193 PabloAST * CC_Compiler::make_range(const CodePointType n1, const CodePointType n2, pablo::PabloBlock & pb)
    194 {
     198PabloAST * CC_Compiler::make_range(const CodePointType n1, const CodePointType n2, PabloBuilder & pb) {
    195199    CodePointType diff_count = 0;
    196200
     
    216220}
    217221
    218 PabloAST * CC_Compiler::GE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb) {
     222PabloAST * CC_Compiler::GE_Range(const unsigned N, const unsigned n, PabloBuilder &pb) {
    219223    if (N == 0) {
    220224        return pb.createOnes(); //Return a true literal.
     
    252256}
    253257
    254 PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb)
     258PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n, PabloBuilder &pb)
    255259{
    256260    /*
     
    266270}
    267271
    268 inline PabloAST * CC_Compiler::char_or_range_expr(const CodePointType lo, const CodePointType hi, pablo::PabloBlock & pb) {
     272inline PabloAST * CC_Compiler::char_or_range_expr(const CodePointType lo, const CodePointType hi, PabloBuilder &pb) {
    269273    if (lo == hi) {
    270274        return char_test_expr(lo, pb);
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4511 r4602  
    88#define CC_COMPILER_H
    99
     10#include <re/re_cc.h>
    1011#include "utf_encoding.h"
    11 #include <pablo/codegenstate.h>
    12 #include <pablo/pabloAST.h>
    13 #include <re/re_cc.h>
    1412#include <string>
     13
     14namespace pablo {
     15    class PabloAST;
     16    class PabloBuilder;
     17    class PabloBlock;
     18    class Var;
     19    class Assign;
     20}
    1521
    1622namespace cc {
     
    2531    std::vector<pablo::Var *> getBasisBits(const CC_NameMap & nameMap);
    2632
    27     pablo::Assign * compileCC(const re::CC *cc, pablo::PabloBlock & pb);
     33    pablo::Assign * compileCC(const re::CC *cc, pablo::PabloBlock & block);
     34
     35    pablo::Assign * compileCC(const re::CC *cc, pablo::PabloBuilder & pb);
    2836
    2937    pablo::Assign * compileCC(const re::CC *cc);
     
    3341private:
    3442    pablo::Var * getBasisVar(const int n) const;
    35     pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits, pablo::PabloBlock & pb);
    36     pablo::PabloAST * char_test_expr(const re::CodePointType ch, pablo::PabloBlock & pb);
    37     pablo::PabloAST * make_range(const re::CodePointType n1, const re::CodePointType n2, pablo::PabloBlock & pb);
    38     pablo::PabloAST * GE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb);
    39     pablo::PabloAST * LE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb);
    40     pablo::PabloAST * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi, pablo::PabloBlock & pb);
    41     pablo::PabloAST * charset_expr(const re::CC *cc, pablo::PabloBlock & pb);
    42 private:
     43    pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits, pablo::PabloBuilder & pb);
     44    pablo::PabloAST * char_test_expr(const re::CodePointType ch, pablo::PabloBuilder & pb);
     45    pablo::PabloAST * make_range(const re::CodePointType n1, const re::CodePointType n2, pablo::PabloBuilder & pb);
     46    pablo::PabloAST * GE_Range(const unsigned N, const unsigned n, pablo::PabloBuilder & pb);
     47    pablo::PabloAST * LE_Range(const unsigned N, const unsigned n, pablo::PabloBuilder & pb);
     48    pablo::PabloAST * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi, pablo::PabloBuilder & pb);
     49    pablo::PabloAST * charset_expr(const re::CC *cc, pablo::PabloBuilder & pb);
     50private:   
    4351    pablo::PabloBlock &         mCG;
    4452    std::vector<pablo::Var *>   mBasisBit;
  • icGREP/icgrep-devel/icgrep/cc/cc_namemap.hpp

    r4337 r4602  
    77#include "re/re_name.h"
    88#include "re/re_cc.h"
     9#include <pablo/expression_map.hpp>
    910
    1011namespace re {
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r4443 r4602  
    33namespace pablo {
    44
    5 #define CALL_UNARY_FUNCTOR(NAME, TYPE, ARGS...) \
     5#define MAKE_UNARY(NAME, TYPE, ARGS...) \
    66struct __##NAME { \
    7     inline PabloAST * operator()(PabloAST * expr) { \
    8         return mPB->NAME(expr); \
     7    inline PabloAST * operator()(PabloAST * arg) { \
     8        return mPb.NAME(arg); \
    99    } \
    10     inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
     10    inline __##NAME(PabloBlock & pb) : mPb(pb) {} \
    1111private: \
    12     PabloBlock * mPB; \
     12    PabloBlock & mPb; \
    1313}; \
    14 __##NAME functor(this); \
    15 mExprTable.findUnaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
     14__##NAME functor(mPb); \
     15PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    1616
    1717
    18 #define CALL_BINARY_FUNCTOR(NAME, TYPE, ARGS...) \
     18#define MAKE_BINARY(NAME, TYPE, ARGS...) \
    1919struct __##NAME { \
    20     inline PabloAST * operator()(PabloAST * expr) { \
    21         return mPB->NAME(expr); \
     20    inline PabloAST * operator()(PabloAST * arg1, PabloAST * arg2) { \
     21        return mPb.NAME(arg1, arg2); \
    2222    } \
    23     inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
     23    inline __##NAME(PabloBlock & pb) : mPb(pb) {} \
    2424private: \
    25     PabloBlock * mPB; \
     25    PabloBlock & mPb; \
    2626}; \
    27 __##NAME functor(this); \
    28 mExprTable.findBinaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
     27__##NAME functor(mPb); \
     28PabloAST * result = mExprTable.findBinaryOrCall(std::move(functor), TYPE, ARGS)
    2929
    30 #define CALL_TERNARY_FUNCTOR(NAME, TYPE, ARGS...) \
     30#define MAKE_TERNARY(NAME, TYPE, ARGS...) \
    3131struct __##NAME { \
    32     inline PabloAST * operator()(PabloAST * expr) { \
    33         return mPB->NAME(expr); \
     32    inline PabloAST * operator()(PabloAST * arg1, PabloAST * arg2, PabloAST * arg3) { \
     33        return mPb.NAME(arg1, arg2, arg3); \
    3434    } \
    35     inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
     35    inline __##NAME(PabloBlock & pb) : mPb(pb) {} \
    3636private: \
    37     PabloBlock * mPB; \
     37    PabloBlock & mPb; \
    3838}; \
    39 __##NAME functor(this); \
    40 mExprTable.findTernaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
     39__##NAME functor(mPb); \
     40PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
    4141
    4242
    4343Call * PabloBuilder::createCall(String * name) {
    44     return CALL_UNARY_FUNCTOR(createCall, PabloAST::ClassTypeId::Call, name);
    45 }
    46 
    47 
    48 Assign * PabloBuilder::createAssign(const std::string prefix, PabloAST * expr, const int outputIndex) {
    49 
     44    MAKE_UNARY(createCall, PabloAST::ClassTypeId::Call, name);
     45    return cast<Call>(result);
    5046}
    5147
    5248PabloAST * PabloBuilder::createAdvance(PabloAST * expr, PabloAST * shiftAmount) {
    53 
     49    MAKE_BINARY(createAdvance, PabloAST::ClassTypeId::Advance, expr, shiftAmount);
     50    return result;
    5451}
    5552
    5653PabloAST * PabloBuilder::createNot(PabloAST * expr) {
    57     return CALL_UNARY_FUNCTOR(createNot, PabloAST::ClassTypeId::Not, expr);
     54    MAKE_UNARY(createNot, PabloAST::ClassTypeId::Not, expr);
     55    return result;
    5856}
    5957
     
    6260        std::swap(expr1, expr2);
    6361    }
    64     return CALL_BINARY_FUNCTOR(createAnd, PabloAST::ClassTypeId::And, expr1, expr2);
     62    MAKE_BINARY(createAnd, PabloAST::ClassTypeId::And, expr1, expr2);
     63    return result;
    6564}
    6665
     
    6968        std::swap(expr1, expr2);
    7069    }
    71     return CALL_BINARY_FUNCTOR(createOr, PabloAST::ClassTypeId::Or, expr1, expr2);
     70    MAKE_BINARY(createOr, PabloAST::ClassTypeId::Or, expr1, expr2);
     71    return result;
    7272}
    7373
     
    7676        std::swap(expr1, expr2);
    7777    }
    78     return CALL_BINARY_FUNCTOR(createXor, PabloAST::ClassTypeId::Xor, expr1, expr2);
     78    MAKE_BINARY(createXor, PabloAST::ClassTypeId::Xor, expr1, expr2);
     79    return result;
    7980}
    8081
    8182PabloAST * PabloBuilder::createMatchStar(PabloAST * marker, PabloAST * charclass) {
    82     return CALL_BINARY_FUNCTOR(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass);
     83    MAKE_BINARY(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass);
     84    return result;
    8385}
    8486
    8587PabloAST * PabloBuilder::createScanThru(PabloAST * from, PabloAST * thru) {
    86     return CALL_BINARY_FUNCTOR(createScanThru, PabloAST::ClassTypeId::ScanThru, from, thru);
     88    MAKE_BINARY(createScanThru, PabloAST::ClassTypeId::ScanThru, from, thru);
     89    return result;
    8790}
    8891
    89 PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
    90     return CALL_TERNARY_FUNCTOR(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr);
     92PabloAST * PabloBuilder::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
     93    MAKE_TERNARY(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr);
     94    return result;
    9195}
    9296
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r4511 r4602  
    1010public:
    1111
    12     inline static PabloBuilder Create(PabloBuilder & predecessor) {
    13         return *(new PabloBlock(predecessor->mPb));
    14     }
     12    PabloBuilder(PabloBlock & pb) : mPb(pb) {}
    1513
    1614    inline Zeroes * createZeroes() const {
    17         return mPb->createZeroes();
     15        return mPb.createZeroes();
    1816    }
    1917
    2018    inline Ones * createOnes() const {
    21         return mPb->createOnes();
     19        return mPb.createOnes();
    2220    }
    2321
    2422    Var * createVar(const std::string name) {
    25         return createVar(mPb->getName(name));
     23        return createVar(mPb.getName(name));
    2624    }
    2725
     
    3331
    3432    inline Call * createCall(const std::string name) {
    35         return createCall(mPb->getName(name));
     33        return createCall(mPb.getName(name));
    3634    }
    3735
    3836    Call * createCall(String * name);
    3937
    40     Assign * createAssign(const std::string prefix, PabloAST * expr, const int outputIndex = -1);
     38    Assign * createAssign(const std::string prefix, PabloAST * expr, const int outputIndex = -1) {
     39        return mPb.createAssign(prefix, expr, outputIndex);
     40    }
    4141
    4242    inline PabloAST * createAdvance(PabloAST * expr, const Integer::integer_t shiftAmount) {
     
    4444            return expr;
    4545        }
    46         return createAdvance(expr, mPb->getInteger(shiftAmount));
     46        return createAdvance(expr, mPb.getInteger(shiftAmount));
    4747    }
    4848
     
    6666
    6767    inline If * createIf(PabloAST * condition, std::initializer_list<Assign *> definedVars, PabloBlock & body) {
    68         mPb->createIf(condition, std::move(definedVars), body);
     68        return mPb.createIf(condition, std::move(definedVars), body);
     69    }
     70
     71    inline If * createIf(PabloAST * condition, std::vector<Assign *> definedVars, PabloBlock & body) {
     72        return mPb.createIf(condition, std::move(definedVars), body);
    6973    }
    7074
    7175    inline While * createWhile(PabloAST * condition, PabloBlock & body) {
    72         mPb->createWhile(condition, body);
     76        return mPb.createWhile(condition, body);
    7377    }
    7478
    7579private:
    7680
    77     PabloBlock *        mPb;
     81    PabloBlock &        mPb;
    7882    ExpressionTable     mExprTable;
    7983};
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4569 r4602  
    5252}
    5353
    54 Call * PabloBlock::createCall(String * name) {
     54Call * PabloBlock::createCall(PabloAST * name) {
    5555    assert (name);
    5656    return insertAtInsertionPoint(new Call(name, this));
     
    8585}
    8686
    87 Var * PabloBlock::createVar(String * name) {
     87Var * PabloBlock::createVar(PabloAST * name) {
    8888    assert (name);
    8989    return new Var(name, this);
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4585 r4602  
    3333namespace pablo {
    3434
    35 class Assign;
    36 class Advance;
    37 class And;
    38 class Call;
    39 class MatchStar;
    40 class Next;
    41 class Not;
    42 class Or;
    43 class Ones;
    44 class ScanThru;
    45 class Sel;
    46 class String;
    47 class Integer;
    48 class Var;
    49 class Xor;
    50 class Zeroes;
    51 class If;
    52 class While;
    53 
    54 
    5535class PabloBlock : public PabloAST, public StatementList {
    56     friend class pablo::PabloAST;
    57     friend class Builder;   
     36    friend class PabloAST;
     37    friend class PabloBuilder;
    5838public:
    5939
     
    9979    }
    10080
    101     Call * createCall(String * name);
     81    inline Call * createCall(String * name) {
     82        return createCall(cast<PabloAST>(name));
     83    }
    10284
    10385    Assign * createAssign(const std::string prefix, PabloAST * expr, const int outputIndex = -1);
     
    10789    }
    10890
    109     Var * createVar(String * name);
    110 
    111     PabloAST * createVar(const PabloAST * const) {
    112         throw std::runtime_error("Var objects should only refer to external Vars (i.e., input basis bit streams). Use Assign objects directly.");
     91    inline Var * createVar(String * name) {
     92        return createVar(cast<PabloAST>(name));
    11393    }
    11494
     
    194174        return expr;
    195175    }
     176private:
     177
     178    Call * createCall(PabloAST * name);
     179
     180    Var * createVar(PabloAST * name);
    196181
    197182private:       
  • icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp

    r4443 r4602  
    8383};
    8484
     85
    8586struct ExpressionTable {
    8687
Note: See TracChangeset for help on using the changeset viewer.