wasmer_compiler_singlepass/
location.rs

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