Created
November 30, 2015 05:26
-
-
Save kornman00/ee492ba57bb721df988d to your computer and use it in GitHub Desktop.
Code Listings for Seeing Sharp C++: The Il2CppSetOption attribute
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
extern TypeInfo* Int32U5BU5D_t1872284309_0_il2cpp_TypeInfo_var; | |
// NOTE: 'Int32U5BU5D_t1872284309_0' is to IL2CPP as 'int[]' is to C# | |
// System.Int32 SharpCpp.SharpCode::Il2CppSetOption_ChecksEnabled() | |
extern "C" int32_t SharpCode_Il2CppSetOption_ChecksEnabled_m_1098767581_0 (Object_t * __this /* static, unused */, const MethodInfo* method) | |
{ | |
Int32U5BU5D_t1872284309_0* V_0 = {0}; | |
{ | |
//var array = new int[1]; | |
V_0 = ((Int32U5BU5D_t1872284309_0*)SZArrayNew(Int32U5BU5D_t1872284309_0_il2cpp_TypeInfo_var, (uint32_t)1)); | |
Int32U5BU5D_t1872284309_0* L_0 = V_0; | |
NullCheck(L_0); // NOTE: Removed with Il2CppSetOption | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_0, 0); // NOTE: Removed with Il2CppSetOption | |
//address of array[0] | |
int32_t* L_1 = ((int32_t*)(int32_t*)SZArrayLdElema(L_0, 0, sizeof(int32_t))); | |
//array[0] *= 1; | |
*((int32_t*)(L_1)) = (int32_t)((int32_t)((int32_t)(*((int32_t*)L_1))*(int32_t)1)); | |
//return array[2]; | |
Int32U5BU5D_t1872284309_0* L_2 = V_0; | |
NullCheck(L_2); // NOTE: Removed with Il2CppSetOption | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_2, 2); // NOTE: Removed with Il2CppSetOption | |
int32_t L_3 = 2; | |
return (*(int32_t*)(int32_t*)SZArrayLdElema(L_2, L_3, sizeof(int32_t))); | |
} | |
} | |
// System.Int32 SharpCpp.SharpCode::Il2CppSetOption_ChecksDisabled() | |
extern "C" int32_t SharpCode_Il2CppSetOption_ChecksDisabled_m1080366460_0 (Object_t * __this /* static, unused */, const MethodInfo* method) | |
{ | |
Int32U5BU5D_t1872284309_0* V_0 = {0}; | |
{ | |
//var array = new int[1]; | |
V_0 = ((Int32U5BU5D_t1872284309_0*)SZArrayNew(Int32U5BU5D_t1872284309_0_il2cpp_TypeInfo_var, (uint32_t)1)); | |
Int32U5BU5D_t1872284309_0* L_0 = V_0; | |
//address of array[0] | |
int32_t* L_1 = ((int32_t*)(int32_t*)SZArrayLdElema(L_0, 0, sizeof(int32_t))); | |
//array[0] *= 1; | |
*((int32_t*)(L_1)) = (int32_t)((int32_t)((int32_t)(*((int32_t*)L_1))*(int32_t)1)); | |
//return array[2]; | |
Int32U5BU5D_t1872284309_0* L_2 = V_0; | |
int32_t L_3 = 2; | |
return (*(int32_t*)(int32_t*)SZArrayLdElema(L_2, L_3, sizeof(int32_t))); | |
} | |
} | |
// System.Int32 SharpCpp.SharpCode::Il2CppSetOption_ChecksEnabledMegaLogic() | |
extern "C" int32_t SharpCode_Il2CppSetOption_ChecksEnabledMegaLogic_m637461515_0 (Object_t * __this /* static, unused */, const MethodInfo* method) | |
{ | |
Int32U5BU5D_t1872284309_0* V_0 = {0}; | |
{ | |
V_0 = ((Int32U5BU5D_t1872284309_0*)SZArrayNew(Int32U5BU5D_t1872284309_0_il2cpp_TypeInfo_var, (uint32_t)5)); | |
Int32U5BU5D_t1872284309_0* L_0 = V_0; | |
NullCheck(L_0); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_0, 1); | |
int32_t* L_1 = ((int32_t*)(int32_t*)SZArrayLdElema(L_0, 1, sizeof(int32_t))); | |
Int32U5BU5D_t1872284309_0* L_2 = V_0; | |
NullCheck(L_2); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_2, 0); | |
int32_t L_3 = 0; | |
*((int32_t*)(L_1)) = (int32_t)((int32_t)((int32_t)(*((int32_t*)L_1))*(int32_t)(*(int32_t*)(int32_t*)SZArrayLdElema(L_2, L_3, sizeof(int32_t))))); | |
Int32U5BU5D_t1872284309_0* L_4 = V_0; | |
NullCheck(L_4); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_4, 2); | |
int32_t* L_5 = ((int32_t*)(int32_t*)SZArrayLdElema(L_4, 2, sizeof(int32_t))); | |
Int32U5BU5D_t1872284309_0* L_6 = V_0; | |
NullCheck(L_6); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_6, 1); | |
int32_t L_7 = 1; | |
*((int32_t*)(L_5)) = (int32_t)((int32_t)((int32_t)(*((int32_t*)L_5))*(int32_t)(*(int32_t*)(int32_t*)SZArrayLdElema(L_6, L_7, sizeof(int32_t))))); | |
Int32U5BU5D_t1872284309_0* L_8 = V_0; | |
NullCheck(L_8); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_8, 3); | |
int32_t* L_9 = ((int32_t*)(int32_t*)SZArrayLdElema(L_8, 3, sizeof(int32_t))); | |
Int32U5BU5D_t1872284309_0* L_10 = V_0; | |
NullCheck(L_10); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_10, 2); | |
int32_t L_11 = 2; | |
*((int32_t*)(L_9)) = (int32_t)((int32_t)((int32_t)(*((int32_t*)L_9))*(int32_t)(*(int32_t*)(int32_t*)SZArrayLdElema(L_10, L_11, sizeof(int32_t))))); | |
Int32U5BU5D_t1872284309_0* L_12 = V_0; | |
NullCheck(L_12); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_12, 4); | |
int32_t* L_13 = ((int32_t*)(int32_t*)SZArrayLdElema(L_12, 4, sizeof(int32_t))); | |
Int32U5BU5D_t1872284309_0* L_14 = V_0; | |
NullCheck(L_14); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_14, 3); | |
int32_t L_15 = 3; | |
*((int32_t*)(L_13)) = (int32_t)((int32_t)((int32_t)(*((int32_t*)L_13))*(int32_t)(*(int32_t*)(int32_t*)SZArrayLdElema(L_14, L_15, sizeof(int32_t))))); | |
Int32U5BU5D_t1872284309_0* L_16 = V_0; | |
NullCheck(L_16); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_16, 2); | |
int32_t L_17 = 2; | |
return (*(int32_t*)(int32_t*)SZArrayLdElema(L_16, L_17, sizeof(int32_t))); | |
} | |
} |
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
using System; | |
using Unity.IL2CPP.CompilerServices; | |
namespace SharpCpp | |
{ | |
public static partial class SharpCode | |
{ | |
public static int Il2CppSetOption_ChecksEnabled() | |
{ | |
var array = new int[1]; | |
array[0] *= 1; | |
return array[2]; | |
} | |
[Il2CppSetOption(Option.NullChecks, false)] | |
[Il2CppSetOption(Option.ArrayBoundsChecks, false)] | |
public static int Il2CppSetOption_ChecksDisabled() | |
{ | |
var array = new int[1]; | |
array[0] *= 1; | |
return array[2]; | |
} | |
public static int Il2CppSetOption_ChecksEnabledMegaLogic() | |
{ | |
var array = new int[5]; | |
array[1] *= array[0]; | |
array[2] *= array[1]; | |
array[3] *= array[2]; | |
array[4] *= array[3]; | |
return array[2]; | |
} | |
}; | |
} |
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
// These can all be found in %UNITY_INSTALL_DIR%/Editor/Data/il2cpp/libil2cpp/codegen/il2cpp-codegen.h | |
inline void NullCheck (void* this_ptr) | |
{ | |
if(this_ptr != NULL) | |
return; | |
il2cpp::vm::Exception::RaiseNullReferenceException (); | |
#if __has_builtin(__builtin_unreachable) | |
__builtin_unreachable(); | |
#endif | |
} | |
// Performance optimization as detailed here: http://blogs.msdn.com/b/clrcodegeneration/archive/2009/08/13/array-bounds-check-elimination-in-the-clr.aspx | |
// Since array size is a signed int32_t, a single unsigned check can be performed to determine if index is less than array size. | |
// Negative indices will map to a unsigned number greater than or equal to 2^31 which is larger than allowed for a valid array. | |
#define IL2CPP_ARRAY_BOUNDS_CHECK(a,index) \ | |
do { \ | |
if (((uint32_t)(index)) >= ((uint32_t)(a)->max_length)) il2cpp::vm::Exception::Raise (il2cpp::vm::Exception::GetIndexOutOfRangeException()); \ | |
} while (0) | |
#if IL2CPP_DEBUG | |
static inline void* SZArrayLdElema (Il2CppCodeGenArray* arr, uint32_t index, size_t size) | |
{ | |
TypeInfo* arrayKlass = arr->_typeInfo; | |
assert (size == arr->_typeInfo->element_size); | |
return (void*)(((uint8_t*)(arr)) + sizeof (Il2CppCodeGenArray) + (arrayKlass->element_size * (index))); | |
} | |
#else | |
#define SZArrayLdElema(a,index,size)\ | |
(void*)(((uint8_t*)(a)) + sizeof (Il2CppCodeGenArray) + ((size) * (index))) | |
#endif |
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
.class public auto ansi abstract sealed beforefieldinit SharpCpp.SharpCode | |
extends [mscorlib]System.Object | |
{ | |
// Methods | |
.method public hidebysig static | |
int32 Il2CppSetOption_ChecksEnabled () cil managed | |
{ | |
// Method begins at RVA 0x21f8 | |
// Code size 23 (0x17) | |
.maxstack 3 | |
.locals init ( | |
[0] int32[] | |
) | |
IL_0000: ldc.i4.1 | |
IL_0001: newarr [mscorlib]System.Int32 | |
IL_0006: stloc.0 | |
IL_0007: ldloc.0 | |
IL_0008: ldc.i4.0 | |
IL_0009: ldelema [mscorlib]System.Int32 | |
IL_000e: dup | |
IL_000f: ldind.i4 | |
IL_0010: ldc.i4.1 | |
IL_0011: mul | |
IL_0012: stind.i4 | |
IL_0013: ldloc.0 | |
IL_0014: ldc.i4.2 | |
IL_0015: ldelem.i4 | |
IL_0016: ret | |
} // end of method SharpCode::Il2CppSetOption_ChecksEnabled | |
.method public hidebysig static | |
int32 Il2CppSetOption_ChecksDisabled () cil managed | |
{ | |
.custom instance void Unity.IL2CPP.CompilerServices.Il2CppSetOptionAttribute::.ctor(valuetype Unity.IL2CPP.CompilerServices.Option, object) = ( | |
01 00 02 00 00 00 02 00 00 00 | |
) | |
.custom instance void Unity.IL2CPP.CompilerServices.Il2CppSetOptionAttribute::.ctor(valuetype Unity.IL2CPP.CompilerServices.Option, object) = ( | |
01 00 01 00 00 00 02 00 00 00 | |
) | |
// Method begins at RVA 0x221c | |
// Code size 23 (0x17) | |
.maxstack 3 | |
.locals init ( | |
[0] int32[] | |
) | |
IL_0000: ldc.i4.1 | |
IL_0001: newarr [mscorlib]System.Int32 | |
IL_0006: stloc.0 | |
IL_0007: ldloc.0 | |
IL_0008: ldc.i4.0 | |
IL_0009: ldelema [mscorlib]System.Int32 | |
IL_000e: dup | |
IL_000f: ldind.i4 | |
IL_0010: ldc.i4.1 | |
IL_0011: mul | |
IL_0012: stind.i4 | |
IL_0013: ldloc.0 | |
IL_0014: ldc.i4.2 | |
IL_0015: ldelem.i4 | |
IL_0016: ret | |
} // end of method SharpCode::Il2CppSetOption_ChecksDisabled | |
} // end of class SharpCpp.SharpCode |
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
// System.Int32 SharpCpp.SharpCode::Il2CppSetOption_ChecksEnabled() | |
extern "C" int32_t SharpCode_Il2CppSetOption_ChecksEnabled_m556003755_0 (Object_t * __this /* static, unused */, const MethodInfo* method) | |
{ | |
Int32U5BU5D_t1496069209_0* V_0 = {0}; | |
int32_t V_1 = 0; | |
{ | |
V_0 = ((Int32U5BU5D_t1496069209_0*)SZArrayNew(Int32U5BU5D_t1496069209_0_il2cpp_TypeInfo_var, (uint32_t)1)); | |
Int32U5BU5D_t1496069209_0* L_0 = V_0; | |
NullCheck(L_0); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_0, 0); | |
int32_t* L_1 = ((int32_t*)(int32_t*)SZArrayLdElema(L_0, 0, sizeof(int32_t))); | |
(*(int32_t*)L_1) = (*(int32_t*)L_1); | |
Int32U5BU5D_t1496069209_0* L_2 = V_0; | |
NullCheck(L_2); | |
IL2CPP_ARRAY_BOUNDS_CHECK(L_2, 2); | |
int32_t L_3 = 2; | |
V_1 = (*(int32_t*)(int32_t*)SZArrayLdElema(L_2, L_3, sizeof(int32_t))); | |
goto IL_0020; | |
} | |
IL_0020: | |
{ | |
int32_t L_4 = V_1; | |
return L_4; | |
} | |
} | |
// System.Int32 SharpCpp.SharpCode::Il2CppSetOption_ChecksDisabled() | |
extern "C" int32_t SharpCode_Il2CppSetOption_ChecksDisabled_m1749734762_0 (Object_t * __this /* static, unused */, const MethodInfo* method) | |
{ | |
Int32U5BU5D_t1496069209_0* V_0 = {0}; | |
int32_t V_1 = 0; | |
{ | |
V_0 = ((Int32U5BU5D_t1496069209_0*)SZArrayNew(Int32U5BU5D_t1496069209_0_il2cpp_TypeInfo_var, (uint32_t)1)); | |
Int32U5BU5D_t1496069209_0* L_0 = V_0; | |
int32_t* L_1 = ((int32_t*)(int32_t*)SZArrayLdElema(L_0, 0, sizeof(int32_t))); | |
(*(int32_t*)L_1) = (*(int32_t*)L_1); | |
Int32U5BU5D_t1496069209_0* L_2 = V_0; | |
int32_t L_3 = 2; | |
V_1 = (*(int32_t*)(int32_t*)SZArrayLdElema(L_2, L_3, sizeof(int32_t))); | |
goto IL_0020; | |
} | |
IL_0020: | |
{ | |
int32_t L_4 = V_1; | |
return L_4; | |
} | |
} |
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
.class public auto ansi abstract sealed beforefieldinit SharpCpp.SharpCode | |
extends [mscorlib]System.Object | |
{ | |
// Methods | |
.method public hidebysig static | |
int32 Il2CppSetOption_ChecksEnabled () cil managed | |
{ | |
// Method begins at RVA 0x221c | |
// Code size 34 (0x22) | |
.maxstack 2 | |
.locals init ( | |
[0] int32[] 'array', | |
[1] int32 CS$1$0000 | |
) | |
IL_0000: nop | |
IL_0001: ldc.i4.1 | |
IL_0002: newarr [mscorlib]System.Int32 | |
IL_0007: stloc.0 | |
IL_0008: ldloc.0 | |
IL_0009: ldc.i4.0 | |
IL_000a: ldelema [mscorlib]System.Int32 | |
IL_000f: dup | |
IL_0010: ldobj [mscorlib]System.Int32 | |
IL_0015: stobj [mscorlib]System.Int32 | |
IL_001a: ldloc.0 | |
IL_001b: ldc.i4.2 | |
IL_001c: ldelem.i4 | |
IL_001d: stloc.1 | |
IL_001e: br.s IL_0020 | |
IL_0020: ldloc.1 | |
IL_0021: ret | |
} // end of method SharpCode::Il2CppSetOption_ChecksEnabled | |
.method public hidebysig static | |
int32 Il2CppSetOption_ChecksDisabled () cil managed | |
{ | |
.custom instance void Unity.IL2CPP.CompilerServices.Il2CppSetOptionAttribute::.ctor(valuetype Unity.IL2CPP.CompilerServices.Option, object) = ( | |
01 00 01 00 00 00 02 00 00 00 | |
) | |
.custom instance void Unity.IL2CPP.CompilerServices.Il2CppSetOptionAttribute::.ctor(valuetype Unity.IL2CPP.CompilerServices.Option, object) = ( | |
01 00 02 00 00 00 02 00 00 00 | |
) | |
// Method begins at RVA 0x224c | |
// Code size 34 (0x22) | |
.maxstack 2 | |
.locals init ( | |
[0] int32[] 'array', | |
[1] int32 CS$1$0000 | |
) | |
IL_0000: nop | |
IL_0001: ldc.i4.1 | |
IL_0002: newarr [mscorlib]System.Int32 | |
IL_0007: stloc.0 | |
IL_0008: ldloc.0 | |
IL_0009: ldc.i4.0 | |
IL_000a: ldelema [mscorlib]System.Int32 | |
IL_000f: dup | |
IL_0010: ldobj [mscorlib]System.Int32 | |
IL_0015: stobj [mscorlib]System.Int32 | |
IL_001a: ldloc.0 | |
IL_001b: ldc.i4.2 | |
IL_001c: ldelem.i4 | |
IL_001d: stloc.1 | |
IL_001e: br.s IL_0020 | |
IL_0020: ldloc.1 | |
IL_0021: ret | |
} // end of method SharpCode::Il2CppSetOption_ChecksDisabled | |
} // end of class SharpCpp.SharpCode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment