aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen/CompilerContext.h
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-05-03 07:13:41 +0800
committerchriseth <c@ethdev.com>2016-05-03 07:14:26 +0800
commit652bc583c0abde30cd54b960502ac50ffd8192d4 (patch)
treea2ece00139b75bf61149cbc3c31624b8bd374cc5 /libsolidity/codegen/CompilerContext.h
parentbee80f1d812078a705c71ade76ab66461a33d099 (diff)
downloaddexon-solidity-652bc583c0abde30cd54b960502ac50ffd8192d4.tar.gz
dexon-solidity-652bc583c0abde30cd54b960502ac50ffd8192d4.tar.zst
dexon-solidity-652bc583c0abde30cd54b960502ac50ffd8192d4.zip
Remove non-determinism in missing code queue.
Diffstat (limited to 'libsolidity/codegen/CompilerContext.h')
-rw-r--r--libsolidity/codegen/CompilerContext.h44
1 files changed, 38 insertions, 6 deletions
diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h
index 9368dbcf..5abe59fe 100644
--- a/libsolidity/codegen/CompilerContext.h
+++ b/libsolidity/codegen/CompilerContext.h
@@ -24,6 +24,7 @@
#include <ostream>
#include <stack>
+#include <queue>
#include <utility>
#include <libevmasm/Instruction.h>
#include <libevmasm/Assembly.h>
@@ -72,8 +73,11 @@ public:
eth::AssemblyItem superFunctionEntryLabel(FunctionDefinition const& _function, ContractDefinition const& _base);
FunctionDefinition const* nextConstructor(ContractDefinition const& _contract) const;
- /// @returns the set of functions for which we still need to generate code
- std::set<Declaration const*> functionsWithoutCode();
+ /// @returns the next function in the queue of functions that are still to be compiled
+ /// (i.e. that were referenced during compilation but where we did not yet generate code for).
+ /// Returns nullptr if the queue is empty. Does not remove the function from the queue,
+ /// that will only be done by startFunction below.
+ Declaration const* nextFunctionToCompile() const;
/// Resets function specific members, inserts the function entry label and marks the function
/// as "having code".
void startFunction(Declaration const& _function);
@@ -168,6 +172,38 @@ private:
/// Updates source location set in the assembly.
void updateSourceLocation();
+ /**
+ * Helper class that manages function labels and ensures that referenced functions are
+ * compiled in a specific order.
+ */
+ struct FunctionCompilationQueue
+ {
+ /// @returns the entry label of the given function and creates it if it does not exist yet.
+ /// @param _context compiler context used to create a new tag if needed
+ eth::AssemblyItem entryLabel(Declaration const& _declaration, CompilerContext& _context);
+ /// @returns the entry label of the given function. Might return an AssemblyItem of type
+ /// UndefinedItem if it does not exist yet.
+ eth::AssemblyItem entryLabelIfExists(Declaration const& _declaration) const;
+
+ /// @returns the next function in the queue of functions that are still to be compiled
+ /// (i.e. that were referenced during compilation but where we did not yet generate code for).
+ /// Returns nullptr if the queue is empty. Does not remove the function from the queue,
+ /// that will only be done by startFunction below.
+ Declaration const* nextFunctionToCompile() const;
+ /// Informs the queue that we are about to compile the given function, i.e. removes
+ /// the function from the queue of functions to compile.
+ void startFunction(const Declaration &_function);
+
+ /// Labels pointing to the entry points of functions.
+ std::map<Declaration const*, eth::AssemblyItem> m_entryLabels;
+ /// Set of functions for which we did not yet generate code.
+ std::set<Declaration const*> m_alreadyCompiledFunctions;
+ /// Queue of functions that still need to be compiled (important to be a queue to maintain
+ /// determinism even in the presence of a non-deterministic allocator).
+ /// Mutable because we will throw out some functions earlier than needed.
+ mutable std::queue<Declaration const*> m_functionsToCompile;
+ } m_functionCompilationQueue;
+
eth::Assembly m_asm;
/// Magic global variables like msg, tx or this, distinguished by type.
std::set<Declaration const*> m_magicGlobals;
@@ -177,10 +213,6 @@ private:
std::map<Declaration const*, std::pair<u256, unsigned>> m_stateVariables;
/// Offsets of local variables on the stack (relative to stack base).
std::map<Declaration const*, unsigned> m_localVariables;
- /// Labels pointing to the entry points of functions.
- std::map<Declaration const*, eth::AssemblyItem> m_functionEntryLabels;
- /// Set of functions for which we did not yet generate code.
- std::set<Declaration const*> m_functionsWithCode;
/// List of current inheritance hierarchy from derived to base.
std::vector<ContractDefinition const*> m_inheritanceHierarchy;
/// Stack of current visited AST nodes, used for location attachment