Browse Source

Correct the order of basic blocks

cl-refactor
Paweł Bylica 10 years ago
parent
commit
d9c1617e60
  1. 19
      evmcc/Compiler.cpp

19
evmcc/Compiler.cpp

@ -53,8 +53,7 @@ BasicBlock& Compiler::getOrCreateBasicBlockAtPC(ProgramCounter pc)
void Compiler::createBasicBlocks(const dev::bytes& bytecode) void Compiler::createBasicBlocks(const dev::bytes& bytecode)
{ {
getOrCreateBasicBlockAtPC(0); getOrCreateBasicBlockAtPC(0); // First basic block
getOrCreateBasicBlockAtPC(bytecode.size());
for (auto curr = bytecode.cbegin(); curr != bytecode.cend(); ++curr) for (auto curr = bytecode.cbegin(); curr != bytecode.cend(); ++curr)
{ {
@ -113,13 +112,6 @@ void Compiler::createBasicBlocks(const dev::bytes& bytecode)
val |= *iter; val |= *iter;
} }
// Create a block for the JUMP target.
ProgramCounter targetPC = val.convert_to<ProgramCounter>();
auto& targetBlock = getOrCreateBasicBlockAtPC(targetPC);
ProgramCounter jumpPC = (next - bytecode.cbegin());
jumpTargets[jumpPC] = targetBlock;
// Create a block following the JUMP. // Create a block following the JUMP.
if (next + 1 < bytecode.cend()) if (next + 1 < bytecode.cend())
{ {
@ -127,6 +119,13 @@ void Compiler::createBasicBlocks(const dev::bytes& bytecode)
getOrCreateBasicBlockAtPC(nextPC); getOrCreateBasicBlockAtPC(nextPC);
} }
// Create a block for the JUMP target.
ProgramCounter targetPC = val.convert_to<ProgramCounter>();
auto& targetBlock = getOrCreateBasicBlockAtPC(targetPC);
ProgramCounter jumpPC = (next - bytecode.cbegin());
jumpTargets[jumpPC] = targetBlock;
curr += 1; // skip over JUMP curr += 1; // skip over JUMP
} }
@ -158,6 +157,8 @@ void Compiler::createBasicBlocks(const dev::bytes& bytecode)
break; break;
} }
} }
getOrCreateBasicBlockAtPC(bytecode.size()); // Final basic block
} }
std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode) std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)

Loading…
Cancel
Save