Skip to content

Commit

Permalink
Optimized the generated filename of CLRBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Apr 2, 2020
1 parent b8bdd82 commit d32dcc7
Show file tree
Hide file tree
Showing 20 changed files with 391 additions and 47 deletions.
2 changes: 1 addition & 1 deletion ILRuntime/Runtime/CLRBinding/BindingCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static void GenerateBindingCode(ILRuntime.Runtime.Enviorment.AppDomain do
oriFileName = oriFileName.Substring(0, len);

int extraNameIndex = 0;
string oFileName = oriFileName + "_t" + extraNameIndex;
string oFileName = oriFileName;
while (files.Contains(oFileName))
{
extraNameIndex++;
Expand Down
3 changes: 3 additions & 0 deletions ILRuntimeTest/AutoGenerate/CLRBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_Collections_Generic_Dictionary_2_UInt32_ILTypeInstance_Binding.Register(app);
System_Collections_Generic_Dictionary_2_UInt32_ILTypeInstance_Binding_Enumerator_Binding.Register(app);
System_Collections_Generic_KeyValuePair_2_UInt32_ILTypeInstance_Binding.Register(app);
ILRuntimeTest_TestFramework_TestVector3NoBinding_Binding.Register(app);
System_AccessViolationException_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Object_Object_Binding.Register(app);
ILRuntimeTest_TestFramework_TestCLREnumClass_Binding.Register(app);
System_IComparable_1_Int32_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int32_Int32_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int32_Int32_Binding_Enumerator_Binding.Register(app);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

using ILRuntime.CLR.TypeSystem;
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using ILRuntime.Runtime.Stack;
using ILRuntime.Reflection;
using ILRuntime.CLR.Utils;

namespace ILRuntime.Runtime.Generated
{
unsafe class ILRuntimeTest_TestFramework_TestCLREnumClass_Binding
{
public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
{
BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
MethodBase method;
FieldInfo field;
Type[] args;
Type type = typeof(ILRuntimeTest.TestFramework.TestCLREnumClass);
args = new Type[]{};
method = type.GetMethod("get_Test2", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Test2_0);

field = type.GetField("Test", flag);
app.RegisterCLRFieldGetter(field, get_Test_0);
app.RegisterCLRFieldSetter(field, set_Test_0);


}


static StackObject* get_Test2_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* __ret = ILIntepreter.Minus(__esp, 0);


var result_of_this_method = ILRuntimeTest.TestFramework.TestCLREnumClass.Test2;

return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}


static object get_Test_0(ref object o)
{
return ILRuntimeTest.TestFramework.TestCLREnumClass.Test;
}
static void set_Test_0(ref object o, object v)
{
ILRuntimeTest.TestFramework.TestCLREnumClass.Test = (ILRuntimeTest.TestFramework.TestCLREnum)v;
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

using ILRuntime.CLR.TypeSystem;
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using ILRuntime.Runtime.Stack;
using ILRuntime.Reflection;
using ILRuntime.CLR.Utils;

namespace ILRuntime.Runtime.Generated
{
unsafe class ILRuntimeTest_TestFramework_TestVector3NoBinding_Binding
{
public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
{
BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
MethodBase method;
FieldInfo field;
Type[] args;
Type type = typeof(ILRuntimeTest.TestFramework.TestVector3NoBinding);

field = type.GetField("y", flag);
app.RegisterCLRFieldGetter(field, get_y_0);
app.RegisterCLRFieldSetter(field, set_y_0);

app.RegisterCLRMemberwiseClone(type, PerformMemberwiseClone);

app.RegisterCLRCreateDefaultInstance(type, () => new ILRuntimeTest.TestFramework.TestVector3NoBinding());

args = new Type[]{typeof(System.Single), typeof(System.Single), typeof(System.Single)};
method = type.GetConstructor(flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Ctor_0);

}

static void WriteBackInstance(ILRuntime.Runtime.Enviorment.AppDomain __domain, StackObject* ptr_of_this_method, IList<object> __mStack, ref ILRuntimeTest.TestFramework.TestVector3NoBinding instance_of_this_method)
{
ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
switch(ptr_of_this_method->ObjectType)
{
case ObjectTypes.Object:
{
__mStack[ptr_of_this_method->Value] = instance_of_this_method;
}
break;
case ObjectTypes.FieldReference:
{
var ___obj = __mStack[ptr_of_this_method->Value];
if(___obj is ILTypeInstance)
{
((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method;
}
else
{
var t = __domain.GetType(___obj.GetType()) as CLRType;
t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method);
}
}
break;
case ObjectTypes.StaticFieldReference:
{
var t = __domain.GetType(ptr_of_this_method->Value);
if(t is ILType)
{
((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method;
}
else
{
((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method);
}
}
break;
case ObjectTypes.ArrayReference:
{
var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as ILRuntimeTest.TestFramework.TestVector3NoBinding[];
instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method;
}
break;
}
}


static object get_y_0(ref object o)
{
return ((ILRuntimeTest.TestFramework.TestVector3NoBinding)o).y;
}
static void set_y_0(ref object o, object v)
{
var h = GCHandle.Alloc(o, GCHandleType.Pinned);
ILRuntimeTest.TestFramework.TestVector3NoBinding* p = (ILRuntimeTest.TestFramework.TestVector3NoBinding *)(void *)h.AddrOfPinnedObject();
p->y = (System.Single)v;
h.Free();
}

static object PerformMemberwiseClone(ref object o)
{
var ins = new ILRuntimeTest.TestFramework.TestVector3NoBinding();
ins = (ILRuntimeTest.TestFramework.TestVector3NoBinding)o;
return ins;
}

static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 3);
ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Single @z = *(float*)&ptr_of_this_method->Value;

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Single @y = *(float*)&ptr_of_this_method->Value;

ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
System.Single @x = *(float*)&ptr_of_this_method->Value;


var result_of_this_method = new ILRuntimeTest.TestFramework.TestVector3NoBinding(@x, @y, @z);

if(!isNewObj)
{
__ret--;
WriteBackInstance(__domain, __ret, __mStack, ref result_of_this_method);
return __ret;
}

return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

using ILRuntime.CLR.TypeSystem;
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using ILRuntime.Runtime.Stack;
using ILRuntime.Reflection;
using ILRuntime.CLR.Utils;

namespace ILRuntime.Runtime.Generated
{
unsafe class System_AccessViolationException_Binding
{
public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
{
BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
MethodBase method;
Type[] args;
Type type = typeof(System.AccessViolationException);

args = new Type[]{};
method = type.GetConstructor(flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Ctor_0);

}



static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* __ret = ILIntepreter.Minus(__esp, 0);

var result_of_this_method = new System.AccessViolationException();

return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}


}
}
48 changes: 24 additions & 24 deletions ILRuntimeTest/AutoGenerate/System_Array_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
args = new Type[]{};
method = type.GetMethod("GetEnumerator", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, GetEnumerator_1);
args = new Type[]{};
method = type.GetMethod("get_Length", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Length_2);
args = new Type[]{typeof(System.Type), typeof(System.Int32)};
method = type.GetMethod("CreateInstance", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, CreateInstance_2);
app.RegisterCLRMethodRedirection(method, CreateInstance_3);
args = new Type[]{typeof(System.Object), typeof(System.Int32)};
method = type.GetMethod("SetValue", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, SetValue_3);
args = new Type[]{};
method = type.GetMethod("get_Length", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Length_4);
app.RegisterCLRMethodRedirection(method, SetValue_4);
args = new Type[]{typeof(System.Byte)};
if (genericMethods.TryGetValue("IndexOf", out lst))
{
Expand Down Expand Up @@ -135,7 +135,24 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}

static StackObject* CreateInstance_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
static StackObject* get_Length_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 1);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Array instance_of_this_method = (System.Array)typeof(System.Array).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);

var result_of_this_method = instance_of_this_method.Length;

__ret->ObjectType = ObjectTypes.Integer;
__ret->Value = result_of_this_method;
return __ret + 1;
}

static StackObject* CreateInstance_3(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
Expand All @@ -154,7 +171,7 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}

static StackObject* SetValue_3(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
static StackObject* SetValue_4(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
Expand All @@ -176,23 +193,6 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
return __ret;
}

static StackObject* get_Length_4(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 1);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Array instance_of_this_method = (System.Array)typeof(System.Array).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);

var result_of_this_method = instance_of_this_method.Length;

__ret->ObjectType = ObjectTypes.Integer;
__ret->Value = result_of_this_method;
return __ret + 1;
}

static StackObject* IndexOf_5(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
args = new Type[]{typeof(System.Int32)};
method = type.GetMethod("Add", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Add_0);
args = new Type[]{typeof(System.Int32)};
method = type.GetMethod("get_Item", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Item_1);

args = new Type[]{};
method = type.GetConstructor(flag, null, args, null);
Expand All @@ -51,6 +54,26 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
return __ret;
}

static StackObject* get_Item_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 2);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Int32 @index = ptr_of_this_method->Value;

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Collections.Generic.List<System.Int32> instance_of_this_method = (System.Collections.Generic.List<System.Int32>)typeof(System.Collections.Generic.List<System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);

var result_of_this_method = instance_of_this_method[index];

__ret->ObjectType = ObjectTypes.Integer;
__ret->Value = result_of_this_method;
return __ret + 1;
}


static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
Expand Down
Loading

0 comments on commit d32dcc7

Please sign in to comment.