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

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

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

File size: 2.7 KB
Line 
1#include <llvm/IR/Module.h>
2#include <llvm/Linker/Linker.h>
3#include <llvm/Support/PrettyStackTrace.h>
4#include <llvm/Support/Signals.h>
5#include <llvm/Support/ManagedStatic.h>
6#include <IR_Gen/idisa_target.h>
7#include <boost/filesystem.hpp>
8#include <boost/iostreams/device/mapped_file.hpp>
9
10#include <cc/cc_compiler.h>
11#include <toolchain/toolchain.h>
12#include <kernels/cc_kernel.h>
13#include <kernels/streamset.h>
14#include <kernels/s2p_kernel.h>
15#include <kernels/kernel_builder.h>
16#include <toolchain/cpudriver.h>
17#include <llvm/Support/raw_ostream.h>
18#include <iostream>
19#include <string>
20
21#include <lzparabix/LZParabixCompressorGenerator.h>
22
23namespace re { class CC; }
24
25using namespace llvm;
26using namespace parabix;
27using namespace kernel;
28
29static cl::OptionCategory compressorFlags("Command Flags", "lzparabix compressor options");
30static cl::opt<std::string> inputFile(cl::Positional, cl::desc("<input file>"), cl::Required, cl::cat(compressorFlags));
31static cl::opt<std::string> outputFile(cl::Positional, cl::desc("<output file>"), cl::Required, cl::cat(compressorFlags));
32static cl::opt<bool> overwriteOutput("f", cl::desc("Overwrite existing output file."), cl::init(false), cl::cat(compressorFlags));
33
34size_t getFileSize(std::string filename) {
35    std::ifstream f(filename, std::ios::binary | std::ios::ate);
36    if (f.fail()) {
37        return 0;
38    }
39    size_t fileSize = f.tellg();
40    f.close();
41    return fileSize;
42}
43
44
45int main(int argc, char *argv[]) {
46// This boilerplate provides convenient stack traces and clean LLVM exit
47    // handling. It also initializes the built in support for convenient
48    // command line option handling.
49    sys::PrintStackTraceOnErrorSignal(argv[0]);
50    llvm::PrettyStackTraceProgram X(argc, argv);
51    llvm_shutdown_obj shutdown;
52    codegen::ParseCommandLineOptions(argc, argv, {&compressorFlags, codegen::codegen_flags()});
53    std::string fileName = inputFile;
54
55    if (boost::filesystem::exists(outputFile)) {
56        if (overwriteOutput) {
57            boost::filesystem::remove(outputFile);
58        } else {
59            llvm::errs() << outputFile + " existed. Use -f argument to overwrite.\n";
60            return -1;
61        }
62    }
63
64    boost::iostreams::mapped_file_source mappedFile;
65    // Since mmap offset has to be multiples of pages, we can't use it to skip headers.
66    size_t fileSize = getFileSize(fileName);
67    mappedFile.open(fileName , fileSize);
68    //char *fileBuffer = const_cast<char *>(mappedFile.data()) + lz4Frame.getBlocksStart();
69    char *fileBuffer = const_cast<char *>(mappedFile.data());
70
71    LZParabixCompressorGenerator g;
72    g.generatePipeline(outputFile);
73    auto main = g.getMainFunc();
74
75    main(fileBuffer, fileSize);
76
77    mappedFile.close();
78    return 0;
79}
Note: See TracBrowser for help on using the repository browser.