More C++11ification.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <alloy/backend/x64/x64_assembler.h>
|
||||
|
||||
#include <alloy/reset_scope.h>
|
||||
#include <alloy/backend/x64/x64_backend.h>
|
||||
#include <alloy/backend/x64/x64_emitter.h>
|
||||
#include <alloy/backend/x64/x64_function.h>
|
||||
@@ -33,12 +34,9 @@ using alloy::runtime::Function;
|
||||
using alloy::runtime::FunctionInfo;
|
||||
|
||||
X64Assembler::X64Assembler(X64Backend* backend)
|
||||
: Assembler(backend), x64_backend_(backend), emitter_(0), allocator_(0) {}
|
||||
: Assembler(backend), x64_backend_(backend) {}
|
||||
|
||||
X64Assembler::~X64Assembler() {
|
||||
delete emitter_;
|
||||
delete allocator_;
|
||||
}
|
||||
X64Assembler::~X64Assembler() = default;
|
||||
|
||||
int X64Assembler::Initialize() {
|
||||
int result = Assembler::Initialize();
|
||||
@@ -46,8 +44,8 @@ int X64Assembler::Initialize() {
|
||||
return result;
|
||||
}
|
||||
|
||||
allocator_ = new XbyakAllocator();
|
||||
emitter_ = new X64Emitter(x64_backend_, allocator_);
|
||||
allocator_.reset(new XbyakAllocator());
|
||||
emitter_.reset(new X64Emitter(x64_backend_, allocator_.get()));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -58,39 +56,39 @@ void X64Assembler::Reset() {
|
||||
}
|
||||
|
||||
int X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
|
||||
uint32_t debug_info_flags, DebugInfo* debug_info,
|
||||
uint32_t debug_info_flags,
|
||||
std::unique_ptr<DebugInfo> debug_info,
|
||||
Function** out_function) {
|
||||
SCOPE_profile_cpu_f("alloy");
|
||||
|
||||
int result = 0;
|
||||
// Reset when we leave.
|
||||
make_reset_scope(this);
|
||||
|
||||
// Lower HIR -> x64.
|
||||
void* machine_code = 0;
|
||||
size_t code_size = 0;
|
||||
result = emitter_->Emit(builder, debug_info_flags, debug_info, machine_code,
|
||||
code_size);
|
||||
XEEXPECTZERO(result);
|
||||
int result = emitter_->Emit(builder, debug_info_flags, debug_info.get(),
|
||||
machine_code, code_size);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Stash generated machine code.
|
||||
if (debug_info_flags & DebugInfoFlags::DEBUG_INFO_MACHINE_CODE_DISASM) {
|
||||
DumpMachineCode(debug_info, machine_code, code_size, &string_buffer_);
|
||||
DumpMachineCode(debug_info.get(), machine_code, code_size, &string_buffer_);
|
||||
debug_info->set_machine_code_disasm(string_buffer_.ToString());
|
||||
string_buffer_.Reset();
|
||||
}
|
||||
|
||||
{
|
||||
X64Function* fn = new X64Function(symbol_info);
|
||||
fn->set_debug_info(debug_info);
|
||||
fn->set_debug_info(std::move(debug_info));
|
||||
fn->Setup(machine_code, code_size);
|
||||
|
||||
*out_function = fn;
|
||||
|
||||
result = 0;
|
||||
}
|
||||
|
||||
XECLEANUP:
|
||||
Reset();
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void X64Assembler::DumpMachineCode(DebugInfo* debug_info, void* machine_code,
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef ALLOY_BACKEND_X64_X64_ASSEMBLER_H_
|
||||
#define ALLOY_BACKEND_X64_X64_ASSEMBLER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
#include <alloy/backend/assembler.h>
|
||||
@@ -25,16 +27,16 @@ class XbyakAllocator;
|
||||
class X64Assembler : public Assembler {
|
||||
public:
|
||||
X64Assembler(X64Backend* backend);
|
||||
virtual ~X64Assembler();
|
||||
~X64Assembler() override;
|
||||
|
||||
virtual int Initialize();
|
||||
int Initialize() override;
|
||||
|
||||
virtual void Reset();
|
||||
void Reset() override;
|
||||
|
||||
virtual int Assemble(runtime::FunctionInfo* symbol_info,
|
||||
hir::HIRBuilder* builder, uint32_t debug_info_flags,
|
||||
runtime::DebugInfo* debug_info,
|
||||
runtime::Function** out_function);
|
||||
int Assemble(runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
|
||||
uint32_t debug_info_flags,
|
||||
std::unique_ptr<runtime::DebugInfo> debug_info,
|
||||
runtime::Function** out_function) override;
|
||||
|
||||
private:
|
||||
void DumpMachineCode(runtime::DebugInfo* debug_info, void* machine_code,
|
||||
@@ -42,8 +44,8 @@ class X64Assembler : public Assembler {
|
||||
|
||||
private:
|
||||
X64Backend* x64_backend_;
|
||||
X64Emitter* emitter_;
|
||||
XbyakAllocator* allocator_;
|
||||
std::unique_ptr<X64Emitter> emitter_;
|
||||
std::unique_ptr<XbyakAllocator> allocator_;
|
||||
|
||||
StringBuffer string_buffer_;
|
||||
};
|
||||
|
||||
@@ -47,17 +47,18 @@ int X64Backend::Initialize() {
|
||||
return result;
|
||||
}
|
||||
|
||||
auto allocator = new XbyakAllocator();
|
||||
auto thunk_emitter = new X64ThunkEmitter(this, allocator);
|
||||
// Generate thunks used to transition between jitted code and host code.
|
||||
auto allocator = std::make_unique<XbyakAllocator>();
|
||||
auto thunk_emitter = std::make_unique<X64ThunkEmitter>(this, allocator.get());
|
||||
host_to_guest_thunk_ = thunk_emitter->EmitHostToGuestThunk();
|
||||
guest_to_host_thunk_ = thunk_emitter->EmitGuestToHostThunk();
|
||||
delete thunk_emitter;
|
||||
delete allocator;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Assembler* X64Backend::CreateAssembler() { return new X64Assembler(this); }
|
||||
std::unique_ptr<Assembler> X64Backend::CreateAssembler() {
|
||||
return std::make_unique<X64Assembler>(this);
|
||||
}
|
||||
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
|
||||
@@ -28,15 +28,15 @@ typedef void* (*GuestToHostThunk)(void* target, void* arg0, void* arg1);
|
||||
class X64Backend : public Backend {
|
||||
public:
|
||||
X64Backend(runtime::Runtime* runtime);
|
||||
virtual ~X64Backend();
|
||||
~X64Backend() override;
|
||||
|
||||
X64CodeCache* code_cache() const { return code_cache_; }
|
||||
HostToGuestThunk host_to_guest_thunk() const { return host_to_guest_thunk_; }
|
||||
GuestToHostThunk guest_to_host_thunk() const { return guest_to_host_thunk_; }
|
||||
|
||||
virtual int Initialize();
|
||||
int Initialize() override;
|
||||
|
||||
virtual Assembler* CreateAssembler();
|
||||
std::unique_ptr<Assembler> CreateAssembler() override;
|
||||
|
||||
private:
|
||||
X64CodeCache* code_cache_;
|
||||
|
||||
@@ -61,7 +61,7 @@ EMITTER(COMMENT, MATCH(I<OPCODE_COMMENT, VoidOp, OffsetOp>)) {
|
||||
auto str = reinterpret_cast<const char*>(i.src1.value);
|
||||
// TODO(benvanik): pass through.
|
||||
// TODO(benvanik): don't just leak this memory.
|
||||
auto str_copy = xestrdupa(str);
|
||||
auto str_copy = strdup(str);
|
||||
e.mov(e.rdx, reinterpret_cast<uint64_t>(str_copy));
|
||||
e.CallNative(TraceString);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user