mirror of
https://github.com/mii443/wasmer.git
synced 2025-09-03 16:09:20 +00:00
Abstraction for CombinedRegister
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
use crate::address_map::get_function_address_map;
|
||||
use crate::{
|
||||
common_decl::*, config::Singlepass, emitter_x64::*, machine_x64::Machine, x64_decl::*,
|
||||
common_decl::*, config::Singlepass, emitter_x64::*, location::CombinedRegister,
|
||||
machine_x64::Machine, x64_decl::*,
|
||||
};
|
||||
use dynasmrt::{x64::Assembler, DynamicLabel};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::common_decl::RegisterIndex;
|
||||
use crate::machine::*;
|
||||
use std::fmt::Debug;
|
||||
|
||||
@ -59,3 +60,15 @@ pub trait Descriptor<R: Reg, S: Reg> {
|
||||
fn caller_arg_location(n: usize) -> Location<R, S>;
|
||||
fn return_location() -> Location<R, S>;
|
||||
}
|
||||
|
||||
pub trait CombinedRegister: Copy + Clone + Eq + PartialEq + Debug {
|
||||
/// Returns the index of the register.
|
||||
fn to_index(&self) -> RegisterIndex;
|
||||
/// Converts a DWARF regnum to CombinedRegister.
|
||||
fn _from_dwarf_regnum(x: u16) -> Option<Self>;
|
||||
/// Returns the instruction prefix for move to stack
|
||||
/// for example `movq %this_reg, ?(%rsp)` on x86_64
|
||||
/// To build an instruction, append the memory location as a 32-bit
|
||||
/// offset to the stack pointer to this prefix.
|
||||
fn _prefix_mov_to_stack(&self) -> Option<&'static [u8]>;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::common_decl::*;
|
||||
use crate::emitter_x64::*;
|
||||
use crate::location::CombinedRegister;
|
||||
use crate::x64_decl::{new_machine_state, X64Register};
|
||||
use smallvec::smallvec;
|
||||
use smallvec::SmallVec;
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! X64 structures.
|
||||
|
||||
use crate::common_decl::{MachineState, MachineValue, RegisterIndex};
|
||||
use crate::location::CombinedRegister;
|
||||
use crate::location::Reg as AbstractReg;
|
||||
use std::collections::BTreeMap;
|
||||
use wasmer_compiler::CallingConvention;
|
||||
@ -140,9 +141,9 @@ pub enum X64Register {
|
||||
XMM(XMM),
|
||||
}
|
||||
|
||||
impl X64Register {
|
||||
impl CombinedRegister for X64Register {
|
||||
/// Returns the index of the register.
|
||||
pub fn to_index(&self) -> RegisterIndex {
|
||||
fn to_index(&self) -> RegisterIndex {
|
||||
match *self {
|
||||
X64Register::GPR(x) => RegisterIndex(x as usize),
|
||||
X64Register::XMM(x) => RegisterIndex(x as usize + 16),
|
||||
@ -150,7 +151,7 @@ impl X64Register {
|
||||
}
|
||||
|
||||
/// Converts a DWARF regnum to X64Register.
|
||||
pub fn _from_dwarf_regnum(x: u16) -> Option<X64Register> {
|
||||
fn _from_dwarf_regnum(x: u16) -> Option<X64Register> {
|
||||
Some(match x {
|
||||
0..=15 => X64Register::GPR(GPR::from_index(x as usize).unwrap()),
|
||||
17..=24 => X64Register::XMM(XMM::from_index(x as usize - 17).unwrap()),
|
||||
@ -162,7 +163,7 @@ impl X64Register {
|
||||
///
|
||||
/// To build an instruction, append the memory location as a 32-bit
|
||||
/// offset to the stack pointer to this prefix.
|
||||
pub fn _prefix_mov_to_stack(&self) -> Option<&'static [u8]> {
|
||||
fn _prefix_mov_to_stack(&self) -> Option<&'static [u8]> {
|
||||
Some(match *self {
|
||||
X64Register::GPR(gpr) => match gpr {
|
||||
GPR::RDI => &[0x48, 0x89, 0xbc, 0x24],
|
||||
|
Reference in New Issue
Block a user