source: icGREP/icgrep-devel/icgrep/lz4d_ext_dep.cpp @ 6053

Last change on this file since 6053 was 6039, checked in by xwa163, 15 months ago

Init checkin for bitstream version of lz4d match copy

File size: 4.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 *  icgrep is a trademark of International Characters.
5 */
6
7
8#include <llvm/IR/Module.h>
9#include <llvm/Linker/Linker.h>
10#include <llvm/Support/PrettyStackTrace.h>
11#include <llvm/Support/Signals.h>
12#include <llvm/Support/ManagedStatic.h>
13#include <IR_Gen/idisa_target.h>
14#include <boost/filesystem.hpp>
15#include <boost/iostreams/device/mapped_file.hpp>
16
17#include <lz4FrameDecoder.h>
18#include <cc/cc_compiler.h>
19#include <toolchain/toolchain.h>
20#include <kernels/cc_kernel.h>
21#include <kernels/streamset.h>
22#include <kernels/s2p_kernel.h>
23#include <kernels/kernel_builder.h>
24#include <toolchain/cpudriver.h>
25#include <llvm/Support/raw_ostream.h>
26#include <iostream>
27#include <lz4/LZ4Generator.h>
28
29namespace re { class CC; }
30
31using namespace llvm;
32using namespace parabix;
33using namespace kernel;
34
35static cl::OptionCategory lz4dFlags("Command Flags", "lz4d options");
36static cl::opt<std::string> inputFile(cl::Positional, cl::desc("<input file>"), cl::Required, cl::cat(lz4dFlags));
37static cl::opt<std::string> outputFile(cl::Positional, cl::desc("<output file>"), cl::Required, cl::cat(lz4dFlags));
38static cl::opt<bool> overwriteOutput("f", cl::desc("Overwrite existing output file."), cl::init(false), cl::cat(lz4dFlags));
39
40
41static cl::OptionCategory lz4dDebugFlags("LZ4D Debug Flags", "lz4d debug options");
42static cl::opt<bool> extractOnly("extract-only", cl::desc("Only extract literal data to output file"), cl::init(false), cl::cat(lz4dDebugFlags));
43static cl::opt<bool> extractAndDepositOnly("extract-and-deposit-only", cl::desc("Only extract and deposit literal data to output file"), cl::init(false), cl::cat(lz4dDebugFlags));
44static cl::opt<bool> swizzledDecompression("swizzled-decompression", cl::desc("Use swizzle approach for decompression"), cl::init(false), cl::cat(lz4dDebugFlags));
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, {&lz4dFlags, &lz4dDebugFlags, codegen::codegen_flags()});
55    std::string fileName = inputFile;
56    LZ4FrameDecoder lz4Frame(fileName);
57    if (!lz4Frame.isValid()) {
58        llvm::errs() << "Invalid LZ4 file.\n";
59        return -1;
60    }
61
62    if (boost::filesystem::exists(outputFile)) {
63        if (overwriteOutput) {
64            boost::filesystem::remove(outputFile);
65        } else {
66            llvm::errs() << outputFile + " existed. Use -f argument to overwrite.\n";
67            return -1;
68        }
69    }
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    mappedFile.open(fileName , lz4Frame.getBlocksLength() + lz4Frame.getBlocksStart());
74    //char *fileBuffer = const_cast<char *>(mappedFile.data()) + lz4Frame.getBlocksStart();
75    char *fileBuffer = const_cast<char *>(mappedFile.data());
76    LZ4Generator g;
77    if (extractOnly) {
78        if (swizzledDecompression) {
79            g.generateSwizzledExtractOnlyPipeline(outputFile);
80        } else {
81            g.generateExtractOnlyPipeline(outputFile);
82        }
83    } else if (extractAndDepositOnly) {
84        if (swizzledDecompression) {
85            g.generateSwizzledExtractAndDepositOnlyPipeline(outputFile);
86        } else {
87            g.generateExtractAndDepositOnlyPipeline(outputFile);
88        }
89    } else {
90        if (swizzledDecompression) {
91            g.generateSwizzledPipeline(outputFile);
92        } else {
93            g.generatePipeline(outputFile);
94        }
95
96    }
97    auto main = g.getMainFunc();
98    main(fileBuffer, lz4Frame.getBlocksStart(), lz4Frame.getBlocksStart() + lz4Frame.getBlocksLength(), lz4Frame.hasBlockChecksum());
99    mappedFile.close();
100
101    return 0;
102}
Note: See TracBrowser for help on using the repository browser.