Browse Source

Introducing CompilerHelper - a base class for... compiler helper classes like Memory, GasMeter, etc.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
83642fe9de
  1. 2
      evmcc/Compiler.cpp
  2. 13
      evmcc/CompilerHelper.cpp
  3. 34
      evmcc/CompilerHelper.h
  4. 4
      evmcc/Ext.cpp
  5. 9
      evmcc/Ext.h
  6. 2
      evmcc/GasMeter.cpp
  7. 11
      evmcc/GasMeter.h
  8. 2
      evmcc/Memory.cpp
  9. 14
      evmcc/Memory.h
  10. 6
      windows/evmcc.vcxproj
  11. 2
      windows/evmcc.vcxproj.filters

2
evmcc/Compiler.cpp

@ -714,7 +714,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, const bytes& bytecode,
auto srcIdx = stack.pop();
auto reqBytes = stack.pop();
auto srcPtr = ext.code();
auto srcPtr = ext.code(); // TODO: Code & its size are constants, feature #80814234
auto srcSize = ext.codesize();
memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes);

13
evmcc/CompilerHelper.cpp

@ -0,0 +1,13 @@
#include "CompilerHelper.h"
namespace dev
{
namespace eth
{
namespace jit
{
}
}
}

34
evmcc/CompilerHelper.h

@ -0,0 +1,34 @@
#pragma once
#include <llvm/IR/IRBuilder.h>
namespace dev
{
namespace eth
{
namespace jit
{
class CompilerHelper
{
protected:
CompilerHelper(llvm::IRBuilder<>& _builder, llvm::Module* _module):
m_builder(_builder),
m_module(_module)
{}
CompilerHelper(const CompilerHelper&) = delete;
void operator=(CompilerHelper) = delete;
/// Reference to parent compiler IR builder
llvm::IRBuilder<>& m_builder;
/// Reference to the IR module being compiled
llvm::Module* m_module;
};
}
}
}

4
evmcc/Ext.cpp

