mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
parent
f1ea6c9257
commit
a2da7c91c8
19 changed files with 154 additions and 36 deletions
|
|
@ -6,7 +6,11 @@
|
||||||
|
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
const char* BasicBlock::NamePrefix = "Instr.";
|
const char* BasicBlock::NamePrefix = "Instr.";
|
||||||
|
|
@ -69,3 +73,6 @@ void BasicBlock::Stack::swap(size_t _index)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,11 @@
|
||||||
|
|
||||||
#include <llvm/IR/BasicBlock.h>
|
#include <llvm/IR/BasicBlock.h>
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
using ProgramCounter = uint64_t; // TODO: Rename
|
using ProgramCounter = uint64_t; // TODO: Rename
|
||||||
|
|
@ -74,3 +78,6 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,11 @@
|
||||||
#include "GasMeter.h"
|
#include "GasMeter.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
using dev::eth::Instruction;
|
using dev::eth::Instruction;
|
||||||
|
|
@ -945,3 +949,6 @@ void Compiler::linkBasicBlocks()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,11 @@
|
||||||
|
|
||||||
#include "BasicBlock.h"
|
#include "BasicBlock.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
class Compiler
|
class Compiler
|
||||||
|
|
@ -66,3 +70,5 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,11 @@
|
||||||
#include "Memory.h"
|
#include "Memory.h"
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
ExecutionEngine::ExecutionEngine()
|
ExecutionEngine::ExecutionEngine()
|
||||||
|
|
@ -91,7 +95,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
|
||||||
ext->currentBlock.gasLimit = 1008;
|
ext->currentBlock.gasLimit = 1008;
|
||||||
std::string calldata = "Hello the Beautiful World of Ethereum!";
|
std::string calldata = "Hello the Beautiful World of Ethereum!";
|
||||||
ext->data = calldata;
|
ext->data = calldata;
|
||||||
unsigned char fakecode[] = { 0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf };
|
unsigned char fakecode[] = {0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf};
|
||||||
ext->code = decltype(ext->code)(fakecode, 8);
|
ext->code = decltype(ext->code)(fakecode, 8);
|
||||||
|
|
||||||
// Init runtime
|
// Init runtime
|
||||||
|
|
@ -134,3 +138,5 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,11 @@
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
#include <libdevcore/Common.h>
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
class ExecutionEngine
|
class ExecutionEngine
|
||||||
|
|
@ -17,3 +21,5 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,11 @@ using Linkage = llvm::GlobalValue::LinkageTypes;
|
||||||
using dev::h256;
|
using dev::h256;
|
||||||
using dev::u256;
|
using dev::u256;
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO: Copy of dev::eth::fromAddress in VM.h
|
// TODO: Copy of dev::eth::fromAddress in VM.h
|
||||||
|
|
@ -238,7 +242,7 @@ llvm::Value* Ext::codesizeAt(llvm::Value* _addr)
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
|
||||||
using namespace evmcc;
|
using namespace dev::eth::jit;
|
||||||
|
|
||||||
EXPORT void ext_init(ExtData* _extData)
|
EXPORT void ext_init(ExtData* _extData)
|
||||||
{
|
{
|
||||||
|
|
@ -377,3 +381,6 @@ EXPORT void ext_codesizeAt(h256* _addr256, i256* _ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
11
evmcc/Ext.h
11
evmcc/Ext.h
|
|
@ -5,10 +5,12 @@
|
||||||
|
|
||||||
#include <libevm/ExtVMFace.h>
|
#include <libevm/ExtVMFace.h>
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Ext
|
class Ext
|
||||||
{
|
{
|
||||||
|
|
@ -80,3 +82,6 @@ private:
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,11 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Ext.h"
|
#include "Ext.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
using namespace dev::eth; // We should move all the JIT code into dev::eth namespace
|
using namespace dev::eth; // We should move all the JIT code into dev::eth namespace
|
||||||
|
|
@ -193,3 +197,6 @@ llvm::Value* GasMeter::getGas()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,11 @@
|
||||||
|
|
||||||
#include <libevmface/Instruction.h>
|
#include <libevmface/Instruction.h>
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
class GasMeter
|
class GasMeter
|
||||||
|
|
@ -45,3 +49,6 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,11 @@
|
||||||
#include "Runtime.h"
|
#include "Runtime.h"
|
||||||
#include "GasMeter.h"
|
#include "GasMeter.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
Memory::Memory(llvm::IRBuilder<>& _builder, llvm::Module* _module, GasMeter& _gasMeter):
|
Memory::Memory(llvm::IRBuilder<>& _builder, llvm::Module* _module, GasMeter& _gasMeter):
|
||||||
|
|
@ -213,11 +217,14 @@ void Memory::dump(uint64_t _begin, uint64_t _end)
|
||||||
m_builder.CreateCall(m_memDump, llvm::ArrayRef<llvm::Value*>(args));
|
m_builder.CreateCall(m_memDump, llvm::ArrayRef<llvm::Value*>(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace evmcc
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
using namespace evmcc;
|
using namespace dev::eth::jit;
|
||||||
|
|
||||||
EXPORT i256 mem_returnDataOffset;
|
EXPORT i256 mem_returnDataOffset;
|
||||||
EXPORT i256 mem_returnDataSize;
|
EXPORT i256 mem_returnDataSize;
|
||||||
|
|
@ -256,7 +263,7 @@ EXPORT void evmccrt_memory_dump(uint64_t _begin, uint64_t _end)
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
dev::bytesConstRef evmcc::Memory::getReturnData()
|
dev::bytesConstRef dev::eth::jit::Memory::getReturnData()
|
||||||
{
|
{
|
||||||
// TODO: Handle large indexes
|
// TODO: Handle large indexes
|
||||||
auto offset = static_cast<size_t>(llvm2eth(mem_returnDataOffset));
|
auto offset = static_cast<size_t>(llvm2eth(mem_returnDataOffset));
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,13 @@
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
#include <libdevcore/Common.h>
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
{
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
|
{
|
||||||
|
|
||||||
class GasMeter;
|
class GasMeter;
|
||||||
|
|
||||||
class Memory
|
class Memory
|
||||||
|
|
@ -58,3 +63,6 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,11 @@
|
||||||
|
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
static Runtime* g_runtime;
|
static Runtime* g_runtime;
|
||||||
|
|
@ -49,3 +53,5 @@ dev::u256 Runtime::getGas()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,11 @@
|
||||||
#define EXPORT
|
#define EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
using StackImpl = std::vector<i256>;
|
using StackImpl = std::vector<i256>;
|
||||||
|
|
@ -41,3 +45,5 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,11 @@
|
||||||
|
|
||||||
#include <llvm/IR/DerivedTypes.h>
|
#include <llvm/IR/DerivedTypes.h>
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
llvm::IntegerType* Type::i256;
|
llvm::IntegerType* Type::i256;
|
||||||
|
|
@ -36,3 +40,6 @@ llvm::Constant* Constant::get(ReturnCode _returnCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,11 @@
|
||||||
#include <llvm/IR/Type.h>
|
#include <llvm/IR/Type.h>
|
||||||
#include <llvm/IR/Constants.h>
|
#include <llvm/IR/Constants.h>
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Type
|
struct Type
|
||||||
|
|
@ -46,3 +50,6 @@ struct Constant
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
dev::u256 llvm2eth(i256 _i)
|
dev::u256 llvm2eth(i256 _i)
|
||||||
|
|
@ -32,3 +36,5 @@ i256 eth2llvm(dev::u256 _u)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,11 @@
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
#include <libdevcore/Common.h>
|
||||||
|
|
||||||
namespace evmcc
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
/// Representation of 256-bit value binary compatible with LLVM i256
|
/// Representation of 256-bit value binary compatible with LLVM i256
|
||||||
|
|
@ -112,3 +116,5 @@ private:
|
||||||
case Instruction::SWAP16
|
case Instruction::SWAP16
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
#include "ExecutionEngine.h"
|
#include "ExecutionEngine.h"
|
||||||
|
|
||||||
using namespace dev;
|
|
||||||
|
|
||||||
|
|
||||||
void show_usage()
|
void show_usage()
|
||||||
{
|
{
|
||||||
|
|
@ -74,6 +72,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
boost::algorithm::trim(src);
|
boost::algorithm::trim(src);
|
||||||
|
|
||||||
|
using namespace dev;
|
||||||
|
|
||||||
bytes bytecode = fromHex(src);
|
bytes bytecode = fromHex(src);
|
||||||
|
|
||||||
if (opt_show_bytes)
|
if (opt_show_bytes)
|
||||||
|
|
@ -89,15 +89,15 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (opt_compile)
|
if (opt_compile)
|
||||||
{
|
{
|
||||||
auto module = evmcc::Compiler().compile(bytecode);
|
auto module = eth::jit::Compiler().compile(bytecode);
|
||||||
llvm::raw_os_ostream out(std::cout);
|
llvm::raw_os_ostream out(std::cout);
|
||||||
module->print(out, nullptr);
|
module->print(out, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_interpret)
|
if (opt_interpret)
|
||||||
{
|
{
|
||||||
auto engine = evmcc::ExecutionEngine();
|
auto engine = eth::jit::ExecutionEngine();
|
||||||
auto module = evmcc::Compiler().compile(bytecode);
|
auto module = eth::jit::Compiler().compile(bytecode);
|
||||||
module->dump();
|
module->dump();
|
||||||
auto result = engine.run(std::move(module));
|
auto result = engine.run(std::move(module));
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue