pub use crate::features::Feature;
pub use crate::passes::Pass;
use crate::profiles::Profile;
use std::collections::{HashMap, HashSet};
#[derive(Clone, Debug)]
pub struct OptimizationOptions {
pub reader: ReaderOptions,
pub writer: WriterOptions,
pub inlining: InliningOptions,
pub passopts: PassOptions,
pub passes: Passes,
pub features: Features,
pub converge: bool,
}
#[derive(Copy, Clone, Debug)]
pub struct ReaderOptions {
pub file_type: FileType,
}
#[derive(Clone, Debug)]
pub struct WriterOptions {
pub file_type: FileType,
}
#[derive(Copy, Clone, Debug)]
pub enum FileType {
Wasm,
Wat,
Any,
}
#[derive(Copy, Clone, Debug)]
pub struct InliningOptions {
pub always_inline_max_size: u32,
pub one_caller_inline_max_size: u32,
pub flexible_inline_max_size: u32,
pub allow_functions_with_loops: bool,
pub partial_inlining_ifs: u32,
}
#[derive(Clone, Debug)]
pub struct PassOptions {
pub validate: bool,
pub validate_globally: bool,
pub optimize_level: OptimizeLevel,
pub shrink_level: ShrinkLevel,
pub traps_never_happen: bool,
pub low_memory_unused: bool,
pub fast_math: bool,
pub zero_filled_memory: bool,
pub debug_info: bool,
pub arguments: HashMap<String, String>,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum OptimizeLevel {
Level0 = 0,
Level1 = 1,
Level2 = 2,
Level3 = 3,
Level4 = 4,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ShrinkLevel {
Level0 = 0,
Level1 = 1,
Level2 = 2,
}
#[derive(Clone, Debug)]
pub struct Passes {
pub add_default_passes: bool,
pub more_passes: Vec<Pass>,
}
#[derive(Clone, Debug, Default)]
pub struct Features {
pub baseline: FeatureBaseline,
pub enabled: HashSet<Feature>,
pub disabled: HashSet<Feature>,
}
#[derive(Clone, Debug)]
pub enum FeatureBaseline {
Default,
MvpOnly,
All,
}
impl OptimizationOptions {
pub(crate) fn new_empty() -> Self {
OptimizationOptions {
reader: ReaderOptions::default(),
writer: WriterOptions::default(),
inlining: InliningOptions::default(),
passopts: PassOptions::default(),
passes: Passes::default(),
features: Features::default(),
converge: false,
}
}
pub fn new_optimize_for_size() -> Self {
Profile::optimize_for_size().into_opts()
}
pub fn new_optimize_for_size_aggressively() -> Self {
Profile::optimize_for_size_aggressively().into_opts()
}
pub fn new_opt_level_0() -> Self {
Profile::opt_level_0().into_opts()
}
pub fn new_opt_level_1() -> Self {
Profile::opt_level_1().into_opts()
}
pub fn new_opt_level_2() -> Self {
Profile::opt_level_2().into_opts()
}
pub fn new_opt_level_3() -> Self {
Profile::opt_level_3().into_opts()
}
pub fn new_opt_level_4() -> Self {
Profile::opt_level_4().into_opts()
}
}
impl Default for ReaderOptions {
fn default() -> ReaderOptions {
ReaderOptions {
file_type: FileType::Any,
}
}
}
impl Default for WriterOptions {
fn default() -> WriterOptions {
WriterOptions {
file_type: FileType::Wasm,
}
}
}
impl Default for InliningOptions {
fn default() -> InliningOptions {
InliningOptions {
always_inline_max_size: 2,
one_caller_inline_max_size: u32::MAX,
flexible_inline_max_size: 20,
allow_functions_with_loops: false,
partial_inlining_ifs: 0,
}
}
}
impl Default for PassOptions {
fn default() -> PassOptions {
PassOptions {
validate: true,
validate_globally: true,
optimize_level: OptimizeLevel::default(),
shrink_level: ShrinkLevel::default(),
traps_never_happen: false,
low_memory_unused: false,
fast_math: false,
zero_filled_memory: false,
debug_info: false,
arguments: HashMap::<String, String>::new(),
}
}
}
impl Default for OptimizeLevel {
fn default() -> OptimizeLevel {
OptimizeLevel::Level0
}
}
impl Default for ShrinkLevel {
fn default() -> ShrinkLevel {
ShrinkLevel::Level0
}
}
impl Default for Passes {
fn default() -> Passes {
Passes {
add_default_passes: true,
more_passes: vec![],
}
}
}
impl Default for FeatureBaseline {
fn default() -> FeatureBaseline {
FeatureBaseline::Default
}
}