mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
Use external counter for gas (external linkage global variable)
[#79942174]
This commit is contained in:
parent
4eb65a8b2c
commit
39ba3ae1d9
6 changed files with 23 additions and 17 deletions
|
|
@ -85,7 +85,8 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
|
|||
ext->data = calldata;
|
||||
|
||||
// Init runtime
|
||||
Runtime runtime(std::move(ext));
|
||||
uint64_t gas = 1000000;
|
||||
Runtime runtime(gas, std::move(ext));
|
||||
|
||||
auto entryFunc = module->getFunction("main");
|
||||
if (!entryFunc)
|
||||
|
|
@ -95,6 +96,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
|
|||
}
|
||||
|
||||
auto result = exec->runFunction(entryFunc, {});
|
||||
gas = static_cast<decltype(gas)>(Runtime::getGas());
|
||||
if (auto intResult = result.IntVal.getZExtValue())
|
||||
{
|
||||
auto index = intResult >> 32;
|
||||
|
|
|
|||
|
|
@ -9,12 +9,6 @@
|
|||
|
||||
#include "Runtime.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
using namespace llvm;
|
||||
using llvm::types::i;
|
||||
using Linkage = llvm::GlobalValue::LinkageTypes;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ bool isCostBlockEnd(Instruction _inst)
|
|||
GasMeter::GasMeter(llvm::IRBuilder<>& _builder, llvm::Module* _module):
|
||||
m_builder(_builder)
|
||||
{
|
||||
m_gas = new llvm::GlobalVariable(*_module, Type::i256, false, llvm::GlobalVariable::PrivateLinkage, llvm::UndefValue::get(Type::i256), "gas");
|
||||
m_gas = new llvm::GlobalVariable(*_module, Type::i256, false, llvm::GlobalVariable::ExternalLinkage, nullptr, "gas");
|
||||
m_gas->setUnnamedAddr(true); // Address is not important
|
||||
|
||||
auto pt = m_builder.GetInsertPoint();
|
||||
|
|
|
|||
|
|
@ -15,12 +15,6 @@
|
|||
#include "Runtime.h"
|
||||
#include "GasMeter.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace evmcc
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,14 @@ namespace evmcc
|
|||
|
||||
static Runtime* g_runtime;
|
||||
|
||||
Runtime::Runtime(std::unique_ptr<dev::eth::ExtVMFace> _ext)
|
||||
: m_ext(std::move(_ext))
|
||||
extern "C" { EXPORT i256 gas; }
|
||||
|
||||
Runtime::Runtime(dev::u256 _gas, std::unique_ptr<dev::eth::ExtVMFace> _ext):
|
||||
m_ext(std::move(_ext))
|
||||
{
|
||||
assert(!g_runtime);
|
||||
g_runtime = this;
|
||||
gas = eth2llvm(_gas);
|
||||
}
|
||||
|
||||
Runtime::~Runtime()
|
||||
|
|
@ -33,4 +36,9 @@ dev::eth::ExtVMFace& Runtime::getExt()
|
|||
return *g_runtime->m_ext;
|
||||
}
|
||||
|
||||
dev::u256 Runtime::getGas()
|
||||
{
|
||||
return llvm2eth(gas);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,13 @@
|
|||
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace evmcc
|
||||
{
|
||||
|
||||
|
|
@ -16,7 +23,7 @@ using MemoryImpl = dev::bytes;
|
|||
class Runtime
|
||||
{
|
||||
public:
|
||||
Runtime(std::unique_ptr<dev::eth::ExtVMFace> _ext);
|
||||
Runtime(dev::u256 _gas, std::unique_ptr<dev::eth::ExtVMFace> _ext);
|
||||
~Runtime();
|
||||
|
||||
Runtime(const Runtime&) = delete;
|
||||
|
|
@ -25,6 +32,7 @@ public:
|
|||
static StackImpl& getStack();
|
||||
static MemoryImpl& getMemory();
|
||||
static dev::eth::ExtVMFace& getExt();
|
||||
static dev::u256 getGas();
|
||||
|
||||
private:
|
||||
StackImpl m_stack;
|
||||
|
|
|
|||
Loading…
Reference in a new issue