mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 03:36:44 +00:00
parent
a2da7c91c8
commit
11bf67b2d8
6 changed files with 19 additions and 28 deletions
|
|
@ -23,10 +23,6 @@ namespace eth
|
|||
namespace jit
|
||||
{
|
||||
|
||||
using dev::eth::Instruction;
|
||||
using namespace dev::eth; // We should move all the JIT code into dev::eth namespace
|
||||
|
||||
|
||||
Compiler::Compiler()
|
||||
: m_finalBlock(nullptr)
|
||||
, m_badJumpBlock(nullptr)
|
||||
|
|
@ -159,14 +155,12 @@ void Compiler::createBasicBlocks(const dev::bytes& bytecode)
|
|||
|
||||
std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
||||
{
|
||||
using namespace llvm;
|
||||
|
||||
auto& context = getGlobalContext();
|
||||
auto module = std::make_unique<Module>("main", context);
|
||||
IRBuilder<> builder(context);
|
||||
auto& context = llvm::getGlobalContext();
|
||||
auto module = std::make_unique<llvm::Module>("main", context);
|
||||
llvm::IRBuilder<> builder(context);
|
||||
|
||||
// Create main function
|
||||
m_mainFunc = Function::Create(FunctionType::get(Type::MainReturn, false), Function::ExternalLinkage, "main", module.get());
|
||||
m_mainFunc = llvm::Function::Create(llvm::FunctionType::get(Type::MainReturn, false), llvm::Function::ExternalLinkage, "main", module.get());
|
||||
|
||||
// Create the basic blocks.
|
||||
auto entryBlock = llvm::BasicBlock::Create(context, "entry", m_mainFunc);
|
||||
|
|
@ -286,7 +280,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
|||
case Instruction::NEG:
|
||||
{
|
||||
auto top = stack.pop();
|
||||
auto zero = ConstantInt::get(Type::i256, 0);
|
||||
auto zero = Constant::get(0);
|
||||
auto res = builder.CreateSub(zero, top);
|
||||
stack.push(res);
|
||||
break;
|
||||
|
|
@ -345,7 +339,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
|||
case Instruction::NOT:
|
||||
{
|
||||
auto top = stack.pop();
|
||||
auto zero = ConstantInt::get(Type::i256, 0);
|
||||
auto zero = Constant::get(0);
|
||||
auto iszero = builder.CreateICmpEQ(top, zero, "iszero");
|
||||
auto result = builder.CreateZExt(iszero, Type::i256);
|
||||
stack.push(result);
|
||||
|
|
@ -566,7 +560,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
|||
{
|
||||
stack.swap(1);
|
||||
auto val = stack.pop();
|
||||
auto zero = ConstantInt::get(Type::i256, 0);
|
||||
auto zero = Constant::get(0);
|
||||
auto cond = builder.CreateICmpNE(val, zero, "nonzero");
|
||||
|
||||
// Assume the basic blocks are properly ordered:
|
||||
|
|
@ -876,7 +870,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
|||
for (auto it = m_indirectJumpTargets.cbegin(); it != m_indirectJumpTargets.cend(); ++it)
|
||||
{
|
||||
auto& bb = *it;
|
||||
auto dest = ConstantInt::get(Type::i256, bb->begin());
|
||||
auto dest = Constant::get(bb->begin());
|
||||
switchInstr->addCase(dest, bb->llvm());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@
|
|||
#include "Runtime.h"
|
||||
|
||||
using namespace llvm;
|
||||
using llvm::types::i;
|
||||
using Linkage = llvm::GlobalValue::LinkageTypes;
|
||||
using dev::h256;
|
||||
using dev::u256;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
|
@ -88,6 +84,8 @@ Ext::Ext(llvm::IRBuilder<>& _builder, llvm::Module* module)
|
|||
|
||||
m_data = m_builder.CreateAlloca(extDataTy, nullptr, "ext.data");
|
||||
|
||||
using llvm::types::i;
|
||||
using Linkage = llvm::GlobalValue::LinkageTypes;
|
||||
m_init = Function::Create(FunctionType::get(m_builder.getVoidTy(), extDataTy->getPointerTo(), false), Linkage::ExternalLinkage, "ext_init", module);
|
||||
m_store = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_store", module);
|
||||
m_setStore = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_setStore", module);
|
||||
|
|
|
|||
|
|
@ -19,12 +19,10 @@ namespace eth
|
|||
namespace jit
|
||||
{
|
||||
|
||||
using namespace dev::eth; // We should move all the JIT code into dev::eth namespace
|
||||
|
||||
namespace // Helper functions
|
||||
{
|
||||
|
||||
uint64_t getStepCost(dev::eth::Instruction inst) // TODO: Add this function to FeeSructure
|
||||
uint64_t getStepCost(dev::eth::Instruction inst) // TODO: Add this function to FeeSructure (pull request submitted)
|
||||
{
|
||||
switch (inst)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -224,7 +224,8 @@ void Memory::dump(uint64_t _begin, uint64_t _end)
|
|||
|
||||
extern "C"
|
||||
{
|
||||
using namespace dev::eth::jit;
|
||||
|
||||
using namespace dev::eth::jit;
|
||||
|
||||
EXPORT i256 mem_returnDataOffset;
|
||||
EXPORT i256 mem_returnDataSize;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ llvm::IntegerType* Type::lowPrecision;
|
|||
llvm::IntegerType* Type::Byte;
|
||||
llvm::PointerType* Type::BytePtr;
|
||||
llvm::Type* Type::Void;
|
||||
llvm::Type* Type::MainReturn;
|
||||
llvm::IntegerType* Type::MainReturn;
|
||||
|
||||
void Type::init(llvm::LLVMContext& _context)
|
||||
{
|
||||
|
|
@ -29,12 +29,12 @@ void Type::init(llvm::LLVMContext& _context)
|
|||
MainReturn = llvm::Type::getInt32Ty(_context);
|
||||
}
|
||||
|
||||
llvm::Constant* Constant::get(uint64_t _n)
|
||||
llvm::ConstantInt* Constant::get(uint64_t _n)
|
||||
{
|
||||
return llvm::ConstantInt::get(Type::i256, _n);
|
||||
}
|
||||
|
||||
llvm::Constant* Constant::get(ReturnCode _returnCode)
|
||||
llvm::ConstantInt* Constant::get(ReturnCode _returnCode)
|
||||
{
|
||||
return llvm::ConstantInt::get(Type::MainReturn, static_cast<uint64_t>(_returnCode));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ struct Type
|
|||
static llvm::Type* Void;
|
||||
|
||||
/// Main function return type
|
||||
static llvm::Type* MainReturn;
|
||||
static llvm::IntegerType* MainReturn;
|
||||
|
||||
static void init(llvm::LLVMContext& _context);
|
||||
};
|
||||
|
|
@ -44,9 +44,9 @@ enum class ReturnCode
|
|||
struct Constant
|
||||
{
|
||||
/// Returns word-size constant
|
||||
static llvm::Constant* get(uint64_t _n);
|
||||
static llvm::ConstantInt* get(uint64_t _n);
|
||||
|
||||
static llvm::Constant* get(ReturnCode _returnCode);
|
||||
static llvm::ConstantInt* get(ReturnCode _returnCode);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue