aboutsummaryrefslogtreecommitdiffstats
path: root/libjulia
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-06-09 19:59:16 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-06-16 17:56:21 +0800
commit868b5ad3aa9741609e9cd79d6033ee4b172dbe2f (patch)
tree293c82b54f40527135c8949a960b74a5695152eb /libjulia
parent1b3ba7bc5796e30143763eb8fcca589bd7095edb (diff)
downloaddexon-solidity-868b5ad3aa9741609e9cd79d6033ee4b172dbe2f.tar.gz
dexon-solidity-868b5ad3aa9741609e9cd79d6033ee4b172dbe2f.tar.zst
dexon-solidity-868b5ad3aa9741609e9cd79d6033ee4b172dbe2f.zip
Split block code generation into main and finalize.
Diffstat (limited to 'libjulia')
-rw-r--r--libjulia/backends/evm/EVMCodeTransform.cpp43
-rw-r--r--libjulia/backends/evm/EVMCodeTransform.h7
2 files changed, 27 insertions, 23 deletions
diff --git a/libjulia/backends/evm/EVMCodeTransform.cpp b/libjulia/backends/evm/EVMCodeTransform.cpp
index 64e13f94..e313e69c 100644
--- a/libjulia/backends/evm/EVMCodeTransform.cpp
+++ b/libjulia/backends/evm/EVMCodeTransform.cpp
@@ -33,24 +33,6 @@ using namespace dev::julia;
using namespace dev::solidity;
using namespace dev::solidity::assembly;
-void CodeTransform::run(Block const& _block)
-{
- m_scope = m_info.scopes.at(&_block).get();
-
- int blockStartStackHeight = m_assembly.stackHeight();
- std::for_each(_block.statements.begin(), _block.statements.end(), boost::apply_visitor(*this));
-
- m_assembly.setSourceLocation(_block.location);
-
- // pop variables
- for (size_t i = 0; i < m_scope->numberOfVariables(); ++i)
- m_assembly.appendInstruction(solidity::Instruction::POP);
-
- int deposit = m_assembly.stackHeight() - blockStartStackHeight;
- solAssert(deposit == 0, "Invalid stack height at end of block.");
- checkStackHeight(&_block);
-}
-
void CodeTransform::operator()(ForLoop const&)
{
@@ -319,7 +301,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
}
CodeTransform(m_assembly, m_info, m_evm15, m_identifierAccess, localStackAdjustment, m_context)
- .run(_function.body);
+ (_function.body);
{
// The stack layout here is:
@@ -364,7 +346,14 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
void CodeTransform::operator()(Block const& _block)
{
- CodeTransform(m_assembly, m_info, m_evm15, m_identifierAccess, m_stackAdjustment, m_context).run(_block);
+ Scope* originalScope = m_scope;
+ m_scope = m_info.scopes.at(&_block).get();
+
+ int blockStartStackHeight = m_assembly.stackHeight();
+ std::for_each(_block.statements.begin(), _block.statements.end(), boost::apply_visitor(*this));
+
+ finalizeBlock(_block, blockStartStackHeight);
+ m_scope = originalScope;
}
AbstractAssembly::LabelID CodeTransform::labelFromIdentifier(Identifier const& _identifier)
@@ -405,6 +394,20 @@ void CodeTransform::visitExpression(Statement const& _expression)
expectDeposit(1, height);
}
+void CodeTransform::finalizeBlock(Block const& _block, int blockStartStackHeight)
+{
+ m_assembly.setSourceLocation(_block.location);
+
+ // pop variables
+ solAssert(m_info.scopes.at(&_block).get() == m_scope, "");
+ for (size_t i = 0; i < m_scope->numberOfVariables(); ++i)
+ m_assembly.appendInstruction(solidity::Instruction::POP);
+
+ int deposit = m_assembly.stackHeight() - blockStartStackHeight;
+ solAssert(deposit == 0, "Invalid stack height at end of block.");
+ checkStackHeight(&_block);
+}
+
void CodeTransform::generateAssignment(Identifier const& _variableName)
{
solAssert(m_scope, "");
diff --git a/libjulia/backends/evm/EVMCodeTransform.h b/libjulia/backends/evm/EVMCodeTransform.h
index 7824247a..57bd4ca5 100644
--- a/libjulia/backends/evm/EVMCodeTransform.h
+++ b/libjulia/backends/evm/EVMCodeTransform.h
@@ -61,9 +61,6 @@ public:
{
}
- /// Processes the block and appends the resulting code to the assembly.
- void run(solidity::assembly::Block const& _block);
-
protected:
struct Context
{
@@ -113,6 +110,10 @@ private:
/// Generates code for an expression that is supposed to return a single value.
void visitExpression(solidity::assembly::Statement const& _expression);
+ /// Pops all variables declared in the block and checks that the stack height is equal
+ /// to @a _blackStartStackHeight.
+ void finalizeBlock(solidity::assembly::Block const& _block, int _blockStartStackHeight);
+
void generateAssignment(solidity::assembly::Identifier const& _variableName);
/// Determines the stack height difference to the given variables. Throws