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

Last change on this file since 5410 was 5410, checked in by cameron, 2 years ago

icgrep refactoring progress; icgrep kernel signatures currently must include -v flag

File size: 2.0 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
17inline static std::string sha1sum(const std::string & str) {
18    char buffer[41];    // 40 hex-digits and the terminating null
19    uint32_t digest[5]; // 160 bits in total
20    boost::uuids::detail::sha1 sha1;
21    sha1.process_bytes(str.c_str(), str.size());
22    sha1.get_digest(digest);
23    snprintf(buffer, sizeof(buffer), "%.8x%.8x%.8x%.8x%.8x",
24             digest[0], digest[1], digest[2], digest[3], digest[4]);
25    return std::string(buffer);
26}
27
28inline std::string makeSignature(RE * const re_ast, const bool CountOnly) {
29    std::string signature = Printer_RE::PrintRE(re_ast);
30    if (CountOnly) {
31        signature += "-c";
32    }
33    if (AlgorithmOptionIsSet(InvertMatches)) {
34        signature += "-v";
35    }
36    return signature;
37}
38
39ICgrepKernelBuilder::ICgrepKernelBuilder (IDISA::IDISA_Builder * const iBuilder, RE * const re_ast, const bool CountOnly)
40: PabloKernel(iBuilder, "",
41              {Binding{iBuilder->getStreamSetTy(8), "basis"}, Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"}},
42              CountOnly ? std::vector<Binding>{} : std::vector<Binding>{Binding{iBuilder->getStreamSetTy(1, 1), "matches"}},
43              {},
44              CountOnly ? std::vector<Binding>{Binding{iBuilder->getSizeTy(), "matchedLineCount"}} : std::vector<Binding>{})
45, mCountOnly(CountOnly)
46, mRE(re_ast)
47, mSignature(makeSignature(re_ast, CountOnly)) {
48    setName("Parabix:" + sha1sum(mSignature));
49}
50
51std::string ICgrepKernelBuilder::generateKernelSignature(std::string moduleId) {
52    return mSignature;
53}
54
55void ICgrepKernelBuilder::prepareKernel() {
56    re2pablo_compiler(this, regular_expression_passes(mRE), mCountOnly);
57    pablo_function_passes(this);
58    PabloKernel::prepareKernel();
59}
Note: See TracBrowser for help on using the repository browser.