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

Last change on this file since 4325 was 4325, checked in by cameron, 5 years ago

New icgrep option parser based on LLVM CommandLine? system.

File size: 2.7 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 "icgrep.h"
8#include "utf_encoding.h"
9#include "compiler.h"
10#include "pablo/pablo_compiler.h"
11#include "do_grep.h"
12
13#include <fstream>
14#include <sstream>
15#include <iostream>
16#include <string>
17#include <stdint.h>
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <unistd.h>
22#include <errno.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25
26#include "llvm/Support/CommandLine.h"
27
28
29   
30int main(int argc, char *argv[]) {
31    static cl::opt<std::string> regexp1(cl::Positional, cl::Required, cl::desc("<regexp>"));
32    static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore);
33   
34    static cl::opt<bool>CountOnly("c", cl::desc("Count and display the matching lines per file only."));
35    cl::alias CountOnlyLong("-count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
36   
37    static cl::opt<bool>ShowFileNames("H", cl::desc("Show the file name with each matching line."));
38    cl::alias ShowFileNamesLong("-with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
39   
40    static cl::opt<bool>ShowLineNumbers("n", cl::desc("Show the line number with each matching line."));
41    cl::alias ShowLineNumbersLong("-line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
42   
43    //cl::opt<std::string> RegexFilename("f", cl::desc("Take regular expressions (one per line) from a file"), cl::value_desc("<filename>"));
44 
45    // Does -b mean the byte offset of the line, or the byte offset of the match start within the line?
46    //static cl::opt<bool>ShowByteOffsets("b", cl::desc("Show the byte offset with each matching line."));
47    //cl::alias ShowByteOffsetsLong("-byte-offset", cl::desc("Alias for -b"), cl::aliasopt(ShowByteOffsets));
48
49    Encoding encoding(Encoding::Type::UTF_8, 8);
50
51    cl::ParseCommandLineOptions(argc, argv);
52
53    const auto llvm_codegen = icgrep::compile(encoding, regexp1, false, false);
54
55    if (llvm_codegen.process_block_fptr != 0)
56     
57    {
58        void (*FP)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output) = 
59           (void (*)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output))(void*)llvm_codegen.process_block_fptr;
60        GrepExecutor grepEngine = GrepExecutor(llvm_codegen.carry_q_size, llvm_codegen.advance_q_size, FP);
61        grepEngine.setCountOnlyOption(CountOnly);
62        if (inputFiles.size() > 1) grepEngine.setShowFileNameOption();
63        for (unsigned i = 0; i != inputFiles.size(); ++i) {
64            grepEngine.doGrep(inputFiles[i].c_str());
65        }
66    }
67
68    return 0;
69}
70
Note: See TracBrowser for help on using the repository browser.