Better guessing on the generic operand type
This commit is contained in:
@@ -12,6 +12,6 @@
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="main, console" />
|
||||
<logger name="Chat" minlevel="Info" writeTo="chat" />
|
||||
<!--<logger name="Torch.Managers.PatchManager.*" minlevel="Trace" writeTo="patch"/>-->
|
||||
<logger name="Torch.Managers.PatchManager.*" minlevel="Trace" writeTo="patch"/>
|
||||
</rules>
|
||||
</nlog>
|
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
@@ -103,6 +105,9 @@ namespace Torch.Managers.PatchManager.MSIL
|
||||
/// </summary>
|
||||
public HashSet<MsilLabel> Labels { get; } = new HashSet<MsilLabel>();
|
||||
|
||||
|
||||
private static readonly ConcurrentDictionary<Type, PropertyInfo> _setterInfoForInlines = new ConcurrentDictionary<Type, PropertyInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the inline value for this instruction.
|
||||
/// </summary>
|
||||
@@ -111,6 +116,23 @@ namespace Torch.Managers.PatchManager.MSIL
|
||||
/// <returns>This instruction</returns>
|
||||
public MsilInstruction InlineValue<T>(T o)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
while (type != null)
|
||||
{
|
||||
if (!_setterInfoForInlines.TryGetValue(type, out PropertyInfo target))
|
||||
{
|
||||
Type genType = typeof(MsilOperandInline<>).MakeGenericType(type);
|
||||
target = genType.GetProperty(nameof(MsilOperandInline<int>.Value));
|
||||
_setterInfoForInlines[type] = target;
|
||||
}
|
||||
Debug.Assert(target?.DeclaringType != null);
|
||||
if (target.DeclaringType.IsInstanceOfType(Operand))
|
||||
{
|
||||
target.SetValue(Operand, o);
|
||||
return this;
|
||||
}
|
||||
type = type.BaseType;
|
||||
}
|
||||
((MsilOperandInline<T>)Operand).Value = o;
|
||||
return this;
|
||||
}
|
||||
|
@@ -143,7 +143,7 @@ namespace Torch.Managers.PatchManager.Transpile
|
||||
|
||||
public string ToHumanMsil()
|
||||
{
|
||||
return string.Join("\n", _instructions.Select(x => $"IL_{x.Offset:X4}: {x.StackChange()} {x}"));
|
||||
return string.Join("\n", _instructions.Select(x => $"IL_{x.Offset:X4}: {x.StackChange():+0;-#} {x}"));
|
||||
}
|
||||
|
||||
private static readonly Dictionary<short, OpCode> OpCodeLookup;
|
||||
|
@@ -16,8 +16,8 @@ namespace Torch.Managers.PatchManager.Transpile
|
||||
var context = new MethodContext(baseMethod);
|
||||
context.Read();
|
||||
context.CheckIntegrity();
|
||||
_log.Trace("Input Method:");
|
||||
_log.Trace(context.ToHumanMsil);
|
||||
// _log.Trace("Input Method:");
|
||||
// _log.Trace(context.ToHumanMsil);
|
||||
|
||||
var methodContent = (IEnumerable<MsilInstruction>)context.Instructions;
|
||||
foreach (var transpiler in transpilers)
|
||||
|
Reference in New Issue
Block a user