Browse Source

added information about jump type for jump instructions

Conflicts:
	libevmcore/Assembly.cpp
	libsolidity/Compiler.cpp
cl-refactor
Liana Husikyan 10 years ago
parent
commit
4323a0c655
  1. 10
      libevmcore/Assembly.cpp
  2. 11
      libsolidity/Compiler.cpp
  3. 7
      libsolidity/CompilerContext.cpp
  4. 2
      libsolidity/CompilerContext.h
  5. 5
      libsolidity/ExpressionCompiler.cpp

10
libevmcore/Assembly.cpp

@ -82,12 +82,12 @@ string AssemblyItem::getJumpTypeAsString() const
switch (m_jumpType)
{
case JumpType::IntoFunction:
return "->";
return "in";
case JumpType::OutOfFunction:
return "<-";
return "out";
case JumpType::Ordinary:
default:
return "->";
return "";
}
}
@ -219,7 +219,7 @@ ostream& Assembly::streamRLP(ostream& _out, string const& _prefix, StringMap con
switch (i.m_type)
{
case Operation:
_out << " " << instructionInfo((Instruction)(byte)i.m_data).name << " " << i.getJumpTypeAsString( ) << endl;
_out << " " << instructionInfo((Instruction)(byte)i.m_data).name << "\t\t" << i.getJumpTypeAsString();
break;
case Push:
_out << " PUSH " << i.m_data;
@ -254,7 +254,7 @@ ostream& Assembly::streamRLP(ostream& _out, string const& _prefix, StringMap con
default:
BOOST_THROW_EXCEPTION(InvalidOpcode());
}
_out << string("\t\t") << getLocationFromSources(_sourceCodes, i.getLocation()) << endl;
_out << "\t\t" << getLocationFromSources(_sourceCodes, i.getLocation()) << endl;
}
if (!m_data.empty() || !m_subs.empty())

11
libsolidity/Compiler.cpp

@ -177,7 +177,9 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract)
{
callDataUnpackerEntryPoints.insert(std::make_pair(it.first, m_context.newTag()));
m_context << eth::dupInstruction(1) << u256(FixedHash<4>::Arith(it.first)) << eth::Instruction::EQ;
m_context.appendConditionalJumpTo(callDataUnpackerEntryPoints.at(it.first));
auto assemblyItem = callDataUnpackerEntryPoints.at(it.first);
//assemblyItem.setJumpType(eth::AssemblyItem::JumpType::IntoFunction);
m_context.appendConditionalJumpTo(assemblyItem);
}
if (FunctionDefinition const* fallback = _contract.getFallbackFunction())
{
@ -197,7 +199,9 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract)
m_context << callDataUnpackerEntryPoints.at(it.first);
eth::AssemblyItem returnTag = m_context.pushNewTag();
appendCalldataUnpacker(functionType->getParameterTypes());
m_context.appendJumpTo(m_context.getFunctionEntryLabel(functionType->getDeclaration()));
auto assemblyItem = m_context.getFunctionEntryLabel(functionType->getDeclaration());
//assemblyItem.setJumpType(eth::AssemblyItem::JumpType::IntoFunction);
m_context.appendJumpTo(assemblyItem);
m_context << returnTag;
appendReturnValuePacker(functionType->getReturnParameterTypes());
}
@ -378,8 +382,9 @@ bool Compiler::visit(FunctionDefinition const& _function)
m_context.removeVariable(*localVariable);
m_context.adjustStackOffset(-(int)c_returnValuesSize);
if (!_function.isConstructor())
m_context << eth::Instruction::JUMP;
m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
return false;
}

7
libsolidity/CompilerContext.cpp

@ -177,6 +177,13 @@ u256 CompilerContext::getStorageLocationOfVariable(const Declaration& _declarati
return it->second;
}
CompilerContext& CompilerContext::appendJump(eth::AssemblyItem::JumpType _jumpType)
{
eth::AssemblyItem item(eth::Instruction::JUMP);
item.setJumpType(_jumpType);
return *this << item;
}
void CompilerContext::resetVisitedNodes(ASTNode const* _node)
{
stack<ASTNode const*> newStack;

2
libsolidity/CompilerContext.h

@ -91,7 +91,7 @@ public:
/// Appends a JUMP to a new tag and @returns the tag
eth::AssemblyItem appendJumpToNew() { return m_asm.appendJump().tag(); }
/// Appends a JUMP to a tag already on the stack
CompilerContext& appendJump() { return *this << eth::Instruction::JUMP; }
CompilerContext& appendJump(eth::AssemblyItem::JumpType _jumpType = eth::AssemblyItem::JumpType::Ordinary);
/// Appends a JUMP to a specific tag
CompilerContext& appendJumpTo(eth::AssemblyItem const& _tag) { m_asm.appendJump(_tag); return *this; }
/// Appends pushing of a new tag and @returns the new tag.

5
libsolidity/ExpressionCompiler.cpp

@ -108,7 +108,8 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
retSizeOnStack = returnType->getSizeOnStack();
}
solAssert(retSizeOnStack <= 15, "Stack too deep.");
m_context << eth::dupInstruction(retSizeOnStack + 1) << eth::Instruction::JUMP;
m_context << eth::dupInstruction(retSizeOnStack + 1);
m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
}
void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type const& _targetType, bool _cleanupNeeded)
@ -405,7 +406,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
}
_functionCall.getExpression().accept(*this);
m_context.appendJump();
m_context.appendJump(eth::AssemblyItem::JumpType::IntoFunction);
m_context << returnLabel;
unsigned returnParametersSize = CompilerUtils::getSizeOnStack(function.getReturnParameterTypes());

Loading…
Cancel
Save