wasmer_compiler_singlepass/
location.rs1use crate::common_decl::RegisterIndex;
2use crate::machine::*;
3use std::fmt::Debug;
4use std::hash::Hash;
5use std::slice::Iter;
6
7#[allow(dead_code)]
8#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
9pub enum Multiplier {
10 Zero = 0,
11 One = 1,
12 Two = 2,
13 Four = 4,
14 Height = 8,
15}
16
17#[allow(dead_code, clippy::upper_case_acronyms)]
18#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
19pub enum Location<R, S> {
20 GPR(R),
21 SIMD(S),
22 Memory(R, i32),
23 Memory2(R, R, Multiplier, i32), Imm8(u8),
25 Imm32(u32),
26 Imm64(u64),
27 None,
28}
29
30impl<R, S> MaybeImmediate for Location<R, S> {
31 fn imm_value(&self) -> Option<Value> {
32 match *self {
33 Location::Imm8(imm) => Some(Value::I8(imm as i8)),
34 Location::Imm32(imm) => Some(Value::I32(imm as i32)),
35 Location::Imm64(imm) => Some(Value::I64(imm as i64)),
36 _ => None,
37 }
38 }
39}
40
41#[allow(unused)]
42pub trait Reg: Copy + Clone + Eq + PartialEq + Debug + Hash + Ord {
43 fn is_callee_save(self) -> bool;
44 fn is_reserved(self) -> bool;
45 fn into_index(self) -> usize;
46 fn from_index(i: usize) -> Result<Self, ()>;
47 fn iterator() -> Iter<'static, Self>;
48
49 #[cfg(feature = "unwind")]
50 fn to_dwarf(self) -> gimli::Register;
51}
52
53#[allow(unused)]
54pub trait Descriptor<R: Reg, S: Reg> {
55 const FP: R;
56 const VMCTX: R;
57 const GPR_COUNT: usize;
58 const SIMD_COUNT: usize;
59 const WORD_SIZE: usize;
60 const STACK_GROWS_DOWN: bool;
61 const FP_STACK_ARG_OFFSET: i32;
62 const ARG_REG_COUNT: usize;
63 fn callee_save_gprs() -> Vec<R>;
64 fn caller_save_gprs() -> Vec<R>;
65 fn callee_save_simd() -> Vec<S>;
66 fn caller_save_simd() -> Vec<S>;
67 fn callee_param_location(n: usize) -> Location<R, S>;
68 fn caller_arg_location(n: usize) -> Location<R, S>;
69 fn return_location() -> Location<R, S>;
70}
71
72#[allow(unused)]
73pub trait CombinedRegister: Copy + Clone + Eq + PartialEq + Debug {
74 fn to_index(&self) -> RegisterIndex;
76 fn from_gpr(x: u16) -> Self;
78 fn from_simd(x: u16) -> Self;
80}