Skip to content

Commit fd6bbf7

Browse files
committed
asm: refactor format constructors with expanding structs
1 parent 2fd4791 commit fd6bbf7

File tree

1 file changed

+11
-21
lines changed
  • cranelift/assembler-x64/meta/src/dsl

1 file changed

+11
-21
lines changed

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

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ pub fn fmt(
3434
/// This function panics if the location is an immediate (i.e., an immediate
3535
/// cannot be written to).
3636
#[must_use]
37-
pub fn rw(location: Location) -> Operand {
38-
assert!(!matches!(location.kind(), OperandKind::Imm(_)));
37+
pub fn rw(op: impl Into<Operand>) -> Operand {
38+
let op = op.into();
39+
assert!(!matches!(op.location.kind(), OperandKind::Imm(_)));
3940
Operand {
40-
location,
4141
mutability: Mutability::ReadWrite,
42-
extension: Extension::default(),
43-
align: false,
42+
..op
4443
}
4544
}
4645

@@ -54,23 +53,20 @@ pub fn r(op: impl Into<Operand>) -> Operand {
5453

5554
/// An abbreviated constructor for a "write" operand.
5655
#[must_use]
57-
pub fn w(location: Location) -> Operand {
56+
pub fn w(op: impl Into<Operand>) -> Operand {
57+
let op = op.into();
5858
Operand {
59-
location,
6059
mutability: Mutability::Write,
61-
extension: Extension::None,
62-
align: false,
60+
..op
6361
}
6462
}
6563

6664
/// An abbreviated constructor for a memory operand that requires alignment.
6765
pub fn align(location: Location) -> Operand {
6866
assert!(location.uses_memory());
6967
Operand {
70-
location,
71-
mutability: Mutability::Read,
72-
extension: Extension::None,
7368
align: true,
69+
..Operand::from(location)
7470
}
7571
}
7672

@@ -84,10 +80,8 @@ pub fn align(location: Location) -> Operand {
8480
pub fn sxq(location: Location) -> Operand {
8581
assert!(location.bits() <= 64);
8682
Operand {
87-
location,
88-
mutability: Mutability::Read,
8983
extension: Extension::SignExtendQuad,
90-
align: false,
84+
..Operand::from(location)
9185
}
9286
}
9387

@@ -101,10 +95,8 @@ pub fn sxq(location: Location) -> Operand {
10195
pub fn sxl(location: Location) -> Operand {
10296
assert!(location.bits() <= 32);
10397
Operand {
104-
location,
105-
mutability: Mutability::Read,
10698
extension: Extension::SignExtendLong,
107-
align: false,
99+
..Operand::from(location)
108100
}
109101
}
110102

@@ -118,10 +110,8 @@ pub fn sxl(location: Location) -> Operand {
118110
pub fn sxw(location: Location) -> Operand {
119111
assert!(location.bits() <= 16);
120112
Operand {
121-
location,
122-
mutability: Mutability::Read,
123113
extension: Extension::SignExtendWord,
124-
align: false,
114+
..Operand::from(location)
125115
}
126116
}
127117

0 commit comments

Comments
 (0)