aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/AssemblyItem.cpp12
-rw-r--r--libevmasm/BlockDeduplicator.h2
-rw-r--r--libevmasm/CommonSubexpressionEliminator.cpp1
-rw-r--r--libevmasm/CommonSubexpressionEliminator.h4
-rw-r--r--libevmasm/ConstantOptimiser.cpp10
-rw-r--r--libevmasm/ConstantOptimiser.h24
-rw-r--r--libevmasm/PathGasMeter.h2
7 files changed, 28 insertions, 27 deletions
diff --git a/libevmasm/AssemblyItem.cpp b/libevmasm/AssemblyItem.cpp
index 76104866..419a8c0b 100644
--- a/libevmasm/AssemblyItem.cpp
+++ b/libevmasm/AssemblyItem.cpp
@@ -219,10 +219,10 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItem const& _item)
_out << "\t" << _item.getJumpTypeAsString();
break;
case Push:
- _out << " PUSH " << hex << _item.data();
+ _out << " PUSH " << hex << _item.data() << dec;
break;
case PushString:
- _out << " PushString" << hex << (unsigned)_item.data();
+ _out << " PushString" << hex << (unsigned)_item.data() << dec;
break;
case PushTag:
{
@@ -237,19 +237,19 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItem const& _item)
_out << " Tag " << _item.data();
break;
case PushData:
- _out << " PushData " << hex << (unsigned)_item.data();
+ _out << " PushData " << hex << (unsigned)_item.data() << dec;
break;
case PushSub:
- _out << " PushSub " << hex << size_t(_item.data());
+ _out << " PushSub " << hex << size_t(_item.data()) << dec;
break;
case PushSubSize:
- _out << " PushSubSize " << hex << size_t(_item.data());
+ _out << " PushSubSize " << hex << size_t(_item.data()) << dec;
break;
case PushProgramSize:
_out << " PushProgramSize";
break;
case PushLibraryAddress:
- _out << " PushLibraryAddress " << hex << h256(_item.data()).abridgedMiddle();
+ _out << " PushLibraryAddress " << hex << h256(_item.data()).abridgedMiddle() << dec;
break;
case UndefinedItem:
_out << " ???";
diff --git a/libevmasm/BlockDeduplicator.h b/libevmasm/BlockDeduplicator.h
index 797c2476..5640984b 100644
--- a/libevmasm/BlockDeduplicator.h
+++ b/libevmasm/BlockDeduplicator.h
@@ -45,7 +45,7 @@ using AssemblyItems = std::vector<AssemblyItem>;
class BlockDeduplicator
{
public:
- BlockDeduplicator(AssemblyItems& _items): m_items(_items) {}
+ explicit BlockDeduplicator(AssemblyItems& _items): m_items(_items) {}
/// @returns true if something was changed
bool deduplicate();
/// @returns the tags that were replaced.
diff --git a/libevmasm/CommonSubexpressionEliminator.cpp b/libevmasm/CommonSubexpressionEliminator.cpp
index 70324e7f..293cb02c 100644
--- a/libevmasm/CommonSubexpressionEliminator.cpp
+++ b/libevmasm/CommonSubexpressionEliminator.cpp
@@ -220,6 +220,7 @@ void CSECodeGenerator::addDependencies(Id _c)
if (m_neededBy.count(_c))
return; // we already computed the dependencies for _c
ExpressionClasses::Expression expr = m_expressionClasses.representative(_c);
+ assertThrow(expr.item, OptimizerException, "");
if (expr.item->type() == UndefinedItem)
BOOST_THROW_EXCEPTION(
// If this exception happens, we need to find a different way to generate the
diff --git a/libevmasm/CommonSubexpressionEliminator.h b/libevmasm/CommonSubexpressionEliminator.h
index 83fc9732..0b957a0e 100644
--- a/libevmasm/CommonSubexpressionEliminator.h
+++ b/libevmasm/CommonSubexpressionEliminator.h
@@ -61,7 +61,7 @@ public:
using Id = ExpressionClasses::Id;
using StoreOperation = KnownState::StoreOperation;
- CommonSubexpressionEliminator(KnownState const& _state): m_initialState(_state), m_state(_state) {}
+ explicit CommonSubexpressionEliminator(KnownState const& _state): m_initialState(_state), m_state(_state) {}
/// Feeds AssemblyItems into the eliminator and @returns the iterator pointing at the first
/// item that must be fed into a new instance of the eliminator.
@@ -147,7 +147,7 @@ private:
AssemblyItems m_generatedItems;
/// Current height of the stack relative to the start.
- int m_stackHeight;
+ int m_stackHeight = 0;
/// If (b, a) is in m_requests then b is needed to compute a.
std::multimap<Id, Id> m_neededBy;
/// Current content of the stack.
diff --git a/libevmasm/ConstantOptimiser.cpp b/libevmasm/ConstantOptimiser.cpp
index 2ecbfa7f..2efd2dc9 100644
--- a/libevmasm/ConstantOptimiser.cpp
+++ b/libevmasm/ConstantOptimiser.cpp
@@ -124,7 +124,7 @@ void ConstantOptimisationMethod::replaceConstants(
_items = std::move(replaced);
}
-bigint LiteralMethod::gasNeeded()
+bigint LiteralMethod::gasNeeded() const
{
return combineGas(
simpleRunGas({Instruction::PUSH1}),
@@ -139,7 +139,7 @@ CodeCopyMethod::CodeCopyMethod(Params const& _params, u256 const& _value):
{
}
-bigint CodeCopyMethod::gasNeeded()
+bigint CodeCopyMethod::gasNeeded() const
{
return combineGas(
// Run gas: we ignore memory increase costs
@@ -151,7 +151,7 @@ bigint CodeCopyMethod::gasNeeded()
);
}
-AssemblyItems CodeCopyMethod::execute(Assembly& _assembly)
+AssemblyItems CodeCopyMethod::execute(Assembly& _assembly) const
{
bytes data = toBigEndian(m_value);
AssemblyItems actualCopyRoutine = copyRoutine();
@@ -159,7 +159,7 @@ AssemblyItems CodeCopyMethod::execute(Assembly& _assembly)
return actualCopyRoutine;
}
-AssemblyItems const& CodeCopyMethod::copyRoutine() const
+AssemblyItems const& CodeCopyMethod::copyRoutine()
{
AssemblyItems static copyRoutine{
u256(0),
@@ -282,7 +282,7 @@ bool ComputeMethod::checkRepresentation(u256 const& _value, AssemblyItems const&
return stack.size() == 1 && stack.front() == _value;
}
-bigint ComputeMethod::gasNeeded(AssemblyItems const& _routine)
+bigint ComputeMethod::gasNeeded(AssemblyItems const& _routine) const
{
size_t numExps = count(_routine.begin(), _routine.end(), Instruction::EXP);
return combineGas(
diff --git a/libevmasm/ConstantOptimiser.h b/libevmasm/ConstantOptimiser.h
index 85bdabac..82982e25 100644
--- a/libevmasm/ConstantOptimiser.h
+++ b/libevmasm/ConstantOptimiser.h
@@ -63,11 +63,11 @@ public:
explicit ConstantOptimisationMethod(Params const& _params, u256 const& _value):
m_params(_params), m_value(_value) {}
- virtual bigint gasNeeded() = 0;
+ virtual bigint gasNeeded() const = 0;
/// Executes the method, potentially appending to the assembly and returns a vector of
/// assembly items the constant should be relpaced with in one sweep.
/// If the vector is empty, the constants will not be deleted.
- virtual AssemblyItems execute(Assembly& _assembly) = 0;
+ virtual AssemblyItems execute(Assembly& _assembly) const = 0;
protected:
size_t dataSize() const { return std::max<size_t>(1, dev::bytesRequired(m_value)); }
@@ -84,7 +84,7 @@ protected:
bigint const& _runGas,
bigint const& _repeatedDataGas,
bigint const& _uniqueDataGas
- )
+ ) const
{
// _runGas is not multiplied by _multiplicity because the runs are "per opcode"
return m_params.runs * _runGas + m_params.multiplicity * _repeatedDataGas + _uniqueDataGas;
@@ -106,8 +106,8 @@ class LiteralMethod: public ConstantOptimisationMethod
public:
explicit LiteralMethod(Params const& _params, u256 const& _value):
ConstantOptimisationMethod(_params, _value) {}
- virtual bigint gasNeeded() override;
- virtual AssemblyItems execute(Assembly&) override { return AssemblyItems{}; }
+ virtual bigint gasNeeded() const override;
+ virtual AssemblyItems execute(Assembly&) const override { return AssemblyItems{}; }
};
/**
@@ -117,11 +117,11 @@ class CodeCopyMethod: public ConstantOptimisationMethod
{
public:
explicit CodeCopyMethod(Params const& _params, u256 const& _value);
- virtual bigint gasNeeded() override;
- virtual AssemblyItems execute(Assembly& _assembly) override;
+ virtual bigint gasNeeded() const override;
+ virtual AssemblyItems execute(Assembly& _assembly) const override;
protected:
- AssemblyItems const& copyRoutine() const;
+ static AssemblyItems const& copyRoutine();
};
/**
@@ -141,8 +141,8 @@ public:
);
}
- virtual bigint gasNeeded() override { return gasNeeded(m_routine); }
- virtual AssemblyItems execute(Assembly&) override
+ virtual bigint gasNeeded() const override { return gasNeeded(m_routine); }
+ virtual AssemblyItems execute(Assembly&) const override
{
return m_routine;
}
@@ -151,8 +151,8 @@ protected:
/// Tries to recursively find a way to compute @a _value.
AssemblyItems findRepresentation(u256 const& _value);
/// Recomputes the value from the calculated representation and checks for correctness.
- bool checkRepresentation(u256 const& _value, AssemblyItems const& _routine);
- bigint gasNeeded(AssemblyItems const& _routine);
+ static bool checkRepresentation(u256 const& _value, AssemblyItems const& _routine);
+ bigint gasNeeded(AssemblyItems const& _routine) const;
/// Counter for the complexity of optimization, will stop when it reaches zero.
size_t m_maxSteps = 10000;
diff --git a/libevmasm/PathGasMeter.h b/libevmasm/PathGasMeter.h
index 0a0fe5d0..4826eac2 100644
--- a/libevmasm/PathGasMeter.h
+++ b/libevmasm/PathGasMeter.h
@@ -50,7 +50,7 @@ struct GasPath
class PathGasMeter
{
public:
- PathGasMeter(AssemblyItems const& _items);
+ explicit PathGasMeter(AssemblyItems const& _items);
GasMeter::GasConsumption estimateMax(size_t _startIndex, std::shared_ptr<KnownState> const& _state);