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

Last change on this file since 6141 was 6122, checked in by cameron, 13 months ago

include <fstream>

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