-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP on new analysis stuff. Would CI-SKIP if I could :((
- Loading branch information
Sam Byass
committed
Jul 15, 2020
1 parent
c10c712
commit 20b83ec
Showing
11 changed files
with
337 additions
and
79 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using Cpp2IL.Analysis.ResultModels; | ||
using SharpDisasm; | ||
|
||
namespace Cpp2IL.Analysis.Actions | ||
{ | ||
/// <summary> | ||
/// Action for a simple reg->reg move | ||
/// </summary> | ||
public class RegContentCopyAction : BaseAction | ||
{ | ||
private IAnalysedOperand beingMoved; | ||
private string originalReg; | ||
private string newReg; | ||
|
||
public RegContentCopyAction(MethodAnalysis context, Instruction instruction) : base(context, instruction) | ||
{ | ||
} | ||
|
||
public override Mono.Cecil.Cil.Instruction[] ToILInstructions() | ||
{ | ||
//No-op | ||
return new Mono.Cecil.Cil.Instruction[0]; | ||
} | ||
|
||
public override string? ToPsuedoCode() | ||
{ | ||
return null; | ||
} | ||
|
||
public override string ToTextSummary() | ||
{ | ||
return $"Copies {beingMoved} from {originalReg} into {newReg}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,98 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Cpp2IL.Analysis.Actions; | ||
using Mono.Cecil; | ||
|
||
namespace Cpp2IL.Analysis.ResultModels | ||
{ | ||
public class MethodAnalysis | ||
{ | ||
public List<LocalDefinition> Locals = new List<LocalDefinition>(); | ||
public List<ConstantDefinition> Constants = new List<ConstantDefinition>(); | ||
public List<BaseAction> Actions = new List<BaseAction>(); | ||
private MethodDefinition _forMethod; | ||
public readonly List<LocalDefinition> Locals = new List<LocalDefinition>(); | ||
public readonly List<ConstantDefinition> Constants = new List<ConstantDefinition>(); | ||
public readonly List<BaseAction> Actions = new List<BaseAction>(); | ||
|
||
private MethodDefinition _method; | ||
|
||
private readonly Dictionary<string, IAnalysedOperand> RegisterData = new Dictionary<string, IAnalysedOperand>(); | ||
private readonly Dictionary<int, IAnalysedOperand> StackData = new Dictionary<int, IAnalysedOperand>(); | ||
|
||
internal MethodAnalysis(MethodDefinition method) | ||
{ | ||
_method = method; | ||
|
||
//Set up parameters in registers & as locals. | ||
var regList = new List<string> {"rcx", "rdx", "r8", "r9"}; | ||
|
||
if (!method.IsStatic) | ||
MakeLocal(method.DeclaringType, "this", regList.RemoveAndReturn(0)); | ||
|
||
var args = method.Parameters.ToList(); | ||
while (args.Count > 0 && regList.Count > 0) | ||
{ | ||
var arg = args.RemoveAndReturn(0); | ||
var dest = regList.RemoveAndReturn(0); | ||
|
||
MakeLocal(arg.ParameterType.Resolve(), arg.Name, dest); | ||
} | ||
|
||
var stackIdx = 0; | ||
while (args.Count > 0) | ||
{ | ||
//Push remainder to stack | ||
var arg = args.RemoveAndReturn(0); | ||
PushToStack(MakeLocal(arg.ParameterType.Resolve(), arg.Name), stackIdx); | ||
stackIdx += (int) Utils.GetSizeOfObject(arg.ParameterType); | ||
} | ||
} | ||
|
||
public LocalDefinition MakeLocal(TypeDefinition? type, string? name = null, string? reg = null) | ||
{ | ||
var local = new LocalDefinition | ||
{ | ||
Name = name ?? $"local{Locals.Count}", | ||
Type = type | ||
}; | ||
|
||
Locals.Add(local); | ||
|
||
if (reg != null) | ||
RegisterData[reg] = local; | ||
|
||
return local; | ||
} | ||
|
||
public IAnalysedOperand PushToStack(IAnalysedOperand operand, int pos) | ||
{ | ||
StackData[pos] = operand; | ||
return operand; | ||
} | ||
|
||
public IAnalysedOperand? GetOperandInRegister(string reg) | ||
{ | ||
if (!RegisterData.TryGetValue(reg, out var result)) | ||
return null; | ||
|
||
return result; | ||
} | ||
|
||
public LocalDefinition? GetLocalInReg(string reg) | ||
{ | ||
if (!RegisterData.TryGetValue(reg, out var result)) | ||
return null; | ||
|
||
if (!(result is LocalDefinition local)) return null; | ||
|
||
return local; | ||
} | ||
|
||
internal MethodAnalysis(MethodDefinition forMethod) | ||
public ConstantDefinition? GetConstantInReg(string reg) | ||
{ | ||
_forMethod = forMethod; | ||
if (!RegisterData.TryGetValue(reg, out var result)) | ||
return null; | ||
|
||
if (!(result is ConstantDefinition constant)) return null; | ||
|
||
return constant; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters