WasmCustomReader.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. WasmCustomReader::WasmCustomReader(ArenaAllocator* alloc) : m_nodes(alloc)
  10. {
  11. }
  12. void WasmCustomReader::SeekToFunctionBody(class WasmFunctionInfo* funcInfo)
  13. {
  14. Assert(funcInfo->GetCustomReader() == this);
  15. m_state = 0;
  16. }
  17. bool WasmCustomReader::IsCurrentFunctionCompleted() const
  18. {
  19. return m_state >= (uint32)m_nodes.Count();
  20. }
  21. WasmOp WasmCustomReader::ReadExpr()
  22. {
  23. if (m_state < (uint32)m_nodes.Count())
  24. {
  25. m_currentNode = m_nodes.Item(m_state++);
  26. return m_currentNode.op;
  27. }
  28. return wbEnd;
  29. }
  30. void WasmCustomReader::FunctionEnd()
  31. {
  32. }
  33. void WasmCustomReader::AddNode(WasmNode node)
  34. {
  35. m_nodes.Add(node);
  36. }
  37. const uint32 WasmCustomReader::EstimateCurrentFunctionBytecodeSize() const
  38. {
  39. uint32 count = min((uint32)m_nodes.Count(), (uint32)AutoSystemInfo::PageSize);
  40. // On average each node takes between 3 - 7 bytes to encode
  41. return count * 5;
  42. }
  43. };
  44. #endif