15 #include "cerata/vhdl/template.h"
19 #include "cerata/logging.h"
25 while (std::getline(*str, line)) {
26 lines_.push_back(line);
39 std::ifstream ifs(filename);
41 CERATA_LOG(FATAL,
"Could not open VHDL template file " + filename);
43 CERATA_LOG(DEBUG,
"Opened template file " + filename);
51 Replace(str, std::to_string(with));
55 if (replace_list_.find(str) != replace_list_.end()) {
56 for (
const auto &loc : replace_list_[str]) {
58 lines_[loc.line].replace(loc.start, str.length() + 3, with);
65 for (
const auto &l : lines_) {
74 const std::regex rs_regex(R
"(\$\{[a-zA-Z0-9_]+\})");
81 for (
const auto &line : lines_) {
83 auto rs_begin = std::sregex_iterator(line.begin(), line.end(), rs_regex);
84 auto rs_end = std::sregex_iterator();
87 for (std::sregex_iterator i = rs_begin; i != rs_end; ++i) {
88 std::smatch match = *i;
89 std::string match_string = match.str();
90 std::string replace_string = match_string.substr(2, match_string.length() - 3);
91 trloc loc(
trloc(line_num,
static_cast<size_t>(match.position(0))));
92 replace_list_[replace_string].push_back(loc);