source: icGREP/icgrep-devel/icgrep/lzparabix_grep.cpp @ 6114

Last change on this file since 6114 was 6114, checked in by xwa163, 10 months ago

Init check in for new compression format (lzparabix) related kernels and pipelines, including compressor, decoder and grep

File size: 3.0 KB
Line 
1//
2// Created by wxy325 on 2018/6/19.
3//
4
5
6#include <llvm/IR/Module.h>
7#include <llvm/Linker/Linker.h>
8#include <llvm/Support/PrettyStackTrace.h>
9#include <llvm/Support/Signals.h>
10#include <llvm/Support/ManagedStatic.h>
11#include <IR_Gen/idisa_target.h>
12#include <boost/filesystem.hpp>
13#include <boost/iostreams/device/mapped_file.hpp>
14
15#include <cc/cc_compiler.h>
16#include <toolchain/toolchain.h>
17#include <kernels/cc_kernel.h>
18#include <kernels/streamset.h>
19#include <kernels/kernel_builder.h>
20#include <toolchain/cpudriver.h>
21
22#include <iostream>
23
24
25#include <re/re_alt.h>
26#include <re/re_start.h>
27#include <re/re_end.h>
28#include <re/re_utility.h>
29#include <re/re_toolchain.h>
30#include <pablo/pablo_toolchain.h>
31#include <llvm/Support/raw_ostream.h>
32#include <lzparabix/LZParabixGrepGenerator.h>
33
34
35namespace re { class CC; }
36
37using namespace llvm;
38using namespace parabix;
39using namespace kernel;
40
41static cl::OptionCategory lz4GrepFlags("Command Flags", "lz4d options");
42static cl::opt<std::string> regexString(cl::Positional, cl::desc("<regex>"), cl::Required, cl::cat(lz4GrepFlags));
43static cl::opt<std::string> inputFile(cl::Positional, cl::desc("<input file>"), cl::Required, cl::cat(lz4GrepFlags));
44static cl::opt<bool> countOnly("count-only", cl::desc("Only count the match result"), cl::init(false), cl::cat(lz4GrepFlags));
45static cl::opt<bool> enableMultiplexing("enable-multiplexing", cl::desc("Enable CC multiplexing."), cl::init(false), cl::cat(lz4GrepFlags));
46
47static cl::OptionCategory lz4GrepDebugFlags("LZ4 Grep Debug Flags", "lz4d debug options");
48
49
50size_t getFileSize(std::string filename) {
51    std::ifstream f(filename, std::ios::binary | std::ios::ate);
52    if (f.fail()) {
53        return 0;
54    }
55    size_t fileSize = f.tellg();
56    f.close();
57    return fileSize;
58}
59
60
61int main(int argc, char *argv[]) {
62    // This boilerplate provides convenient stack traces and clean LLVM exit
63    // handling. It also initializes the built in support for convenient
64    // command line option handling.
65    sys::PrintStackTraceOnErrorSignal(argv[0]);
66    llvm::PrettyStackTraceProgram X(argc, argv);
67    llvm_shutdown_obj shutdown;
68    codegen::ParseCommandLineOptions(argc, argv, {&lz4GrepFlags, &lz4GrepDebugFlags, codegen::codegen_flags()});
69    std::string fileName = inputFile;
70
71    boost::iostreams::mapped_file_source mappedFile;
72    // Since mmap offset has to be multiples of pages, we can't use it to skip headers.
73    size_t fileSize = getFileSize(fileName);
74    mappedFile.open(fileName , fileSize);
75    //char *fileBuffer = const_cast<char *>(mappedFile.data()) + lz4Frame.getBlocksStart();
76    char *fileBuffer = const_cast<char *>(mappedFile.data());
77    re::RE * re_ast = re::RE_Parser::parse(regexString, re::MULTILINE_MODE_FLAG);
78
79    LZParabixGrepGenerator g;
80
81    g.generateCountOnlyAioPipeline(re_ast);
82    auto main = g.getCountOnlyGrepMainFunction();
83    uint64_t countResult = main(fileBuffer, 0, fileSize, false);
84    llvm::outs() << countResult << "\n";
85
86
87    mappedFile.close();
88    return 0;
89}
Note: See TracBrowser for help on using the repository browser.