@ -43,8 +43,8 @@ struct ExtData
const byte* code;
};
Ext::Ext(llvm::IRBuilder<>& _builder, llvm::Module* module)
: m_builder(_builder)
Ext::Ext(llvm::IRBuilder<>& _builder, llvm::Module* module):
CompilerHelper(_builder, module)
{
auto&& ctx = _builder.getContext();

9
evmcc/Ext.h

@ -1,10 +1,10 @@
#pragma once
#include <llvm/IR/IRBuilder.h>
#include <libevm/ExtVMFace.h>
#include "CompilerHelper.h"
namespace dev
{
namespace eth
@ -12,11 +12,10 @@ namespace eth
namespace jit
{
class Ext
class Ext : public CompilerHelper
{
public:
Ext(llvm::IRBuilder<>& _builder, llvm::Module* module);
static void init(std::unique_ptr<ExtVMFace> _ext);
llvm::Value* store(llvm::Value* _index);
void setStore(llvm::Value* _index, llvm::Value* _value);
@ -54,8 +53,6 @@ private:
llvm::Value* bswap(llvm::Value*);
private:
llvm::IRBuilder<>& m_builder;
llvm::Value* m_args[2];
llvm::Value* m_arg2;
llvm::Value* m_arg3;

2
evmcc/GasMeter.cpp

@ -81,7 +81,7 @@ bool isCostBlockEnd(Instruction _inst)
}
GasMeter::GasMeter(llvm::IRBuilder<>& _builder, llvm::Module* _module) :
m_builder(_builder)
CompilerHelper(_builder, _module)
{
m_gas = new llvm::GlobalVariable(*_module, Type::i256, false, llvm::GlobalVariable::ExternalLinkage, nullptr, "gas");
m_gas->setUnnamedAddr(true); // Address is not important

11
evmcc/GasMeter.h

@ -1,10 +1,10 @@
#pragma once
#include <llvm/IR/IRBuilder.h>
#include <libevmface/Instruction.h>
#include "CompilerHelper.h"
namespace dev
{
namespace eth
@ -12,14 +12,11 @@ namespace eth
namespace jit
{
class GasMeter
class GasMeter : public CompilerHelper
{
public:
GasMeter(llvm::IRBuilder<>& _builder, llvm::Module* _module);
GasMeter(const GasMeter&) = delete;
void operator=(GasMeter) = delete;
/// Count step cost of instruction
void count(Instruction _inst);
@ -42,7 +39,7 @@ private:
/// Cumulative gas cost of a block of instructions
/// @TODO Handle overflow
uint64_t m_blockCost = 0;
llvm::IRBuilder<>& m_builder;
llvm::CallInst* m_checkCall = nullptr;
llvm::GlobalVariable* m_gas;
llvm::Function* m_gasCheckFunc;

2
evmcc/Memory.cpp

@ -23,7 +23,7 @@ namespace jit
{
Memory::Memory(llvm::IRBuilder<>& _builder, llvm::Module* _module, GasMeter& _gasMeter):
m_builder(_builder)
CompilerHelper(_builder, _module)
{
auto i64Ty = m_builder.getInt64Ty();
llvm::Type* argTypes[] = {i64Ty, i64Ty};

14
evmcc/Memory.h

@ -1,9 +1,9 @@
#pragma once
#include <llvm/IR/IRBuilder.h>
#include <libdevcore/Common.h>
#include "CompilerHelper.h"
namespace dev
{
namespace eth
@ -11,14 +11,10 @@ namespace eth
namespace jit
{
class GasMeter;
class Memory
class Memory : public CompilerHelper
{
public:
Memory(llvm::IRBuilder<>& _builder, llvm::Module* _module, GasMeter& _gasMeter);
Memory(const Memory&) = delete;
void operator=(Memory) = delete;
Memory(llvm::IRBuilder<>& _builder, llvm::Module* _module, class GasMeter& _gasMeter);
llvm::Value* loadWord(llvm::Value* _addr);
void storeWord(llvm::Value* _addr, llvm::Value* _word);
@ -44,8 +40,6 @@ private:
llvm::Function* createRequireFunc(llvm::Module* _module, GasMeter& _gasMeter);
private:
llvm::IRBuilder<>& m_builder;
llvm::GlobalVariable* m_data;
llvm::GlobalVariable* m_size;

6
windows/evmcc.vcxproj

@ -21,6 +21,7 @@
<ItemGroup>
<ClCompile Include="..\evmcc\BasicBlock.cpp" />
<ClCompile Include="..\evmcc\Compiler.cpp" />
<ClCompile Include="..\evmcc\CompilerHelper.cpp" />
<ClCompile Include="..\evmcc\evmcc.cpp" />
<ClCompile Include="..\evmcc\ExecutionEngine.cpp" />
<ClCompile Include="..\evmcc\Ext.cpp" />
@ -33,6 +34,7 @@
<ItemGroup>
<ClInclude Include="..\evmcc\BasicBlock.h" />
<ClInclude Include="..\evmcc\Compiler.h" />
<ClInclude Include="..\evmcc\CompilerHelper.h" />
<ClInclude Include="..\evmcc\ExecutionEngine.h" />
<ClInclude Include="..\evmcc\Ext.h" />
<ClInclude Include="..\evmcc\GasMeter.h" />
@ -123,8 +125,9 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../llvm-3.5.0/include;../../builds/llvm3.5/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnablePREfast>false</EnablePREfast>
<TreatWarningAsError>false</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -144,6 +147,7 @@
<AdditionalIncludeDirectories>../../llvm-3.5.0/include;../../builds/llvm3.5/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4068;4244;4267;4800</DisableSpecificWarnings>
<EnablePREfast>false</EnablePREfast>
<TreatWarningAsError>false</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

2
windows/evmcc.vcxproj.filters

@ -11,6 +11,7 @@
<ClCompile Include="..\evmcc\BasicBlock.cpp" />
<ClCompile Include="..\evmcc\GasMeter.cpp" />
<ClCompile Include="..\evmcc\Type.cpp" />
<ClCompile Include="..\evmcc\CompilerHelper.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\evmcc\Compiler.h" />
@ -22,5 +23,6 @@
<ClInclude Include="..\evmcc\BasicBlock.h" />
<ClInclude Include="..\evmcc\GasMeter.h" />
<ClInclude Include="..\evmcc\Type.h" />
<ClInclude Include="..\evmcc\CompilerHelper.h" />
</ItemGroup>
</Project>
Loading…
Cancel
Save