Ignore:
Timestamp:
Nov 6, 2016, 8:37:11 PM (2 years ago)
Author:
nmedfort
Message:

Initial work on adding types to PabloAST and mutable Var objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5176 r5202  
    4343
    4444#include <fcntl.h>
     45using namespace pablo;
     46
    4547static cl::OptionCategory wcFlags("Command Flags", "wc options");
    4648
     
    9799//
    98100
    99 pablo::PabloFunction * wc_gen() {
     101PabloFunction * wc_gen() {
    100102    //  input: 8 basis bit streams
    101103    //  output: 3 counters
    102104   
    103     pablo::PabloFunction * function = pablo::PabloFunction::Create("wc", 8, 0);
     105    PabloFunction * function = PabloFunction::Create("wc"); // , 8, 0
    104106    cc::CC_Compiler ccc(*function);
    105107   
    106     pablo::PabloBuilder pBuilder(ccc.getBuilder().getPabloBlock(), ccc.getBuilder());
    107     const std::vector<pablo::Var *> u8_bits = ccc.getBasisBits();
     108    PabloBuilder & pb = ccc.getBuilder();
     109    // const std::vector<Parameter *> u8_bits = ccc.getBasisBits();
     110
     111    Var * lc = function->addResult("lineCount", getScalarTy());
     112    Var * wc = function->addResult("wordCount", getScalarTy());
     113    Var * cc = function->addResult("charCount", getScalarTy());
    108114
    109115    if (CountLines) {
    110         pablo::PabloAST * LF = ccc.compileCC(re::makeCC(0x0A));
    111         function->setResultCount(pBuilder.createCount("lineCount", LF));
     116        PabloAST * LF = ccc.compileCC(re::makeCC(0x0A));
     117        pb.createAssign(lc, pb.createCount(LF));
    112118    }
    113119    if (CountWords) {
    114         pablo::PabloAST * WS = ccc.compileCC(re::makeCC(re::makeCC(0x09, 0x0D), re::makeCC(0x20)));
    115        
    116         pablo::PabloAST * wordChar = pBuilder.createNot(WS);
     120        PabloAST * WS = ccc.compileCC(re::makeCC(re::makeCC(0x09, 0x0D), re::makeCC(0x20)));
     121        PabloAST * wordChar = pb.createNot(WS);
    117122        // WS_follow_or_start = 1 past WS or at start of file
    118         pablo::PabloAST * WS_follow_or_start = pBuilder.createNot(pBuilder.createAdvance(wordChar, 1));
    119         //
    120         pablo::PabloAST * wordStart = pBuilder.createInFile(pBuilder.createAnd(wordChar, WS_follow_or_start));
    121         function->setResultCount(pBuilder.createCount("wordCount", wordStart));
     123        PabloAST * WS_follow_or_start = pb.createNot(pb.createAdvance(wordChar, 1));
     124        PabloAST * wordStart = pb.createInFile(pb.createAnd(wordChar, WS_follow_or_start));
     125        pb.createAssign(wc, pb.createCount(wordStart));
    122126    }
    123127    if (CountChars) {
     
    126130        // not UTF-8, or is not valid?
    127131        //
    128         pablo::PabloAST * u8Begin = ccc.compileCC(re::makeCC(re::makeCC(0, 0x7F), re::makeCC(0xC2, 0xF4)));
    129         function->setResultCount(pBuilder.createCount("charCount", u8Begin));
     132        PabloAST * u8Begin = ccc.compileCC(re::makeCC(re::makeCC(0, 0x7F), re::makeCC(0xC2, 0xF4)));       
     133        pb.createAssign(cc, pb.createCount(u8Begin));
    130134    }
    131135    return function;
     
    136140
    137141
    138 Function * wcPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, pablo::PabloFunction * function) {
     142Function * wcPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, PabloFunction * function) {
    139143    Type * mBitBlockType = iBuilder->getBitBlockType();
    140144   
    141     ExternalFileBuffer ByteStream(iBuilder, StreamSetType(1, i8));
    142     SingleBlockBuffer BasisBits(iBuilder, StreamSetType(8, i1));
    143     //CircularBuffer BasisBits(iBuilder, StreamSetType(8, i1), codegen::SegmentSize * codegen::BufferSegments);
     145    ExternalFileBuffer ByteStream(iBuilder, StreamSetType(iBuilder,1, 8));
     146    SingleBlockBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, 1));
     147    //CircularBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, 1), codegen::SegmentSize * codegen::BufferSegments);
    144148
    145149    s2pKernel  s2pk(iBuilder);
     
    147151   
    148152    pablo_function_passes(function);
    149     pablo::PabloKernel  wck(iBuilder, "wc", function, {"lineCount", "wordCount", "charCount"});
     153    PabloKernel wck(iBuilder, "wc", function);
    150154   
    151155    std::unique_ptr<Module> wcM = wck.createKernelModule({&BasisBits}, {});
     
    183187    Value * lineCount = wck.createGetAccumulatorCall(wcInstance, "lineCount");
    184188    Value * wordCount = wck.createGetAccumulatorCall(wcInstance, "wordCount");
    185     Value * charCount = wck.createGetAccumulatorCall(wcInstance, "charCount");;
     189    Value * charCount = wck.createGetAccumulatorCall(wcInstance, "charCount");
    186190
    187191    iBuilder->CreateCall(record_counts_routine, std::vector<Value *>({lineCount, wordCount, charCount, fileSize, fileIdx}));
     
    201205static ExecutionEngine * wcEngine = nullptr;
    202206
    203 wcFunctionType wcCodeGen(void) {
    204     LLVMContext TheContext;                           
    205     Module * M = new Module("wc", TheContext);
     207wcFunctionType wcCodeGen(void) {
     208    Module * M = new Module("wc", getGlobalContext());
    206209    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    207210
    208     pablo::PabloFunction * function = wc_gen();
     211    PabloFunction * function = wc_gen();
    209212    llvm::Function * main_IR = wcPipeline(M, idb, function);
    210213
     
    255258
    256259int main(int argc, char *argv[]) {
    257     cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *>{&wcFlags, pablo::pablo_toolchain_flags(), codegen::codegen_flags()});
     260    cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *>{&wcFlags, pablo_toolchain_flags(), codegen::codegen_flags()});
    258261    cl::ParseCommandLineOptions(argc, argv);
    259262    if (wcOptions.size() == 0) {
Note: See TracChangeset for help on using the changeset viewer.