aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-08-17 08:14:15 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-08-22 17:51:46 +0800
commite2cfc9ee92158169b5dd058074f25d67959e9875 (patch)
tree90cb281b48f95bdcc9904ed12def22bffcb88fb7 /libevmasm
parentc94b1f81730c27480cb5813a7a909511613c14c5 (diff)
downloaddexon-solidity-e2cfc9ee92158169b5dd058074f25d67959e9875.tar.gz
dexon-solidity-e2cfc9ee92158169b5dd058074f25d67959e9875.tar.zst
dexon-solidity-e2cfc9ee92158169b5dd058074f25d67959e9875.zip
Mark a lot of functions const (where possible)
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/ConstantOptimiser.cpp10
-rw-r--r--libevmasm/ConstantOptimiser.h22
2 files changed, 16 insertions, 16 deletions
diff --git a/libevmasm/ConstantOptimiser.cpp b/libevmasm/ConstantOptimiser.cpp
index 2ecbfa7f..a7a87c35 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();
@@ -234,7 +234,7 @@ AssemblyItems ComputeMethod::findRepresentation(u256 const& _value)
}
}
-bool ComputeMethod::checkRepresentation(u256 const& _value, AssemblyItems const& _routine)
+bool ComputeMethod::checkRepresentation(u256 const& _value, AssemblyItems const& _routine) const
{
// This is a tiny EVM that can only evaluate some instructions.
vector<u256> stack;
@@ -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..19f14f7a 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,8 +117,8 @@ 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;
@@ -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);
+ bool checkRepresentation(u256 const& _value, AssemblyItems const& _routine) const;
+ bigint gasNeeded(AssemblyItems const& _routine) const;
/// Counter for the complexity of optimization, will stop when it reaches zero.
size_t m_maxSteps = 10000;