Merge pull request from ethereum/add-blockchain-ops

Support generation of calldata, code, extcode and returndata opcodes
This commit is contained in:
chriseth 2019-05-02 10:47:54 +02:00 committed by GitHub
commit 2538bf897d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 0 deletions

View File

@ -307,6 +307,15 @@ void ProtoConverter::visit(UnaryOp const& _x)
case UnaryOp::ISZERO:
m_output << "iszero";
break;
case UnaryOp::CALLDATALOAD:
m_output << "calldataload";
break;
case UnaryOp::EXTCODESIZE:
m_output << "extcodesize";
break;
case UnaryOp::EXTCODEHASH:
m_output << "extcodehash";
break;
}
m_output << "(";
visit(_x.operand());
@ -346,9 +355,55 @@ void ProtoConverter::visit(NullaryOp const& _x)
case NullaryOp::GAS:
m_output << "gas()";
break;
case NullaryOp::CALLDATASIZE:
m_output << "calldatasize()";
break;
case NullaryOp::CODESIZE:
m_output << "codesize()";
break;
case NullaryOp::RETURNDATASIZE:
m_output << "returndatasize()";
break;
}
}
void ProtoConverter::visit(CopyFunc const& _x)
{
switch (_x.ct())
{
case CopyFunc::CALLDATA:
m_output << "calldatacopy";
break;
case CopyFunc::CODE:
m_output << "codecopy";
break;
case CopyFunc::RETURNDATA:
m_output << "returndatacopy";
break;
}
m_output << "(";
visit(_x.target());
m_output << ", ";
visit(_x.source());
m_output << ", ";
visit(_x.size());
m_output << ")\n";
}
void ProtoConverter::visit(ExtCodeCopy const& _x)
{
m_output << "extcodecopy";
m_output << "(";
visit(_x.addr());
m_output << ", ";
visit(_x.target());
m_output << ", ";
visit(_x.source());
m_output << ", ";
visit(_x.size());
m_output << ")\n";
}
void ProtoConverter::visit(LogFunc const& _x)
{
switch (_x.num_topics())
@ -535,6 +590,12 @@ void ProtoConverter::visit(Statement const& _x)
case Statement::kLogFunc:
visit(_x.log_func());
break;
case Statement::kCopyFunc:
visit(_x.copy_func());
break;
case Statement::kExtcodeCopy:
visit(_x.extcode_copy());
break;
case Statement::STMT_ONEOF_NOT_SET:
break;
}

View File

@ -69,6 +69,8 @@ private:
void visit(TernaryOp const&);
void visit(NullaryOp const&);
void visit(LogFunc const&);
void visit(CopyFunc const&);
void visit(ExtCodeCopy const&);
template <class T>
void visit(google::protobuf::RepeatedPtrField<T> const& _repeated_field);

View File

@ -106,6 +106,9 @@ message UnaryOp {
MLOAD = 1;
SLOAD = 2;
ISZERO = 3;
CALLDATALOAD = 4;
EXTCODESIZE = 5;
EXTCODEHASH = 6;
}
required UOp op = 1;
required Expression operand = 2;
@ -122,11 +125,33 @@ message TernaryOp {
required Expression arg3 = 4;
}
message CopyFunc {
enum CopyType {
CALLDATA = 0;
CODE = 1;
RETURNDATA = 2;
}
required CopyType ct = 1;
required Expression target = 2;
required Expression source = 3;
required Expression size = 4;
}
message ExtCodeCopy {
required Expression addr = 1;
required Expression target = 2;
required Expression source = 3;
required Expression size = 4;
}
message NullaryOp {
enum NOp {
PC = 1;
MSIZE = 2;
GAS = 3;
CALLDATASIZE = 4;
CODESIZE = 5;
RETURNDATASIZE = 6;
}
required NOp op = 1;
}
@ -210,6 +235,8 @@ message Statement {
BreakStmt breakstmt = 8;
ContinueStmt contstmt = 9;
LogFunc log_func = 10;
CopyFunc copy_func = 11;
ExtCodeCopy extcode_copy = 12;
}
}