WasmFunctionInfo.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "WasmReaderPch.h"
  6. #ifdef ENABLE_WASM
  7. namespace Wasm
  8. {
  9. WasmFunctionInfo::WasmFunctionInfo(ArenaAllocator * alloc, WasmSignature* signature, uint32 number) :
  10. m_alloc(alloc),
  11. m_signature(signature),
  12. m_body(nullptr),
  13. m_name(nullptr),
  14. m_customReader(nullptr),
  15. m_nameLength(0),
  16. m_number(number),
  17. m_locals(alloc, signature->GetParamCount())
  18. #if DBG_DUMP
  19. , importedFunctionReference(nullptr)
  20. #endif
  21. {
  22. for (Js::ArgSlot i = 0; i < signature->GetParamCount(); ++i)
  23. {
  24. m_locals.Add(signature->GetParam(i));
  25. }
  26. }
  27. void
  28. WasmFunctionInfo::AddLocal(WasmTypes::WasmType type, uint32 count)
  29. {
  30. for (uint32 i = 0; i < count; ++i)
  31. {
  32. m_locals.Add(Wasm::Local(type));
  33. }
  34. }
  35. Local
  36. WasmFunctionInfo::GetLocal(uint32 index) const
  37. {
  38. if (index < GetLocalCount())
  39. {
  40. return m_locals.ItemInBuffer(index);
  41. }
  42. return WasmTypes::Limit;
  43. }
  44. WasmTypes::WasmType
  45. WasmFunctionInfo::GetResultType() const
  46. {
  47. return m_signature->GetResultType();
  48. }
  49. uint32
  50. WasmFunctionInfo::GetLocalCount() const
  51. {
  52. return m_locals.Count();
  53. }
  54. Js::ArgSlot
  55. WasmFunctionInfo::GetParamCount() const
  56. {
  57. return m_signature->GetParamCount();
  58. }
  59. } // namespace Wasm
  60. #endif // ENABLE_WASM