From 97cc968a133247e729ed1d189d35ef2b7b53b3d4 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 24 May 2017 18:34:19 +0200 Subject: Initial EVM1.5 assembly implementation. --- libjulia/backends/evm/EVMCodeTransform.h | 43 ++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'libjulia/backends/evm/EVMCodeTransform.h') diff --git a/libjulia/backends/evm/EVMCodeTransform.h b/libjulia/backends/evm/EVMCodeTransform.h index 64e76246..d82462a7 100644 --- a/libjulia/backends/evm/EVMCodeTransform.h +++ b/libjulia/backends/evm/EVMCodeTransform.h @@ -18,12 +18,13 @@ * Common code generator for translating Julia / inline assembly to EVM and EVM1.5. */ -#include +#include #include #include #include +#include namespace dev { @@ -45,37 +46,49 @@ struct StackAssignment; struct FunctionDefinition; struct FunctionCall; +using Statement = boost::variant; + struct AsmAnalysisInfo; } } namespace julia { +class EVMAssembly; class CodeTransform: public boost::static_visitor<> { public: - /// Create the code transformer which appends assembly to _assembly as a side-effect - /// of its creation. + /// Create the code transformer. /// @param _identifierAccess used to resolve identifiers external to the inline assembly CodeTransform( solidity::ErrorReporter& _errorReporter, julia::AbstractAssembly& _assembly, - solidity::assembly::Block const& _block, solidity::assembly::AsmAnalysisInfo& _analysisInfo, + bool _evm15 = false, ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess() - ): CodeTransform(_errorReporter, _assembly, _block, _analysisInfo, _identifierAccess, _assembly.stackHeight()) + ): CodeTransform(_errorReporter, _assembly, _analysisInfo, _evm15, _identifierAccess, _assembly.stackHeight()) { } -private: + /// Processes the block and appends the resulting code to the assembly. + void run(solidity::assembly::Block const& _block); + +protected: CodeTransform( solidity::ErrorReporter& _errorReporter, julia::AbstractAssembly& _assembly, - solidity::assembly::Block const& _block, solidity::assembly::AsmAnalysisInfo& _analysisInfo, + bool _evm15, ExternalIdentifierAccess const& _identifierAccess, int _initialStackHeight - ); + ): + m_errorReporter(_errorReporter), + m_assembly(_assembly), + m_info(_analysisInfo), + m_evm15(_evm15), + m_identifierAccess(_identifierAccess), + m_initialStackHeight(_initialStackHeight) + {} public: void operator()(solidity::assembly::Instruction const& _instruction); @@ -87,11 +100,14 @@ public: void operator()(solidity::assembly::StackAssignment const& _assignment); void operator()(solidity::assembly::Assignment const& _assignment); void operator()(solidity::assembly::VariableDeclaration const& _varDecl); - void operator()(solidity::assembly::Block const& _block); void operator()(solidity::assembly::Switch const& _switch); void operator()(solidity::assembly::FunctionDefinition const&); + void operator()(solidity::assembly::Block const& _block); + + AbstractAssembly::LabelID labelFromIdentifier(solidity::assembly::Identifier const& _identifier); + /// Generates code for an expression that is supposed to return a single value. + void visitExpression(solidity::assembly::Statement const& _expression); -private: void generateAssignment(solidity::assembly::Identifier const& _variableName, SourceLocation const& _location); /// Determines the stack height difference to the given variables. Automatically generates @@ -103,13 +119,14 @@ private: void checkStackHeight(void const* _astElement); - /// Assigns the label's id to a value taken from eth::Assembly if it has not yet been set. - void assignLabelIdIfUnset(solidity::assembly::Scope::Label& _label); + /// Assigns the label's or function's id to a value taken from eth::Assembly if it has not yet been set. + void assignLabelIdIfUnset(boost::optional& _labelId); solidity::ErrorReporter& m_errorReporter; julia::AbstractAssembly& m_assembly; solidity::assembly::AsmAnalysisInfo& m_info; - solidity::assembly::Scope& m_scope; + solidity::assembly::Scope* m_scope = nullptr; + bool m_evm15 = false; ExternalIdentifierAccess m_identifierAccess; int const m_initialStackHeight; }; -- cgit