InterpreterUtil.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #if HYBRIDCLR_UNITY_2023_OR_NEW
  3. #include "codegen/il2cpp-codegen.h"
  4. #else
  5. #include "codegen/il2cpp-codegen-il2cpp.h"
  6. #endif
  7. #include "InterpreterDefs.h"
  8. namespace hybridclr
  9. {
  10. namespace interpreter
  11. {
  12. struct TypeDesc
  13. {
  14. LocationDataType type;
  15. uint32_t stackObjectSize; //
  16. };
  17. IL2CPP_FORCE_INLINE void RuntimeInitClassCCtor(Il2CppClass* klass)
  18. {
  19. il2cpp::vm::ClassInlines::InitFromCodegen(klass);
  20. if (!IS_CCTOR_FINISH_OR_NO_CCTOR(klass))
  21. {
  22. il2cpp_codegen_runtime_class_init(klass);
  23. }
  24. }
  25. IL2CPP_FORCE_INLINE void RuntimeInitClassCCtor(const MethodInfo* method)
  26. {
  27. RuntimeInitClassCCtor(method->klass);
  28. }
  29. IL2CPP_FORCE_INLINE void RuntimeInitClassCCtorWithoutInitClass(Il2CppClass* klass)
  30. {
  31. if (!IS_CCTOR_FINISH_OR_NO_CCTOR(klass))
  32. {
  33. il2cpp_codegen_runtime_class_init(klass);
  34. }
  35. }
  36. IL2CPP_FORCE_INLINE void RuntimeInitClassCCtorWithoutInitClass(const MethodInfo* method)
  37. {
  38. RuntimeInitClassCCtorWithoutInitClass(method->klass);
  39. }
  40. inline bool IsNeedExpandLocationType(LocationDataType type)
  41. {
  42. return type < LocationDataType::U8;
  43. }
  44. TypeDesc GetTypeArgDesc(const Il2CppType* type);
  45. inline LocationDataType GetLocationDataTypeByType(const Il2CppType* type)
  46. {
  47. return GetTypeArgDesc(type).type;
  48. }
  49. inline void ExpandLocationData2StackDataByType(void* retValue, LocationDataType type)
  50. {
  51. switch (type)
  52. {
  53. case LocationDataType::I1:
  54. *(int32_t*)retValue = *(int8_t*)retValue;
  55. break;
  56. case LocationDataType::U1:
  57. *(int32_t*)retValue = *(uint8_t*)retValue;
  58. break;
  59. case LocationDataType::I2:
  60. *(int32_t*)retValue = *(int16_t*)retValue;
  61. break;
  62. case LocationDataType::U2:
  63. *(int32_t*)retValue = *(uint16_t*)retValue;
  64. break;
  65. default:
  66. break;
  67. }
  68. }
  69. inline void CopyLocationData2StackDataByType(StackObject* dst, StackObject* src, LocationDataType type)
  70. {
  71. switch (type)
  72. {
  73. case LocationDataType::I1:
  74. *(int32_t*)dst = *(int8_t*)src;
  75. break;
  76. case LocationDataType::U1:
  77. *(int32_t*)dst = *(uint8_t*)src;
  78. break;
  79. case LocationDataType::I2:
  80. *(int32_t*)dst = *(int16_t*)src;
  81. break;
  82. case LocationDataType::U2:
  83. *(int32_t*)dst = *(uint16_t*)src;
  84. break;
  85. default:
  86. *dst = *src;
  87. break;
  88. }
  89. }
  90. TypeDesc GetValueTypeArgDescBySize(uint32_t size);
  91. Il2CppObject* TranslateNativeValueToBoxValue(const Il2CppType* type, void* value);
  92. }
  93. }