1use super::consts::config::ConfigInstructions;
4
5#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
11pub struct Config {
12 pub global: ConfigGlobal,
17 pub instructions: ConfigInstructions,
19}
20
21impl Config {
22 pub fn new() -> Self {
24 Self::default()
25 }
26}
27
28#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
30pub struct ConfigGlobal {
31 pub syntax: FormatSyntaxGlobal,
33 pub aliases: FormatAliasGlobal,
35}
36
37impl ConfigGlobal {
38 pub fn new() -> Self {
40 Self::default()
41 }
42}
43
44#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
46pub struct ConfigInstruction<A> {
47 pub syntax: FormatSyntax,
49 pub aliases: Option<FormatAliasInstruction<A>>,
53}
54
55impl<A> ConfigInstruction<A> {
56 pub fn new() -> Self {
57 Self::default()
58 }
59}
60
61impl<A> Default for ConfigInstruction<A> {
62 fn default() -> Self {
63 Self {
64 syntax: FormatSyntax::default(),
65 aliases: None,
66 }
67 }
68}
69
70pub trait HasConfigInstruction {
72 fn syntax(&self) -> &FormatSyntax;
73}
74
75impl<A> HasConfigInstruction for ConfigInstruction<A> {
76 fn syntax(&self) -> &FormatSyntax {
77 &self.syntax
78 }
79}
80
81#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
89pub enum FormatAliasGlobal {
90 Never,
92 #[default]
94 Recommended,
95 Always,
97}
98
99#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
103pub enum FormatAliasInstruction<A> {
104 Never,
106 #[default]
108 Recommended,
109 Preferred(A),
111 Always(A),
113}
114
115#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
121pub enum FormatInteger {
122 #[default]
124 DecimalSigned,
125 DecimalUnsigned,
127 HexadecimalSigned,
129 HexadecimalUnsigned,
131}
132
133#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
135pub struct FormatSyntaxGlobal {
136 pub omit_src_dst_same_reg: bool,
141 pub omit_src_dst_diff_reg: bool,
146 pub omit_deref_null_const: bool,
150 pub positive_integer_format: FormatInteger,
152 pub negative_integer_format: FormatInteger,
154}
155
156#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
158pub struct FormatSyntax {
159 pub omit_src_dst_same_reg: Option<bool>,
166 pub omit_src_dst_diff_reg: Option<bool>,
173 pub omit_deref_null_const: Option<bool>,
179 pub positive_integer_format: Option<FormatInteger>,
183 pub negative_integer_format: Option<FormatInteger>,
187}
188
189impl FormatSyntax {
190 pub fn new() -> Self {
191 Self::default()
192 }
193
194 pub fn get_omit_src_dst_same_reg(&self, global: &FormatSyntaxGlobal) -> bool {
195 if let Some(value) = self.omit_src_dst_same_reg {
196 return value;
197 }
198 global.omit_src_dst_same_reg
199 }
200
201 pub fn get_omit_src_dst_diff_reg(&self, global: &FormatSyntaxGlobal) -> bool {
202 if let Some(value) = self.omit_src_dst_diff_reg {
203 return value;
204 }
205 global.omit_src_dst_diff_reg
206 }
207
208 pub fn get_positive_integer_format(&self, global: &FormatSyntaxGlobal) -> FormatInteger {
209 if let Some(value) = self.positive_integer_format {
210 return value;
211 }
212 global.positive_integer_format
213 }
214
215 pub fn get_negative_integer_format(&self, global: &FormatSyntaxGlobal) -> FormatInteger {
216 if let Some(value) = self.negative_integer_format {
217 return value;
218 }
219 global.negative_integer_format
220 }
221}
222
223pub struct ConfigLLVM {}
229
230impl ConfigLLVM {
231 pub fn new() -> Config {
233 let mut config = Config::default();
234
235 config.global.syntax.omit_src_dst_same_reg = true;
238 config.global.syntax.omit_src_dst_diff_reg = false;
239 config.global.syntax.omit_deref_null_const = true;
240
241 config
244 .instructions
245 .and_32_log_imm
246 .syntax
247 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
248 config
249 .instructions
250 .and_32_log_imm
251 .syntax
252 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
253 config
254 .instructions
255 .and_64_log_imm
256 .syntax
257 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
258 config
259 .instructions
260 .and_64_log_imm
261 .syntax
262 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
263 config
264 .instructions
265 .ands_32s_log_imm
266 .syntax
267 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
268 config
269 .instructions
270 .ands_32s_log_imm
271 .syntax
272 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
273 config
274 .instructions
275 .ands_64s_log_imm
276 .syntax
277 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
278 config
279 .instructions
280 .ands_64s_log_imm
281 .syntax
282 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
283 config
284 .instructions
285 .eor_32_log_imm
286 .syntax
287 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
288 config
289 .instructions
290 .eor_32_log_imm
291 .syntax
292 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
293 config
294 .instructions
295 .eor_64_log_imm
296 .syntax
297 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
298 config
299 .instructions
300 .eor_64_log_imm
301 .syntax
302 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
303 config
304 .instructions
305 .orr_32_log_imm
306 .syntax
307 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
308 config
309 .instructions
310 .orr_32_log_imm
311 .syntax
312 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
313 config
314 .instructions
315 .orr_64_log_imm
316 .syntax
317 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
318 config
319 .instructions
320 .orr_64_log_imm
321 .syntax
322 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
323 config
324 .instructions
325 .tst_ands_32s_log_imm
326 .syntax
327 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
328 config
329 .instructions
330 .tst_ands_32s_log_imm
331 .syntax
332 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
333 config
334 .instructions
335 .tst_ands_64s_log_imm
336 .syntax
337 .positive_integer_format = Some(FormatInteger::HexadecimalUnsigned);
338 config
339 .instructions
340 .tst_ands_64s_log_imm
341 .syntax
342 .negative_integer_format = Some(FormatInteger::HexadecimalUnsigned);
343
344 config.instructions.ldtadd_32_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
347 config.instructions.ldtadd_64_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
348 config.instructions.ldtaddl_32_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
349 config.instructions.ldtaddl_64_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
350 config.instructions.ldtclr_32_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
351 config.instructions.ldtclr_64_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
352 config.instructions.ldtclrl_32_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
353 config.instructions.ldtclrl_64_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
354 config.instructions.ldtset_32_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
355 config.instructions.ldtset_64_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
356 config.instructions.ldtsetl_32_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
357 config.instructions.ldtsetl_64_memop_unpriv.aliases = Some(FormatAliasInstruction::Never);
358 config.instructions.subps_64s_dp_2src.aliases = Some(FormatAliasInstruction::Never);
359
360 config
361 }
362}