mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
Merge branch 'develop-evmcc' of https://github.com/imapp-pl/ethereum into develop-evmcc
This commit is contained in:
commit
89d4a1cb29
6 changed files with 130 additions and 67 deletions
|
|
@ -10,6 +10,7 @@ add_executable(${EXECUTABLE} ${SRC_LIST})
|
||||||
|
|
||||||
target_link_libraries(${EXECUTABLE} devcore)
|
target_link_libraries(${EXECUTABLE} devcore)
|
||||||
target_link_libraries(${EXECUTABLE} ethcore)
|
target_link_libraries(${EXECUTABLE} ethcore)
|
||||||
|
target_link_libraries(${EXECUTABLE} ethereum)
|
||||||
target_link_libraries(${EXECUTABLE} evm)
|
target_link_libraries(${EXECUTABLE} evm)
|
||||||
target_link_libraries(${EXECUTABLE} evmface)
|
target_link_libraries(${EXECUTABLE} evmface)
|
||||||
target_link_libraries(${EXECUTABLE} evmjit)
|
target_link_libraries(${EXECUTABLE} evmjit)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
@ -32,6 +33,7 @@ int main(int argc, char** argv)
|
||||||
bool opt_interpret = false;
|
bool opt_interpret = false;
|
||||||
bool opt_dump_graph = false;
|
bool opt_dump_graph = false;
|
||||||
bool opt_unknown = false;
|
bool opt_unknown = false;
|
||||||
|
bool opt_verbose = false;
|
||||||
size_t initialGas = 10000;
|
size_t initialGas = 10000;
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
|
|
@ -45,14 +47,16 @@ int main(int argc, char** argv)
|
||||||
opt_dissassemble = true;
|
opt_dissassemble = true;
|
||||||
else if (option == "-i")
|
else if (option == "-i")
|
||||||
opt_interpret = true;
|
opt_interpret = true;
|
||||||
else if (option == "-g")
|
else if (option == "--dump-cfg")
|
||||||
opt_dump_graph = true;
|
opt_dump_graph = true;
|
||||||
else if (option == "-G" && i + 1 < argc)
|
else if (option == "-g" && i + 1 < argc)
|
||||||
{
|
{
|
||||||
std::string gasValue = argv[++i];
|
std::string gasValue = argv[++i];
|
||||||
initialGas = boost::lexical_cast<size_t>(gasValue);
|
initialGas = boost::lexical_cast<size_t>(gasValue);
|
||||||
std::cerr << "Initial gas set to " << initialGas << "\n";
|
std::cerr << "Initial gas set to " << initialGas << "\n";
|
||||||
}
|
}
|
||||||
|
else if (option == "-v")
|
||||||
|
opt_verbose = true;
|
||||||
else if (option[0] != '-' && input_file.empty())
|
else if (option[0] != '-' && input_file.empty())
|
||||||
input_file = option;
|
input_file = option;
|
||||||
else
|
else
|
||||||
|
|
@ -87,9 +91,7 @@ int main(int argc, char** argv)
|
||||||
bytes bytecode = fromHex(src);
|
bytes bytecode = fromHex(src);
|
||||||
|
|
||||||
if (opt_show_bytes)
|
if (opt_show_bytes)
|
||||||
{
|
|
||||||
std::cout << memDump(bytecode) << std::endl;
|
std::cout << memDump(bytecode) << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
if (opt_dissassemble)
|
if (opt_dissassemble)
|
||||||
{
|
{
|
||||||
|
|
@ -99,11 +101,22 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (opt_compile || opt_interpret)
|
if (opt_compile || opt_interpret)
|
||||||
{
|
{
|
||||||
|
auto compilationStartTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
auto compiler = eth::jit::Compiler();
|
auto compiler = eth::jit::Compiler();
|
||||||
auto module = compiler.compile({bytecode.data(), bytecode.size()});
|
auto module = compiler.compile({bytecode.data(), bytecode.size()});
|
||||||
|
|
||||||
|
auto compilationEndTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
module->dump();
|
module->dump();
|
||||||
|
|
||||||
|
if (opt_verbose)
|
||||||
|
{
|
||||||
|
std::cerr << "*** Compilation time: "
|
||||||
|
<< std::chrono::duration_cast<std::chrono::microseconds>(compilationEndTime - compilationStartTime).count()
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
if (opt_dump_graph)
|
if (opt_dump_graph)
|
||||||
{
|
{
|
||||||
std::ofstream ofs("blocks.dot");
|
std::ofstream ofs("blocks.dot");
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,20 @@ Arith256::Arith256(llvm::IRBuilder<>& _builder) :
|
||||||
m_result = m_builder.CreateAlloca(Type::i256, nullptr, "arith.result");
|
m_result = m_builder.CreateAlloca(Type::i256, nullptr, "arith.result");
|
||||||
m_arg1 = m_builder.CreateAlloca(Type::i256, nullptr, "arith.arg1");
|
m_arg1 = m_builder.CreateAlloca(Type::i256, nullptr, "arith.arg1");
|
||||||
m_arg2 = m_builder.CreateAlloca(Type::i256, nullptr, "arith.arg2");
|
m_arg2 = m_builder.CreateAlloca(Type::i256, nullptr, "arith.arg2");
|
||||||
|
m_arg3 = m_builder.CreateAlloca(Type::i256, nullptr, "arith.arg3");
|
||||||
|
|
||||||
using Linkage = GlobalValue::LinkageTypes;
|
using Linkage = GlobalValue::LinkageTypes;
|
||||||
|
|
||||||
llvm::Type* argTypes[] = {Type::WordPtr, Type::WordPtr, Type::WordPtr};
|
llvm::Type* arg2Types[] = {Type::WordPtr, Type::WordPtr, Type::WordPtr};
|
||||||
m_mul = Function::Create(FunctionType::get(Type::Void, argTypes, false), Linkage::ExternalLinkage, "arith_mul", getModule());
|
llvm::Type* arg3Types[] = {Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr};
|
||||||
m_div = Function::Create(FunctionType::get(Type::Void, argTypes, false), Linkage::ExternalLinkage, "arith_div", getModule());
|
|
||||||
m_mod = Function::Create(FunctionType::get(Type::Void, argTypes, false), Linkage::ExternalLinkage, "arith_mod", getModule());
|
m_mul = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_mul", getModule());
|
||||||
m_sdiv = Function::Create(FunctionType::get(Type::Void, argTypes, false), Linkage::ExternalLinkage, "arith_sdiv", getModule());
|
m_div = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_div", getModule());
|
||||||
m_smod = Function::Create(FunctionType::get(Type::Void, argTypes, false), Linkage::ExternalLinkage, "arith_smod", getModule());
|
m_mod = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_mod", getModule());
|
||||||
|
m_sdiv = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_sdiv", getModule());
|
||||||
|
m_smod = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_smod", getModule());
|
||||||
|
m_addmod = Function::Create(FunctionType::get(Type::Void, arg3Types, false), Linkage::ExternalLinkage, "arith_addmod", getModule());
|
||||||
|
m_mulmod = Function::Create(FunctionType::get(Type::Void, arg3Types, false), Linkage::ExternalLinkage, "arith_mulmod", getModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
Arith256::~Arith256()
|
Arith256::~Arith256()
|
||||||
|
|
@ -43,6 +48,15 @@ llvm::Value* Arith256::binaryOp(llvm::Function* _op, llvm::Value* _arg1, llvm::V
|
||||||
return m_builder.CreateLoad(m_result);
|
return m_builder.CreateLoad(m_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::Value* Arith256::ternaryOp(llvm::Function* _op, llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3)
|
||||||
|
{
|
||||||
|
m_builder.CreateStore(_arg1, m_arg1);
|
||||||
|
m_builder.CreateStore(_arg2, m_arg2);
|
||||||
|
m_builder.CreateStore(_arg3, m_arg3);
|
||||||
|
m_builder.CreateCall4(_op, m_arg1, m_arg2, m_arg3, m_result);
|
||||||
|
return m_builder.CreateLoad(m_result);
|
||||||
|
}
|
||||||
|
|
||||||
llvm::Value* Arith256::mul(llvm::Value* _arg1, llvm::Value* _arg2)
|
llvm::Value* Arith256::mul(llvm::Value* _arg1, llvm::Value* _arg2)
|
||||||
{
|
{
|
||||||
return binaryOp(m_mul, _arg1, _arg2);
|
return binaryOp(m_mul, _arg1, _arg2);
|
||||||
|
|
@ -68,6 +82,17 @@ llvm::Value* Arith256::smod(llvm::Value* _arg1, llvm::Value* _arg2)
|
||||||
return binaryOp(m_smod, _arg1, _arg2);
|
return binaryOp(m_smod, _arg1, _arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::Value* Arith256::addmod(llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3)
|
||||||
|
{
|
||||||
|
return ternaryOp(m_addmod, _arg1, _arg2, _arg3);
|
||||||
|
}
|
||||||
|
|
||||||
|
llvm::Value* Arith256::mulmod(llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3)
|
||||||
|
{
|
||||||
|
return ternaryOp(m_mulmod, _arg1, _arg2, _arg3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -113,6 +138,22 @@ EXPORT void arith_smod(i256* _arg1, i256* _arg2, i256* _result)
|
||||||
*_result = eth2llvm(arg2 == 0 ? arg2 : dev::s2u(dev::u2s(arg1) % dev::u2s(arg2)));
|
*_result = eth2llvm(arg2 == 0 ? arg2 : dev::s2u(dev::u2s(arg1) % dev::u2s(arg2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXPORT void arith_mulmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* _result)
|
||||||
|
{
|
||||||
|
dev::u256 arg1 = llvm2eth(*_arg1);
|
||||||
|
dev::u256 arg2 = llvm2eth(*_arg2);
|
||||||
|
dev::u256 arg3 = llvm2eth(*_arg3);
|
||||||
|
*_result = eth2llvm(dev::u256((dev::bigint(arg1) * dev::bigint(arg2)) % arg3));
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT void arith_addmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* _result)
|
||||||
|
{
|
||||||
|
dev::u256 arg1 = llvm2eth(*_arg1);
|
||||||
|
dev::u256 arg2 = llvm2eth(*_arg2);
|
||||||
|
dev::u256 arg3 = llvm2eth(*_arg3);
|
||||||
|
*_result = eth2llvm(dev::u256((dev::bigint(arg1) + dev::bigint(arg2)) % arg3));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,24 @@ public:
|
||||||
llvm::Value* mod(llvm::Value* _arg1, llvm::Value* _arg2);
|
llvm::Value* mod(llvm::Value* _arg1, llvm::Value* _arg2);
|
||||||
llvm::Value* sdiv(llvm::Value* _arg1, llvm::Value* _arg2);
|
llvm::Value* sdiv(llvm::Value* _arg1, llvm::Value* _arg2);
|
||||||
llvm::Value* smod(llvm::Value* _arg1, llvm::Value* _arg2);
|
llvm::Value* smod(llvm::Value* _arg1, llvm::Value* _arg2);
|
||||||
|
llvm::Value* mulmod(llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3);
|
||||||
|
llvm::Value* addmod(llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
llvm::Value* binaryOp(llvm::Function* _op, llvm::Value* _arg1, llvm::Value* _arg2);
|
llvm::Value* binaryOp(llvm::Function* _op, llvm::Value* _arg1, llvm::Value* _arg2);
|
||||||
|
llvm::Value* ternaryOp(llvm::Function* _op, llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3);
|
||||||
|
|
||||||
llvm::Function* m_mul;
|
llvm::Function* m_mul;
|
||||||
llvm::Function* m_div;
|
llvm::Function* m_div;
|
||||||
llvm::Function* m_mod;
|
llvm::Function* m_mod;
|
||||||
llvm::Function* m_sdiv;
|
llvm::Function* m_sdiv;
|
||||||
llvm::Function* m_smod;
|
llvm::Function* m_smod;
|
||||||
|
llvm::Function* m_mulmod;
|
||||||
|
llvm::Function* m_addmod;
|
||||||
|
|
||||||
llvm::Value* m_arg1;
|
llvm::Value* m_arg1;
|
||||||
llvm::Value* m_arg2;
|
llvm::Value* m_arg2;
|
||||||
|
llvm::Value* m_arg3;
|
||||||
llvm::Value* m_result;
|
llvm::Value* m_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,12 @@ void Compiler::createBasicBlocks(bytesConstRef bytecode)
|
||||||
|
|
||||||
case Instruction::JUMPDEST:
|
case Instruction::JUMPDEST:
|
||||||
{
|
{
|
||||||
// A basic block starts here.
|
// A basic block starts at the next instruction.
|
||||||
splitPoints.insert(currentPC);
|
if (currentPC + 1 < bytecode.size())
|
||||||
indirectJumpTargets.push_back(currentPC);
|
{
|
||||||
|
splitPoints.insert(currentPC + 1);
|
||||||
|
indirectJumpTargets.push_back(currentPC + 1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -486,9 +489,8 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
|
||||||
{
|
{
|
||||||
auto lhs = stack.pop();
|
auto lhs = stack.pop();
|
||||||
auto rhs = stack.pop();
|
auto rhs = stack.pop();
|
||||||
auto sum = m_builder.CreateAdd(lhs, rhs);
|
|
||||||
auto mod = stack.pop();
|
auto mod = stack.pop();
|
||||||
auto res = arith.mod(sum, mod);
|
auto res = arith.addmod(lhs, rhs, mod);
|
||||||
stack.push(res);
|
stack.push(res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -497,9 +499,8 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
|
||||||
{
|
{
|
||||||
auto lhs = stack.pop();
|
auto lhs = stack.pop();
|
||||||
auto rhs = stack.pop();
|
auto rhs = stack.pop();
|
||||||
auto prod = m_builder.CreateMul(lhs, rhs);
|
|
||||||
auto mod = stack.pop();
|
auto mod = stack.pop();
|
||||||
auto res = arith.mod(prod, mod);
|
auto res = arith.mulmod(lhs, rhs, mod);
|
||||||
stack.push(res);
|
stack.push(res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -654,8 +655,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
|
||||||
|
|
||||||
case Instruction::JUMPDEST:
|
case Instruction::JUMPDEST:
|
||||||
{
|
{
|
||||||
// Extra asserts just in case.
|
// Nothing to do
|
||||||
assert(currentPC == basicBlock.begin());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include <setjmp.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <libevm/ExtVMFace.h>
|
#include <libevm/ExtVMFace.h>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue