mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Merge branch 'develop-evmcc' of https://github.com/imapp-pl/ethereum into develop-evmcc
This commit is contained in:
commit
172fc1c06b
3 changed files with 47 additions and 31 deletions
|
|
@ -758,8 +758,8 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytesConstRef _bytecod
|
||||||
_gasMeter.commitCostBlock(gas);
|
_gasMeter.commitCostBlock(gas);
|
||||||
|
|
||||||
// Require memory for in and out buffers
|
// Require memory for in and out buffers
|
||||||
memory.require(outOff, outSize); // Out buffer first as we guess it will be after the in one
|
_memory.require(outOff, outSize); // Out buffer first as we guess it will be after the in one
|
||||||
memory.require(inOff, inSize);
|
_memory.require(inOff, inSize);
|
||||||
|
|
||||||
auto receiveAddress = codeAddress;
|
auto receiveAddress = codeAddress;
|
||||||
if (inst == Instruction::CALLCODE)
|
if (inst == Instruction::CALLCODE)
|
||||||
|
|
|
||||||
|
|
@ -18,55 +18,70 @@ class Compiler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
struct Options
|
||||||
|
{
|
||||||
|
/// Optimize stack operations between basic blocks
|
||||||
|
bool optimizeStack;
|
||||||
|
|
||||||
|
/// Rewrite switch instructions to sequences of branches
|
||||||
|
bool rewriteSwitchToBranches;
|
||||||
|
|
||||||
|
/// Dump CFG as a .dot file for graphviz
|
||||||
|
bool dumpCFG;
|
||||||
|
|
||||||
|
Options():
|
||||||
|
optimizeStack(true),
|
||||||
|
rewriteSwitchToBranches(true),
|
||||||
|
dumpCFG(false)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
using ProgramCounter = uint64_t;
|
using ProgramCounter = uint64_t;
|
||||||
|
|
||||||
Compiler();
|
Compiler(Options const& _options);
|
||||||
|
|
||||||
std::unique_ptr<llvm::Module> compile(bytesConstRef bytecode);
|
|
||||||
|
|
||||||
void dumpBasicBlockGraph(std::ostream& out);
|
|
||||||
|
|
||||||
|
std::unique_ptr<llvm::Module> compile(bytesConstRef _bytecode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void createBasicBlocks(bytesConstRef bytecode);
|
void createBasicBlocks(bytesConstRef _bytecode);
|
||||||
|
|
||||||
void compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode, class RuntimeManager& _runtimeManager, class Arith256& arith, class Memory& memory, class Ext& ext, class GasMeter& gasMeter, llvm::BasicBlock* nextBasicBlock);
|
void compileBasicBlock(BasicBlock& _basicBlock, bytesConstRef _bytecode, class RuntimeManager& _runtimeManager, class Arith256& _arith, class Memory& _memory, class Ext& _ext, class GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock);
|
||||||
|
|
||||||
void removeDeadBlocks();
|
void removeDeadBlocks();
|
||||||
|
|
||||||
/// Dump all basic blocks to stderr. Useful in a debugging session.
|
/// Dumps basic block graph in graphviz format to a file, if option dumpCFG is enabled.
|
||||||
|
void dumpCFGifRequired(std::string const& _dotfilePath);
|
||||||
|
|
||||||
|
/// Dumps basic block graph in graphviz format to a stream.
|
||||||
|
void dumpCFGtoStream(std::ostream& _out);
|
||||||
|
|
||||||
|
/// Dumps all basic blocks to stderr. Useful in a debugging session.
|
||||||
void dump();
|
void dump();
|
||||||
|
|
||||||
|
/// Compiler options
|
||||||
|
Options const& m_options;
|
||||||
|
|
||||||
|
/// Helper class for generating IR
|
||||||
llvm::IRBuilder<> m_builder;
|
llvm::IRBuilder<> m_builder;
|
||||||
|
|
||||||
/**
|
/// Maps a program counter pc to a basic block that 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;
|
|
||||||
|
|
||||||
/**
|
/// Maps a pc at which there is a JUMP or JUMPI to the target block of the jump.
|
||||||
* Maps a pc at which there is a JUMP or JUMPI to the target block of the jump.
|
std::map<ProgramCounter, llvm::BasicBlock*> m_directJumpTargets = {};
|
||||||
*/
|
|
||||||
std::map<ProgramCounter, llvm::BasicBlock*> m_directJumpTargets;
|
|
||||||
|
|
||||||
/**
|
/// A list of possible blocks to which there may be indirect jumps.
|
||||||
* A list of possible blocks to which there may be indirect jumps.
|
std::vector<BasicBlock*> m_indirectJumpTargets = {};
|
||||||
*/
|
|
||||||
std::vector<BasicBlock*> m_indirectJumpTargets;
|
|
||||||
|
|
||||||
/// Stop basic block - terminates execution with STOP code (0)
|
/// Stop basic block - terminates execution with STOP code (0)
|
||||||
llvm::BasicBlock* m_stopBB = nullptr;
|
llvm::BasicBlock* m_stopBB = nullptr;
|
||||||
|
|
||||||
/**
|
/// Block with a jump table.
|
||||||
* Block with a jump table.
|
std::unique_ptr<BasicBlock> m_jumpTableBlock = nullptr;
|
||||||
*/
|
|
||||||
std::unique_ptr<BasicBlock> m_jumpTableBlock;
|
|
||||||
|
|
||||||
/**
|
/// Default destination for indirect jumps.
|
||||||
* Default destination for indirect jumps.
|
std::unique_ptr<BasicBlock> m_badJumpBlock = nullptr;
|
||||||
*/
|
|
||||||
std::unique_ptr<BasicBlock> m_badJumpBlock;
|
|
||||||
|
|
||||||
/// Main program function
|
/// Main program function
|
||||||
llvm::Function* m_mainFunc = nullptr;
|
llvm::Function* m_mainFunc = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ namespace jit
|
||||||
|
|
||||||
bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
|
bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
|
||||||
{
|
{
|
||||||
auto module = Compiler().compile(_ext.code);
|
Compiler::Options defaultOptions;
|
||||||
|
auto module = Compiler(defaultOptions).compile(_ext.code);
|
||||||
|
|
||||||
ExecutionEngine engine;
|
ExecutionEngine engine;
|
||||||
auto exitCode = engine.run(std::move(module), m_gas, &_ext);
|
auto exitCode = engine.run(std::move(module), m_gas, &_ext);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue