wasmer_compiler_singlepass/
location.rs1use 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), 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 fn imm_value_scalar(&self) -> Option<i64> {
40 match *self {
41 Location::Imm8(imm) => Some(imm as _),
42 Location::Imm32(imm) => Some(imm as _),
43 Location::Imm64(imm) => Some(imm as _),
44 _ => None,
45 }
46 }
47}
48
49#[allow(unused)]
50pub trait Reg: Copy + Clone + Eq + PartialEq + Debug + Hash + Ord {
51 fn into_index(self) -> usize;
52 fn from_index(i: usize) -> Result<Self, ()>;
53 fn iterator() -> Iter<'static, Self>;
54
55 #[cfg(feature = "unwind")]
56 fn to_dwarf(self) -> gimli::Register;
57}
58
59#[allow(unused)]
60pub trait Descriptor<R: Reg, S: Reg> {
61 const FP: R;
62 const VMCTX: R;
63 const GPR_COUNT: usize;
64 const SIMD_COUNT: usize;
65 const WORD_SIZE: usize;
66 const STACK_GROWS_DOWN: bool;
67 const FP_STACK_ARG_OFFSET: i32;
68 const ARG_REG_COUNT: usize;
69 fn callee_save_gprs() -> Vec<R>;
70 fn caller_save_gprs() -> Vec<R>;
71 fn callee_save_simd() -> Vec<S>;
72 fn caller_save_simd() -> Vec<S>;
73 fn callee_param_location(n: usize) -> Location<R, S>;
74 fn caller_arg_location(n: usize) -> Location<R, S>;
75 fn return_location() -> Location<R, S>;
76}
77
78#[allow(unused)]
79pub trait CombinedRegister: Copy + Clone + Eq + PartialEq + Debug {
80 fn from_gpr(x: u16) -> Self;
82 fn from_simd(x: u16) -> Self;
84}