source: icGREP/icgrep-devel/icgrep/lzparabix_decoder.cpp @ 6135

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