bool-ifying xe::cpu
This commit is contained in:
@@ -17,7 +17,7 @@ Assembler::Assembler(Backend* backend) : backend_(backend) {}
|
||||
|
||||
Assembler::~Assembler() { Reset(); }
|
||||
|
||||
int Assembler::Initialize() { return 0; }
|
||||
bool Assembler::Initialize() { return true; }
|
||||
|
||||
void Assembler::Reset() {}
|
||||
|
||||
|
||||
@@ -34,14 +34,14 @@ class Assembler {
|
||||
Assembler(Backend* backend);
|
||||
virtual ~Assembler();
|
||||
|
||||
virtual int Initialize();
|
||||
virtual bool Initialize();
|
||||
|
||||
virtual void Reset();
|
||||
|
||||
virtual int Assemble(FunctionInfo* symbol_info, hir::HIRBuilder* builder,
|
||||
uint32_t debug_info_flags,
|
||||
std::unique_ptr<DebugInfo> debug_info,
|
||||
uint32_t trace_flags, Function** out_function) = 0;
|
||||
virtual bool Assemble(FunctionInfo* symbol_info, hir::HIRBuilder* builder,
|
||||
uint32_t debug_info_flags,
|
||||
std::unique_ptr<DebugInfo> debug_info,
|
||||
uint32_t trace_flags, Function** out_function) = 0;
|
||||
|
||||
protected:
|
||||
Backend* backend_;
|
||||
|
||||
@@ -19,7 +19,7 @@ Backend::Backend(Processor* processor) : processor_(processor) {
|
||||
|
||||
Backend::~Backend() = default;
|
||||
|
||||
int Backend::Initialize() { return 0; }
|
||||
bool Backend::Initialize() { return true; }
|
||||
|
||||
void* Backend::AllocThreadData() { return nullptr; }
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class Backend {
|
||||
Processor* processor() const { return processor_; }
|
||||
const MachineInfo* machine_info() const { return &machine_info_; }
|
||||
|
||||
virtual int Initialize();
|
||||
virtual bool Initialize();
|
||||
|
||||
virtual void* AllocThreadData();
|
||||
virtual void FreeThreadData(void* thread_data);
|
||||
|
||||
@@ -41,16 +41,15 @@ X64Assembler::~X64Assembler() {
|
||||
allocator_.reset();
|
||||
}
|
||||
|
||||
int X64Assembler::Initialize() {
|
||||
int result = Assembler::Initialize();
|
||||
if (result) {
|
||||
return result;
|
||||
bool X64Assembler::Initialize() {
|
||||
if (!Assembler::Initialize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
allocator_.reset(new XbyakAllocator());
|
||||
emitter_.reset(new X64Emitter(x64_backend_, allocator_.get()));
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
void X64Assembler::Reset() {
|
||||
@@ -58,10 +57,10 @@ void X64Assembler::Reset() {
|
||||
Assembler::Reset();
|
||||
}
|
||||
|
||||
int X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
|
||||
uint32_t debug_info_flags,
|
||||
std::unique_ptr<DebugInfo> debug_info,
|
||||
uint32_t trace_flags, Function** out_function) {
|
||||
bool X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
|
||||
uint32_t debug_info_flags,
|
||||
std::unique_ptr<DebugInfo> debug_info,
|
||||
uint32_t trace_flags, Function** out_function) {
|
||||
SCOPE_profile_cpu_f("cpu");
|
||||
|
||||
// Reset when we leave.
|
||||
@@ -70,10 +69,9 @@ int X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
|
||||
// Lower HIR -> x64.
|
||||
void* machine_code = 0;
|
||||
size_t code_size = 0;
|
||||
int result = emitter_->Emit(builder, debug_info_flags, debug_info.get(),
|
||||
trace_flags, machine_code, code_size);
|
||||
if (result) {
|
||||
return result;
|
||||
if (!emitter_->Emit(builder, debug_info_flags, debug_info.get(), trace_flags,
|
||||
machine_code, code_size)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Stash generated machine code.
|
||||
@@ -91,7 +89,7 @@ int X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
|
||||
*out_function = fn;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void X64Assembler::DumpMachineCode(DebugInfo* debug_info, void* machine_code,
|
||||
|
||||
@@ -29,13 +29,14 @@ class X64Assembler : public Assembler {
|
||||
X64Assembler(X64Backend* backend);
|
||||
~X64Assembler() override;
|
||||
|
||||
int Initialize() override;
|
||||
bool Initialize() override;
|
||||
|
||||
void Reset() override;
|
||||
|
||||
int Assemble(FunctionInfo* symbol_info, hir::HIRBuilder* builder,
|
||||
uint32_t debug_info_flags, std::unique_ptr<DebugInfo> debug_info,
|
||||
uint32_t trace_flags, Function** out_function) override;
|
||||
bool Assemble(FunctionInfo* symbol_info, hir::HIRBuilder* builder,
|
||||
uint32_t debug_info_flags,
|
||||
std::unique_ptr<DebugInfo> debug_info, uint32_t trace_flags,
|
||||
Function** out_function) override;
|
||||
|
||||
private:
|
||||
void DumpMachineCode(DebugInfo* debug_info, void* machine_code,
|
||||
|
||||
@@ -24,10 +24,9 @@ X64Backend::X64Backend(Processor* processor)
|
||||
|
||||
X64Backend::~X64Backend() { delete code_cache_; }
|
||||
|
||||
int X64Backend::Initialize() {
|
||||
int result = Backend::Initialize();
|
||||
if (result) {
|
||||
return result;
|
||||
bool X64Backend::Initialize() {
|
||||
if (!Backend::Initialize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RegisterSequences();
|
||||
@@ -42,9 +41,8 @@ int X64Backend::Initialize() {
|
||||
};
|
||||
|
||||
code_cache_ = new X64CodeCache();
|
||||
result = code_cache_->Initialize();
|
||||
if (result) {
|
||||
return result;
|
||||
if (!code_cache_->Initialize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Generate thunks used to transition between jitted code and host code.
|
||||
@@ -53,7 +51,7 @@ int X64Backend::Initialize() {
|
||||
host_to_guest_thunk_ = thunk_emitter->EmitHostToGuestThunk();
|
||||
guest_to_host_thunk_ = thunk_emitter->EmitGuestToHostThunk();
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<Assembler> X64Backend::CreateAssembler() {
|
||||
|
||||
@@ -33,7 +33,7 @@ class X64Backend : public Backend {
|
||||
HostToGuestThunk host_to_guest_thunk() const { return host_to_guest_thunk_; }
|
||||
GuestToHostThunk guest_to_host_thunk() const { return guest_to_host_thunk_; }
|
||||
|
||||
int Initialize() override;
|
||||
bool Initialize() override;
|
||||
|
||||
std::unique_ptr<Assembler> CreateAssembler() override;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class X64CodeCache {
|
||||
X64CodeCache(size_t chunk_size = DEFAULT_CHUNK_SIZE);
|
||||
virtual ~X64CodeCache();
|
||||
|
||||
int Initialize();
|
||||
bool Initialize();
|
||||
|
||||
// TODO(benvanik): ELF serialization/etc
|
||||
// TODO(benvanik): keep track of code blocks
|
||||
|
||||
@@ -57,7 +57,7 @@ X64CodeCache::~X64CodeCache() {
|
||||
head_chunk_ = NULL;
|
||||
}
|
||||
|
||||
int X64CodeCache::Initialize() { return 0; }
|
||||
bool X64CodeCache::Initialize() { return true; }
|
||||
|
||||
void* X64CodeCache::PlaceCode(void* machine_code, size_t code_size,
|
||||
size_t stack_size) {
|
||||
|
||||
@@ -70,13 +70,11 @@ X64Emitter::X64Emitter(X64Backend* backend, XbyakAllocator* allocator)
|
||||
trace_flags_(0),
|
||||
cpu_() {}
|
||||
|
||||
X64Emitter::~X64Emitter() {}
|
||||
X64Emitter::~X64Emitter() = default;
|
||||
|
||||
int X64Emitter::Initialize() { return 0; }
|
||||
|
||||
int X64Emitter::Emit(HIRBuilder* builder, uint32_t debug_info_flags,
|
||||
DebugInfo* debug_info, uint32_t trace_flags,
|
||||
void*& out_code_address, size_t& out_code_size) {
|
||||
bool X64Emitter::Emit(HIRBuilder* builder, uint32_t debug_info_flags,
|
||||
DebugInfo* debug_info, uint32_t trace_flags,
|
||||
void*& out_code_address, size_t& out_code_size) {
|
||||
SCOPE_profile_cpu_f("cpu");
|
||||
|
||||
// Reset.
|
||||
@@ -88,9 +86,8 @@ int X64Emitter::Emit(HIRBuilder* builder, uint32_t debug_info_flags,
|
||||
|
||||
// Fill the generator with code.
|
||||
size_t stack_size = 0;
|
||||
int result = Emit(builder, stack_size);
|
||||
if (result) {
|
||||
return result;
|
||||
if (!Emit(builder, stack_size)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy the final code to the cache and relocate it.
|
||||
@@ -103,7 +100,7 @@ int X64Emitter::Emit(HIRBuilder* builder, uint32_t debug_info_flags,
|
||||
source_map_count_, (SourceMapEntry*)source_map_arena_.CloneContents());
|
||||
}
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void* X64Emitter::Emplace(size_t stack_size) {
|
||||
@@ -120,7 +117,7 @@ void* X64Emitter::Emplace(size_t stack_size) {
|
||||
return new_address;
|
||||
}
|
||||
|
||||
int X64Emitter::Emit(HIRBuilder* builder, size_t& out_stack_size) {
|
||||
bool X64Emitter::Emit(HIRBuilder* builder, size_t& out_stack_size) {
|
||||
// Calculate stack size. We need to align things to their natural sizes.
|
||||
// This could be much better (sort by type/etc).
|
||||
auto locals = builder->locals();
|
||||
@@ -204,7 +201,7 @@ int X64Emitter::Emit(HIRBuilder* builder, size_t& out_stack_size) {
|
||||
nop();
|
||||
#endif // XE_DEBUG
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void X64Emitter::MarkSourceOffset(const Instr* i) {
|
||||
|
||||
@@ -105,11 +105,9 @@ class X64Emitter : public Xbyak::CodeGenerator {
|
||||
X64Backend* backend() const { return backend_; }
|
||||
const Xbyak::util::Cpu* cpu() const { return &cpu_; }
|
||||
|
||||
int Initialize();
|
||||
|
||||
int Emit(hir::HIRBuilder* builder, uint32_t debug_info_flags,
|
||||
DebugInfo* debug_info, uint32_t trace_flags, void*& out_code_address,
|
||||
size_t& out_code_size);
|
||||
bool Emit(hir::HIRBuilder* builder, uint32_t debug_info_flags,
|
||||
DebugInfo* debug_info, uint32_t trace_flags,
|
||||
void*& out_code_address, size_t& out_code_size);
|
||||
|
||||
public:
|
||||
// Reserved: rsp
|
||||
@@ -182,7 +180,7 @@ class X64Emitter : public Xbyak::CodeGenerator {
|
||||
|
||||
protected:
|
||||
void* Emplace(size_t stack_size);
|
||||
int Emit(hir::HIRBuilder* builder, size_t& out_stack_size);
|
||||
bool Emit(hir::HIRBuilder* builder, size_t& out_stack_size);
|
||||
void EmitGetCurrentThreadId();
|
||||
void EmitTraceUserCallReturn();
|
||||
|
||||
|
||||
@@ -30,19 +30,21 @@ void X64Function::Setup(void* machine_code, size_t code_size) {
|
||||
code_size_ = code_size;
|
||||
}
|
||||
|
||||
int X64Function::AddBreakpointImpl(debug::Breakpoint* breakpoint) { return 0; }
|
||||
|
||||
int X64Function::RemoveBreakpointImpl(debug::Breakpoint* breakpoint) {
|
||||
return 0;
|
||||
bool X64Function::AddBreakpointImpl(debug::Breakpoint* breakpoint) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int X64Function::CallImpl(ThreadState* thread_state, uint32_t return_address) {
|
||||
bool X64Function::RemoveBreakpointImpl(debug::Breakpoint* breakpoint) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool X64Function::CallImpl(ThreadState* thread_state, uint32_t return_address) {
|
||||
auto backend =
|
||||
reinterpret_cast<X64Backend*>(thread_state->processor()->backend());
|
||||
auto thunk = backend->host_to_guest_thunk();
|
||||
thunk(machine_code_, thread_state->context(),
|
||||
reinterpret_cast<void*>(uintptr_t(return_address)));
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace x64
|
||||
|
||||
@@ -30,9 +30,9 @@ class X64Function : public Function {
|
||||
void Setup(void* machine_code, size_t code_size);
|
||||
|
||||
protected:
|
||||
virtual int AddBreakpointImpl(debug::Breakpoint* breakpoint);
|
||||
virtual int RemoveBreakpointImpl(debug::Breakpoint* breakpoint);
|
||||
virtual int CallImpl(ThreadState* thread_state, uint32_t return_address);
|
||||
virtual bool AddBreakpointImpl(debug::Breakpoint* breakpoint);
|
||||
virtual bool RemoveBreakpointImpl(debug::Breakpoint* breakpoint);
|
||||
virtual bool CallImpl(ThreadState* thread_state, uint32_t return_address);
|
||||
|
||||
private:
|
||||
void* machine_code_;
|
||||
|
||||
Reference in New Issue
Block a user