Skip to content

Commit

Permalink
rename namespace for instruction.h/cpp in libevmasm
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Apr 2, 2016
1 parent ccbd3ff commit 858c412
Show file tree
Hide file tree
Showing 29 changed files with 596 additions and 594 deletions.
4 changes: 2 additions & 2 deletions libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ostream& Assembly::streamAsm(ostream& _out, string const& _prefix, StringMap con
switch (i.type())
{
case Operation:
_out << " " << instructionInfo(i.instruction()).name << "\t" << i.getJumpTypeAsString();
_out << " " << getInstructionInfo(i.instruction()).name << "\t" << i.getJumpTypeAsString();
break;
case Push:
_out << " PUSH " << hex << i.data();
Expand Down Expand Up @@ -205,7 +205,7 @@ Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes
{
case Operation:
collection.append(
createJsonValue(instructionInfo(i.instruction()).name, i.location().start, i.location().end, i.getJumpTypeAsString()));
createJsonValue(getInstructionInfo(i.instruction()).name, i.location().start, i.location().end, i.getJumpTypeAsString()));
break;
case Push:
collection.append(
Expand Down
6 changes: 3 additions & 3 deletions libevmasm/AssemblyItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int AssemblyItem::deposit() const
switch (m_type)
{
case Operation:
return instructionInfo(instruction()).ret - instructionInfo(instruction()).args;
return getInstructionInfo(instruction()).ret - getInstructionInfo(instruction()).args;
case Push:
case PushString:
case PushTag:
Expand Down Expand Up @@ -93,8 +93,8 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItem const& _item)
switch (_item.type())
{
case Operation:
_out << " " << instructionInfo(_item.instruction()).name;
if (_item.instruction() == eth::Instruction::JUMP || _item.instruction() == eth::Instruction::JUMPI)
_out << " " << getInstructionInfo(_item.instruction()).name;
if (_item.instruction() == solidity::Instruction::JUMP || _item.instruction() == solidity::Instruction::JUMPI)
_out << "\t" << _item.getJumpTypeAsString();
break;
case Push:
Expand Down
1 change: 1 addition & 0 deletions libevmasm/AssemblyItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <libevmasm/Instruction.h>
#include <libevmasm/SourceLocation.h>
#include "Exceptions.h"
using namespace dev::solidity;

namespace dev
{
Expand Down
2 changes: 1 addition & 1 deletion libevmasm/BlockDeduplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ BlockDeduplicator::BlockIterator& BlockDeduplicator::BlockIterator::operator++()
{
if (it == end)
return *this;
if (SemanticInformation::altersControlFlow(*it) && *it != AssemblyItem(eth::Instruction::JUMPI))
if (SemanticInformation::altersControlFlow(*it) && *it != AssemblyItem(solidity::Instruction::JUMPI))
it = end;
else
{
Expand Down
4 changes: 2 additions & 2 deletions libevmasm/CommonSubexpressionEliminator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced)
m_stack.erase(m_stackHeight - i);
}
appendItem(*expr.item);
if (expr.item->type() != Operation || instructionInfo(expr.item->instruction()).ret == 1)
if (expr.item->type() != Operation || getInstructionInfo(expr.item->instruction()).ret == 1)
{
m_stack[m_stackHeight] = _c;
m_classPositions[_c].insert(m_stackHeight);
}
else
{
assertThrow(
instructionInfo(expr.item->instruction()).ret == 0,
getInstructionInfo(expr.item->instruction()).ret == 0,
OptimizerException,
"Invalid number of return values."
);
Expand Down
2 changes: 1 addition & 1 deletion libevmasm/ExpressionClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ string Pattern::toString() const
switch (m_type)
{
case Operation:
s << instructionInfo(Instruction(unsigned(m_data))).name;
s << getInstructionInfo(Instruction(unsigned(m_data))).name;
break;
case Push:
s << "PUSH " << hex << m_data;
Expand Down
8 changes: 4 additions & 4 deletions libevmasm/GasMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item)
break;
case Instruction::MLOAD:
case Instruction::MSTORE:
gas += memoryGas(classes.find(eth::Instruction::ADD, {
gas += memoryGas(classes.find(solidity::Instruction::ADD, {
m_state->relativeStackElement(0),
classes.find(AssemblyItem(32))
}));
break;
case Instruction::MSTORE8:
gas += memoryGas(classes.find(eth::Instruction::ADD, {
gas += memoryGas(classes.find(solidity::Instruction::ADD, {
m_state->relativeStackElement(0),
classes.find(AssemblyItem(1))
}));
Expand Down Expand Up @@ -198,7 +198,7 @@ GasMeter::GasConsumption GasMeter::memoryGas(int _stackPosOffset, int _stackPosS
if (classes.knownZero(m_state->relativeStackElement(_stackPosSize)))
return GasConsumption(0);
else
return memoryGas(classes.find(eth::Instruction::ADD, {
return memoryGas(classes.find(solidity::Instruction::ADD, {
m_state->relativeStackElement(_stackPosOffset),
m_state->relativeStackElement(_stackPosSize)
}));
Expand All @@ -209,7 +209,7 @@ u256 GasMeter::runGas(Instruction _instruction, EVMSchedule const& _es)
if (_instruction == Instruction::JUMPDEST)
return 1;

int tier = instructionInfo(_instruction).gasPriceTier;
int tier = getInstructionInfo(_instruction).gasPriceTier;
assertThrow(tier != InvalidTier, OptimizerException, "Invalid gas tier.");
return _es.tierStepGas[tier];
}
Expand Down
18 changes: 9 additions & 9 deletions libevmasm/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
* @date 2014
*/

#include "Instruction.h"
#include "./Instruction.h"

#include <functional>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/Log.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace dev::solidity;

const std::map<std::string, Instruction> dev::eth::c_instructions =
const std::map<std::string, Instruction> dev::solidity::c_instructions =
{
{ "STOP", Instruction::STOP },
{ "ADD", Instruction::ADD },
Expand Down Expand Up @@ -297,7 +297,7 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
{ Instruction::SUICIDE, { "SUICIDE", 0, 1, 0, true, ZeroTier } }
};

void dev::eth::eachInstruction(
void dev::solidity::eachInstruction(
bytes const& _mem,
function<void(Instruction,u256 const&)> const& _onInstruction
)
Expand All @@ -307,7 +307,7 @@ void dev::eth::eachInstruction(
Instruction instr = Instruction(*it);
size_t additional = 0;
if (isValidInstruction(instr))
additional = instructionInfo(instr).additional;
additional = getInstructionInfo(instr).additional;
u256 data;
for (size_t i = 0; i < additional; ++i)
{
Expand All @@ -319,15 +319,15 @@ void dev::eth::eachInstruction(
}
}

string dev::eth::disassemble(bytes const& _mem)
string dev::solidity::disassemble(bytes const& _mem)
{
stringstream ret;
eachInstruction(_mem, [&](Instruction _instr, u256 const& _data) {
if (!isValidInstruction(_instr))
ret << "0x" << hex << int(_instr) << " ";
else
{
InstructionInfo info = instructionInfo(_instr);
InstructionInfo info = getInstructionInfo(_instr);
ret << info.name << " ";
if (info.additional)
ret << "0x" << hex << _data << " ";
Expand All @@ -336,7 +336,7 @@ string dev::eth::disassemble(bytes const& _mem)
return ret.str();
}

InstructionInfo dev::eth::instructionInfo(Instruction _inst)
InstructionInfo dev::solidity::getInstructionInfo(Instruction _inst)
{
try
{
Expand All @@ -348,7 +348,7 @@ InstructionInfo dev::eth::instructionInfo(Instruction _inst)
}
}

bool dev::eth::isValidInstruction(Instruction _inst)
bool dev::solidity::isValidInstruction(Instruction _inst)
{
return !!c_instructionInfo.count(_inst);
}
4 changes: 2 additions & 2 deletions libevmasm/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace dev
{
namespace eth
namespace solidity
{

DEV_SIMPLE_EXCEPTION(InvalidDeposit);
Expand Down Expand Up @@ -250,7 +250,7 @@ struct InstructionInfo
};

/// Information on all the instructions.
InstructionInfo instructionInfo(Instruction _inst);
InstructionInfo getInstructionInfo(Instruction _inst);

/// check whether instructions exists
bool isValidInstruction(Instruction _inst);
Expand Down
2 changes: 1 addition & 1 deletion libevmasm/KnownState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
else
{
Instruction instruction = _item.instruction();
InstructionInfo info = instructionInfo(instruction);
InstructionInfo info = getInstructionInfo(instruction);
if (SemanticInformation::isDupInstruction(_item))
setStackElement(
m_stackHeight + 1,
Expand Down
6 changes: 3 additions & 3 deletions libevmasm/PathGasMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ GasMeter::GasConsumption PathGasMeter::handleQueueItem()
bool branchStops = false;
jumpTags.clear();
AssemblyItem const& item = m_items.at(index);
if (item.type() == Tag || item == AssemblyItem(eth::Instruction::JUMPDEST))
if (item.type() == Tag || item == AssemblyItem(solidity::Instruction::JUMPDEST))
{
// Do not allow any backwards jump. This is quite restrictive but should work for
// the simplest things.
if (path->visitedJumpdests.count(index))
return GasMeter::GasConsumption::infinite();
path->visitedJumpdests.insert(index);
}
else if (item == AssemblyItem(eth::Instruction::JUMP))
else if (item == AssemblyItem(solidity::Instruction::JUMP))
{
branchStops = true;
jumpTags = state->tagsInExpression(state->relativeStackElement(0));
if (jumpTags.empty()) // unknown jump destination
return GasMeter::GasConsumption::infinite();
}
else if (item == AssemblyItem(eth::Instruction::JUMPI))
else if (item == AssemblyItem(solidity::Instruction::JUMPI))
{
ExpressionClasses::Id condition = state->relativeStackElement(-1);
if (classes.knownNonZero(condition) || !classes.knownZero(condition))
Expand Down
4 changes: 2 additions & 2 deletions libevmasm/SemanticInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool SemanticInformation::breaksCSEAnalysisBlock(AssemblyItem const& _item)
return true; // GAS and PC assume a specific order of opcodes
if (_item.instruction() == Instruction::MSIZE)
return true; // msize is modified already by memory access, avoid that for now
InstructionInfo info = instructionInfo(_item.instruction());
InstructionInfo info = getInstructionInfo(_item.instruction());
if (_item.instruction() == Instruction::SSTORE)
return false;
if (_item.instruction() == Instruction::MSTORE)
Expand Down Expand Up @@ -147,7 +147,7 @@ bool SemanticInformation::isDeterministic(AssemblyItem const& _item)
}
}

bool SemanticInformation::invalidatesMemory(Instruction _instruction)
bool SemanticInformation::invalidatesMemory(solidity::Instruction _instruction)
{
switch (_instruction)
{
Expand Down
4 changes: 2 additions & 2 deletions libevmasm/SemanticInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ struct SemanticInformation
/// the information in the current block header, memory, storage or stack.
static bool isDeterministic(AssemblyItem const& _item);
/// @returns true if the given instruction modifies memory.
static bool invalidatesMemory(Instruction _instruction);
static bool invalidatesMemory(solidity::Instruction _instruction);
/// @returns true if the given instruction modifies storage (even indirectly).
static bool invalidatesStorage(Instruction _instruction);
static bool invalidatesStorage(solidity::Instruction _instruction);
};

}
Expand Down
2 changes: 1 addition & 1 deletion liblll/CodeFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
else if (c_instructions.count(us))
{
auto it = c_instructions.find(us);
int ea = instructionInfo(it->second).args;
int ea = getInstructionInfo(it->second).args;
if (ea >= 0)
requireSize(ea);
else
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
if (!varDecl->isLocalVariable())
return false; // only local variables are inline-assemlby lvalues
for (unsigned i = 0; i < declaration->type()->sizeOnStack(); ++i)
_assembly.append(eth::Instruction::POP); // remove value just to verify the stack height
_assembly.append(solidity::Instruction::POP); // remove value just to verify the stack height
}
else
return false;
Expand Down
Loading

0 comments on commit 858c412

Please sign in to comment.