Merge pull request #2791 from peterhuene/compile-command
Add a compile command to Wasmtime.
This commit is contained in:
@@ -53,3 +53,4 @@ wasm = ["wat", "cranelift-wasm"]
|
||||
experimental_x64 = ["cranelift-codegen/x64", "cranelift-filetests/experimental_x64", "cranelift-reader/experimental_x64"]
|
||||
experimental_arm32 = ["cranelift-codegen/arm32", "cranelift-filetests/experimental_arm32"]
|
||||
souper-harvest = ["cranelift-codegen/souper-harvest", "rayon"]
|
||||
all-arch = ["cranelift-codegen/all-arch"]
|
||||
|
||||
@@ -20,6 +20,7 @@ pub(crate) enum SpecificSetting {
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
pub(crate) struct Setting {
|
||||
pub name: &'static str,
|
||||
pub description: &'static str,
|
||||
pub comment: &'static str,
|
||||
pub specific: SpecificSetting,
|
||||
pub byte_offset: u8,
|
||||
@@ -88,6 +89,7 @@ impl Into<PresetType> for PresetIndex {
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
pub(crate) struct Preset {
|
||||
pub name: &'static str,
|
||||
pub description: &'static str,
|
||||
values: Vec<BoolSettingIndex>,
|
||||
}
|
||||
|
||||
@@ -169,6 +171,7 @@ pub(crate) enum ProtoSpecificSetting {
|
||||
/// This is the information provided during building for a setting.
|
||||
struct ProtoSetting {
|
||||
name: &'static str,
|
||||
description: &'static str,
|
||||
comment: &'static str,
|
||||
specific: ProtoSpecificSetting,
|
||||
}
|
||||
@@ -251,11 +254,13 @@ impl SettingGroupBuilder {
|
||||
fn add_setting(
|
||||
&mut self,
|
||||
name: &'static str,
|
||||
description: &'static str,
|
||||
comment: &'static str,
|
||||
specific: ProtoSpecificSetting,
|
||||
) {
|
||||
self.settings.push(ProtoSetting {
|
||||
name,
|
||||
description,
|
||||
comment,
|
||||
specific,
|
||||
})
|
||||
@@ -264,6 +269,7 @@ impl SettingGroupBuilder {
|
||||
pub fn add_bool(
|
||||
&mut self,
|
||||
name: &'static str,
|
||||
description: &'static str,
|
||||
comment: &'static str,
|
||||
default: bool,
|
||||
) -> BoolSettingIndex {
|
||||
@@ -271,28 +277,55 @@ impl SettingGroupBuilder {
|
||||
self.predicates.is_empty(),
|
||||
"predicates must be added after the boolean settings"
|
||||
);
|
||||
self.add_setting(name, comment, ProtoSpecificSetting::Bool(default));
|
||||
self.add_setting(
|
||||
name,
|
||||
description,
|
||||
comment,
|
||||
ProtoSpecificSetting::Bool(default),
|
||||
);
|
||||
BoolSettingIndex(self.settings.len() - 1)
|
||||
}
|
||||
|
||||
pub fn add_enum(
|
||||
&mut self,
|
||||
name: &'static str,
|
||||
description: &'static str,
|
||||
comment: &'static str,
|
||||
values: Vec<&'static str>,
|
||||
) {
|
||||
self.add_setting(name, comment, ProtoSpecificSetting::Enum(values));
|
||||
self.add_setting(
|
||||
name,
|
||||
description,
|
||||
comment,
|
||||
ProtoSpecificSetting::Enum(values),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn add_num(&mut self, name: &'static str, comment: &'static str, default: u8) {
|
||||
self.add_setting(name, comment, ProtoSpecificSetting::Num(default));
|
||||
pub fn add_num(
|
||||
&mut self,
|
||||
name: &'static str,
|
||||
description: &'static str,
|
||||
comment: &'static str,
|
||||
default: u8,
|
||||
) {
|
||||
self.add_setting(
|
||||
name,
|
||||
description,
|
||||
comment,
|
||||
ProtoSpecificSetting::Num(default),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn add_predicate(&mut self, name: &'static str, node: PredicateNode) {
|
||||
self.predicates.push(ProtoPredicate { name, node });
|
||||
}
|
||||
|
||||
pub fn add_preset(&mut self, name: &'static str, args: Vec<PresetType>) -> PresetIndex {
|
||||
pub fn add_preset(
|
||||
&mut self,
|
||||
name: &'static str,
|
||||
description: &'static str,
|
||||
args: Vec<PresetType>,
|
||||
) -> PresetIndex {
|
||||
let mut values = Vec::new();
|
||||
for arg in args {
|
||||
match arg {
|
||||
@@ -302,7 +335,11 @@ impl SettingGroupBuilder {
|
||||
PresetType::BoolSetting(index) => values.push(index),
|
||||
}
|
||||
}
|
||||
self.presets.push(Preset { name, values });
|
||||
self.presets.push(Preset {
|
||||
name,
|
||||
description,
|
||||
values,
|
||||
});
|
||||
PresetIndex(self.presets.len() - 1)
|
||||
}
|
||||
|
||||
@@ -347,6 +384,7 @@ impl SettingGroupBuilder {
|
||||
|
||||
group.settings.push(Setting {
|
||||
name: s.name,
|
||||
description: s.description,
|
||||
comment: s.comment,
|
||||
byte_offset,
|
||||
specific,
|
||||
@@ -367,6 +405,7 @@ impl SettingGroupBuilder {
|
||||
};
|
||||
group.settings.push(Setting {
|
||||
name: s.name,
|
||||
description: s.description,
|
||||
comment: s.comment,
|
||||
byte_offset: byte_offset + predicate_number / 8,
|
||||
specific: SpecificSetting::Bool(BoolSetting {
|
||||
|
||||
@@ -70,6 +70,33 @@ fn gen_constructor(group: &SettingGroup, parent: ParentGroup, fmt: &mut Formatte
|
||||
fmtln!(fmt, "}");
|
||||
}
|
||||
|
||||
/// Generates the `iter` function.
|
||||
fn gen_iterator(group: &SettingGroup, fmt: &mut Formatter) {
|
||||
fmtln!(fmt, "impl Flags {");
|
||||
fmt.indent(|fmt| {
|
||||
fmt.doc_comment("Iterates the setting values.");
|
||||
fmtln!(fmt, "pub fn iter(&self) -> impl Iterator<Item = Value> {");
|
||||
fmt.indent(|fmt| {
|
||||
fmtln!(fmt, "let mut bytes = [0; {}];", group.settings_size);
|
||||
fmtln!(fmt, "bytes.copy_from_slice(&self.bytes[0..{}]);", group.settings_size);
|
||||
fmtln!(fmt, "DESCRIPTORS.iter().filter_map(move |d| {");
|
||||
fmt.indent(|fmt| {
|
||||
fmtln!(fmt, "let values = match &d.detail {");
|
||||
fmt.indent(|fmt| {
|
||||
fmtln!(fmt, "detail::Detail::Preset => return None,");
|
||||
fmtln!(fmt, "detail::Detail::Enum { last, enumerators } => Some(TEMPLATE.enums(*last, *enumerators)),");
|
||||
fmtln!(fmt, "_ => None");
|
||||
});
|
||||
fmtln!(fmt, "};");
|
||||
fmtln!(fmt, "Some(Value{ name: d.name, detail: d.detail, values, value: bytes[d.offset as usize] })");
|
||||
});
|
||||
fmtln!(fmt, "})");
|
||||
});
|
||||
fmtln!(fmt, "}");
|
||||
});
|
||||
fmtln!(fmt, "}");
|
||||
}
|
||||
|
||||
/// Emit Display and FromStr implementations for enum settings.
|
||||
fn gen_to_and_from_str(name: &str, values: &[&'static str], fmt: &mut Formatter) {
|
||||
fmtln!(fmt, "impl fmt::Display for {} {{", name);
|
||||
@@ -136,7 +163,7 @@ fn gen_enum_types(group: &SettingGroup, fmt: &mut Formatter) {
|
||||
|
||||
/// Emit a getter function for `setting`.
|
||||
fn gen_getter(setting: &Setting, fmt: &mut Formatter) {
|
||||
fmt.doc_comment(setting.comment);
|
||||
fmt.doc_comment(format!("{}\n{}", setting.description, setting.comment));
|
||||
match setting.specific {
|
||||
SpecificSetting::Bool(BoolSetting {
|
||||
predicate_number, ..
|
||||
@@ -254,6 +281,7 @@ fn gen_descriptors(group: &SettingGroup, fmt: &mut Formatter) {
|
||||
fmtln!(fmt, "detail::Descriptor {");
|
||||
fmt.indent(|fmt| {
|
||||
fmtln!(fmt, "name: \"{}\",", setting.name);
|
||||
fmtln!(fmt, "description: \"{}\",", setting.description);
|
||||
fmtln!(fmt, "offset: {},", setting.byte_offset);
|
||||
match setting.specific {
|
||||
SpecificSetting::Bool(BoolSetting { bit_offset, .. }) => {
|
||||
@@ -286,6 +314,7 @@ fn gen_descriptors(group: &SettingGroup, fmt: &mut Formatter) {
|
||||
fmtln!(fmt, "detail::Descriptor {");
|
||||
fmt.indent(|fmt| {
|
||||
fmtln!(fmt, "name: \"{}\",", preset.name);
|
||||
fmtln!(fmt, "description: \"{}\",", preset.description);
|
||||
fmtln!(fmt, "offset: {},", (idx as u8) * group.settings_size);
|
||||
fmtln!(fmt, "detail: detail::Detail::Preset,");
|
||||
});
|
||||
@@ -427,6 +456,7 @@ fn gen_group(group: &SettingGroup, parent: ParentGroup, fmt: &mut Formatter) {
|
||||
fmtln!(fmt, "}");
|
||||
|
||||
gen_constructor(group, parent, fmt);
|
||||
gen_iterator(group, fmt);
|
||||
gen_enum_types(group, fmt);
|
||||
gen_getters(group, fmt);
|
||||
gen_descriptors(group, fmt);
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::shared::Definitions as SharedDefinitions;
|
||||
|
||||
fn define_settings(_shared: &SettingGroup) -> SettingGroup {
|
||||
let mut setting = SettingGroupBuilder::new("arm64");
|
||||
let has_lse = setting.add_bool("has_lse", "Large System Extensions", false);
|
||||
let has_lse = setting.add_bool("has_lse", "Has Large System Extensions support.", "", false);
|
||||
|
||||
setting.add_predicate("use_lse", predicate!(has_lse));
|
||||
setting.build()
|
||||
|
||||
@@ -17,33 +17,39 @@ fn define_settings(shared: &SettingGroup) -> SettingGroup {
|
||||
let supports_m = setting.add_bool(
|
||||
"supports_m",
|
||||
"CPU supports the 'M' extension (mul/div)",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
let supports_a = setting.add_bool(
|
||||
"supports_a",
|
||||
"CPU supports the 'A' extension (atomics)",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
let supports_f = setting.add_bool(
|
||||
"supports_f",
|
||||
"CPU supports the 'F' extension (float)",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
let supports_d = setting.add_bool(
|
||||
"supports_d",
|
||||
"CPU supports the 'D' extension (double)",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
|
||||
let enable_m = setting.add_bool(
|
||||
"enable_m",
|
||||
"Enable the use of 'M' instructions if available",
|
||||
"",
|
||||
true,
|
||||
);
|
||||
|
||||
setting.add_bool(
|
||||
"enable_e",
|
||||
"Enable the 'RV32E' instruction set with only 16 registers",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
|
||||
|
||||
@@ -4,37 +4,77 @@ pub(crate) fn define(shared: &SettingGroup) -> SettingGroup {
|
||||
let mut settings = SettingGroupBuilder::new("x86");
|
||||
|
||||
// CPUID.01H:ECX
|
||||
let has_sse3 = settings.add_bool("has_sse3", "SSE3: CPUID.01H:ECX.SSE3[bit 0]", false);
|
||||
let has_ssse3 = settings.add_bool("has_ssse3", "SSSE3: CPUID.01H:ECX.SSSE3[bit 9]", false);
|
||||
let has_sse41 = settings.add_bool("has_sse41", "SSE4.1: CPUID.01H:ECX.SSE4_1[bit 19]", false);
|
||||
let has_sse42 = settings.add_bool("has_sse42", "SSE4.2: CPUID.01H:ECX.SSE4_2[bit 20]", false);
|
||||
let has_avx = settings.add_bool("has_avx", "AVX: CPUID.01H:ECX.AVX[bit 28]", false);
|
||||
let has_avx2 = settings.add_bool("has_avx2", "AVX2: CPUID.07H:EBX.AVX2[bit 5]", false);
|
||||
let has_sse3 = settings.add_bool(
|
||||
"has_sse3",
|
||||
"Has support for SSE3.",
|
||||
"SSE3: CPUID.01H:ECX.SSE3[bit 0]",
|
||||
false,
|
||||
);
|
||||
let has_ssse3 = settings.add_bool(
|
||||
"has_ssse3",
|
||||
"Has support for SSSE3.",
|
||||
"SSSE3: CPUID.01H:ECX.SSSE3[bit 9]",
|
||||
false,
|
||||
);
|
||||
let has_sse41 = settings.add_bool(
|
||||
"has_sse41",
|
||||
"Has support for SSE4.1.",
|
||||
"SSE4.1: CPUID.01H:ECX.SSE4_1[bit 19]",
|
||||
false,
|
||||
);
|
||||
let has_sse42 = settings.add_bool(
|
||||
"has_sse42",
|
||||
"Has support for SSE4.2.",
|
||||
"SSE4.2: CPUID.01H:ECX.SSE4_2[bit 20]",
|
||||
false,
|
||||
);
|
||||
let has_avx = settings.add_bool(
|
||||
"has_avx",
|
||||
"Has support for AVX.",
|
||||
"AVX: CPUID.01H:ECX.AVX[bit 28]",
|
||||
false,
|
||||
);
|
||||
let has_avx2 = settings.add_bool(
|
||||
"has_avx2",
|
||||
"Has support for AVX2.",
|
||||
"AVX2: CPUID.07H:EBX.AVX2[bit 5]",
|
||||
false,
|
||||
);
|
||||
let has_avx512dq = settings.add_bool(
|
||||
"has_avx512dq",
|
||||
"Has support for AVX512DQ.",
|
||||
"AVX512DQ: CPUID.07H:EBX.AVX512DQ[bit 17]",
|
||||
false,
|
||||
);
|
||||
let has_avx512vl = settings.add_bool(
|
||||
"has_avx512vl",
|
||||
"Has support for AVX512VL.",
|
||||
"AVX512VL: CPUID.07H:EBX.AVX512VL[bit 31]",
|
||||
false,
|
||||
);
|
||||
let has_avx512f = settings.add_bool(
|
||||
"has_avx512f",
|
||||
"Has support for AVX512F.",
|
||||
"AVX512F: CPUID.07H:EBX.AVX512F[bit 16]",
|
||||
false,
|
||||
);
|
||||
let has_popcnt = settings.add_bool("has_popcnt", "POPCNT: CPUID.01H:ECX.POPCNT[bit 23]", false);
|
||||
let has_popcnt = settings.add_bool(
|
||||
"has_popcnt",
|
||||
"Has support for POPCNT.",
|
||||
"POPCNT: CPUID.01H:ECX.POPCNT[bit 23]",
|
||||
false,
|
||||
);
|
||||
|
||||
// CPUID.(EAX=07H, ECX=0H):EBX
|
||||
let has_bmi1 = settings.add_bool(
|
||||
"has_bmi1",
|
||||
"Has support for BMI1.",
|
||||
"BMI1: CPUID.(EAX=07H, ECX=0H):EBX.BMI1[bit 3]",
|
||||
false,
|
||||
);
|
||||
let has_bmi2 = settings.add_bool(
|
||||
"has_bmi2",
|
||||
"Has support for BMI2.",
|
||||
"BMI2: CPUID.(EAX=07H, ECX=0H):EBX.BMI2[bit 8]",
|
||||
false,
|
||||
);
|
||||
@@ -42,6 +82,7 @@ pub(crate) fn define(shared: &SettingGroup) -> SettingGroup {
|
||||
// CPUID.EAX=80000001H:ECX
|
||||
let has_lzcnt = settings.add_bool(
|
||||
"has_lzcnt",
|
||||
"Has support for LZCNT.",
|
||||
"LZCNT: CPUID.EAX=80000001H:ECX.LZCNT[bit 5]",
|
||||
false,
|
||||
);
|
||||
@@ -85,7 +126,7 @@ pub(crate) fn define(shared: &SettingGroup) -> SettingGroup {
|
||||
settings.add_predicate("use_lzcnt", predicate!(has_lzcnt));
|
||||
|
||||
// Some shared boolean values are used in x86 instruction predicates, so we need to group them
|
||||
// in the same TargetIsa, for compabitibity with code generated by meta-python.
|
||||
// in the same TargetIsa, for compatibility with code generated by meta-python.
|
||||
// TODO Once all the meta generation code has been migrated from Python to Rust, we can put it
|
||||
// back in the shared SettingGroup, and use it in x86 instruction predicates.
|
||||
|
||||
@@ -104,21 +145,40 @@ pub(crate) fn define(shared: &SettingGroup) -> SettingGroup {
|
||||
|
||||
// Presets corresponding to x86 CPUs.
|
||||
|
||||
settings.add_preset("baseline", preset!());
|
||||
settings.add_preset(
|
||||
"baseline",
|
||||
"A baseline preset with no extensions enabled.",
|
||||
preset!(),
|
||||
);
|
||||
let nehalem = settings.add_preset(
|
||||
"nehalem",
|
||||
"Nehalem microarchitecture.",
|
||||
preset!(has_sse3 && has_ssse3 && has_sse41 && has_sse42 && has_popcnt),
|
||||
);
|
||||
let haswell = settings.add_preset(
|
||||
"haswell",
|
||||
"Haswell microarchitecture.",
|
||||
preset!(nehalem && has_bmi1 && has_bmi2 && has_lzcnt),
|
||||
);
|
||||
let broadwell = settings.add_preset("broadwell", preset!(haswell));
|
||||
let skylake = settings.add_preset("skylake", preset!(broadwell));
|
||||
let cannonlake = settings.add_preset("cannonlake", preset!(skylake));
|
||||
settings.add_preset("icelake", preset!(cannonlake));
|
||||
let broadwell = settings.add_preset(
|
||||
"broadwell",
|
||||
"Broadwell microarchitecture.",
|
||||
preset!(haswell),
|
||||
);
|
||||
let skylake = settings.add_preset("skylake", "Skylake microarchitecture.", preset!(broadwell));
|
||||
let cannonlake = settings.add_preset(
|
||||
"cannonlake",
|
||||
"Canon Lake microarchitecture.",
|
||||
preset!(skylake),
|
||||
);
|
||||
settings.add_preset(
|
||||
"icelake",
|
||||
"Ice Lake microarchitecture.",
|
||||
preset!(cannonlake),
|
||||
);
|
||||
settings.add_preset(
|
||||
"znver1",
|
||||
"Zen (first generation) microarchitecture.",
|
||||
preset!(
|
||||
has_sse3
|
||||
&& has_ssse3
|
||||
|
||||
@@ -5,29 +5,29 @@ pub(crate) fn define() -> SettingGroup {
|
||||
|
||||
settings.add_enum(
|
||||
"regalloc",
|
||||
r#"Register allocator to use with the MachInst backend.
|
||||
"Register allocator to use with the MachInst backend.",
|
||||
r#"
|
||||
This selects the register allocator as an option among those offered by the `regalloc.rs`
|
||||
crate. Please report register allocation bugs to the maintainers of this crate whenever
|
||||
possible.
|
||||
|
||||
This selects the register allocator as an option among those offered by the `regalloc.rs`
|
||||
crate. Please report register allocation bugs to the maintainers of this crate whenever
|
||||
possible.
|
||||
Note: this only applies to target that use the MachInst backend. As of 2020-04-17, this
|
||||
means the x86_64 backend doesn't use this yet.
|
||||
|
||||
Note: this only applies to target that use the MachInst backend. As of 2020-04-17, this
|
||||
means the x86_64 backend doesn't use this yet.
|
||||
Possible values:
|
||||
|
||||
Possible values:
|
||||
|
||||
- `backtracking` is a greedy, backtracking register allocator as implemented in
|
||||
Spidermonkey's optimizing tier IonMonkey. It may take more time to allocate registers, but
|
||||
it should generate better code in general, resulting in better throughput of generated
|
||||
code.
|
||||
- `backtracking_checked` is the backtracking allocator with additional self checks that may
|
||||
take some time to run, and thus these checks are disabled by default.
|
||||
- `experimental_linear_scan` is an experimental linear scan allocator. It may take less
|
||||
time to allocate registers, but generated code's quality may be inferior. As of
|
||||
2020-04-17, it is still experimental and it should not be used in production settings.
|
||||
- `experimental_linear_scan_checked` is the linear scan allocator with additional self
|
||||
checks that may take some time to run, and thus these checks are disabled by default.
|
||||
"#,
|
||||
- `backtracking` is a greedy, backtracking register allocator as implemented in
|
||||
Spidermonkey's optimizing tier IonMonkey. It may take more time to allocate registers, but
|
||||
it should generate better code in general, resulting in better throughput of generated
|
||||
code.
|
||||
- `backtracking_checked` is the backtracking allocator with additional self checks that may
|
||||
take some time to run, and thus these checks are disabled by default.
|
||||
- `experimental_linear_scan` is an experimental linear scan allocator. It may take less
|
||||
time to allocate registers, but generated code's quality may be inferior. As of
|
||||
2020-04-17, it is still experimental and it should not be used in production settings.
|
||||
- `experimental_linear_scan_checked` is the linear scan allocator with additional self
|
||||
checks that may take some time to run, and thus these checks are disabled by default.
|
||||
"#,
|
||||
vec![
|
||||
"backtracking",
|
||||
"backtracking_checked",
|
||||
@@ -38,24 +38,23 @@ pub(crate) fn define() -> SettingGroup {
|
||||
|
||||
settings.add_enum(
|
||||
"opt_level",
|
||||
"Optimization level for generated code.",
|
||||
r#"
|
||||
Optimization level:
|
||||
Supported levels:
|
||||
|
||||
- none: Minimise compile time by disabling most optimizations.
|
||||
- speed: Generate the fastest possible code
|
||||
- speed_and_size: like "speed", but also perform transformations
|
||||
aimed at reducing code size.
|
||||
- `none`: Minimise compile time by disabling most optimizations.
|
||||
- `speed`: Generate the fastest possible code
|
||||
- `speed_and_size`: like "speed", but also perform transformations aimed at reducing code size.
|
||||
"#,
|
||||
vec!["none", "speed", "speed_and_size"],
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_verifier",
|
||||
"Run the Cranelift IR verifier at strategic times during compilation.",
|
||||
r#"
|
||||
Run the Cranelift IR verifier at strategic times during compilation.
|
||||
|
||||
This makes compilation slower but catches many bugs. The verifier is always enabled by
|
||||
default, which is useful during development.
|
||||
This makes compilation slower but catches many bugs. The verifier is always enabled by
|
||||
default, which is useful during development.
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
@@ -65,110 +64,110 @@ pub(crate) fn define() -> SettingGroup {
|
||||
// `colocated` flag on external functions and global values.
|
||||
settings.add_bool(
|
||||
"is_pic",
|
||||
"Enable Position-Independent Code generation",
|
||||
"Enable Position-Independent Code generation.",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"use_colocated_libcalls",
|
||||
"Use colocated libcalls.",
|
||||
r#"
|
||||
Use colocated libcalls.
|
||||
|
||||
Generate code that assumes that libcalls can be declared "colocated",
|
||||
meaning they will be defined along with the current function, such that
|
||||
they can use more efficient addressing.
|
||||
"#,
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"avoid_div_traps",
|
||||
"Generate explicit checks around native division instructions to avoid their trapping.",
|
||||
r#"
|
||||
Generate explicit checks around native division instructions to avoid
|
||||
their trapping.
|
||||
|
||||
This is primarily used by SpiderMonkey which doesn't install a signal
|
||||
handler for SIGFPE, but expects a SIGILL trap for division by zero.
|
||||
|
||||
On ISAs like ARM where the native division instructions don't trap,
|
||||
this setting has no effect - explicit checks are always inserted.
|
||||
"#,
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_float",
|
||||
"Enable the use of floating-point instructions.",
|
||||
r#"
|
||||
Enable the use of floating-point instructions
|
||||
|
||||
Disabling use of floating-point instructions is not yet implemented.
|
||||
"#,
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_nan_canonicalization",
|
||||
"Enable NaN canonicalization.",
|
||||
r#"
|
||||
Enable NaN canonicalization
|
||||
|
||||
This replaces NaNs with a single canonical value, for users requiring
|
||||
entirely deterministic WebAssembly computation. This is not required
|
||||
by the WebAssembly spec, so it is not enabled by default.
|
||||
"#,
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_pinned_reg",
|
||||
r#"Enable the use of the pinned register.
|
||||
|
||||
This register is excluded from register allocation, and is completely under the control of
|
||||
the end-user. It is possible to read it via the get_pinned_reg instruction, and to set it
|
||||
with the set_pinned_reg instruction.
|
||||
"Enable the use of the pinned register.",
|
||||
r#"
|
||||
This register is excluded from register allocation, and is completely under the control of
|
||||
the end-user. It is possible to read it via the get_pinned_reg instruction, and to set it
|
||||
with the set_pinned_reg instruction.
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"use_pinned_reg_as_heap_base",
|
||||
r#"Use the pinned register as the heap base.
|
||||
"Use the pinned register as the heap base.",
|
||||
r#"
|
||||
Enabling this requires the enable_pinned_reg setting to be set to true. It enables a custom
|
||||
legalization of the `heap_addr` instruction so it will use the pinned register as the heap
|
||||
base, instead of fetching it from a global value.
|
||||
|
||||
Enabling this requires the enable_pinned_reg setting to be set to true. It enables a custom
|
||||
legalization of the `heap_addr` instruction so it will use the pinned register as the heap
|
||||
base, instead of fetching it from a global value.
|
||||
|
||||
Warning! Enabling this means that the pinned register *must* be maintained to contain the
|
||||
heap base address at all times, during the lifetime of a function. Using the pinned
|
||||
register for other purposes when this is set is very likely to cause crashes.
|
||||
Warning! Enabling this means that the pinned register *must* be maintained to contain the
|
||||
heap base address at all times, during the lifetime of a function. Using the pinned
|
||||
register for other purposes when this is set is very likely to cause crashes.
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool("enable_simd", "Enable the use of SIMD instructions.", false);
|
||||
settings.add_bool(
|
||||
"enable_simd",
|
||||
"Enable the use of SIMD instructions.",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_atomics",
|
||||
"Enable the use of atomic instructions",
|
||||
"",
|
||||
true,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_safepoints",
|
||||
"Enable safepoint instruction insertions.",
|
||||
r#"
|
||||
Enable safepoint instruction insertions.
|
||||
|
||||
This will allow the emit_stack_maps() function to insert the safepoint
|
||||
instruction on top of calls and interrupt traps in order to display the
|
||||
live reference values at that point in the program.
|
||||
"#,
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_enum(
|
||||
"tls_model",
|
||||
r#"
|
||||
Defines the model used to perform TLS accesses.
|
||||
"#,
|
||||
"Defines the model used to perform TLS accesses.",
|
||||
"",
|
||||
vec!["none", "elf_gd", "macho", "coff"],
|
||||
);
|
||||
|
||||
@@ -176,9 +175,9 @@ pub(crate) fn define() -> SettingGroup {
|
||||
|
||||
settings.add_enum(
|
||||
"libcall_call_conv",
|
||||
"Defines the calling convention to use for LibCalls call expansion.",
|
||||
r#"
|
||||
Defines the calling convention to use for LibCalls call expansion,
|
||||
since it may be different from the ISA default calling convention.
|
||||
This may be different from the ISA default calling convention.
|
||||
|
||||
The default value is to use the same calling convention as the ISA
|
||||
default calling convention.
|
||||
@@ -202,9 +201,8 @@ pub(crate) fn define() -> SettingGroup {
|
||||
|
||||
settings.add_num(
|
||||
"baldrdash_prologue_words",
|
||||
"Number of pointer-sized words pushed by the baldrdash prologue.",
|
||||
r#"
|
||||
Number of pointer-sized words pushed by the baldrdash prologue.
|
||||
|
||||
Functions with the `baldrdash` calling convention don't generate their
|
||||
own prologue and epilogue. They depend on externally generated code
|
||||
that pushes a fixed number of words in the prologue and restores them
|
||||
@@ -213,15 +211,14 @@ pub(crate) fn define() -> SettingGroup {
|
||||
This setting configures the number of pointer-sized words pushed on the
|
||||
stack when the Cranelift-generated code is entered. This includes the
|
||||
pushed return address on x86.
|
||||
"#,
|
||||
"#,
|
||||
0,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_llvm_abi_extensions",
|
||||
"Enable various ABI extensions defined by LLVM's behavior.",
|
||||
r#"
|
||||
Enable various ABI extensions defined by LLVM's behavior.
|
||||
|
||||
In some cases, LLVM's implementation of an ABI (calling convention)
|
||||
goes beyond a standard and supports additional argument types or
|
||||
behavior. This option instructs Cranelift codegen to follow LLVM's
|
||||
@@ -232,18 +229,18 @@ pub(crate) fn define() -> SettingGroup {
|
||||
registers. The Fastcall implementation otherwise does not support
|
||||
`i128` arguments, and will panic if they are present and this
|
||||
option is not set.
|
||||
"#,
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"unwind_info",
|
||||
"Generate unwind information.",
|
||||
r#"
|
||||
Generate unwind info. This increases metadata size and compile time,
|
||||
but allows for the debugger to trace frames, is needed for GC tracing
|
||||
that relies on libunwind (such as in Wasmtime), and is
|
||||
unconditionally needed on certain platforms (such as Windows) that
|
||||
must always be able to unwind.
|
||||
This increases metadata size and compile time, but allows for the
|
||||
debugger to trace frames, is needed for GC tracing that relies on
|
||||
libunwind (such as in Wasmtime), and is unconditionally needed on
|
||||
certain platforms (such as Windows) that must always be able to unwind.
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
@@ -253,6 +250,7 @@ pub(crate) fn define() -> SettingGroup {
|
||||
settings.add_bool(
|
||||
"emit_all_ones_funcaddrs",
|
||||
"Emit not-yet-relocated function addresses as all-ones bit patterns.",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
|
||||
@@ -260,32 +258,27 @@ pub(crate) fn define() -> SettingGroup {
|
||||
|
||||
settings.add_bool(
|
||||
"enable_probestack",
|
||||
r#"
|
||||
Enable the use of stack probes, for calling conventions which support this
|
||||
functionality.
|
||||
"#,
|
||||
"Enable the use of stack probes for supported calling conventions.",
|
||||
"",
|
||||
true,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"probestack_func_adjusts_sp",
|
||||
r#"
|
||||
Set this to true of the stack probe function modifies the stack pointer
|
||||
itself.
|
||||
"#,
|
||||
"Enable if the stack probe adjusts the stack pointer.",
|
||||
"",
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_num(
|
||||
"probestack_size_log2",
|
||||
"The log2 of the size of the stack guard region.",
|
||||
r#"
|
||||
The log2 of the size of the stack guard region.
|
||||
|
||||
Stack frames larger than this size will have stack overflow checked
|
||||
by calling the probestack function.
|
||||
|
||||
The default is 12, which translates to a size of 4096.
|
||||
"#,
|
||||
"#,
|
||||
12,
|
||||
);
|
||||
|
||||
@@ -294,6 +287,7 @@ pub(crate) fn define() -> SettingGroup {
|
||||
settings.add_bool(
|
||||
"enable_jump_tables",
|
||||
"Enable the use of jump tables in generated machine code.",
|
||||
"",
|
||||
true,
|
||||
);
|
||||
|
||||
@@ -301,16 +295,15 @@ pub(crate) fn define() -> SettingGroup {
|
||||
|
||||
settings.add_bool(
|
||||
"enable_heap_access_spectre_mitigation",
|
||||
"Enable Spectre mitigation on heap bounds checks.",
|
||||
r#"
|
||||
Enable Spectre mitigation on heap bounds checks.
|
||||
This is a no-op for any heap that needs no bounds checks; e.g.,
|
||||
if the limit is static and the guard region is large enough that
|
||||
the index cannot reach past it.
|
||||
|
||||
This is a no-op for any heap that needs no bounds checks; e.g.,
|
||||
if the limit is static and the guard region is large enough that
|
||||
the index cannot reach past it.
|
||||
|
||||
This option is enabled by default because it is highly
|
||||
recommended for secure sandboxing. The embedder should consider
|
||||
the security implications carefully before disabling this option.
|
||||
This option is enabled by default because it is highly
|
||||
recommended for secure sandboxing. The embedder should consider
|
||||
the security implications carefully before disabling this option.
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
|
||||
@@ -7,10 +7,8 @@ use crate::isa::Builder as IsaBuilder;
|
||||
use crate::machinst::{compile, MachBackend, MachCompileResult, TargetIsaAdapter, VCode};
|
||||
use crate::result::CodegenResult;
|
||||
use crate::settings as shared_settings;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::{boxed::Box, vec::Vec};
|
||||
use core::hash::{Hash, Hasher};
|
||||
|
||||
use regalloc::{PrettyPrint, RealRegUniverse};
|
||||
use target_lexicon::{Aarch64Architecture, Architecture, Triple};
|
||||
|
||||
@@ -104,6 +102,10 @@ impl MachBackend for AArch64Backend {
|
||||
&self.flags
|
||||
}
|
||||
|
||||
fn isa_flags(&self) -> Vec<shared_settings::Value> {
|
||||
self.isa_flags.iter().collect()
|
||||
}
|
||||
|
||||
fn hash_all_flags(&self, mut hasher: &mut dyn Hasher) {
|
||||
self.flags.hash(&mut hasher);
|
||||
self.isa_flags.hash(&mut hasher);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! AArch64 Settings.
|
||||
|
||||
use crate::settings::{self, detail, Builder};
|
||||
use crate::settings::{self, detail, Builder, Value};
|
||||
use core::fmt;
|
||||
|
||||
// Include code generated by `cranelift-codegen/meta/src/gen_settings.rs:`. This file contains a
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::machinst::{compile, MachBackend, MachCompileResult, TargetIsaAdapter,
|
||||
use crate::result::CodegenResult;
|
||||
use crate::settings;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::{boxed::Box, vec::Vec};
|
||||
use core::hash::{Hash, Hasher};
|
||||
use regalloc::{PrettyPrint, RealRegUniverse};
|
||||
use target_lexicon::{Architecture, ArmArchitecture, Triple};
|
||||
@@ -92,6 +92,10 @@ impl MachBackend for Arm32Backend {
|
||||
&self.flags
|
||||
}
|
||||
|
||||
fn isa_flags(&self) -> Vec<settings::Value> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn hash_all_flags(&self, mut hasher: &mut dyn Hasher) {
|
||||
self.flags.hash(&mut hasher);
|
||||
}
|
||||
|
||||
@@ -63,8 +63,7 @@ use crate::result::CodegenResult;
|
||||
use crate::settings;
|
||||
use crate::settings::SetResult;
|
||||
use crate::timing;
|
||||
use alloc::borrow::Cow;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::{borrow::Cow, boxed::Box, vec::Vec};
|
||||
use core::any::Any;
|
||||
use core::fmt;
|
||||
use core::fmt::{Debug, Formatter};
|
||||
@@ -201,6 +200,16 @@ pub struct Builder {
|
||||
}
|
||||
|
||||
impl Builder {
|
||||
/// Gets the triple for the builder.
|
||||
pub fn triple(&self) -> &Triple {
|
||||
&self.triple
|
||||
}
|
||||
|
||||
/// Iterates the available settings in the builder.
|
||||
pub fn iter(&self) -> impl Iterator<Item = settings::Setting> {
|
||||
self.setup.iter()
|
||||
}
|
||||
|
||||
/// Combine the ISA-specific settings with the provided ISA-independent settings and allocate a
|
||||
/// fully configured `TargetIsa` trait object.
|
||||
pub fn finish(self, shared_flags: settings::Flags) -> Box<dyn TargetIsa> {
|
||||
@@ -265,8 +274,10 @@ pub trait TargetIsa: fmt::Display + Send + Sync {
|
||||
/// Get the ISA-independent flags that were used to make this trait object.
|
||||
fn flags(&self) -> &settings::Flags;
|
||||
|
||||
/// Hashes all flags, both ISA-independent and ISA-specific, into the
|
||||
/// specified hasher.
|
||||
/// Get the ISA-dependent flag values that were used to make this trait object.
|
||||
fn isa_flags(&self) -> Vec<settings::Value>;
|
||||
|
||||
/// Hashes all flags, both ISA-independent and ISA-dependent, into the specified hasher.
|
||||
fn hash_all_flags(&self, hasher: &mut dyn Hasher);
|
||||
|
||||
/// Get the default calling convention of this target.
|
||||
|
||||
@@ -15,8 +15,7 @@ use crate::isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encoding
|
||||
use crate::isa::Builder as IsaBuilder;
|
||||
use crate::isa::{EncInfo, RegClass, RegInfo, TargetIsa};
|
||||
use crate::regalloc;
|
||||
use alloc::borrow::Cow;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::{borrow::Cow, boxed::Box, vec::Vec};
|
||||
use core::any::Any;
|
||||
use core::fmt;
|
||||
use core::hash::{Hash, Hasher};
|
||||
@@ -70,6 +69,10 @@ impl TargetIsa for Isa {
|
||||
&self.shared_flags
|
||||
}
|
||||
|
||||
fn isa_flags(&self) -> Vec<shared_settings::Value> {
|
||||
self.isa_flags.iter().collect()
|
||||
}
|
||||
|
||||
fn hash_all_flags(&self, mut hasher: &mut dyn Hasher) {
|
||||
self.shared_flags.hash(&mut hasher);
|
||||
self.isa_flags.hash(&mut hasher);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! RISC-V Settings.
|
||||
|
||||
use crate::settings::{self, detail, Builder};
|
||||
use crate::settings::{self, detail, Builder, Value};
|
||||
use core::fmt;
|
||||
|
||||
// Include code generated by `cranelift-codegen/meta/src/gen_settings.rs`. This file contains a
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::isa::Builder as IsaBuilder;
|
||||
use crate::machinst::{compile, MachBackend, MachCompileResult, TargetIsaAdapter, VCode};
|
||||
use crate::result::CodegenResult;
|
||||
use crate::settings::{self as shared_settings, Flags};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::{boxed::Box, vec::Vec};
|
||||
use core::hash::{Hash, Hasher};
|
||||
use regalloc::{PrettyPrint, RealRegUniverse, Reg};
|
||||
use target_lexicon::Triple;
|
||||
@@ -85,6 +85,10 @@ impl MachBackend for X64Backend {
|
||||
&self.flags
|
||||
}
|
||||
|
||||
fn isa_flags(&self) -> Vec<shared_settings::Value> {
|
||||
self.x64_flags.iter().collect()
|
||||
}
|
||||
|
||||
fn hash_all_flags(&self, mut hasher: &mut dyn Hasher) {
|
||||
self.flags.hash(&mut hasher);
|
||||
self.x64_flags.hash(&mut hasher);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! x86 Settings.
|
||||
|
||||
use crate::settings::{self, detail, Builder};
|
||||
use crate::settings::{self, detail, Builder, Value};
|
||||
use core::fmt;
|
||||
|
||||
// Include code generated by `cranelift-codegen/meta/src/gen_settings.rs:`. This file contains a
|
||||
|
||||
@@ -21,8 +21,7 @@ use crate::isa::{EncInfo, RegClass, RegInfo, TargetIsa};
|
||||
use crate::regalloc;
|
||||
use crate::result::CodegenResult;
|
||||
use crate::timing;
|
||||
use alloc::borrow::Cow;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::{borrow::Cow, boxed::Box, vec::Vec};
|
||||
use core::any::Any;
|
||||
use core::fmt;
|
||||
use core::hash::{Hash, Hasher};
|
||||
@@ -79,6 +78,10 @@ impl TargetIsa for Isa {
|
||||
&self.shared_flags
|
||||
}
|
||||
|
||||
fn isa_flags(&self) -> Vec<shared_settings::Value> {
|
||||
self.isa_flags.iter().collect()
|
||||
}
|
||||
|
||||
fn hash_all_flags(&self, mut hasher: &mut dyn Hasher) {
|
||||
self.shared_flags.hash(&mut hasher);
|
||||
self.isa_flags.hash(&mut hasher);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! x86 Settings.
|
||||
|
||||
use crate::settings::{self, detail, Builder};
|
||||
use crate::settings::{self, detail, Builder, Value};
|
||||
use core::fmt;
|
||||
|
||||
// Include code generated by `cranelift-codegen/meta/src/gen_settings.rs:`. This file contains a
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::ir;
|
||||
use crate::isa::{EncInfo, Encoding, Encodings, Legalize, RegClass, RegInfo, TargetIsa};
|
||||
use crate::machinst::*;
|
||||
use crate::regalloc::RegisterSet;
|
||||
use crate::settings::Flags;
|
||||
use crate::settings::{self, Flags};
|
||||
|
||||
#[cfg(feature = "testing_hooks")]
|
||||
use crate::regalloc::RegDiversions;
|
||||
@@ -14,7 +14,6 @@ use crate::regalloc::RegDiversions;
|
||||
use crate::isa::unwind::systemv::RegisterMappingError;
|
||||
|
||||
use core::any::Any;
|
||||
use core::hash::Hasher;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use target_lexicon::Triple;
|
||||
@@ -59,8 +58,12 @@ impl TargetIsa for TargetIsaAdapter {
|
||||
self.backend.flags()
|
||||
}
|
||||
|
||||
fn isa_flags(&self) -> Vec<settings::Value> {
|
||||
self.backend.isa_flags()
|
||||
}
|
||||
|
||||
fn hash_all_flags(&self, hasher: &mut dyn Hasher) {
|
||||
self.backend.hash_all_flags(hasher)
|
||||
self.backend.hash_all_flags(hasher);
|
||||
}
|
||||
|
||||
fn register_info(&self) -> RegInfo {
|
||||
|
||||
@@ -64,18 +64,18 @@ use crate::binemit::{CodeInfo, CodeOffset, StackMap};
|
||||
use crate::ir::condcodes::IntCC;
|
||||
use crate::ir::{Function, SourceLoc, StackSlot, Type, ValueLabel};
|
||||
use crate::result::CodegenResult;
|
||||
use crate::settings::Flags;
|
||||
use crate::settings::{self, Flags};
|
||||
use crate::value_label::ValueLabelsRanges;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::vec::Vec;
|
||||
use core::fmt::Debug;
|
||||
use core::hash::Hasher;
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use regalloc::RegUsageCollector;
|
||||
use regalloc::{
|
||||
RealReg, RealRegUniverse, Reg, RegClass, RegUsageMapper, SpillSlot, VirtualReg, Writable,
|
||||
};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::hash::Hasher;
|
||||
use std::string::String;
|
||||
use target_lexicon::Triple;
|
||||
|
||||
@@ -368,8 +368,10 @@ pub trait MachBackend {
|
||||
/// Return flags for this backend.
|
||||
fn flags(&self) -> &Flags;
|
||||
|
||||
/// Hashes all flags, both ISA-independent and ISA-specific, into the
|
||||
/// specified hasher.
|
||||
/// Get the ISA-dependent flag values that were used to make this trait object.
|
||||
fn isa_flags(&self) -> Vec<settings::Value>;
|
||||
|
||||
/// Hashes all flags, both ISA-independent and ISA-dependent, into the specified hasher.
|
||||
fn hash_all_flags(&self, hasher: &mut dyn Hasher);
|
||||
|
||||
/// Return triple for this backend.
|
||||
|
||||
@@ -44,6 +44,78 @@ pub trait Configurable {
|
||||
fn enable(&mut self, name: &str) -> SetResult<()>;
|
||||
}
|
||||
|
||||
/// Represents the kind of setting.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum SettingKind {
|
||||
/// The setting is an enumeration.
|
||||
Enum,
|
||||
/// The setting is a number.
|
||||
Num,
|
||||
/// The setting is a boolean.
|
||||
Bool,
|
||||
/// The setting is a preset.
|
||||
Preset,
|
||||
}
|
||||
|
||||
/// Represents an available builder setting.
|
||||
///
|
||||
/// This is used for iterating settings in a builder.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Setting {
|
||||
/// The name of the setting.
|
||||
pub name: &'static str,
|
||||
/// The description of the setting.
|
||||
pub description: &'static str,
|
||||
/// The kind of the setting.
|
||||
pub kind: SettingKind,
|
||||
/// The supported values of the setting (for enum values).
|
||||
pub values: Option<&'static [&'static str]>,
|
||||
}
|
||||
|
||||
/// Represents a setting value.
|
||||
///
|
||||
/// This is used for iterating values in `Flags`.
|
||||
pub struct Value {
|
||||
/// The name of the setting associated with this value.
|
||||
pub name: &'static str,
|
||||
pub(crate) detail: detail::Detail,
|
||||
pub(crate) values: Option<&'static [&'static str]>,
|
||||
pub(crate) value: u8,
|
||||
}
|
||||
|
||||
impl Value {
|
||||
/// Gets the kind of setting.
|
||||
pub fn kind(&self) -> SettingKind {
|
||||
match &self.detail {
|
||||
detail::Detail::Enum { .. } => SettingKind::Enum,
|
||||
detail::Detail::Num => SettingKind::Num,
|
||||
detail::Detail::Bool { .. } => SettingKind::Bool,
|
||||
detail::Detail::Preset => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the enum value if the value is from an enum setting.
|
||||
pub fn as_enum(&self) -> Option<&'static str> {
|
||||
self.values.map(|v| v[self.value as usize])
|
||||
}
|
||||
|
||||
/// Gets the numerical value if the value is from a num setting.
|
||||
pub fn as_num(&self) -> Option<u8> {
|
||||
match &self.detail {
|
||||
detail::Detail::Num => Some(self.value),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the boolean value if the value is from a boolean setting.
|
||||
pub fn as_bool(&self) -> Option<bool> {
|
||||
match &self.detail {
|
||||
detail::Detail::Bool { bit } => Some(self.value & (1 << bit) != 0),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect settings values based on a template.
|
||||
#[derive(Clone, Hash)]
|
||||
pub struct Builder {
|
||||
@@ -66,6 +138,30 @@ impl Builder {
|
||||
self.bytes
|
||||
}
|
||||
|
||||
/// Iterates the available settings in the builder.
|
||||
pub fn iter(&self) -> impl Iterator<Item = Setting> {
|
||||
let template = self.template;
|
||||
|
||||
template.descriptors.iter().map(move |d| {
|
||||
let (kind, values) = match d.detail {
|
||||
detail::Detail::Enum { last, enumerators } => {
|
||||
let values = template.enums(last, enumerators);
|
||||
(SettingKind::Enum, Some(values))
|
||||
}
|
||||
detail::Detail::Num => (SettingKind::Num, None),
|
||||
detail::Detail::Bool { .. } => (SettingKind::Bool, None),
|
||||
detail::Detail::Preset => (SettingKind::Preset, None),
|
||||
};
|
||||
|
||||
Setting {
|
||||
name: d.name,
|
||||
description: d.description,
|
||||
kind,
|
||||
values,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Set the value of a single bit.
|
||||
fn set_bit(&mut self, offset: usize, bit: u8, value: bool) {
|
||||
let byte = &mut self.bytes[offset];
|
||||
@@ -288,6 +384,9 @@ pub mod detail {
|
||||
/// Lower snake-case name of setting as defined in meta.
|
||||
pub name: &'static str,
|
||||
|
||||
/// The description of the setting.
|
||||
pub description: &'static str,
|
||||
|
||||
/// Offset of byte containing this setting.
|
||||
pub offset: u32,
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ smallvec = "1.6.1"
|
||||
thiserror = "1.0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
wat = "1.0.36"
|
||||
wat = "1.0.37"
|
||||
target-lexicon = "0.12"
|
||||
# Enable the riscv feature for cranelift-codegen, as some tests require it
|
||||
cranelift-codegen = { path = "../codegen", version = "0.72.0", default-features = false, features = ["riscv"] }
|
||||
|
||||
Reference in New Issue
Block a user