Ignore:
Timestamp:
Feb 18, 2017, 4:13:44 PM (2 years ago)
Author:
nmedfort
Message:

Continued work on parenthesis matching; addition of Pablo ScanTo? and AdvanceThenScanTo/Thru? statements. Bug fix for Pablo Compiler for escaping variables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5320 r5329  
    99#include <kernels/mmap_kernel.h>                   // for MMapSourceKernel
    1010#include <kernels/s2p_kernel.h>                    // for S2PKernel
     11#include <kernels/alignedprint.h>
    1112#include <kernels/streamset.h>                     // for SingleBlockBuffer
    1213#include <kernels/pipeline.h>
     
    1920#include <pablo/pablo_kernel.h>                    // for PabloKernel
    2021#include <pablo/pe_zeroes.h>
     22#include <pablo/pe_ones.h>
    2123#include <toolchain.h>                             // for JIT_to_ExecutionEn...
    2224#include <pablo/builder.hpp>                       // for PabloBuilder
     
    2931#include "llvm/IR/Value.h"                         // for Value
    3032#include "llvm/Support/Debug.h"                    // for dbgs
     33#include <pablo/pablo_toolchain.h>
    3134#include <iostream>
     35
    3236namespace llvm { class Type; }
    3337namespace pablo { class Integer; }
     
    4650
    4751    Var * input = kernel->getInputStreamVar("input");
    48     Var * matches = kernel->getOutputStreamVar("matches");
    4952
    5053    PabloAST * basis[8];
     
    5356    }
    5457
    55     PabloAST * temp1 = pb.createOr(basis[0], basis[1]);
    56     PabloAST * temp2 = pb.createAnd(basis[2], pb.createNot(basis[3]));
    57     PabloAST * temp3 = pb.createAnd(temp2, pb.createNot(temp1));
    58     PabloAST * temp4 = pb.createAnd(basis[4], pb.createNot(basis[5]));
    59     PabloAST * temp5 = pb.createOr(basis[6], basis[7]);
    60     PabloAST * temp6 = pb.createAnd(temp4, pb.createNot(temp5));
     58    PabloAST * temp1 = pb.createOr(basis[0], basis[1], "temp1");
     59    PabloAST * temp2 = pb.createAnd(basis[2], pb.createNot(basis[3]), "temp2");
     60    PabloAST * temp3 = pb.createAnd(temp2, pb.createNot(temp1), "temp3");
     61    PabloAST * temp4 = pb.createAnd(basis[4], pb.createNot(basis[5]), "temp4");
     62    PabloAST * temp5 = pb.createOr(basis[6], basis[7], "temp5");
     63    PabloAST * temp6 = pb.createAnd(temp4, pb.createNot(temp5), "temp6");
    6164    PabloAST * lparen = pb.createAnd(temp3, temp6, "lparens");
    62     PabloAST * temp7 = pb.createAnd(basis[7], pb.createNot(basis[6]));
    63     PabloAST * temp8 = pb.createAnd(temp4, temp7);
     65    PabloAST * temp7 = pb.createAnd(basis[7], pb.createNot(basis[6]), "temp7");
     66    PabloAST * temp8 = pb.createAnd(temp4, temp7, "temp8");
    6467    PabloAST * rparen = pb.createAnd(temp3, temp8, "rparens");
    65     PabloAST * parens = pb.createOr(lparen, rparen);
    66     PabloAST * pscan = pb.createScanTo(pb.createAdvance(lparen, 1), parens, "pscan");
    67     PabloAST * closed = pb.createAnd(pscan, rparen, "closed");
    68 
    69     pb.createAssign(pb.createExtract(matches, 0), closed);
    70 
    71     Var * const all_closed = pb.createVar("all_closed", closed);
    72     Var * const pending_lparen = pb.createVar("pending_lparen", pb.createAnd(pscan, lparen));
    73     PabloAST * unmatched_rparen = pb.createAnd(rparen, pb.createNot(closed));
    74     Var * const in_play = pb.createVar("in_play", pb.createOr(pending_lparen, unmatched_rparen));
    75     Var * const errors = pb.createVar("errors", pb.createZeroes());
    76 
    77     Integer * const one = pb.getInteger(1);
    78     Var * const index = pb.createVar("i", one);
     68    PabloAST * parens = pb.createOr(lparen, rparen, "parens");
     69
     70
     71    Var * const pending_lparen = pb.createVar("pending_lparen", lparen);
     72    Var * const all_closed = pb.createVar("all_closed", pb.createZeroes());
     73    Var * const accumulated_errors = pb.createVar("accumulated_errors", pb.createZeroes());
     74    Var * const in_play = pb.createVar("in_play", parens);
     75    Var * const index = pb.createVar("i", pb.getInteger(0));
     76
     77    Var * matches = kernel->getOutputStreamVar("matches");
    7978
    8079    PabloBuilder body = PabloBuilder::Create(pb);
     
    8281    pb.createWhile(pending_lparen, body);
    8382
    84         pscan = body.createScanTo(body.createAdvance(pending_lparen, 1), in_play);
    85         closed = body.createAnd(pscan, rparen);
     83        PabloAST * pscan = body.createAdvanceThenScanTo(pending_lparen, in_play, "pscan");
     84
     85        PabloAST * closed = body.createAnd(pscan, rparen, "closed");
     86        body.createAssign(all_closed, body.createOr(all_closed, closed));
     87
     88        body.createAssign(pending_lparen, body.createAnd(pscan, lparen));
     89        // Mark any opening paren without a matching closer as an error.
     90        body.createAssign(accumulated_errors, body.createOr(accumulated_errors, body.createAtEOF(pscan)));
     91
    8692        body.createAssign(body.createExtract(matches, index), closed);
    87         body.createAssign(all_closed, body.createOr(all_closed, closed));
    88         body.createAssign(errors, body.createOr(errors, body.createAtEOF(pscan)));
    89 
    90         body.createAssign(pending_lparen, body.createAnd(pscan, lparen));
    91 
    92         unmatched_rparen = body.createAnd(rparen, body.createNot(all_closed));
    93         body.createAssign(in_play, body.createOr(pending_lparen, unmatched_rparen));
    94         body.createAssign(index, body.createAdd(index, one));
    95 
    96 
    97     pb.createAssign(errors, pb.createOr(errors, pb.createAnd(rparen, pb.createNot(all_closed))));
    98     pb.createAssign(kernel->getOutputStreamVar("errors"), errors);
    99 
    100     pb.print(errs());
    101 
    102 }
    103 
    104 //42    def Match_Parens(lex, matches):
    105 //43            parens = lex.LParen | lex.RParen
    106 //44            i = 0
    107 //45            pscan = pablo.AdvanceThenScanTo(lex.LParen, parens)
    108 //46            matches.closed[0] = pscan & lex.RParen
    109 //47            all_closed = matches.closed[0]
    110 //48            matches.error = pablo.atEOF(pscan)
    111 //49            # Not matched, still pending.
    112 //50            pending_LParen = pscan & lex.LParen
    113 //51            RParen_unmatched = lex.RParen &~ matches.closed[0]
    114 //52            inPlay = pending_LParen | RParen_unmatched
    115 //53            while pending_LParen:
    116 //54                    i += 1
    117 //55                    pscan = pablo.AdvanceThenScanTo(pending_LParen, inPlay)
    118 //56                    matches.closed[i] = pscan & lex.RParen
    119 //57                    all_closed |= matches.closed[i]
    120 //58                    matches.error |= pablo.atEOF(pscan)
    121 //59                    pending_LParen = pscan & lex.LParen
    122 //60                    RParen_unmatched = lex.RParen &~ all_closed
    123 //61                    inPlay = pending_LParen | RParen_unmatched
    124 //62            #
    125 //63            # Any closing paren that was not actually used to close
    126 //64            # an opener is in error.
    127 //65            matches.error |= lex.RParen &~ all_closed
     93
     94        PabloAST * pending_rparen = body.createAnd(rparen, body.createNot(all_closed), "pending_rparen");
     95        body.createAssign(in_play, body.createOr(pending_lparen, pending_rparen));
     96        body.createAssign(index, body.createAdd(index, body.getInteger(1)));
     97
     98    // Mark any closing paren that was not actually used to close an opener as an error.
     99    PabloAST * const unmatched_rparen = pb.createAnd(rparen, pb.createNot(all_closed), "unmatched_rparen");
     100    pb.createAssign(kernel->getOutputStreamVar("errors"), pb.createOr(accumulated_errors, unmatched_rparen));
     101
     102}
     103
    128104
    129105Function * pipeline(IDISA::IDISA_Builder * iBuilder, const unsigned count) {
    130106
    131     Type * byteStreamTy = iBuilder->getStreamSetTy(1, 8);
     107    Type * byteStreamTy = iBuilder->getStreamSetTy(1, 2);
    132108
    133109    Module * const mod = iBuilder->getModule();
     
    146122    ExpandableBuffer matches(iBuilder, iBuilder->getStreamSetTy(count, 1), 2);
    147123    SingleBlockBuffer errors(iBuilder, iBuilder->getStreamTy());
     124    ExpandableBuffer output(iBuilder, iBuilder->getStreamSetTy(count * 8, 8), 2);
    148125
    149126    MMapSourceKernel mmapK(iBuilder);
     
    159136
    160137    generate(&bm);
     138    pablo_function_passes(&bm);
    161139
    162140    bm.generateKernel({&BasisBits}, {&matches, &errors});
     141
     142    PrintableStreamSet pss(iBuilder);
     143    pss.generateKernel({&matches}, {&output});
    163144
    164145    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main, 0));
     
    168149    matches.allocateBuffer();
    169150    errors.allocateBuffer();
    170 
    171     generatePipelineLoop(iBuilder, {&mmapK, &s2pk, &bm});
     151    output.allocateBuffer();
     152
     153    generatePipelineLoop(iBuilder, {&mmapK, &s2pk, &bm, &pss});
    172154    iBuilder->CreateRetVoid();
    173155
     
    182164    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    183165
    184     llvm::Function * f = pipeline(idb, 2);
     166    llvm::Function * f = pipeline(idb, 3);
    185167
    186168    verifyModule(*M, &dbgs());
Note: See TracChangeset for help on using the changeset viewer.