diff options
author | chriseth <c@ethdev.com> | 2015-11-19 20:16:13 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-11-19 20:16:13 +0800 |
commit | 8dfc964e7d6dc0ca997e29091f8a7d25e26942cf (patch) | |
tree | f30ff9d4d5845cc6fe13e42b596f6f1ff7c52067 /libsolidity | |
parent | 3be0ae6e2cff95239dab9b37c9722d55481e8b26 (diff) | |
parent | 0cf8d022ae7d2e2da347347fdc76ba9529149c35 (diff) | |
download | dexon-solidity-8dfc964e7d6dc0ca997e29091f8a7d25e26942cf.tar.gz dexon-solidity-8dfc964e7d6dc0ca997e29091f8a7d25e26942cf.tar.zst dexon-solidity-8dfc964e7d6dc0ca997e29091f8a7d25e26942cf.zip |
Merge pull request #227 from chriseth/addmod
Addmod and mulmod.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/GlobalContext.cpp | 4 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 2 | ||||
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 14 |
3 files changed, 20 insertions, 0 deletions
diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index 20f8272f..d519934d 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -40,6 +40,10 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared< make_shared<MagicVariableDeclaration>("now", make_shared<IntegerType>(256)), make_shared<MagicVariableDeclaration>("suicide", make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Suicide)), + make_shared<MagicVariableDeclaration>("addmod", + make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Location::AddMod)), + make_shared<MagicVariableDeclaration>("mulmod", + make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Location::MulMod)), make_shared<MagicVariableDeclaration>("sha3", make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Location::SHA3, true)), make_shared<MagicVariableDeclaration>("log0", diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 2f75975f..59c84b7a 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -747,6 +747,8 @@ public: SetGas, ///< modify the default gas value for the function call SetValue, ///< modify the default value transfer for the function call BlockHash, ///< BLOCKHASH + AddMod, ///< ADDMOD + MulMod, ///< MULMOD ArrayPush, ///< .push() to a dynamically sized array in storage ByteArrayPush ///< .push() to a dynamically sized byte array in storage }; diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 3906a897..0f952f9c 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -637,6 +637,20 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << eth::Instruction::BLOCKHASH; break; } + case Location::AddMod: + case Location::MulMod: + { + for (unsigned i = 0; i < 3; i ++) + { + arguments[2 - i]->accept(*this); + utils().convertType(*arguments[2 - i]->annotation().type, IntegerType(256)); + } + if (function.location() == Location::AddMod) + m_context << eth::Instruction::ADDMOD; + else + m_context << eth::Instruction::MULMOD; + break; + } case Location::ECRecover: case Location::SHA256: case Location::RIPEMD160: |