InterpreterUtil.h 2.2 KB

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