handle debug info (#16)

This commit is contained in:
Filipe Azevedo
2022-06-06 15:42:52 +01:00
committed by GitHub
parent 8380823e62
commit 4a51f16874
12 changed files with 50 additions and 31 deletions
+14 -2
View File
@@ -11,7 +11,7 @@ use alloc::{vec, vec::Vec};
use core::{cmp::min, mem, num::NonZeroU32};
use parity_wasm::{
builder,
elements::{self, Instruction, ValueType},
elements::{self, IndexMap, Instruction, ValueType},
};
/// An interface that describes instruction costs.
@@ -129,7 +129,8 @@ impl Rules for ConstantCostRules {
///
/// The above transformations are performed for every function body defined in the module. This
/// function also rewrites all function indices references by code, table elements, etc., since
/// the addition of an imported functions changes the indices of module-defined functions.
/// the addition of an imported functions changes the indices of module-defined functions. If the
/// the module has a NameSection, added by calling `parse_names`, the indices will also be updated.
///
/// This routine runs in time linear in the size of the input module.
///
@@ -212,6 +213,17 @@ pub fn inject<R: Rules>(
if *start_idx >= gas_func {
*start_idx += 1
},
elements::Section::Name(s) =>
for functions in s.functions_mut() {
*functions.names_mut() =
IndexMap::from_iter(functions.names().iter().map(|(mut idx, name)| {
if idx >= gas_func {
idx += 1;
}
(idx, name.clone())
}));
},
_ => {},
}
}