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 edited

Legend:

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

    r4944 r4946  
    99#include <fstream>
    1010
    11 #include "toolchain.h"
    12 #include "utf_encoding.h"
    13 #include "pablo/pablo_compiler.h"
    14 #include <llvm/IR/Function.h>
    15 #include <llvm/IR/Type.h>
    16 #include <llvm/IR/Module.h>
    17 #include <llvm/ExecutionEngine/ExecutionEngine.h>
    18 #include <llvm/ExecutionEngine/MCJIT.h>
    19 #include <llvm/IRReader/IRReader.h>
     11
    2012#include <llvm/Support/SourceMgr.h>
    2113#include <llvm/Support/CommandLine.h>
     
    2315#include <llvm/Support/TargetSelect.h>
    2416#include <llvm/Support/Host.h>
    25 #include <llvm/IR/Verifier.h>
    2617
    2718#include <re/re_re.h>
     
    3021#include <re/re_any.h>
    3122#include <re/re_alt.h>
    32 #include <pablo/function.h>
    3323
    34 #include "do_grep.h"
    35 #include <kernels/pipeline.h>
     24#include <grep_engine.h>
    3625
    3726static cl::OptionCategory aRegexSourceOptions("Regular Expression Options",
     
    134123    cl::ParseCommandLineOptions(argc, argv);
    135124   
    136     Module * M = new Module("grepcode", getGlobalContext());
     125    re::RE * re_ast = get_icgrep_RE();
    137126   
    138     IDISA::IDISA_Builder * idb = GetNativeIDISA_Builder(M, VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
    139 
    140     PipelineBuilder pipelineBuilder(M, idb);
    141 
    142     re::RE * re_ast = get_icgrep_RE();
    143     Encoding encoding(Encoding::Type::UTF_8, 8);
    144     re_ast = regular_expression_passes(encoding, re_ast);   
    145     pablo::PabloFunction * function = re2pablo_compiler(encoding, re_ast);
    146 
    147     pipelineBuilder.CreateKernels(function, false);
    148 
    149     pipelineBuilder.ExecuteKernels();
    150 
    151     llvm::Function * main_IR = M->getFunction("Main");
    152     llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);
     127    GrepEngine grepEngine;
     128    grepEngine.grepCodeGen("grepcode", re_ast);
    153129   
    154     icgrep_Linking(M, engine);
    155     verifyModule(*M, &dbgs());
    156     engine->finalizeObject();
    157 
    158     void * main_MCptr = engine->getPointerToFunction(main_IR);
    159 
    160     if(main_MCptr){
    161         GrepExecutor grepEngine(main_MCptr);
    162         for (unsigned i = firstInputFile; i != inputFiles.size(); ++i) {
     130    for (unsigned i = firstInputFile; i != inputFiles.size(); ++i) {
    163131            grepEngine.doGrep(inputFiles[i]);
    164         }
    165132    }
    166133   
    167     delete engine;
    168     delete idb;
    169 
    170134    return 0;
    171135}
Note: See TracChangeset for help on using the changeset viewer.