From 9d7eb49f35f801b53960135b7c353fa64cea7439 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 4 May 2015 10:15:41 +0200 Subject: Gather knowledge about the state during control flow analysis. --- ControlFlowGraph.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'ControlFlowGraph.h') diff --git a/ControlFlowGraph.h b/ControlFlowGraph.h index 5d16df32..4310d664 100644 --- a/ControlFlowGraph.h +++ b/ControlFlowGraph.h @@ -24,16 +24,17 @@ #pragma once #include +#include #include #include +#include namespace dev { namespace eth { -class AssemblyItem; -using AssemblyItems = std::vector; +class KnownState; /** * Identifier for a block, coincides with the tag number of an AssemblyItem but adds a special @@ -69,14 +70,20 @@ struct BasicBlock unsigned end = 0; /// Tags pushed inside this block, with multiplicity. std::vector pushedTags; - /// ID of the block that always follows this one (either JUMP or flow into new block), - /// or BlockId::invalid() otherwise + /// ID of the block that always follows this one (either non-branching part of JUMPI or flow + /// into new block), or BlockId::invalid() otherwise BlockId next = BlockId::invalid(); - /// ID of the block that has to precede this one. + /// ID of the block that has to precede this one (because control flows into it). BlockId prev = BlockId::invalid(); enum class EndType { JUMP, JUMPI, STOP, HANDOVER }; EndType endType = EndType::HANDOVER; + + /// Knowledge about the state when this block is entered. Intersection of all possible ways + /// to enter this block. + std::shared_ptr startState; + /// Knowledge about the state at the end of this block. + std::shared_ptr endState; }; class ControlFlowGraph @@ -93,9 +100,14 @@ private: void splitBlocks(); void resolveNextLinks(); void removeUnusedBlocks(); + void gatherKnowledge(); void setPrevLinks(); AssemblyItems rebuildCode(); + /// @returns the corresponding BlockId if _id is a pushed jump tag, + /// and an invalid BlockId otherwise. + BlockId expressionClassToBlockId(ExpressionClasses::Id _id, ExpressionClasses& _exprClasses); + BlockId generateNewId(); unsigned m_lastUsedId = 0; -- cgit