WasmByteCodeWriter.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Copyright (c) ChakraCore Project Contributors. All rights reserved.
  4. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. //-------------------------------------------------------------------------------------------------------
  6. #include "RuntimeByteCodePch.h"
  7. #ifdef ENABLE_WASM
  8. #include "WasmByteCodeWriter.h"
  9. #define WASM_BYTECODE_WRITER
  10. #define AsmJsByteCodeWriter WasmByteCodeWriter
  11. #include "ByteCode/AsmJsByteCodeWriter.cpp"
  12. #undef WASM_BYTECODE_WRITER
  13. #undef AsmJsByteCodeWriter
  14. namespace Js
  15. {
  16. void WasmByteCodeWriter::Create()
  17. {
  18. ByteCodeWriter::Create();
  19. }
  20. void WasmByteCodeWriter::End()
  21. {
  22. ByteCodeWriter::End();
  23. }
  24. void WasmByteCodeWriter::Reset()
  25. {
  26. ByteCodeWriter::Reset();
  27. }
  28. void WasmByteCodeWriter::Begin(FunctionBody* functionWrite, ArenaAllocator* alloc)
  29. {
  30. ByteCodeWriter::Begin(functionWrite, alloc, true, true, false);
  31. }
  32. ByteCodeLabel WasmByteCodeWriter::DefineLabel()
  33. {
  34. return ByteCodeWriter::DefineLabel();
  35. }
  36. void WasmByteCodeWriter::SetCallSiteCount(Js::ProfileId callSiteCount)
  37. {
  38. ByteCodeWriter::SetCallSiteCount(callSiteCount);
  39. }
  40. uint32 WasmByteCodeWriter::WasmLoopStart(ByteCodeLabel loopEntrance, __in_ecount(WAsmJs::LIMIT) RegSlot* curRegs)
  41. {
  42. uint loopId = m_functionWrite->IncrLoopCount();
  43. Assert((uint)m_loopHeaders->Count() == loopId);
  44. m_loopHeaders->Add(LoopHeaderData(m_byteCodeData.GetCurrentOffset(), 0, m_loopNest > 0, false));
  45. m_loopNest++;
  46. this->MarkAsmJsLabel(loopEntrance);
  47. MULTISIZE_LAYOUT_WRITE(WasmLoopStart, Js::OpCodeAsmJs::WasmLoopBodyStart, loopId, curRegs);
  48. return loopId;
  49. }
  50. template <typename SizePolicy>
  51. bool WasmByteCodeWriter::TryWriteWasmLoopStart(OpCodeAsmJs op, uint loopId, __in_ecount(WAsmJs::LIMIT) RegSlot* curRegs)
  52. {
  53. OpLayoutT_WasmLoopStart<SizePolicy> layout;
  54. if (SizePolicy::Assign(layout.loopId, loopId))
  55. {
  56. for (WAsmJs::Types type = WAsmJs::Types(0); type != WAsmJs::LIMIT; type = WAsmJs::Types(type + 1))
  57. {
  58. if (!SizePolicy::Assign(layout.curRegs[type], curRegs[type]))
  59. {
  60. return false;
  61. }
  62. }
  63. m_byteCodeData.EncodeT<SizePolicy::LayoutEnum>(op, &layout, sizeof(layout), this);
  64. return true;
  65. }
  66. return false;
  67. }
  68. }
  69. #endif