Browse Source

Some changes about final/stop block

cl-refactor
Paweł Bylica 10 years ago
parent
commit
5586ff5bdc
  1. 15
      evmcc/Compiler.cpp
  2. 13
      evmcc/Compiler.h

15
evmcc/Compiler.cpp

@ -24,8 +24,7 @@ namespace jit
{
Compiler::Compiler()
: m_finalBlock(nullptr)
, m_badJumpBlock(nullptr)
: m_badJumpBlock(nullptr)
{
Type::init(llvm::getGlobalContext());
}
@ -125,10 +124,9 @@ void Compiler::createBasicBlocks(const bytes& bytecode)
basicBlocks.emplace(std::piecewise_construct, std::forward_as_tuple(beginInstIdx), std::forward_as_tuple(beginInstIdx, endInstIdx, m_mainFunc));
}
m_finalBlock = std::make_unique<BasicBlock>("FinalBlock", m_mainFunc);
m_stopBB = llvm::BasicBlock::Create(m_mainFunc->getContext(), "Stop", m_mainFunc);
m_badJumpBlock = std::make_unique<BasicBlock>("BadJumpBlock", m_mainFunc);
m_jumpTableBlock = std::make_unique<BasicBlock>("JumpTableBlock", m_mainFunc);
m_outOfGasBlock = std::make_unique<BasicBlock>("OutOfGas", m_mainFunc);
for (auto it = directJumpTargets.cbegin(); it != directJumpTargets.cend(); ++it)
{
@ -830,8 +828,8 @@ std::unique_ptr<llvm::Module> Compiler::compile(const bytes& bytecode)
{
if (basicBlock.end() == bytecode.size())
{
// Branch from the last regular block to the final block.
builder.CreateBr(m_finalBlock->llvm());
// Return STOP code
builder.CreateRet(Constant::get(ReturnCode::Stop));
}
else
{
@ -848,15 +846,12 @@ std::unique_ptr<llvm::Module> Compiler::compile(const bytes& bytecode)
// TODO: move to separate function.
// Note: Right now the codegen for special blocks depends only on createBasicBlock(),
// not on the codegen for 'regular' blocks. But it has to be done before linkBasicBlocks().
builder.SetInsertPoint(m_finalBlock->llvm());
builder.SetInsertPoint(m_stopBB);
builder.CreateRet(Constant::get(ReturnCode::Stop));
builder.SetInsertPoint(m_badJumpBlock->llvm());
builder.CreateRet(Constant::get(ReturnCode::BadJumpDestination));
builder.SetInsertPoint(m_outOfGasBlock->llvm());
builder.CreateRet(Constant::get(ReturnCode::OutOfGas));
builder.SetInsertPoint(m_jumpTableBlock->llvm());
if (m_indirectJumpTargets.size() > 0)
{

13
evmcc/Compiler.h

@ -31,7 +31,7 @@ private:
void linkBasicBlocks();
/**
* Maps a program counter pc to a basic block which starts at pc (if any).
* Maps a program counter pc to a basic block that starts at pc (if any).
*/
std::map<ProgramCounter, BasicBlock> basicBlocks;
@ -45,13 +45,8 @@ private:
*/
std::vector<BasicBlock*> m_indirectJumpTargets;
/// Collection of basic blocks in program
//std::vector<BasicBlock> m_basicBlocks;
/**
* Final block for normal (non-exceptional) execution.
*/
std::unique_ptr<BasicBlock> m_finalBlock;
/// Stop basic block - terminates execution with STOP code (0)
llvm::BasicBlock* m_stopBB = nullptr;
/**
* Block with a jump table.
@ -63,8 +58,6 @@ private:
*/
std::unique_ptr<BasicBlock> m_badJumpBlock;
std::unique_ptr<BasicBlock> m_outOfGasBlock;
/// Main program function
llvm::Function* m_mainFunc = nullptr;
};

Loading…
Cancel
Save