Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update optimizer #466

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static partial class ConstMgr
public const string PdbBytesFolder = "Assets/HotUpdateResources/Main/Dll/";
public const string DLLBytesFolder = "Assets/HotUpdateResources/Main/Dll/";
public const string MainHotDLLName = "HotUpdateScripts";
public const string ExprFlag = "_expr";
public const string DLLExtension = ".dll";
public const string PdbExtension = ".pdb";
public const string BytesExtension = ".bytes";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,96 +7,66 @@ public static partial class Optimizer
private static string GetLdLocName(Instruction instruction)
{
var code = instruction.OpCode.Code.ToString();
if(code.StartsWith("Ldloc"))
if (code.StartsWith("Ldloc"))
{
if(code.EndsWith("S"))
if (code.EndsWith("S"))
{
return instruction.Operand.ToString();
}
return code.Substring(code.Length - 1);

return code.Replace("Ldloc", "").Replace("_", "");
}

return null;
}

private static string GetStLocName(Instruction instruction)
{
var code = instruction.OpCode.Code.ToString();
if(code.StartsWith("Stloc"))
if (code.StartsWith("Stloc"))
{
if(code.EndsWith("S"))
if (code.EndsWith("S"))
{
return instruction.Operand.ToString();
}
return code.Substring(code.Length - 1);

return code.Replace("Stloc", "").Replace("_", "");
}

return null;
}
private static int GetLdcI4Num(Instruction instruction)

private static long GetLdcNumForInteger(Instruction instruction)
{
var code = instruction.OpCode.Code.ToString();
if(code.StartsWith("Ldc_I4"))
var code = instruction.OpCode.Code;
switch (code)
{
if(code.EndsWith("S"))
{
return (sbyte)instruction.Operand;
}

if(code.EndsWith("M1"))
{
case Code.Ldc_I4_M1:
return -1;
}

if(code.EndsWith("0"))
{
case Code.Ldc_I4_0:
return 0;
}

if(code.EndsWith("1"))
{
case Code.Ldc_I4_1:
return 1;
}

if(code.EndsWith("2"))
{
case Code.Ldc_I4_2:
return 2;
}

if(code.EndsWith("3"))
{
case Code.Ldc_I4_3:
return 3;
}

if(code.EndsWith("4"))
{
case Code.Ldc_I4_4:
return 4;
}

if(code.EndsWith("5"))
{
case Code.Ldc_I4_5:
return 5;
}

if(code.EndsWith("6"))
{
case Code.Ldc_I4_6:
return 6;
}

if(code.EndsWith("7"))
{
case Code.Ldc_I4_7:
return 7;
}

if(code.EndsWith("8"))
{
case Code.Ldc_I4_8:
return 8;
}

return (int)instruction.Operand;
case Code.Ldc_I4_S:
return (sbyte)instruction.Operand;
case Code.Ldc_I4:
return (int)instruction.Operand;
case Code.Ldc_I8:
return (long)instruction.Operand;
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace JEngine.Editor
{
public static partial class Optimizer
{
private static Instruction NewLdcI4Instruction(int i)
private static Instruction NewLdcInstruction(long i)
{
switch (i)
{
Expand All @@ -28,16 +28,13 @@ private static Instruction NewLdcI4Instruction(int i)
return Instruction.Create(OpCodes.Ldc_I4_7);
case 8:
return Instruction.Create(OpCodes.Ldc_I4_8);
case var _ when i <= 127:
case var _ when i <= 127 && i >= -128:
return Instruction.Create(OpCodes.Ldc_I4_S, (sbyte)i);
case var _ when i <= int.MaxValue && i >= int.MinValue:
return Instruction.Create(OpCodes.Ldc_I4, (int)i);
default:
return Instruction.Create(OpCodes.Ldc_I4, i);
return Instruction.Create(OpCodes.Ldc_I8, i);
}
}

private static Instruction NewLdcI8Instruction(long i)
{
return Instruction.Create(OpCodes.Ldc_I8, i);
}
}
}
Loading