|
| 1 | +use std::collections::HashMap; |
| 2 | + |
1 | 3 | use parity_wasm::elements::Module;
|
2 | 4 |
|
3 |
| -use super::{ChiselModule, ModuleError, ModuleKind, ModuleTranslator}; |
| 5 | +use super::{ChiselModule, ModuleConfig, ModuleError, ModuleKind, ModuleTranslator}; |
4 | 6 |
|
5 | 7 | #[derive(Clone)]
|
6 | 8 | pub struct Snip(wasm_snip::Options);
|
@@ -32,6 +34,30 @@ impl<'a> ChiselModule<'a> for Snip {
|
32 | 34 | }
|
33 | 35 | }
|
34 | 36 |
|
| 37 | +// TODO: consider making this a generic helper? |
| 38 | +fn check_bool_option(config: &HashMap<String, String>, option: &str, default: bool) -> bool { |
| 39 | + if let Some(value) = config.get(option) { |
| 40 | + value == "true" |
| 41 | + } else { |
| 42 | + default |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +impl ModuleConfig for Snip { |
| 47 | + fn with_defaults() -> Result<Self, ModuleError> { |
| 48 | + Ok(Snip::new()) |
| 49 | + } |
| 50 | + |
| 51 | + fn with_config(config: &HashMap<String, String>) -> Result<Self, ModuleError> { |
| 52 | + let mut options = wasm_snip::Options::default(); |
| 53 | + options.snip_rust_fmt_code = check_bool_option(&config, "snip_rust_fmt_code", true); |
| 54 | + options.snip_rust_panicking_code = |
| 55 | + check_bool_option(&config, "snip_rust_panicking_code", true); |
| 56 | + options.skip_producers_section = check_bool_option(&config, "skip_producers_section", true); |
| 57 | + Ok(Snip { 0: options }) |
| 58 | + } |
| 59 | +} |
| 60 | + |
35 | 61 | impl From<failure::Error> for ModuleError {
|
36 | 62 | fn from(error: failure::Error) -> Self {
|
37 | 63 | ModuleError::Custom(error.to_string())
|
|
0 commit comments