aboutsummaryrefslogtreecommitdiffstats
path: root/liblll/CodeFragment.cpp
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2017-10-18 18:02:14 +0800
committerGitHub <noreply@github.com>2017-10-18 18:02:14 +0800
commitfda8499c1549dee11dea4207d7f0ed4ab75c7856 (patch)
tree771be72c1e500933597c325b15e210a49fcd53ed /liblll/CodeFragment.cpp
parente854da1a8c2253704e412214e8115fd1c1c819f2 (diff)
parent15517b571d3ac4ee01af3e2e2f3fff7c5b2296c5 (diff)
downloaddexon-solidity-fda8499c1549dee11dea4207d7f0ed4ab75c7856.tar
dexon-solidity-fda8499c1549dee11dea4207d7f0ed4ab75c7856.tar.gz
dexon-solidity-fda8499c1549dee11dea4207d7f0ed4ab75c7856.tar.bz2
dexon-solidity-fda8499c1549dee11dea4207d7f0ed4ab75c7856.tar.lz
dexon-solidity-fda8499c1549dee11dea4207d7f0ed4ab75c7856.tar.xz
dexon-solidity-fda8499c1549dee11dea4207d7f0ed4ab75c7856.tar.zst
dexon-solidity-fda8499c1549dee11dea4207d7f0ed4ab75c7856.zip
Merge pull request #3070 from ethereum/lll-assembly
lll: disallow useless PUSHn in assembly
Diffstat (limited to 'liblll/CodeFragment.cpp')
-rw-r--r--liblll/CodeFragment.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp
index d4ef3888..5c68194b 100644
--- a/liblll/CodeFragment.cpp
+++ b/liblll/CodeFragment.cpp
@@ -47,6 +47,32 @@ void CodeFragment::finalise(CompilerState const& _cs)
}
}
+namespace
+{
+/// Returns true iff the instruction is valid in "inline assembly".
+bool validAssemblyInstruction(string us)
+{
+ auto it = c_instructions.find(us);
+ return !(
+ it == c_instructions.end() ||
+ solidity::isPushInstruction(it->second)
+ );
+}
+
+/// Returns true iff the instruction is valid as a function.
+bool validFunctionalInstruction(string us)
+{
+ auto it = c_instructions.find(us);
+ return !(
+ it == c_instructions.end() ||
+ solidity::isPushInstruction(it->second) ||
+ solidity::isDupInstruction(it->second) ||
+ solidity::isSwapInstruction(it->second) ||
+ it->second == solidity::Instruction::JUMPDEST
+ );
+}
+}
+
CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, ReadCallback const& _readFile, bool _allowASM):
m_readFile(_readFile)
{
@@ -80,7 +106,7 @@ CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, ReadCallback
auto sr = _t.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::symbol_type>>();
string s(sr.begin(), sr.end());
string us = boost::algorithm::to_upper_copy(s);
- if (_allowASM && c_instructions.count(us))
+ if (_allowASM && c_instructions.count(us) && validAssemblyInstruction(us))
m_asm.append(c_instructions.at(us));
else if (_s.defs.count(s))
m_asm.append(_s.defs.at(s).m_asm);
@@ -114,22 +140,6 @@ CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, ReadCallback
}
}
-namespace
-{
-/// Returns true iff the instruction is valid as a function.
-bool validFunctionalInstruction(string us)
-{
- auto it = c_instructions.find(us);
- return !(
- it == c_instructions.end() ||
- solidity::isPushInstruction(it->second) ||
- solidity::isDupInstruction(it->second) ||
- solidity::isSwapInstruction(it->second) ||
- it->second == solidity::Instruction::JUMPDEST
- );
-}
-}
-
void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
{
if (_t.tag() == 0 && _t.empty())