|
| 1 | +use std::collections::HashMap; |
| 2 | +use std::error::Error; |
| 3 | + |
1 | 4 | use parity_wasm::elements::{Module, Section}; |
2 | 5 |
|
3 | 6 | use super::{ChiselModule, ModuleError, ModuleKind, ModuleTranslator}; |
@@ -29,6 +32,34 @@ impl<'a> ChiselModule<'a> for DropSection { |
29 | 32 | } |
30 | 33 | } |
31 | 34 |
|
| 35 | +impl From<std::num::ParseIntError> for ModuleError { |
| 36 | + fn from(error: std::num::ParseIntError) -> Self { |
| 37 | + ModuleError::Custom(error.description().to_string()) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +impl ModuleConfig for DropSection { |
| 42 | + fn with_defaults() -> Result<Self, ModuleError> { |
| 43 | + Err(ModuleError::NotSupported) |
| 44 | + } |
| 45 | + |
| 46 | + fn with_config(config: &HashMap<String, String>) -> Result<Self, ModuleError> { |
| 47 | + for (key, val) in config.iter() { |
| 48 | + return match key.as_str() { |
| 49 | + "names" => Ok(DropSection::NamesSection), |
| 50 | + "custom_by_name" => Ok(DropSection::CustomSectionByName(val.clone())), |
| 51 | + "custom_by_index" => { |
| 52 | + Ok(DropSection::CustomSectionByIndex(str::parse::<usize>(val)?)) |
| 53 | + } |
| 54 | + "unknown_by_index" => Ok(DropSection::UnknownSectionByIndex(str::parse::<usize>( |
| 55 | + val, |
| 56 | + )?)), |
| 57 | + _ => Err(ModuleError::NotSupported), |
| 58 | + }; |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
32 | 63 | // TODO: consider upstreaming this |
33 | 64 | fn custom_section_index_for(module: &Module, name: &str) -> Option<usize> { |
34 | 65 | module.sections().iter().position(|e| match e { |
|
0 commit comments