added information about jump type for jump instructions

Conflicts:
	libevmcore/Assembly.cpp
	libsolidity/Compiler.cpp
This commit is contained in:
Liana Husikyan 2015-03-09 19:22:24 +01:00
parent 9c82cbeddf
commit 74a01826ee
4 changed files with 19 additions and 6 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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.

View File

@ -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());