diff --git a/src/xenia/cpu/codegen/module_generator.cc b/src/xenia/cpu/codegen/module_generator.cc deleted file mode 100644 index a2a1c0acd..000000000 --- a/src/xenia/cpu/codegen/module_generator.cc +++ /dev/null @@ -1,151 +0,0 @@ -/** - ****************************************************************************** - * Xenia : Xbox 360 Emulator Research Project * - ****************************************************************************** - * Copyright 2013 Ben Vanik. All rights reserved. * - * Released under the BSD license - see LICENSE in the root for more details. * - ****************************************************************************** - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - // Build out all the user functions. - size_t n = 0; - XELOGI("Beginning generation of %ld functions...", functions.size()); - for (std::map::iterator it = - functions_.begin(); it != functions_.end(); ++it, ++n) { - FunctionSymbol* symbol = it->second->symbol; - XELOGI("Generating %ld/%ld %.8X %s", - n, functions_.size(), symbol->start_address, symbol->name()); - BuildFunction(it->second); - } - XELOGI("Function generation complete"); - - di_builder_->finalize(); - - return 0; -} - -void ModuleGenerator::AddFunctionsToMap( - std::tr1::unordered_map& map) { - for (std::map::iterator it = functions_.begin(); - it != functions_.end(); ++it) { - map.insert(std::pair(it->first, it->second->function)); - } -} - - -void ModuleGenerator::AddMissingImport(FunctionSymbol* fn) { - Module *m = gen_module_; - LLVMContext& context = m->getContext(); - - // Create the function (and setup args/attributes/etc). - Function* f = CreateFunctionDefinition(fn->name()); - - BasicBlock* block = BasicBlock::Create(context, "entry", f); - IRBuilder<> b(block); - - if (FLAGS_trace_kernel_calls) { - Value* traceKernelCall = m->getFunction("XeTraceKernelCall"); - b.CreateCall4( - traceKernelCall, - f->arg_begin(), - b.getInt64(fn->start_address), - ++f->arg_begin(), - b.getInt64((uint64_t)fn->kernel_export)); - } - - b.CreateRetVoid(); - - OptimizeFunction(m, f); - - //GlobalAlias *alias = new GlobalAlias(f->getType(), GlobalValue::InternalLinkage, name, f, m); - // printf(" F %.8X %.8X %.3X (%3d) %s %s\n", - // info->value_address, info->thunk_address, info->ordinal, - // info->ordinal, implemented ? " " : "!!", name); - // For values: - // printf(" V %.8X %.3X (%3d) %s %s\n", - // info->value_address, info->ordinal, info->ordinal, - // implemented ? " " : "!!", name); -} - -void ModuleGenerator::AddPresentImport(FunctionSymbol* fn) { - Module *m = gen_module_; - LLVMContext& context = m->getContext(); - - const DataLayout* dl = engine_->getDataLayout(); - Type* intPtrTy = dl->getIntPtrType(context); - Type* int8PtrTy = PointerType::getUnqual(Type::getInt8Ty(context)); - - // Add the externs. - // We have both the shim function pointer and the shim data pointer. - char shim_name[256]; - xesnprintfa(shim_name, XECOUNT(shim_name), - "__shim_%s", fn->kernel_export->name); - char shim_data_name[256]; - xesnprintfa(shim_data_name, XECOUNT(shim_data_name), - "__shim_data_%s", fn->kernel_export->name); - std::vector shimArgs; - shimArgs.push_back(int8PtrTy); - shimArgs.push_back(int8PtrTy); - FunctionType* shimTy = FunctionType::get( - Type::getVoidTy(context), shimArgs, false); - Function* shim = Function::Create( - shimTy, Function::ExternalLinkage, shim_name, m); - - GlobalVariable* gv = new GlobalVariable( - *m, int8PtrTy, true, GlobalValue::ExternalLinkage, 0, - shim_data_name); - - // TODO(benvanik): don't initialize on startup - move to exec_module - gv->setInitializer(ConstantExpr::getIntToPtr( - ConstantInt::get(intPtrTy, - (uintptr_t)fn->kernel_export->function_data.shim_data), - int8PtrTy)); - engine_->addGlobalMapping(shim, - (void*)fn->kernel_export->function_data.shim); - - // Create the function (and setup args/attributes/etc). - Function* f = CreateFunctionDefinition(fn->name()); - - BasicBlock* block = BasicBlock::Create(context, "entry", f); - IRBuilder<> b(block); - - if (FLAGS_trace_kernel_calls) { - Value* traceKernelCall = m->getFunction("XeTraceKernelCall"); - b.CreateCall4( - traceKernelCall, - f->arg_begin(), - b.getInt64(fn->start_address), - ++f->arg_begin(), - b.getInt64((uint64_t)fn->kernel_export)); - } - - b.CreateCall2( - shim, - f->arg_begin(), - b.CreateLoad(gv)); - - b.CreateRetVoid(); - - OptimizeFunction(m, f); -} diff --git a/src/xenia/cpu/codegen/module_generator.h b/src/xenia/cpu/codegen/module_generator.h deleted file mode 100644 index 2e2bbba4e..000000000 --- a/src/xenia/cpu/codegen/module_generator.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - ****************************************************************************** - * Xenia : Xbox 360 Emulator Research Project * - ****************************************************************************** - * Copyright 2013 Ben Vanik. All rights reserved. * - * Released under the BSD license - see LICENSE in the root for more details. * - ****************************************************************************** - */ - -#ifndef XENIA_CPU_CODEGEN_MODULE_GENERATOR_H_ -#define XENIA_CPU_CODEGEN_MODULE_GENERATOR_H_ - -#include -#include - -#include -#include -#include - - -namespace llvm { - class DIBuilder; - class ExecutionEngine; - class Function; - class FunctionType; - class LLVMContext; - class Module; - class MDNode; -} - - -namespace xe { -namespace cpu { -namespace codegen { - - -class ModuleGenerator { -public: - ModuleGenerator( - xe_memory_ref memory, kernel::ExportResolver* export_resolver, - const char* module_name, const char* module_path, - sdb::SymbolDatabase* sdb, - llvm::LLVMContext* context, llvm::Module* gen_module, - llvm::ExecutionEngine* engine); - ~ModuleGenerator(); - - int Generate(); - - void AddFunctionsToMap( - std::tr1::unordered_map& map); - -private: - class CodegenFunction { - public: - sdb::FunctionSymbol* symbol; - llvm::FunctionType* function_type; - llvm::Function* function; - }; - - CodegenFunction* GetCodegenFunction(uint32_t address); - - void AddImports(); - llvm::Function* CreateFunctionDefinition(const char* name); - void AddMissingImport(sdb::FunctionSymbol* fn); - void AddPresentImport(sdb::FunctionSymbol* fn); - void PrepareFunction(sdb::FunctionSymbol* fn); - void BuildFunction(CodegenFunction* cgf); - void OptimizeFunction(llvm::Module* m, llvm::Function* fn); - - xe_memory_ref memory_; - kernel::ExportResolver* export_resolver_; - char* module_name_; - char* module_path_; - sdb::SymbolDatabase* sdb_; - - llvm::LLVMContext* context_; - llvm::Module* gen_module_; - llvm::ExecutionEngine* engine_; - llvm::DIBuilder* di_builder_; - llvm::MDNode* cu_; - - std::map functions_; -}; - - -} // namespace codegen -} // namespace cpu -} // namespace xe - - -#endif // XENIA_CPU_CODEGEN_MODULE_GENERATOR_H_ diff --git a/src/xenia/cpu/codegen/recompiler.cc b/src/xenia/cpu/codegen/recompiler.cc deleted file mode 100644 index fe65c2e4a..000000000 --- a/src/xenia/cpu/codegen/recompiler.cc +++ /dev/null @@ -1,121 +0,0 @@ -/** - ****************************************************************************** - * Xenia : Xbox 360 Emulator Research Project * - ****************************************************************************** - * Copyright 2013 Ben Vanik. All rights reserved. * - * Released under the BSD license - see LICENSE in the root for more details. * - ****************************************************************************** - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - - -using namespace llvm; -using namespace xe; -using namespace xe::cpu; -using namespace xe::cpu::codegen; -using namespace xe::cpu::sdb; -using namespace xe::kernel; - - -Recompiler::Recompiler( - xe_memory_ref memory, shared_ptr export_resolver, - shared_ptr sdb, const char* module_name) { - memory_ = xe_memory_retain(memory); - export_resolver_ = export_resolver; - sdb_ = sdb; -} - -Recompiler::~Recompiler() { - xe_memory_release(memory_); -} - -int Recompiler::Process() { - // Check to see if a cached result exists on disk - if so, use it. - if (!LoadLibrary(library_path)) { - // Succeeded - done! - return 0; - } - - // Generate all the code and dump it to code units. - // This happens in multiple threads. - if (GenerateCodeUnits()) { - XELOGCPU("Failed to generate code units for module"); - return 1; - } - - // Link all of the generated code units. This runs any link-time optimizations - // and other per-library operations. - if (LinkCodeUnits()) { - XELOGCPU("Failed to link code units"); - return 1; - } - - // Load the built library now. - if (LoadLibrary(library_path)) { - XELOGCPU("Failed to load the generated library"); - return 1; - } - - return 0; -} - -int Recompiler::GenerateCodeUnits() { - xe_system_info sys_info; - XEEXPECTZERO(xe_pal_get_system_info(&sys_info)); - // sys_info.processors.physical_count; - // sys_info.processors.logical_count; - - // Queue up all functions to process. - - // Spawn worker threads to process the queue. - - // Wait until all threads complete. - - return 0; - -XECLEANUP: - return 1; -} - -int Recompiler::LinkCodeUnits() { - // Invoke linker. - - return 0; -} - -int Recompiler::LoadLibrary(const char* path) { - // Check file exists. - - // TODO(benvanik): version check somehow? - - // Load library. - - return 0; -} diff --git a/src/xenia/cpu/codegen/recompiler.h b/src/xenia/cpu/codegen/recompiler.h deleted file mode 100644 index 1c5977a98..000000000 --- a/src/xenia/cpu/codegen/recompiler.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - ****************************************************************************** - * Xenia : Xbox 360 Emulator Research Project * - ****************************************************************************** - * Copyright 2013 Ben Vanik. All rights reserved. * - * Released under the BSD license - see LICENSE in the root for more details. * - ****************************************************************************** - */ - -#ifndef XENIA_CPU_CODEGEN_RECOMPILER_H_ -#define XENIA_CPU_CODEGEN_RECOMPILER_H_ - -#include - -#include - - -namespace xe { -namespace cpu { -namespace codegen { - - -class Recompiler { -public: - Recompiler( - xe_memory_ref memory, shared_ptr export_resolver, - shared_ptr sdb, const char* module_name); - ~Recompiler(); - - int Process(); - -private: - int GenerateCodeUnits(); - int LinkCodeUnits(); - int LoadLibrary(const char* path); - - xechar_t* library_path_; -}; - - - -} // namespace codegen -} // namespace cpu -} // namespace xe - - -#endif // XENIA_CPU_CODEGEN_RECOMPILER_H_