Change the name of a module to some hash (for caching)

This commit is contained in:
Paweł Bylica 2014-12-18 13:01:45 +01:00
parent bd85efa299
commit 2332595c9c

View file

@ -1,6 +1,7 @@
#include "Compiler.h"
#include <functional>
#include <fstream>
#include <chrono>
@ -153,8 +154,13 @@ void Compiler::createBasicBlocks(bytes const& _bytecode)
std::unique_ptr<llvm::Module> Compiler::compile(bytes const& _bytecode)
{
// TODO: Better hash of code needed, probably SHA3
std::string code{reinterpret_cast<char const*>(_bytecode.data()), _bytecode.size()};
auto hash = std::hash<std::string>{}(code);
auto strHash = std::to_string(hash);
auto compilationStartTime = std::chrono::high_resolution_clock::now();
auto module = std::unique_ptr<llvm::Module>(new llvm::Module("main", m_builder.getContext()));
auto module = std::unique_ptr<llvm::Module>(new llvm::Module(strHash, m_builder.getContext()));
// Create main function
auto mainFuncType = llvm::FunctionType::get(Type::MainReturn, Type::RuntimePtr, false);