mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Handle bytecode as bytes
This commit is contained in:
parent
2bd4d6cd07
commit
86334f5eff
6 changed files with 10 additions and 11 deletions
|
|
@ -121,7 +121,7 @@ int main(int argc, char** argv)
|
||||||
compilerOptions.optimizeStack = options.count("optimize-stack") > 0;
|
compilerOptions.optimizeStack = options.count("optimize-stack") > 0;
|
||||||
|
|
||||||
auto compiler = eth::jit::Compiler(compilerOptions);
|
auto compiler = eth::jit::Compiler(compilerOptions);
|
||||||
auto module = compiler.compile({bytecode.data(), bytecode.size()});
|
auto module = compiler.compile(bytecode);
|
||||||
|
|
||||||
auto compilationEndTime = std::chrono::high_resolution_clock::now();
|
auto compilationEndTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ Compiler::Compiler(Options const& _options):
|
||||||
Type::init(m_builder.getContext());
|
Type::init(m_builder.getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compiler::createBasicBlocks(bytesConstRef _bytecode)
|
void Compiler::createBasicBlocks(bytes const& _bytecode)
|
||||||
{
|
{
|
||||||
std::set<ProgramCounter> splitPoints; // Sorted collections of instruction indices where basic blocks start/end
|
std::set<ProgramCounter> splitPoints; // Sorted collections of instruction indices where basic blocks start/end
|
||||||
|
|
||||||
|
|
@ -151,7 +151,7 @@ void Compiler::createBasicBlocks(bytesConstRef _bytecode)
|
||||||
m_indirectJumpTargets.push_back(&basicBlocks.find(*it)->second);
|
m_indirectJumpTargets.push_back(&basicBlocks.find(*it)->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<llvm::Module> Compiler::compile(bytesConstRef _bytecode)
|
std::unique_ptr<llvm::Module> Compiler::compile(bytes const& _bytecode)
|
||||||
{
|
{
|
||||||
auto module = std::unique_ptr<llvm::Module>(new llvm::Module("main", m_builder.getContext()));
|
auto module = std::unique_ptr<llvm::Module>(new llvm::Module("main", m_builder.getContext()));
|
||||||
|
|
||||||
|
|
@ -247,7 +247,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytesConstRef _bytecode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytesConstRef _bytecode, RuntimeManager& _runtimeManager,
|
void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode, RuntimeManager& _runtimeManager,
|
||||||
Arith256& _arith, Memory& _memory, Ext& _ext, GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock)
|
Arith256& _arith, Memory& _memory, Ext& _ext, GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock)
|
||||||
{
|
{
|
||||||
if (!_nextBasicBlock) // this is the last block in the code
|
if (!_nextBasicBlock) // this is the last block in the code
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,13 @@ public:
|
||||||
|
|
||||||
Compiler(Options const& _options);
|
Compiler(Options const& _options);
|
||||||
|
|
||||||
std::unique_ptr<llvm::Module> compile(bytesConstRef _bytecode);
|
std::unique_ptr<llvm::Module> compile(bytes const& _bytecode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void createBasicBlocks(bytesConstRef _bytecode);
|
void createBasicBlocks(bytes const& _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, bytes const& _bytecode, class RuntimeManager& _runtimeManager, class Arith256& _arith, class Memory& _memory, class Ext& _ext, class GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock);
|
||||||
|
|
||||||
void removeDeadBlocks();
|
void removeDeadBlocks();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,8 +100,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, ExtV
|
||||||
_ext->currentBlock.gasLimit = 1008;
|
_ext->currentBlock.gasLimit = 1008;
|
||||||
std::string calldata = "Hello the Beautiful World of Ethereum!";
|
std::string calldata = "Hello the Beautiful World of Ethereum!";
|
||||||
_ext->data = calldata;
|
_ext->data = calldata;
|
||||||
unsigned char fakecode[] = {0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf};
|
_ext->code = { 0x0d, 0x0e, 0x0a, 0x0d, 0x0b, 0x0e, 0xe, 0xf };
|
||||||
_ext->code = decltype(_ext->code)(fakecode, 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto entryFunc = module->getFunction("main");
|
auto entryFunc = module->getFunction("main");
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ i256 eth2llvm(u256 _u)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
u256 readPushData(const byte*& _curr, const byte* _end)
|
u256 readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end)
|
||||||
{
|
{
|
||||||
auto pushInst = *_curr;
|
auto pushInst = *_curr;
|
||||||
assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32);
|
assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32);
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ i256 eth2llvm(u256);
|
||||||
/// Reads PUSH data from pointed fragment of bytecode and constructs number out of it
|
/// Reads PUSH data from pointed fragment of bytecode and constructs number out of it
|
||||||
/// Reading out of bytecode means reading 0
|
/// Reading out of bytecode means reading 0
|
||||||
/// @param _curr is updates and points the last real byte read
|
/// @param _curr is updates and points the last real byte read
|
||||||
u256 readPushData(const byte*& _curr, const byte* _end);
|
u256 readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end);
|
||||||
|
|
||||||
#define ANY_PUSH PUSH1: \
|
#define ANY_PUSH PUSH1: \
|
||||||
case Instruction::PUSH2: \
|
case Instruction::PUSH2: \
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue