-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
78 lines (61 loc) · 1.81 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* \file main.cpp
* \brief Main source code of the module.
* \author Adam Piecek <[email protected]>
* \date 2020
*/
#include "backend/backend.hpp"
#include "parsing/ast/ast_adapted.hpp"
#include "parsing/exception.hpp"
#include "parsing/parser.hpp"
#include <boost/spirit/home/x3.hpp>
#include <fstream>
#include <iostream>
#include <string>
int main(int argc, char **argv)
{
/* Handling command line arguments. */
Program_arguments config(argc, argv);
int ret;
if ((ret = config.processing_arguments()) != ARGS_OK) {
return ret;
}
/* Open the file containing the user rules. */
std::ifstream in(config.get_srcIn_filename(), std::ios_base::in);
std::string storage; /* We will read the contents here. */
in.unsetf(std::ios::skipws); /* No white space skipping! */
std::copy(std::istream_iterator < char >(in),
std::istream_iterator < char >(), std::back_inserter(storage));
Parser parser(storage);
try {
/* Parse user rules. */
parser.run();
}
catch(ProgramError::Error & e) {
std::cerr << e.msg_body << std::endl;
return e.retCode;
}
/* Check the number of output interfaces. */
if ((ret = config.check_number_of_output_interfaces(parser.get_number_of_output_interfaces()))) {
return ret;
}
/* Take the information obtained during parsing. */
Inter_repr data = parser.get_data();
// data.print(data.filterVars);
// data.print(data.group_filterVars);
// data.print(data.aggrVars);
// data.print(data.selVars);
if (check_inter_repr(data)) {
return -1;
}
Backend backend(&data, &config);
/* Prepare backend. */
if (backend.build_backend() != 0) {
return -1;
}
/* Start Policer processing. */
if (backend.start_processing() != 0) {
return -1;
}
return 0;
}