Skip to content

Commit 05ea71d

Browse files
authored
x64: Stringify fixed registers with their runtime value (#10815)
This commit updates the display implementation of instructions using fixed registers to use the current value of the register rather than the end-result that'll happen after register allocation. That should help ensure that if a virtual register is being used in an instruction that'll get printed instead of the fixed value that should pop out after regalloc. Disassembly shouldn't change though after register allocation because the value of the register should match the fixed encoding.
1 parent fd28db3 commit 05ea71d

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ impl dsl::Location {
4040
pub fn generate_to_string(&self, extension: dsl::Extension) -> String {
4141
use dsl::Location::*;
4242
match self {
43-
al => "\"%al\"".into(),
44-
ax => "\"%ax\"".into(),
45-
eax => "\"%eax\"".into(),
46-
rax => "\"%rax\"".into(),
47-
cl => "\"%cl\"".into(),
48-
dx => "\"%dx\"".into(),
49-
edx => "\"%edx\"".into(),
50-
rdx => "\"%rdx\"".into(),
5143
imm8 | imm16 | imm32 => {
5244
if extension.is_sign_extended() {
5345
let variant = extension.generate_variant();
@@ -56,7 +48,8 @@ impl dsl::Location {
5648
format!("self.{self}.to_string()")
5749
}
5850
}
59-
r8 | r16 | r32 | r64 | rm8 | rm16 | rm32 | rm64 => match self.generate_size() {
51+
al | ax | eax | rax | cl | dx | edx | rdx | r8 | r16 | r32 | r64 | rm8 | rm16
52+
| rm32 | rm64 => match self.generate_size() {
6053
Some(size) => format!("self.{self}.to_string({size})"),
6154
None => unreachable!(),
6255
},
@@ -71,11 +64,11 @@ impl dsl::Location {
7164
fn generate_size(&self) -> Option<&str> {
7265
use dsl::Location::*;
7366
match self {
74-
al | ax | eax | rax | cl | dx | edx | rdx | imm8 | imm16 | imm32 => None,
75-
r8 | rm8 => Some("Size::Byte"),
76-
r16 | rm16 => Some("Size::Word"),
77-
r32 | rm32 => Some("Size::Doubleword"),
78-
r64 | rm64 => Some("Size::Quadword"),
67+
imm8 | imm16 | imm32 => None,
68+
al | cl | r8 | rm8 => Some("Size::Byte"),
69+
ax | dx | r16 | rm16 => Some("Size::Word"),
70+
eax | edx | r32 | rm32 => Some("Size::Doubleword"),
71+
rax | rdx | r64 | rm64 => Some("Size::Quadword"),
7972
m8 | m16 | m32 | m64 => {
8073
panic!("no need to generate a size for memory-only access")
8174
}

cranelift/assembler-x64/src/fixed.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Operands with fixed register encodings.
22
3-
use crate::AsReg;
3+
use crate::{AsReg, Size};
44

55
/// A _fixed_ register.
66
///
@@ -33,6 +33,14 @@ impl<R, const E: u8> Fixed<R, E> {
3333
pub fn expected_enc(&self) -> u8 {
3434
E
3535
}
36+
37+
/// Return the register name at the given `size`.
38+
pub fn to_string(&self, size: Size) -> String
39+
where
40+
R: AsReg,
41+
{
42+
self.0.to_string(Some(size))
43+
}
3644
}
3745

3846
impl<R: AsReg, const E: u8> AsReg for Fixed<R, E> {

0 commit comments

Comments
 (0)