c1d01aea11
Compilation of wasm functions happens before instantiation. Imports are linked afterwards, at instantiation time. Globals and memory are also allocated and then tied in via relocation at instantiation time. This paves the way for implementing Wasm.compile, a prerequisite to offering the compiled code serialization feature. Currently, the WasmModule::Compile method just returns a fixed array containing the code objects. More appropriate modeling of the compiled module to come. Opportunistically centralized the logic on how to update memory references, size, and globals, since that logic is the exact same on each architecture, except for the actual storing of values back in the instruction stream. BUG=v8:5072 Review-Url: https://codereview.chromium.org/2056633002 Cr-Commit-Position: refs/heads/master@{#37086}
80 lines
2.0 KiB
C++
80 lines
2.0 KiB
C++
// Copyright 2011 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef V8_MEMORY_H_
|
|
#define V8_MEMORY_H_
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
// Memory provides an interface to 'raw' memory. It encapsulates the casts
|
|
// that typically are needed when incompatible pointer types are used.
|
|
|
|
class Memory {
|
|
public:
|
|
static uint8_t& uint8_at(Address addr) {
|
|
return *reinterpret_cast<uint8_t*>(addr);
|
|
}
|
|
|
|
static uint16_t& uint16_at(Address addr) {
|
|
return *reinterpret_cast<uint16_t*>(addr);
|
|
}
|
|
|
|
static uint32_t& uint32_at(Address addr) {
|
|
return *reinterpret_cast<uint32_t*>(addr);
|
|
}
|
|
|
|
static int32_t& int32_at(Address addr) {
|
|
return *reinterpret_cast<int32_t*>(addr);
|
|
}
|
|
|
|
static uint64_t& uint64_at(Address addr) {
|
|
return *reinterpret_cast<uint64_t*>(addr);
|
|
}
|
|
|
|
static int& int_at(Address addr) {
|
|
return *reinterpret_cast<int*>(addr);
|
|
}
|
|
|
|
static unsigned& unsigned_at(Address addr) {
|
|
return *reinterpret_cast<unsigned*>(addr);
|
|
}
|
|
|
|
static intptr_t& intptr_at(Address addr) {
|
|
return *reinterpret_cast<intptr_t*>(addr);
|
|
}
|
|
|
|
static uintptr_t& uintptr_at(Address addr) {
|
|
return *reinterpret_cast<uintptr_t*>(addr);
|
|
}
|
|
|
|
static double& double_at(Address addr) {
|
|
return *reinterpret_cast<double*>(addr);
|
|
}
|
|
|
|
static Address& Address_at(Address addr) {
|
|
return *reinterpret_cast<Address*>(addr);
|
|
}
|
|
|
|
static Object*& Object_at(Address addr) {
|
|
return *reinterpret_cast<Object**>(addr);
|
|
}
|
|
|
|
static Handle<Object>& Object_Handle_at(Address addr) {
|
|
return *reinterpret_cast<Handle<Object>*>(addr);
|
|
}
|
|
|
|
static bool IsAddressInRange(Address base, Address address, uint32_t size) {
|
|
uintptr_t numeric_base = reinterpret_cast<uintptr_t>(base);
|
|
uintptr_t numeric_address = reinterpret_cast<uintptr_t>(address);
|
|
return numeric_base <= numeric_address &&
|
|
numeric_address < numeric_base + size;
|
|
}
|
|
};
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|
|
|
|
#endif // V8_MEMORY_H_
|