mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 04:06:44 +00:00
Some changes about final/stop block
This commit is contained in:
parent
07f6bbffe5
commit
5586ff5bdc
2 changed files with 8 additions and 20 deletions
|
|
@ -24,8 +24,7 @@ namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
Compiler::Compiler()
|
Compiler::Compiler()
|
||||||
: m_finalBlock(nullptr)
|
: m_badJumpBlock(nullptr)
|
||||||
, m_badJumpBlock(nullptr)
|
|
||||||
{
|
{
|
||||||
Type::init(llvm::getGlobalContext());
|
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));
|
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_badJumpBlock = std::make_unique<BasicBlock>("BadJumpBlock", m_mainFunc);
|
||||||
m_jumpTableBlock = std::make_unique<BasicBlock>("JumpTableBlock", 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)
|
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())
|
if (basicBlock.end() == bytecode.size())
|
||||||
{
|
{
|
||||||
// Branch from the last regular block to the final block.
|
// Return STOP code
|
||||||
builder.CreateBr(m_finalBlock->llvm());
|
builder.CreateRet(Constant::get(ReturnCode::Stop));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -848,15 +846,12 @@ std::unique_ptr<llvm::Module> Compiler::compile(const bytes& bytecode)
|
||||||
// TODO: move to separate function.
|
// TODO: move to separate function.
|
||||||
// Note: Right now the codegen for special blocks depends only on createBasicBlock(),
|
// 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().
|
// 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.CreateRet(Constant::get(ReturnCode::Stop));
|
||||||
|
|
||||||
builder.SetInsertPoint(m_badJumpBlock->llvm());
|
builder.SetInsertPoint(m_badJumpBlock->llvm());
|
||||||
builder.CreateRet(Constant::get(ReturnCode::BadJumpDestination));
|
builder.CreateRet(Constant::get(ReturnCode::BadJumpDestination));
|
||||||
|
|
||||||
builder.SetInsertPoint(m_outOfGasBlock->llvm());
|
|
||||||
builder.CreateRet(Constant::get(ReturnCode::OutOfGas));
|
|
||||||
|
|
||||||
builder.SetInsertPoint(m_jumpTableBlock->llvm());
|
builder.SetInsertPoint(m_jumpTableBlock->llvm());
|
||||||
if (m_indirectJumpTargets.size() > 0)
|
if (m_indirectJumpTargets.size() > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ private:
|
||||||
void linkBasicBlocks();
|
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;
|
std::map<ProgramCounter, BasicBlock> basicBlocks;
|
||||||
|
|
||||||
|
|
@ -45,13 +45,8 @@ private:
|
||||||
*/
|
*/
|
||||||
std::vector<BasicBlock*> m_indirectJumpTargets;
|
std::vector<BasicBlock*> m_indirectJumpTargets;
|
||||||
|
|
||||||
/// Collection of basic blocks in program
|
/// Stop basic block - terminates execution with STOP code (0)
|
||||||
//std::vector<BasicBlock> m_basicBlocks;
|
llvm::BasicBlock* m_stopBB = nullptr;
|
||||||
|
|
||||||
/**
|
|
||||||
* Final block for normal (non-exceptional) execution.
|
|
||||||
*/
|
|
||||||
std::unique_ptr<BasicBlock> m_finalBlock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block with a jump table.
|
* Block with a jump table.
|
||||||
|
|
@ -63,8 +58,6 @@ private:
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<BasicBlock> m_badJumpBlock;
|
std::unique_ptr<BasicBlock> m_badJumpBlock;
|
||||||
|
|
||||||
std::unique_ptr<BasicBlock> m_outOfGasBlock;
|
|
||||||
|
|
||||||
/// Main program function
|
/// Main program function
|
||||||
llvm::Function* m_mainFunc = nullptr;
|
llvm::Function* m_mainFunc = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue