AssemblyData has now been ported
This commit is contained in:
parent
8d87fa02bc
commit
4fc663ce8c
|
@ -130,7 +130,8 @@ namespace AssemblyData.methodsrewriter {
|
|||
if (resolver != null)
|
||||
return resolver.type;
|
||||
|
||||
if (typeRef.IsGenericParameter)
|
||||
var ts = typeRef as TypeSpec;
|
||||
if (ts != null && ts.TypeSig is GenericSig)
|
||||
return typeof(MGenericParameter);
|
||||
|
||||
return null;
|
||||
|
|
|
@ -178,8 +178,8 @@ namespace AssemblyData.methodsrewriter {
|
|||
|
||||
void initLocals() {
|
||||
locals = new List<LocalBuilder>();
|
||||
foreach (var local in methodInfo.methodDef.CilBody.Variables)
|
||||
locals.Add(ilg.DeclareLocal(Resolver.getRtType(local.VariableType), local.IsPinned));
|
||||
foreach (var local in methodInfo.methodDef.CilBody.LocalList)
|
||||
locals.Add(ilg.DeclareLocal(Resolver.getRtType(local.Type), local.Type.IsPinned));
|
||||
tempObjLocal = ilg.DeclareLocal(typeof(object));
|
||||
tempObjArrayLocal = ilg.DeclareLocal(typeof(object[]));
|
||||
}
|
||||
|
@ -256,14 +256,6 @@ namespace AssemblyData.methodsrewriter {
|
|||
return labels;
|
||||
}
|
||||
|
||||
int getArgIndex(Parameter arg) {
|
||||
return arg.Index;
|
||||
}
|
||||
|
||||
int getLocalIndex(Local local) {
|
||||
return local.Index;
|
||||
}
|
||||
|
||||
void writeInstr(Instruction instr) {
|
||||
var opcode = convertOpCode(instr.OpCode);
|
||||
switch (instr.OpCode.OperandType) {
|
||||
|
@ -324,20 +316,12 @@ namespace AssemblyData.methodsrewriter {
|
|||
throw new ApplicationException(string.Format("Unknown type: {0}", (obj == null ? obj : obj.GetType())));
|
||||
break;
|
||||
|
||||
case OperandType.InlineArg:
|
||||
ilg.Emit(opcode, checked((short)getArgIndex((Parameter)instr.Operand)));
|
||||
break;
|
||||
|
||||
case OperandType.ShortInlineArg:
|
||||
ilg.Emit(opcode, checked((byte)getArgIndex((Parameter)instr.Operand)));
|
||||
break;
|
||||
|
||||
case OperandType.InlineVar:
|
||||
ilg.Emit(opcode, checked((short)getLocalIndex((Local)instr.Operand)));
|
||||
ilg.Emit(opcode, checked((short)((IVariable)instr.Operand).Number));
|
||||
break;
|
||||
|
||||
case OperandType.ShortInlineVar:
|
||||
ilg.Emit(opcode, checked((byte)getLocalIndex((Local)instr.Operand)));
|
||||
ilg.Emit(opcode, checked((byte)((IVariable)instr.Operand).Number));
|
||||
break;
|
||||
|
||||
case OperandType.InlineSig: //TODO:
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace AssemblyData.methodsrewriter {
|
|||
}
|
||||
}
|
||||
|
||||
public MType getType(ITypeDefOrRef typeRef) {
|
||||
public MType getType(IType typeRef) {
|
||||
return typeReferenceToType.find(typeRef);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace AssemblyData.methodsrewriter {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static MType getType(ITypeDefOrRef typeRef) {
|
||||
public static MType getType(IType typeRef) {
|
||||
if (typeRef == null)
|
||||
return null;
|
||||
var module = getModule(typeRef.Scope);
|
||||
|
@ -104,7 +104,7 @@ namespace AssemblyData.methodsrewriter {
|
|||
throw new ApplicationException(string.Format("Unknown MemberReference: {0}", memberRef));
|
||||
}
|
||||
|
||||
public static Type getRtType(ITypeDefOrRef typeRef) {
|
||||
public static Type getRtType(IType typeRef) {
|
||||
var mtype = getType(typeRef);
|
||||
if (mtype != null)
|
||||
return mtype.type;
|
||||
|
@ -139,12 +139,14 @@ namespace AssemblyData.methodsrewriter {
|
|||
static Type resolve(IType typeRef) {
|
||||
if (typeRef == null)
|
||||
return null;
|
||||
var elemType = typeRef.GetElementType();
|
||||
var resolver = getAssemblyResolver(elemType);
|
||||
var resolvedType = resolver.resolve(elemType);
|
||||
var scopeType = typeRef.ScopeType;
|
||||
var resolver = getAssemblyResolver(scopeType);
|
||||
var resolvedType = resolver.resolve(scopeType);
|
||||
if (resolvedType != null)
|
||||
return fixType(typeRef, resolvedType);
|
||||
throw new ApplicationException(string.Format("Could not resolve type {0} ({1:X8}) in assembly {2}", typeRef, typeRef.MDToken.Raw, resolver));
|
||||
var tdr = typeRef as ITypeDefOrRef;
|
||||
uint token = tdr == null ? 0 : tdr.MDToken.Raw;
|
||||
throw new ApplicationException(string.Format("Could not resolve type {0} ({1:X8}) in assembly {2}", typeRef, token, resolver));
|
||||
}
|
||||
|
||||
static FieldInfo resolve(IField fieldRef) {
|
||||
|
@ -167,11 +169,13 @@ namespace AssemblyData.methodsrewriter {
|
|||
throw new ApplicationException(string.Format("Could not resolve method {0} ({1:X8}) in assembly {2}", methodRef, methodRef.MDToken.Raw, resolver));
|
||||
}
|
||||
|
||||
static Type fixType(ITypeDefOrRef typeRef, Type type) {
|
||||
var ts = typeRef as TypeSpec;
|
||||
if (ts == null)
|
||||
return type;
|
||||
var sig = ts.TypeSig;
|
||||
static Type fixType(IType typeRef, Type type) {
|
||||
var sig = typeRef as TypeSig;
|
||||
if (sig != null) {
|
||||
var ts = typeRef as TypeSpec;
|
||||
if (ts != null)
|
||||
sig = ts.TypeSig;
|
||||
}
|
||||
while (sig != null) {
|
||||
switch (sig.ElementType) {
|
||||
case ElementType.SZArray:
|
||||
|
|
|
@ -37,12 +37,14 @@ namespace AssemblyData.methodsrewriter {
|
|||
initFields();
|
||||
|
||||
List<FieldInfo> list;
|
||||
if (!fields.TryGetValue(fieldRef.Name, out list))
|
||||
if (!fields.TryGetValue(fieldRef.Name.String, out list))
|
||||
return null;
|
||||
|
||||
var git = fieldRef.DeclaringType.ToGenericInstSig();
|
||||
if (git != null)
|
||||
fieldRef = FieldReferenceInstance.make(fieldRef, git);
|
||||
if (git != null) {
|
||||
//TODO: Replace all generic params with generic args and create a new field ref
|
||||
fieldRef = null;
|
||||
}
|
||||
|
||||
foreach (var field in list) {
|
||||
if (ResolverUtils.compareFields(field, fieldRef))
|
||||
|
@ -70,12 +72,14 @@ namespace AssemblyData.methodsrewriter {
|
|||
initMethods();
|
||||
|
||||
List<MethodBase> list;
|
||||
if (!methods.TryGetValue(methodRef.Name, out list))
|
||||
if (!methods.TryGetValue(methodRef.Name.String, out list))
|
||||
return null;
|
||||
|
||||
var git = methodRef.DeclaringType.ToGenericInstSig();
|
||||
var gim = methodRef as MethodSpec;
|
||||
methodRef = MethodReferenceInstance.make(methodRef, git, gim);
|
||||
if (git != null && gim != null) {
|
||||
//TODO: Create a new method ref with all generic params replaced with generic args
|
||||
}
|
||||
|
||||
foreach (var method in list) {
|
||||
if (ResolverUtils.compareMethods(method, methodRef))
|
||||
|
|
2
dot10
2
dot10
|
@ -1 +1 @@
|
|||
Subproject commit 5df20e544a7b220b3155dfc00c23c72362915806
|
||||
Subproject commit 709b4cce8000c50f969dcb2636637a8840fcb4e8
|
Loading…
Reference in New Issue
Block a user