Ignore:
Timestamp:
Feb 29, 2016, 3:46:35 PM (3 years ago)
Author:
cameron
Message:

Refactor and encapsulate grep codegen/execution in GrepEngine?

File:
1 moved

Legend:

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

    r4945 r4946  
    55 */
    66
    7 #include "toolchain.h"
    8 #include "do_grep.h"
     7#include <grep_engine.h>
     8#include <toolchain.h>
     9#include <utf_encoding.h>
     10#include <pablo/pablo_compiler.h>
     11#include <kernels/pipeline.h>
     12#include <llvm/IR/Function.h>
     13#include <llvm/IR/Type.h>
     14#include <llvm/IR/Module.h>
     15#include <llvm/ExecutionEngine/MCJIT.h>
     16#include <llvm/IRReader/IRReader.h>
     17#include <llvm/Support/Debug.h>
     18#include <llvm/IR/Verifier.h>
    919
    1020#include <fstream>
     
    3747#include <fcntl.h>
    3848
    39 
    40 #define BUFFER_SEGMENTS 15
    41 #define BUFFER_SIZE (BUFFER_SEGMENTS * SEGMENT_SIZE)
    42 
    43 //
    44 // Write matched lines from a buffer to an output file, given segment
    45 // scanners for line ends and matches (where matches are a subset of line ends).
    46 // The buffer pointer must point to the first byte of the segment
    47 // corresponding to the scanner indexes.   The first_line_start is the
    48 // start position of the first line relative to the buffer start position.
    49 // It must be zero or negative;  if negative, the buffer must permit negative
    50 // indexing so that the lineup to the buffer start position can also be printed.
    51 // The start position of the final line in the processed segment is returned.
    52 //
     49#include <kernels/kernel.h>
    5350
    5451
    55 bool GrepExecutor::finalLineIsUnterminated() const {
     52
     53bool GrepEngine::finalLineIsUnterminated() const {
    5654    if (mFileSize == 0) return false;
    5755    unsigned char end_byte = static_cast<unsigned char>(mFileBuffer[mFileSize-1]);
     
    6967}
    7068
    71 void GrepExecutor::doGrep(const std::string & fileName) {
     69void GrepEngine::doGrep(const std::string & fileName) {
    7270
    7371    mFileName = fileName;
     
    151149#endif   
    152150}
     151
     152void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool isNameExpression) {
     153                           
     154    Module * M = new Module("moduleName", getGlobalContext());
     155   
     156    IDISA::IDISA_Builder * idb = GetNativeIDISA_Builder(M, VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
     157
     158    PipelineBuilder pipelineBuilder(M, idb);
     159
     160    Encoding encoding(Encoding::Type::UTF_8, 8);
     161    re_ast = regular_expression_passes(encoding, re_ast);   
     162    pablo::PabloFunction * function = re2pablo_compiler(encoding, re_ast);
     163
     164    pipelineBuilder.CreateKernels(function, isNameExpression);
     165
     166    pipelineBuilder.ExecuteKernels();
     167
     168    llvm::Function * main_IR = M->getFunction("Main");
     169    mEngine = JIT_to_ExecutionEngine(M);
     170   
     171    icgrep_Linking(M, mEngine);
     172    verifyModule(*M, &dbgs());
     173    mEngine->finalizeObject();
     174    delete idb;
     175
     176    mMainFcn = (main_fcn_T) mEngine->getPointerToFunction(main_IR);
     177}
     178
     179
     180re::CC *  GrepEngine::grepCodepoints(const std::string & UNameFile) {
     181    setParsedCodePointSet();
     182    doGrep(UNameFile);
     183    return getParsedCodePointSet();
     184}
Note: See TracChangeset for help on using the changeset viewer.