aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/IntermediateRepresentation/OperandType.cs
blob: bfdf5130cffc75554a488b359efbdf53ac5db77d (plain)
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
using System;

namespace ARMeilleure.IntermediateRepresentation
{
    enum OperandType
    {
        None,
        I32,
        I64,
        FP32,
        FP64,
        V128
    }

    static class OperandTypeExtensions
    {
        public static bool IsInteger(this OperandType type)
        {
            return type == OperandType.I32 ||
                   type == OperandType.I64;
        }

        public static RegisterType ToRegisterType(this OperandType type)
        {
            switch (type)
            {
                case OperandType.FP32: return RegisterType.Vector;
                case OperandType.FP64: return RegisterType.Vector;
                case OperandType.I32:  return RegisterType.Integer;
                case OperandType.I64:  return RegisterType.Integer;
                case OperandType.V128: return RegisterType.Vector;
            }

            throw new InvalidOperationException($"Invalid operand type \"{type}\".");
        }

        public static int GetSizeInBytes(this OperandType type)
        {
            switch (type)
            {
                case OperandType.FP32: return 4;
                case OperandType.FP64: return 8;
                case OperandType.I32:  return 4;
                case OperandType.I64:  return 8;
                case OperandType.V128: return 16;
            }

            throw new InvalidOperationException($"Invalid operand type \"{type}\".");
        }
    }
}