mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 19:30:44 +00:00
Accessing Ext static data: CALLER, ORIGIN, CALLVALUE, CALLDATASIZE, GASPRICE
This commit is contained in:
parent
ac795c481b
commit
fcde2f3d22
6 changed files with 64 additions and 3 deletions
|
|
@ -270,6 +270,41 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
|||
break;
|
||||
}
|
||||
|
||||
case Instruction::CALLER:
|
||||
{
|
||||
auto value = ext.caller();
|
||||
stack.push(value);
|
||||
break;
|
||||
}
|
||||
|
||||
case Instruction::ORIGIN:
|
||||
{
|
||||
auto value = ext.origin();
|
||||
stack.push(value);
|
||||
break;
|
||||
}
|
||||
|
||||
case Instruction::CALLVALUE:
|
||||
{
|
||||
auto value = ext.callvalue();
|
||||
stack.push(value);
|
||||
break;
|
||||
}
|
||||
|
||||
case Instruction::CALLDATASIZE:
|
||||
{
|
||||
auto value = ext.calldatasize();
|
||||
stack.push(value);
|
||||
break;
|
||||
}
|
||||
|
||||
case Instruction::GASPRICE:
|
||||
{
|
||||
auto value = ext.gasprice();
|
||||
stack.push(value);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,12 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
|
|||
|
||||
auto ext = std::make_unique<dev::eth::ExtVMFace>();
|
||||
ext->myAddress = dev::Address(1122334455667788);
|
||||
ext->caller = dev::Address(0xfacefacefaceface);
|
||||
ext->origin = dev::Address(101010101010101010);
|
||||
ext->value = 0xabcd;
|
||||
ext->gasPrice = 1002;
|
||||
std::string calldata = "Hello World!";
|
||||
ext->data = calldata;
|
||||
Ext::init(std::move(ext));
|
||||
|
||||
auto entryFunc = module->getFunction("main");
|
||||
|
|
|
|||
|
|
@ -87,12 +87,19 @@ void Ext::setStore(llvm::Value* _index, llvm::Value* _value)
|
|||
m_builder.CreateCall(m_setStore, m_args);
|
||||
}
|
||||
|
||||
Value* Ext::address()
|
||||
Value* Ext::getDataElem(unsigned _index, const Twine& _name)
|
||||
{
|
||||
auto valuePtr = m_builder.CreateStructGEP(m_data, 0);
|
||||
auto valuePtr = m_builder.CreateStructGEP(m_data, _index, _name);
|
||||
return m_builder.CreateLoad(valuePtr);
|
||||
}
|
||||
|
||||
Value* Ext::address() { return getDataElem(0, "address"); }
|
||||
Value* Ext::caller() { return getDataElem(1, "caller"); }
|
||||
Value* Ext::origin() { return getDataElem(2, "origin"); }
|
||||
Value* Ext::callvalue() { return getDataElem(3, "callvalue"); }
|
||||
Value* Ext::calldatasize() { return getDataElem(5, "calldatasize"); }
|
||||
Value* Ext::gasprice() { return getDataElem(4, "gasprice"); }
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,14 @@ public:
|
|||
void setStore(llvm::Value* _index, llvm::Value* _value);
|
||||
|
||||
llvm::Value* address();
|
||||
llvm::Value* caller();
|
||||
llvm::Value* origin();
|
||||
llvm::Value* callvalue();
|
||||
llvm::Value* calldatasize();
|
||||
llvm::Value* gasprice();
|
||||
|
||||
private:
|
||||
llvm::Value* getDataElem(unsigned _index, const llvm::Twine& _name = "");
|
||||
|
||||
private:
|
||||
llvm::IRBuilder<>& m_builder;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
30
|
||||
30333234363a
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
|
||||
(asm
|
||||
ADDRESS
|
||||
CALLER
|
||||
ORIGIN
|
||||
CALLVALUE
|
||||
CALLDATASIZE
|
||||
GASPRICE
|
||||
)
|
||||
Loading…
Reference in a new issue