aboutsummaryrefslogtreecommitdiffstats
path: root/python/libghdl/thin/vhdl/elocations.py
blob: 87d87b731da1f5eb103cae66c05be5d684157242 (plain)
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
from libghdl import libghdl


Get_Start_Location = libghdl.vhdl__elocations__get_start_location

Set_Start_Location = libghdl.vhdl__elocations__set_start_location

Get_Right_Paren_Location = libghdl.vhdl__elocations__get_right_paren_location

Set_Right_Paren_Location = libghdl.vhdl__elocations__set_right_paren_location

Get_End_Location = libghdl.vhdl__elocations__get_end_location

Set_End_Location = libghdl.vhdl__elocations__set_end_location

Get_Is_Location = libghdl.vhdl__elocations__get_is_location

Set_Is_Location = libghdl.vhdl__elocations__set_is_location

Get_Begin_Location = libghdl.vhdl__elocations__get_begin_location

Set_Begin_Location = libghdl.vhdl__elocations__set_begin_location

Get_Then_Location = libghdl.vhdl__elocations__get_then_location

Set_Then_Location = libghdl.vhdl__elocations__set_then_location

Get_Use_Location = libghdl.vhdl__elocations__get_use_location

Set_Use_Location = libghdl.vhdl__elocations__set_use_location

Get_Loop_Location = libghdl.vhdl__elocations__get_loop_location

Set_Loop_Location = libghdl.vhdl__elocations__set_loop_location

Get_Generate_Location = libghdl.vhdl__elocations__get_generate_location

Set_Generate_Location = libghdl.vhdl__elocations__set_generate_location

Get_Generic_Location = libghdl.vhdl__elocations__get_generic_location

Set_Generic_Location = libghdl.vhdl__elocations__set_generic_location

Get_Port_Location = libghdl.vhdl__elocations__get_port_location

Set_Port_Location = libghdl.vhdl__elocations__set_port_location

Get_Generic_Map_Location = libghdl.vhdl__elocations__get_generic_map_location

Set_Generic_Map_Location = libghdl.vhdl__elocations__set_generic_map_location

Get_Port_Map_Location = libghdl.vhdl__elocations__get_port_map_location

Set_Port_Map_Location = libghdl.vhdl__elocations__set_port_map_location

Get_Arrow_Location = libghdl.vhdl__elocations__get_arrow_location

Set_Arrow_Location = libghdl.vhdl__elocations__set_arrow_location

Get_Colon_Location = libghdl.vhdl__elocations__get_colon_location

Set_Colon_Location = libghdl.vhdl__elocations__set_colon_location

Get_Assign_Location = libghdl.vhdl__elocations__get_assign_location

Set_Assign_Location = libghdl.vhdl__elocations__set_assign_location
// ------------------------------------------------ template<typename Key, typename T, typename OPS = hash_ops<Key>> struct stackmap { private: std::vector<dict<Key, T*, OPS>> backup_state; dict<Key, T, OPS> current_state; static T empty_tuple; public: stackmap() { } stackmap(const dict<Key, T, OPS> &other) : current_state(other) { } template<typename Other> void operator=(const Other &other) { for (auto &it : current_state) if (!backup_state.empty() && backup_state.back().count(it.first) == 0) backup_state.back()[it.first] = new T(it.second); current_state.clear(); for (auto &it : other) set(it.first, it.second); } bool has(const Key &k) { return current_state.count(k) != 0; } void set(const Key &k, const T &v) { if (!backup_state.empty() && backup_state.back().count(k) == 0) backup_state.back()[k] = current_state.count(k) ? new T(current_state.at(k)) : nullptr; current_state[k] = v; } void unset(const Key &k) { if (!backup_state.empty() && backup_state.back().count(k) == 0) backup_state.back()[k] = current_state.count(k) ? new T(current_state.at(k)) : nullptr; current_state.erase(k); } const T &get(const Key &k) { if (current_state.count(k) == 0) return empty_tuple; return current_state.at(k); } void reset(const Key &k) { for (int i = GetSize(backup_state)-1; i >= 0; i--) if (backup_state[i].count(k) != 0) { if (backup_state[i].at(k) == nullptr) current_state.erase(k); else current_state[k] = *backup_state[i].at(k); return; } current_state.erase(k); } const dict<Key, T, OPS> &stdmap() { return current_state; } void save() { backup_state.resize(backup_state.size()+1); } void restore() { log_assert(!backup_state.empty()); for (auto &it : backup_state.back()) if (it.second != nullptr) { current_state[it.first] = *it.second; delete it.second; } else current_state.erase(it.first); backup_state.pop_back(); } ~stackmap() { while (!backup_state.empty()) restore(); } }; // ------------------------------------------------ // A simple class for topological sorting // ------------------------------------------------ template<typename T, typename C = std::less<T>> struct TopoSort { bool analyze_loops, found_loops; std::map<T, std::set<T, C>, C> database; std::set<std::set<T, C>> loops; std::vector<T> sorted; TopoSort() { analyze_loops = true; found_loops = false; } void node(T n) { if (database.count(n) == 0) database[n] = std::set<T, C>(); } void edge(T left, T right) { node(left); database[right].insert(left); } void sort_worker(const T &n, std::set<T, C> &marked_cells, std::set<T, C> &active_cells, std::vector<T> &active_stack) { if (active_cells.count(n)) { found_loops = true; if (analyze_loops) { std::set<T, C> loop; for (int i = GetSize(active_stack)-1; i >= 0; i--) { loop.insert(active_stack[i]); if (active_stack[i] == n) break; } loops.insert(loop); } return; } if (marked_cells.count(n)) return; if (!database.at(n).empty()) { if (analyze_loops) active_stack.push_back(n); active_cells.insert(n); for (auto &left_n : database.at(n)) sort_worker(left_n, marked_cells, active_cells, active_stack); if (analyze_loops) active_stack.pop_back(); active_cells.erase(n); } marked_cells.insert(n); sorted.push_back(n); } bool sort() { loops.clear(); sorted.clear(); found_loops = false; std::set<T, C> marked_cells; std::set<T, C> active_cells; std::vector<T> active_stack; for (auto &it : database) sort_worker(it.first, marked_cells, active_cells, active_stack); log_assert(GetSize(sorted) == GetSize(database)); return !found_loops; } }; YOSYS_NAMESPACE_END #endif