mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'upstream/develop' into evmjit
This commit is contained in:
commit
8181792a6a
@ -378,8 +378,9 @@ bool Compiler::visit(FunctionDefinition const& _function)
|
|||||||
m_context.removeVariable(*localVariable);
|
m_context.removeVariable(*localVariable);
|
||||||
|
|
||||||
m_context.adjustStackOffset(-(int)c_returnValuesSize);
|
m_context.adjustStackOffset(-(int)c_returnValuesSize);
|
||||||
|
|
||||||
if (!_function.isConstructor())
|
if (!_function.isConstructor())
|
||||||
m_context << eth::Instruction::JUMP;
|
m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,8 +94,8 @@ private:
|
|||||||
std::vector<eth::AssemblyItem> m_continueTags; ///< tag to jump to for a "continue" statement
|
std::vector<eth::AssemblyItem> m_continueTags; ///< tag to jump to for a "continue" statement
|
||||||
eth::AssemblyItem m_returnTag; ///< tag to jump to for a "return" statement
|
eth::AssemblyItem m_returnTag; ///< tag to jump to for a "return" statement
|
||||||
unsigned m_modifierDepth = 0;
|
unsigned m_modifierDepth = 0;
|
||||||
FunctionDefinition const* m_currentFunction;
|
FunctionDefinition const* m_currentFunction = nullptr;
|
||||||
unsigned m_stackCleanupForReturn; ///< this number of stack elements need to be removed before jump to m_returnTag
|
unsigned m_stackCleanupForReturn = 0; ///< this number of stack elements need to be removed before jump to m_returnTag
|
||||||
// arguments for base constructors, filled in derived-to-base order
|
// arguments for base constructors, filled in derived-to-base order
|
||||||
std::map<FunctionDefinition const*, std::vector<ASTPointer<Expression>> const*> m_baseArguments;
|
std::map<FunctionDefinition const*, std::vector<ASTPointer<Expression>> const*> m_baseArguments;
|
||||||
};
|
};
|
||||||
|
@ -177,6 +177,13 @@ u256 CompilerContext::getStorageLocationOfVariable(const Declaration& _declarati
|
|||||||
return it->second;
|
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)
|
void CompilerContext::resetVisitedNodes(ASTNode const* _node)
|
||||||
{
|
{
|
||||||
stack<ASTNode const*> newStack;
|
stack<ASTNode const*> newStack;
|
||||||
|
@ -91,7 +91,7 @@ public:
|
|||||||
/// Appends a JUMP to a new tag and @returns the tag
|
/// Appends a JUMP to a new tag and @returns the tag
|
||||||
eth::AssemblyItem appendJumpToNew() { return m_asm.appendJump().tag(); }
|
eth::AssemblyItem appendJumpToNew() { return m_asm.appendJump().tag(); }
|
||||||
/// Appends a JUMP to a tag already on the stack
|
/// 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
|
/// Appends a JUMP to a specific tag
|
||||||
CompilerContext& appendJumpTo(eth::AssemblyItem const& _tag) { m_asm.appendJump(_tag); return *this; }
|
CompilerContext& appendJumpTo(eth::AssemblyItem const& _tag) { m_asm.appendJump(_tag); return *this; }
|
||||||
/// Appends pushing of a new tag and @returns the new tag.
|
/// Appends pushing of a new tag and @returns the new tag.
|
||||||
@ -120,7 +120,7 @@ public:
|
|||||||
|
|
||||||
eth::Assembly const& getAssembly() const { return m_asm; }
|
eth::Assembly const& getAssembly() const { return m_asm; }
|
||||||
/// @arg _sourceCodes is the map of input files to source code strings
|
/// @arg _sourceCodes is the map of input files to source code strings
|
||||||
void streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap()) const { m_asm.streamRLP(_stream, "", _sourceCodes); }
|
void streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap()) const { m_asm.stream(_stream, "", _sourceCodes); }
|
||||||
|
|
||||||
bytes getAssembledBytecode(bool _optimize = false) { return m_asm.optimise(_optimize).assemble(); }
|
bytes getAssembledBytecode(bool _optimize = false) { return m_asm.optimise(_optimize).assemble(); }
|
||||||
|
|
||||||
|
@ -108,7 +108,8 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
|
|||||||
retSizeOnStack = returnType->getSizeOnStack();
|
retSizeOnStack = returnType->getSizeOnStack();
|
||||||
}
|
}
|
||||||
solAssert(retSizeOnStack <= 15, "Stack too deep.");
|
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)
|
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);
|
_functionCall.getExpression().accept(*this);
|
||||||
|
|
||||||
m_context.appendJump();
|
m_context.appendJump(eth::AssemblyItem::JumpType::IntoFunction);
|
||||||
m_context << returnLabel;
|
m_context << returnLabel;
|
||||||
|
|
||||||
unsigned returnParametersSize = CompilerUtils::getSizeOnStack(function.getReturnParameterTypes());
|
unsigned returnParametersSize = CompilerUtils::getSizeOnStack(function.getReturnParameterTypes());
|
||||||
@ -825,10 +826,20 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
|
|||||||
Declaration const* declaration = _identifier.getReferencedDeclaration();
|
Declaration const* declaration = _identifier.getReferencedDeclaration();
|
||||||
if (MagicVariableDeclaration const* magicVar = dynamic_cast<MagicVariableDeclaration const*>(declaration))
|
if (MagicVariableDeclaration const* magicVar = dynamic_cast<MagicVariableDeclaration const*>(declaration))
|
||||||
{
|
{
|
||||||
if (magicVar->getType()->getCategory() == Type::Category::Contract)
|
switch (magicVar->getType()->getCategory())
|
||||||
|
{
|
||||||
|
case Type::Category::Contract:
|
||||||
// "this" or "super"
|
// "this" or "super"
|
||||||
if (!dynamic_cast<ContractType const&>(*magicVar->getType()).isSuper())
|
if (!dynamic_cast<ContractType const&>(*magicVar->getType()).isSuper())
|
||||||
m_context << eth::Instruction::ADDRESS;
|
m_context << eth::Instruction::ADDRESS;
|
||||||
|
break;
|
||||||
|
case Type::Category::Integer:
|
||||||
|
// "now"
|
||||||
|
m_context << eth::Instruction::TIMESTAMP;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (FunctionDefinition const* functionDef = dynamic_cast<FunctionDefinition const*>(declaration))
|
else if (FunctionDefinition const* functionDef = dynamic_cast<FunctionDefinition const*>(declaration))
|
||||||
m_context << m_context.getVirtualFunctionEntryLabel(*functionDef).pushTag();
|
m_context << m_context.getVirtualFunctionEntryLabel(*functionDef).pushTag();
|
||||||
|
@ -37,6 +37,7 @@ GlobalContext::GlobalContext():
|
|||||||
m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block)),
|
m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block)),
|
||||||
make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::Message)),
|
make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::Message)),
|
||||||
make_shared<MagicVariableDeclaration>("tx", make_shared<MagicType>(MagicType::Kind::Transaction)),
|
make_shared<MagicVariableDeclaration>("tx", make_shared<MagicType>(MagicType::Kind::Transaction)),
|
||||||
|
make_shared<MagicVariableDeclaration>("now", make_shared<IntegerType>(256)),
|
||||||
make_shared<MagicVariableDeclaration>("suicide",
|
make_shared<MagicVariableDeclaration>("suicide",
|
||||||
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Suicide)),
|
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Suicide)),
|
||||||
make_shared<MagicVariableDeclaration>("sha3",
|
make_shared<MagicVariableDeclaration>("sha3",
|
||||||
|
2
Parser.h
2
Parser.h
@ -34,6 +34,8 @@ class Scanner;
|
|||||||
class Parser
|
class Parser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Parser() {}
|
||||||
|
|
||||||
ASTPointer<SourceUnit> parse(std::shared_ptr<Scanner> const& _scanner);
|
ASTPointer<SourceUnit> parse(std::shared_ptr<Scanner> const& _scanner);
|
||||||
std::shared_ptr<std::string const> const& getSourceName() const;
|
std::shared_ptr<std::string const> const& getSourceName() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user