source: icGREP/icgrep-devel/icgrep/kernels/grep_kernel.cpp @ 5404

Last change on this file since 5404 was 5404, checked in by cameron, 3 years ago

Grep kernels with signatures and object caching

File size: 1.8 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "grep_kernel.h"
7#include <boost/uuid/sha1.hpp>
8#include <re/printer_re.h>
9#include <re/re_toolchain.h>
10#include <pablo/pablo_toolchain.h>
11
12using namespace kernel;
13using namespace pablo;
14using namespace re;
15using namespace llvm;
16
17static std::string sha1sum(const std::string & str) {
18    char buffer[41];    // 40 hex-digits and the terminating null
19    unsigned int digest[5];     // 160 bits in total
20   
21    boost::uuids::detail::sha1 sha1;
22    sha1.process_bytes(str.c_str(), str.size());
23    sha1.get_digest(digest);
24    snprintf(buffer, sizeof(buffer), "%.8x%.8x%.8x%.8x%.8x",
25             digest[0], digest[1], digest[2], digest[3], digest[4]);
26    return std::string(buffer);
27}
28
29ICgrepKernelBuilder::ICgrepKernelBuilder (IDISA::IDISA_Builder * iBuilder, RE * re_ast, bool CountOnly)
30: PabloKernel(iBuilder, "",
31              {Binding{iBuilder->getStreamSetTy(8), "basis"}, Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"}},
32              CountOnly ? std::vector<Binding>{} : std::vector<Binding>{Binding{iBuilder->getStreamSetTy(1, 1), "matches"}},
33              {},
34              CountOnly ? std::vector<Binding>{Binding{iBuilder->getSizeTy(), "matchedLineCount"}} : std::vector<Binding>{}),
35  mCountOnly(CountOnly),
36  mRE(re_ast) {
37   
38    mSignature = Printer_RE::PrintRE(re_ast);
39    if (CountOnly) {
40        mSignature += "-c";
41    }
42    std::string uniqueID = sha1sum(mSignature);
43    setName("Parabix:" + uniqueID);
44}
45
46std::string ICgrepKernelBuilder::generateKernelSignature(std::string moduleId) {
47    return mSignature;
48}
49
50void ICgrepKernelBuilder::prepareKernel() {
51    re2pablo_compiler(this, regular_expression_passes(mRE), mCountOnly);
52    pablo_function_passes(this);
53    PabloKernel::prepareKernel();
54}
Note: See TracBrowser for help on using the repository browser.