Browse Source

Introducing GasMeter

cl-refactor
Paweł Bylica 10 years ago
parent
commit
5e3113e49e
  1. 4
      evmcc/Compiler.cpp
  2. 49
      evmcc/GasMeter.cpp
  3. 9
      evmcc/GasMeter.h
  4. 2
      windows/evmcc.vcxproj
  5. 2
      windows/evmcc.vcxproj.filters

4
evmcc/Compiler.cpp

@ -12,6 +12,9 @@
namespace evmcc
{
using dev::eth::Instruction;
using namespace dev::eth; // We should move all the JIT code into dev::eth namespace
struct
{
llvm::Type* word8;
@ -191,7 +194,6 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
for (auto currentPC = basicBlock.begin(); currentPC != basicBlock.end(); ++currentPC)
{
using dev::eth::Instruction;
auto inst = static_cast<Instruction>(bytecode[currentPC]);
switch (inst)
{

49
evmcc/GasMeter.cpp

@ -0,0 +1,49 @@
#include "GasMeter.h"
#include <libevmface/Instruction.h>
#include <libevm/FeeStructure.h>
namespace evmcc
{
using namespace dev::eth; // We should move all the JIT code into dev::eth namespace
namespace
{
uint64_t getStepCost(dev::eth::Instruction inst) // TODO: Add this function to FeeSructure
{
switch (inst)
{
case Instruction::STOP:
case Instruction::SUICIDE:
return 0;
case Instruction::SSTORE:
return static_cast<uint64_t>(c_sstoreGas);
case Instruction::SLOAD:
return static_cast<uint64_t>(c_sloadGas);
case Instruction::SHA3:
return static_cast<uint64_t>(c_sha3Gas);
case Instruction::BALANCE:
return static_cast<uint64_t>(c_sha3Gas);
case Instruction::CALL:
case Instruction::CALLCODE:
return static_cast<uint64_t>(c_callGas);
case Instruction::CREATE:
return static_cast<uint64_t>(c_createGas);
default: // Assumes instruction code is valid
return static_cast<uint64_t>(c_stepGas);;
}
}
}
}

9
evmcc/GasMeter.h

@ -0,0 +1,9 @@
#pragma once
#include <libevmface/Instruction.h>
namespace evmcc
{
}

2
windows/evmcc.vcxproj

@ -24,6 +24,7 @@
<ClCompile Include="..\evmcc\evmcc.cpp" />
<ClCompile Include="..\evmcc\ExecutionEngine.cpp" />
<ClCompile Include="..\evmcc\Ext.cpp" />
<ClCompile Include="..\evmcc\GasMeter.cpp" />
<ClCompile Include="..\evmcc\Memory.cpp" />
<ClCompile Include="..\evmcc\Runtime.cpp" />
<ClCompile Include="..\evmcc\Utils.cpp" />
@ -33,6 +34,7 @@
<ClInclude Include="..\evmcc\Compiler.h" />
<ClInclude Include="..\evmcc\ExecutionEngine.h" />
<ClInclude Include="..\evmcc\Ext.h" />
<ClInclude Include="..\evmcc\GasMeter.h" />
<ClInclude Include="..\evmcc\Memory.h" />
<ClInclude Include="..\evmcc\Runtime.h" />
<ClInclude Include="..\evmcc\Utils.h" />

2
windows/evmcc.vcxproj.filters

@ -9,6 +9,7 @@
<ClCompile Include="..\evmcc\Utils.cpp" />
<ClCompile Include="..\evmcc\Runtime.cpp" />
<ClCompile Include="..\evmcc\BasicBlock.cpp" />
<ClCompile Include="..\evmcc\GasMeter.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\evmcc\Compiler.h" />
@ -18,5 +19,6 @@
<ClInclude Include="..\evmcc\Utils.h" />
<ClInclude Include="..\evmcc\Runtime.h" />
<ClInclude Include="..\evmcc\BasicBlock.h" />
<ClInclude Include="..\evmcc\GasMeter.h" />
</ItemGroup>
</Project>
Loading…
Cancel
Save