| 1067 | } |
| 1068 | |
| 1069 | void compiler_type::import_csym(const std::string &module_path, const std::string &csym_path) |
| 1070 | { |
| 1071 | std::ifstream ifs(csym_path); |
| 1072 | if (!ifs.is_open()) |
| 1073 | return; |
| 1074 | csym_info csym; |
| 1075 | std::regex reg("^#\\$cSYM/1\\.0\\(([^\\)]*)\\):(.*)$"); |
| 1076 | // Read file |
| 1077 | std::string header, buff; |
| 1078 | bool expect_n = false; |
| 1079 | for (int ch = ifs.get(); ifs; ch = ifs.get()) { |
| 1080 | if (expect_n) { |
| 1081 | expect_n = false; |
| 1082 | if (ch != '\n') |
| 1083 | buff += '\r'; |
| 1084 | } |
| 1085 | switch (ch) { |
| 1086 | case '\n': |
| 1087 | if (!header.empty()) { |
| 1088 | csym.codes.emplace_back(buff); |
| 1089 | buff.clear(); |
| 1090 | } |
| 1091 | else |
| 1092 | std::swap(header, buff); |
| 1093 | break; |
| 1094 | case '\r': |
| 1095 | expect_n = true; |
| 1096 | break; |
| 1097 | default: |
| 1098 | buff += ch; |
| 1099 | break; |
| 1100 | } |
| 1101 | } |
| 1102 | if (!buff.empty()) { |
| 1103 | csym.codes.emplace_back(buff); |
| 1104 | } |
| 1105 | // Parsing header |
| 1106 | std::smatch match; |
| 1107 | if (!std::regex_match(header, match, reg)) |
| 1108 | return; |
| 1109 | csym.file = match.str(1); |
| 1110 | std::string map_str = match.str(2); |
| 1111 | for (auto &ch : map_str) { |
| 1112 | if (ch == ',') { |
| 1113 | if (!buff.empty()) { |
| 1114 | if (buff != "-") |
| 1115 | csym.map.push_back(std::stoull(buff) + 1); |
| 1116 | else |
| 1117 | csym.map.push_back(0); |
| 1118 | buff.clear(); |
| 1119 | } |
| 1120 | } |
| 1121 | else |
| 1122 | buff += ch; |
| 1123 | } |
| 1124 | if (!buff.empty()) { |
| 1125 | if (buff != "-") |
| 1126 | csym.map.push_back(std::stoull(buff) + 1); |
no test coverage detected