mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 04:06:44 +00:00
Introducing GasMeter
This commit is contained in:
parent
7f8848744d
commit
d3f59f6de4
3 changed files with 61 additions and 1 deletions
|
|
@ -12,6 +12,9 @@
|
||||||
namespace evmcc
|
namespace evmcc
|
||||||
{
|
{
|
||||||
|
|
||||||
|
using dev::eth::Instruction;
|
||||||
|
using namespace dev::eth; // We should move all the JIT code into dev::eth namespace
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
llvm::Type* word8;
|
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)
|
for (auto currentPC = basicBlock.begin(); currentPC != basicBlock.end(); ++currentPC)
|
||||||
{
|
{
|
||||||
using dev::eth::Instruction;
|
|
||||||
auto inst = static_cast<Instruction>(bytecode[currentPC]);
|
auto inst = static_cast<Instruction>(bytecode[currentPC]);
|
||||||
switch (inst)
|
switch (inst)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
49
evmcc/GasMeter.cpp
Normal file
49
evmcc/GasMeter.cpp
Normal file
|
|
@ -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
Normal file
9
evmcc/GasMeter.h
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <libevmface/Instruction.h>
|
||||||
|
|
||||||
|
namespace evmcc
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue