aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure
diff options
context:
space:
mode:
Diffstat (limited to 'ARMeilleure')
-rw-r--r--ARMeilleure/Common/AddressTable.cs15
-rw-r--r--ARMeilleure/Common/Counter.cs5
-rw-r--r--ARMeilleure/Common/EntryTable.cs15
-rw-r--r--ARMeilleure/IntermediateRepresentation/BasicBlock.cs11
-rw-r--r--ARMeilleure/Translation/DelegateHelper.cs5
-rw-r--r--ARMeilleure/Translation/Delegates.cs10
-rw-r--r--ARMeilleure/Translation/IntervalTree.cs15
-rw-r--r--ARMeilleure/Translation/TranslatorStubs.cs19
8 files changed, 21 insertions, 74 deletions
diff --git a/ARMeilleure/Common/AddressTable.cs b/ARMeilleure/Common/AddressTable.cs
index 7cb83fdd..9db2d00d 100644
--- a/ARMeilleure/Common/AddressTable.cs
+++ b/ARMeilleure/Common/AddressTable.cs
@@ -80,10 +80,7 @@ namespace ARMeilleure.Common
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
lock (_pages)
{
@@ -100,10 +97,7 @@ namespace ARMeilleure.Common
/// <exception cref="ArgumentException">Length of <paramref name="levels"/> is less than 2</exception>
public AddressTable(Level[] levels)
{
- if (levels == null)
- {
- throw new ArgumentNullException(nameof(levels));
- }
+ ArgumentNullException.ThrowIfNull(levels);
if (levels.Length < 2)
{
@@ -141,10 +135,7 @@ namespace ARMeilleure.Common
/// <exception cref="ArgumentException"><paramref name="address"/> is not mapped</exception>
public ref TEntry GetValue(ulong address)
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
if (!IsValid(address))
{
diff --git a/ARMeilleure/Common/Counter.cs b/ARMeilleure/Common/Counter.cs
index 4b0627c1..d7210d15 100644
--- a/ARMeilleure/Common/Counter.cs
+++ b/ARMeilleure/Common/Counter.cs
@@ -49,10 +49,7 @@ namespace ARMeilleure.Common
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
return ref _countTable.GetValue(_index);
}
diff --git a/ARMeilleure/Common/EntryTable.cs b/ARMeilleure/Common/EntryTable.cs
index f3f3ce28..6f205797 100644
--- a/ARMeilleure/Common/EntryTable.cs
+++ b/ARMeilleure/Common/EntryTable.cs
@@ -53,10 +53,7 @@ namespace ARMeilleure.Common
/// <exception cref="ObjectDisposedException"><see cref="EntryTable{TEntry}"/> instance was disposed</exception>
public int Allocate()
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
lock (_allocated)
{
@@ -83,10 +80,7 @@ namespace ARMeilleure.Common
/// <exception cref="ObjectDisposedException"><see cref="EntryTable{TEntry}"/> instance was disposed</exception>
public void Free(int index)
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
lock (_allocated)
{
@@ -108,10 +102,7 @@ namespace ARMeilleure.Common
/// <exception cref="ArgumentException">Entry at <paramref name="index"/> is not allocated</exception>
public ref TEntry GetValue(int index)
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
lock (_allocated)
{
diff --git a/ARMeilleure/IntermediateRepresentation/BasicBlock.cs b/ARMeilleure/IntermediateRepresentation/BasicBlock.cs
index 7cee52e5..07bd8b67 100644
--- a/ARMeilleure/IntermediateRepresentation/BasicBlock.cs
+++ b/ARMeilleure/IntermediateRepresentation/BasicBlock.cs
@@ -48,10 +48,7 @@ namespace ARMeilleure.IntermediateRepresentation
public void AddSuccessor(BasicBlock block)
{
- if (block == null)
- {
- ThrowNull(nameof(block));
- }
+ ArgumentNullException.ThrowIfNull(block);
if ((uint)_succCount + 1 > MaxSuccessors)
{
@@ -100,10 +97,7 @@ namespace ARMeilleure.IntermediateRepresentation
public void SetSuccessor(int index, BasicBlock block)
{
- if (block == null)
- {
- ThrowNull(nameof(block));
- }
+ ArgumentNullException.ThrowIfNull(block);
if ((uint)index >= (uint)_succCount)
{
@@ -144,7 +138,6 @@ namespace ARMeilleure.IntermediateRepresentation
}
}
- private static void ThrowNull(string name) => throw new ArgumentNullException(name);
private static void ThrowOutOfRange(string name) => throw new ArgumentOutOfRangeException(name);
private static void ThrowSuccessorOverflow() => throw new OverflowException($"BasicBlock can only have {MaxSuccessors} successors.");
diff --git a/ARMeilleure/Translation/DelegateHelper.cs b/ARMeilleure/Translation/DelegateHelper.cs
index f021d116..43a39bab 100644
--- a/ARMeilleure/Translation/DelegateHelper.cs
+++ b/ARMeilleure/Translation/DelegateHelper.cs
@@ -25,10 +25,7 @@ namespace ARMeilleure.Translation
public static Delegate GetDelegate(MethodInfo info)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
+ ArgumentNullException.ThrowIfNull(info);
Type[] parameters = info.GetParameters().Select(pI => pI.ParameterType).ToArray();
Type returnType = info.ReturnType;
diff --git a/ARMeilleure/Translation/Delegates.cs b/ARMeilleure/Translation/Delegates.cs
index fef1f4ef..9d3fdc17 100644
--- a/ARMeilleure/Translation/Delegates.cs
+++ b/ARMeilleure/Translation/Delegates.cs
@@ -35,10 +35,7 @@ namespace ARMeilleure.Translation
public static IntPtr GetDelegateFuncPtr(MethodInfo info)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
+ ArgumentNullException.ThrowIfNull(info);
string key = GetKey(info);
@@ -52,10 +49,7 @@ namespace ARMeilleure.Translation
public static int GetDelegateIndex(MethodInfo info)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
+ ArgumentNullException.ThrowIfNull(info);
string key = GetKey(info);
diff --git a/ARMeilleure/Translation/IntervalTree.cs b/ARMeilleure/Translation/IntervalTree.cs
index 79662bc9..9af01bea 100644
--- a/ARMeilleure/Translation/IntervalTree.cs
+++ b/ARMeilleure/Translation/IntervalTree.cs
@@ -67,10 +67,7 @@ namespace ARMeilleure.Translation
/// <returns>True if the value was added, false if the start key was already in the dictionary</returns>
public bool AddOrUpdate(K start, K end, V value, Func<K, V, V> updateFactoryCallback)
{
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(value);
return BSTInsert(start, end, value, updateFactoryCallback, out IntervalTreeNode<K, V> node);
}
@@ -85,10 +82,7 @@ namespace ARMeilleure.Translation
/// <returns><paramref name="value"/> if <paramref name="start"/> is not yet on the tree, or the existing value otherwise</returns>
public V GetOrAdd(K start, K end, V value)
{
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
+ ArgumentNullException.ThrowIfNull(value);
BSTInsert(start, end, value, null, out IntervalTreeNode<K, V> node);
return node.Value;
@@ -152,10 +146,7 @@ namespace ARMeilleure.Translation
/// <returns>Node reference in the tree</returns>
private IntervalTreeNode<K, V> GetNode(K key)
{
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key));
- }
+ ArgumentNullException.ThrowIfNull(key);
IntervalTreeNode<K, V> node = _root;
while (node != null)
diff --git a/ARMeilleure/Translation/TranslatorStubs.cs b/ARMeilleure/Translation/TranslatorStubs.cs
index 4ad6c2f2..67d2bba8 100644
--- a/ARMeilleure/Translation/TranslatorStubs.cs
+++ b/ARMeilleure/Translation/TranslatorStubs.cs
@@ -30,10 +30,7 @@ namespace ARMeilleure.Translation
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
return _dispatchStub.Value;
}
@@ -47,10 +44,7 @@ namespace ARMeilleure.Translation
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
return _slowDispatchStub.Value;
}
@@ -64,10 +58,7 @@ namespace ARMeilleure.Translation
{
get
{
- if (_disposed)
- {
- throw new ObjectDisposedException(null);
- }
+ ObjectDisposedException.ThrowIf(_disposed, this);
return _dispatchLoop.Value;
}
@@ -81,7 +72,9 @@ namespace ARMeilleure.Translation
/// <exception cref="ArgumentNullException"><paramref name="translator"/> is null</exception>
public TranslatorStubs(Translator translator)
{
- _translator = translator ?? throw new ArgumentNullException(nameof(translator));
+ ArgumentNullException.ThrowIfNull(translator);
+
+ _translator = translator;
_dispatchStub = new(GenerateDispatchStub, isThreadSafe: true);
_dispatchLoop = new(GenerateDispatchLoop, isThreadSafe: true);
}