diff --git a/src/alloy/backend/backend.cc b/src/alloy/backend/backend.cc index 3982caa1f..d66283c82 100644 --- a/src/alloy/backend/backend.cc +++ b/src/alloy/backend/backend.cc @@ -15,14 +15,14 @@ namespace backend { using alloy::runtime::Runtime; Backend::Backend(Runtime* runtime) : runtime_(runtime) { - xe_zero_struct(&machine_info_, sizeof(machine_info_)); + memset(&machine_info_, 0, sizeof(machine_info_)); } -Backend::~Backend() {} +Backend::~Backend() = default; int Backend::Initialize() { return 0; } -void* Backend::AllocThreadData() { return NULL; } +void* Backend::AllocThreadData() { return nullptr; } void Backend::FreeThreadData(void* thread_data) {} diff --git a/src/alloy/compiler/compiler.cc b/src/alloy/compiler/compiler.cc index ac86f3212..2ad7ca527 100644 --- a/src/alloy/compiler/compiler.cc +++ b/src/alloy/compiler/compiler.cc @@ -17,24 +17,13 @@ namespace compiler { using alloy::hir::HIRBuilder; using alloy::runtime::Runtime; -Compiler::Compiler(Runtime* runtime) : runtime_(runtime) { - scratch_arena_ = new Arena(); -} +Compiler::Compiler(Runtime* runtime) : runtime_(runtime) {} -Compiler::~Compiler() { - Reset(); +Compiler::~Compiler() { Reset(); } - for (auto it = passes_.begin(); it != passes_.end(); ++it) { - CompilerPass* pass = *it; - delete pass; - } - - delete scratch_arena_; -} - -void Compiler::AddPass(CompilerPass* pass) { +void Compiler::AddPass(std::unique_ptr pass) { pass->Initialize(this); - passes_.push_back(pass); + passes_.push_back(std::move(pass)); } void Compiler::Reset() {} @@ -44,9 +33,8 @@ int Compiler::Compile(HIRBuilder* builder) { // TODO(benvanik): sophisticated stuff. Run passes in parallel, run until they // stop changing things, etc. - for (auto it = passes_.begin(); it != passes_.end(); ++it) { - CompilerPass* pass = *it; - scratch_arena_->Reset(); + for (auto& pass : passes_) { + scratch_arena_.Reset(); if (pass->Run(builder)) { return 1; } diff --git a/src/alloy/compiler/compiler.h b/src/alloy/compiler/compiler.h index 82c13890b..ed592bdb8 100644 --- a/src/alloy/compiler/compiler.h +++ b/src/alloy/compiler/compiler.h @@ -10,6 +10,9 @@ #ifndef ALLOY_COMPILER_COMPILER_H_ #define ALLOY_COMPILER_COMPILER_H_ +#include +#include + #include #include @@ -30,9 +33,9 @@ class Compiler { ~Compiler(); runtime::Runtime* runtime() const { return runtime_; } - Arena* scratch_arena() const { return scratch_arena_; } + Arena* scratch_arena() { return &scratch_arena_; } - void AddPass(CompilerPass* pass); + void AddPass(std::unique_ptr pass); void Reset(); @@ -40,10 +43,9 @@ class Compiler { private: runtime::Runtime* runtime_; - Arena* scratch_arena_; + Arena scratch_arena_; - typedef std::vector PassList; - PassList passes_; + std::vector> passes_; }; } // namespace compiler diff --git a/src/alloy/compiler/compiler_pass.cc b/src/alloy/compiler/compiler_pass.cc index 2c3e84afc..67ac1700f 100644 --- a/src/alloy/compiler/compiler_pass.cc +++ b/src/alloy/compiler/compiler_pass.cc @@ -16,7 +16,7 @@ namespace compiler { CompilerPass::CompilerPass() : runtime_(0), compiler_(0) {} -CompilerPass::~CompilerPass() {} +CompilerPass::~CompilerPass() = default; int CompilerPass::Initialize(Compiler* compiler) { runtime_ = compiler->runtime(); diff --git a/src/alloy/compiler/passes/constant_propagation_pass.h b/src/alloy/compiler/passes/constant_propagation_pass.h index cdc7f1353..ff7241e3e 100644 --- a/src/alloy/compiler/passes/constant_propagation_pass.h +++ b/src/alloy/compiler/passes/constant_propagation_pass.h @@ -19,9 +19,9 @@ namespace passes { class ConstantPropagationPass : public CompilerPass { public: ConstantPropagationPass(); - virtual ~ConstantPropagationPass(); + ~ConstantPropagationPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: void PropagateCarry(hir::Value* v, bool did_carry); diff --git a/src/alloy/compiler/passes/context_promotion_pass.h b/src/alloy/compiler/passes/context_promotion_pass.h index 925f0bb32..a9b8bc95b 100644 --- a/src/alloy/compiler/passes/context_promotion_pass.h +++ b/src/alloy/compiler/passes/context_promotion_pass.h @@ -19,11 +19,11 @@ namespace passes { class ContextPromotionPass : public CompilerPass { public: ContextPromotionPass(); - virtual ~ContextPromotionPass(); + virtual ~ContextPromotionPass() override; - virtual int Initialize(Compiler* compiler); + int Initialize(Compiler* compiler) override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: void PromoteBlock(hir::Block* block); diff --git a/src/alloy/compiler/passes/control_flow_analysis_pass.h b/src/alloy/compiler/passes/control_flow_analysis_pass.h index 35ce33fba..bcde6cd5a 100644 --- a/src/alloy/compiler/passes/control_flow_analysis_pass.h +++ b/src/alloy/compiler/passes/control_flow_analysis_pass.h @@ -19,9 +19,9 @@ namespace passes { class ControlFlowAnalysisPass : public CompilerPass { public: ControlFlowAnalysisPass(); - virtual ~ControlFlowAnalysisPass(); + ~ControlFlowAnalysisPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: }; diff --git a/src/alloy/compiler/passes/data_flow_analysis_pass.h b/src/alloy/compiler/passes/data_flow_analysis_pass.h index d19dc6e1c..f3990b2ec 100644 --- a/src/alloy/compiler/passes/data_flow_analysis_pass.h +++ b/src/alloy/compiler/passes/data_flow_analysis_pass.h @@ -21,9 +21,9 @@ namespace passes { class DataFlowAnalysisPass : public CompilerPass { public: DataFlowAnalysisPass(); - virtual ~DataFlowAnalysisPass(); + ~DataFlowAnalysisPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: uint32_t LinearizeBlocks(hir::HIRBuilder* builder); diff --git a/src/alloy/compiler/passes/dead_code_elimination_pass.h b/src/alloy/compiler/passes/dead_code_elimination_pass.h index 9c3100f8c..14d8667df 100644 --- a/src/alloy/compiler/passes/dead_code_elimination_pass.h +++ b/src/alloy/compiler/passes/dead_code_elimination_pass.h @@ -21,9 +21,9 @@ namespace passes { class DeadCodeEliminationPass : public CompilerPass { public: DeadCodeEliminationPass(); - virtual ~DeadCodeEliminationPass(); + ~DeadCodeEliminationPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: void MakeNopRecursive(hir::Instr* i); diff --git a/src/alloy/compiler/passes/finalization_pass.h b/src/alloy/compiler/passes/finalization_pass.h index 30cec0d3c..cf951f706 100644 --- a/src/alloy/compiler/passes/finalization_pass.h +++ b/src/alloy/compiler/passes/finalization_pass.h @@ -19,9 +19,9 @@ namespace passes { class FinalizationPass : public CompilerPass { public: FinalizationPass(); - virtual ~FinalizationPass(); + ~FinalizationPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: }; diff --git a/src/alloy/compiler/passes/register_allocation_pass.h b/src/alloy/compiler/passes/register_allocation_pass.h index 70f212c08..aa8b03fb2 100644 --- a/src/alloy/compiler/passes/register_allocation_pass.h +++ b/src/alloy/compiler/passes/register_allocation_pass.h @@ -24,9 +24,9 @@ namespace passes { class RegisterAllocationPass : public CompilerPass { public: RegisterAllocationPass(const backend::MachineInfo* machine_info); - virtual ~RegisterAllocationPass(); + ~RegisterAllocationPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: // TODO(benvanik): rewrite all this set shit -- too much indirection, the diff --git a/src/alloy/compiler/passes/simplification_pass.h b/src/alloy/compiler/passes/simplification_pass.h index 6806d48c7..328e200a9 100644 --- a/src/alloy/compiler/passes/simplification_pass.h +++ b/src/alloy/compiler/passes/simplification_pass.h @@ -19,9 +19,9 @@ namespace passes { class SimplificationPass : public CompilerPass { public: SimplificationPass(); - virtual ~SimplificationPass(); + ~SimplificationPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: void EliminateConversions(hir::HIRBuilder* builder); diff --git a/src/alloy/compiler/passes/validation_pass.h b/src/alloy/compiler/passes/validation_pass.h index 47c474887..133187d6f 100644 --- a/src/alloy/compiler/passes/validation_pass.h +++ b/src/alloy/compiler/passes/validation_pass.h @@ -19,9 +19,9 @@ namespace passes { class ValidationPass : public CompilerPass { public: ValidationPass(); - virtual ~ValidationPass(); + ~ValidationPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: int ValidateInstruction(hir::Block* block, hir::Instr* instr); diff --git a/src/alloy/compiler/passes/value_reduction_pass.h b/src/alloy/compiler/passes/value_reduction_pass.h index 95a9eaac0..b2ea00bb7 100644 --- a/src/alloy/compiler/passes/value_reduction_pass.h +++ b/src/alloy/compiler/passes/value_reduction_pass.h @@ -19,9 +19,9 @@ namespace passes { class ValueReductionPass : public CompilerPass { public: ValueReductionPass(); - virtual ~ValueReductionPass(); + ~ValueReductionPass() override; - virtual int Run(hir::HIRBuilder* builder); + int Run(hir::HIRBuilder* builder) override; private: void ComputeLastUse(hir::Value* value); diff --git a/src/alloy/frontend/frontend.cc b/src/alloy/frontend/frontend.cc index d97236d72..a9da0bfd7 100644 --- a/src/alloy/frontend/frontend.cc +++ b/src/alloy/frontend/frontend.cc @@ -14,10 +14,9 @@ namespace alloy { namespace frontend { -Frontend::Frontend(runtime::Runtime* runtime) - : runtime_(runtime), context_info_(0) {} +Frontend::Frontend(runtime::Runtime* runtime) : runtime_(runtime) {} -Frontend::~Frontend() { delete context_info_; } +Frontend::~Frontend() = default; Memory* Frontend::memory() const { return runtime_->memory(); } diff --git a/src/alloy/frontend/frontend.h b/src/alloy/frontend/frontend.h index 33662ea3e..ec43bee3d 100644 --- a/src/alloy/frontend/frontend.h +++ b/src/alloy/frontend/frontend.h @@ -10,6 +10,8 @@ #ifndef ALLOY_FRONTEND_FRONTEND_H_ #define ALLOY_FRONTEND_FRONTEND_H_ +#include + #include #include #include @@ -32,7 +34,7 @@ class Frontend { runtime::Runtime* runtime() const { return runtime_; } Memory* memory() const; - ContextInfo* context_info() const { return context_info_; } + ContextInfo* context_info() const { return context_info_.get(); } virtual int Initialize(); @@ -43,7 +45,7 @@ class Frontend { protected: runtime::Runtime* runtime_; - ContextInfo* context_info_; + std::unique_ptr context_info_; }; } // namespace frontend diff --git a/src/alloy/frontend/ppc/ppc_frontend.cc b/src/alloy/frontend/ppc/ppc_frontend.cc index a537efda9..33451e21f 100644 --- a/src/alloy/frontend/ppc/ppc_frontend.cc +++ b/src/alloy/frontend/ppc/ppc_frontend.cc @@ -46,10 +46,10 @@ void CleanupOnShutdown() {} PPCFrontend::PPCFrontend(Runtime* runtime) : Frontend(runtime) { InitializeIfNeeded(); - ContextInfo* info = - new ContextInfo(sizeof(PPCContext), offsetof(PPCContext, thread_state)); + std::unique_ptr context_info( + new ContextInfo(sizeof(PPCContext), offsetof(PPCContext, thread_state))); // Add fields/etc. - context_info_ = info; + context_info_ = std::move(context_info); } PPCFrontend::~PPCFrontend() { diff --git a/src/alloy/frontend/ppc/ppc_translator.cc b/src/alloy/frontend/ppc/ppc_translator.cc index 4a701c729..d93b9bd16 100644 --- a/src/alloy/frontend/ppc/ppc_translator.cc +++ b/src/alloy/frontend/ppc/ppc_translator.cc @@ -43,23 +43,24 @@ PPCTranslator::PPCTranslator(PPCFrontend* frontend) : frontend_(frontend) { bool validate = FLAGS_validate_hir; // Build the CFG first. - compiler_->AddPass(new passes::ControlFlowAnalysisPass()); + compiler_->AddPass(std::make_unique()); // Passes are executed in the order they are added. Multiple of the same // pass type may be used. - if (validate) compiler_->AddPass(new passes::ValidationPass()); - compiler_->AddPass(new passes::ContextPromotionPass()); - if (validate) compiler_->AddPass(new passes::ValidationPass()); - compiler_->AddPass(new passes::SimplificationPass()); - if (validate) compiler_->AddPass(new passes::ValidationPass()); - compiler_->AddPass(new passes::ConstantPropagationPass()); - if (validate) compiler_->AddPass(new passes::ValidationPass()); - compiler_->AddPass(new passes::SimplificationPass()); - if (validate) compiler_->AddPass(new passes::ValidationPass()); - // compiler_->AddPass(new passes::DeadStoreEliminationPass()); - // if (validate) compiler_->AddPass(new passes::ValidationPass()); - compiler_->AddPass(new passes::DeadCodeEliminationPass()); - if (validate) compiler_->AddPass(new passes::ValidationPass()); + if (validate) compiler_->AddPass(std::make_unique()); + compiler_->AddPass(std::make_unique()); + if (validate) compiler_->AddPass(std::make_unique()); + compiler_->AddPass(std::make_unique()); + if (validate) compiler_->AddPass(std::make_unique()); + compiler_->AddPass(std::make_unique()); + if (validate) compiler_->AddPass(std::make_unique()); + compiler_->AddPass(std::make_unique()); + if (validate) compiler_->AddPass(std::make_unique()); + // compiler_->AddPass(std::make_unique()); + // if (validate) + // compiler_->AddPass(std::make_unique()); + compiler_->AddPass(std::make_unique()); + if (validate) compiler_->AddPass(std::make_unique()); //// Removes all unneeded variables. Try not to add new ones after this. // compiler_->AddPass(new passes::ValueReductionPass()); @@ -69,12 +70,12 @@ PPCTranslator::PPCTranslator(PPCFrontend* frontend) : frontend_(frontend) { // Will modify the HIR to add loads/stores. // This should be the last pass before finalization, as after this all // registers are assigned and ready to be emitted. - compiler_->AddPass( - new passes::RegisterAllocationPass(backend->machine_info())); - if (validate) compiler_->AddPass(new passes::ValidationPass()); + compiler_->AddPass(std::make_unique( + backend->machine_info())); + if (validate) compiler_->AddPass(std::make_unique()); // Must come last. The HIR is not really HIR after this. - compiler_->AddPass(new passes::FinalizationPass()); + compiler_->AddPass(std::make_unique()); } PPCTranslator::~PPCTranslator() { diff --git a/src/alloy/runtime/debugger.h b/src/alloy/runtime/debugger.h index fcac741d8..1b09f3ab3 100644 --- a/src/alloy/runtime/debugger.h +++ b/src/alloy/runtime/debugger.h @@ -107,12 +107,10 @@ class Debugger { Runtime* runtime_; std::mutex threads_lock_; - typedef std::unordered_map ThreadMap; - ThreadMap threads_; + std::unordered_map threads_; std::mutex breakpoints_lock_; - typedef std::multimap BreakpointMultimap; - BreakpointMultimap breakpoints_; + std::multimap breakpoints_; }; } // namespace runtime diff --git a/src/alloy/runtime/entry_table.cc b/src/alloy/runtime/entry_table.cc index df1a6f89b..aa0a41cbb 100644 --- a/src/alloy/runtime/entry_table.cc +++ b/src/alloy/runtime/entry_table.cc @@ -16,7 +16,7 @@ EntryTable::EntryTable() = default; EntryTable::~EntryTable() { std::lock_guard guard(lock_); - EntryMap::iterator it = map_.begin(); + auto& it = map_.begin(); for (; it != map_.end(); ++it) { Entry* entry = it->second; delete entry; @@ -25,7 +25,7 @@ EntryTable::~EntryTable() { Entry* EntryTable::Get(uint64_t address) { std::lock_guard guard(lock_); - EntryMap::const_iterator it = map_.find(address); + const auto& it = map_.find(address); Entry* entry = it != map_.end() ? it->second : nullptr; if (entry) { // TODO(benvanik): wait if needed? @@ -38,7 +38,7 @@ Entry* EntryTable::Get(uint64_t address) { Entry::Status EntryTable::GetOrCreate(uint64_t address, Entry** out_entry) { lock_.lock(); - EntryMap::const_iterator it = map_.find(address); + const auto& it = map_.find(address); Entry* entry = it != map_.end() ? it->second : nullptr; Entry::Status status; if (entry) { diff --git a/src/alloy/runtime/entry_table.h b/src/alloy/runtime/entry_table.h index 0470c7b27..d2a0fa225 100644 --- a/src/alloy/runtime/entry_table.h +++ b/src/alloy/runtime/entry_table.h @@ -47,8 +47,7 @@ class EntryTable { private: // TODO(benvanik): replace with a better data structure. std::mutex lock_; - typedef std::unordered_map EntryMap; - EntryMap map_; + std::unordered_map map_; }; } // namespace runtime diff --git a/src/alloy/runtime/module.cc b/src/alloy/runtime/module.cc index ff640088b..bf953bf1e 100644 --- a/src/alloy/runtime/module.cc +++ b/src/alloy/runtime/module.cc @@ -20,20 +20,13 @@ namespace runtime { Module::Module(Runtime* runtime) : runtime_(runtime), memory_(runtime->memory()) {} -Module::~Module() { - std::lock_guard guard(lock_); - SymbolMap::iterator it = map_.begin(); - for (; it != map_.end(); ++it) { - SymbolInfo* symbol_info = it->second; - delete symbol_info; - } -} +Module::~Module() = default; bool Module::ContainsAddress(uint64_t address) { return true; } SymbolInfo* Module::LookupSymbol(uint64_t address, bool wait) { lock_.lock(); - SymbolMap::const_iterator it = map_.find(address); + const auto it = map_.find(address); SymbolInfo* symbol_info = it != map_.end() ? it->second : nullptr; if (symbol_info) { if (symbol_info->status() == SymbolInfo::STATUS_DECLARING) { @@ -60,7 +53,7 @@ SymbolInfo::Status Module::DeclareSymbol(SymbolInfo::Type type, SymbolInfo** out_symbol_info) { *out_symbol_info = nullptr; lock_.lock(); - SymbolMap::const_iterator it = map_.find(address); + auto it = map_.find(address); SymbolInfo* symbol_info = it != map_.end() ? it->second : nullptr; SymbolInfo::Status status; if (symbol_info) { @@ -91,7 +84,7 @@ SymbolInfo::Status Module::DeclareSymbol(SymbolInfo::Type type, break; } map_[address] = symbol_info; - list_.push_back(symbol_info); + list_.emplace_back(symbol_info); status = SymbolInfo::STATUS_NEW; } lock_.unlock(); @@ -157,10 +150,9 @@ SymbolInfo::Status Module::DefineVariable(VariableInfo* symbol_info) { void Module::ForEachFunction(std::function callback) { SCOPE_profile_cpu_f("alloy"); std::lock_guard guard(lock_); - for (auto it = list_.begin(); it != list_.end(); ++it) { - SymbolInfo* symbol_info = *it; + for (auto& symbol_info : list_) { if (symbol_info->type() == SymbolInfo::TYPE_FUNCTION) { - FunctionInfo* info = (FunctionInfo*)symbol_info; + FunctionInfo* info = static_cast(symbol_info.get()); callback(info); } } @@ -173,9 +165,9 @@ void Module::ForEachFunction(size_t since, size_t& version, size_t count = list_.size(); version = count; for (size_t n = since; n < count; n++) { - SymbolInfo* symbol_info = list_[n]; + auto& symbol_info = list_[n]; if (symbol_info->type() == SymbolInfo::TYPE_FUNCTION) { - FunctionInfo* info = (FunctionInfo*)symbol_info; + FunctionInfo* info = static_cast(symbol_info.get()); callback(info); } } diff --git a/src/alloy/runtime/module.h b/src/alloy/runtime/module.h index e74899a63..0c46c0418 100644 --- a/src/alloy/runtime/module.h +++ b/src/alloy/runtime/module.h @@ -63,10 +63,8 @@ class Module { private: // TODO(benvanik): replace with a better data structure. std::mutex lock_; - typedef std::unordered_map SymbolMap; - SymbolMap map_; - typedef std::vector SymbolList; - SymbolList list_; + std::unordered_map map_; + std::vector> list_; }; } // namespace runtime diff --git a/src/alloy/runtime/runtime.cc b/src/alloy/runtime/runtime.cc index 955cf0d85..bca91c686 100644 --- a/src/alloy/runtime/runtime.cc +++ b/src/alloy/runtime/runtime.cc @@ -30,11 +30,7 @@ Runtime::Runtime(Memory* memory) : memory_(memory) {} Runtime::~Runtime() { { std::lock_guard guard(modules_lock_); - for (ModuleList::iterator it = modules_.begin(); it != modules_.end(); - ++it) { - Module* module = *it; - delete module; - } + modules_.clear(); } debugger_.reset(); @@ -99,28 +95,28 @@ int Runtime::Initialize(std::unique_ptr frontend, return 0; } -int Runtime::AddModule(Module* module) { +int Runtime::AddModule(std::unique_ptr module) { std::lock_guard guard(modules_lock_); - modules_.push_back(module); + modules_.push_back(std::move(module)); return 0; } Module* Runtime::GetModule(const char* name) { std::lock_guard guard(modules_lock_); - Module* result = NULL; - for (ModuleList::iterator it = modules_.begin(); it != modules_.end(); ++it) { - Module* module = *it; + for (const auto& module : modules_) { if (module->name() == name) { - result = module; - break; + return module.get(); } } - return result; + return nullptr; } -Runtime::ModuleList Runtime::GetModules() { +std::vector Runtime::GetModules() { std::lock_guard guard(modules_lock_); - ModuleList clone = modules_; + std::vector clone(modules_.size()); + for (const auto& module : modules_) { + clone.push_back(module.get()); + } return clone; } @@ -176,11 +172,9 @@ int Runtime::LookupFunctionInfo(uint64_t address, std::lock_guard guard(modules_lock_); // TODO(benvanik): sort by code address (if contiguous) so can bsearch. // TODO(benvanik): cache last module low/high, as likely to be in there. - for (ModuleList::const_iterator it = modules_.begin(); it != modules_.end(); - ++it) { - Module* module = *it; + for (const auto& module : modules_) { if (module->ContainsAddress(address)) { - code_module = module; + code_module = module.get(); break; } } diff --git a/src/alloy/runtime/runtime.h b/src/alloy/runtime/runtime.h index 97968a9b8..2fd5d1498 100644 --- a/src/alloy/runtime/runtime.h +++ b/src/alloy/runtime/runtime.h @@ -28,9 +28,6 @@ namespace alloy { namespace runtime { class Runtime { - public: - typedef std::vector ModuleList; - public: explicit Runtime(Memory* memory); virtual ~Runtime(); @@ -43,9 +40,10 @@ class Runtime { int Initialize(std::unique_ptr frontend, std::unique_ptr backend = 0); - int AddModule(Module* module); + int AddModule(std::unique_ptr module); Module* GetModule(const char* name); - ModuleList GetModules(); + Module* GetModule(const std::string& name) { return GetModule(name.c_str()); } + std::vector GetModules(); std::vector FindFunctionsWithAddress(uint64_t address); @@ -69,7 +67,7 @@ class Runtime { EntryTable entry_table_; std::mutex modules_lock_; - ModuleList modules_; + std::vector> modules_; }; } // namespace runtime diff --git a/src/alloy/runtime/symbol_info.h b/src/alloy/runtime/symbol_info.h index c8157105e..50f97e322 100644 --- a/src/alloy/runtime/symbol_info.h +++ b/src/alloy/runtime/symbol_info.h @@ -69,7 +69,7 @@ class FunctionInfo : public SymbolInfo { public: FunctionInfo(Module* module, uint64_t address); - virtual ~FunctionInfo(); + ~FunctionInfo() override; bool has_end_address() const { return end_address_ > 0; } uint64_t end_address() const { return end_address_; } @@ -101,9 +101,7 @@ class FunctionInfo : public SymbolInfo { class VariableInfo : public SymbolInfo { public: VariableInfo(Module* module, uint64_t address); - virtual ~VariableInfo(); - - private: + ~VariableInfo() override; }; } // namespace runtime diff --git a/src/xenia/kernel/objects/xuser_module.cc b/src/xenia/kernel/objects/xuser_module.cc index 3a07b209a..2008aa94a 100644 --- a/src/xenia/kernel/objects/xuser_module.cc +++ b/src/xenia/kernel/objects/xuser_module.cc @@ -103,25 +103,26 @@ XECLEANUP: X_STATUS XUserModule::LoadFromMemory(const void* addr, const size_t length) { Processor* processor = kernel_state()->processor(); XenonRuntime* runtime = processor->runtime(); - XexModule* xex_module = NULL; // Load the XEX into memory and decrypt. xe_xex2_options_t xex_options; xe_zero_struct(&xex_options, sizeof(xex_options)); xex_ = xe_xex2_load(kernel_state()->memory(), addr, length, xex_options); - XEEXPECTNOTNULL(xex_); + if (!xex_) { + return X_STATUS_UNSUCCESSFUL; + } // Prepare the module for execution. // Runtime takes ownership. - xex_module = new XexModule(runtime); - XEEXPECTZERO(xex_module->Load(name_, path_, xex_)); - XEEXPECTZERO(runtime->AddModule(xex_module)); + auto xex_module = std::make_unique(runtime); + if (xex_module->Load(name_, path_, xex_)) { + return X_STATUS_UNSUCCESSFUL; + } + if (runtime->AddModule(std::move(xex_module))) { + return X_STATUS_UNSUCCESSFUL; + } return X_STATUS_SUCCESS; - -XECLEANUP: - delete xex_module; - return X_STATUS_UNSUCCESSFUL; } void* XUserModule::GetProcAddressByOrdinal(uint16_t ordinal) { diff --git a/tools/alloy-sandbox/alloy-sandbox.cc b/tools/alloy-sandbox/alloy-sandbox.cc index 75ec323dc..437204d2d 100644 --- a/tools/alloy-sandbox/alloy-sandbox.cc +++ b/tools/alloy-sandbox/alloy-sandbox.cc @@ -38,9 +38,9 @@ int alloy_sandbox(int argc, xechar_t** argv) { // backend.reset(new alloy::backend::x64::X64Backend(runtime)); runtime->Initialize(std::move(backend)); - RawModule* module = new RawModule(runtime); + auto module = std::make_unique(runtime); module->LoadFile(0x82000000, "test\\codegen\\instr_add.bin"); - runtime->AddModule(module); + runtime->AddModule(std::move(module)); XenonThreadState* thread_state = new XenonThreadState(runtime, 100, 64 * 1024, 0);