Browse Source

Add raiseException helper to RuntimeManager [#81563132]

cl-refactor
Paweł Bylica 10 years ago
parent
commit
ac38bf9ac1
  1. 6
      libevmjit/GasMeter.cpp
  2. 2
      libevmjit/GasMeter.h
  3. 7
      libevmjit/Runtime.cpp
  4. 8
      libevmjit/Runtime.h

6
libevmjit/GasMeter.cpp

@ -101,11 +101,7 @@ GasMeter::GasMeter(llvm::IRBuilder<>& _builder, RuntimeManager& _runtimeManager)
m_builder.CreateCondBr(isOutOfGas, outOfGasBB, updateBB);
m_builder.SetInsertPoint(outOfGasBB);
//auto longjmpFunc = llvm::Intrinsic::getDeclaration(_module, llvm::Intrinsic::eh_sjlj_longjmp);
llvm::Type* args[] = {Type::BytePtr, m_builder.getInt32Ty()};
auto longjmpNative = llvm::Function::Create(llvm::FunctionType::get(Type::Void, args, false), llvm::Function::ExternalLinkage, "longjmp", module);
m_builder.CreateCall2(longjmpNative, m_runtimeManager.getJmpBuf(), Constant::get(ReturnCode::OutOfGas));
_runtimeManager.raiseException(ReturnCode::OutOfGas);
m_builder.CreateUnreachable();
m_builder.SetInsertPoint(updateBB);

2
libevmjit/GasMeter.h

@ -13,7 +13,7 @@ namespace jit
{
class RuntimeManager;
class GasMeter : public CompilerHelper
class GasMeter : public CompilerHelper // TODO: Use RuntimeHelper
{
public:
GasMeter(llvm::IRBuilder<>& _builder, RuntimeManager& _runtimeManager);

7
libevmjit/Runtime.cpp

@ -113,6 +113,8 @@ bytesConstRef Runtime::getReturnData() const
RuntimeManager::RuntimeManager(llvm::IRBuilder<>& _builder): CompilerHelper(_builder)
{
m_dataPtr = new llvm::GlobalVariable(*getModule(), Type::RuntimePtr, false, llvm::GlobalVariable::PrivateLinkage, llvm::UndefValue::get(Type::RuntimePtr), "rt");
llvm::Type* args[] = {Type::BytePtr, m_builder.getInt32Ty()};
m_longjmp = llvm::Function::Create(llvm::FunctionType::get(Type::Void, args, false), llvm::Function::ExternalLinkage, "longjmp", getModule());
// Export data
auto mainFunc = getMainFunction();
@ -149,6 +151,11 @@ void RuntimeManager::registerReturnData(llvm::Value* _offset, llvm::Value* _size
set(RuntimeData::ReturnDataSize, _size);
}
void RuntimeManager::raiseException(ReturnCode _returnCode)
{
m_builder.CreateCall2(m_longjmp, getJmpBuf(), Constant::get(_returnCode));
}
llvm::Value* RuntimeManager::get(Instruction _inst)
{
switch (_inst)

8
libevmjit/Runtime.h

@ -7,6 +7,7 @@
#include "CompilerHelper.h"
#include "Utils.h"
#include "Type.h"
#ifdef _MSC_VER
@ -99,16 +100,19 @@ public:
llvm::Value* getGas(); // TODO: Remove
llvm::Value* getCallData();
llvm::Value* getCode();
llvm::Value* getJmpBuf();
void setGas(llvm::Value* _gas);
void registerReturnData(llvm::Value* _index, llvm::Value* _size);
void raiseException(ReturnCode _returnCode);
private:
llvm::Value* getPtr(RuntimeData::Index _index);
void set(RuntimeData::Index _index, llvm::Value* _value);
llvm::Value* getJmpBuf();
llvm::GlobalVariable* m_dataPtr;
llvm::GlobalVariable* m_dataPtr = nullptr;
llvm::Function* m_longjmp = nullptr;
};
}

Loading…
Cancel
Save