aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/IntermediateRepresentation/MemoryOperand.cs
blob: 07d2633b42d4b1ba6e5c58436e3ad5c4c023d08e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace ARMeilleure.IntermediateRepresentation
{
    unsafe struct MemoryOperand
    {
        private struct Data
        {
#pragma warning disable CS0649
            public byte Kind;
            public byte Type;
#pragma warning restore CS0649
            public byte Scale;
            public Operand BaseAddress;
            public Operand Index;
            public int Displacement;
        }

        private Data* _data;

        public MemoryOperand(Operand operand)
        {
            Debug.Assert(operand.Kind == OperandKind.Memory);

            _data = (Data*)Unsafe.As<Operand, IntPtr>(ref operand);
        }

        public Operand BaseAddress
        {
            get => _data->BaseAddress;
            set => _data->BaseAddress = value; 
        }

        public Operand Index
        {
            get => _data->Index;
            set => _data->Index = value; 
        }

        public Multiplier Scale
        {
            get => (Multiplier)_data->Scale;
            set => _data->Scale = (byte)value;
        }

        public int Displacement
        {
            get => _data->Displacement;
            set => _data->Displacement = value;
        }
    }
}