1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#[derive(Clone)]
/// Flags group `shared`.
pub struct Flags {
    bytes: [u8; 4],
}
impl Flags {
    /// Create flags shared settings group.
    #[allow(unused_variables)]
    pub fn new(builder: &Builder) -> Flags {
        let bvec = builder.state_for("shared");
        let mut bytes = [0; 4];
        debug_assert_eq!(bvec.len(), 4);
        for (i, b) in bvec.iter().enumerate() {
            bytes[i] = *b;
        }
        Flags { bytes: bytes }
    }
}
/// Values for shared.opt_level.
#[derive(Debug, PartialEq, Eq)]
pub enum OptLevel {
    /// `default`.
    Default,
    /// `best`.
    Best,
    /// `fastest`.
    Fastest,
}
/// User-defined settings.
#[allow(dead_code)]
impl Flags {
    /// Get a view of the boolean predicates.
    pub fn predicate_view(&self) -> ::settings::PredicateView {
        ::settings::PredicateView::new(&self.bytes[2..])
    }
    /// Dynamic numbered predicate getter.
    fn numbered_predicate(&self, p: usize) -> bool {
        self.bytes[2 + p / 8] & (1 << (p % 8)) != 0
    }
    /// Optimization level:
    ///
    /// - default: Very profitable optimizations enabled, none slow.
    /// - best: Enable all optimizations
    /// - fastest: Optimize for compile time by disabling most optimizations.
    pub fn opt_level(&self) -> OptLevel {
        match self.bytes[0] {
            0 => {
                OptLevel::Default
            }
            1 => {
                OptLevel::Best
            }
            2 => {
                OptLevel::Fastest
            }
            _ => {
                panic!("Invalid enum value")
            }
        }
    }
    /// Run the Cretonne IL verifier at strategic times during compilation.
    ///
    /// This makes compilation slower but catches many bugs. The verifier is
    /// disabled by default, except when reading Cretonne IL from a text file.
    pub fn enable_verifier(&self) -> bool {
        self.numbered_predicate(0)
    }
    /// Enable 64-bit code generation
    pub fn is_64bit(&self) -> bool {
        self.numbered_predicate(1)
    }
    /// Enable Position-Independent Code generation
    pub fn is_pic(&self) -> bool {
        self.numbered_predicate(2)
    }
    /// Generate functions with at most a single return instruction at the
    /// end of the function.
    ///
    /// This guarantees that functions do not have any internal return
    /// instructions. Either they never return, or they have a single return
    /// instruction at the end.
    pub fn return_at_end(&self) -> bool {
        self.numbered_predicate(3)
    }
    /// 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.
    pub fn avoid_div_traps(&self) -> bool {
        self.numbered_predicate(4)
    }
    /// Enable compressed instructions
    pub fn is_compressed(&self) -> bool {
        self.numbered_predicate(5)
    }
    /// Enable the use of floating-point instructions
    ///
    /// Disabling use of floating-point instructions is not yet implemented.
    pub fn enable_float(&self) -> bool {
        self.numbered_predicate(6)
    }
    /// Enable the use of SIMD instructions.
    pub fn enable_simd(&self) -> bool {
        self.numbered_predicate(7)
    }
    /// Enable the use of atomic instructions
    pub fn enable_atomics(&self) -> bool {
        self.numbered_predicate(8)
    }
    /// Number of pointer-sized words pushed by the spiderwasm prologue.
    ///
    /// Functions with the `spiderwasm` 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
    /// in the epilogue.
    ///
    /// This setting configures the number of pointer-sized words pushed on the
    /// stack when the Cretonne-generated code is entered. This includes the
    /// pushed return address on Intel ISAs.
    pub fn spiderwasm_prologue_words(&self) -> u8 {
        self.bytes[1]
    }
    /// Emit not-yet-relocated function addresses as all-ones bit patterns.
    pub fn allones_funcaddrs(&self) -> bool {
        self.numbered_predicate(9)
    }
}
static DESCRIPTORS: [detail::Descriptor; 12] = [
    detail::Descriptor {
        name: "opt_level",
        offset: 0,
        detail: detail::Detail::Enum { last: 2, enumerators: 0 },
    },
    detail::Descriptor {
        name: "enable_verifier",
        offset: 2,
        detail: detail::Detail::Bool { bit: 0 },
    },
    detail::Descriptor {
        name: "is_64bit",
        offset: 2,
        detail: detail::Detail::Bool { bit: 1 },
    },
    detail::Descriptor {
        name: "is_pic",
        offset: 2,
        detail: detail::Detail::Bool { bit: 2 },
    },
    detail::Descriptor {
        name: "return_at_end",
        offset: 2,
        detail: detail::Detail::Bool { bit: 3 },
    },
    detail::Descriptor {
        name: "avoid_div_traps",
        offset: 2,
        detail: detail::Detail::Bool { bit: 4 },
    },
    detail::Descriptor {
        name: "is_compressed",
        offset: 2,
        detail: detail::Detail::Bool { bit: 5 },
    },
    detail::Descriptor {
        name: "enable_float",
        offset: 2,
        detail: detail::Detail::Bool { bit: 6 },
    },
    detail::Descriptor {
        name: "enable_simd",
        offset: 2,
        detail: detail::Detail::Bool { bit: 7 },
    },
    detail::Descriptor {
        name: "enable_atomics",
        offset: 3,
        detail: detail::Detail::Bool { bit: 0 },
    },
    detail::Descriptor {
        name: "spiderwasm_prologue_words",
        offset: 1,
        detail: detail::Detail::Num,
    },
    detail::Descriptor {
        name: "allones_funcaddrs",
        offset: 3,
        detail: detail::Detail::Bool { bit: 1 },
    },
];
static ENUMERATORS: [&str; 3] = [
    "default",
    "best",
    "fastest",
];
static HASH_TABLE: [u16; 16] = [
    0xffff,
    11,
    0xffff,
    5,
    10,
    1,
    9,
    8,
    6,
    2,
    0xffff,
    0xffff,
    0,
    3,
    4,
    7,
];
static PRESETS: [(u8, u8); 0] = [
];
static TEMPLATE: detail::Template = detail::Template {
    name: "shared",
    descriptors: &DESCRIPTORS,
    enumerators: &ENUMERATORS,
    hash_table: &HASH_TABLE,
    defaults: &[0x00, 0x00, 0xc1, 0x01],
    presets: &PRESETS,
};
/// Create a `settings::Builder` for the shared settings group.
pub fn builder() -> Builder {
    Builder::new(&TEMPLATE)
}
impl fmt::Display for Flags {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        writeln!(f, "[shared]")?;
        for d in &DESCRIPTORS {
            if !d.detail.is_preset() {
                write!(f, "{} = ", d.name)?;
                TEMPLATE.format_toml_value(d.detail,self.bytes[d.offset as usize], f)?;
                writeln!(f, "")?;
            }
        }
        Ok(())
    }
}