2013-01-20 09:13:59 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2013-01-21 18:58:52 +00:00
|
|
|
#ifndef XENIA_CPU_CODEGEN_MODULE_GENERATOR_H_
|
|
|
|
#define XENIA_CPU_CODEGEN_MODULE_GENERATOR_H_
|
2013-01-20 09:13:59 +00:00
|
|
|
|
2013-01-28 01:49:32 +00:00
|
|
|
#include <xenia/common.h>
|
|
|
|
#include <xenia/core.h>
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
#include <xenia/cpu/sdb.h>
|
|
|
|
#include <xenia/core/memory.h>
|
|
|
|
#include <xenia/kernel/export.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace llvm {
|
2013-01-28 01:49:32 +00:00
|
|
|
class DIBuilder;
|
2013-01-28 20:36:39 +00:00
|
|
|
class ExecutionEngine;
|
2013-01-28 01:49:32 +00:00
|
|
|
class Function;
|
|
|
|
class FunctionType;
|
2013-01-20 09:13:59 +00:00
|
|
|
class LLVMContext;
|
|
|
|
class Module;
|
|
|
|
class MDNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace xe {
|
|
|
|
namespace cpu {
|
|
|
|
namespace codegen {
|
|
|
|
|
|
|
|
|
2013-01-21 18:58:52 +00:00
|
|
|
class ModuleGenerator {
|
2013-01-20 17:48:39 +00:00
|
|
|
public:
|
2013-01-21 18:58:52 +00:00
|
|
|
ModuleGenerator(
|
2013-01-20 09:13:59 +00:00
|
|
|
xe_memory_ref memory, kernel::ExportResolver* export_resolver,
|
2013-01-27 20:48:10 +00:00
|
|
|
const char* module_name, const char* module_path,
|
|
|
|
sdb::SymbolDatabase* sdb,
|
2013-01-28 20:36:39 +00:00
|
|
|
llvm::LLVMContext* context, llvm::Module* gen_module,
|
|
|
|
llvm::ExecutionEngine* engine);
|
2013-01-21 18:58:52 +00:00
|
|
|
~ModuleGenerator();
|
2013-01-20 09:13:59 +00:00
|
|
|
|
2013-01-21 18:58:52 +00:00
|
|
|
int Generate();
|
2013-01-20 09:13:59 +00:00
|
|
|
|
2013-01-28 01:49:32 +00:00
|
|
|
void AddFunctionsToMap(
|
|
|
|
std::tr1::unordered_map<uint32_t, llvm::Function*>& map);
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
private:
|
2013-01-21 18:58:52 +00:00
|
|
|
class CodegenFunction {
|
|
|
|
public:
|
|
|
|
sdb::FunctionSymbol* symbol;
|
|
|
|
llvm::FunctionType* function_type;
|
|
|
|
llvm::Function* function;
|
|
|
|
};
|
|
|
|
|
2013-01-21 09:11:57 +00:00
|
|
|
CodegenFunction* GetCodegenFunction(uint32_t address);
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
void AddImports();
|
2013-01-24 06:38:59 +00:00
|
|
|
llvm::Function* CreateFunctionDefinition(const char* name);
|
2013-01-21 09:11:57 +00:00
|
|
|
void AddMissingImport(sdb::FunctionSymbol* fn);
|
|
|
|
void AddPresentImport(sdb::FunctionSymbol* fn);
|
2013-01-20 17:48:39 +00:00
|
|
|
void PrepareFunction(sdb::FunctionSymbol* fn);
|
|
|
|
void BuildFunction(CodegenFunction* cgf);
|
2013-01-20 09:13:59 +00:00
|
|
|
void OptimizeFunction(llvm::Module* m, llvm::Function* fn);
|
|
|
|
|
|
|
|
xe_memory_ref memory_;
|
|
|
|
kernel::ExportResolver* export_resolver_;
|
2013-01-27 20:48:10 +00:00
|
|
|
char* module_name_;
|
|
|
|
char* module_path_;
|
2013-01-20 09:13:59 +00:00
|
|
|
sdb::SymbolDatabase* sdb_;
|
|
|
|
|
|
|
|
llvm::LLVMContext* context_;
|
|
|
|
llvm::Module* gen_module_;
|
2013-01-28 20:36:39 +00:00
|
|
|
llvm::ExecutionEngine* engine_;
|
2013-01-20 09:13:59 +00:00
|
|
|
llvm::DIBuilder* di_builder_;
|
|
|
|
llvm::MDNode* cu_;
|
2013-01-20 17:48:39 +00:00
|
|
|
|
2013-01-21 09:11:57 +00:00
|
|
|
std::map<uint32_t, CodegenFunction*> functions_;
|
2013-01-20 09:13:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace codegen
|
|
|
|
} // namespace cpu
|
|
|
|
} // namespace xe
|
|
|
|
|
|
|
|
|
2013-01-21 18:58:52 +00:00
|
|
|
#endif // XENIA_CPU_CODEGEN_MODULE_GENERATOR_H_
|