source: icGREP/icgrep-devel/icgrep/icgrep.cpp @ 4401

Last change on this file since 4401 was 4401, checked in by cameron, 4 years ago

Optimized system for carry/advance summary variables

File size: 5.2 KB
Line 
1/*
2 *  Copyright (c) 2014 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#include <string>
8#include <iostream>
9#include <fstream>
10
11#include "icgrep.h"
12#include "utf_encoding.h"
13#include "compiler.h"
14#include "pablo/pablo_compiler.h"
15#include "do_grep.h"
16
17#include "llvm/Support/CommandLine.h"
18
19int main(int argc, char *argv[]) {
20    StringMap<cl::Option*> Map;
21    cl::getRegisteredOptions(Map);
22    Map["time-passes"]->setHiddenFlag(cl::Hidden);
23    Map["disable-spill-fusing"]->setHiddenFlag(cl::Hidden);
24    Map["enable-misched"]->setHiddenFlag(cl::Hidden);
25    Map["enable-tbaa"]->setHiddenFlag(cl::Hidden);
26    Map["exhaustive-register-search"]->setHiddenFlag(cl::Hidden);
27    Map["fatal-assembler-warnings"]->setHiddenFlag(cl::Hidden);
28    Map["join-liveintervals"]->setHiddenFlag(cl::Hidden);
29    Map["limit-float-precision"]->setHiddenFlag(cl::Hidden);
30    Map["mc-x86-disable-arith-relaxation"]->setHiddenFlag(cl::Hidden);
31    Map["limit-float-precision"]->setHiddenFlag(cl::Hidden);
32    Map["print-after-all"]->setHiddenFlag(cl::Hidden);
33    Map["print-before-all"]->setHiddenFlag(cl::Hidden);
34    Map["print-machineinstrs"]->setHiddenFlag(cl::Hidden);
35    Map["regalloc"]->setHiddenFlag(cl::Hidden);
36    Map["rng-seed"]->setHiddenFlag(cl::Hidden);
37    Map["spiller"]->setHiddenFlag(cl::Hidden);
38    Map["stackmap-version"]->setHiddenFlag(cl::Hidden);
39    Map["x86-asm-syntax"]->setHiddenFlag(cl::Hidden);
40    Map["verify-debug-info"]->setHiddenFlag(cl::Hidden);
41    Map["verify-dom-info"]->setHiddenFlag(cl::Hidden);
42    Map["verify-loop-info"]->setHiddenFlag(cl::Hidden);
43    Map["verify-regalloc"]->setHiddenFlag(cl::Hidden);
44    Map["verify-scev"]->setHiddenFlag(cl::Hidden);
45   
46   
47    cl::OptionCategory aRegexSourceOptions("Regular Expression Options",
48                                          "These options control the regular expression source.");
49   
50    cl::OptionCategory bGrepOutputOptions("Output Options",
51                                         "These options control the output.");
52   
53    int firstInputFile = 1;  // Normal case when first positional arg is a regex.
54    cl::list<std::string> inputFiles(cl::Positional, cl::desc("<regex> <input file ...>"), cl::OneOrMore);
55   
56    cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(bGrepOutputOptions));
57    cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
58   
59    cl::opt<bool> ShowFileNames("H", cl::desc("Show the file name with each matching line."), cl::cat(bGrepOutputOptions));
60    cl::alias ShowFileNamesLong("with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
61   
62    cl::opt<bool> ShowLineNumbers("n", cl::desc("Show the line number with each matching line."), cl::cat(bGrepOutputOptions));
63    cl::alias ShowLineNumbersLong("line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
64   
65    cl::list<std::string> regexVector("e", cl::desc("Regular expression"), cl::ZeroOrMore, cl::cat(aRegexSourceOptions));
66   
67    cl::opt<std::string> RegexFilename("f", cl::desc("Take regular expressions (one per line) from a file"), cl::value_desc("regex file"), cl::init(""), cl::cat(aRegexSourceOptions));
68 
69    // Does -b mean the byte offset of the line, or the byte offset of the match start within the line?
70    //static cl::opt<bool>ShowByteOffsets("b", cl::desc("Show the byte offset with each matching line."));
71    //cl::alias ShowByteOffsetsLong("-byte-offset", cl::desc("Alias for -b"), cl::aliasopt(ShowByteOffsets));
72
73    Encoding encoding(Encoding::Type::UTF_8, 8);
74
75    cl::ParseCommandLineOptions(argc, argv);
76   
77    //std::vector<std::string> regexVector;
78    if (RegexFilename != "") {
79        std::ifstream regexFile(RegexFilename.c_str());
80        std::string r;
81        if (regexFile.is_open()) {
82            while (std::getline(regexFile, r)) {
83                regexVector.push_back(r);
84            }
85            regexFile.close();
86        }
87    }
88   
89    // if there are no regexes specified through -e or -f, the first positional argument
90    // must be a regex, not an input file.
91   
92    if (regexVector.size() == 0) {
93        regexVector.push_back(inputFiles[0]);
94        firstInputFile = 1;
95    }
96    else {
97        firstInputFile = 0;
98    }
99   
100    const auto llvm_codegen = icgrep::compile(encoding, regexVector, false);
101
102    if (llvm_codegen.process_block_fptr != 0) {
103        void (*FP)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output) = 
104           (void (*)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output))(void*)llvm_codegen.process_block_fptr;
105        GrepExecutor grepEngine = GrepExecutor(llvm_codegen.carry_q_size, llvm_codegen.advance_q_size, FP);
106        grepEngine.setCountOnlyOption(CountOnly);
107        grepEngine.setShowLineNumberOption(ShowLineNumbers);
108            if (inputFiles.size() > (firstInputFile + 1) || ShowFileNames) {
109            grepEngine.setShowFileNameOption();
110        }
111        for (unsigned i = firstInputFile; i != inputFiles.size(); ++i) {
112            grepEngine.doGrep(inputFiles[i].c_str());
113        }
114    }
115   
116    return 0;
117}
118
Note: See TracBrowser for help on using the repository browser.