|
7 | 7 | #include "regex_wrapper.h" |
8 | 8 | #include "aiebu/aiebu_error.h" |
9 | 9 |
|
10 | | -#include <functional> |
11 | | -#include <unordered_map> |
12 | | - |
13 | 10 | namespace aiebu { |
14 | 11 |
|
15 | 12 | assembler_state:: |
@@ -162,59 +159,23 @@ process(bool makeunique) |
162 | 159 | * 3. If string is hex number string (start with "0x"): it return decimal equavalent |
163 | 160 | * 4. If string is numeric string: it will convert to decimal |
164 | 161 | */ |
165 | | -uint32_t assembler_state::parse_num_arg(const std::string& str) { |
166 | | - static const std::unordered_map<std::string, std::function<uint32_t(const std::string&)>> handlers = { |
167 | | - {"@", [this](const std::string& s) -> uint32_t { |
168 | | - //If string start with '@': it can be either pad name or label name |
169 | | - auto key = s.substr(1); |
170 | | - if (m_scratchpad.find(key) != m_scratchpad.end()) |
171 | | - return m_scratchpad[key]->get_base() + m_scratchpad[key]->get_offset(); |
172 | | - if (m_labelmap.find(key) != m_labelmap.end()) |
173 | | - return m_labelmap[key]->get_pos(); |
174 | | - throw error(error::error_code::invalid_asm, "Label " + key + " not present in label map\n"); |
175 | | - }}, |
176 | | - {"s2mm_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}, |
177 | | - {"mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}, |
178 | | - {"mem_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}, |
179 | | - {"mem_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}, |
180 | | - {"shim_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}, |
181 | | - {"shim_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}, |
182 | | - {"tile_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}, |
183 | | - {"tile_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}, |
184 | | - {"shim_ctrl_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }} |
185 | | - }; |
186 | | - |
| 162 | +uint32_t assembler_state::parse_num_arg(const std::string &str) const { |
187 | 163 | // check if its pad/label/actor |
188 | 164 | for (const auto& [prefix, handler] : handlers) { |
189 | 165 | if (str.rfind(prefix) == 0) { |
190 | 166 | return handler(str); |
191 | 167 | } |
192 | 168 | } |
193 | 169 |
|
194 | | - /* |
195 | | - if (str.rfind("tile_") == 0) |
196 | | - { |
197 | | - // Parse and return perticular col and row 32bit base address eg: tile_0_1 |
198 | | - constexpr static size_t col_start = 5; |
199 | | - constexpr static size_t len_of_underscore = 1; |
200 | | - constexpr static size_t row_mask = 0x1F; |
201 | | - constexpr static size_t col_mask = 0x7F; |
202 | | - constexpr static size_t col_shift = 5; |
203 | | - size_t row_start = col_start + len_of_underscore + str.substr(col_start).rfind("_"); |
204 | | - uint32_t col = std::stoi(str.substr(col_start)); |
205 | | - uint32_t row = std::stoi(str.substr(row_start)); |
206 | | - return (((col & col_mask) << col_shift) | (row & row_mask)); |
207 | | - } |
208 | | - */ |
209 | 170 | static const regex kTileRe{R"(^tile_(\d+)_(\d+)$)"}; |
210 | 171 | smatch m; |
211 | | - if (regex_match(str, m, kTileRe) && (m.size() == 3)) |
| 172 | + if ((str[0] == 't') && regex_match(str, m, kTileRe) && (m.size() == 3)) |
212 | 173 | { |
213 | 174 | constexpr static size_t row_mask = 0x1F; |
214 | 175 | constexpr static size_t col_mask = 0x7F; |
215 | 176 | constexpr static size_t col_shift = 5; |
216 | | - const uint32_t col = std::stoi(m[1].str()); |
217 | | - const uint32_t row = std::stoi(m[2].str()); |
| 177 | + const uint32_t col = std::stoi(m[1]); |
| 178 | + const uint32_t row = std::stoi(m[2]); |
218 | 179 | return (((col & col_mask) << col_shift) | (row & row_mask)); |
219 | 180 | } |
220 | 181 | else if (str.rfind("0x") == 0) |
|
0 commit comments