Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jul 22, 2017
1 parent dfa98a6 commit f7df602
Show file tree
Hide file tree
Showing 43 changed files with 409 additions and 521 deletions.
2 changes: 1 addition & 1 deletion Core/CSPspEmu.Core.Cpu/Dynarec/Ast/GeneratorILPsp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace CSPspEmu.Core.Cpu.Dynarec.Ast
{
public class GeneratorIlPsp : GeneratorIL
public class GeneratorIlPsp : GeneratorIl
{
protected void _Generate(AstNodeStmPspInstruction pspInstruction)
{
Expand Down
2 changes: 1 addition & 1 deletion Core/CSPspEmu.Core.Cpu/FastPspMemoryUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static MethodInfo GetFastMemoryReader(IntPtr fixedGlobalAddress)
)
);

new GeneratorIL().Reset().Init(method, method.GetILGenerator()).GenerateRoot(astTree);
new GeneratorIl().Reset().Init(method, method.GetILGenerator()).GenerateRoot(astTree);

var type = typeBuilder.CreateType();
Cache[cacheKey] = type.GetMethod(methodName);
Expand Down
2 changes: 1 addition & 1 deletion Core/CSPspEmu.Core.Cpu/InstructionCache/MethodCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class MethodCache : IInjectInitialize
public static readonly MethodCache Methods = new MethodCache();

private static readonly AstMipsGenerator Ast = AstMipsGenerator.Instance;
private static readonly GeneratorIL GeneratorIlInstance = new GeneratorIL();
private static readonly GeneratorIl GeneratorIlInstance = new GeneratorIl();

private readonly Dictionary<uint, MethodCacheInfo> _methodMapping =
new Dictionary<uint, MethodCacheInfo>(64 * 1024);
Expand Down
4 changes: 2 additions & 2 deletions Core/CSPspEmu.Core.Cpu/InstructionCache/MethodCacheInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void SetDynarecFunction(DynarecFunction dynarecFunction)
/// <summary>
/// Static Field that will hold the Delegate
/// </summary>
public ILInstanceHolderPoolItem<Action<CpuThreadState>> StaticField;
public IlInstanceHolderPoolItem<Action<CpuThreadState>> StaticField;

/// <summary>
///
Expand All @@ -63,7 +63,7 @@ public MethodCacheInfo(MethodCache methodCache, Action<CpuThreadState> delegateG
{
MethodCache = methodCache;
_functionDelegate = delegateGeneratorForPc;
StaticField = IlInstanceHolder.TAlloc(delegateGeneratorForPc);
StaticField = IlInstanceHolder.TaAlloc(delegateGeneratorForPc);
Pc = pc;
}

Expand Down
2 changes: 1 addition & 1 deletion Core/CSPspEmu.Core.Cpu/NativeSyscallInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class NativeSyscallInfo
{
public string Name => $"{ModuleImportName}.{FunctionEntryName} (0x{Nid:X8})";

public ILInstanceHolderPoolItem<Action<CpuThreadState>> PoolItem;
public IlInstanceHolderPoolItem<Action<CpuThreadState>> PoolItem;
public uint Nid;
public string FunctionEntryName;
public string ModuleImportName;
Expand Down
2 changes: 1 addition & 1 deletion Hle/CSPspEmu.Hle/Managers/HleModuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public uint AllocDelegateSlot(Action<CpuThreadState> Action, string ModuleImport
ModuleImportName = ModuleImportName,
FunctionEntryName = FunctionEntry.Name,
Nid = FunctionEntry.NID,
PoolItem = IlInstanceHolder.TAlloc<Action<CpuThreadState>>(FunctionEntry.Delegate),
PoolItem = IlInstanceHolder.TaAlloc<Action<CpuThreadState>>(FunctionEntry.Delegate),
};
DelegateTable[DelegateId] = new DelegateInfo()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public static unsafe void TransferChannelsDataLinear(Rectangle rectangle, Bitmap
public static unsafe void TransferChannelsDataLinear(Rectangle rectangle, Bitmap bitmap, byte* newDataPtr,
Direction direction, params BitmapChannel[] channels)
{
var widthHeight = bitmap.Width * bitmap.Height;
var fullRectangle = bitmap.GetFullRectangle();
if (!fullRectangle.Contains(rectangle.Location))
throw (new InvalidOperationException("TransferChannelsDataLinear"));
Expand All @@ -213,7 +212,6 @@ public static unsafe void TransferChannelsDataLinear(Rectangle rectangle, Bitmap
{
var bitmapDataScan0 = (byte*) bitmapData.Scan0.ToPointer();
var width = bitmap.Width;
var height = bitmap.Height;
var stride = bitmapData.Stride;
if (numberOfChannels == 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public SpaceAssigner1D.Space AllocateUnique(byte[] data)
/// <returns></returns>
public SpaceAssigner1D.Space[] AllocateUnique(byte[][] data)
{
/// @TODO Has to use data.Distinct() and the Allocate[] function in order
/// to be able to avoid a greedy behaviour.
// @TODO Has to use data.Distinct() and the Allocate[] function in order
// to be able to avoid a greedy behaviour.

var spaces = new SpaceAssigner1D.Space[data.Length];
for (var n = 0; n < data.Length; n++)
Expand All @@ -74,7 +74,7 @@ public SpaceAssigner1D.Space[] AllocateUnique(byte[][] data)
/// <returns></returns>
public SpaceAssigner1D.Space AllocateUnique(string String, Encoding encoding = null)
{
if (encoding == null) encoding = this.Encoding;
if (encoding == null) encoding = Encoding;
return AllocateUnique(String.GetStringzBytes(encoding));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SafeILGenerator.Tests.Ast.Generators
public unsafe class GeneratorILTest
{
private static AstGenerator ast = AstGenerator.Instance;
private GeneratorIL GeneratorIL = new GeneratorIL();
private GeneratorIl GeneratorIL = new GeneratorIl();

public static void TestAstSetGetLValue_Set(int Index, int Value)
{
Expand Down Expand Up @@ -198,11 +198,11 @@ public void TestWriteLineLoadString()
ast.Return()
);

var GeneratorIL = new GeneratorIL();
var GeneratorIL = new GeneratorIl();
var Method = GeneratorIL.GenerateDelegate<Action<string>>("TestWriteLine", Ast);

Console.WriteLine(new GeneratorCSharp().GenerateRoot(Ast).ToString());
Console.WriteLine("{0}", new GeneratorIL().GenerateToString(Method.Method, Ast));
Console.WriteLine("{0}", new GeneratorIl().GenerateToString(Method.Method, Ast));

var Output = AstStringUtils.CaptureOutput(() => { Method("Hello World!"); });

Expand All @@ -222,7 +222,7 @@ public void TestAstSwitch()
),
ast.Return("Invalid!")
);
var GeneratorIL = new GeneratorIL();
var GeneratorIL = new GeneratorIl();
var Method = GeneratorIL.GenerateDelegate<Func<int, string>>("TestSwitch", Ast);
Assert.Equal("-", Method(0));
Assert.Equal("One", Method(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void TestMethod2()
ast.Return()
);
Console.WriteLine(GeneratorCSharp.GenerateString<GeneratorCSharp>(astNode));
var generatorIl = new GeneratorIL();
var generatorIl = new GeneratorIl();
var itemSet = generatorIl.GenerateDelegate<Action<int>>("ItemSet", astNode);
itemSet(10);
Assert.Equal(10, item.Value);
Expand All @@ -59,7 +59,7 @@ public void TestGlobalAlloc()
Assert.Equal(0, IlInstanceHolder.CapacityCount);
Assert.Equal(0, IlInstanceHolder.FreeCount);

var globalKey = IlInstanceHolder.TAlloc<int>();
var globalKey = IlInstanceHolder.TaAlloc<int>();

Assert.Equal(4, IlInstanceHolder.CapacityCount);
Assert.Equal(3, IlInstanceHolder.FreeCount);
Expand Down
11 changes: 3 additions & 8 deletions Libraries/SafeILGenerator/SafeILGenerator/Ast/AstArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ public AstArgument(int index, Type type, string name = null)
Name = name ?? ("@ARG(" + index + ")");
}

public static AstArgument Create(Type type, int index, string name = null)
{
return new AstArgument(index, type, name);
}
public static AstArgument Create(Type type, int index, string name = null) =>
new AstArgument(index, type, name);

public static AstArgument Create<TType>(int index, string name = null)
{
return Create(typeof(TType), index, name);
}
public static AstArgument Create<TType>(int index, string name = null) => Create(typeof(TType), index, name);

public static AstArgument Create(MethodInfo methodInfo, int index, string name = null)
{
Expand Down
4 changes: 2 additions & 2 deletions Libraries/SafeILGenerator/SafeILGenerator/Ast/AstGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public AstNodeExprLValue FieldPropertyAccess(AstNodeExpr instance, string fieldP
if (instance.Type.GetField(fieldPropertyName) != null) return FieldAccess(instance, fieldPropertyName);
if (instance.Type.GetProperty(fieldPropertyName) != null)
return PropertyAccess(instance, fieldPropertyName);
throw (new InvalidOperationException(string.Format("Can't find Field/Property '{0}' for type '{1}'",
fieldPropertyName, instance.Type)));
throw (new InvalidOperationException(
$"Can't find Field/Property '{fieldPropertyName}' for type '{instance.Type}'"));
}

public AstNodeExprPropertyAccess PropertyAccess(AstNodeExpr instance, PropertyInfo propertyInfo) =>
Expand Down
2 changes: 1 addition & 1 deletion Libraries/SafeILGenerator/SafeILGenerator/Ast/AstUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static object CastType(object value, Type castType)
if (castType == typeof(sbyte)) return (sbyte) Convert.ToInt64(value);
if (castType == typeof(short)) return (short) Convert.ToInt64(value);
if (castType == typeof(int)) return (int) Convert.ToInt64(value);
if (castType == typeof(long)) return (long) Convert.ToInt64(value);
if (castType == typeof(long)) return Convert.ToInt64(value);

if (castType == typeof(byte)) return (byte) Convert.ToInt64(value);
if (castType == typeof(ushort)) return (ushort) Convert.ToInt64(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class Generator<TGenerator>

protected Generator()
{
foreach (var method in this.GetType()
foreach (var method in GetType()
.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
.Where(method => method.ReturnType == typeof(void))
.Where(method => method.GetParameters().Count() == 1)
Expand Down Expand Up @@ -119,8 +119,7 @@ protected virtual void Generate(AstNode astNode)
{
Console.WriteLine(generateMapping);
}
throw (new NotImplementedException(string.Format("Don't know how to generate {0} for {1}", astNodeType,
GetType())));
throw (new NotImplementedException($"Don't know how to generate {astNodeType} for {GetType()}"));
}

GenerateMappings[astNodeType].Call(this, astNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static string ValueAsString(object value, Type type = null)
if (value is IntPtr) return $"0x{((IntPtr) value).ToInt64():X}";
if (value is string) return $"{AstStringUtils.ToLiteral(value as string)}";
if (AstUtils.IsTypeSigned(type)) return value.ToString();
if (Convert.ToInt64(value) > 9) return string.Format("0x{0:X}", value);
if (Convert.ToInt64(value) > 9) return $"0x{value:X}";
return value.ToString();
}

Expand Down
Loading

0 comments on commit f7df602

Please sign in to comment.