artur-zawlocki
10 years ago
12 changed files with 135 additions and 79 deletions
@ -0,0 +1,26 @@ |
|||
|
|||
#include "CompilerHelper.h" |
|||
|
|||
#include <llvm/IR/Function.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
namespace jit |
|||
{ |
|||
|
|||
CompilerHelper::CompilerHelper(llvm::IRBuilder<>& _builder) : |
|||
m_builder(_builder) |
|||
{} |
|||
|
|||
llvm::Module* CompilerHelper::getModule() |
|||
{ |
|||
assert(m_builder.GetInsertBlock()); |
|||
assert(m_builder.GetInsertBlock()->getParent()); // BB must be in a function
|
|||
return m_builder.GetInsertBlock()->getParent()->getParent(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
|
|||
#pragma once |
|||
|
|||
#include <llvm/IR/IRBuilder.h> |
|||
|
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
namespace jit |
|||
{ |
|||
|
|||
/// Base class for compiler helpers like Memory, GasMeter, etc.
|
|||
class CompilerHelper |
|||
{ |
|||
protected: |
|||
CompilerHelper(llvm::IRBuilder<>& _builder); |
|||
|
|||
CompilerHelper(const CompilerHelper&) = delete; |
|||
void operator=(CompilerHelper) = delete; |
|||
|
|||
/// Reference to the IR module being compiled
|
|||
llvm::Module* getModule(); |
|||
|
|||
/// Reference to parent compiler IR builder
|
|||
llvm::IRBuilder<>& m_builder; |
|||
}; |
|||
|
|||
|
|||
/// Saves the insert point of the IR builder and restores it when destructed
|
|||
struct InsertPointGuard |
|||
{ |
|||
InsertPointGuard(llvm::IRBuilder<>& _builder) : |
|||
m_builder(_builder), |
|||
m_insertBB(m_builder.GetInsertBlock()), |
|||
m_insertPt(m_builder.GetInsertPoint()) |
|||
{} |
|||
|
|||
InsertPointGuard(const InsertPointGuard&) = delete; |
|||
void operator=(InsertPointGuard) = delete; |
|||
|
|||
~InsertPointGuard() |
|||
{ |
|||
m_builder.SetInsertPoint(m_insertBB, m_insertPt); |
|||
} |
|||
|
|||
private: |
|||
llvm::IRBuilder<>& m_builder; |
|||
llvm::BasicBlock* m_insertBB; |
|||
llvm::BasicBlock::iterator m_insertPt; |
|||
}; |
|||
|
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue