Browse Source

Merge branch 'develop-evmcc' of https://github.com/imapp-pl/ethereum into develop-evmcc

cl-refactor
Paweł Bylica 10 years ago
parent
commit
2bbbf6c3c4
  1. 30
      libevmjit/Compiler.cpp
  2. 7
      libevmjit/Ext.cpp
  3. 26
      libevmjit/Memory.cpp
  4. 2
      libevmjit/VM.cpp

30
libevmjit/Compiler.cpp

@ -504,6 +504,36 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
break;
}
case Instruction::SIGNEXTEND:
{
auto idx = stack.pop();
auto word = stack.pop();
auto k32_ = m_builder.CreateTrunc(idx, m_builder.getIntNTy(5), "k_32");
auto k32 = m_builder.CreateZExt(k32_, Type::i256);
auto k32x8 = m_builder.CreateMul(k32, Constant::get(8), "kx8");
// test for b >> (k * 8 + 7)
auto bitpos = m_builder.CreateAdd(k32x8, Constant::get(7), "bitpos");
auto bitval = m_builder.CreateLShr(word, bitpos, "bitval");
auto bittest = m_builder.CreateTrunc(bitval, m_builder.getInt1Ty(), "bittest");
auto mask_ = m_builder.CreateShl(Constant::get(1), bitpos);
auto mask = m_builder.CreateSub(mask_, Constant::get(1), "mask");
auto negmask = m_builder.CreateXor(mask, llvm::ConstantInt::getAllOnesValue(Type::i256), "negmask");
auto val1 = m_builder.CreateOr(word, negmask);
auto val0 = m_builder.CreateAnd(word, mask);
auto kInRange = m_builder.CreateICmpULE(idx, llvm::ConstantInt::get(Type::i256, 30));
auto result = m_builder.CreateSelect(kInRange,
m_builder.CreateSelect(bittest, val1, val0),
word);
stack.push(result);
break;
}
case Instruction::SHA3:
{
auto inOff = stack.pop();

7
libevmjit/Ext.cpp

@ -26,14 +26,13 @@ inline u256 fromAddress(Address _a)
}
Ext::Ext(RuntimeManager& _runtimeManager):
RuntimeHelper(_runtimeManager)
RuntimeHelper(_runtimeManager),
m_data()
{
auto&& ctx = m_builder.getContext();
auto module = getModule();
auto i256Ty = m_builder.getIntNTy(256);
auto i256PtrTy = i256Ty->getPointerTo();
auto i8PtrTy = m_builder.getInt8PtrTy();
m_args[0] = m_builder.CreateAlloca(i256Ty, nullptr, "ext.index");
m_args[1] = m_builder.CreateAlloca(i256Ty, nullptr, "ext.value");
@ -266,7 +265,7 @@ extern "C"
*_ret = *reinterpret_cast<i256*>(&hash);
}
EXPORT void ext_exp(Runtime* _rt, i256* _left, i256* _right, i256* _ret)
EXPORT void ext_exp(Runtime*, i256* _left, i256* _right, i256* _ret)
{
bigint left = llvm2eth(*_left);
bigint right = llvm2eth(*_right);

26
libevmjit/Memory.cpp

@ -89,7 +89,7 @@ llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _
return func;
}
llvm::Function* Memory::createFunc(bool _isStore, llvm::Type* _valueType, GasMeter& _gasMeter)
llvm::Function* Memory::createFunc(bool _isStore, llvm::Type* _valueType, GasMeter&)
{
auto isWord = _valueType == Type::i256;
@ -228,28 +228,4 @@ extern "C"
return memory.data();
}
EXPORT void evmccrt_memory_dump(uint64_t _begin, uint64_t _end)
{
//if (_end == 0)
// _end = Runtime::getMemory().size();
//std::cerr << "MEMORY: active size: " << std::dec
// << Runtime::getMemory().size() / 32 << " words\n";
//std::cerr << "MEMORY: dump from " << std::dec
// << _begin << " to " << _end << ":";
//if (_end <= _begin)
// return;
//_begin = _begin / 16 * 16;
//for (size_t i = _begin; i < _end; i++)
//{
// if ((i - _begin) % 16 == 0)
// std::cerr << '\n' << std::dec << i << ": ";
// auto b = Runtime::getMemory()[i];
// std::cerr << std::hex << std::setw(2) << static_cast<int>(b) << ' ';
//}
//std::cerr << std::endl;
}
} // extern "C"

2
libevmjit/VM.cpp

@ -31,6 +31,8 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
BOOST_THROW_EXCEPTION(StackTooSmall(1, 0));
case ReturnCode::BadInstruction:
BOOST_THROW_EXCEPTION(BadInstruction());
default:
break;
}
m_output = std::move(engine.returnData);

Loading…
Cancel
Save