WasmFunctionInfo.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #pragma once
  6. namespace Wasm
  7. {
  8. class WasmReaderBase;
  9. // All the Wasm function's share the same reader (except when using CustomReaders)
  10. // This struct is used to remember where is this particular function in the buffer
  11. struct FunctionBodyReaderInfo
  12. {
  13. friend class WasmBinaryReader;
  14. FunctionBodyReaderInfo(uint32 size = 0, size_t startOffset = 0): size(size), startOffset(startOffset) {}
  15. private:
  16. Field(uint32) size = 0;
  17. Field(size_t) startOffset = 0;
  18. };
  19. class WasmFunctionInfo
  20. {
  21. public:
  22. WasmFunctionInfo(ArenaAllocator* alloc, WasmSignature* signature, uint32 number);
  23. void AddLocal(WasmTypes::WasmType type, uint32 count = 1);
  24. Local GetLocal(uint32 index) const;
  25. uint32 GetResultCount() const;
  26. Local GetResult(uint32 index) const;
  27. uint32 GetLocalCount() const;
  28. Js::ArgSlot GetParamCount() const;
  29. void SetName(const char16* name, uint32 nameLength) { m_name = name; m_nameLength = nameLength; }
  30. const char16* GetName() const { return m_name; }
  31. uint32 GetNameLength() const { return m_nameLength; }
  32. uint32 GetNumber() const { return m_number; }
  33. WasmSignature* GetSignature() const { return m_signature; }
  34. void SetExitLabel(Js::ByteCodeLabel label) { m_ExitLabel = label; }
  35. Js::ByteCodeLabel GetExitLabel() const { return m_ExitLabel; }
  36. Js::FunctionBody* GetBody() const { return m_body; }
  37. void SetBody(Js::FunctionBody* val) { m_body = val; }
  38. WasmReaderBase* GetCustomReader() const { return m_customReader; }
  39. void SetCustomReader(WasmReaderBase* customReader) { m_customReader = customReader; }
  40. #if DBG_DUMP
  41. FieldNoBarrier(WasmImport*) importedFunctionReference;
  42. #endif
  43. FunctionBodyReaderInfo GetReaderInfo() const
  44. {
  45. AssertMsg(!m_customReader, "ReaderInfo is not needed and invalid when a custom reader is present");
  46. return m_readerInfo;
  47. }
  48. void SetReaderInfo(FunctionBodyReaderInfo info)
  49. {
  50. AssertMsg(!m_customReader, "ReaderInfo is not needed and invalid when a custom reader is present");
  51. m_readerInfo = info;
  52. }
  53. private:
  54. FieldNoBarrier(ArenaAllocator*) m_alloc;
  55. typedef JsUtil::GrowingArray<Local, ArenaAllocator> WasmTypeArray;
  56. Field(WasmTypeArray) m_locals;
  57. Field(Js::FunctionBody*) m_body;
  58. Field(WasmSignature*) m_signature;
  59. Field(Js::ByteCodeLabel) m_ExitLabel;
  60. Field(WasmReaderBase*) m_customReader;
  61. Field(const char16*) m_name;
  62. Field(uint32) m_nameLength;
  63. Field(uint32) m_number;
  64. Field(FunctionBodyReaderInfo) m_readerInfo;
  65. };
  66. } // namespace Wasm