Skip to content

Commit 0502ab1

Browse files
committed
cranelift-assembler-x64: no_std support
1 parent bbd12e9 commit 0502ab1

File tree

17 files changed

+62
-33
lines changed

17 files changed

+62
-33
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ jobs:
550550
cargo check -p wasmtime --no-default-features --features runtime,component-model &&
551551
cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,async,debug-builtins &&
552552
cargo check -p cranelift-control --no-default-features &&
553+
cargo check -p cranelift-assembler-x64 --no-default-features -F core &&
553554
cargo check -p pulley-interpreter --features encode,decode,disas,interp &&
554555
cargo check -p wasmtime-wasi-io --no-default-features
555556
# Use `cross` for illumos to have a C compiler/linker available.

cranelift/assembler-x64/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ workspace = true
2323

2424
[features]
2525
fuzz = ['dep:arbitrary', 'dep:capstone']
26+
core = []

cranelift/assembler-x64/meta/src/dsl/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl Default for Mutability {
535535
}
536536

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

578578
impl core::fmt::Display for Extension {
579-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
579+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
580580
match self {
581581
Extension::None => write!(f, ""),
582582
Extension::SignExtendQuad => write!(f, "sxq"),
@@ -627,7 +627,7 @@ impl Default for Eflags {
627627
}
628628

629629
impl core::fmt::Display for Eflags {
630-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
630+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
631631
match self {
632632
Self::None => write!(f, ""),
633633
Self::R => write!(f, "r"),

cranelift/assembler-x64/meta/src/generate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ fn match_variants(f: &mut Formatter, insts: &[dsl::Inst], invoke: &str) {
5353
});
5454
}
5555

56-
/// `impl std::fmt::Display for Inst { ... }`
56+
/// `impl core::fmt::Display for Inst { ... }`
5757
fn generate_inst_display_impl(f: &mut Formatter, insts: &[dsl::Inst]) {
58-
f.add_block("impl<R: Registers> std::fmt::Display for Inst<R>", |f| {
58+
f.add_block("impl<R: Registers> core::fmt::Display for Inst<R>", |f| {
5959
f.add_block(
60-
"fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result",
60+
"fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result",
6161
|f| {
6262
match_variants(f, insts, "fmt(f)");
6363
},

cranelift/assembler-x64/meta/src/generate/inst.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ impl dsl::Inst {
107107
fmtln!(f, "#[must_use]");
108108
fmtln!(f, "#[inline]");
109109
f.add_block(
110-
&format!("pub fn mnemonic(&self) -> std::borrow::Cow<'static, str>"),
110+
&format!("pub fn mnemonic(&self) -> alloc::borrow::Cow<'static, str>"),
111111
|f| {
112112
if self.custom.contains(Mnemonic) {
113113
fmtln!(f, "crate::custom::mnemonic::{}(self)", self.name());
114114
} else {
115-
fmtln!(f, "std::borrow::Cow::Borrowed(\"{}\")", self.mnemonic);
115+
fmtln!(f, "alloc::borrow::Cow::Borrowed(\"{}\")", self.mnemonic);
116116
}
117117
},
118118
);
@@ -265,10 +265,10 @@ impl dsl::Inst {
265265
let impl_block = self.generate_impl_block_start();
266266
let struct_name = self.struct_name_with_generic();
267267
f.add_block(
268-
&format!("{impl_block} std::fmt::Display for {struct_name}"),
268+
&format!("{impl_block} core::fmt::Display for {struct_name}"),
269269
|f| {
270270
f.add_block(
271-
"fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result",
271+
"fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result",
272272
|f| {
273273
if self.custom.contains(Display) {
274274
fmtln!(f, "crate::custom::display::{}(f, self)", self.name());

cranelift/assembler-x64/src/api.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
use crate::gpr;
44
use crate::xmm;
55
use crate::{Amode, DeferredTarget, GprMem, XmmMem};
6-
use std::fmt;
7-
use std::{num::NonZeroU8, vec::Vec};
8-
6+
use alloc::vec::Vec;
7+
use core::fmt;
8+
use core::num::NonZeroU8;
9+
use alloc::string::String;
910
/// Describe how an instruction is emitted into a code buffer.
1011
pub trait CodeSink {
1112
/// Add 1 byte to the code section.
@@ -113,7 +114,7 @@ pub trait Registers {
113114
}
114115

115116
/// Describe how to interact with an external register type.
116-
pub trait AsReg: Copy + Clone + std::fmt::Debug + PartialEq {
117+
pub trait AsReg: Copy + Clone + core::fmt::Debug + PartialEq {
117118
/// Create a register from its hardware encoding.
118119
///
119120
/// This is primarily useful for fuzzing, though it is also useful for

cranelift/assembler-x64/src/custom.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub mod encode {
7575
pub mod mnemonic {
7676
use crate::inst;
7777
use crate::{Registers, XmmMem};
78-
use std::borrow::Cow;
78+
use alloc::borrow::Cow;
7979

8080
macro_rules! lock {
8181
($name:tt => $mnemonic:expr) => {
@@ -191,7 +191,8 @@ pub mod mnemonic {
191191
pub mod display {
192192
use crate::inst;
193193
use crate::{Amode, Gpr, GprMem, Registers, Size};
194-
use std::fmt;
194+
use core::fmt;
195+
use alloc::string::ToString;
195196

196197
pub fn callq_d(f: &mut fmt::Formatter, inst: &inst::callq_d) -> fmt::Result {
197198
let inst::callq_d { imm32 } = inst;

cranelift/assembler-x64/src/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//! [`Inst::features`]: crate::inst::Inst::features
3333
3434
use crate::inst::for_each_feature;
35-
use std::fmt;
35+
use core::fmt;
3636

3737
// Helpfully generate `enum Feature`.
3838
macro_rules! create_feature_enum {

cranelift/assembler-x64/src/fixed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Operands with fixed register encodings.
22
33
use crate::{AsReg, Size};
4+
use alloc::string::String;
45

56
/// A _fixed_ register.
67
///

cranelift/assembler-x64/src/fuzz.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn disassemble(assembled: &[u8], original: &Inst<FuzzRegs>) -> String {
146146
}
147147

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

261261
/// Run some post-processing on the disassembly to make it match Capstone.
262-
fn fix_up(dis: &str) -> std::borrow::Cow<'_, str> {
262+
fn fix_up(dis: &str) -> alloc::borrow::Cow<'_, str> {
263263
let dis = remove_after_semicolon(dis);
264264
replace_signed_immediates(&dis)
265265
}

0 commit comments

Comments
 (0)