walk the fixup list once every block has an offset
| 50 | |
| 51 | // walk the fixup list once every block has an offset |
| 52 | void resolve_branches() { |
| 53 | for (const auto& f : branch_fixups_) { |
| 54 | auto it = block_offsets_.find(f.target_block_id); |
| 55 | |
| 56 | if (it == block_offsets_.end()) throw Error("resolve_branches: missing block"); |
| 57 | const std::int64_t rel = static_cast<std::int64_t>(it->second) - (static_cast<std::int64_t>(f.patch_pos) + 4); |
| 58 | |
| 59 | if (rel < INT32_MIN || rel > INT32_MAX) throw Error("resolve_branches: oob"); |
| 60 | const std::uint32_t v = static_cast<std::uint32_t>(static_cast<std::int32_t>(rel)); |
| 61 | |
| 62 | for (int i = 0; i < 4; ++i) { |
| 63 | buf_[f.patch_pos + i] = static_cast<std::uint8_t>(v >> (8*i)); |
| 64 | } |
| 65 | } |
| 66 | branch_fixups_.clear(); |
| 67 | } |
| 68 | |
| 69 | // placeholder offset into the data island for an original VA. encoder |
| 70 | // fills it in using the IRProgram data map |
no test coverage detected