Browse Source

Introducing GasMeter

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

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
{
}
Loading…
Cancel
Save