mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-23 16:38:02 +00:00
solc-json-interface: do not unconditionally skip serialization of custom keys (#337)
The data structure can be used to build the JSON input for `resolc` too. In that case serializing of provided custom options should not be dismissed. Makes the memory settings struct more modular as a drive-by. --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -46,7 +46,7 @@ pub struct Settings {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<Metadata>,
|
||||
/// The resolc custom PolkaVM settings.
|
||||
#[serde(skip_serializing)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub polkavm: Option<PolkaVM>,
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ impl Settings {
|
||||
|
||||
/// Sets the necessary defaults.
|
||||
pub fn normalize(&mut self, version: &semver::Version) {
|
||||
self.polkavm = None;
|
||||
self.optimizer.normalize(version);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@ pub struct Optimizer {
|
||||
/// Whether the optimizer is enabled.
|
||||
pub enabled: bool,
|
||||
/// The optimization mode string.
|
||||
#[serde(skip_serializing)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mode: Option<char>,
|
||||
/// The `solc` optimizer details.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub details: Option<Details>,
|
||||
/// Whether to try to recompile with -Oz if the bytecode is too large.
|
||||
#[serde(skip_serializing)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub fallback_to_optimizing_for_size: Option<bool>,
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ impl Optimizer {
|
||||
|
||||
/// Sets the necessary defaults.
|
||||
pub fn normalize(&mut self, version: &semver::Version) {
|
||||
self.mode = None;
|
||||
self.fallback_to_optimizing_for_size = None;
|
||||
self.details = if version >= &semver::Version::new(0, 5, 5) {
|
||||
Some(Details::disabled(version))
|
||||
} else {
|
||||
|
||||
@@ -2,20 +2,35 @@
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const DEFAULT_HEAP_SIZE: u32 = 64 * 1024;
|
||||
pub const DEFAULT_STACK_SIZE: u32 = 32 * 1024;
|
||||
|
||||
/// The PolkaVM memory configuration.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub struct MemoryConfig {
|
||||
/// The emulated EVM linear heap memory size in bytes.
|
||||
pub heap_size: u32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub heap_size: Option<u32>,
|
||||
/// The PVM stack size in bytes.
|
||||
pub stack_size: u32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stack_size: Option<u32>,
|
||||
}
|
||||
|
||||
impl MemoryConfig {
|
||||
/// A shorthand constructor.
|
||||
pub fn new(heap_size: Option<u32>, stack_size: Option<u32>) -> Self {
|
||||
Self {
|
||||
heap_size,
|
||||
stack_size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for MemoryConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
heap_size: 64 * 1024,
|
||||
stack_size: 32 * 1024,
|
||||
heap_size: Some(DEFAULT_HEAP_SIZE),
|
||||
stack_size: Some(DEFAULT_STACK_SIZE),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,18 @@ pub mod memory;
|
||||
#[derive(Clone, Copy, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct PolkaVM {
|
||||
/// The PolkaVM target machine memory configuration settings.
|
||||
pub memory_config: MemoryConfig,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub memory_config: Option<MemoryConfig>,
|
||||
/// Instruct LLVM to emit debug information.
|
||||
pub debug_information: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub debug_information: Option<bool>,
|
||||
}
|
||||
|
||||
impl PolkaVM {
|
||||
pub fn new(memory_config: Option<MemoryConfig>, debug_information: bool) -> Self {
|
||||
Self {
|
||||
memory_config: memory_config.unwrap_or_default(),
|
||||
debug_information,
|
||||
memory_config,
|
||||
debug_information: Some(debug_information),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user