Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (77 loc) · 2.41 KB
/
Copy pathmain.cpp
File metadata and controls
89 lines (77 loc) · 2.41 KB
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
79
80
81
82
83
84
85
86
87
88
89
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <regex>
#include <string>
#include "Core.hpp"
#include "main.hpp"
namespace {
const std::regex CHIPSET_REG(R"([\s]*([\S]+)[\s]+([\S]+)[\s]*$)");
const std::regex LINK_REG(R"([\s]*([\S]+):([\d]+)[\s]+([\S]+):([\d]+)[\s]*$)");
auto load_file(const char *filepath) -> std::vector<nts_entry>
{
std::vector<nts_entry> result;
std::ifstream infile(filepath);
std::string line;
parser_state state = parser_state::Initial;
std::size_t line_number = 0;
while (std::getline(infile, line)) {
line_number++;
if (line == ".chipsets:") {
state = parser_state::Chipsets;
continue;
}
if (line == ".links:") {
state = parser_state::Links;
continue;
}
// TODO: Cleanup the line of comments
if (line == "")
continue;
switch (state) {
case parser_state::Initial:
std::cerr << "Line " << line_number << "had data without chipset or link header! '" << line << "'\n";
exit(84);
case parser_state::Chipsets: {
std::smatch match;
auto matched = std::regex_match(line, match, CHIPSET_REG);
if (!matched) {
std::cerr << "Could not parse line " << line_number << " as a chipset: '" << line << "'\n";
exit(84);
}
result.emplace_back(par_chipset{
.type = match[1],
.name = match[2],
});
break;
}
case parser_state::Links: {
std::smatch match;
auto matched = std::regex_match(line, match, LINK_REG);
if (!matched) {
std::cerr << "Could not parse line " << line_number << " as a link: '" << line << "'\n";
exit(84);
}
result.emplace_back(par_link{
.name_a = match[1],
.pin_a = (std::size_t) std::stoi(match[2]) - 1,
.name_b = match[3],
.pin_b = (std::size_t) std::stoi(match[4]) - 1,
});
break;
}
};
}
return result;
}
} // namespace
auto main(int argc, const char **argv) -> int
{
if (argc != 2)
return 84;
auto tokens = load_file(argv[1]);
Core &core = Core::get_instance();
core.load_circuit(tokens);
core.cli_loop();
return 0;
}