aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-01-27 23:55:06 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-01-29 04:46:16 +0800
commit2947e038d28d3d732b1db352f71c8c9669df8eef (patch)
treed7ce1854e21c124b8af1ebcc300e04bda39890e1
parentff91ab96ea843bd8ab9a7c57fd799add2ebc9873 (diff)
downloaddexon-solidity-2947e038d28d3d732b1db352f71c8c9669df8eef.tar
dexon-solidity-2947e038d28d3d732b1db352f71c8c9669df8eef.tar.gz
dexon-solidity-2947e038d28d3d732b1db352f71c8c9669df8eef.tar.bz2
dexon-solidity-2947e038d28d3d732b1db352f71c8c9669df8eef.tar.lz
dexon-solidity-2947e038d28d3d732b1db352f71c8c9669df8eef.tar.xz
dexon-solidity-2947e038d28d3d732b1db352f71c8c9669df8eef.tar.zst
dexon-solidity-2947e038d28d3d732b1db352f71c8c9669df8eef.zip
EVM Code for simple accessor function is properly generated
-rw-r--r--Compiler.cpp12
-rw-r--r--Compiler.h2
-rw-r--r--ExpressionCompiler.cpp15
-rw-r--r--ExpressionCompiler.h6
4 files changed, 20 insertions, 15 deletions
diff --git a/Compiler.cpp b/Compiler.cpp
index c419f484..bda18bc6 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -292,21 +292,19 @@ void Compiler::registerStateVariables(ContractDefinition const& _contract)
m_context.addStateVariable(*variable);
}
-bool Compiler::generateAccessorCode(VariableDeclaration const& _varDecl)
+void Compiler::generateAccessorCode(VariableDeclaration const& _varDecl)
{
m_context.startNewFunction();
m_returnTag = m_context.newTag();
m_breakTags.clear();
m_continueTags.clear();
- // TODO: Work in progress
m_context << m_context.getFunctionEntryLabel(_varDecl);
- // CompilerUtils(m_context).moveToStackVariable(firstVariable);
- m_context.appendJumpTo(m_returnTag);
- m_context << m_returnTag;
+ ExpressionCompiler::appendStateVariableAccessor(m_context, &_varDecl);
- // TODO: perhaps return void if there are no checks?
- return true;
+ uint64_t foo = uint64_t(_varDecl.getType()->getStorageSize());
+ m_context << eth::dupInstruction(foo + 1);
+ m_context << eth::Instruction::JUMP;
}
bool Compiler::visit(FunctionDefinition const& _function)
diff --git a/Compiler.h b/Compiler.h
index 71a12a66..144af8eb 100644
--- a/Compiler.h
+++ b/Compiler.h
@@ -63,7 +63,7 @@ private:
void registerStateVariables(ContractDefinition const& _contract);
- bool generateAccessorCode(VariableDeclaration const& _varDecl);
+ void generateAccessorCode(VariableDeclaration const& _varDecl);
virtual bool visit(FunctionDefinition const& _function) override;
virtual bool visit(IfStatement const& _ifStatement) override;
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index 450cc2fe..66e2c68c 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -48,6 +48,12 @@ void ExpressionCompiler::appendTypeConversion(CompilerContext& _context, Type co
compiler.appendTypeConversion(_typeOnStack, _targetType, _cleanupNeeded);
}
+void ExpressionCompiler::appendStateVariableAccessor(CompilerContext& _context, VariableDeclaration const* _varDecl, bool _optimize)
+{
+ ExpressionCompiler compiler(_context, _optimize);
+ compiler.appendStateVariableAccessor(_varDecl);
+}
+
bool ExpressionCompiler::visit(Assignment const& _assignment)
{
_assignment.getRightHandSide().accept(*this);
@@ -792,8 +798,7 @@ unsigned ExpressionCompiler::appendArgumentCopyToMemory(TypePointers const& _typ
void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const* _varDecl)
{
m_currentLValue.fromStateVariable(*_varDecl, _varDecl->getType());
- // TODO
- // m_currentLValue.retrieveValueFromStorage();
+ m_currentLValue.retrieveValueFromStorage(_varDecl->getType(), true);
}
ExpressionCompiler::LValue::LValue(CompilerContext& _compilerContext, LValueType _type, Type const& _dataType,
@@ -823,7 +828,7 @@ void ExpressionCompiler::LValue::retrieveValue(Expression const& _expression, bo
break;
}
case STORAGE:
- retrieveValueFromStorage(_expression, _remove);
+ retrieveValueFromStorage(_expression.getType(), _remove);
break;
case MEMORY:
if (!_expression.getType()->isValueType())
@@ -838,9 +843,9 @@ void ExpressionCompiler::LValue::retrieveValue(Expression const& _expression, bo
}
}
-void ExpressionCompiler::LValue::retrieveValueFromStorage(Expression const& _expression, bool _remove) const
+void ExpressionCompiler::LValue::retrieveValueFromStorage(std::shared_ptr<Type const> const& _type, bool _remove) const
{
- if (!_expression.getType()->isValueType())
+ if (!_type->isValueType())
return; // no distinction between value and reference for non-value types
if (!_remove)
*m_context << eth::Instruction::DUP1;
diff --git a/ExpressionCompiler.h b/ExpressionCompiler.h
index bff2cd7c..8479344a 100644
--- a/ExpressionCompiler.h
+++ b/ExpressionCompiler.h
@@ -53,6 +53,8 @@ public:
/// Appends code to remove dirty higher order bits in case of an implicit promotion to a wider type.
static void appendTypeConversion(CompilerContext& _context, Type const& _typeOnStack,
Type const& _targetType, bool _cleanupNeeded = false);
+ /// Appends code for a State Variable accessor function
+ static void appendStateVariableAccessor(CompilerContext& _context, VariableDeclaration const* _varDecl, bool _optimize = false);
private:
explicit ExpressionCompiler(CompilerContext& _compilerContext, bool _optimize = false):
@@ -130,8 +132,8 @@ private:
/// also removes the reference from the stack (note that is does not reset the type to @a NONE).
/// @a _expression is the current expression, used for error reporting.
void retrieveValue(Expression const& _expression, bool _remove = false) const;
- /// Convenience function to retrive Value from Storage. Specific version of @ref retrieveValue
- void retrieveValueFromStorage(Expression const& _expression, bool _remove = false) const;
+ /// Convenience function to retrieve Value from Storage. Specific version of @ref retrieveValue
+ void retrieveValueFromStorage(std::shared_ptr<Type const> const& _type, bool _remove = false) const;
/// Stores a value (from the stack directly beneath the reference, which is assumed to
/// be on the top of the stack, if any) in the lvalue and removes the reference.
/// Also removes the stored value from the stack if @a _move is