Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ jobs:
cargo check -p wasmtime --no-default-features --features runtime,component-model &&
cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,async,debug-builtins &&
cargo check -p cranelift-control --no-default-features &&
cargo check -p cranelift-assembler-x64 --lib &&
cargo check -p pulley-interpreter --features encode,decode,disas,interp &&
cargo check -p wasmtime-wasi-io --no-default-features
# Use `cross` for illumos to have a C compiler/linker available.
Expand Down
6 changes: 3 additions & 3 deletions cranelift/assembler-x64/meta/src/dsl/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl Default for Mutability {
}

impl core::fmt::Display for Mutability {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Read => write!(f, "r"),
Self::ReadWrite => write!(f, "rw"),
Expand Down Expand Up @@ -576,7 +576,7 @@ impl Default for Extension {
}

impl core::fmt::Display for Extension {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Extension::None => write!(f, ""),
Extension::SignExtendQuad => write!(f, "sxq"),
Expand Down Expand Up @@ -627,7 +627,7 @@ impl Default for Eflags {
}

impl core::fmt::Display for Eflags {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::None => write!(f, ""),
Self::R => write!(f, "r"),
Expand Down
6 changes: 3 additions & 3 deletions cranelift/assembler-x64/meta/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ fn match_variants(f: &mut Formatter, insts: &[dsl::Inst], invoke: &str) {
});
}

/// `impl std::fmt::Display for Inst { ... }`
/// `impl core::fmt::Display for Inst { ... }`
fn generate_inst_display_impl(f: &mut Formatter, insts: &[dsl::Inst]) {
f.add_block("impl<R: Registers> std::fmt::Display for Inst<R>", |f| {
f.add_block("impl<R: Registers> core::fmt::Display for Inst<R>", |f| {
f.add_block(
"fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result",
"fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result",
|f| {
match_variants(f, insts, "fmt(f)");
},
Expand Down
8 changes: 4 additions & 4 deletions cranelift/assembler-x64/meta/src/generate/inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ impl dsl::Inst {
fmtln!(f, "#[must_use]");
fmtln!(f, "#[inline]");
f.add_block(
&format!("pub fn mnemonic(&self) -> std::borrow::Cow<'static, str>"),
&format!("pub fn mnemonic(&self) -> alloc::borrow::Cow<'static, str>"),
|f| {
if self.custom.contains(Mnemonic) {
fmtln!(f, "crate::custom::mnemonic::{}(self)", self.name());
} else {
fmtln!(f, "std::borrow::Cow::Borrowed(\"{}\")", self.mnemonic);
fmtln!(f, "alloc::borrow::Cow::Borrowed(\"{}\")", self.mnemonic);
}
},
);
Expand Down Expand Up @@ -265,10 +265,10 @@ impl dsl::Inst {
let impl_block = self.generate_impl_block_start();
let struct_name = self.struct_name_with_generic();
f.add_block(
&format!("{impl_block} std::fmt::Display for {struct_name}"),
&format!("{impl_block} core::fmt::Display for {struct_name}"),
|f| {
f.add_block(
"fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result",
"fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result",
|f| {
if self.custom.contains(Display) {
fmtln!(f, "crate::custom::display::{}(f, self)", self.name());
Expand Down
8 changes: 5 additions & 3 deletions cranelift/assembler-x64/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
use crate::gpr;
use crate::xmm;
use crate::{Amode, DeferredTarget, GprMem, XmmMem};
use std::fmt;
use std::{num::NonZeroU8, vec::Vec};
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt;
use core::num::NonZeroU8;

/// Describe how an instruction is emitted into a code buffer.
pub trait CodeSink {
Expand Down Expand Up @@ -113,7 +115,7 @@ pub trait Registers {
}

/// Describe how to interact with an external register type.
pub trait AsReg: Copy + Clone + std::fmt::Debug + PartialEq {
pub trait AsReg: Copy + Clone + core::fmt::Debug + PartialEq {
/// Create a register from its hardware encoding.
///
/// This is primarily useful for fuzzing, though it is also useful for
Expand Down
5 changes: 3 additions & 2 deletions cranelift/assembler-x64/src/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub mod encode {
pub mod mnemonic {
use crate::inst;
use crate::{Registers, XmmMem};
use std::borrow::Cow;
use alloc::borrow::Cow;

macro_rules! lock {
($name:tt => $mnemonic:expr) => {
Expand Down Expand Up @@ -191,7 +191,8 @@ pub mod mnemonic {
pub mod display {
use crate::inst;
use crate::{Amode, Gpr, GprMem, Registers, Size};
use std::fmt;
use alloc::string::ToString;
use core::fmt;

pub fn callq_d(f: &mut fmt::Formatter, inst: &inst::callq_d) -> fmt::Result {
let inst::callq_d { imm32 } = inst;
Expand Down
2 changes: 1 addition & 1 deletion cranelift/assembler-x64/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
//! [`Inst::features`]: crate::inst::Inst::features

use crate::inst::for_each_feature;
use std::fmt;
use core::fmt;

// Helpfully generate `enum Feature`.
macro_rules! create_feature_enum {
Expand Down
1 change: 1 addition & 0 deletions cranelift/assembler-x64/src/fixed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Operands with fixed register encodings.

use crate::{AsReg, Size};
use alloc::string::String;

/// A _fixed_ register.
///
Expand Down
10 changes: 7 additions & 3 deletions cranelift/assembler-x64/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
//! throughout this crate to avoid depending on the `arbitrary` crate
//! unconditionally (use the `fuzz` feature instead).

use std::string::{String, ToString};
use std::vec::Vec;
use std::{format, println};

use crate::{
AmodeOffset, AmodeOffsetPlusKnownOffset, AsReg, CodeSink, DeferredTarget, Fixed, Gpr, Inst,
KnownOffset, NonRspGpr, Registers, TrapCode, Xmm,
Expand Down Expand Up @@ -146,7 +150,7 @@ fn disassemble(assembled: &[u8], original: &Inst<FuzzRegs>) -> String {
}

fn pretty_print_hexadecimal(hex: &[u8]) -> String {
use std::fmt::Write;
use core::fmt::Write;
let mut s = String::with_capacity(hex.len() * 2);
for b in hex {
write!(&mut s, "{b:02X}").unwrap();
Expand Down Expand Up @@ -183,7 +187,7 @@ macro_rules! hex_print_signed_imm {
/// - print negative values as `-0x...` (signed hex) instead of `0xff...`
/// (normal hex)
/// - print `mov` immediates as base-10 instead of base-16 (?!).
fn replace_signed_immediates(dis: &str) -> std::borrow::Cow<'_, str> {
fn replace_signed_immediates(dis: &str) -> alloc::borrow::Cow<'_, str> {
match dis.find('$') {
None => dis.into(),
Some(idx) => {
Expand Down Expand Up @@ -259,7 +263,7 @@ fn remove_after_parenthesis_test() {
}

/// Run some post-processing on the disassembly to make it match Capstone.
fn fix_up(dis: &str) -> std::borrow::Cow<'_, str> {
fn fix_up(dis: &str) -> alloc::borrow::Cow<'_, str> {
let dis = remove_after_semicolon(dis);
replace_signed_immediates(&dis)
}
Expand Down
1 change: 1 addition & 0 deletions cranelift/assembler-x64/src/gpr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Pure register operands; see [`Gpr`].

use crate::AsReg;
use alloc::string::String;

/// A general purpose x64 register (e.g., `%rax`).
///
Expand Down
11 changes: 6 additions & 5 deletions cranelift/assembler-x64/src/imm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Immediate operands to instructions.

use crate::api::CodeSink;
use std::fmt;
use alloc::{format, string::String};
use core::fmt;

/// This helper function prints the unsigned hexadecimal representation of the
/// immediate value: e.g., this prints `$0xfe` to represent both the signed `-2`
Expand Down Expand Up @@ -49,7 +50,7 @@ impl From<u8> for Imm8 {
}

impl TryFrom<i32> for Imm8 {
type Error = std::num::TryFromIntError;
type Error = core::num::TryFromIntError;
fn try_from(simm32: i32) -> Result<Self, Self::Error> {
Ok(Self(u8::try_from(simm32)?))
}
Expand Down Expand Up @@ -100,7 +101,7 @@ impl From<i8> for Simm8 {
}

impl TryFrom<i32> for Simm8 {
type Error = std::num::TryFromIntError;
type Error = core::num::TryFromIntError;
fn try_from(simm32: i32) -> Result<Self, Self::Error> {
Ok(Self(i8::try_from(simm32)?))
}
Expand Down Expand Up @@ -134,7 +135,7 @@ impl From<u16> for Imm16 {
}

impl TryFrom<i32> for Imm16 {
type Error = std::num::TryFromIntError;
type Error = core::num::TryFromIntError;
fn try_from(simm32: i32) -> Result<Self, Self::Error> {
Ok(Self(u16::try_from(simm32)?))
}
Expand Down Expand Up @@ -185,7 +186,7 @@ impl From<i16> for Simm16 {
}

impl TryFrom<i32> for Simm16 {
type Error = std::num::TryFromIntError;
type Error = core::num::TryFromIntError;
fn try_from(simm32: i32) -> Result<Self, Self::Error> {
Ok(Self(i16::try_from(simm32)?))
}
Expand Down
2 changes: 2 additions & 0 deletions cranelift/assembler-x64/src/inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::rex::RexPrefix;
use crate::vex::VexPrefix;
use crate::xmm::{self, Xmm};

use alloc::string::ToString;

// Include code generated by the `meta` crate.
include!(concat!(env!("OUT_DIR"), "/assembler.rs"));

Expand Down
4 changes: 4 additions & 0 deletions cranelift/assembler-x64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
non_camel_case_types,
reason = "all of the generated struct names use snake case"
)]
#![no_std]
extern crate alloc;
#[cfg(any(test, feature = "fuzz"))]
extern crate std;

mod api;
mod custom;
Expand Down
1 change: 0 additions & 1 deletion cranelift/assembler-x64/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Print the path to the generated code.

fn main() {
let paths: Vec<std::path::PathBuf> = include!(concat!(env!("OUT_DIR"), "/generated-files.rs"));
for path in paths {
Expand Down
18 changes: 10 additions & 8 deletions cranelift/assembler-x64/src/mem.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Memory operands to instructions.

use alloc::string::{String, ToString};

use crate::api::{AsReg, CodeSink, Constant, KnownOffset, Label, TrapCode};
use crate::gpr::{self, NonRspGpr, Size};
use crate::rex::{Disp, RexPrefix, encode_modrm, encode_sib};
Expand Down Expand Up @@ -99,8 +101,8 @@ impl From<i32> for AmodeOffset {
}
}

impl std::fmt::LowerHex for AmodeOffset {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::LowerHex for AmodeOffset {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
// This rather complex implementation is necessary to match how
// `capstone` pretty-prints memory immediates.
if self.0 == 0 {
Expand All @@ -116,7 +118,7 @@ impl std::fmt::LowerHex for AmodeOffset {
Some(i) => i,
None => -2_147_483_648,
};
std::fmt::LowerHex::fmt(&abs, f)
core::fmt::LowerHex::fmt(&abs, f)
}
}

Expand Down Expand Up @@ -154,12 +156,12 @@ impl AmodeOffsetPlusKnownOffset {
}
}

impl std::fmt::LowerHex for AmodeOffsetPlusKnownOffset {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::LowerHex for AmodeOffsetPlusKnownOffset {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
if let Some(offset) = self.offset {
write!(f, "<offset:{offset}>+")?;
}
std::fmt::LowerHex::fmt(&self.simm32, f)
core::fmt::LowerHex::fmt(&self.simm32, f)
}
}

Expand All @@ -172,8 +174,8 @@ pub enum DeferredTarget {
None,
}

impl<R: AsReg> std::fmt::Display for Amode<R> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl<R: AsReg> core::fmt::Display for Amode<R> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let pointer_width = Size::Quadword;
match self {
Amode::ImmReg { simm32, base, .. } => {
Expand Down
2 changes: 2 additions & 0 deletions cranelift/assembler-x64/src/xmm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use crate::{AsReg, CodeSink, rex::encode_modrm};

use alloc::string::String;

/// An x64 SSE register (e.g., `%xmm0`).
#[derive(Clone, Copy, Debug)]
pub struct Xmm<R: AsReg = u8>(pub(crate) R);
Expand Down