1#include "backend/WebAssembly.hpp"
23 auto result = BinaryenModuleAllocateAndWrite(
ref_,
nullptr);
24 return std::make_pair(
reinterpret_cast<uint8_t*
>(result.binary), result.binaryBytes);
30 auto result = BinaryenModuleAllocateAndWriteText(module.
ref_);
38 auto [buffer, length] =
binary();
39 out <<
'[' << std::hex;
40 for (
auto ptr = buffer, end = buffer + length; ptr != end; ++ptr) {
41 if (ptr != buffer) out <<
", ";
42 out <<
"0x" << uint32_t(*ptr);
45 out <<
']' << std::endl;
73 const std::size_t num_instances = (table.
store().
num_rows() + num_rows_per_instance - 1) / num_rows_per_instance;
74 const std::size_t bytes = instance_stride_in_bytes * num_instances;
77 const auto off = heap;
81 mem.
map(aligned_bytes, 0, vm, off);
82 heap += aligned_bytes;
93 if (not config(TRAP_GUARD_PAGES)) {
95 M_DISCARD mmap(vm.as<uint8_t*>() + heap,
get_pagesize(), PROT_READ, MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
std::size_t Is_Page_Aligned(std::size_t n)
Returns true iff n is a integral multiple of the page size (in bytes).
std::size_t M_EXPORT get_pagesize()
Returns the page size of the system.
M_LCOV_EXCL_START std::ostream & operator<<(std::ostream &out, const PlanTableBase< Actual > &PT)
std::size_t Ceil_To_Next_Page(std::size_t n)
Returns the smallest integral multiple of the page size (in bytes) greater than or equals to n.
void register_wasm_operators(PhysicalOptimizer &phys_opt)
Registers physical Wasm operators in phys_opt depending on the set CLI options.
The physical optimizer interface.
virtual const memory::Memory & memory() const =0
Returns the memory corresponding to the Linearization's root node.
virtual std::size_t num_rows() const =0
Return the number of rows in this store.
A table is a sorted set of attributes.
virtual const storage::DataLayout & layout() const =0
Returns a reference to the physical data layout.
virtual Store & store() const =0
Returns a reference to the backing store.
void register_operators(PhysicalOptimizer &phys_opt) const override
Registers all physical operators of this Backend in phys_opt.
void execute(const MatchBase &plan) const override
Executes the already computed physical covering represented by plan using this Backend.
void install_guard_page()
Installs a guard page at the current heap and increments heap to the next page.
uint32_t map_table(const Table &table)
Maps a table at the current start of heap and advances heap past the mapped region.
WasmContext(uint32_t id, const MatchBase &plan, config_t configuration, std::size_t size)
static constexpr std::size_t WASM_MAX_MEMORY
The maximum memory of a WebAssembly module: 2^32 - 2^16 bytes ≈ 4 GiB.
A WasmModule is a wrapper around a [Binaryen] (https://github.com/WebAssembly/binaryen) wasm::Module.
std::pair< uint8_t *, std::size_t > binary() const
Returns the binary representation of this module in a freshly allocated memory.
::wasm::Module * ref_
the underlying [Binaryen] (https://github.com/WebAssembly/binaryen) WASM module
void map(std::size_t size, std::size_t offset_src, const AddressSpace &vm, std::size_t offset_dst) const
Map size bytes starting at offset_src into the address space of vm at offset offset_dst.
virtual size_type num_tuples() const =0
returns the number of tuples represented by an instance of this node
uint64_t stride_in_bits() const
return the stride (in bits) of the single child of the DataLayout
const Node & child() const
returns a reference to the single child of this DataLayout