Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 1 | #include <isolator/hei_isolation_chip.hpp> |
| 2 | |
| 3 | namespace libhei |
| 4 | { |
| 5 | |
| 6 | //------------------------------------------------------------------------------ |
| 7 | |
| 8 | bool IsolationChip::analyze(const Chip& i_chip, IsolationData& io_isoData) const |
| 9 | { |
| 10 | bool o_activeAttn = false; // Initially, assume no active attentions. |
| 11 | |
| 12 | // The given chip must be the same type as iv_chipType. |
| 13 | HEI_ASSERT(iv_chipType == i_chip.getType()); |
| 14 | |
| 15 | // Iterate each root node. |
| 16 | for (const auto& node : iv_rootNodes) |
| 17 | { |
| 18 | if (node.second->analyze(i_chip, node.first, io_isoData)) |
| 19 | { |
| 20 | // At least one attention type had an active attention. |
| 21 | o_activeAttn = true; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | return o_activeAttn; |
| 26 | } |
| 27 | |
| 28 | //------------------------------------------------------------------------------ |
| 29 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 30 | void IsolationChip::addHardwareRegister(HardwareRegister::ConstPtr i_hwReg) |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 31 | { |
| 32 | HEI_ASSERT(i_hwReg); // should not be null |
| 33 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 34 | auto ret = iv_regs.emplace(i_hwReg->getKey(), i_hwReg); |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 35 | |
| 36 | // If an entry already exists, it should point to the same object. |
| 37 | HEI_ASSERT(ret.second || (ret.first->second == i_hwReg)); |
| 38 | } |
| 39 | |
| 40 | //------------------------------------------------------------------------------ |
| 41 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 42 | void IsolationChip::addIsolationNode(IsolationNode::ConstPtr i_isoNode) |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 43 | { |
| 44 | HEI_ASSERT(i_isoNode); // should not be null |
| 45 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 46 | auto ret = iv_nodes.emplace(i_isoNode->getKey(), i_isoNode); |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 47 | |
| 48 | // If an entry already exists, it should point to the same object. |
| 49 | HEI_ASSERT(ret.second || (ret.first->second == i_isoNode)); |
| 50 | } |
| 51 | |
| 52 | //------------------------------------------------------------------------------ |
| 53 | |
| 54 | void IsolationChip::addRootNode(AttentionType_t i_attnType, |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 55 | IsolationNode::ConstPtr i_rootNode) |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 56 | { |
| 57 | HEI_ASSERT(i_rootNode); // should not be null |
| 58 | |
| 59 | auto ret = iv_rootNodes.emplace(i_attnType, i_rootNode); |
| 60 | |
| 61 | // If an entry already exists, it should point to the same object. |
| 62 | HEI_ASSERT(ret.second || (ret.first->second == i_rootNode)); |
| 63 | } |
| 64 | |
| 65 | //------------------------------------------------------------------------------ |
| 66 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 67 | HardwareRegister::ConstPtr |
| 68 | IsolationChip::getHardwareRegister(HardwareRegister::Key i_key) const |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 69 | { |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 70 | auto itr = iv_regs.find(i_key); |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 71 | HEI_ASSERT(iv_regs.end() != itr); // The register should exist. |
| 72 | |
| 73 | return itr->second; |
| 74 | } |
| 75 | |
| 76 | //------------------------------------------------------------------------------ |
| 77 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 78 | IsolationNode::ConstPtr |
| 79 | IsolationChip::getIsolationNode(IsolationNode::Key i_key) const |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 80 | { |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 81 | auto itr = iv_nodes.find(i_key); |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 82 | HEI_ASSERT(iv_nodes.end() != itr); // The node should exist. |
| 83 | |
| 84 | return itr->second; |
| 85 | } |
| 86 | |
| 87 | //------------------------------------------------------------------------------ |
| 88 | |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 89 | } // end namespace libhei |