WebAssemblyEnvironment.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 WasmGlobal;
  9. struct WasmConstLitNode;
  10. }
  11. namespace Js
  12. {
  13. class WebAssemblyModule;
  14. class WebAssemblyTable;
  15. class WebAssemblyMemory;
  16. class WebAssemblyEnvironment
  17. {
  18. public:
  19. WebAssemblyEnvironment(WebAssemblyModule* module);
  20. Field(Var)* GetStartPtr() const { return start; }
  21. WasmScriptFunction* GetWasmFunction(uint32 index) const;
  22. void SetWasmFunction(uint32 index, WasmScriptFunction* func);
  23. void SetImportedFunction(uint32 index, Var importedFunc);
  24. WebAssemblyTable* GetTable(uint32 index) const;
  25. void SetTable(uint32 index, class WebAssemblyTable* table);
  26. WebAssemblyMemory* GetMemory(uint32 index) const;
  27. void SetMemory(uint32 index, WebAssemblyMemory* mem);
  28. Wasm::WasmConstLitNode GetGlobalValue(Wasm::WasmGlobal* global) const;
  29. void SetGlobalValue(class Wasm::WasmGlobal* global, Wasm::WasmConstLitNode cnst);
  30. void CalculateOffsets(WebAssemblyTable* table, WebAssemblyMemory* memory);
  31. uint32 GetElementSegmentOffset(uint32 index) const;
  32. uint32 GetDataSegmentOffset(uint32 index) const;
  33. private:
  34. Field(WebAssemblyModule*) module;
  35. Field(Field(Var)*) start;
  36. Field(Field(Var)*) end;
  37. // Precalculated pointer from ptr using the offsets
  38. Field(Field(Var)*) memory;
  39. Field(Field(Var)*) imports;
  40. Field(Field(Var)*) functions;
  41. Field(Field(Var)*) table;
  42. Field(Field(Var)*) globals;
  43. uint32* elementSegmentOffsets;
  44. uint32* dataSegmentOffsets;
  45. DebugOnly(bool offsetInitialized = false);
  46. ArenaAllocator m_alloc;
  47. private:
  48. template<typename T> void CheckPtrIsValid(intptr_t ptr) const;
  49. template<typename T> T* GetVarElement(Field(Var)* ptr, uint32 index, uint32 maxCount) const;
  50. template<typename T> void SetVarElement(Field(Var)* ptr, T* val, uint32 index, uint32 maxCount);
  51. template<typename T> T GetGlobalInternal(uint32 offset) const;
  52. template<typename T> void SetGlobalInternal(uint32 offset, T val);
  53. };
  54. } // namespace Js