2016-06-22 15:37:51 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef LLVM_AVAILABLE
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "types.h"
|
2017-06-24 17:36:49 +02:00
|
|
|
#include "mutex.h"
|
2016-06-22 15:37:51 +02:00
|
|
|
|
2017-01-28 13:32:45 +01:00
|
|
|
#include "restore_new.h"
|
2016-06-22 15:37:51 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push, 0)
|
|
|
|
#endif
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2017-01-28 13:32:45 +01:00
|
|
|
#include "define_new_memleakdetect.h"
|
2016-06-22 15:37:51 +02:00
|
|
|
|
|
|
|
// Temporary compiler interface
|
|
|
|
class jit_compiler final
|
|
|
|
{
|
2017-06-24 17:36:49 +02:00
|
|
|
// Local LLVM context
|
|
|
|
llvm::LLVMContext m_context;
|
|
|
|
|
|
|
|
// JIT Event Listener
|
|
|
|
std::unique_ptr<struct EventListener> m_jit_el;
|
|
|
|
|
2016-06-22 15:37:51 +02:00
|
|
|
// Execution instance
|
|
|
|
std::unique_ptr<llvm::ExecutionEngine> m_engine;
|
|
|
|
|
2017-06-24 17:36:49 +02:00
|
|
|
// Link table
|
2017-06-22 23:52:09 +02:00
|
|
|
std::unordered_map<std::string, u64> m_link;
|
|
|
|
|
2017-02-26 16:56:31 +01:00
|
|
|
// Arch
|
|
|
|
std::string m_cpu;
|
|
|
|
|
2016-06-22 15:37:51 +02:00
|
|
|
public:
|
2018-05-01 12:20:36 +02:00
|
|
|
jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu, bool large = false);
|
2016-06-22 15:37:51 +02:00
|
|
|
~jit_compiler();
|
|
|
|
|
2017-06-24 17:36:49 +02:00
|
|
|
// Get LLVM context
|
|
|
|
auto& get_context()
|
|
|
|
{
|
|
|
|
return m_context;
|
|
|
|
}
|
|
|
|
|
2018-05-01 12:20:36 +02:00
|
|
|
auto& get_engine() const
|
|
|
|
{
|
|
|
|
return *m_engine;
|
|
|
|
}
|
|
|
|
|
2017-07-15 11:20:40 +02:00
|
|
|
// Add module (path to obj cache dir)
|
2017-06-22 23:52:09 +02:00
|
|
|
void add(std::unique_ptr<llvm::Module> module, const std::string& path);
|
|
|
|
|
2018-05-01 12:20:36 +02:00
|
|
|
// Add module (not cached)
|
|
|
|
void add(std::unique_ptr<llvm::Module> module);
|
|
|
|
|
2017-07-15 11:20:40 +02:00
|
|
|
// Add object (path to obj file)
|
|
|
|
void add(const std::string& path);
|
|
|
|
|
2017-06-22 23:52:09 +02:00
|
|
|
// Finalize
|
2017-06-24 17:36:49 +02:00
|
|
|
void fin();
|
2017-02-26 16:56:31 +01:00
|
|
|
|
2016-06-22 15:37:51 +02:00
|
|
|
// Get compiled function address
|
2017-06-24 17:36:49 +02:00
|
|
|
u64 get(const std::string& name);
|
|
|
|
|
|
|
|
// Add functions directly to the memory manager (name -> code)
|
|
|
|
static std::unordered_map<std::string, u64> add(std::unordered_map<std::string, std::string>);
|
2017-02-26 16:56:31 +01:00
|
|
|
|
|
|
|
// Get CPU info
|
2018-03-17 18:41:35 +01:00
|
|
|
static std::string cpu(const std::string& _cpu);
|
2017-06-29 16:25:39 +02:00
|
|
|
|
|
|
|
// Check JIT purpose
|
|
|
|
bool is_primary() const
|
|
|
|
{
|
|
|
|
return !m_link.empty();
|
|
|
|
}
|
2016-06-22 15:37:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|