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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
using ARMeilleure.Common;
using ARMeilleure.Translation.PTC;
using System.Runtime.CompilerServices;
namespace ARMeilleure.IntermediateRepresentation
{
static class OperandHelper
{
public static Operand Const(OperandType type, long value)
{
return type == OperandType.I32 ? Operand().With((int)value) : Operand().With(value);
}
public static Operand Const(bool value)
{
return Operand().With(value ? 1 : 0);
}
public static Operand Const(int value)
{
return Operand().With(value);
}
public static Operand Const(uint value)
{
return Operand().With(value);
}
public static Operand Const(long value)
{
return Operand().With(value);
}
public static Operand Const(long value, Symbol symbol)
{
return Operand().With(value, symbol);
}
public static Operand Const(ulong value)
{
return Operand().With(value);
}
public static unsafe Operand Const<T>(ref T reference, Symbol symbol = default)
{
return Operand().With((long)Unsafe.AsPointer(ref reference), symbol);
}
public static Operand ConstF(float value)
{
return Operand().With(value);
}
public static Operand ConstF(double value)
{
return Operand().With(value);
}
public static Operand Label()
{
return Operand().With(OperandKind.Label);
}
public static Operand Local(OperandType type)
{
return Operand().With(OperandKind.LocalVariable, type);
}
public static Operand Register(int index, RegisterType regType, OperandType type)
{
return Operand().With(index, regType, type);
}
public static Operand Undef()
{
return Operand().With(OperandKind.Undefined);
}
public static MemoryOperand MemoryOp(
OperandType type,
Operand baseAddress,
Operand index = null,
Multiplier scale = Multiplier.x1,
int displacement = 0)
{
return MemoryOperand().With(type, baseAddress, index, scale, displacement);
}
#region "ThreadStaticPool"
public static void PrepareOperandPool(int groupId = 0)
{
ThreadStaticPool<Operand>.PreparePool(groupId, ChunkSizeLimit.Large);
ThreadStaticPool<MemoryOperand>.PreparePool(groupId, ChunkSizeLimit.Small);
}
private static Operand Operand()
{
return ThreadStaticPool<Operand>.Instance.Allocate();
}
private static MemoryOperand MemoryOperand()
{
return ThreadStaticPool<MemoryOperand>.Instance.Allocate();
}
public static void ResetOperandPool(int groupId = 0)
{
ThreadStaticPool<MemoryOperand>.ResetPool(groupId);
ThreadStaticPool<Operand>.ResetPool(groupId);
}
public static void DisposeOperandPools()
{
ThreadStaticPool<Operand>.DisposePools();
ThreadStaticPool<MemoryOperand>.DisposePools();
}
#endregion
}
}
|