Skip to content

Commit 6719d0c

Browse files
committed
implement dropsection
1 parent 76b7514 commit 6719d0c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

libchisel/src/dropsection.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use std::collections::HashMap;
2+
use std::error::Error;
3+
14
use parity_wasm::elements::{Module, Section};
25

36
use super::{ChiselModule, ModuleError, ModuleKind, ModuleTranslator};
@@ -29,6 +32,34 @@ impl<'a> ChiselModule<'a> for DropSection {
2932
}
3033
}
3134

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+
3263
// TODO: consider upstreaming this
3364
fn custom_section_index_for(module: &Module, name: &str) -> Option<usize> {
3465
module.sections().iter().position(|e| match e {

libchisel/src/fromwat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use parity_wasm::elements::Module;
22
use wabt::Wat2Wasm;
33

4-
use super::{ChiselModule, ModuleCreator, ModuleError, ModuleKind};
4+
use super::{ChiselModule, ModuleConfig, ModuleCreator, ModuleError, ModuleKind};
55

66
/// Struct on which ModuleCreator is implemented.
77
pub struct FromWat<'a> {

0 commit comments

Comments
 (0)