Encode exception table entries. Uses 6-bit varint encoding with start marker (MSB) and continuation bit.
(entries: &[ExceptionTableEntry])
| 65 | /// Encode exception table entries. |
| 66 | /// Uses 6-bit varint encoding with start marker (MSB) and continuation bit. |
| 67 | pub fn encode_exception_table(entries: &[ExceptionTableEntry]) -> alloc::boxed::Box<[u8]> { |
| 68 | let mut data = Vec::new(); |
| 69 | for entry in entries { |
| 70 | let size = entry.end.saturating_sub(entry.start); |
| 71 | let depth_lasti = ((entry.depth as u32) << 1) | (entry.push_lasti as u32); |
| 72 | |
| 73 | write_varint_with_start(&mut data, entry.start); |
| 74 | write_varint_be(&mut data, size); |
| 75 | write_varint_be(&mut data, entry.target); |
| 76 | write_varint_be(&mut data, depth_lasti); |
| 77 | } |
| 78 | data.into_boxed_slice() |
| 79 | } |
| 80 | |
| 81 | /// Find exception handler for given instruction offset. |
| 82 | pub fn find_exception_handler(table: &[u8], offset: u32) -> Option<ExceptionTableEntry> { |