diff --git a/src/alloy/backend/assembler.h b/src/alloy/backend/assembler.h index b9f6ed788..161142389 100644 --- a/src/alloy/backend/assembler.h +++ b/src/alloy/backend/assembler.h @@ -10,6 +10,8 @@ #ifndef ALLOY_BACKEND_ASSEMBLER_H_ #define ALLOY_BACKEND_ASSEMBLER_H_ +#include + #include namespace alloy { @@ -40,7 +42,7 @@ class Assembler { virtual int Assemble(runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder, uint32_t debug_info_flags, - runtime::DebugInfo* debug_info, + std::unique_ptr debug_info, runtime::Function** out_function) = 0; protected: diff --git a/src/alloy/backend/backend.h b/src/alloy/backend/backend.h index 7f3124646..e4dea7832 100644 --- a/src/alloy/backend/backend.h +++ b/src/alloy/backend/backend.h @@ -10,6 +10,8 @@ #ifndef ALLOY_BACKEND_BACKEND_H_ #define ALLOY_BACKEND_BACKEND_H_ +#include + #include #include @@ -37,7 +39,7 @@ class Backend { virtual void* AllocThreadData(); virtual void FreeThreadData(void* thread_data); - virtual Assembler* CreateAssembler() = 0; + virtual std::unique_ptr CreateAssembler() = 0; protected: runtime::Runtime* runtime_; diff --git a/src/alloy/backend/ivm/ivm_assembler.cc b/src/alloy/backend/ivm/ivm_assembler.cc index 220d9063d..53d78e336 100644 --- a/src/alloy/backend/ivm/ivm_assembler.cc +++ b/src/alloy/backend/ivm/ivm_assembler.cc @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -21,6 +22,7 @@ namespace backend { namespace ivm { using alloy::hir::HIRBuilder; +using alloy::runtime::DebugInfo; using alloy::runtime::Function; using alloy::runtime::FunctionInfo; @@ -47,10 +49,15 @@ void IVMAssembler::Reset() { int IVMAssembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder, uint32_t debug_info_flags, - runtime::DebugInfo* debug_info, + std::unique_ptr debug_info, Function** out_function) { + SCOPE_profile_cpu_f("alloy"); + + // Reset when we leave. + make_reset_scope(this); + IVMFunction* fn = new IVMFunction(symbol_info); - fn->set_debug_info(debug_info); + fn->set_debug_info(std::move(debug_info)); TranslationContext ctx; ctx.register_count = 0; diff --git a/src/alloy/backend/ivm/ivm_assembler.h b/src/alloy/backend/ivm/ivm_assembler.h index 04f4c142d..446361647 100644 --- a/src/alloy/backend/ivm/ivm_assembler.h +++ b/src/alloy/backend/ivm/ivm_assembler.h @@ -21,16 +21,16 @@ namespace ivm { class IVMAssembler : public Assembler { public: IVMAssembler(Backend* backend); - virtual ~IVMAssembler(); + ~IVMAssembler() 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 debug_info, + runtime::Function** out_function) override; private: Arena intcode_arena_; diff --git a/src/alloy/backend/ivm/ivm_backend.cc b/src/alloy/backend/ivm/ivm_backend.cc index 286d3b5a3..171765a36 100644 --- a/src/alloy/backend/ivm/ivm_backend.cc +++ b/src/alloy/backend/ivm/ivm_backend.cc @@ -47,7 +47,9 @@ void IVMBackend::FreeThreadData(void* thread_data) { delete stack; } -Assembler* IVMBackend::CreateAssembler() { return new IVMAssembler(this); } +std::unique_ptr IVMBackend::CreateAssembler() { + return std::make_unique(this); +} } // namespace ivm } // namespace backend diff --git a/src/alloy/backend/ivm/ivm_backend.h b/src/alloy/backend/ivm/ivm_backend.h index 5311e56f2..b01536b6b 100644 --- a/src/alloy/backend/ivm/ivm_backend.h +++ b/src/alloy/backend/ivm/ivm_backend.h @@ -23,14 +23,14 @@ namespace ivm { class IVMBackend : public Backend { public: IVMBackend(runtime::Runtime* runtime); - virtual ~IVMBackend(); + ~IVMBackend() override; - virtual int Initialize(); + int Initialize() override; - virtual void* AllocThreadData(); - virtual void FreeThreadData(void* thread_data); + void* AllocThreadData() override; + void FreeThreadData(void* thread_data) override; - virtual Assembler* CreateAssembler(); + std::unique_ptr CreateAssembler() override; }; } // namespace ivm diff --git a/src/alloy/backend/ivm/ivm_intcode.cc b/src/alloy/backend/ivm/ivm_intcode.cc index cc9e81d73..91181a9e7 100644 --- a/src/alloy/backend/ivm/ivm_intcode.cc +++ b/src/alloy/backend/ivm/ivm_intcode.cc @@ -216,7 +216,7 @@ int Translate_COMMENT(TranslationContext& ctx, Instr* i) { ic->flags = i->flags; ic->debug_flags = 0; // HACK HACK HACK - char* src = xestrdupa((char*)i->src1.offset); + char* src = strdup(reinterpret_cast(i->src1.offset)); uint64_t src_p = (uint64_t)src; ic->src1_reg = (uint32_t)src_p; ic->src2_reg = (uint32_t)(src_p >> 32); diff --git a/src/alloy/backend/x64/x64_assembler.cc b/src/alloy/backend/x64/x64_assembler.cc index 01b179774..be3777b1c 100644 --- a/src/alloy/backend/x64/x64_assembler.cc +++ b/src/alloy/backend/x64/x64_assembler.cc @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -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 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, diff --git a/src/alloy/backend/x64/x64_assembler.h b/src/alloy/backend/x64/x64_assembler.h index 6cbf0c02c..769bee9db 100644 --- a/src/alloy/backend/x64/x64_assembler.h +++ b/src/alloy/backend/x64/x64_assembler.h @@ -10,6 +10,8 @@ #ifndef ALLOY_BACKEND_X64_X64_ASSEMBLER_H_ #define ALLOY_BACKEND_X64_X64_ASSEMBLER_H_ +#include + #include #include @@ -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 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 emitter_; + std::unique_ptr allocator_; StringBuffer string_buffer_; }; diff --git a/src/alloy/backend/x64/x64_backend.cc b/src/alloy/backend/x64/x64_backend.cc index cca85ca59..32aed4d78 100644 --- a/src/alloy/backend/x64/x64_backend.cc +++ b/src/alloy/backend/x64/x64_backend.cc @@ -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(); + auto thunk_emitter = std::make_unique(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 X64Backend::CreateAssembler() { + return std::make_unique(this); +} } // namespace x64 } // namespace backend diff --git a/src/alloy/backend/x64/x64_backend.h b/src/alloy/backend/x64/x64_backend.h index f0ebfdd2a..e8322ee1a 100644 --- a/src/alloy/backend/x64/x64_backend.h +++ b/src/alloy/backend/x64/x64_backend.h @@ -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 CreateAssembler() override; private: X64CodeCache* code_cache_; diff --git a/src/alloy/backend/x64/x64_sequences.cc b/src/alloy/backend/x64/x64_sequences.cc index f59f465db..b89916585 100644 --- a/src/alloy/backend/x64/x64_sequences.cc +++ b/src/alloy/backend/x64/x64_sequences.cc @@ -61,7 +61,7 @@ EMITTER(COMMENT, MATCH(I)) { auto str = reinterpret_cast(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(str_copy)); e.CallNative(TraceString); } diff --git a/src/alloy/frontend/ppc/ppc_translator.cc b/src/alloy/frontend/ppc/ppc_translator.cc index d93b9bd16..92897ea0b 100644 --- a/src/alloy/frontend/ppc/ppc_translator.cc +++ b/src/alloy/frontend/ppc/ppc_translator.cc @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -34,10 +35,10 @@ namespace passes = alloy::compiler::passes; PPCTranslator::PPCTranslator(PPCFrontend* frontend) : frontend_(frontend) { Backend* backend = frontend->runtime()->backend(); - scanner_ = new PPCScanner(frontend); - builder_ = new PPCHIRBuilder(frontend); - compiler_ = new Compiler(frontend->runtime()); - assembler_ = backend->CreateAssembler(); + scanner_.reset(new PPCScanner(frontend)); + builder_.reset(new PPCHIRBuilder(frontend)); + compiler_.reset(new Compiler(frontend->runtime())); + assembler_ = std::move(backend->CreateAssembler()); assembler_->Initialize(); bool validate = FLAGS_validate_hir; @@ -78,18 +79,19 @@ PPCTranslator::PPCTranslator(PPCFrontend* frontend) : frontend_(frontend) { compiler_->AddPass(std::make_unique()); } -PPCTranslator::~PPCTranslator() { - delete assembler_; - delete compiler_; - delete builder_; - delete scanner_; -} +PPCTranslator::~PPCTranslator() = default; int PPCTranslator::Translate(FunctionInfo* symbol_info, uint32_t debug_info_flags, Function** out_function) { SCOPE_profile_cpu_f("alloy"); + // Reset() all caching when we leave. + make_reset_scope(builder_); + make_reset_scope(compiler_); + make_reset_scope(assembler_); + make_reset_scope(&string_buffer_); + // Scan the function to find its extents. We only need to do this if we // haven't already been provided with them from some other source. if (!symbol_info->has_end_address()) { @@ -106,9 +108,9 @@ int PPCTranslator::Translate(FunctionInfo* symbol_info, if (FLAGS_always_disasm) { debug_info_flags |= DEBUG_INFO_ALL_DISASM; } - DebugInfo* debug_info = NULL; + std::unique_ptr debug_info; if (debug_info_flags) { - debug_info = new DebugInfo(); + debug_info.reset(new DebugInfo()); } // Stash source. @@ -119,8 +121,10 @@ int PPCTranslator::Translate(FunctionInfo* symbol_info, } // Emit function. - int result = builder_->Emit(symbol_info, debug_info != NULL); - XEEXPECTZERO(result); + int result = builder_->Emit(symbol_info, debug_info != nullptr); + if (result) { + return result; + } // Stash raw HIR. if (debug_info_flags & DEBUG_INFO_RAW_HIR_DISASM) { @@ -130,8 +134,10 @@ int PPCTranslator::Translate(FunctionInfo* symbol_info, } // Compile/optimize/etc. - result = compiler_->Compile(builder_); - XEEXPECTZERO(result); + result = compiler_->Compile(builder_.get()); + if (result) { + return result; + } // Stash optimized HIR. if (debug_info_flags & DEBUG_INFO_HIR_DISASM) { @@ -141,21 +147,13 @@ int PPCTranslator::Translate(FunctionInfo* symbol_info, } // Assemble to backend machine code. - result = assembler_->Assemble(symbol_info, builder_, debug_info_flags, - debug_info, out_function); - XEEXPECTZERO(result); - - result = 0; - -XECLEANUP: + result = assembler_->Assemble(symbol_info, builder_.get(), debug_info_flags, + std::move(debug_info), out_function); if (result) { - delete debug_info; + return result; } - builder_->Reset(); - compiler_->Reset(); - assembler_->Reset(); - string_buffer_.Reset(); - return result; + + return 0; }; void PPCTranslator::DumpSource(runtime::FunctionInfo* symbol_info, diff --git a/src/alloy/frontend/ppc/ppc_translator.h b/src/alloy/frontend/ppc/ppc_translator.h index 868ad5aeb..22011d449 100644 --- a/src/alloy/frontend/ppc/ppc_translator.h +++ b/src/alloy/frontend/ppc/ppc_translator.h @@ -10,6 +10,8 @@ #ifndef ALLOY_FRONTEND_PPC_PPC_TRANSLATOR_H_ #define ALLOY_FRONTEND_PPC_PPC_TRANSLATOR_H_ +#include + #include #include #include @@ -37,10 +39,10 @@ class PPCTranslator { private: PPCFrontend* frontend_; - PPCScanner* scanner_; - PPCHIRBuilder* builder_; - compiler::Compiler* compiler_; - backend::Assembler* assembler_; + std::unique_ptr scanner_; + std::unique_ptr builder_; + std::unique_ptr compiler_; + std::unique_ptr assembler_; StringBuffer string_buffer_; }; diff --git a/src/alloy/hir/hir_builder.cc b/src/alloy/hir/hir_builder.cc index 439a09e51..1ba6ce55d 100644 --- a/src/alloy/hir/hir_builder.cc +++ b/src/alloy/hir/hir_builder.cc @@ -544,7 +544,7 @@ void HIRBuilder::Comment(const char* format, ...) { va_start(args, format); xevsnprintfa(buffer, 1024, format, args); va_end(args); - size_t len = xestrlena(buffer); + size_t len = strlen(buffer); if (!len) { return; } diff --git a/src/alloy/reset_scope.h b/src/alloy/reset_scope.h new file mode 100644 index 000000000..d10c2561d --- /dev/null +++ b/src/alloy/reset_scope.h @@ -0,0 +1,45 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2014 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef ALLOY_RESET_SCOPE_H_ +#define ALLOY_RESET_SCOPE_H_ + +#include + +#include + +namespace alloy { + +template +class ResetScope { + public: + ResetScope(T* value) : value_(value) {} + ~ResetScope() { + if (value_) { + value_->Reset(); + } + } + + private: + T* value_; +}; + +template +inline ResetScope make_reset_scope(T* value) { + return ResetScope(value); +} + +template +inline ResetScope make_reset_scope(const std::unique_ptr& value) { + return ResetScope(value.get()); +} + +} // namespace alloy + +#endif // ALLOY_RESET_SCOPE_H_ diff --git a/src/alloy/runtime/function.cc b/src/alloy/runtime/function.cc index 7002cc86b..4be19f45e 100644 --- a/src/alloy/runtime/function.cc +++ b/src/alloy/runtime/function.cc @@ -18,8 +18,7 @@ namespace runtime { Function::Function(FunctionInfo* symbol_info) : address_(symbol_info->address()), - symbol_info_(symbol_info), - debug_info_(0) {} + symbol_info_(symbol_info) {} Function::~Function() = default; diff --git a/src/alloy/runtime/function.h b/src/alloy/runtime/function.h index 3ea3c4c9e..68366ba8f 100644 --- a/src/alloy/runtime/function.h +++ b/src/alloy/runtime/function.h @@ -10,6 +10,7 @@ #ifndef ALLOY_RUNTIME_FUNCTION_H_ #define ALLOY_RUNTIME_FUNCTION_H_ +#include #include #include @@ -31,8 +32,10 @@ class Function { uint64_t address() const { return address_; } FunctionInfo* symbol_info() const { return symbol_info_; } - DebugInfo* debug_info() const { return debug_info_; } - void set_debug_info(DebugInfo* debug_info) { debug_info_ = debug_info; } + DebugInfo* debug_info() const { return debug_info_.get(); } + void set_debug_info(std::unique_ptr debug_info) { + debug_info_ = std::move(debug_info); + } int AddBreakpoint(Breakpoint* breakpoint); int RemoveBreakpoint(Breakpoint* breakpoint); @@ -48,7 +51,7 @@ class Function { protected: uint64_t address_; FunctionInfo* symbol_info_; - DebugInfo* debug_info_; + std::unique_ptr debug_info_; // TODO(benvanik): move elsewhere? DebugData? std::mutex lock_; diff --git a/src/alloy/runtime/raw_module.cc b/src/alloy/runtime/raw_module.cc index 0d0a4c6d7..365d620ac 100644 --- a/src/alloy/runtime/raw_module.cc +++ b/src/alloy/runtime/raw_module.cc @@ -21,8 +21,8 @@ RawModule::~RawModule() { } } -int RawModule::LoadFile(uint64_t base_address, const char* path) { - FILE* file = fopen(path, "rb"); +int RawModule::LoadFile(uint64_t base_address, const std::string& path) { + FILE* file = fopen(path.c_str(), "rb"); fseek(file, 0, SEEK_END); size_t file_length = ftell(file); fseek(file, 0, SEEK_SET); @@ -42,7 +42,12 @@ int RawModule::LoadFile(uint64_t base_address, const char* path) { fclose(file); // Setup debug info. - name_ = std::string(xestrrchra(path, XE_PATH_SEPARATOR) + 1); + auto last_slash = path.find_last_of(poly::path_separator); + if (last_slash != std::string::npos) { + name_ = path.substr(last_slash + 1); + } else { + name_ = path; + } // TODO(benvanik): debug info low_address_ = base_address; diff --git a/src/alloy/runtime/raw_module.h b/src/alloy/runtime/raw_module.h index 8eb2c645d..37723119b 100644 --- a/src/alloy/runtime/raw_module.h +++ b/src/alloy/runtime/raw_module.h @@ -22,7 +22,7 @@ class RawModule : public Module { RawModule(Runtime* runtime); ~RawModule() override; - int LoadFile(uint64_t base_address, const char* path); + int LoadFile(uint64_t base_address, const std::string& path); const std::string& name() const override { return name_; } diff --git a/src/alloy/sources.gypi b/src/alloy/sources.gypi index 6e3d80e12..c912345b5 100644 --- a/src/alloy/sources.gypi +++ b/src/alloy/sources.gypi @@ -10,6 +10,7 @@ 'delegate.h', 'memory.cc', 'memory.h', + 'reset_scope.h', 'string_buffer.cc', 'string_buffer.h', 'type_pool.h', diff --git a/src/alloy/type_pool.h b/src/alloy/type_pool.h index ce124eab4..57be0b36e 100644 --- a/src/alloy/type_pool.h +++ b/src/alloy/type_pool.h @@ -52,8 +52,7 @@ class TypePool { private: std::mutex lock_; - typedef std::vector TList; - TList list_; + std::vector list_; }; } // namespace alloy diff --git a/src/poly/platform.h b/src/poly/platform.h index 019d69060..10efb54c3 100644 --- a/src/poly/platform.h +++ b/src/poly/platform.h @@ -161,4 +161,16 @@ XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN #include #endif // MSVC +namespace poly { + +#if XE_LIKE_WIN32 +const char path_separator = '\\'; +const size_t max_path = _MAX_PATH; +#else +const char path_separator = '/'; +const size_t max_path = PATH_MAX; +#endif // WIN32 + +} // namespace poly + #endif // POLY_PLATFORM_H_ diff --git a/src/xenia/core/file.cc b/src/xenia/core/file.cc index bf240d7f6..2c8bfd616 100644 --- a/src/xenia/core/file.cc +++ b/src/xenia/core/file.cc @@ -30,12 +30,12 @@ xe_file_ref xe_file_open(const xe_file_mode mode, const xechar_t *path) { xechar_t mode_string[10]; mode_string[0] = 0; if (mode & kXEFileModeRead) { - XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("r"))); + XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), L"r")); } if (mode & kXEFileModeWrite) { - XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("w"))); + XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), L"w")); } - XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("b"))); + XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), L"b")); #if XE_LIKE_WIN32 && XE_WCHAR XEEXPECTZERO(_wfopen_s((FILE**)&file->handle, path, mode_string)); diff --git a/src/xenia/core/pal_win.cc b/src/xenia/core/pal_win.cc index 3ef63b141..5f6498e5b 100644 --- a/src/xenia/core/pal_win.cc +++ b/src/xenia/core/pal_win.cc @@ -75,7 +75,7 @@ int xe_pal_get_system_info(xe_system_info* out_info) { LPFN_GLPI glpi = NULL; PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL; - kernel32 = GetModuleHandle(TEXT("kernel32")); + kernel32 = GetModuleHandle(L"kernel32"); XEEXPECTNOTNULL(kernel32); glpi = (LPFN_GLPI)GetProcAddress(kernel32, "GetLogicalProcessorInformation"); XEEXPECTNOTNULL(glpi); diff --git a/src/xenia/core/path.cc b/src/xenia/core/path.cc index 6356178f6..c24d22966 100644 --- a/src/xenia/core/path.cc +++ b/src/xenia/core/path.cc @@ -13,11 +13,11 @@ void xe_path_join(const xechar_t* left, const xechar_t* right, xechar_t* out_path, size_t out_path_size) { #if XE_WCHAR - xesnprintf(out_path, out_path_size, XT("%ls%c%ls"), - left, XE_PATH_SEPARATOR, right); + xesnprintf(out_path, out_path_size, L"%ls%c%ls", + left, poly::path_separator, right); #else - xesnprintf(out_path, out_path_size, XT("%s%c%s"), - left, XE_PATH_SEPARATOR, right); + xesnprintf(out_path, out_path_size, L"%s%c%s", + left, poly::path_separator, right); #endif // XE_WCHAR } diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index 64c9ac00b..1b3dbbcac 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -147,7 +147,7 @@ X_STATUS Emulator::LaunchXexFile(const xechar_t* path) { int result_code = 0; // Get just the filename (foo.xex). - const xechar_t* file_name = xestrrchr(path, XE_PATH_SEPARATOR); + const xechar_t* file_name = xestrrchr(path, poly::path_separator); if (file_name) { // Skip slash. file_name++; @@ -157,7 +157,7 @@ X_STATUS Emulator::LaunchXexFile(const xechar_t* path) { } // Get the parent path of the file. - xechar_t parent_path[XE_MAX_PATH]; + xechar_t parent_path[poly::max_path]; XEIGNORE(xestrcpy(parent_path, XECOUNT(parent_path), path)); parent_path[file_name - path] = 0; @@ -176,7 +176,7 @@ X_STATUS Emulator::LaunchXexFile(const xechar_t* path) { "d:", "\\Device\\Harddisk1\\Partition0"); // Get the file name of the module to load from the filesystem. - char fs_path[XE_MAX_PATH]; + char fs_path[poly::max_path]; XEIGNORE(xestrcpya(fs_path, XECOUNT(fs_path), "game:\\")); char* fs_path_ptr = fs_path + xestrlena(fs_path); *fs_path_ptr = 0; diff --git a/src/xenia/emulator.h b/src/xenia/emulator.h index 82ede0ec6..3548e5d2c 100644 --- a/src/xenia/emulator.h +++ b/src/xenia/emulator.h @@ -65,7 +65,7 @@ public: X_STATUS LaunchSTFSTitle(const xechar_t* path); private: - xechar_t command_line_[XE_MAX_PATH]; + xechar_t command_line_[poly::max_path]; ui::Window* main_window_; diff --git a/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc b/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc index d8660cbfe..071395b7e 100644 --- a/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc +++ b/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc @@ -96,7 +96,7 @@ ID3D10Blob* D3D11GeometryShader::Compile(const char* shader_source) { base_path = FLAGS_dump_shaders.c_str(); } uint64_t hash = xe_hash64(shader_source, xestrlena(shader_source)); // ? - char file_name[XE_MAX_PATH]; + char file_name[poly::max_path]; xesnprintfa(file_name, XECOUNT(file_name), "%s/gen_%.16llX.gs", base_path, diff --git a/src/xenia/gpu/d3d11/d3d11_shader_resource.cc b/src/xenia/gpu/d3d11/d3d11_shader_resource.cc index b5c28c9f2..c9c3e033f 100644 --- a/src/xenia/gpu/d3d11/d3d11_shader_resource.cc +++ b/src/xenia/gpu/d3d11/d3d11_shader_resource.cc @@ -47,7 +47,7 @@ ID3D10Blob* D3D11ShaderCompile(XE_GPU_SHADER_TYPE type, base_path = FLAGS_dump_shaders.c_str(); } size_t hash = xe_hash64(disasm_source, xestrlena(disasm_source)); // ? - char file_name[XE_MAX_PATH]; + char file_name[poly::max_path]; xesnprintfa(file_name, XECOUNT(file_name), "%s/gen_%.16llX.%s", base_path, diff --git a/src/xenia/kernel/fs/devices/disc_image_device.cc b/src/xenia/kernel/fs/devices/disc_image_device.cc index e3e2a8c4b..b64172919 100644 --- a/src/xenia/kernel/fs/devices/disc_image_device.cc +++ b/src/xenia/kernel/fs/devices/disc_image_device.cc @@ -62,7 +62,7 @@ Entry* DiscImageDevice::ResolvePath(const char* path) { // Walk the path, one separator at a time. // We copy it into the buffer and shift it left over and over. - char remaining[XE_MAX_PATH]; + char remaining[poly::max_path]; XEIGNORE(xestrcpya(remaining, XECOUNT(remaining), path)); while (remaining[0]) { char* next_slash = xestrchra(remaining, '\\'); diff --git a/src/xenia/kernel/fs/devices/host_path_device.cc b/src/xenia/kernel/fs/devices/host_path_device.cc index b4cbf5046..9eed206f0 100644 --- a/src/xenia/kernel/fs/devices/host_path_device.cc +++ b/src/xenia/kernel/fs/devices/host_path_device.cc @@ -35,23 +35,23 @@ Entry* HostPathDevice::ResolvePath(const char* path) { XELOGFS("HostPathDevice::ResolvePath(%s)", path); #if XE_WCHAR - xechar_t rel_path[XE_MAX_PATH]; + xechar_t rel_path[poly::max_path]; XEIGNORE(xestrwiden(rel_path, XECOUNT(rel_path), path)); #else const xechar_t* rel_path = path; #endif - xechar_t full_path[XE_MAX_PATH]; + xechar_t full_path[poly::max_path]; xe_path_join(local_path_, rel_path, full_path, XECOUNT(full_path)); // Swap around path separators. - if (XE_PATH_SEPARATOR != '\\') { + if (poly::path_separator != '\\') { for (size_t n = 0; n < XECOUNT(full_path); n++) { if (full_path[n] == 0) { break; } if (full_path[n] == '\\') { - full_path[n] = XE_PATH_SEPARATOR; + full_path[n] = poly::path_separator; } } } diff --git a/src/xenia/kernel/fs/devices/host_path_entry.cc b/src/xenia/kernel/fs/devices/host_path_entry.cc index a7f908bd3..f37f30008 100644 --- a/src/xenia/kernel/fs/devices/host_path_entry.cc +++ b/src/xenia/kernel/fs/devices/host_path_entry.cc @@ -87,10 +87,10 @@ X_STATUS HostPathEntry::QueryDirectory( } if (handle == INVALID_HANDLE_VALUE) { - xechar_t target_path[XE_MAX_PATH]; - xestrcpy(target_path, XE_MAX_PATH, local_path_); + xechar_t target_path[poly::max_path]; + xestrcpy(target_path, poly::max_path, local_path_); if (file_name == NULL) { - xestrcat(target_path, XE_MAX_PATH, XETEXT("*")); + xestrcat(target_path, poly::max_path, L"*"); } else { auto target_length = xestrlen(local_path_); diff --git a/src/xenia/kernel/fs/devices/stfs_container_device.cc b/src/xenia/kernel/fs/devices/stfs_container_device.cc index b055e8820..4d0d97127 100644 --- a/src/xenia/kernel/fs/devices/stfs_container_device.cc +++ b/src/xenia/kernel/fs/devices/stfs_container_device.cc @@ -63,7 +63,7 @@ Entry* STFSContainerDevice::ResolvePath(const char* path) { // Walk the path, one separator at a time. // We copy it into the buffer and shift it left over and over. - char remaining[XE_MAX_PATH]; + char remaining[poly::max_path]; XEIGNORE(xestrcpya(remaining, XECOUNT(remaining), path)); while (remaining[0]) { char* next_slash = xestrchra(remaining, '\\'); diff --git a/src/xenia/kernel/fs/filesystem.cc b/src/xenia/kernel/fs/filesystem.cc index e83d409c8..2b53acd0e 100644 --- a/src/xenia/kernel/fs/filesystem.cc +++ b/src/xenia/kernel/fs/filesystem.cc @@ -91,7 +91,7 @@ Entry* FileSystem::ResolvePath(const char* path) { // Resolve symlinks. // TODO(benvanik): more robust symlink handling - right now we assume simple // drive path -> device mappings with nothing nested. - char full_path[XE_MAX_PATH]; + char full_path[poly::max_path]; XEIGNORE(xestrcpya(full_path, XECOUNT(full_path), path)); for (std::unordered_map::iterator it = symlinks_.begin(); it != symlinks_.end(); ++it) { @@ -111,7 +111,7 @@ Entry* FileSystem::ResolvePath(const char* path) { if (xestrcasestra(full_path, device->path()) == full_path) { // Found! // Trim the device prefix off and pass down. - char device_path[XE_MAX_PATH]; + char device_path[poly::max_path]; XEIGNORE(xestrcpya(device_path, XECOUNT(device_path), full_path + xestrlena(device->path()))); return device->ResolvePath(device_path); diff --git a/src/xenia/kernel/objects/xmodule.h b/src/xenia/kernel/objects/xmodule.h index 97c49b907..c19a4961f 100644 --- a/src/xenia/kernel/objects/xmodule.h +++ b/src/xenia/kernel/objects/xmodule.h @@ -34,7 +34,7 @@ public: protected: char name_[256]; - char path_[XE_MAX_PATH]; + char path_[poly::max_path]; }; diff --git a/src/xenia/logging.cc b/src/xenia/logging.cc index 77106bc54..1f387ad57 100644 --- a/src/xenia/logging.cc +++ b/src/xenia/logging.cc @@ -31,7 +31,7 @@ void xe_format_log_line( const char* function_name, const char level_char, const char* fmt, va_list args) { // Strip out just the filename from the path. - const char* filename = xestrrchra(file_path, XE_PATH_SEPARATOR); + const char* filename = xestrrchra(file_path, poly::path_separator); if (filename) { // Slash - skip over it. filename++; diff --git a/src/xenia/platform.cc b/src/xenia/platform.cc index d5d0a14eb..c9d4d063b 100644 --- a/src/xenia/platform.cc +++ b/src/xenia/platform.cc @@ -94,7 +94,7 @@ int xe_main_window_thunk( xe_attach_console(); wchar_t buffer[2048]; xestrcpy(buffer, XECOUNT(buffer), name); - xestrcat(buffer, XECOUNT(buffer), XETEXT(" ")); + xestrcat(buffer, XECOUNT(buffer), L" "); xestrcat(buffer, XECOUNT(buffer), command_line); int argc; wchar_t** argv = CommandLineToArgvW(buffer, &argc); diff --git a/src/xenia/string.h b/src/xenia/string.h index 6008d3073..4f4c44642 100644 --- a/src/xenia/string.h +++ b/src/xenia/string.h @@ -40,7 +40,6 @@ char* xestrcasestra(const char* str, const char* substr); #define xestrdupw _wcsdup #define xestrchrw wcschr #define xestrrchrw wcsrchr -#define xestrstrw wcsstr #define xestrcasestrw ?? #define xestrcpyw(dest, destLength, source) (wcscpy_s(dest, destLength, source) == 0) #define xestrncpyw(dest, destLength, source, count) (wcsncpy_s(dest, destLength, source, count) == 0) @@ -54,7 +53,6 @@ char* xestrcasestra(const char* str, const char* substr); #define xestrcasecmpa strcasecmp #define xestrchra strchr #define xestrrchra strrchr -#define xestrstra strstr #define xestrcpya(dest, destLength, source) (strcpy_s(dest, destLength, source) == 0) #define xestrncpya(dest, destLength, source, count) (strncpy_s(dest, destLength, source, count) == 0) #define xestrcata(dest, destLength, source) (strcat_s(dest, destLength, source) == 0) @@ -65,8 +63,6 @@ char* xestrcasestra(const char* str, const char* substr); typedef wchar_t xechar_t; #define XE_WCHAR 1 -#define XETEXT(s) L ## s -#define XESTRFORMAT L"%ls" #define xestrlen xestrlenw #define xestrcmp xestrcmpw @@ -74,7 +70,6 @@ typedef wchar_t xechar_t; #define xestrdup xestrdupw #define xestrchr xestrchrw #define xestrrchr xestrrchrw -#define xestrstr xestrstrw #define xestrcasestr xestrcasestrw #define xestrtoull xestrtoullw #define xestrcpy xestrcpyw @@ -89,8 +84,6 @@ typedef wchar_t xechar_t; typedef char xechar_t; #define XE_CHAR 1 -#define XETEXT(s) s -#define XESTRFORMAT "%s" #define xestrlen xestrlena #define xestrcmp xestrcmpa @@ -98,7 +91,6 @@ typedef char xechar_t; #define xestrdup xestrdupa #define xestrchr xestrchra #define xestrrchr xestrrchra -#define xestrstr xestrstra #define xestrcasestr xestrcasestra #define xestrtoull xestrtoulla #define xestrcpy xestrcpya @@ -111,15 +103,4 @@ typedef char xechar_t; #endif // WIN32 -#define XT XETEXT -#define XTS XESTRFORMAT - -#if XE_LIKE_WIN32 -#define XE_PATH_SEPARATOR ((xechar_t)'\\') -#define XE_MAX_PATH _MAX_PATH -#else -#define XE_PATH_SEPARATOR ((xechar_t)'/') -#define XE_MAX_PATH PATH_MAX -#endif // WIN32 - #endif // XENIA_STRING_H_ diff --git a/tools/xenia-run/xenia-run.cc b/tools/xenia-run/xenia-run.cc index 9f2151d8c..f684d14eb 100644 --- a/tools/xenia-run/xenia-run.cc +++ b/tools/xenia-run/xenia-run.cc @@ -37,7 +37,7 @@ int xenia_run(int argc, xechar_t** argv) { if (FLAGS_target.size()) { // Passed as a named argument. // TODO(benvanik): find something better than gflags that supports unicode. - xechar_t buffer[XE_MAX_PATH]; + xechar_t buffer[poly::max_path]; XEIGNORE(xestrwiden(buffer, sizeof(buffer), FLAGS_target.c_str())); path = buffer; } else { @@ -52,7 +52,7 @@ int xenia_run(int argc, xechar_t** argv) { // Normalize the path and make absolute. // TODO(benvanik): move this someplace common. - xechar_t abs_path[XE_MAX_PATH]; + xechar_t abs_path[poly::max_path]; xe_path_get_absolute(path, abs_path, XECOUNT(abs_path)); // Grab file extension. @@ -60,7 +60,7 @@ int xenia_run(int argc, xechar_t** argv) { const xechar_t* dot = xestrrchr(abs_path, '.'); // Create the emulator. - emulator = new Emulator(XT("")); + emulator = new Emulator(L""); XEEXPECTNOTNULL(emulator); X_STATUS result = emulator->Setup(); if (XFAILED(result)) { @@ -74,7 +74,7 @@ int xenia_run(int argc, xechar_t** argv) { if (!dot) { // Likely an STFS container. result = emulator->LaunchSTFSTitle(abs_path); - } else if (xestrcmp(dot, XT(".xex")) == 0) { + } else if (xestrcmp(dot, L".xex") == 0) { // Treat as a naked xex file. result = emulator->LaunchXexFile(abs_path); } else { @@ -96,4 +96,4 @@ XECLEANUP: Profiler::Shutdown(); return result_code; } -XE_MAIN_WINDOW_THUNK(xenia_run, XETEXT("xenia-run"), "xenia-run some.xex"); +XE_MAIN_WINDOW_THUNK(xenia_run, L"xenia-run", "xenia-run some.xex");