WasmElementSegment.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. 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. WasmElementSegment::WasmElementSegment(ArenaAllocator* alloc, const uint32 index, const WasmNode initExpr, const uint32 numElem) :
  10. m_alloc(alloc),
  11. m_index(index),
  12. m_offsetExpr(initExpr),
  13. m_numElem(numElem),
  14. m_offset(0),
  15. m_elemIdx(0),
  16. m_elems(nullptr)
  17. {}
  18. void WasmElementSegment::Init()
  19. {
  20. Assert(m_numElem > 0);
  21. m_elems = AnewArray(m_alloc, uint32, m_numElem);
  22. memset(m_elems, Js::Constants::UninitializedValue, m_numElem * sizeof(uint32));
  23. }
  24. void WasmElementSegment::AddElement(const uint32 funcIndex)
  25. {
  26. if (m_elems == nullptr)
  27. {
  28. Init();
  29. }
  30. Assert(m_elemIdx < m_numElem);
  31. m_elems[m_elemIdx++] = funcIndex;
  32. }
  33. uint32 WasmElementSegment::GetElement(const uint32 tableIndex) const
  34. {
  35. Assert(m_elems != nullptr);
  36. return m_elems[tableIndex];
  37. }
  38. } // namespace Wasm
  39. #endif // ENABLE_WASM