return instructionInfo style

This commit is contained in:
Dimitry 2016-04-04 15:27:09 +04:00
parent 9816510065
commit d43d4347bf
11 changed files with 17 additions and 17 deletions

View File

@ -121,7 +121,7 @@ ostream& Assembly::streamAsm(ostream& _out, string const& _prefix, StringMap con
switch (i.type()) switch (i.type())
{ {
case Operation: case Operation:
_out << " " << getInstructionInfo(i.instruction()).name << "\t" << i.getJumpTypeAsString(); _out << " " << instructionInfo(i.instruction()).name << "\t" << i.getJumpTypeAsString();
break; break;
case Push: case Push:
_out << " PUSH " << hex << i.data(); _out << " PUSH " << hex << i.data();
@ -205,7 +205,7 @@ Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes
{ {
case Operation: case Operation:
collection.append( collection.append(
createJsonValue(getInstructionInfo(i.instruction()).name, i.location().start, i.location().end, i.getJumpTypeAsString())); createJsonValue(instructionInfo(i.instruction()).name, i.location().start, i.location().end, i.getJumpTypeAsString()));
break; break;
case Push: case Push:
collection.append( collection.append(

View File

@ -57,7 +57,7 @@ int AssemblyItem::deposit() const
switch (m_type) switch (m_type)
{ {
case Operation: case Operation:
return getInstructionInfo(instruction()).ret - getInstructionInfo(instruction()).args; return instructionInfo(instruction()).ret - instructionInfo(instruction()).args;
case Push: case Push:
case PushString: case PushString:
case PushTag: case PushTag:
@ -93,7 +93,7 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItem const& _item)
switch (_item.type()) switch (_item.type())
{ {
case Operation: case Operation:
_out << " " << getInstructionInfo(_item.instruction()).name; _out << " " << instructionInfo(_item.instruction()).name;
if (_item.instruction() == solidity::Instruction::JUMP || _item.instruction() == solidity::Instruction::JUMPI) if (_item.instruction() == solidity::Instruction::JUMP || _item.instruction() == solidity::Instruction::JUMPI)
_out << "\t" << _item.getJumpTypeAsString(); _out << "\t" << _item.getJumpTypeAsString();
break; break;

View File

@ -399,7 +399,7 @@ void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced)
m_stack.erase(m_stackHeight - i); m_stack.erase(m_stackHeight - i);
} }
appendItem(*expr.item); appendItem(*expr.item);
if (expr.item->type() != Operation || getInstructionInfo(expr.item->instruction()).ret == 1) if (expr.item->type() != Operation || instructionInfo(expr.item->instruction()).ret == 1)
{ {
m_stack[m_stackHeight] = _c; m_stack[m_stackHeight] = _c;
m_classPositions[_c].insert(m_stackHeight); m_classPositions[_c].insert(m_stackHeight);
@ -407,7 +407,7 @@ void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced)
else else
{ {
assertThrow( assertThrow(
getInstructionInfo(expr.item->instruction()).ret == 0, instructionInfo(expr.item->instruction()).ret == 0,
OptimizerException, OptimizerException,
"Invalid number of return values." "Invalid number of return values."
); );

View File

@ -435,7 +435,7 @@ string Pattern::toString() const
switch (m_type) switch (m_type)
{ {
case Operation: case Operation:
s << getInstructionInfo(Instruction(unsigned(m_data))).name; s << instructionInfo(Instruction(unsigned(m_data))).name;
break; break;
case Push: case Push:
s << "PUSH " << hex << m_data; s << "PUSH " << hex << m_data;

View File

@ -209,7 +209,7 @@ u256 GasMeter::runGas(Instruction _instruction, EVMSchedule const& _es)
if (_instruction == Instruction::JUMPDEST) if (_instruction == Instruction::JUMPDEST)
return 1; return 1;
int tier = getInstructionInfo(_instruction).gasPriceTier; int tier = instructionInfo(_instruction).gasPriceTier;
assertThrow(tier != InvalidTier, OptimizerException, "Invalid gas tier."); assertThrow(tier != InvalidTier, OptimizerException, "Invalid gas tier.");
return _es.tierStepGas[tier]; return _es.tierStepGas[tier];
} }

View File

@ -307,7 +307,7 @@ void dev::solidity::eachInstruction(
Instruction instr = Instruction(*it); Instruction instr = Instruction(*it);
size_t additional = 0; size_t additional = 0;
if (isValidInstruction(instr)) if (isValidInstruction(instr))
additional = getInstructionInfo(instr).additional; additional = instructionInfo(instr).additional;
u256 data; u256 data;
for (size_t i = 0; i < additional; ++i) for (size_t i = 0; i < additional; ++i)
{ {
@ -327,7 +327,7 @@ string dev::solidity::disassemble(bytes const& _mem)
ret << "0x" << hex << int(_instr) << " "; ret << "0x" << hex << int(_instr) << " ";
else else
{ {
InstructionInfo info = getInstructionInfo(_instr); InstructionInfo info = instructionInfo(_instr);
ret << info.name << " "; ret << info.name << " ";
if (info.additional) if (info.additional)
ret << "0x" << hex << _data << " "; ret << "0x" << hex << _data << " ";
@ -336,7 +336,7 @@ string dev::solidity::disassemble(bytes const& _mem)
return ret.str(); return ret.str();
} }
InstructionInfo dev::solidity::getInstructionInfo(Instruction _inst) InstructionInfo dev::solidity::instructionInfo(Instruction _inst)
{ {
try try
{ {

View File

@ -250,7 +250,7 @@ struct InstructionInfo
}; };
/// Information on all the instructions. /// Information on all the instructions.
InstructionInfo getInstructionInfo(Instruction _inst); InstructionInfo instructionInfo(Instruction _inst);
/// check whether instructions exists /// check whether instructions exists
bool isValidInstruction(Instruction _inst); bool isValidInstruction(Instruction _inst);

View File

@ -101,7 +101,7 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
else else
{ {
Instruction instruction = _item.instruction(); Instruction instruction = _item.instruction();
InstructionInfo info = getInstructionInfo(instruction); InstructionInfo info = instructionInfo(instruction);
if (SemanticInformation::isDupInstruction(_item)) if (SemanticInformation::isDupInstruction(_item))
setStackElement( setStackElement(
m_stackHeight + 1, m_stackHeight + 1,

View File

@ -53,7 +53,7 @@ bool SemanticInformation::breaksCSEAnalysisBlock(AssemblyItem const& _item)
return true; // GAS and PC assume a specific order of opcodes return true; // GAS and PC assume a specific order of opcodes
if (_item.instruction() == Instruction::MSIZE) if (_item.instruction() == Instruction::MSIZE)
return true; // msize is modified already by memory access, avoid that for now return true; // msize is modified already by memory access, avoid that for now
InstructionInfo info = getInstructionInfo(_item.instruction()); InstructionInfo info = instructionInfo(_item.instruction());
if (_item.instruction() == Instruction::SSTORE) if (_item.instruction() == Instruction::SSTORE)
return false; return false;
if (_item.instruction() == Instruction::MSTORE) if (_item.instruction() == Instruction::MSTORE)

View File

@ -375,7 +375,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
else if (c_instructions.count(us)) else if (c_instructions.count(us))
{ {
auto it = c_instructions.find(us); auto it = c_instructions.find(us);
int ea = getInstructionInfo(it->second).args; int ea = instructionInfo(it->second).args;
if (ea >= 0) if (ea >= 0)
requireSize(ea); requireSize(ea);
else else

View File

@ -154,7 +154,7 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
dev::solidity::Instruction const& instr = s_instructions[literal]; dev::solidity::Instruction const& instr = s_instructions[literal];
if (_onlySinglePusher) if (_onlySinglePusher)
{ {
InstructionInfo info = dev::solidity::getInstructionInfo(instr); InstructionInfo info = dev::solidity::instructionInfo(instr);
if (info.ret != 1) if (info.ret != 1)
fatalParserError("Instruction " + info.name + " not allowed in this context."); fatalParserError("Instruction " + info.name + " not allowed in this context.");
} }
@ -200,7 +200,7 @@ FunctionalInstruction Parser::parseFunctionalInstruction(assembly::Statement con
if (_instruction.type() != typeid(Instruction)) if (_instruction.type() != typeid(Instruction))
fatalParserError("Assembly instruction required in front of \"(\")"); fatalParserError("Assembly instruction required in front of \"(\")");
solidity::Instruction instr = boost::get<solidity::assembly::Instruction>(_instruction).instruction; solidity::Instruction instr = boost::get<solidity::assembly::Instruction>(_instruction).instruction;
InstructionInfo instrInfo = getInstructionInfo(instr); InstructionInfo instrInfo = instructionInfo(instr);
if (solidity::Instruction::DUP1 <= instr && instr <= solidity::Instruction::DUP16) if (solidity::Instruction::DUP1 <= instr && instr <= solidity::Instruction::DUP16)
fatalParserError("DUPi instructions not allowed for functional notation"); fatalParserError("DUPi instructions not allowed for functional notation");
if (solidity::Instruction::SWAP1 <= instr && instr <= solidity::Instruction::SWAP16) if (solidity::Instruction::SWAP1 <= instr && instr <= solidity::Instruction::SWAP16)