assembler/mnemonic_parameter_types/memory_offsets/
MemoryOffset64Bit.rs

1// This file is part of assembler. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/assembler/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2018 The developers of assembler. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/assembler/master/COPYRIGHT.
3
4
5/// 64-bit memory offset.
6#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub enum MemoryOffset64Bit
8{
9	/// `segment:offset` form.
10	///
11	/// Segment register is ignored in 64-bit long mode.
12	SegmentOffsetForm64(SegmentRegister, Immediate64Bit),
13
14	/// `offset` form.
15	OffsetForm64(Immediate64Bit),
16}
17
18impl Default for MemoryOffset64Bit
19{
20	#[inline(always)]
21	fn default() -> Self
22	{
23		MemoryOffset64Bit::OffsetForm64(Immediate64Bit::default())
24	}
25}
26
27impl AsDisplacement for MemoryOffset64Bit
28{
29	type D = u64;
30	
31	#[inline(always)]
32	fn displacement(self) -> Self::D
33	{
34		self.get_offset().displacement()
35	}
36}
37
38impl From<(SegmentRegister, Immediate64Bit)> for MemoryOffset64Bit
39{
40	#[inline(always)]
41	fn from(value: (SegmentRegister, Immediate64Bit)) -> Self
42	{
43		MemoryOffset64Bit::SegmentOffsetForm64(value.0, value.1)
44	}
45}
46
47impl From<(Option<SegmentRegister>, Immediate64Bit)> for MemoryOffset64Bit
48{
49	#[inline(always)]
50	fn from(value: (Option<SegmentRegister>, Immediate64Bit)) -> Self
51	{
52		use self::MemoryOffset64Bit::*;
53		
54		match value.0
55		{
56			Some(segment_register) => SegmentOffsetForm64(segment_register, value.1),
57			None => OffsetForm64(value.1),
58		}
59	}
60}
61
62impl From<Immediate64Bit> for MemoryOffset64Bit
63{
64	#[inline(always)]
65	fn from(value: Immediate64Bit) -> Self
66	{
67		MemoryOffset64Bit::OffsetForm64(value)
68	}
69}
70
71impl From<i8> for MemoryOffset64Bit
72{
73	#[inline(always)]
74	fn from(value: i8) -> Self
75	{
76		MemoryOffset64Bit::OffsetForm64(value.into())
77	}
78}
79
80impl From<u8> for MemoryOffset64Bit
81{
82	#[inline(always)]
83	fn from(value: u8) -> Self
84	{
85		MemoryOffset64Bit::OffsetForm64(value.into())
86	}
87}
88
89impl From<i16> for MemoryOffset64Bit
90{
91	#[inline(always)]
92	fn from(value: i16) -> Self
93	{
94		MemoryOffset64Bit::OffsetForm64(value.into())
95	}
96}
97
98impl From<u16> for MemoryOffset64Bit
99{
100	#[inline(always)]
101	fn from(value: u16) -> Self
102	{
103		MemoryOffset64Bit::OffsetForm64(value.into())
104	}
105}
106
107impl From<i32> for MemoryOffset64Bit
108{
109	#[inline(always)]
110	fn from(value: i32) -> Self
111	{
112		MemoryOffset64Bit::OffsetForm64(value.into())
113	}
114}
115
116impl From<u32> for MemoryOffset64Bit
117{
118	#[inline(always)]
119	fn from(value: u32) -> Self
120	{
121		MemoryOffset64Bit::OffsetForm64(value.into())
122	}
123}
124
125impl From<i64> for MemoryOffset64Bit
126{
127	#[inline(always)]
128	fn from(value: i64) -> Self
129	{
130		MemoryOffset64Bit::OffsetForm64(value.into())
131	}
132}
133
134impl From<u64> for MemoryOffset64Bit
135{
136	#[inline(always)]
137	fn from(value: u64) -> Self
138	{
139		MemoryOffset64Bit::OffsetForm64(value.into())
140	}
141}
142
143impl Into<(Option<SegmentRegister>, Immediate64Bit)> for MemoryOffset64Bit
144{
145	#[inline(always)]
146	fn into(self) -> (Option<SegmentRegister>, Immediate64Bit)
147	{
148		use self::MemoryOffset64Bit::*;
149		
150		match self
151		{
152			SegmentOffsetForm64(segment_register, immediate) => (Some(segment_register), immediate),
153			OffsetForm64(immediate) => (None, immediate),
154		}
155	}
156}
157
158impl Into<Immediate64Bit> for MemoryOffset64Bit
159{
160	#[inline(always)]
161	fn into(self) -> Immediate64Bit
162	{
163		use self::MemoryOffset64Bit::*;
164		
165		match self
166		{
167			SegmentOffsetForm64(_, immediate) => immediate,
168			OffsetForm64(immediate) => immediate,
169		}
170	}
171}
172
173impl Into<i64> for MemoryOffset64Bit
174{
175	#[inline(always)]
176	fn into(self) -> i64
177	{
178		let immediate: Immediate64Bit = self.into();
179		immediate.into()
180	}
181}
182
183impl Into<u64> for MemoryOffset64Bit
184{
185	#[inline(always)]
186	fn into(self) -> u64
187	{
188		let immediate: Immediate64Bit = self.into();
189		immediate.into()
190	}
191}
192
193impl MemoryOffset for MemoryOffset64Bit
194{
195	#[inline(always)]
196	fn get_segment_register(&self) -> Option<SegmentRegister>
197	{
198		use self::MemoryOffset64Bit::*;
199		
200		match *self
201		{
202			SegmentOffsetForm64(segment_register, _) => Some(segment_register),
203			OffsetForm64(_) => None,
204		}
205	}
206	
207	#[inline(always)]
208	fn get_offset(&self) -> Immediate64Bit
209	{
210		use self::MemoryOffset64Bit::*;
211		
212		match *self
213		{
214			SegmentOffsetForm64(_, immediate) => immediate,
215			OffsetForm64(immediate) => immediate,
216		}
217	}
218}